For the API, add a new flag to sys_rseq 'flags' argument called
RSEQ_FLAG_QUERY_CS_FLAGS.
When this flag is passed it returns a bit mask of all the supported
rseq cs flags in the user provided rseq struct's 'flags' member.
Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Prakash Sangappa <prakash.sangappa@oracle.com>
---
include/uapi/linux/rseq.h | 1 +
kernel/rseq.c | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/uapi/linux/rseq.h b/include/uapi/linux/rseq.h
index 015534f064af..44baea9dd10a 100644
--- a/include/uapi/linux/rseq.h
+++ b/include/uapi/linux/rseq.h
@@ -20,6 +20,7 @@ enum rseq_cpu_id_state {
enum rseq_flags {
RSEQ_FLAG_UNREGISTER = (1 << 0),
+ RSEQ_FLAG_QUERY_CS_FLAGS = (1 << 1),
};
enum rseq_cs_flags_bit {
diff --git a/kernel/rseq.c b/kernel/rseq.c
index c4bc52f8ba9c..997f7ca722ca 100644
--- a/kernel/rseq.c
+++ b/kernel/rseq.c
@@ -576,6 +576,23 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
return 0;
}
+ /*
+ * return supported rseq_cs flags
+ * It is an or of all the rseq_cs_flags;
+ */
+ if (flags & RSEQ_FLAG_QUERY_CS_FLAGS) {
+ u32 rseq_csflags = RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT |
+ RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL |
+ RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE |
+ RSEQ_CS_FLAG_DELAY_RESCHED |
+ RSEQ_CS_FLAG_RESCHEDULED;
+ if (!rseq)
+ return -EINVAL;
+ if (copy_to_user(&rseq->flags, &rseq_csflags, sizeof(u32)))
+ return -EFAULT;
+ return 0;
+ }
+
if (unlikely(flags))
return -EINVAL;
--
2.43.5
On 2025-05-13 17:45, Prakash Sangappa wrote:
> For the API, add a new flag to sys_rseq 'flags' argument called
> RSEQ_FLAG_QUERY_CS_FLAGS.
>
> When this flag is passed it returns a bit mask of all the supported
> rseq cs flags in the user provided rseq struct's 'flags' member.
>
> Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
> Signed-off-by: Prakash Sangappa <prakash.sangappa@oracle.com>
> ---
> include/uapi/linux/rseq.h | 1 +
> kernel/rseq.c | 17 +++++++++++++++++
> 2 files changed, 18 insertions(+)
>
> diff --git a/include/uapi/linux/rseq.h b/include/uapi/linux/rseq.h
> index 015534f064af..44baea9dd10a 100644
> --- a/include/uapi/linux/rseq.h
> +++ b/include/uapi/linux/rseq.h
> @@ -20,6 +20,7 @@ enum rseq_cpu_id_state {
>
> enum rseq_flags {
> RSEQ_FLAG_UNREGISTER = (1 << 0),
> + RSEQ_FLAG_QUERY_CS_FLAGS = (1 << 1),
> };
>
> enum rseq_cs_flags_bit {
> diff --git a/kernel/rseq.c b/kernel/rseq.c
> index c4bc52f8ba9c..997f7ca722ca 100644
> --- a/kernel/rseq.c
> +++ b/kernel/rseq.c
> @@ -576,6 +576,23 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
> return 0;
> }
>
> + /*
> + * return supported rseq_cs flags
> + * It is an or of all the rseq_cs_flags;
> + */
> + if (flags & RSEQ_FLAG_QUERY_CS_FLAGS) {
> + u32 rseq_csflags = RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT |
> + RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL |
> + RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE |
Those 3 flags (above) are already or'd by RSEQ_CS_NO_RESTART_FLAGS,
and they are all deprecated. See rseq_warn_flags().
So I would not return them within the set of supported
rseq flags.
Thanks,
Mathieu
> + RSEQ_CS_FLAG_DELAY_RESCHED |
> + RSEQ_CS_FLAG_RESCHEDULED;
> + if (!rseq)
> + return -EINVAL;
> + if (copy_to_user(&rseq->flags, &rseq_csflags, sizeof(u32)))
> + return -EFAULT;
> + return 0;
> + }
> +
> if (unlikely(flags))
> return -EINVAL;
>
--
Mathieu Desnoyers
EfficiOS Inc.
https://www.efficios.com
> On May 23, 2025, at 12:57 PM, Mathieu Desnoyers <mathieu.desnoyers@efficios.com> wrote:
>
> On 2025-05-13 17:45, Prakash Sangappa wrote:
>> For the API, add a new flag to sys_rseq 'flags' argument called
>> RSEQ_FLAG_QUERY_CS_FLAGS.
>> When this flag is passed it returns a bit mask of all the supported
>> rseq cs flags in the user provided rseq struct's 'flags' member.
>> Suggested-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
>> Signed-off-by: Prakash Sangappa <prakash.sangappa@oracle.com>
>> ---
>> include/uapi/linux/rseq.h | 1 +
>> kernel/rseq.c | 17 +++++++++++++++++
>> 2 files changed, 18 insertions(+)
>> diff --git a/include/uapi/linux/rseq.h b/include/uapi/linux/rseq.h
>> index 015534f064af..44baea9dd10a 100644
>> --- a/include/uapi/linux/rseq.h
>> +++ b/include/uapi/linux/rseq.h
>> @@ -20,6 +20,7 @@ enum rseq_cpu_id_state {
>> enum rseq_flags {
>> RSEQ_FLAG_UNREGISTER = (1 << 0),
>> + RSEQ_FLAG_QUERY_CS_FLAGS = (1 << 1),
>> };
>> enum rseq_cs_flags_bit {
>> diff --git a/kernel/rseq.c b/kernel/rseq.c
>> index c4bc52f8ba9c..997f7ca722ca 100644
>> --- a/kernel/rseq.c
>> +++ b/kernel/rseq.c
>> @@ -576,6 +576,23 @@ SYSCALL_DEFINE4(rseq, struct rseq __user *, rseq, u32, rseq_len,
>> return 0;
>> }
>> + /*
>> + * return supported rseq_cs flags
>> + * It is an or of all the rseq_cs_flags;
>> + */
>> + if (flags & RSEQ_FLAG_QUERY_CS_FLAGS) {
>> + u32 rseq_csflags = RSEQ_CS_FLAG_NO_RESTART_ON_PREEMPT |
>> + RSEQ_CS_FLAG_NO_RESTART_ON_SIGNAL |
>> + RSEQ_CS_FLAG_NO_RESTART_ON_MIGRATE |
>
> Those 3 flags (above) are already or'd by RSEQ_CS_NO_RESTART_FLAGS,
> and they are all deprecated. See rseq_warn_flags().
>
> So I would not return them within the set of supported
> rseq flags.
WIll remove those from the supported flags.
Thanks
-Prakash.
>
> Thanks,
>
> Mathieu
>
>
>
>> + RSEQ_CS_FLAG_DELAY_RESCHED |
>> + RSEQ_CS_FLAG_RESCHEDULED;
>> + if (!rseq)
>> + return -EINVAL;
>> + if (copy_to_user(&rseq->flags, &rseq_csflags, sizeof(u32)))
>> + return -EFAULT;
>> + return 0;
>> + }
>> +
>> if (unlikely(flags))
>> return -EINVAL;
>>
>
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> https://www.efficios.com
© 2016 - 2025 Red Hat, Inc.