[tip: core/rseq] rseq: Clear stale yield state on slice grant
From: tip-bot2 for Shawn Shao
Date: Sat Dec 05 2026 - 15:01:06 EST
The following commit has been merged into the core/rseq branch of tip:
Commit-ID: 6602eb187c8c083a170b89dab9e7abe509d598bf
Gitweb: https://git.kernel.org/tip/6602eb187c8c083a170b89dab9e7abe509d598bf
Author: Shawn Shao <shawnq1@xxxxxxx>
AuthorDate: Sat, 05 Dec 2026 03:39:44
Committer: Thomas Gleixner <tglx@xxxxxxxxxx>
CommitterDate: Sat, 05 Dec 2026 20:57:41 +01:00
rseq: Clear stale yield state on slice grant
rseq_syscall_enter_work() sets the yield result of a rseq_slice_yield()
syscall before ptrace or seccomp decides whether to dispatch the
syscall. If entry processing aborts the call or changes the syscall number,
the syscall body does not consume the result.
Due to the stale result a subsequent rseq_slice_yield() will return
'yielded == true' unconditionally. That's wrong as the subsequent
rseq_slice_yield() invocation is related to a subsequent time slice
request.
There is no point to handle this situation in the entry code after
rseq_syscall_enter_work() because the aborted syscall leaves the critical
section scope.
Fix this by clearing a potentially stale result when the next time slice is
granted.
Also clarify the undocumented validity of the rseq_slice_yield() return
value:
The return value is only valid when rseq_slice_yield() follows a grant
observed by user space at the end of the corresponding critical
section. Any invocation outside of that condition and scope returns a
undefined value.
[ tglx: Massage change log ]
Fixes: dd0a04606937 ("rseq: Implement syscall entry work for time slice extensions")
Signed-off-by: Shawn Shao <shawnq1@xxxxxxx>
Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
Cc: stable@xxxxxxxxxxxxxxx
Link: https://gist.github.com/shaos26/525e502547c0fd673e93067aed7f6d88
Link: https://patch.msgid.link/20261205033944.2871328-1-shawnq1@xxxxxxx
---
Documentation/userspace-api/rseq.rst | 6 ++++++
include/linux/rseq_entry.h | 2 ++
2 files changed, 8 insertions(+)
diff --git a/Documentation/userspace-api/rseq.rst b/Documentation/userspace-api/rseq.rst
index 8549a6c..42b6e3a 100644
--- a/Documentation/userspace-api/rseq.rst
+++ b/Documentation/userspace-api/rseq.rst
@@ -191,6 +191,12 @@ leaving the critical section to relinquish the CPU. The kernel enforces
this by arming a timer to prevent misbehaving userspace from abusing this
mechanism.
+The return value from ``rseq_slice_yield(2)`` is only valid when the
+syscall follows userspace observing the granted bit set at the end of the
+corresponding critical section. A call outside this sequence is invalid;
+its return value is undefined and must not be used to determine the result
+of an earlier or unrelated time slice extension request.
+
If both the request bit and the granted bit are false when leaving the
critical section, then this indicates that a grant was revoked and no
further action is required by userspace.
diff --git a/include/linux/rseq_entry.h b/include/linux/rseq_entry.h
index 31ce349..7806fd8 100644
--- a/include/linux/rseq_entry.h
+++ b/include/linux/rseq_entry.h
@@ -174,6 +174,8 @@ static __always_inline bool __rseq_grant_slice_extension(bool work_pending)
rseq_stat_inc(rseq_stats.s_granted);
curr->rseq.slice.state.granted = true;
+ /* Clear stale state left by an aborted rseq_slice_yield() syscall. */
+ curr->rseq.slice.yielded = false;
/* Store expiry time for arming the timer on the way out */
curr->rseq.slice.expires = data_race(rseq_slice_ext_nsecs) + ktime_get_mono_fast_ns();
/*