Skip to contentSkip to conversation

powerpc/64: system call implement the bulk of the logic in C

PATCH Superseded Nicholas Piggin 2 participants 3 messages Sep 2, 2019 – Sep 5, 2019

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

PATCH v2 1/1 powerpc/64: system call implement the bulk of the logic in C

System call entry and particularly exit code is beyond the limit of what is reasonable to implement in asm.

This conversion moves all conditional branches out of the asm code, except for the case that all GPRs should be restored at exit.

Null syscall test is about 5% faster after this patch, because the exit work is handled under local_irq_disable, and the hard mask and pending interrupt replay is handled after that, which avoids games with MSR.

---
Since v1:
- Fix big endian build (mpe)
- Fix order of exit tracing to after the result registers have been set.
- Move ->softe store before MSR[EE] is set, fix the now obsolete comment.
- More #ifdef tidyups and writing the accounting helpers nicer (Christophe)
- Minor things like move the TM debug store into C

 arch/powerpc/include/asm/asm-prototypes.h     |  11 -
 .../powerpc/include/asm/book3s/64/kup-radix.h |  10 +-
 arch/powerpc/include/asm/cputime.h            |  24 ++
 arch/powerpc/include/asm/ptrace.h             |   3 +
 arch/powerpc/include/asm/signal.h             |   3 +
 arch/powerpc/include/asm/switch_to.h          |   5 +
 arch/powerpc/include/asm/time.h               |   3 +
 arch/powerpc/kernel/Makefile                  |   3 +-
 arch/powerpc/kernel/entry_64.S                | 337 +++---------------
 arch/powerpc/kernel/signal.h                  |   2 -
 arch/powerpc/kernel/syscall_64.c              | 183 ++++++++++
 11 files changed, 277 insertions(+), 307 deletions(-)
 create mode 100644 arch/powerpc/kernel/syscall_64.c
arch/powerpc/include/asm/asm-prototypes.h +0 -11
index ec1c97a8e8cb..f00ef8924a99 100644
@@ -92,14 +92,6 @@ long sys_switch_endian(void);
 notrace unsigned int __check_irq_replay(void);
 void notrace restore_interrupts(void);
 
-/* ptrace */
-long do_syscall_trace_enter(struct pt_regs *regs);
-void do_syscall_trace_leave(struct pt_regs *regs);
-
-/* process */
-void restore_math(struct pt_regs *regs);
-void restore_tm_state(struct pt_regs *regs);
-
 /* prom_init (OpenFirmware) */
 unsigned long __init prom_init(unsigned long r3, unsigned long r4,
 			       unsigned long pp,
@@ -110,9 +102,6 @@ unsigned long __init prom_init(unsigned long r3, unsigned long r4,
 void __init early_setup(unsigned long dt_ptr);
 void early_setup_secondary(void);
 
-/* time */
-void accumulate_stolen_time(void);
-
 /* misc runtime */
 extern u64 __bswapdi2(u64);
 extern s64 __lshrdi3(s64, int);
arch/powerpc/include/asm/book3s/64/kup-radix.h +9 -1
index f254de956d6a..83f6bda0542b 100644
@@ -3,6 +3,7 @@
 #define _ASM_POWERPC_BOOK3S_64_KUP_RADIX_H
 
 #include <linux/const.h>
+#include <asm/reg.h>
 
 #define AMR_KUAP_BLOCK_READ	UL(0x4000000000000000)
 #define AMR_KUAP_BLOCK_WRITE	UL(0x8000000000000000)
@@ -56,7 +57,14 @@
 
 #ifdef CONFIG_PPC_KUAP
 
-#include <asm/reg.h>
+#include <asm/mmu.h>
+#include <asm/ptrace.h>
+
+static inline void kuap_check_amr(void)
+{
+	if (IS_ENABLED(CONFIG_PPC_KUAP_DEBUG) && mmu_has_feature(MMU_FTR_RADIX_KUAP))
+		WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED);
+}
 
 /*
  * We support individually allowing read or write, but we don't support nesting
arch/powerpc/include/asm/cputime.h +24 -0
index 2431b4ada2fa..c43614cffaac 100644
@@ -60,6 +60,30 @@ static inline void arch_vtime_task_switch(struct task_struct *prev)
 }
 #endif
 
+static inline void account_cpu_user_entry(void)
+{
+	unsigned long tb = mftb();
+	struct cpu_accounting_data *acct = get_accounting(current);
+
+	acct->utime += (tb - acct->starttime_user);
+	acct->starttime = tb;
+}
+static inline void account_cpu_user_exit(void)
+{
+	unsigned long tb = mftb();
+	struct cpu_accounting_data *acct = get_accounting(current);
+
+	acct->stime += (tb - acct->starttime);
+	acct->starttime_user = tb;
+}
+
 #endif /* __KERNEL__ */
+#else /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
+static inline void account_cpu_user_entry(void)
+{
+}
+static inline void account_cpu_user_exit(void)
+{
+}
 #endif /* CONFIG_VIRT_CPU_ACCOUNTING_NATIVE */
 #endif /* __POWERPC_CPUTIME_H */
arch/powerpc/include/asm/ptrace.h +3 -0
index feee1b21bbd5..af363086403a 100644
@@ -138,6 +138,9 @@ extern unsigned long profile_pc(struct pt_regs *regs);
 #define profile_pc(regs) instruction_pointer(regs)
 #endif
 
+long do_syscall_trace_enter(struct pt_regs *regs);
+void do_syscall_trace_leave(struct pt_regs *regs);
+
 #define kernel_stack_pointer(regs) ((regs)->gpr[1])
 static inline int is_syscall_success(struct pt_regs *regs)
 {
arch/powerpc/include/asm/signal.h +3 -0
index 0803ca8b9149..99e1c6de27bc 100644
@@ -6,4 +6,7 @@
 #include <uapi/asm/signal.h>
 #include <uapi/asm/ptrace.h>
 
+struct pt_regs;
+void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags);
+
 #endif /* _ASM_POWERPC_SIGNAL_H */
arch/powerpc/include/asm/switch_to.h +5 -0
index 5b03d8a82409..476008bc3d08 100644
@@ -5,6 +5,7 @@
 #ifndef _ASM_POWERPC_SWITCH_TO_H
 #define _ASM_POWERPC_SWITCH_TO_H
 
+#include <linux/sched.h>
 #include <asm/reg.h>
 
 struct thread_struct;
@@ -22,6 +23,10 @@ extern void switch_booke_debug_regs(struct debug_reg *new_debug);
 
 extern int emulate_altivec(struct pt_regs *);
 
+void restore_math(struct pt_regs *regs);
+
+void restore_tm_state(struct pt_regs *regs);
+
 extern void flush_all_to_thread(struct task_struct *);
 extern void giveup_all(struct task_struct *);
 
arch/powerpc/include/asm/time.h +3 -0
index 54f4ec1f9fab..ba97858c9d76 100644
@@ -199,5 +199,8 @@ DECLARE_PER_CPU(u64, decrementers_next_tb);
 /* Convert timebase ticks to nanoseconds */
 unsigned long long tb_to_ns(unsigned long long tb_ticks);
 
+/* SPLPAR */
+void accumulate_stolen_time(void);
+
 #endif /* __KERNEL__ */
 #endif /* __POWERPC_TIME_H */
arch/powerpc/kernel/Makefile +2 -1
index 56dfa7a2a6f2..7f53cc07f933 100644
@@ -52,7 +52,8 @@ obj-y				:= cputable.o ptrace.o syscalls.o \
 				   of_platform.o prom_parse.o
 obj-$(CONFIG_PPC64)		+= setup_64.o sys_ppc32.o \
 				   signal_64.o ptrace32.o \
-				   paca.o nvram_64.o firmware.o
+				   paca.o nvram_64.o firmware.o \
+				   syscall_64.o
 obj-$(CONFIG_VDSO32)		+= vdso32/
 obj-$(CONFIG_PPC_WATCHDOG)	+= watchdog.o
 obj-$(CONFIG_HAVE_HW_BREAKPOINT)	+= hw_breakpoint.o
arch/powerpc/kernel/entry_64.S +45 -292

415 lines not on this page · raw message

arch/powerpc/kernel/signal.h +0 -2
index 800433685888..d396efca4068 100644
@@ -10,8 +10,6 @@
 #ifndef _POWERPC_ARCH_SIGNAL_H
 #define _POWERPC_ARCH_SIGNAL_H
 
-extern void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags);
-
 extern void __user *get_sigframe(struct ksignal *ksig, unsigned long sp,
 				  size_t frame_size, int is_32);
 
