Skip to contentSkip to conversation

powerpc/64: syscalls in C

PATCH Superseded Nicholas Piggin 5 participants 19 messages Aug 27, 2019 – Sep 2, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Nicholas Piggin

author reviewer
#0 lore raw

cover powerpc/64: syscalls in C

This hasn't been highly stress tested or tested all cases (like 32-bit binaries, single stepping, etc.) but so far it's running stable doing normal kernel development and microbenchmarks.

Thanks,
Nick

Nicholas Piggin (4):
powerpc: convert to copy_thread_tls
powerpc/64: remove support for kernel-mode syscalls powerpc/64: system call remove non-volatile GPR save optimisation powerpc/64: system call implement the bulk of the logic in C

 arch/powerpc/Kconfig                      |   1 +
 arch/powerpc/include/asm/asm-prototypes.h |  11 -
 arch/powerpc/include/asm/ptrace.h         |   3 +
 arch/powerpc/include/asm/signal.h         |   2 +
 arch/powerpc/include/asm/switch_to.h      |   4 +
 arch/powerpc/include/asm/time.h           |   3 +
 arch/powerpc/kernel/Makefile              |   3 +-
 arch/powerpc/kernel/entry_64.S            | 424 ++++------------------
 arch/powerpc/kernel/exceptions-64s.S      |   2 -
 arch/powerpc/kernel/process.c             |  15 +-
 arch/powerpc/kernel/signal.h              |   2 -
 arch/powerpc/kernel/syscall_64.c          | 202 +++++++++++
 arch/powerpc/kernel/syscalls/syscall.tbl  |  22 +-
 13 files changed, 305 insertions(+), 389 deletions(-)
 create mode 100644 arch/powerpc/kernel/syscall_64.c
Signature · 1 line
2.22.0
author reviewer
#1 lore raw

PATCH 1/4 powerpc: convert to copy_thread_tls

Commit 3033f14ab78c3 ("clone: support passing tls argument via C rather than pt_regs magic") introduced the HAVE_COPY_THREAD_TLS option. Use it to avoid a subtle assumption about the argument ordering of clone type syscalls.

---
 arch/powerpc/Kconfig          | 1 +
 arch/powerpc/kernel/process.c | 9 +++++----
 2 files changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/Kconfig +1 -0
index d8dcd8820369..7477a3263225 100644
@@ -182,6 +182,7 @@ config PPC
 	select HAVE_STACKPROTECTOR		if PPC64 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r13)
 	select HAVE_STACKPROTECTOR		if PPC32 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r2)
 	select HAVE_CONTEXT_TRACKING		if PPC64
+	select HAVE_COPY_THREAD_TLS
 	select HAVE_DEBUG_KMEMLEAK
 	select HAVE_DEBUG_STACKOVERFLOW
 	select HAVE_DYNAMIC_FTRACE
arch/powerpc/kernel/process.c +5 -4
index 8fc4de0d22b4..24621e7e5033 100644
@@ -1600,8 +1600,9 @@ static void setup_ksp_vsid(struct task_struct *p, unsigned long sp)
 /*
  * Copy architecture-specific thread state
  */
