Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rseq: Separate the signal delivery path

Completely separate the signal delivery path from the notify handler as
they have different semantics versus the event handling.

The signal delivery only needs to ensure that the interrupted user context
was not in a critical section or the section is aborted before it switches
to the signal frame context. The signal frame context does not have the
original instruction pointer anymore, so that can't be handled on exit to
user space.

No point in updating the CPU/CID ids as they might change again before the
task returns to user space for real.

The fast path optimization, which checks for the 'entry from user via
interrupt' condition is only available for architectures which use the
generic entry code.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: https://patch.msgid.link/20251027084307.455429038@linutronix.de

authored by

Thomas Gleixner and committed by
Ingo Molnar
9f6ffd4c 0f085b41

+38 -13
+16 -5
include/linux/rseq.h
··· 7 7 8 8 #include <uapi/linux/rseq.h> 9 9 10 - void __rseq_handle_notify_resume(struct ksignal *sig, struct pt_regs *regs); 10 + void __rseq_handle_notify_resume(struct pt_regs *regs); 11 11 12 12 static inline void rseq_handle_notify_resume(struct pt_regs *regs) 13 13 { 14 14 if (current->rseq.event.has_rseq) 15 - __rseq_handle_notify_resume(NULL, regs); 15 + __rseq_handle_notify_resume(regs); 16 16 } 17 17 18 + void __rseq_signal_deliver(int sig, struct pt_regs *regs); 19 + 20 + /* 21 + * Invoked from signal delivery to fixup based on the register context before 22 + * switching to the signal delivery context. 23 + */ 18 24 static inline void rseq_signal_deliver(struct ksignal *ksig, struct pt_regs *regs) 19 25 { 20 - if (current->rseq.event.has_rseq) { 21 - current->rseq.event.sched_switch = true; 22 - __rseq_handle_notify_resume(ksig, regs); 26 + if (IS_ENABLED(CONFIG_GENERIC_IRQ_ENTRY)) { 27 + /* '&' is intentional to spare one conditional branch */ 28 + if (current->rseq.event.has_rseq & current->rseq.event.user_irq) 29 + __rseq_signal_deliver(ksig->sig, regs); 30 + } else { 31 + if (current->rseq.event.has_rseq) 32 + __rseq_signal_deliver(ksig->sig, regs); 23 33 } 24 34 } 25 35 36 + /* Raised from context switch and exevce to force evaluation on exit to user */ 26 37 static inline void rseq_sched_switch_event(struct task_struct *t) 27 38 { 28 39 if (t->rseq.event.has_rseq) {
+22 -8
kernel/rseq.c
··· 250 250 * respect to other threads scheduled on the same CPU, and with respect 251 251 * to signal handlers. 252 252 */ 253 - void __rseq_handle_notify_resume(struct ksignal *ksig, struct pt_regs *regs) 253 + void __rseq_handle_notify_resume(struct pt_regs *regs) 254 254 { 255 255 struct task_struct *t = current; 256 256 struct rseq_ids ids; 257 257 u32 node_id; 258 258 bool event; 259 - int sig; 260 259 261 260 /* 262 261 * If invoked from hypervisors before entering the guest via ··· 274 275 if (unlikely(t->flags & PF_EXITING)) 275 276 return; 276 277 277 - if (ksig) 278 - rseq_stat_inc(rseq_stats.signal); 279 - else 280 - rseq_stat_inc(rseq_stats.slowpath); 278 + rseq_stat_inc(rseq_stats.slowpath); 281 279 282 280 /* 283 281 * Read and clear the event pending bit first. If the task ··· 313 317 return; 314 318 315 319 error: 316 - sig = ksig ? ksig->sig : 0; 317 - force_sigsegv(sig); 320 + force_sig(SIGSEGV); 321 + } 322 + 323 + void __rseq_signal_deliver(int sig, struct pt_regs *regs) 324 + { 325 + rseq_stat_inc(rseq_stats.signal); 326 + /* 327 + * Don't update IDs, they are handled on exit to user if 328 + * necessary. The important thing is to abort a critical section of 329 + * the interrupted context as after this point the instruction 330 + * pointer in @regs points to the signal handler. 331 + */ 332 + if (unlikely(!rseq_handle_cs(current, regs))) { 333 + /* 334 + * Clear the errors just in case this might survive 335 + * magically, but leave the rest intact. 336 + */ 337 + current->rseq.event.error = 0; 338 + force_sigsegv(sig); 339 + } 318 340 } 319 341 320 342 /*