arch/powerpc/kernel/syscall_64.c new file +183 -0

183 lines not on this page · raw message

Signature · 1 line
2.22.0
#1 lore raw
Quoted 10 lines · Nicholas Piggin

System call entry and particularly exit code is beyond the limit of what is reasonable to implement in asm.

This conversion moves all conditional branches out of the asm code, except for the case that all GPRs should be restored at exit.

Null syscall test is about 5% faster after this patch, because the exit work is handled under local_irq_disable, and the hard mask and pending interrupt replay is handled after that, which avoids games with MSR.

Quoted 8 lines

---
Since v1:
- Fix big endian build (mpe)
- Fix order of exit tracing to after the result registers have been set.
- Move ->softe store before MSR[EE] is set, fix the now obsolete comment.
- More #ifdef tidyups and writing the accounting helpers nicer (Christophe)
- Minor things like move the TM debug store into C

This doesn't build in a few configs.

It needed:

+#else
+static inline void kuap_check_amr(void) { }

In kup-radix.h to fix the KUAP=n build.

It still fails to build on ppc64e with:

arch/powerpc/kernel/syscall_64.c:161:2: error: implicit declaration of function '__mtmsrd' [-Werror=implicit-function-declaration]

http://kisskb.ellerman.id.au/kisskb/buildresult/13946972/

Which I haven't debugged yet.

cheers

author reviewer
#2 lore raw

Michael Ellerman's on September 5, 2019 2:14 pm:

Quoted 27 lines
Quoted 10 lines · Nicholas Piggin

System call entry and particularly exit code is beyond the limit of what is reasonable to implement in asm.

This conversion moves all conditional branches out of the asm code, except for the case that all GPRs should be restored at exit.

Null syscall test is about 5% faster after this patch, because the exit work is handled under local_irq_disable, and the hard mask and pending interrupt replay is handled after that, which avoids games with MSR.

Quoted 8 lines

---
Since v1:
- Fix big endian build (mpe)
- Fix order of exit tracing to after the result registers have been set.
- Move ->softe store before MSR[EE] is set, fix the now obsolete comment.
- More #ifdef tidyups and writing the accounting helpers nicer (Christophe)
- Minor things like move the TM debug store into C

This doesn't build in a few configs.

It needed:

(quoted diff) +2 -0
+#else
+static inline void kuap_check_amr(void) { }
Quoted 1 line

In kup-radix.h to fix the KUAP=n build.

Thanks.

Quoted 4 lines

It still fails to build on ppc64e with:

arch/powerpc/kernel/syscall_64.c:161:2: error: implicit declaration of function '__mtmsrd' [-Werror=implicit-function-declaration]

Ah, no __mtmsrd or RI on BookE, so that will need a new function in hw_irq.h. I think I also need to do the irq tracing with RI=1 now I think about it.

I'll resend a fixed patch.

Thanks,
Nick