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: Record interrupt from user space

For RSEQ the only relevant reason to inspect and eventually fixup (abort)
user space critical sections is when user space was interrupted and the
task was scheduled out.

If the user to kernel entry was from a syscall no fixup is required. If
user space invokes a syscall from a critical section it can keep the
pieces as documented.

This is only supported on architectures which utilize the generic entry
code. If your architecture does not use it, bad luck.

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/20251027084306.905067101@linutronix.de

authored by

Thomas Gleixner and committed by
Ingo Molnar
2fc0e4b4 4b7de6df

+33 -6
+2 -1
include/linux/irq-entry-common.h
··· 4 4 5 5 #include <linux/context_tracking.h> 6 6 #include <linux/kmsan.h> 7 - #include <linux/rseq.h> 7 + #include <linux/rseq_entry.h> 8 8 #include <linux/static_call_types.h> 9 9 #include <linux/syscalls.h> 10 10 #include <linux/tick.h> ··· 281 281 static __always_inline void irqentry_enter_from_user_mode(struct pt_regs *regs) 282 282 { 283 283 enter_from_user_mode(regs); 284 + rseq_note_user_irq_entry(); 284 285 } 285 286 286 287 /**
+11 -5
include/linux/rseq.h
··· 31 31 32 32 static __always_inline void rseq_exit_to_user_mode(void) 33 33 { 34 - if (IS_ENABLED(CONFIG_DEBUG_RSEQ)) { 35 - if (WARN_ON_ONCE(current->rseq.event.has_rseq && 36 - current->rseq.event.events)) 37 - current->rseq.event.events = 0; 38 - } 34 + struct rseq_event *ev = &current->rseq.event; 35 + 36 + if (IS_ENABLED(CONFIG_DEBUG_RSEQ)) 37 + WARN_ON_ONCE(ev->sched_switch); 38 + 39 + /* 40 + * Ensure that event (especially user_irq) is cleared when the 41 + * interrupt did not result in a schedule and therefore the 42 + * rseq processing did not clear it. 43 + */ 44 + ev->events = 0; 39 45 } 40 46 41 47 /*
+18
include/linux/rseq_entry.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + #ifndef _LINUX_RSEQ_ENTRY_H 3 + #define _LINUX_RSEQ_ENTRY_H 4 + 5 + #ifdef CONFIG_RSEQ 6 + #include <linux/rseq.h> 7 + 8 + static __always_inline void rseq_note_user_irq_entry(void) 9 + { 10 + if (IS_ENABLED(CONFIG_GENERIC_IRQ_ENTRY)) 11 + current->rseq.event.user_irq = true; 12 + } 13 + 14 + #else /* CONFIG_RSEQ */ 15 + static inline void rseq_note_user_irq_entry(void) { } 16 + #endif /* !CONFIG_RSEQ */ 17 + 18 + #endif /* _LINUX_RSEQ_ENTRY_H */
+2
include/linux/rseq_types.h
··· 12 12 * @all: Compound to initialize and clear the data efficiently 13 13 * @events: Compound to access events with a single load/store 14 14 * @sched_switch: True if the task was scheduled out 15 + * @user_irq: True on interrupt entry from user mode 15 16 * @has_rseq: True if the task has a rseq pointer installed 16 17 */ 17 18 struct rseq_event { ··· 23 22 u16 events; 24 23 struct { 25 24 u8 sched_switch; 25 + u8 user_irq; 26 26 }; 27 27 }; 28 28