-int copy_thread(unsigned long clone_flags, unsigned long usp,
-		unsigned long kthread_arg, struct task_struct *p)
+int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
+		unsigned long kthread_arg, struct task_struct *p,
+		unsigned long tls)
 {
 	struct pt_regs *childregs, *kregs;
 	extern void ret_from_fork(void);
@@ -1642,10 +1643,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
 		if (clone_flags & CLONE_SETTLS) {
 #ifdef CONFIG_PPC64
 			if (!is_32bit_task())
-				childregs->gpr[13] = childregs->gpr[6];
+				childregs->gpr[13] = tls;
 			else
 #endif
-				childregs->gpr[2] = childregs->gpr[6];
+				childregs->gpr[2] = tls;
 		}
 
 		f = ret_from_fork;
Signature · 1 line
2.22.0
author reviewer
#6 lore raw

PATCH 2/4 powerpc/64: remove support for kernel-mode syscalls

In reply to Nicholas Piggin

There is support for the kernel to execute the 'sc 0' instruction and make a system call to itself. This is a relic that is unused in the tree, therefore untested. It's also highly questionable for modules to be doing this.

---
 arch/powerpc/kernel/entry_64.S       | 21 ++++++---------------
 arch/powerpc/kernel/exceptions-64s.S |  2 --
 2 files changed, 6 insertions(+), 17 deletions(-)
arch/powerpc/kernel/entry_64.S +6 -15
index 0a0b5310f54a..6467bdab8d40 100644
@@ -69,24 +69,20 @@ BEGIN_FTR_SECTION
 	bne	.Ltabort_syscall
 END_FTR_SECTION_IFSET(CPU_FTR_TM)
 #endif
-	andi.	r10,r12,MSR_PR
 	mr	r10,r1
-	addi	r1,r1,-INT_FRAME_SIZE
-	beq-	1f
 	ld	r1,PACAKSAVE(r13)
-1:	std	r10,0(r1)
+	std	r10,0(r1)
 	std	r11,_NIP(r1)
 	std	r12,_MSR(r1)
 	std	r0,GPR0(r1)
 	std	r10,GPR1(r1)
-	beq	2f			/* if from kernel mode */
 #ifdef CONFIG_PPC_FSL_BOOK3E
 START_BTB_FLUSH_SECTION
 	BTB_FLUSH(r10)
 END_BTB_FLUSH_SECTION
 #endif
 	ACCOUNT_CPU_USER_ENTRY(r13, r10, r11)
-2:	std	r2,GPR2(r1)
+	std	r2,GPR2(r1)
 	std	r3,GPR3(r1)
 	mfcr	r2
 	std	r4,GPR4(r1)
@@ -122,14 +118,13 @@ END_BTB_FLUSH_SECTION
 
 #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
 BEGIN_FW_FTR_SECTION
-	beq	33f
-	/* if from user, see if there are any DTL entries to process */
+	/* see if there are any DTL entries to process */
 	ld	r10,PACALPPACAPTR(r13)	/* get ptr to VPA */
 	ld	r11,PACA_DTL_RIDX(r13)	/* get log read index */
 	addi	r10,r10,LPPACA_DTLIDX
 	LDX_BE	r10,0,r10		/* get log write index */
-	cmpd	cr1,r11,r10
-	beq+	cr1,33f
+	cmpd	r11,r10
+	beq+	33f
 	bl	accumulate_stolen_time
 	REST_GPR(0,r1)
 	REST_4GPRS(3,r1)
@@ -203,6 +198,7 @@ system_call:			/* label this so stack traces look sane */
 	mtctr   r12
 	bctrl			/* Call handler */
 
+	/* syscall_exit can exit to kernel mode, via ret_from_kernel_thread */
 .Lsyscall_exit:
 	std	r3,RESULT(r1)
 
@@ -216,11 +212,6 @@ system_call:			/* label this so stack traces look sane */
 	ld	r12, PACA_THREAD_INFO(r13)
 
 	ld	r8,_MSR(r1)
-#ifdef CONFIG_PPC_BOOK3S
-	/* No MSR:RI on BookE */
-	andi.	r10,r8,MSR_RI
-	beq-	.Lunrecov_restore
-#endif
 
 /*
  * This is a few instructions into the actual syscall exit path (which actually
arch/powerpc/kernel/exceptions-64s.S +0 -2
index 6ba3cc2ef8ab..768f133de4f1 100644
@@ -1521,8 +1521,6 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
  * system call / hypercall (0xc00, 0x4c00)
  *
  * The system call exception is invoked with "sc 0" and does not alter HV bit.
- * There is support for kernel code to invoke system calls but there are no
- * in-tree users.
  *
  * The hypercall is invoked with "sc 1" and sets HV=1.
  *
Signature · 1 line
2.22.0
author reviewer
#10 lore raw

PATCH 2/4 powerpc/64s: remove support for kernel-mode syscalls

In reply to Nicholas Piggin

There is support for the kernel to execute the 'sc 0' instruction and make a system call to itself. This is a relic that is unused in the tree, therefore untested. It's also highly questionable for modules to be doing this.

---
 arch/powerpc/kernel/entry_64.S       | 21 ++++++---------------
 arch/powerpc/kernel/exceptions-64s.S |  2 --
 2 files changed, 6 insertions(+), 17 deletions(-)
arch/powerpc/kernel/entry_64.S +6 -15
index 0a0b5310f54a..6467bdab8d40 100644
@@ -69,24 +69,20 @@ BEGIN_FTR_SECTION
 	bne	.Ltabort_syscall
 END_FTR_SECTION_IFSET(CPU_FTR_TM)
 #endif
-	andi.	r10,r12,MSR_PR
 	mr	r10,r1
-	addi	r1,r1,-INT_FRAME_SIZE
-	beq-	1f
 	ld	r1,PACAKSAVE(r13)
-1:	std	r10,0(r1)
+	std	r10,0(r1)
 	std	r11,_NIP(r1)
 	std	r12,_MSR(r1)
 	std	r0,GPR0(r1)
 	std	r10,GPR1(r1)
-	beq	2f			/* if from kernel mode */
 #ifdef CONFIG_PPC_FSL_BOOK3E
 START_BTB_FLUSH_SECTION
 	BTB_FLUSH(r10)
 END_BTB_FLUSH_SECTION
 #endif
 	ACCOUNT_CPU_USER_ENTRY(r13, r10, r11)
-2:	std	r2,GPR2(r1)
+	std	r2,GPR2(r1)
 	std	r3,GPR3(r1)
 	mfcr	r2
 	std	r4,GPR4(r1)
@@ -122,14 +118,13 @@ END_BTB_FLUSH_SECTION
 
 #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
 BEGIN_FW_FTR_SECTION
-	beq	33f
-	/* if from user, see if there are any DTL entries to process */
+	/* see if there are any DTL entries to process */
 	ld	r10,PACALPPACAPTR(r13)	/* get ptr to VPA */
 	ld	r11,PACA_DTL_RIDX(r13)	/* get log read index */
 	addi	r10,r10,LPPACA_DTLIDX
 	LDX_BE	r10,0,r10		/* get log write index */
-	cmpd	cr1,r11,r10
-	beq+	cr1,33f
+	cmpd	r11,r10
+	beq+	33f
 	bl	accumulate_stolen_time
 	REST_GPR(0,r1)
 	REST_4GPRS(3,r1)
@@ -203,6 +198,7 @@ system_call:			/* label this so stack traces look sane */
 	mtctr   r12
 	bctrl			/* Call handler */
 
+	/* syscall_exit can exit to kernel mode, via ret_from_kernel_thread */
 .Lsyscall_exit:
 	std	r3,RESULT(r1)
 
@@ -216,11 +212,6 @@ system_call:			/* label this so stack traces look sane */
 	ld	r12, PACA_THREAD_INFO(r13)
 
 	ld	r8,_MSR(r1)
-#ifdef CONFIG_PPC_BOOK3S
-	/* No MSR:RI on BookE */
-	andi.	r10,r8,MSR_RI
-	beq-	.Lunrecov_restore
-#endif
 
 /*
  * This is a few instructions into the actual syscall exit path (which actually
arch/powerpc/kernel/exceptions-64s.S +0 -2
index 6ba3cc2ef8ab..768f133de4f1 100644
@@ -1521,8 +1521,6 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
  * system call / hypercall (0xc00, 0x4c00)
  *
  * The system call exception is invoked with "sc 0" and does not alter HV bit.
- * There is support for kernel code to invoke system calls but there are no
- * in-tree users.
  *
  * The hypercall is invoked with "sc 1" and sets HV=1.
  *
Signature · 1 line
2.22.0
author reviewer
#13 lore raw

PATCH 3/4 powerpc/64: system call remove non-volatile GPR save optimisation

In reply to Nicholas Piggin

powerpc has an optimisation where interrupts avoid saving the non-volatile (or callee saved) registers to the interrupt stack frame if they are not required.

Two problems with this are that an interrupt does not always know whether it will need non-volatiles; and if it does need them, they can only be saved from the entry-scoped asm code (because we don't control what the C compiler does with these registers).

system calls are about the worst example of this, some system calls always require all registers (e.g., fork, to copy regs into the child). Sometimes registers are only required under certain conditions (e.g., tracing, signal delivery). This causes weird ugly logic in the call chains (e.g., ppc_fork), and also prevents moving substantial amounts of logic to C.

Remove this optimisation for system calls, and always save NVGPRs on entry. On modern CPUs this doesn't appear to be worth the complexity because the stores can be hidden by other work quite well the null syscall selftests benchmark on a POWER9 has (124.40ns before and 123.64ns after, i.e., well within the noise).

Other interrupts are a little less complex in NVGPR handling, many do less work at entry and also they don't have as clear a fast path for avoiding the GPR restore as system calls, so this patch does not remove the facility completely until more tests can be done.

---
 arch/powerpc/kernel/entry_64.S           | 72 +++++-------------------
 arch/powerpc/kernel/syscalls/syscall.tbl | 22 +++++---
 2 files changed, 28 insertions(+), 66 deletions(-)
arch/powerpc/kernel/entry_64.S +13 -59
index 6467bdab8d40..5a3e0b5c9ad1 100644
@@ -98,13 +98,14 @@ END_BTB_FLUSH_SECTION
 	std	r11,_XER(r1)
 	std	r11,_CTR(r1)
 	std	r9,GPR13(r1)
+	SAVE_NVGPRS(r1)
 	mflr	r10
 	/*
 	 * This clears CR0.SO (bit 28), which is the error indication on
 	 * return from this system call.
 	 */
 	rldimi	r2,r11,28,(63-28)
-	li	r11,0xc01
+	li	r11,0xc00
 	std	r10,_LINK(r1)
 	std	r11,_TRAP(r1)
 	std	r3,ORIG_GPR3(r1)
@@ -323,7 +324,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
 
 /* Traced system call support */
 .Lsyscall_dotrace:
-	bl	save_nvgprs
 	addi	r3,r1,STACK_FRAME_OVERHEAD
 	bl	do_syscall_trace_enter
 
@@ -408,7 +408,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
 	mtmsrd	r10,1
 #endif /* CONFIG_PPC_BOOK3E */
 
-	bl	save_nvgprs
 	addi	r3,r1,STACK_FRAME_OVERHEAD
 	bl	do_syscall_trace_leave
 	b	ret_from_except
@@ -442,62 +441,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR)
 _ASM_NOKPROBE_SYMBOL(system_call_common);
 _ASM_NOKPROBE_SYMBOL(system_call_exit);
 
-/* Save non-volatile GPRs, if not already saved. */
-_GLOBAL(save_nvgprs)
-	ld	r11,_TRAP(r1)
-	andi.	r0,r11,1
-	beqlr-
-	SAVE_NVGPRS(r1)
-	clrrdi	r0,r11,1
-	std	r0,_TRAP(r1)
-	blr
-_ASM_NOKPROBE_SYMBOL(save_nvgprs);
-
-	
-/*
- * The sigsuspend and rt_sigsuspend system calls can call do_signal
- * and thus put the process into the stopped state where we might
- * want to examine its user state with ptrace.  Therefore we need
- * to save all the nonvolatile registers (r14 - r31) before calling
- * the C code.  Similarly, fork, vfork and clone need the full
- * register state on the stack so that it can be copied to the child.
- */
-
-_GLOBAL(ppc_fork)
-	bl	save_nvgprs
-	bl	sys_fork
-	b	.Lsyscall_exit
-
-_GLOBAL(ppc_vfork)
-	bl	save_nvgprs
-	bl	sys_vfork
-	b	.Lsyscall_exit
-
-_GLOBAL(ppc_clone)
-	bl	save_nvgprs
-	bl	sys_clone
-	b	.Lsyscall_exit
-
-_GLOBAL(ppc_clone3)
-       bl      save_nvgprs
-       bl      sys_clone3
-       b       .Lsyscall_exit
-
-_GLOBAL(ppc32_swapcontext)
-	bl	save_nvgprs
-	bl	compat_sys_swapcontext
-	b	.Lsyscall_exit
-
-_GLOBAL(ppc64_swapcontext)
-	bl	save_nvgprs
-	bl	sys_swapcontext
-	b	.Lsyscall_exit
-
-_GLOBAL(ppc_switch_endian)
-	bl	save_nvgprs
-	bl	sys_switch_endian
-	b	.Lsyscall_exit
-
 _GLOBAL(ret_from_fork)
 	bl	schedule_tail
 	REST_NVGPRS(r1)
