[v8,5/8] nptl: Add rseq internal utils
Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Testing passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Testing passed
|
Commit Message
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(+)
Comments
Michael Jeanson <mjeanson@efficios.com> writes:
> Implement internal rseq utils in preparation for their use in
> rseq_load32_load32_relaxed().
>
> This implementation is imported from the librseq project.
*Which* librseq project, and what are the copyright/license terms of
that project? I assume this has been discussed and approved before, but
for archival reasons, that URL should be listed here explicitly, along
with some note of the copyright clearance.
> diff --git a/sysdeps/unix/sysv/linux/rseq-internal.h b/sysdeps/unix/sysv/linux/rseq-internal.h
> +/*
> + * 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")
Ok.
> +#define __rseq_str_1(x) #x
> +#define __rseq_str(x) __rseq_str_1(x)
Ok.
> +/* Offset of rseq_cs field in struct rseq. */
> +#define RSEQ_CS_OFFSET 8
Ok.
> +#define rseq_sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
> +#define rseq_offsetofend(TYPE, MEMBER) \
> + (offsetof(TYPE, MEMBER) + rseq_sizeof_field(TYPE, MEMBER))
Technically offsetofjustafterend, but ok ;-)
> +/* 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);
> +}
Ok.
> +/* Returns true if the rseq registration is active. */
> +static inline bool
> +rseq_is_registered(void)
> +{
> + return rseq_get_cpu_id() >= 0;
> +}
Ok, REGISTRATION_FAILED is -2
> +/* 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);
> +}
Ok.
> +/* 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);
> +}
Ok.
On 2024-02-16 21:33, DJ Delorie wrote:
> Michael Jeanson <mjeanson@efficios.com> writes:
>> Implement internal rseq utils in preparation for their use in
>> rseq_load32_load32_relaxed().
>>
>> This implementation is imported from the librseq project.
>
> *Which* librseq project, and what are the copyright/license terms of
> that project? I assume this has been discussed and approved before, but
> for archival reasons, that URL should be listed here explicitly, along
> with some note of the copyright clearance.
For reference, here is the URL to the librseq project :
https://git.kernel.org/pub/scm/libs/librseq/librseq.git
I'll double check the copyright clearance and licensing before sending the
next patchset.
@@ -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)