From: Linus Walleij <linus.walleij@linaro.org>
To: Dmitry Vyukov <dvyukov@google.com>,
Oleg Nesterov <oleg@redhat.com>,
Russell King <linux@armlinux.org.uk>,
Kees Cook <kees@kernel.org>,
Andy Lutomirski <luto@amacapital.net>,
Will Drewry <wad@chromium.org>,
Frederic Weisbecker <frederic@kernel.org>,
"Paul E. McKenney" <paulmck@kernel.org>,
Jinjie Ruan <ruanjinjie@huawei.com>,
Arnd Bergmann <arnd@arndb.de>, Ard Biesheuvel <ardb@kernel.org>,
Al Viro <viro@zeniv.linux.org.uk>
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
Linus Walleij <linus.walleij@linaro.org>
Subject: [PATCH RFC v3 15/30] ARM: entry: Separate call path for syscall SWI entry
Date: Tue, 07 Jan 2025 10:41:31 +0100 [thread overview]
Message-ID: <20250107-arm-generic-entry-v3-15-4e5f3c15db2d@linaro.org> (raw)
In-Reply-To: <20250107-arm-generic-entry-v3-0-4e5f3c15db2d@linaro.org>
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@linaro.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 e26f369375ca3cf762f92fb499657a666b223ca2..e259b074caef75c7f777b18199623f07bebee5b4 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 c71110126fc105fc6ac2d6cb0f5f399b4c8b1548..6edf362ab1e1035dafebf6fb7c55db71462c1eae 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -403,14 +403,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
@@ -430,7 +422,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
@@ -441,7 +433,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
@@ -455,7 +447,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
@@ -480,7 +472,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 ff1dd3169346f3770cad6b7e218f5d74ffc646fe..14b2495cae3c2f95b0dfecd849b4e16ec143dbe9 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 8b2e8ea66c1376759d6c0c14aad8728895b3ff1e..1973947c7ad753fccd694b3ef334fba1326f58b6 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.47.1
next prev parent reply other threads:[~2025-01-07 9:41 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-07 9:41 [PATCH RFC v3 00/30] ARM: Switch to generic entry Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 01/30] ARM: Prepare includes for " Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 02/30] ARM: ptrace: Split report_syscall() Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 03/30] ARM: entry: Skip ret_slow_syscall label Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 04/30] ARM: process: Rewrite ret_from_fork i C Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 05/30] ARM: process: Remove local restart Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 06/30] ARM: entry: Invoke syscalls using C Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 07/30] ARM: entry: Rewrite two asm calls in C Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 08/30] ARM: entry: Move trace entry to C function Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 09/30] ARM: entry: save the syscall sp in thread_info Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 10/30] ARM: entry: move all tracing invocation to C Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 11/30] ARM: entry: Merge the common and trace entry code Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 12/30] ARM: entry: Rename syscall invocation Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 13/30] ARM: entry: Create user_mode_enter/exit Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 14/30] ARM: entry: Drop trace argument from usr_entry macro Linus Walleij
2025-01-07 9:41 ` Linus Walleij [this message]
2025-01-07 9:41 ` [PATCH RFC v3 16/30] ARM: entry: Drop argument to asm_irqentry macros Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 17/30] ARM: entry: Implement syscall_exit_to_user_mode() Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 18/30] ARM: entry: Drop the superfast ret_fast_syscall Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 19/30] ARM: entry: Remove fast and offset register restore Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 20/30] ARM: entry: Untangle ret_fast_syscall/to_user Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 21/30] ARM: entry: Do not double-call exit functions Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 22/30] ARM: entry: Move work processing to C Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 23/30] ARM: entry: Stop exiting syscalls like IRQs Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 24/30] ARM: entry: Complete syscall and IRQ transition to C Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 25/30] ARM: entry: Create irqentry calls from kernel mode Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 26/30] ARM: entry: Move in-kernel hardirq tracing to C Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 27/30] ARM: irq: Add irqstack helpers Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 28/30] ARM: entry: Convert to generic entry Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 29/30] ARM: entry: Handle prefetch and data aborts as interrupts Linus Walleij
2025-01-07 9:41 ` [PATCH RFC v3 30/30] RFC: ARM: entry: Block IRQs in early IRQ context Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250107-arm-generic-entry-v3-15-4e5f3c15db2d@linaro.org \
--to=linus.walleij@linaro.org \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=dvyukov@google.com \
--cc=frederic@kernel.org \
--cc=kees@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=luto@amacapital.net \
--cc=oleg@redhat.com \
--cc=paulmck@kernel.org \
--cc=ruanjinjie@huawei.com \
--cc=viro@zeniv.linux.org.uk \
--cc=wad@chromium.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®