[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <176224426080.2601451.9036759120278947883.tip-bot2@tip-bot2>
Date: Tue, 04 Nov 2025 08:17:40 -0000
From: "tip-bot2 for Thomas Gleixner" <tip-bot2@...utronix.de>
To: linux-tip-commits@...r.kernel.org
Cc: Thomas Gleixner <tglx@...utronix.de>,
"Peter Zijlstra (Intel)" <peterz@...radead.org>,
Ingo Molnar <mingo@...nel.org>,
Mathieu Desnoyers <mathieu.desnoyers@...icios.com>, x86@...nel.org,
linux-kernel@...r.kernel.org
Subject: [tip: core/rseq] rseq: Move algorithm comment to top
The following commit has been merged into the core/rseq branch of tip:
Commit-ID: 77f19e4d4fc90a9364f5055a4daf8b98a76cb303
Gitweb: https://git.kernel.org/tip/77f19e4d4fc90a9364f5055a4daf8b98a76cb303
Author: Thomas Gleixner <tglx@...utronix.de>
AuthorDate: Mon, 27 Oct 2025 09:44:20 +01:00
Committer: Ingo Molnar <mingo@...nel.org>
CommitterDate: Tue, 04 Nov 2025 08:29:52 +01:00
rseq: Move algorithm comment to top
Move the comment which documents the RSEQ algorithm to the top of the file,
so it does not create horrible diffs later when the actual implementation
is fed into the mincer.
Signed-off-by: Thomas Gleixner <tglx@...utronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@...radead.org>
Signed-off-by: Ingo Molnar <mingo@...nel.org>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
Link: https://patch.msgid.link/20251027084306.149519580@linutronix.de
---
kernel/rseq.c | 119 ++++++++++++++++++++++++-------------------------
1 file changed, 59 insertions(+), 60 deletions(-)
diff --git a/kernel/rseq.c b/kernel/rseq.c
index 246319d..51fafc4 100644
--- a/kernel/rseq.c
+++ b/kernel/rseq.c
@@ -8,6 +8,65 @@
* Mathieu Desnoyers <mathieu.desnoyers@...icios.com>
*/
+/*
+ * Restartable sequences are a lightweight interface that allows
+ * user-level code to be executed atomically relative to scheduler
+ * preemption and signal delivery. Typically used for implementing
+ * per-cpu operations.
+ *
+ * It allows user-space to perform update operations on per-cpu data
+ * without requiring heavy-weight atomic operations.
+ *
+ * Detailed algorithm of rseq user-space assembly sequences:
+ *
+ * init(rseq_cs)
+ * cpu = TLS->rseq::cpu_id_start
+ * [1] TLS->rseq::rseq_cs = rseq_cs
+ * [start_ip] ----------------------------
+ * [2] if (cpu != TLS->rseq::cpu_id)
+ * goto abort_ip;
+ * [3] <last_instruction_in_cs>
+ * [post_commit_ip] ----------------------------
+ *
+ * The address of jump target abort_ip must be outside the critical
+ * region, i.e.:
+ *
+ * [abort_ip] < [start_ip] || [abort_ip] >= [post_commit_ip]
+ *
+ * Steps [2]-[3] (inclusive) need to be a sequence of instructions in
+ * userspace that can handle being interrupted between any of those
+ * instructions, and then resumed to the abort_ip.
+ *
+ * 1. Userspace stores the address of the struct rseq_cs assembly
+ * block descriptor into the rseq_cs field of the registered
+ * struct rseq TLS area. This update is performed through a single
+ * store within the inline assembly instruction sequence.
+ * [start_ip]
+ *
+ * 2. Userspace tests to check whether the current cpu_id field match
+ * the cpu number loaded before start_ip, branching to abort_ip
+ * in case of a mismatch.
+ *
+ * If the sequence is preempted or interrupted by a signal
+ * at or after start_ip and before post_commit_ip, then the kernel
+ * clears TLS->__rseq_abi::rseq_cs, and sets the user-space return
+ * ip to abort_ip before returning to user-space, so the preempted
+ * execution resumes at abort_ip.
+ *
+ * 3. Userspace critical section final instruction before
+ * post_commit_ip is the commit. The critical section is
+ * self-terminating.
+ * [post_commit_ip]
+ *
+ * 4. <success>
+ *
+ * On failure at [2], or if interrupted by preempt or signal delivery
+ * between [1] and [3]:
+ *
+ * [abort_ip]
+ * F1. <failure>
+ */
+
#include <linux/sched.h>
#include <linux/uaccess.h>
#include <linux/syscalls.h>
@@ -98,66 +157,6 @@ static int rseq_validate_ro_fields(struct task_struct *t)
unsafe_put_user(value, &t->rseq->field, error_label)
#endif
-/*
- *
- * Restartable sequences are a lightweight interface that allows
- * user-level code to be executed atomically relative to scheduler
- * preemption and signal delivery. Typically used for implementing
- * per-cpu operations.
- *
- * It allows user-space to perform update operations on per-cpu data
- * without requiring heavy-weight atomic operations.
- *
- * Detailed algorithm of rseq user-space assembly sequences:
- *
- * init(rseq_cs)
- * cpu = TLS->rseq::cpu_id_start
- * [1] TLS->rseq::rseq_cs = rseq_cs
- * [start_ip] ----------------------------
- * [2] if (cpu != TLS->rseq::cpu_id)
- * goto abort_ip;
- * [3] <last_instruction_in_cs>
- * [post_commit_ip] ----------------------------
- *
- * The address of jump target abort_ip must be outside the critical
- * region, i.e.:
- *
- * [abort_ip] < [start_ip] || [abort_ip] >= [post_commit_ip]
- *
- * Steps [2]-[3] (inclusive) need to be a sequence of instructions in
- * userspace that can handle being interrupted between any of those
- * instructions, and then resumed to the abort_ip.
- *
- * 1. Userspace stores the address of the struct rseq_cs assembly
- * block descriptor into the rseq_cs field of the registered
- * struct rseq TLS area. This update is performed through a single
- * store within the inline assembly instruction sequence.
- * [start_ip]
- *
- * 2. Userspace tests to check whether the current cpu_id field match
- * the cpu number loaded before start_ip, branching to abort_ip
- * in case of a mismatch.
- *
- * If the sequence is preempted or interrupted by a signal
- * at or after start_ip and before post_commit_ip, then the kernel
- * clears TLS->__rseq_abi::rseq_cs, and sets the user-space return
- * ip to abort_ip before returning to user-space, so the preempted
- * execution resumes at abort_ip.
- *
- * 3. Userspace critical section final instruction before
- * post_commit_ip is the commit. The critical section is
- * self-terminating.
- * [post_commit_ip]
- *
- * 4. <success>
- *
- * On failure at [2], or if interrupted by preempt or signal delivery
- * between [1] and [3]:
- *
- * [abort_ip]
- * F1. <failure>
- */
-
static int rseq_update_cpu_node_id(struct task_struct *t)
{
struct rseq __user *rseq = t->rseq;
Powered by blists - more mailing lists