@@ -516,6 +459,17 @@ _GLOBAL(ret_from_kernel_thread)
 	li	r3,0
 	b	.Lsyscall_exit
 
+/* Save non-volatile GPRs, if not already saved. */
+_GLOBAL(save_nvgprs)
+	ld	r11,_TRAP(r1)
+	andi.	r0,r11,1
+	beqlr-
+	SAVE_NVGPRS(r1)
+	clrrdi	r0,r11,1
+	std	r0,_TRAP(r1)
+	blr
+_ASM_NOKPROBE_SYMBOL(save_nvgprs);
+
 #ifdef CONFIG_PPC_BOOK3S_64
 
 #define FLUSH_COUNT_CACHE	\
arch/powerpc/kernel/syscalls/syscall.tbl +15 -7
index 43f736ed47f2..010b9f445586 100644
@@ -9,7 +9,9 @@
 #
 0	nospu	restart_syscall			sys_restart_syscall
 1	nospu	exit				sys_exit
-2	nospu	fork				ppc_fork
+2	32	fork				ppc_fork			sys_fork
+2	64	fork				sys_fork
+2	spu	fork				sys_ni_syscall
 3	common	read				sys_read
 4	common	write				sys_write
 5	common	open				sys_open			compat_sys_open
@@ -158,7 +160,9 @@
 119	32	sigreturn			sys_sigreturn			compat_sys_sigreturn
 119	64	sigreturn			sys_ni_syscall
 119	spu	sigreturn			sys_ni_syscall
-120	nospu	clone				ppc_clone
+120	32	clone				ppc_clone			sys_clone
+120	64	clone				sys_clone
+120	spu	clone				sys_ni_syscall
 121	common	setdomainname			sys_setdomainname
 122	common	uname				sys_newuname
 123	common	modify_ldt			sys_ni_syscall
@@ -240,7 +244,9 @@
 186	spu	sendfile			sys_sendfile64
 187	common	getpmsg				sys_ni_syscall
 188	common 	putpmsg				sys_ni_syscall
-189	nospu	vfork				ppc_vfork
+189	32	vfork				ppc_vfork			sys_vfork
+189	64	vfork				sys_vfork
+189	spu	vfork				sys_ni_syscall
 190	common	ugetrlimit			sys_getrlimit			compat_sys_getrlimit
 191	common	readahead			sys_readahead			compat_sys_readahead
 192	32	mmap2				sys_mmap2			compat_sys_mmap2
@@ -316,8 +322,8 @@
 248	32	clock_nanosleep			sys_clock_nanosleep_time32
 248	64	clock_nanosleep			sys_clock_nanosleep
 248	spu	clock_nanosleep			sys_clock_nanosleep
-249	32	swapcontext			ppc_swapcontext			ppc32_swapcontext
-249	64	swapcontext			ppc64_swapcontext
+249	32	swapcontext			ppc_swapcontext			compat_sys_swapcontext
+249	64	swapcontext			sys_swapcontext
 249	spu	swapcontext			sys_ni_syscall
 250	common	tgkill				sys_tgkill
 251	32	utimes				sys_utimes_time32
@@ -456,7 +462,7 @@
 361	common	bpf				sys_bpf
 362	nospu	execveat			sys_execveat			compat_sys_execveat
 363	32	switch_endian			sys_ni_syscall
-363	64	switch_endian			ppc_switch_endian
+363	64	switch_endian			sys_switch_endian
 363	spu	switch_endian			sys_ni_syscall
 364	common	userfaultfd			sys_userfaultfd
 365	common	membarrier			sys_membarrier
@@ -516,4 +522,6 @@
 432	common	fsmount				sys_fsmount
 433	common	fspick				sys_fspick
 434	common	pidfd_open			sys_pidfd_open
-435	nospu	clone3				ppc_clone3
+435	32	clone3				ppc_clone3			sys_clone3
+435	64	clone3				sys_clone3
+435	nospu	clone3				sys_ni_syscall
Signature · 1 line
2.22.0
author reviewer
#15 lore raw

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

In reply to 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 a relatively simple test to see whether all GPRs should be restored at exit time.

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.

The asm instruction scheduling has not really been analysed and optimised yet, as there are higher level features and improvements to add first.

---
 arch/powerpc/include/asm/asm-prototypes.h |  11 -
 arch/powerpc/include/asm/ptrace.h         |   3 +
 arch/powerpc/include/asm/signal.h         |   2 +
 arch/powerpc/include/asm/switch_to.h      |   4 +
 arch/powerpc/include/asm/time.h           |   3 +
 arch/powerpc/kernel/Makefile              |   3 +-
 arch/powerpc/kernel/entry_64.S            | 343 ++++------------------
 arch/powerpc/kernel/process.c             |   6 +-
 arch/powerpc/kernel/signal.h              |   2 -
 arch/powerpc/kernel/syscall_64.c          | 202 +++++++++++++
 10 files changed, 271 insertions(+), 308 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/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 +2 -0
index 0803ca8b9149..0113be8dcb59 100644
@@ -6,4 +6,6 @@
 #include <uapi/asm/signal.h>
 #include <uapi/asm/ptrace.h>
 
+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 +4 -0
index 5b03d8a82409..231fcb2058cf 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,9 @@ 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 +51 -292

422 lines not on this page · raw message

arch/powerpc/kernel/process.c +4 -2
index 24621e7e5033..f444525da9ce 100644
@@ -1609,7 +1609,6 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
 	extern void ret_from_kernel_thread(void);
 	void (*f)(void);
 	unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
-	struct thread_info *ti = task_thread_info(p);
 
 	klp_init_thread_info(p);
 
@@ -1617,6 +1616,8 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
 	sp -= sizeof(struct pt_regs);
 	childregs = (struct pt_regs *) sp;
 	if (unlikely(p->flags & PF_KTHREAD)) {
+		struct thread_info *ti = task_thread_info(p);
+
 		/* kernel thread */
 		memset(childregs, 0, sizeof(struct pt_regs));
 		childregs->gpr[1] = sp + sizeof(struct pt_regs);
@@ -1634,12 +1635,13 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
 	} else {
 		/* user thread */
 		struct pt_regs *regs = current_pt_regs();
+
 		CHECK_FULL_REGS(regs);
 		*childregs = *regs;
 		if (usp)
 			childregs->gpr[1] = usp;
 		p->thread.regs = childregs;
-		childregs->gpr[3] = 0;  /* Result from fork() */
+		/* ret_from_fork sets fork() result to 0 */
 		if (clone_flags & CLONE_SETTLS) {
 #ifdef CONFIG_PPC64
 			if (!is_32bit_task())
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 +202 -0

202 lines not on this page · raw message

Signature · 1 line
2.22.0
#2 lore raw

Re: [PATCH 1/4] powerpc: convert to copy_thread_tls

In reply to Nicholas Piggin

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 40 lines

Commit 3033f14ab78c3 ("clone: support passing tls argument via C rather than pt_regs magic") introduced the HAVE_COPY_THREAD_TLS option. Use it to avoid a subtle assumption about the argument ordering of clone type syscalls.

---
  arch/powerpc/Kconfig          | 1 +
  arch/powerpc/kernel/process.c | 9 +++++----
  2 files changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/Kconfig +1 -0
index d8dcd8820369..7477a3263225 100644
@@ -182,6 +182,7 @@ config PPC
  	select HAVE_STACKPROTECTOR		if PPC64 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r13)
  	select HAVE_STACKPROTECTOR		if PPC32 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r2)
  	select HAVE_CONTEXT_TRACKING		if PPC64
+	select HAVE_COPY_THREAD_TLS
  	select HAVE_DEBUG_KMEMLEAK
  	select HAVE_DEBUG_STACKOVERFLOW
  	select HAVE_DYNAMIC_FTRACE
arch/powerpc/kernel/process.c +3 -2
index 8fc4de0d22b4..24621e7e5033 100644
@@ -1600,8 +1600,9 @@ static void setup_ksp_vsid(struct task_struct *p, unsigned long sp)
  /*
   * Copy architecture-specific thread state
   */
