mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ARM: enable PREEMPT_LAZY
@ 2026-11-17  8:21 Linus Walleij
  0 siblings, 0 replies; only message in thread
From: Linus Walleij @ 2026-11-17  8:21 UTC (permalink / raw)
  To: Russell King, Mark Rutland, Arnd Bergmann
  Cc: linux-arm-kernel, linux-kernel, Linus Walleij

Add lazy preemption support following commit c8597e2dd8b6 ("arm64:
enable PREEMPT_LAZY"). Define TIF_NEED_RESCHED_LAZY in the low flag
bits inspected by the assembly return-to-user paths, include it in
_TIF_WORK_MASK, and handle it in do_work_pending() by calling schedule().

Keep kernel-mode IRQ return preemption restricted to TIF_NEED_RESCHED,
so lazy requests can defer preemption until return to userspace or
escalation by the scheduler tick.

Signed-off-by: Linus Walleij <linusw@kernel.org>
---
Tested with Debian armhf on QEMU virt with four Cortex-A15 CPUs, in
both lazy and full modes: 45 futex, 21 POSIX timer and 12 nanosleep
checks passed, along with CPU/syscall, affinity and signal stress.
A temporary test module verified scheduling on lazy-only syscall
return requests. Single-CPU lazy-mode boot and stress also passed.
ARMv5 and Thumb-2 static-lazy return-path build checks passed.

Assisted by an LLM.
---
 arch/arm/Kconfig                   | 1 +
 arch/arm/include/asm/thread_info.h | 6 ++++--
 arch/arm/kernel/signal.c           | 2 +-
 3 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
index 0cc289a7184a..9f5e346249a1 100644
--- a/arch/arm/Kconfig
+++ b/arch/arm/Kconfig
@@ -21,6 +21,7 @@ config ARM
 	select ARCH_HAS_KCOV
 	select ARCH_HAS_MEMBARRIER_SYNC_CORE
 	select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE
+	select ARCH_HAS_PREEMPT_LAZY
 	select ARCH_HAS_PTE_SPECIAL if ARM_LPAE
 	select ARCH_HAS_SETUP_DMA_OPS
 	select ARCH_HAS_SET_MEMORY
diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
index 943ffcf069d2..8bc647b8e079 100644
--- a/arch/arm/include/asm/thread_info.h
+++ b/arch/arm/include/asm/thread_info.h
@@ -144,6 +144,7 @@ extern int vfp_restore_user_hwstate(struct user_vfp *,
 #define TIF_NOTIFY_RESUME	2	/* callback before returning to user */
 #define TIF_UPROBE		3	/* breakpointed or singlestepping */
 #define TIF_NOTIFY_SIGNAL	4	/* signal notifications exist */
+#define TIF_NEED_RESCHED_LAZY	5	/* lazy rescheduling needed */
 
 #define TIF_USING_IWMMXT	17
 #define TIF_MEMDIE		18	/* is terminating due to OOM killer */
@@ -156,6 +157,7 @@ extern int vfp_restore_user_hwstate(struct user_vfp *,
 
 #define _TIF_SIGPENDING		(1 << TIF_SIGPENDING)
 #define _TIF_NEED_RESCHED	(1 << TIF_NEED_RESCHED)
+#define _TIF_NEED_RESCHED_LAZY	(1 << TIF_NEED_RESCHED_LAZY)
 #define _TIF_NOTIFY_RESUME	(1 << TIF_NOTIFY_RESUME)
 #define _TIF_UPROBE		(1 << TIF_UPROBE)
 #define _TIF_SYSCALL_TRACE	(1 << TIF_SYSCALL_TRACE)
@@ -172,9 +174,9 @@ extern int vfp_restore_user_hwstate(struct user_vfp *,
 /*
  * Change these and you break ASM code in entry-common.S
  */
-#define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_SIGPENDING | \
+#define _TIF_WORK_MASK		(_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY | \
 				 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
-				 _TIF_NOTIFY_SIGNAL)
+				 _TIF_NOTIFY_SIGNAL | _TIF_SIGPENDING)
 
 #endif /* __KERNEL__ */
 #endif /* __ASM_ARM_THREAD_INFO_H */
diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
index 763e1930a1ea..efc8b8c2dc67 100644
--- a/arch/arm/kernel/signal.c
+++ b/arch/arm/kernel/signal.c
@@ -619,7 +619,7 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
 	 */
 	trace_hardirqs_off();
 	do {
-		if (likely(thread_flags & _TIF_NEED_RESCHED)) {
+		if (likely(thread_flags & (_TIF_NEED_RESCHED | _TIF_NEED_RESCHED_LAZY))) {
 			schedule();
 		} else {
 			if (unlikely(!user_mode(regs)))

---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261117-arm-lazy-preempt-05f9c4c81d6b

Best regards,
--  
Linus Walleij <linusw@kernel.org>


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-11-17  8:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17  8:21 [PATCH] ARM: enable PREEMPT_LAZY Linus Walleij

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®