mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "tip-bot2 for Shawn Shao" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: Shawn Shao <shawnq1@163.com>, Thomas Gleixner <tglx@kernel.org>,
	stable@vger.kernel.org, x86@kernel.org,
	linux-kernel@vger.kernel.org
Subject: [tip: core/rseq] rseq: Clear stale yield state on slice grant
Date: Sat, 05 Dec 2026 20:00:57 -0000	[thread overview]
Message-ID: <179650085779.2286038.6112818634188473947.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20261205033944.2871328-1-shawnq1@163.com>

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@163.com>
AuthorDate:    Sat, 05 Dec 2026 03:39:44 
Committer:     Thomas Gleixner <tglx@kernel.org>
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@163.com>
Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Cc: stable@vger.kernel.org
Link: https://gist.github.com/shaos26/525e502547c0fd673e93067aed7f6d88
Link: https://patch.msgid.link/20261205033944.2871328-1-shawnq1@163.com
---
 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();
 	/*

      reply	other threads:[~2026-12-05 20:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  8:50 [PATCH] rseq: Clear yield state when syscall entry aborts Shawn Shao
2026-12-04 13:10 ` Thomas Gleixner
2026-12-05  3:39   ` [PATCH v2] rseq: Clear stale yield state on slice grant Shawn Shao
2026-12-05 20:00     ` tip-bot2 for Shawn Shao [this message]

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=179650085779.2286038.6112818634188473947.tip-bot2@tip-bot2 \
    --to=tip-bot2@linutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-tip-commits@vger.kernel.org \
    --cc=shawnq1@163.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®