[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20241029-arm-generic-entry-v2-15-573519abef38@linaro.org>
Date: Tue, 29 Oct 2024 11:52:55 +0100
From: Linus Walleij <linus.walleij@...aro.org>
To: Oleg Nesterov <oleg@...hat.com>, Russell King <linux@...linux.org.uk>,
Kees Cook <kees@...nel.org>, Andy Lutomirski <luto@...capital.net>,
Will Drewry <wad@...omium.org>, Frederic Weisbecker <frederic@...nel.org>,
"Paul E. McKenney" <paulmck@...nel.org>,
Jinjie Ruan <ruanjinjie@...wei.com>, Arnd Bergmann <arnd@...db.de>,
Ard Biesheuvel <ardb@...nel.org>, Al Viro <viro@...iv.linux.org.uk>
Cc: linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org,
Linus Walleij <linus.walleij@...aro.org>
Subject: [PATCH RFC v2 15/28] ARM: entry: Separate call path for syscall
SWI entry
The syscalls (SWIs, software interrupts) are deviating from how
any other interrupts are handled as they enable the IRQs again
while processing the syscall, while "hard" IRQs disable all
interrupts until they are handled.
Break out syscall_enter_from_user_mode() into its own function
and call it instead of irqentry_enter_from_user_mode().
As we are moving toward generic entry, we use the signature
from the generic function.
As the generic function requires the syscall number to be
determined, we move the call down below the code that
figures out the syscall number, the only practical effect
should be that interrupts are re-enabled a few instructions
later.
As we move the trace_hardirqs_on/off() calls into C, we can
just get rid of the helper macro usr_entry_enter again and
call asm_irqentry_enter_from_user_mode directly.
Signed-off-by: Linus Walleij <linus.walleij@...aro.org>
---
arch/arm/include/asm/entry.h | 1 +
arch/arm/kernel/entry-armv.S | 16 ++++------------
arch/arm/kernel/entry-common.S | 18 +++++++++++++-----
arch/arm/kernel/entry.c | 14 ++++++++++++++
4 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/arch/arm/include/asm/entry.h b/arch/arm/include/asm/entry.h
index e26f369375ca..e259b074caef 100644
--- a/arch/arm/include/asm/entry.h
+++ b/arch/arm/include/asm/entry.h
@@ -8,6 +8,7 @@ struct pt_regs;
* These are copies of generic entry headers so we can transition
* to generic entry once they are semantically equivalent.
*/
+long syscall_enter_from_user_mode(struct pt_regs *regs, long);
void irqentry_enter_from_user_mode(struct pt_regs *regs);
void irqentry_exit_to_user_mode(struct pt_regs *regs);
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index be2df297ec0a..0328860475e1 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -402,14 +402,6 @@ ENDPROC(__fiq_abt)
zero_fp
.endm
- /* Called after usr_entry for everything except FIQ */
- .macro usr_entry_enter
-#ifdef CONFIG_TRACE_IRQFLAGS
- bl trace_hardirqs_off
-#endif
- asm_irqentry_enter_from_user_mode save = 0
- .endm
-
.macro kuser_cmpxchg_check
#if !defined(CONFIG_CPU_32v6K) && defined(CONFIG_KUSER_HELPERS)
#ifndef CONFIG_MMU
@@ -429,7 +421,7 @@ ENDPROC(__fiq_abt)
.align 5
__dabt_usr:
usr_entry uaccess=0
- usr_entry_enter
+ asm_irqentry_enter_from_user_mode save = 0
kuser_cmpxchg_check
mov r2, sp
dabt_helper
@@ -440,7 +432,7 @@ ENDPROC(__dabt_usr)
.align 5
__irq_usr:
usr_entry
- usr_entry_enter
+ asm_irqentry_enter_from_user_mode save = 0
kuser_cmpxchg_check
irq_handler from_user=1
get_thread_info tsk
@@ -454,7 +446,7 @@ ENDPROC(__irq_usr)
.align 5
__und_usr:
usr_entry uaccess=0
- usr_entry_enter
+ asm_irqentry_enter_from_user_mode save = 0
@ IRQs must be enabled before attempting to read the instruction from
@ user space since that could cause a page/translation fault if the
@@ -479,7 +471,7 @@ ENDPROC(__und_usr)
.align 5
__pabt_usr:
usr_entry
- usr_entry_enter
+ asm_irqentry_enter_from_user_mode save = 0
mov r2, sp @ regs
pabt_helper
UNWIND(.fnend )
diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index ff1dd3169346..14b2495cae3c 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -109,8 +109,6 @@ ENTRY(ret_to_user_from_irq)
movs r1, r1, lsl #16
bne slow_work_pending
no_work_pending:
- asm_trace_hardirqs_on save = 0
-
asm_irqentry_exit_to_user_mode save = 0
#ifdef CONFIG_GCC_PLUGIN_STACKLEAK
@@ -189,9 +187,6 @@ ENTRY(vector_swi)
reload_current r10, ip
zero_fp
alignment_trap r10, ip, cr_alignment
- asm_trace_hardirqs_on save=0
- enable_irq_notrace
- asm_irqentry_enter_from_user_mode save = 0
/*
* Get the system call number.
@@ -256,6 +251,19 @@ ENTRY(vector_swi)
#else
str scno, [tsk, #TI_ABI_SYSCALL]
#endif
+
+ /*
+ * Calling out to C to be careful to save and restore registers.
+ * This call could modify the syscall number. scno is r7 so we
+ * do not save and restore r7.
+ */
+ mov r0, sp @ regs
+ mov r1, scno
+ push {r4 - r6, r8 - r10, lr}
+ bl syscall_enter_from_user_mode
+ pop {r4 - r6, r8 - r10, lr}
+ mov scno, r0
+
mov r1, sp @ put regs into r1
stmdb sp!, {r4, r5} @ push fifth and sixth args
mov r0, tbl
diff --git a/arch/arm/kernel/entry.c b/arch/arm/kernel/entry.c
index 8b2e8ea66c13..1973947c7ad7 100644
--- a/arch/arm/kernel/entry.c
+++ b/arch/arm/kernel/entry.c
@@ -1,15 +1,29 @@
// SPDX-License-Identifier: GPL-2.0
#include <asm/entry.h>
#include <linux/context_tracking.h>
+#include <linux/irqflags.h>
+
+long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)
+{
+ trace_hardirqs_on();
+ local_irq_enable();
+ /* This context tracking call has inverse naming */
+ user_exit_callable();
+
+ /* This will optionally be modified later */
+ return syscall;
+}
noinstr void irqentry_enter_from_user_mode(struct pt_regs *regs)
{
+ trace_hardirqs_off();
/* This context tracking call has inverse naming */
user_exit_callable();
}
noinstr void irqentry_exit_to_user_mode(struct pt_regs *regs)
{
+ trace_hardirqs_on();
/* This context tracking call has inverse naming */
user_enter_callable();
}
--
2.46.2
Powered by blists - more mailing lists