[patch 03/12] rseq: Provide static branch for time slice extensions

Thomas Gleixner posted 12 patches 1 day, 3 hours ago
[patch 03/12] rseq: Provide static branch for time slice extensions
Posted by Thomas Gleixner 1 day, 2 hours ago
Guard the time slice extension functionality with a static key, which can
be disabled on the kernel command line.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: "Paul E. McKenney" <paulmck@kernel.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
---
 include/linux/rseq_entry.h |   11 +++++++++++
 kernel/rseq.c              |   17 +++++++++++++++++
 2 files changed, 28 insertions(+)

--- a/include/linux/rseq_entry.h
+++ b/include/linux/rseq_entry.h
@@ -77,6 +77,17 @@ DECLARE_STATIC_KEY_MAYBE(CONFIG_RSEQ_DEB
 #define rseq_inline __always_inline
 #endif
 
+#ifdef CONFIG_RSEQ_SLICE_EXTENSION
+DECLARE_STATIC_KEY_TRUE(rseq_slice_extension_key);
+
+static __always_inline bool rseq_slice_extension_enabled(void)
+{
+	return static_branch_likely(&rseq_slice_extension_key);
+}
+#else /* CONFIG_RSEQ_SLICE_EXTENSION */
+static inline bool rseq_slice_extension_enabled(void) { return false; }
+#endif /* !CONFIG_RSEQ_SLICE_EXTENSION */
+
 bool rseq_debug_update_user_cs(struct task_struct *t, struct pt_regs *regs, unsigned long csaddr);
 bool rseq_debug_validate_ids(struct task_struct *t);
 
--- a/kernel/rseq.c
+++ b/kernel/rseq.c
@@ -474,3 +474,20 @@ SYSCALL_DEFINE4(rseq, struct rseq __user
 
 	return 0;
 }
+
+#ifdef CONFIG_RSEQ_SLICE_EXTENSION
+DEFINE_STATIC_KEY_TRUE(rseq_slice_extension_key);
+
+static int __init rseq_slice_cmdline(char *str)
+{
+	bool on;
+
+	if (kstrtobool(str, &on))
+		return -EINVAL;
+
+	if (!on)
+		static_branch_disable(&rseq_slice_extension_key);
+	return 0;
+}
+__setup("rseq_slice_ext=", rseq_slice_cmdline);
+#endif /* CONFIG_RSEQ_SLICE_EXTENSION */
Re: [patch 03/12] rseq: Provide static branch for time slice extensions
Posted by K Prateek Nayak 22 hours ago
Hello Thomas,

On 9/9/2025 4:29 AM, Thomas Gleixner wrote:
> +#ifdef CONFIG_RSEQ_SLICE_EXTENSION
> +DEFINE_STATIC_KEY_TRUE(rseq_slice_extension_key);
> +
> +static int __init rseq_slice_cmdline(char *str)
> +{
> +	bool on;
> +
> +	if (kstrtobool(str, &on))
> +		return -EINVAL;
> +
> +	if (!on)
> +		static_branch_disable(&rseq_slice_extension_key);
> +	return 0;

I believe this should return "1" signalling that the cmdline was handled
correctly to avoid an "Unknown kernel command line parameters" message.

> +}
> +__setup("rseq_slice_ext=", rseq_slice_cmdline);
> +#endif /* CONFIG_RSEQ_SLICE_EXTENSION */
> 

-- 
Thanks and Regards,
Prateek
Re: [patch 03/12] rseq: Provide static branch for time slice extensions
Posted by Randy Dunlap 21 hours ago

On 9/8/25 8:10 PM, K Prateek Nayak wrote:
> Hello Thomas,
> 
> On 9/9/2025 4:29 AM, Thomas Gleixner wrote:
>> +#ifdef CONFIG_RSEQ_SLICE_EXTENSION
>> +DEFINE_STATIC_KEY_TRUE(rseq_slice_extension_key);
>> +
>> +static int __init rseq_slice_cmdline(char *str)
>> +{
>> +	bool on;
>> +
>> +	if (kstrtobool(str, &on))
>> +		return -EINVAL;
>> +
>> +	if (!on)
>> +		static_branch_disable(&rseq_slice_extension_key);
>> +	return 0;
> 
> I believe this should return "1" signalling that the cmdline was handled
> correctly to avoid an "Unknown kernel command line parameters" message.

Good catch. I agree.
Thanks.

>> +}
>> +__setup("rseq_slice_ext=", rseq_slice_cmdline);
>> +#endif /* CONFIG_RSEQ_SLICE_EXTENSION */
>>
> 

-- 
~Randy
Re: [patch 03/12] rseq: Provide static branch for time slice extensions
Posted by Thomas Gleixner 13 hours ago
On Mon, Sep 08 2025 at 21:11, Randy Dunlap wrote:
> On 9/8/25 8:10 PM, K Prateek Nayak wrote:
>> Hello Thomas,
>> 
>> On 9/9/2025 4:29 AM, Thomas Gleixner wrote:
>>> +#ifdef CONFIG_RSEQ_SLICE_EXTENSION
>>> +DEFINE_STATIC_KEY_TRUE(rseq_slice_extension_key);
>>> +
>>> +static int __init rseq_slice_cmdline(char *str)
>>> +{
>>> +	bool on;
>>> +
>>> +	if (kstrtobool(str, &on))
>>> +		return -EINVAL;
>>> +
>>> +	if (!on)
>>> +		static_branch_disable(&rseq_slice_extension_key);
>>> +	return 0;
>> 
>> I believe this should return "1" signalling that the cmdline was handled
>> correctly to avoid an "Unknown kernel command line parameters" message.
>
> Good catch. I agree.
> Thanks.

It seems I can't get that right ever ....
Re: [patch 03/12] rseq: Provide static branch for time slice extensions
Posted by Randy Dunlap 9 hours ago

On 9/9/25 5:12 AM, Thomas Gleixner wrote:
> On Mon, Sep 08 2025 at 21:11, Randy Dunlap wrote:
>> On 9/8/25 8:10 PM, K Prateek Nayak wrote:
>>> Hello Thomas,
>>>
>>> On 9/9/2025 4:29 AM, Thomas Gleixner wrote:
>>>> +#ifdef CONFIG_RSEQ_SLICE_EXTENSION
>>>> +DEFINE_STATIC_KEY_TRUE(rseq_slice_extension_key);
>>>> +
>>>> +static int __init rseq_slice_cmdline(char *str)
>>>> +{
>>>> +	bool on;
>>>> +
>>>> +	if (kstrtobool(str, &on))
>>>> +		return -EINVAL;
>>>> +
>>>> +	if (!on)
>>>> +		static_branch_disable(&rseq_slice_extension_key);
>>>> +	return 0;
>>>
>>> I believe this should return "1" signalling that the cmdline was handled
>>> correctly to avoid an "Unknown kernel command line parameters" message.
>>
>> Good catch. I agree.
>> Thanks.
> 
> It seems I can't get that right ever ....

Yeah, it's bass-ackwards.

I guess that's partly why we have early_param() and friends.

-- 
~Randy