powerpc: merge 32-bit and 64-bit _switch implementation
Nicholas Piggin
reviewerPATCH 1/2 powerpc: merge 32-bit and 64-bit _switch implementation
The _switch stack frame setup are substantially the same, so are the comments. The difference in how the stack and current are switched, and other hardware and software housekeeping is done is moved into macros.
---
These patches are mostly just shuffling code around. Better? Worse?
Thanks,
Nick
arch/powerpc/kernel/Makefile | 2 +- arch/powerpc/kernel/entry_32.S | 57 -------- arch/powerpc/kernel/entry_64.S | 220 ---------------------------- arch/powerpc/kernel/switch.S | 260 +++++++++++++++++++++++++++++++++ 4 files changed, 261 insertions(+), 278 deletions(-) create mode 100644 arch/powerpc/kernel/switch.S
arch/powerpc/kernel/Makefile +1 -1
@@ -68,7 +68,7 @@ CFLAGS_REMOVE_syscall.o = -fstack-protector -fstack-protector-strong CFLAGS_syscall.o += -fno-stack-protector #endif -obj-y := cputable.o syscalls.o \ +obj-y := cputable.o syscalls.o switch.o \ irq.o align.o signal_$(BITS).o pmc.o vdso.o \ process.o systbl.o idle.o \ signal.o sysfs.o cacheinfo.o time.o \
arch/powerpc/kernel/entry_32.S +0 -57
63 lines not on this page · raw message
arch/powerpc/kernel/entry_64.S +0 -220
234 lines not on this page · raw message
arch/powerpc/kernel/switch.S new file +260 -0
260 lines not on this page · raw message
Signature · 1 line
2.37.2
Nicholas Piggin
reviewerPATCH 2/2 powerpc/64: Rename entry_64.S to prom_entry.S
This file contains only the enter_prom implementation now. Trim includes and update header comment while we're here.
---
arch/powerpc/kernel/Makefile | 8 +++--
.../kernel/{entry_64.S => prom_entry.S} | 30 ++-----------------
scripts/head-object-list.txt | 2 +-
3 files changed, 9 insertions(+), 31 deletions(-)
rename arch/powerpc/kernel/{entry_64.S => prom_entry.S} (73%)arch/powerpc/kernel/Makefile +5 -3
@@ -209,10 +209,12 @@ CFLAGS_paca.o += -fno-stack-protector obj-$(CONFIG_PPC_FPU) += fpu.o obj-$(CONFIG_ALTIVEC) += vector.o -obj-$(CONFIG_PPC64) += entry_64.o -obj-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init.o -extra-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init_check +ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE +obj-y += prom_init.o +obj-$(CONFIG_PPC64) += prom_entry.o +extra-y += prom_init_check +endif quiet_cmd_prom_init_check = PROMCHK $@ cmd_prom_init_check = $(CONFIG_SHELL) $< "$(NM)" $(obj)/prom_init.o; touch $@
arch/powerpc/kernel/prom_entry.S renamed from arch/powerpc/kernel/entry_64.S +3 -27
@@ -10,41 +10,17 @@ * Copyright (C) 1996 Paul Mackerras. * MPC8xx modifications Copyright (C) 1997 Dan Malek ([email protected]). * - * This file contains the system call entry code, context switch - * code, and exception/interrupt return code for PowerPC. + * This file contains the prom entry code. */ - -#include <linux/errno.h> -#include <linux/err.h> -#include <asm/cache.h> -#include <asm/unistd.h> -#include <asm/processor.h> -#include <asm/page.h> -#include <asm/mmu.h> -#include <asm/thread_info.h> -#include <asm/code-patching-asm.h> -#include <asm/ppc_asm.h> #include <asm/asm-offsets.h> -#include <asm/cputable.h> -#include <asm/firmware.h> -#include <asm/bug.h> -#include <asm/ptrace.h> -#include <asm/irqflags.h> -#include <asm/hw_irq.h> -#include <asm/context_tracking.h> -#include <asm/ppc-opcode.h> -#include <asm/barrier.h> -#include <asm/export.h> -#include <asm/asm-compat.h> #ifdef CONFIG_PPC_BOOK3S #include <asm/exception-64s.h> #else #include <asm/exception-64e.h> #endif -#include <asm/feature-fixups.h> -#include <asm/kup.h> +#include <asm/ppc_asm.h> - .section ".text" +.section ".text","ax",@progbits _GLOBAL(enter_prom) mflr r0
scripts/head-object-list.txt +1 -1
@@ -34,7 +34,7 @@ arch/powerpc/kernel/head_64.o arch/powerpc/kernel/head_8xx.o arch/powerpc/kernel/head_85xx.o arch/powerpc/kernel/head_book3s_32.o -arch/powerpc/kernel/entry_64.o +arch/powerpc/kernel/prom_entry.o arch/powerpc/kernel/fpu.o arch/powerpc/kernel/vector.o arch/powerpc/kernel/prom_init.o
Signature · 1 line
2.37.2
Re: [PATCH 2/2] powerpc/64: Rename entry_64.S to prom_entry.S
Le 25/03/2023 à 14:06, Nicholas Piggin a écrit :
Quoted 16 lines
This file contains only the
enter_promimplementation now. Trim includes and update header comment while we're here.Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/kernel/Makefile | 8 +++-- .../kernel/{entry_64.S => prom_entry.S} | 30 ++----------------- scripts/head-object-list.txt | 2 +- 3 files changed, 9 insertions(+), 31 deletions(-)rename
arch/powerpc/kernel/{entry_64.S=>prom_entry.S} (73%)arch/powerpc/kernel/Makefile +0
-0
arch/powerpc/kernel/Makefile CFLAGS_paca.o += -fno-stack-protector · line 213
Quoted 8 lines
arch/powerpc/kernel/Makefile +1
-3@@ -209,10 +209,12 @@ CFLAGS_paca.o += -fno-stack-protector obj-$(CONFIG_PPC_FPU) += fpu.o obj-$(CONFIG_ALTIVEC) += vector.o -obj-$(CONFIG_PPC64) += entry_64.o -obj-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init.o -extra-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init_check +ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINE
You don't need that ifdef construct, you can do:
obj64-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_entry.o
arch/powerpc/kernel/Makefile CFLAGS_paca.o += -fno-stack-protector · line 220
Quoted 7 lines
arch/powerpc/kernel/Makefile +4
-0+obj-y += prom_init.o +obj-$(CONFIG_PPC64) += prom_entry.o +extra-y += prom_init_check +endif quiet_cmd_prom_init_check = PROMCHK $@ cmd_prom_init_check = $(CONFIG_SHELL) $< "$(NM)" $(obj)/prom_init.o; touch $@
Christophe
Nicholas Piggin
reviewerRe: [PATCH 2/2] powerpc/64: Rename entry_64.S to prom_entry.S
Quoted 25 lines · Christophe Leroy
Le 25/03/2023 à 14:06, Nicholas Piggin a écrit :
Quoted 22 lines
This file contains only the
enter_promimplementation now. Trim includes and update header comment while we're here.Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/kernel/Makefile | 8 +++-- .../kernel/{entry_64.S => prom_entry.S} | 30 ++----------------- scripts/head-object-list.txt | 2 +- 3 files changed, 9 insertions(+), 31 deletions(-)rename
arch/powerpc/kernel/{entry_64.S=>prom_entry.S} (73%)arch/powerpc/kernel/Makefile +0
-2@@ -209,10 +209,12 @@ CFLAGS_paca.o += -fno-stack-protector obj-$(CONFIG_PPC_FPU) += fpu.o obj-$(CONFIG_ALTIVEC) += vector.o -obj-$(CONFIG_PPC64) += entry_64.o -obj-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init.o
Quoted 6 lines
arch/powerpc/kernel/Makefile CFLAGS_paca.o += -fno-stack-protector · line 213
Quoted 2 lines
arch/powerpc/kernel/Makefile +1
-1-extra-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init_check +ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINEYou don't need that ifdef construct, you can do:
obj64-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_entry.o
Nice. So that could have been obj64-y from the start?
Thanks,
Nick
Quoted 11 lines
arch/powerpc/kernel/Makefile CFLAGS_paca.o += -fno-stack-protector · line 220
Quoted 8 lines
arch/powerpc/kernel/Makefile +4
-0+obj-y += prom_init.o +obj-$(CONFIG_PPC64) += prom_entry.o +extra-y += prom_init_check +endif quiet_cmd_prom_init_check = PROMCHK $@ cmd_prom_init_check = $(CONFIG_SHELL) $< "$(NM)" $(obj)/prom_init.o; touch $@Christophe
Re: [PATCH 2/2] powerpc/64: Rename entry_64.S to prom_entry.S
Le 28/03/2023 à 08:51, Nicholas Piggin a écrit :
Quoted 26 lines · Christophe Leroy
Quoted 25 lines
Le 25/03/2023 à 14:06, Nicholas Piggin a écrit :
Quoted 22 lines
This file contains only the
enter_promimplementation now. Trim includes and update header comment while we're here.Signed-off-by Nicholas Piggin <[email protected]>--- arch/powerpc/kernel/Makefile | 8 +++-- .../kernel/{entry_64.S => prom_entry.S} | 30 ++----------------- scripts/head-object-list.txt | 2 +- 3 files changed, 9 insertions(+), 31 deletions(-)rename
arch/powerpc/kernel/{entry_64.S=>prom_entry.S} (73%)arch/powerpc/kernel/Makefile +0
-2@@ -209,10 +209,12 @@ CFLAGS_paca.o += -fno-stack-protector obj-$(CONFIG_PPC_FPU) += fpu.o obj-$(CONFIG_ALTIVEC) += vector.o -obj-$(CONFIG_PPC64) += entry_64.o -obj-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init.o
Quoted 8 lines
Quoted 6 lines
arch/powerpc/kernel/Makefile CFLAGS_paca.o += -fno-stack-protector · line 213
Quoted 2 lines
arch/powerpc/kernel/Makefile +1
-1-extra-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_init_check +ifdef CONFIG_PPC_OF_BOOT_TRAMPOLINEYou don't need that ifdef construct, you can do:
obj64-$(CONFIG_PPC_OF_BOOT_TRAMPOLINE) += prom_entry.o
Nice. So that could have been obj64-y from the start?
Yes, allthought it is not used that way in ppc/kernel/Makefile:
$ git grep -e obj64 -e obj32 arch/powerpc/kernel/Makefile arch/powerpc/kernel/Makefile:obj64-$(CONFIG_HIBERNATION) += swsusp_asm64.o arch/powerpc/kernel/Makefile:obj64-$(CONFIG_AUDIT) += compat_audit.o arch/powerpc/kernel/Makefile:obj64-$(CONFIG_PPC_TRANSACTIONAL_MEM) += tm.o arch/powerpc/kernel/Makefile:obj-$(CONFIG_PPC64) += $(obj64-y) arch/powerpc/kernel/Makefile:obj-$(CONFIG_PPC32) += $(obj32-y)
But it is in ppc/lib/Makefile:
$ git grep -e obj64 -e obj32 arch/powerpc/lib/Makefile arch/powerpc/lib/Makefile:obj64-y += copypage_64.o copyuser_64.o mem_64.o hweight_64.o \ arch/powerpc/lib/Makefile:obj64-$(CONFIG_SMP) += locks.o arch/powerpc/lib/Makefile:obj64-$(CONFIG_ALTIVEC) += vmx-helper.o arch/powerpc/lib/Makefile:obj64-$(CONFIG_KPROBES_SANITY_TEST) += test_emulate_step.o \ arch/powerpc/lib/Makefile:obj64-y += quad.o arch/powerpc/lib/Makefile:obj-$(CONFIG_PPC64) += $(obj64-y)
Christophe
Le 25/03/2023 à 14:06, Nicholas Piggin a écrit :
Quoted 8 lines
The
_switchstack frame setup are substantially the same, so are the comments. The difference in how the stack and current are switched, and other hardware and software housekeeping is done is moved into macros.Signed-off-by Nicholas Piggin <[email protected]>---
These patches are mostly just shuffling code around. Better? Worse?
I find it nice, at least for PPC32 part.
For PPC32 generated code is almost the same, only a few reordering at the start of the function.
Before the change I have:
00000238 <_switch>:
238: 94 21 ff 30 stwu r1,-208(r1) 23c: 7c 08 02 a6 mflr r0 240: 90 01 00 d4 stw r0,212(r1) 244: 91 a1 00 44 stw r13,68(r1) ... 28c: 93 e1 00 8c stw r31,140(r1) 290: 90 01 00 90 stw r0,144(r1) 294: 7d 40 00 26 mfcr r10 298: 91 41 00 a8 stw r10,168(r1) 29c: 90 23 00 00 stw r1,0(r3) 2a0: 3c 04 40 00 addis r0,r4,16384 2a4: 7c 13 43 a6 mtsprg 3,r0
...
After the change I have:
00000000 <_switch>:
0: 7c 08 02 a6 mflr r0
4: 90 01 00 04 stw r0,4(r1)
8: 94 21 ff 30 stwu r1,-208(r1)
c: 90 23 00 00 stw r1,0(r3)
10: 91 a1 00 44 stw r13,68(r1)
...
58: 93 e1 00 8c stw r31,140(r1)
5c: 90 01 00 90 stw r0,144(r1)
60: 7c 00 00 26 mfcr r0
64: 90 01 00 a8 stw r0,168(r1)
68: 3c 04 40 00 addis r0,r4,16384
6c: 7c 13 43 a6 mtsprg 3,r0...
Everything else is identical.
Not sure, maybe re-using r1 immediately after stwu will introduce latency.
Christophe
Nicholas Piggin
reviewerQuoted 17 lines · Christophe Leroy
Le 25/03/2023 à 14:06, Nicholas Piggin a écrit :
Quoted 8 lines
The
_switchstack frame setup are substantially the same, so are the comments. The difference in how the stack and current are switched, and other hardware and software housekeeping is done is moved into macros.Signed-off-by Nicholas Piggin <[email protected]>---
These patches are mostly just shuffling code around. Better? Worse?I find it nice, at least for PPC32 part.
For PPC32 generated code is almost the same, only a few reordering at the start of the function.
Quoted 7 lines
Before the change I have:
00000238 <
_switch>:238: 94 21 ff 30 stwu r1,-208(r1) 23c: 7c 08 02 a6 mflr r0 240: 90 01 00 d4 stw r0,212(r1) 244: 91 a1 00 44 stw r13,68(r1)
Hmm, this is how GCC seems to emits stack prologue code for ppc32.
On ppc64 the mflr r0 comes first, then the non-volatile register saving, then the LR save, then ther r1 stdu.
Seems a bit pointless to have to different implementations. I think we'd like to have LR saved before r1 though, otherwise you get an unreliable backtrace in your last 2 stack frames instead of just the last one, don't you?
Thanks,
Nick