-int copy_thread(unsigned long clone_flags, unsigned long usp,
-		unsigned long kthread_arg, struct task_struct *p)
+int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
+		unsigned long kthread_arg, struct task_struct *p,
+		unsigned long tls)
  {
  	struct pt_regs *childregs, *kregs;
  	extern void ret_from_fork(void);

arch/powerpc/kernel/process.c int copy_thread(unsigned long clone_flags, unsigned long usp, · line 1644

Quoted 2 lines
arch/powerpc/kernel/process.c +0 -0
@@ -1642,10 +1643,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
  		if (clone_flags & CLONE_SETTLS) {
  #ifdef CONFIG_PPC64

is_32bit_task() exists and always returns 1 on PPC32 so this gross ifdef in the middle of an if/else is pointless, it should be dropped.

arch/powerpc/kernel/process.c int copy_thread(unsigned long clone_flags, unsigned long usp, · line 1652

Quoted 11 lines
arch/powerpc/kernel/process.c +2 -2
  			if (!is_32bit_task())
-				childregs->gpr[13] = childregs->gpr[6];
+				childregs->gpr[13] = tls;
  			else
  #endif
-				childregs->gpr[2] = childregs->gpr[6];
+				childregs->gpr[2] = tls;
  		}
 
  		f = ret_from_fork;

Christophe

#7 lore raw

Re: [PATCH 2/4] powerpc/64: remove support for kernel-mode syscalls

In reply to Nicholas Piggin

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 4 lines

There is support for the kernel to execute the 'sc 0' instruction and make a system call to itself. This is a relic that is unused in the tree, therefore untested. It's also highly questionable for modules to be doing this.

I like it.

I dropped support for that in PPC32 when I added fast-path syscalls.

Quoted 43 lines
---
  arch/powerpc/kernel/entry_64.S       | 21 ++++++---------------
  arch/powerpc/kernel/exceptions-64s.S |  2 --
  2 files changed, 6 insertions(+), 17 deletions(-)
arch/powerpc/kernel/entry_64.S +2 -7
index 0a0b5310f54a..6467bdab8d40 100644
@@ -69,24 +69,20 @@ BEGIN_FTR_SECTION
  	bne	.Ltabort_syscall
  END_FTR_SECTION_IFSET(CPU_FTR_TM)
  #endif
-	andi.	r10,r12,MSR_PR
  	mr	r10,r1
-	addi	r1,r1,-INT_FRAME_SIZE
-	beq-	1f
  	ld	r1,PACAKSAVE(r13)
-1:	std	r10,0(r1)
+	std	r10,0(r1)
  	std	r11,_NIP(r1)
  	std	r12,_MSR(r1)
  	std	r0,GPR0(r1)
  	std	r10,GPR1(r1)
-	beq	2f			/* if from kernel mode */
  #ifdef CONFIG_PPC_FSL_BOOK3E
  START_BTB_FLUSH_SECTION
  	BTB_FLUSH(r10)
  END_BTB_FLUSH_SECTION
  #endif
  	ACCOUNT_CPU_USER_ENTRY(r13, r10, r11)
-2:	std	r2,GPR2(r1)
+	std	r2,GPR2(r1)
  	std	r3,GPR3(r1)
  	mfcr	r2
  	std	r4,GPR4(r1)
@@ -122,14 +118,13 @@ END_BTB_FLUSH_SECTION
 
  #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
  BEGIN_FW_FTR_SECTION
-	beq	33f

arch/powerpc/kernel/entry_64.S END_BTB_FLUSH_SECTION · line 127

Quoted 10 lines
arch/powerpc/kernel/entry_64.S +3 -3
-	/* if from user, see if there are any DTL entries to process */
+	/* see if there are any DTL entries to process */
  	ld	r10,PACALPPACAPTR(r13)	/* get ptr to VPA */
  	ld	r11,PACA_DTL_RIDX(r13)	/* get log read index */
  	addi	r10,r10,LPPACA_DTLIDX
  	LDX_BE	r10,0,r10		/* get log write index */
-	cmpd	cr1,r11,r10
-	beq+	cr1,33f
+	cmpd	r11,r10
+	beq+	33f

Any need to do this change ? Why not keep it as is ?

Christophe

Quoted 37 lines
arch/powerpc/kernel/entry_64.S +1 -5
  	bl	accumulate_stolen_time
  	REST_GPR(0,r1)
  	REST_4GPRS(3,r1)
@@ -203,6 +198,7 @@ system_call:			/* label this so stack traces look sane */
  	mtctr   r12
  	bctrl			/* Call handler */
 
+	/* syscall_exit can exit to kernel mode, via ret_from_kernel_thread */
  .Lsyscall_exit:
  	std	r3,RESULT(r1)
 
@@ -216,11 +212,6 @@ system_call:			/* label this so stack traces look sane */
  	ld	r12, PACA_THREAD_INFO(r13)
 
  	ld	r8,_MSR(r1)
-#ifdef CONFIG_PPC_BOOK3S
-	/* No MSR:RI on BookE */
-	andi.	r10,r8,MSR_RI
-	beq-	.Lunrecov_restore
-#endif
 
  /*
   * This is a few instructions into the actual syscall exit path (which actually
arch/powerpc/kernel/exceptions-64s.S +0 -2
index 6ba3cc2ef8ab..768f133de4f1 100644
@@ -1521,8 +1521,6 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
   * system call / hypercall (0xc00, 0x4c00)
   *
   * The system call exception is invoked with "sc 0" and does not alter HV bit.
- * There is support for kernel code to invoke system calls but there are no
- * in-tree users.
   *
   * The hypercall is invoked with "sc 1" and sets HV=1.
   *
#11 lore raw

Re: [PATCH 2/4] powerpc/64s: remove support for kernel-mode syscalls

In reply to Nicholas Piggin

Euh ... That's a duplicate of [PATCH 2/4] "powerpc/64: remove support for kernel-mode syscalls" ?

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 94 lines

There is support for the kernel to execute the 'sc 0' instruction and make a system call to itself. This is a relic that is unused in the tree, therefore untested. It's also highly questionable for modules to be doing this.

---
  arch/powerpc/kernel/entry_64.S       | 21 ++++++---------------
  arch/powerpc/kernel/exceptions-64s.S |  2 --
  2 files changed, 6 insertions(+), 17 deletions(-)
arch/powerpc/kernel/entry_64.S +6 -15
index 0a0b5310f54a..6467bdab8d40 100644
@@ -69,24 +69,20 @@ BEGIN_FTR_SECTION
  	bne	.Ltabort_syscall
  END_FTR_SECTION_IFSET(CPU_FTR_TM)
  #endif
-	andi.	r10,r12,MSR_PR
  	mr	r10,r1
-	addi	r1,r1,-INT_FRAME_SIZE
-	beq-	1f
  	ld	r1,PACAKSAVE(r13)
-1:	std	r10,0(r1)
+	std	r10,0(r1)
  	std	r11,_NIP(r1)
  	std	r12,_MSR(r1)
  	std	r0,GPR0(r1)
  	std	r10,GPR1(r1)
-	beq	2f			/* if from kernel mode */
  #ifdef CONFIG_PPC_FSL_BOOK3E
  START_BTB_FLUSH_SECTION
  	BTB_FLUSH(r10)
  END_BTB_FLUSH_SECTION
  #endif
  	ACCOUNT_CPU_USER_ENTRY(r13, r10, r11)
-2:	std	r2,GPR2(r1)
+	std	r2,GPR2(r1)
  	std	r3,GPR3(r1)
  	mfcr	r2
  	std	r4,GPR4(r1)
@@ -122,14 +118,13 @@ END_BTB_FLUSH_SECTION
 
  #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
  BEGIN_FW_FTR_SECTION
-	beq	33f
-	/* if from user, see if there are any DTL entries to process */
+	/* see if there are any DTL entries to process */
  	ld	r10,PACALPPACAPTR(r13)	/* get ptr to VPA */
  	ld	r11,PACA_DTL_RIDX(r13)	/* get log read index */
  	addi	r10,r10,LPPACA_DTLIDX
  	LDX_BE	r10,0,r10		/* get log write index */
-	cmpd	cr1,r11,r10
-	beq+	cr1,33f
+	cmpd	r11,r10
+	beq+	33f
  	bl	accumulate_stolen_time
  	REST_GPR(0,r1)
  	REST_4GPRS(3,r1)
@@ -203,6 +198,7 @@ system_call:			/* label this so stack traces look sane */
  	mtctr   r12
  	bctrl			/* Call handler */
 
+	/* syscall_exit can exit to kernel mode, via ret_from_kernel_thread */
  .Lsyscall_exit:
  	std	r3,RESULT(r1)
 
@@ -216,11 +212,6 @@ system_call:			/* label this so stack traces look sane */
  	ld	r12, PACA_THREAD_INFO(r13)
 
  	ld	r8,_MSR(r1)
-#ifdef CONFIG_PPC_BOOK3S
-	/* No MSR:RI on BookE */
-	andi.	r10,r8,MSR_RI
-	beq-	.Lunrecov_restore
-#endif
 
  /*
   * This is a few instructions into the actual syscall exit path (which actually
arch/powerpc/kernel/exceptions-64s.S +0 -2
index 6ba3cc2ef8ab..768f133de4f1 100644
@@ -1521,8 +1521,6 @@ EXC_COMMON(trap_0b_common, 0xb00, unknown_exception)
   * system call / hypercall (0xc00, 0x4c00)
   *
   * The system call exception is invoked with "sc 0" and does not alter HV bit.
- * There is support for kernel code to invoke system calls but there are no
- * in-tree users.
   *
   * The hypercall is invoked with "sc 1" and sets HV=1.
   *
#16 lore raw

Re: [PATCH 4/4] powerpc/64: system call implement the bulk of the logic in C

In reply to Nicholas Piggin

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 10 lines

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 a relatively simple test to see whether all GPRs should be restored at exit time.

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.

Interesting optimisation.

Quoted 20 lines

The asm instruction scheduling has not really been analysed and optimised yet, as there are higher level features and improvements to add first.

---
  arch/powerpc/include/asm/asm-prototypes.h |  11 -
  arch/powerpc/include/asm/ptrace.h         |   3 +
  arch/powerpc/include/asm/signal.h         |   2 +
  arch/powerpc/include/asm/switch_to.h      |   4 +
  arch/powerpc/include/asm/time.h           |   3 +
  arch/powerpc/kernel/Makefile              |   3 +-
  arch/powerpc/kernel/entry_64.S            | 343 ++++------------------
  arch/powerpc/kernel/process.c             |   6 +-
  arch/powerpc/kernel/signal.h              |   2 -
  arch/powerpc/kernel/syscall_64.c          | 202 +++++++++++++
  10 files changed, 271 insertions(+), 308 deletions(-)

create mode 100644 arch/powerpc/kernel/syscall_64.c

[...]

Quoted 23 lines
arch/powerpc/kernel/process.c +2 -1
index 24621e7e5033..f444525da9ce 100644
@@ -1609,7 +1609,6 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
  	extern void ret_from_kernel_thread(void);
  	void (*f)(void);
  	unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
-	struct thread_info *ti = task_thread_info(p);
 
  	klp_init_thread_info(p);
 
@@ -1617,6 +1616,8 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
  	sp -= sizeof(struct pt_regs);
  	childregs = (struct pt_regs *) sp;
  	if (unlikely(p->flags & PF_KTHREAD)) {
+		struct thread_info *ti = task_thread_info(p);
+
  		/* kernel thread */
  		memset(childregs, 0, sizeof(struct pt_regs));
  		childregs->gpr[1] = sp + sizeof(struct pt_regs);
@@ -1634,12 +1635,13 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
  	} else {

arch/powerpc/kernel/process.c int copy_thread_tls(unsigned long clone_flags, unsigned long usp, · line 1644

Quoted 10 lines
arch/powerpc/kernel/process.c +2 -1
  		/* user thread */
  		struct pt_regs *regs = current_pt_regs();
+
  		CHECK_FULL_REGS(regs);
  		*childregs = *regs;
  		if (usp)
  			childregs->gpr[1] = usp;
  		p->thread.regs = childregs;
-		childregs->gpr[3] = 0;  /* Result from fork() */
+		/* ret_from_fork sets fork() result to 0 */

Does PPC32 ret_from_fork() do it as well ?

Quoted 47 lines
arch/powerpc/kernel/process.c +0 -0
  		if (clone_flags & CLONE_SETTLS) {
  #ifdef CONFIG_PPC64
  			if (!is_32bit_task())
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 +25 -0
new file mode 100644
index 000000000000..98ed970796d5
@@ -0,0 +1,202 @@
+#include <linux/err.h>
+#include <asm/hw_irq.h>
+#include <asm/paca.h>
+#include <asm/ptrace.h>
+#include <asm/reg.h>
+#include <asm/signal.h>
+#include <asm/switch_to.h>
+#include <asm/syscall.h>
+#include <asm/time.h>
+
+extern void __noreturn tabort_syscall(void);
+
+#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
+static inline void account_cpu_user_entry(void)
+{
+	unsigned long tb = mftb();
+
+	local_paca->accounting.utime += (tb - local_paca->accounting.starttime_user);
+	local_paca->accounting.starttime = tb;
+}
+static inline void account_cpu_user_exit(void)
+{
+	unsigned long tb = mftb();
+
+	local_paca->accounting.stime += (tb - local_paca->accounting.starttime);

arch/powerpc/kernel/syscall_64.c line 35

Quoted 10 lines
arch/powerpc/kernel/syscall_64.c new file +10 -0
+	local_paca->accounting.starttime_user = tb;
+}
+#else
+static inline void account_cpu_user_entry(void)
+{
+}
+static inline void account_cpu_user_exit(void)
+{
+}
+#endif

I think this block should go in arch/powerpc/include/asm/cputime.h, we should limit #ifdefs as much as possible in C files.

And use get_accounting() instead of local_paca->accounting in order to be usable on PPC32 as well

Quoted 4 lines
arch/powerpc/kernel/syscall_64.c new file +4 -0
+
+typedef long (*syscall_fn)(long, long, long, long, long, long);
+
+long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, unsigned long r0, struct pt_regs *regs)

arch/powerpc/kernel/syscall_64.c line 49

Quoted 10 lines
arch/powerpc/kernel/syscall_64.c new file +10 -0
+{
+	unsigned long ti_flags;
+	syscall_fn f;
+
+	BUG_ON(!(regs->msr & MSR_PR));
+
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+	if (unlikely(regs->msr & MSR_TS_T))
+		tabort_syscall();
+#endif

MSR_TS_T and tabort_syscall() are declared regardless of CONFIG_PPC_TRANSACTIONAL_MEM so IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) should be used instead of #ifdef

arch/powerpc/kernel/syscall_64.c line 60

Quoted 11 lines
arch/powerpc/kernel/syscall_64.c new file +11 -0
+
+	account_cpu_user_entry();
+
+#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
+	if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
+		struct lppaca *lp = get_lppaca();
+
+		if (unlikely(local_paca->dtl_ridx != lp->dtl_idx))
+			accumulate_stolen_time();
+	}
+#endif

Same here, I think everything is available so IS_ENABLED() should be used instead of #if

arch/powerpc/kernel/syscall_64.c line 65

Quoted 5 lines
arch/powerpc/kernel/syscall_64.c new file +5 -0
+
+#ifdef CONFIG_PPC_KUAP_DEBUG
+	if (mmu_has_feature(MMU_FTR_RADIX_KUAP))
+		WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED);
+#endif

This should go in a helper in one of the kup/kuap header files.

arch/powerpc/kernel/syscall_64.c line 76

Quoted 11 lines
arch/powerpc/kernel/syscall_64.c new file +11 -0
+
+	/*
+	 * A syscall should always be called with interrupts enabled
+	 * so we just unconditionally hard-enable here. When some kind
+	 * of irq tracing is used, we additionally check that condition
+	 * is correct
+	 */
+#if defined(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)
+	WARN_ON(irq_soft_mask_return() != IRQS_ENABLED);
+	WARN_ON(local_paca->irq_happened);
+#endif

Can we use IS_ENABLED() here as well ?

Quoted 91 lines
arch/powerpc/kernel/syscall_64.c new file +91 -0
+
+	__hard_irq_enable();
+
+	/*
+	 * We do need to set SOFTE in the stack frame or the return
+	 * from interrupt will be painful
+	 */
+	regs->softe = IRQS_ENABLED;
+
+	ti_flags = current_thread_info()->flags;
+	if (unlikely(ti_flags & _TIF_SYSCALL_DOTRACE)) {
+		/*
+		 * We use the return value of do_syscall_trace_enter() as the
+		 * syscall number. If the syscall was rejected for any reason
+		 * do_syscall_trace_enter() returns an invalid syscall number
+		 * and the test below against NR_syscalls will fail.
+		 */
+		r0 = do_syscall_trace_enter(regs);
+	}
+
+	if (unlikely(r0 >= NR_syscalls))
+		return -ENOSYS;
+
+	/* May be faster to do array_index_nospec? */
+	barrier_nospec();
+
+	if (unlikely(ti_flags & _TIF_32BIT)) {
+		f = (void *)compat_sys_call_table[r0];
+
+		r3 &= 0x00000000ffffffffULL;
+		r4 &= 0x00000000ffffffffULL;
+		r5 &= 0x00000000ffffffffULL;
+		r6 &= 0x00000000ffffffffULL;
+		r7 &= 0x00000000ffffffffULL;
+		r8 &= 0x00000000ffffffffULL;
+
+	} else {
+		f = (void *)sys_call_table[r0];
+	}
+
+	return f(r3, r4, r5, r6, r7, r8);
+}
+
+unsigned long syscall_exit_prepare(unsigned long r3, struct pt_regs *regs)
+{
+	unsigned long *ti_flagsp = &current_thread_info()->flags;
+	unsigned long ti_flags;
+	unsigned long ret = 0;
+
+	regs->result = r3;
+
+	/* Check whether the syscall is issued inside a restartable sequence */
+	rseq_syscall(regs);
+
+	ti_flags = *ti_flagsp;
+	if (unlikely(ti_flags & _TIF_SYSCALL_DOTRACE))
+		do_syscall_trace_leave(regs);
+
+	if (unlikely(r3 >= (unsigned long)-MAX_ERRNO)) {
+		if (likely(!(ti_flags & (_TIF_NOERROR | _TIF_RESTOREALL)))) {
+			r3 = -r3;
+			regs->ccr |= 0x10000000; /* Set SO bit in CR */
+		}
+	}
+
+	if (unlikely(ti_flags & _TIF_PERSYSCALL_MASK)) {
+		if (ti_flags & _TIF_RESTOREALL)
+			ret = _TIF_RESTOREALL;
+		else
+			regs->gpr[3] = r3;
+		clear_bits(_TIF_PERSYSCALL_MASK, ti_flagsp);
+	} else {
+		regs->gpr[3] = r3;
+	}
+
+again:
+	local_irq_disable();
+	ti_flags = READ_ONCE(*ti_flagsp);
+	while (unlikely(ti_flags & _TIF_USER_WORK_MASK)) {
+		local_irq_enable();
+		if (ti_flags & _TIF_NEED_RESCHED) {
+			schedule();
+		} else {
+			/*
+			 * SIGPENDING must restore signal handler function
+			 * argument GPRs, and some non-volatiles (e.g., r1).
+			 * Restore all for now. This could be made lighter.
+			 */
+			if (ti_flags & _TIF_SIGPENDING)
+				ret |= _TIF_RESTOREALL;
+			do_notify_resume(regs, ti_flags);

arch/powerpc/kernel/syscall_64.c line 177

Quoted 10 lines
arch/powerpc/kernel/syscall_64.c new file +10 -0
+		}
+		local_irq_disable();
+		ti_flags = READ_ONCE(*ti_flagsp);
+	}
+
+#ifdef CONFIG_ALTIVEC
+	if ((regs->msr & (MSR_FP|MSR_VEC)) != (MSR_FP|MSR_VEC))
+#else
+	if ((regs->msr & MSR_FP) != MSR_FP)
+#endif

Use 'if (IS_ENABLED(CONFIG_ALTIVEC)) / else' instead of an #ifdef/#else/#endif

Quoted 11 lines
arch/powerpc/kernel/syscall_64.c new file +11 -0
+		restore_math(regs);
+
+	/* This pattern matches prep_irq_for_idle */
+	__mtmsrd(0, 1);	/* Disable MSR_EE and MSR_RI */
+	if (unlikely(lazy_irq_pending())) {
+		__mtmsrd(MSR_RI, 1);
+		local_paca->irq_happened |= PACA_IRQ_HARD_DIS;
+		local_irq_enable();
+		/* Took an interrupt which may have more exit work to do. */
+		goto again;
+	}

arch/powerpc/kernel/syscall_64.c line 198

Quoted 10 lines
arch/powerpc/kernel/syscall_64.c new file +10 -0
+	trace_hardirqs_on();
+	local_paca->irq_happened &= ~PACA_IRQ_HARD_DIS;
+	irq_soft_mask_set(IRQS_ENABLED);
+
+	account_cpu_user_exit();
+
+#ifdef CONFIG_PPC_KUAP_DEBUG
+	if (mmu_has_feature(MMU_FTR_RADIX_KUAP))
+		WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED);
+#endif

Same, define a helper in the kuap header files to avoid the #ifdefs and platform specif stuff here.

arch/powerpc/kernel/syscall_64.c line 202

Quoted 5 lines
arch/powerpc/kernel/syscall_64.c new file +4 -0
+
+	return ret;
+}
+

