From: Michael Jeanson <mjeanson@efficios.com>
To: libc-alpha@sourceware.org
Cc: Michael Jeanson <mjeanson@efficios.com>,
Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: [PATCH v8 5/8] nptl: Add rseq internal utils
Date: Tue, 6 Feb 2024 11:27:58 -0500 [thread overview]
Message-ID: <20240206162801.882585-6-mjeanson@efficios.com> (raw)
In-Reply-To: <20240206162801.882585-1-mjeanson@efficios.com>
Implement internal rseq utils in preparation for their use in
rseq_load32_load32_relaxed().
This implementation is imported from the librseq project.
Co-authored-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
---
sysdeps/unix/sysv/linux/rseq-internal.h | 56 +++++++++++++++++++++++++
1 file changed, 56 insertions(+)
diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h
index a63e4afbdb..b6c29c14cc 100644
--- a/sysdeps/unix/sysv/linux/rseq-internal.h
+++ b/sysdeps/unix/sysv/linux/rseq-internal.h
@@ -41,12 +41,68 @@ struct rseq_area
uint32_t mm_cid;
};
+/*
+ * gcc prior to 4.8.2 miscompiles asm goto.
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
+ *
+ * gcc prior to 8.1.0 miscompiles asm goto at O1.
+ * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103908
+ *
+ * clang prior to version 13.0.1 miscompiles asm goto at O2.
+ * https://github.com/llvm/llvm-project/issues/52735
+ *
+ * Work around these issues by adding a volatile inline asm with
+ * memory clobber in the fallthrough after the asm goto and at each
+ * label target. Emit this for all compilers in case other similar
+ * issues are found in the future.
+ */
+#define rseq_after_asm_goto() __asm__ __volatile__ ("" : : : "memory")
+
+#define __rseq_str_1(x) #x
+#define __rseq_str(x) __rseq_str_1(x)
+
+/* Offset of rseq_cs field in struct rseq. */
+#define RSEQ_CS_OFFSET 8
+
+#define rseq_sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
+#define rseq_offsetofend(TYPE, MEMBER) \
+ (offsetof(TYPE, MEMBER) + rseq_sizeof_field(TYPE, MEMBER))
+
+/* Returns a pointer to the current thread rseq area. */
static inline struct rseq_area *
rseq_get_area(void)
{
return (struct rseq_area *) ((char *) __thread_pointer() + GLRO (dl_tls_rseq_offset));
}
+/* Returns the int value of 'rseq_area->cpu_id'. */
+static inline int
+rseq_get_cpu_id(void)
+{
+ return (int) RSEQ_GETMEM_VOLATILE (rseq_get_area(), cpu_id);
+}
+
+/* Returns true if the rseq registration is active. */
+static inline bool
+rseq_is_registered(void)
+{
+ return rseq_get_cpu_id() >= 0;
+}
+
+/* Returns true if the current rseq registration has the 'node_id' field. */
+static inline bool
+rseq_node_id_available(void)
+{
+ return __rseq_feature_size >= rseq_offsetofend(struct rseq_area, node_id);
+}
+
+/* Returns true if the current rseq registration has the 'mm_cid' field. */
+static inline bool
+rseq_mm_cid_available(void)
+{
+ return __rseq_feature_size >= rseq_offsetofend(struct rseq_area, mm_cid);
+}
+
#ifdef RSEQ_SIG
static inline bool
rseq_register_current_thread (struct pthread *self, bool do_rseq)
--
2.34.1
next prev parent reply other threads:[~2024-02-06 16:28 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-06 16:27 [PATCH v8 0/8] Extend rseq support Michael Jeanson
2024-02-06 16:27 ` [PATCH v8 1/8] nptl: fix potential merge of __rseq_* relro symbols Michael Jeanson
2024-02-06 16:41 ` Mathieu Desnoyers
2024-02-16 2:02 ` DJ Delorie
2024-02-16 20:18 ` Michael Jeanson
2024-02-16 20:29 ` DJ Delorie
2024-02-06 16:27 ` [PATCH v8 2/8] Add rseq extensible ABI support Michael Jeanson
2024-02-16 4:42 ` DJ Delorie
2024-02-16 20:19 ` Michael Jeanson
2024-02-16 20:37 ` DJ Delorie
2024-02-16 21:10 ` Michael Jeanson
2024-02-16 21:17 ` DJ Delorie
2024-02-16 21:24 ` Michael Jeanson
2024-02-06 16:27 ` [PATCH v8 3/8] nptl: Add public __rseq_feature_size symbol Michael Jeanson
2024-02-16 22:07 ` DJ Delorie
2024-02-19 19:25 ` Michael Jeanson
2024-02-19 19:43 ` DJ Delorie
2024-02-19 20:15 ` Michael Jeanson
2024-02-19 20:24 ` DJ Delorie
2024-02-19 22:06 ` Michael Jeanson
2024-02-19 22:08 ` DJ Delorie
2024-02-19 22:18 ` Michael Jeanson
2024-02-19 22:21 ` DJ Delorie
2024-02-06 16:27 ` [PATCH v8 4/8] nptl: Add features to internal 'struct rseq_area' Michael Jeanson
2024-02-17 2:04 ` DJ Delorie
2024-02-06 16:27 ` Michael Jeanson [this message]
2024-02-17 2:33 ` [PATCH v8 5/8] nptl: Add rseq internal utils DJ Delorie
2024-02-19 20:25 ` Michael Jeanson
2024-02-06 16:27 ` [PATCH v8 6/8] x86-64: Add rseq_load32_load32_relaxed Michael Jeanson
2024-02-17 3:08 ` DJ Delorie
2024-02-19 20:27 ` Michael Jeanson
2024-02-06 16:28 ` [PATCH v8 7/8] aarch64: " Michael Jeanson
2024-02-17 3:53 ` DJ Delorie
2024-02-19 20:29 ` Michael Jeanson
2024-02-20 15:07 ` Mathieu Desnoyers
2024-02-20 17:55 ` DJ Delorie
2024-02-06 16:28 ` [PATCH v8 8/8] Linux: Use rseq to accelerate getcpu Michael Jeanson
2024-02-17 3:57 ` DJ Delorie
2024-02-19 22:14 ` Michael Jeanson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240206162801.882585-6-mjeanson@efficios.com \
--to=mjeanson@efficios.com \
--cc=libc-alpha@sourceware.org \
--cc=mathieu.desnoyers@efficios.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).