Re: [PATCH 1/7] powerpc/entry: convert to common and generic entry

From: Christophe Leroy
Date: Tue Oct 15 2024 - 13:44:13 EST




Le 12/10/2024 à 05:56, Luming Yu a écrit :
convert powerpc entry code in syscall and fault to use syscall_work
and irqentry_state as well as common calls implemented in generic
entry infrastructure.

Signed-off-by: Luming Yu <luming.yu@xxxxxxxxxxxx>
---
arch/powerpc/Kconfig | 1 +
arch/powerpc/include/asm/hw_irq.h | 5 +++++
arch/powerpc/include/asm/processor.h | 6 ++++++
arch/powerpc/include/asm/syscall.h | 5 +++++
arch/powerpc/include/asm/thread_info.h | 1 +
arch/powerpc/kernel/syscall.c | 5 ++++-
arch/powerpc/mm/fault.c | 3 +++
7 files changed, 25 insertions(+), 1 deletion(-)


...

diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c
index 77fedb190c93..e0338bd8d383 100644
--- a/arch/powerpc/kernel/syscall.c
+++ b/arch/powerpc/kernel/syscall.c
@@ -3,6 +3,7 @@
#include <linux/compat.h>
#include <linux/context_tracking.h>
#include <linux/randomize_kstack.h>
+#include <linux/entry-common.h>
#include <asm/interrupt.h>
#include <asm/kup.h>
@@ -131,7 +132,7 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
* and the test against NR_syscalls will fail and the return
* value to be used is in regs->gpr[3].
*/
- r0 = do_syscall_trace_enter(regs);
+ r0 = syscall_enter_from_user_mode(regs, r0);

Can you provide details on how this works ?

For instance, do_syscall_trace_enter() was calling do_seccomp().
do_seccomp() sets regs->r3 to -ENOSYS then calls __secure_computing().

Now you call syscall_enter_from_user_mode() instead which calls syscall_enter_from_user_mode_work() which calls syscall_trace_enter() which calls __secure_computing() but without seting regs->r3 to -ENOSYS.

So what will be returned by the below return when syscall_enter_from_user_mode returns -1 ?

if (unlikely(r0 >= NR_syscalls))
return regs->gpr[3];
@@ -184,6 +185,8 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0)
* So the resulting 6 or 7 bits of entropy is seen in SP[9:4] or SP[9:3].
*/
choose_random_kstack_offset(mftb());
+ /*common entry*/
+ syscall_exit_to_user_mode(regs);
return ret;
}