Christophe

#14 lore raw

Re: [PATCH 3/4] powerpc/64: system call remove non-volatile GPR save optimisation

In reply to Nicholas Piggin
Quoted 4 lines · Nicholas Piggin

-435 nospu clone3 ppc_clone3
+435 32 clone3 ppc_clone3 sys_clone3
+435 64 clone3 sys_clone3
+435 nospu clone3 sys_ni_syscall

s/no// on that last line. Rest looks good to me :-)

Segher

author reviewer
#3 lore raw

Re: [PATCH 1/4] powerpc: convert to copy_thread_tls

In reply to Christophe Leroy

Christophe Leroy's on August 27, 2019 4:07 pm:

Quoted 40 lines

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 37 lines

Commit 3033f14ab78c3 ("clone: support passing tls argument via C rather than pt_regs magic") introduced the HAVE_COPY_THREAD_TLS option. Use it to avoid a subtle assumption about the argument ordering of clone type syscalls.

---
  arch/powerpc/Kconfig          | 1 +
  arch/powerpc/kernel/process.c | 9 +++++----
  2 files changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/Kconfig +1 -0
index d8dcd8820369..7477a3263225 100644
@@ -182,6 +182,7 @@ config PPC
  	select HAVE_STACKPROTECTOR		if PPC64 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r13)
  	select HAVE_STACKPROTECTOR		if PPC32 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r2)
  	select HAVE_CONTEXT_TRACKING		if PPC64
+	select HAVE_COPY_THREAD_TLS
  	select HAVE_DEBUG_KMEMLEAK
  	select HAVE_DEBUG_STACKOVERFLOW
  	select HAVE_DYNAMIC_FTRACE
arch/powerpc/kernel/process.c +3 -2
index 8fc4de0d22b4..24621e7e5033 100644
@@ -1600,8 +1600,9 @@ static void setup_ksp_vsid(struct task_struct *p, unsigned long sp)
  /*
   * Copy architecture-specific thread state
   */
-int copy_thread(unsigned long clone_flags, unsigned long usp,
-		unsigned long kthread_arg, struct task_struct *p)
+int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
+		unsigned long kthread_arg, struct task_struct *p,
+		unsigned long tls)
  {
Quoted 8 lines

arch/powerpc/kernel/process.c int copy_thread(unsigned long clone_flags, unsigned long usp, · line 1644

Quoted 5 lines
arch/powerpc/kernel/process.c +0 -0
  	struct pt_regs *childregs, *kregs;
  	extern void ret_from_fork(void);
@@ -1642,10 +1643,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
  		if (clone_flags & CLONE_SETTLS) {
  #ifdef CONFIG_PPC64

is_32bit_task() exists and always returns 1 on PPC32 so this gross ifdef in the middle of an if/else is pointless, it should be dropped.

I could do that as another patch in the series.

Thanks,
Nick

author reviewer
#8 lore raw

Re: [PATCH 2/4] powerpc/64: remove support for kernel-mode syscalls

In reply to Christophe Leroy

Christophe Leroy's on August 27, 2019 4:13 pm:

Quoted 11 lines

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 4 lines

There is support for the kernel to execute the 'sc 0' instruction and make a system call to itself. This is a relic that is unused in the tree, therefore untested. It's also highly questionable for modules to be doing this.

I like it.

I dropped support for that in PPC32 when I added fast-path syscalls.

Good, then we'll match again.

Quoted 8 lines

arch/powerpc/kernel/entry_64.S BEGIN_FTR_SECTION · line 89

Quoted 8 lines
arch/powerpc/kernel/entry_64.S +0 -2
-	beq	2f			/* if from kernel mode */
  #ifdef CONFIG_PPC_FSL_BOOK3E
  START_BTB_FLUSH_SECTION
  	BTB_FLUSH(r10)
  END_BTB_FLUSH_SECTION
  #endif
  	ACCOUNT_CPU_USER_ENTRY(r13, r10, r11)
-2:	std	r2,GPR2(r1)

Btw. there is a hunk which restores this optimisation but it leaked into a later patch, I'll move it back here.

Quoted 17 lines
Quoted 5 lines
arch/powerpc/kernel/entry_64.S +0 -1
@@ -122,14 +118,13 @@ END_BTB_FLUSH_SECTION
 
  #if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
  BEGIN_FW_FTR_SECTION
-	beq	33f

arch/powerpc/kernel/entry_64.S END_BTB_FLUSH_SECTION · line 127

Quoted 10 lines
arch/powerpc/kernel/entry_64.S +3 -3
-	/* if from user, see if there are any DTL entries to process */
+	/* see if there are any DTL entries to process */
  	ld	r10,PACALPPACAPTR(r13)	/* get ptr to VPA */
  	ld	r11,PACA_DTL_RIDX(r13)	/* get log read index */
  	addi	r10,r10,LPPACA_DTLIDX
  	LDX_BE	r10,0,r10		/* get log write index */
-	cmpd	cr1,r11,r10
-	beq+	cr1,33f
+	cmpd	r11,r10
+	beq+	33f

Any need to do this change ? Why not keep it as is ?

We don't need to keep cr0 alive with the MSR_PR compare, so I prefer to keep the cr usage more compact, and I prefer to have cr0 for short lived results and others for long running ones as a rule.

Thanks,
Nick

author reviewer
#12 lore raw

Re: [PATCH 2/4] powerpc/64s: remove support for kernel-mode syscalls

In reply to Christophe Leroy

Christophe Leroy's on August 27, 2019 4:14 pm:

Quoted 2 lines

Euh ... That's a duplicate of [PATCH 2/4] "powerpc/64: remove support for kernel-mode syscalls" ?

Yeah sorry I changed the title and got myself confused.

Thanks,
Nick

author reviewer
#17 lore raw

Re: [PATCH 4/4] powerpc/64: system call implement the bulk of the logic in C

In reply to Christophe Leroy

Christophe Leroy's on August 27, 2019 4:46 pm:

Quoted 66 lines

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 10 lines

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 a relatively simple test to see whether all GPRs should be restored at exit time.

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.

Interesting optimisation.

Quoted 20 lines

The asm instruction scheduling has not really been analysed and optimised yet, as there are higher level features and improvements to add first.

---
  arch/powerpc/include/asm/asm-prototypes.h |  11 -
  arch/powerpc/include/asm/ptrace.h         |   3 +
  arch/powerpc/include/asm/signal.h         |   2 +
  arch/powerpc/include/asm/switch_to.h      |   4 +
  arch/powerpc/include/asm/time.h           |   3 +
  arch/powerpc/kernel/Makefile              |   3 +-
  arch/powerpc/kernel/entry_64.S            | 343 ++++------------------
  arch/powerpc/kernel/process.c             |   6 +-
  arch/powerpc/kernel/signal.h              |   2 -
  arch/powerpc/kernel/syscall_64.c          | 202 +++++++++++++
  10 files changed, 271 insertions(+), 308 deletions(-)

create mode 100644 arch/powerpc/kernel/syscall_64.c

[...]

Quoted 27 lines
arch/powerpc/kernel/process.c +3 -1
index 24621e7e5033..f444525da9ce 100644
@@ -1609,7 +1609,6 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
  	extern void ret_from_kernel_thread(void);
  	void (*f)(void);
  	unsigned long sp = (unsigned long)task_stack_page(p) + THREAD_SIZE;
-	struct thread_info *ti = task_thread_info(p);
 
  	klp_init_thread_info(p);
 
@@ -1617,6 +1616,8 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
  	sp -= sizeof(struct pt_regs);
  	childregs = (struct pt_regs *) sp;
  	if (unlikely(p->flags & PF_KTHREAD)) {
+		struct thread_info *ti = task_thread_info(p);
+
  		/* kernel thread */
  		memset(childregs, 0, sizeof(struct pt_regs));
  		childregs->gpr[1] = sp + sizeof(struct pt_regs);
@@ -1634,12 +1635,13 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
  	} else {
  		/* user thread */
  		struct pt_regs *regs = current_pt_regs();
+
  		CHECK_FULL_REGS(regs);
Quoted 8 lines

arch/powerpc/kernel/process.c int copy_thread_tls(unsigned long clone_flags, unsigned long usp, · line 1644

Quoted 6 lines
arch/powerpc/kernel/process.c +1 -1
  		*childregs = *regs;
  		if (usp)
  			childregs->gpr[1] = usp;
  		p->thread.regs = childregs;
-		childregs->gpr[3] = 0;  /* Result from fork() */
+		/* ret_from_fork sets fork() result to 0 */

Does PPC32 ret_from_fork() do it as well ?

AFAICT it does, but I guess it should be a patch by itself with powerpc: prefix. I will split it out.

Quoted 27 lines
Quoted 13 lines
arch/powerpc/kernel/process.c +13 -0
+#ifdef CONFIG_VIRT_CPU_ACCOUNTING_NATIVE
+static inline void account_cpu_user_entry(void)
+{
+	unsigned long tb = mftb();
+
+	local_paca->accounting.utime += (tb - local_paca->accounting.starttime_user);
+	local_paca->accounting.starttime = tb;
+}
+static inline void account_cpu_user_exit(void)
+{
+	unsigned long tb = mftb();
+
+	local_paca->accounting.stime += (tb - local_paca->accounting.starttime);

arch/powerpc/kernel/process.c int copy_thread_tls(unsigned long clone_flags, unsigned long usp,

Quoted 10 lines
arch/powerpc/kernel/process.c +10 -0
+	local_paca->accounting.starttime_user = tb;
+}
+#else
+static inline void account_cpu_user_entry(void)
+{
+}
+static inline void account_cpu_user_exit(void)
+{
+}
+#endif

I think this block should go in arch/powerpc/include/asm/cputime.h, we should limit #ifdefs as much as possible in C files.

Quoted 2 lines

And use get_accounting() instead of local_paca->accounting in order to be usable on PPC32 as well

Sure thing. I need to move them for other interrupt return in C as well.

Quoted 10 lines
Quoted 10 lines
arch/powerpc/kernel/process.c +10 -0
+
+typedef long (*syscall_fn)(long, long, long, long, long, long);
+
+long system_call_exception(long r3, long r4, long r5, long r6, long r7, long r8, unsigned long r0, struct pt_regs *regs)
+{
+	unsigned long ti_flags;
+	syscall_fn f;
+
+	BUG_ON(!(regs->msr & MSR_PR));
+
Quoted 8 lines

arch/powerpc/kernel/process.c

Quoted 4 lines
arch/powerpc/kernel/process.c +4 -0
+#ifdef CONFIG_PPC_TRANSACTIONAL_MEM
+	if (unlikely(regs->msr & MSR_TS_T))
+		tabort_syscall();
+#endif

MSR_TS_T and tabort_syscall() are declared regardless of CONFIG_PPC_TRANSACTIONAL_MEM so IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) should be used instead of #ifdef

Will do.

Quoted 11 lines

arch/powerpc/kernel/process.c

Quoted 8 lines
arch/powerpc/kernel/process.c +8 -0
+#if defined(CONFIG_VIRT_CPU_ACCOUNTING_NATIVE) && defined(CONFIG_PPC_SPLPAR)
+	if (firmware_has_feature(FW_FEATURE_SPLPAR)) {
+		struct lppaca *lp = get_lppaca();
+
+		if (unlikely(local_paca->dtl_ridx != lp->dtl_idx))
+			accumulate_stolen_time();
+	}
+#endif

Same here, I think everything is available so IS_ENABLED() should be used instead of #if

Will do.

Quoted 7 lines

arch/powerpc/kernel/process.c

Quoted 5 lines
arch/powerpc/kernel/process.c +5 -0
+
+#ifdef CONFIG_PPC_KUAP_DEBUG
+	if (mmu_has_feature(MMU_FTR_RADIX_KUAP))
+		WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED);
+#endif

This should go in a helper in one of the kup/kuap header files.

Will do.

Quoted 5 lines
Quoted 5 lines
arch/powerpc/kernel/process.c +5 -0
+
+	/*
+	 * A syscall should always be called with interrupts enabled
+	 * so we just unconditionally hard-enable here. When some kind
+	 * of irq tracing is used, we additionally check that condition
Quoted 8 lines

arch/powerpc/kernel/process.c

Quoted 6 lines
arch/powerpc/kernel/process.c +6 -0
+	 * is correct
+	 */
+#if defined(CONFIG_PPC_IRQ_SOFT_MASK_DEBUG)
+	WARN_ON(irq_soft_mask_return() != IRQS_ENABLED);
+	WARN_ON(local_paca->irq_happened);
+#endif

Can we use IS_ENABLED() here as well ?

I think so.

Quoted 8 lines

arch/powerpc/kernel/process.c

Quoted 5 lines
arch/powerpc/kernel/process.c +5 -0
+#ifdef CONFIG_ALTIVEC
+	if ((regs->msr & (MSR_FP|MSR_VEC)) != (MSR_FP|MSR_VEC))
+#else
+	if ((regs->msr & MSR_FP) != MSR_FP)
+#endif

Use 'if (IS_ENABLED(CONFIG_ALTIVEC)) / else' instead of an #ifdef/#else/#endif

Yeah that'll be nicer.

Quoted 7 lines

arch/powerpc/kernel/process.c

Quoted 4 lines
arch/powerpc/kernel/process.c +4 -0
+#ifdef CONFIG_PPC_KUAP_DEBUG
+	if (mmu_has_feature(MMU_FTR_RADIX_KUAP))
+		WARN_ON_ONCE(mfspr(SPRN_AMR) != AMR_KUAP_BLOCKED);
+#endif

Same, define a helper in the kuap header files to avoid the #ifdefs and platform specif stuff here.

Will do. Thanks for the quick review.

Thanks,
Nick

author reviewer
#9 lore raw

Re: [PATCH 2/4] powerpc/64: remove support for kernel-mode syscalls

In reply to Nicholas Piggin

Nicholas Piggin's on August 27, 2019 8:20 pm:

Quoted 15 lines

Christophe Leroy's on August 27, 2019 4:13 pm:

Quoted 11 lines

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 4 lines

There is support for the kernel to execute the 'sc 0' instruction and make a system call to itself. This is a relic that is unused in the tree, therefore untested. It's also highly questionable for modules to be doing this.

I like it.

I dropped support for that in PPC32 when I added fast-path syscalls.

Good, then we'll match again.

Quoted 11 lines
Quoted 8 lines

arch/powerpc/kernel/entry_64.S BEGIN_FTR_SECTION · line 89

Quoted 8 lines
arch/powerpc/kernel/entry_64.S +0 -2
-	beq	2f			/* if from kernel mode */
  #ifdef CONFIG_PPC_FSL_BOOK3E
  START_BTB_FLUSH_SECTION
  	BTB_FLUSH(r10)
  END_BTB_FLUSH_SECTION
  #endif
  	ACCOUNT_CPU_USER_ENTRY(r13, r10, r11)
-2:	std	r2,GPR2(r1)

Btw. there is a hunk which restores this optimisation but it leaked into a later patch, I'll move it back here.

I'm wrong. Now I look at it again, the hunk should be removed completely of course.

Thanks,
Nick

#4 lore raw

Re: [PATCH 1/4] powerpc: convert to copy_thread_tls

In reply to Nicholas Piggin

Le 27/08/2019 à 12:13, Nicholas Piggin a écrit :

Quoted 50 lines

Christophe Leroy's on August 27, 2019 4:07 pm:

Quoted 40 lines

Le 27/08/2019 à 05:30, Nicholas Piggin a écrit :

Quoted 37 lines

Commit 3033f14ab78c3 ("clone: support passing tls argument via C rather than pt_regs magic") introduced the HAVE_COPY_THREAD_TLS option. Use it to avoid a subtle assumption about the argument ordering of clone type syscalls.

---
   arch/powerpc/Kconfig          | 1 +
   arch/powerpc/kernel/process.c | 9 +++++----
   2 files changed, 6 insertions(+), 4 deletions(-)
arch/powerpc/Kconfig +1 -0
index d8dcd8820369..7477a3263225 100644
@@ -182,6 +182,7 @@ config PPC
   	select HAVE_STACKPROTECTOR		if PPC64 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r13)
   	select HAVE_STACKPROTECTOR		if PPC32 && $(cc-option,-mstack-protector-guard=tls -mstack-protector-guard-reg=r2)
   	select HAVE_CONTEXT_TRACKING		if PPC64
+	select HAVE_COPY_THREAD_TLS
   	select HAVE_DEBUG_KMEMLEAK
   	select HAVE_DEBUG_STACKOVERFLOW
   	select HAVE_DYNAMIC_FTRACE
arch/powerpc/kernel/process.c +3 -2
index 8fc4de0d22b4..24621e7e5033 100644
@@ -1600,8 +1600,9 @@ static void setup_ksp_vsid(struct task_struct *p, unsigned long sp)
   /*
    * Copy architecture-specific thread state
    */
-int copy_thread(unsigned long clone_flags, unsigned long usp,
-		unsigned long kthread_arg, struct task_struct *p)
+int copy_thread_tls(unsigned long clone_flags, unsigned long usp,
+		unsigned long kthread_arg, struct task_struct *p,
+		unsigned long tls)
   {
Quoted 8 lines

arch/powerpc/kernel/process.c int copy_thread(unsigned long clone_flags, unsigned long usp, · line 1644

Quoted 5 lines
arch/powerpc/kernel/process.c +0 -0
   	struct pt_regs *childregs, *kregs;
   	extern void ret_from_fork(void);
@@ -1642,10 +1643,10 @@ int copy_thread(unsigned long clone_flags, unsigned long usp,
   		if (clone_flags & CLONE_SETTLS) {
   #ifdef CONFIG_PPC64

is_32bit_task() exists and always returns 1 on PPC32 so this gross ifdef in the middle of an if/else is pointless, it should be dropped.

Quoted 1 line

I could do that as another patch in the series.

Yes, would be good, because if I do an independant patch for that it will conflict with your series.

Thanks
Christophe

#18 lore raw

Re: [PATCH 4/4] powerpc/64: system call implement the bulk of the logic in C

In reply to Nicholas Piggin
I love your patch! Yet something to improve:

Hi Nicholas,

I love your patch! Yet something to improve:

[auto build test ERROR on linus/master]
[cannot apply to v5.3-rc6 next-20190827]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Nicholas-Piggin/powerpc-64-syscalls-in-C/20190827-202000
config: powerpc-defconfig (attached as .config)
compiler: powerpc64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=powerpc

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

powerpc64-linux-ld: warning: orphan section .gnu.hash' from linker stubs' being placed in section .gnu.hash'. arch/powerpc/kernel/syscall_64.o: In function .system_call_exception':

>> syscall_64.c:(.text+0x180): undefined reference to `.tabort_syscall'

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#5 lore raw

Re: [PATCH 1/4] powerpc: convert to copy_thread_tls

In reply to Nicholas Piggin
Quoted 6 lines · Nicholas Piggin

Commit 3033f14ab78c3 ("clone: support passing tls argument via C rather than pt_regs magic") introduced the HAVE_COPY_THREAD_TLS option. Use it to avoid a subtle assumption about the argument ordering of clone type syscalls.

Patches 1 & 2 applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/facd04a904ff6cdc6ee85d6e85d500f478a1bec4

cheers