powerpc/64s: system call scv tabort fix for corrupt irq soft-mask state
Nicholas Piggin
reviewerPATCH v2 1/2 powerpc/64s: system call scv tabort fix for corrupt irq soft-mask state
If a system call is made with a transaction active, the kernel immediately aborts it and returns. scv system calls disable irqs even earlier in their interrupt handler, and tabort_syscall does not fix this up.
This can result in irq soft-mask state being messed up on the next kernel entry, and crashing at BUG_ON(arch_irq_disabled_regs(regs)) in the kernel exit handlers, or possibly worse.
Fix this by having tabort_syscall setting irq soft-mask back to enabled (which requires MSR[EE] be disabled first).
---
Tested the wrong kernel before sending v1 and missed a bug, sorry.
arch/powerpc/kernel/interrupt_64.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
arch/powerpc/kernel/interrupt_64.S +7 -1
@@ -428,16 +428,22 @@ RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) #ifdef CONFIG_PPC_TRANSACTIONAL_MEM tabort_syscall: _ASM_NOKPROBE_SYMBOL(tabort_syscall) - /* Firstly we need to enable TM in the kernel */ + /* We need to enable TM in the kernel, and disable EE (for scv) */ mfmsr r10 li r9, 1 rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG + LOAD_REG_IMMEDIATE(r9, MSR_EE) + andc r10, r10, r9 mtmsrd r10, 0 /* tabort, this dooms the transaction, nothing else */ li r9, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT) TABORT(R9) + /* scv has disabled irqs so must re-enable. sc just remains enabled */ + li r9,IRQS_ENABLED + stb r9,PACAIRQSOFTMASK(r13) + /* * Return directly to userspace. We have corrupted user register state, * but userspace will never see that register state. Execution will
Signature · 1 line
2.23.0
Nicholas Piggin
reviewerPATCH v2 2/2 selftests/powerpc: Add scv versions of the basic TM syscall tests
The basic TM vs syscall test code hard codes an sc instruction for the system call, which fails to cover scv even when the userspace libc has support for it.
Duplicate the tests with hard coded scv variants so both are tested when possible.
--- .../selftests/powerpc/tm/tm-syscall-asm.S | 46 +++++++++++++++++++ .../testing/selftests/powerpc/tm/tm-syscall.c | 36 ++++++++++++--- 2 files changed, 75 insertions(+), 7 deletions(-)
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +46 -0
@@ -2,6 +2,10 @@ #include <ppc-asm.h> #include <asm/unistd.h> +/* ppc-asm.h does not define r0 or r1 */ +#define r0 0 +#define r1 1 + .text FUNC_START(getppid_tm_active) tbegin.
@@ -26,3 +30,45 @@ FUNC_START(getppid_tm_suspended) 1: li r3, -1 blr + +FUNC_START(getppid_scv_tm_active) + mflr r0 + std r0,16(r1) + stdu r1,-32(r1) + tbegin. + beq 1f + li r0, __NR_getppid + scv 0 + tend. + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr +1: + li r3, -1 + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr + +FUNC_START(getppid_scv_tm_suspended) + mflr r0 + std r0,16(r1) + stdu r1,-32(r1) + tbegin. + beq 1f + li r0, __NR_getppid + tsuspend. + scv 0 + tresume. + tend. + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr +1: + li r3, -1 + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr
tools/testing/selftests/powerpc/tm/tm-syscall.c +29 -7
@@ -19,24 +19,37 @@#include "utils.h" #include "tm.h" +#ifndef PPC_FEATURE2_SCV +#define PPC_FEATURE2_SCV 0x00100000/* scv syscall */ +#endif +extern int getppid_tm_active (void );extern int getppid_tm_suspended (void ); +extern int getppid_scv_tm_active (void ); +extern int getppid_scv_tm_suspended (void );unsigned retries =0 ;#define TEST_DURATION 10/* seconds */ #define TM_RETRIES 100 -pid_t getppid_tm (bool suspend) +pid_t getppid_tm (bool scv,bool suspend) {int i;pid_t pid;for (i =0 ; i <TM_RETRIES ; i++) { -if (suspend) - pid =getppid_tm_suspended (); -else - pid =getppid_tm_active (); +if (suspend) { +if (scv) + pid =getppid_scv_tm_suspended (); +else + pid =getppid_tm_suspended (); + }else { +if (scv) + pid =getppid_scv_tm_active (); +else + pid =getppid_tm_active (); + }if (pid >=0 )return pid;
@@ -82,15 +95,24 @@ int tm_syscall(void)* Test a syscall within a suspended transaction and verify * that it succeeds. */ -FAIL_IF (getppid_tm (true) ==-1 );/* Should succeed. */ +FAIL_IF (getppid_tm (false, true) ==-1 );/* Should succeed. */ /* * Test a syscall within an active transaction and verify that * it fails with the correct failure code. */ -FAIL_IF (getppid_tm (false) !=-1 );/* Should fail... */ +FAIL_IF (getppid_tm (false, false) !=-1 );/* Should fail... */ FAIL_IF (!failure_is_persistent ());/* ...persistently... */ FAIL_IF (!failure_is_syscall ());/* ...with code syscall. */ + +/* Now do it all again with scv if it is available. */ +if (have_hwcap2 (PPC_FEATURE2_SCV )) { +FAIL_IF (getppid_tm (true, true) ==-1 );/* Should succeed. */ +FAIL_IF (getppid_tm (true, false) !=-1 );/* Should fail... */ +FAIL_IF (!failure_is_persistent ());/* ...persistently... */ +FAIL_IF (!failure_is_syscall ());/* ...with code syscall. */ + } +gettimeofday (&now,0 ); }
Signature · 1 line
2.23.0
Re: [PATCH v2 2/2] selftests/powerpc: Add scv versions of the basic TM syscall tests
Le 01/09/2021 à 18:54, Nicholas Piggin a écrit :
Quoted 18 lines
The basic TM vs syscall test code hard codes an sc instruction for the system call, which fails to cover scv even when the userspace libc has support for it.
Duplicate the tests with hard coded scv variants so both are tested when possible.
Signed-off-by Nicholas Piggin <[email protected]>--- .../selftests/powerpc/tm/tm-syscall-asm.S | 46 +++++++++++++++++++ .../testing/selftests/powerpc/tm/tm-syscall.c | 36 ++++++++++++--- 2 files changed, 75 insertions(+), 7 deletions(-)tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +0
-0
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S line 8
Quoted 7 lines
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +4
-0@@ -2,6 +2,10 @@ #include <ppc-asm.h> #include <asm/unistd.h> +/* ppc-asm.h does not define r0 or r1 */ +#define r0 0 +#define r1 1 +
See https://github.com/gcc-mirror/gcc/blob/master/gcc/config/rs6000/ppc-asm.h
It doesn't not define r1 but it defines r0.
And it defines 'sp' as register 1.
Quoted 124 lines
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +42
-0.text FUNC_START(getppid_tm_active) tbegin.@@ -26,3 +30,45 @@ FUNC_START(getppid_tm_suspended) 1: li r3, -1 blr + +FUNC_START(getppid_scv_tm_active) + mflr r0 + std r0,16(r1) + stdu r1,-32(r1) + tbegin. + beq 1f + li r0, __NR_getppid + scv 0 + tend. + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr +1: + li r3, -1 + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr + +FUNC_START(getppid_scv_tm_suspended) + mflr r0 + std r0,16(r1) + stdu r1,-32(r1) + tbegin. + beq 1f + li r0, __NR_getppid + tsuspend. + scv 0 + tresume. + tend. + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr +1: + li r3, -1 + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blrtools/testing/selftests/powerpc/tm/tm-syscall.c +29
-7@@ -19,24 +19,37 @@#include "utils.h" #include "tm.h" +#ifndef PPC_FEATURE2_SCV +#define PPC_FEATURE2_SCV 0x00100000/* scv syscall */ +#endif +extern int getppid_tm_active (void );extern int getppid_tm_suspended (void ); +extern int getppid_scv_tm_active (void ); +extern int getppid_scv_tm_suspended (void );unsigned retries =0 ;#define TEST_DURATION 10/* seconds */ #define TM_RETRIES 100 -pid_t getppid_tm (bool suspend) +pid_t getppid_tm (bool scv,bool suspend) {int i;pid_t pid;for (i =0 ; i <TM_RETRIES ; i++) { -if (suspend) - pid =getppid_tm_suspended (); -else - pid =getppid_tm_active (); +if (suspend) { +if (scv) + pid =getppid_scv_tm_suspended (); +else + pid =getppid_tm_suspended (); + }else { +if (scv) + pid =getppid_scv_tm_active (); +else + pid =getppid_tm_active (); + }if (pid >=0 )return pid;@@ -82,15 +95,24 @@ int tm_syscall(void)* Test a syscall within a suspended transaction and verify * that it succeeds. */ -FAIL_IF (getppid_tm (true) ==-1 );/* Should succeed. */ +FAIL_IF (getppid_tm (false, true) ==-1 );/* Should succeed. */ /* * Test a syscall within an active transaction and verify that * it fails with the correct failure code. */ -FAIL_IF (getppid_tm (false) !=-1 );/* Should fail... */ +FAIL_IF (getppid_tm (false, false) !=-1 );/* Should fail... */ FAIL_IF (!failure_is_persistent ());/* ...persistently... */ FAIL_IF (!failure_is_syscall ());/* ...with code syscall. */ + +/* Now do it all again with scv if it is available. */ +if (have_hwcap2 (PPC_FEATURE2_SCV )) { +FAIL_IF (getppid_tm (true, true) ==-1 );/* Should succeed. */ +FAIL_IF (getppid_tm (true, false) !=-1 );/* Should fail... */ +FAIL_IF (!failure_is_persistent ());/* ...persistently... */ +FAIL_IF (!failure_is_syscall ());/* ...with code syscall. */ + } +gettimeofday (&now,0 ); }
Nicholas Piggin
reviewerRe: [PATCH v2 2/2] selftests/powerpc: Add scv versions of the basic TM syscall tests
Excerpts from Christophe Leroy's message of September 2, 2021 3:15 am:
Quoted 24 lines
Le 01/09/2021 à 18:54, Nicholas Piggin a écrit :
Quoted 21 lines
The basic TM vs syscall test code hard codes an sc instruction for the system call, which fails to cover scv even when the userspace libc has support for it.
Duplicate the tests with hard coded scv variants so both are tested when possible.
Signed-off-by Nicholas Piggin <[email protected]>--- .../selftests/powerpc/tm/tm-syscall-asm.S | 46 +++++++++++++++++++ .../testing/selftests/powerpc/tm/tm-syscall.c | 36 ++++++++++++--- 2 files changed, 75 insertions(+), 7 deletions(-)tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +0
-0@@ -2,6 +2,10 @@ #include <ppc-asm.h> #include <asm/unistd.h>
Quoted 8 lines
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S line 8
Quoted 4 lines
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +4
-0+/* ppc-asm.h does not define r0 or r1 */ +#define r0 0 +#define r1 1 +See https://github.com/gcc-mirror/gcc/blob/master/gcc/config/rs6000/ppc-asm.h
It doesn't not define r1 but it defines r0.
Oops, I'll fix that.
Quoted 1 line
And it defines 'sp' as register 1.
Does userspace code typically use that? Kernel code AFAIKS does not.
Thanks,
Nick
Michael Ellerman
reviewerRe: [PATCH v2 2/2] selftests/powerpc: Add scv versions of the basic TM syscall tests
Quoted 30 lines · Nicholas Piggin
Excerpts from Christophe Leroy's message of September 2, 2021 3:15 am:
Quoted 29 lines
Le 01/09/2021 à 18:54, Nicholas Piggin a écrit :
Quoted 18 lines
The basic TM vs syscall test code hard codes an sc instruction for the system call, which fails to cover scv even when the userspace libc has support for it.
Duplicate the tests with hard coded scv variants so both are tested when possible.
Signed-off-by Nicholas Piggin <[email protected]>--- .../selftests/powerpc/tm/tm-syscall-asm.S | 46 +++++++++++++++++++ .../testing/selftests/powerpc/tm/tm-syscall.c | 36 ++++++++++++--- 2 files changed, 75 insertions(+), 7 deletions(-)tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +0
-0tools/testing/selftests/powerpc/tm/tm-syscall-asm.S line 8
Quoted 7 lines
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +4
-0@@ -2,6 +2,10 @@ #include <ppc-asm.h> #include <asm/unistd.h> +/* ppc-asm.h does not define r0 or r1 */ +#define r0 0 +#define r1 1 +See https://github.com/gcc-mirror/gcc/blob/master/gcc/config/rs6000/ppc-asm.h
Quoted 7 lines
Quoted 1 line
It doesn't not define r1 but it defines r0.
Oops, I'll fix that.
Quoted 1 line
And it defines 'sp' as register 1.
Does userspace code typically use that? Kernel code AFAIKS does not.
Some does, but it's not used consistently IME.
I'd prefer you just use %r1.
cheers
Michael Ellerman
reviewerRe: [PATCH v2 2/2] selftests/powerpc: Add scv versions of the basic TM syscall tests
In reply to Nicholas PigginQuoted 42 lines · Nicholas Piggin
The basic TM vs syscall test code hard codes an sc instruction for the system call, which fails to cover scv even when the userspace libc has support for it.
Duplicate the tests with hard coded scv variants so both are tested when possible.
Signed-off-by Nicholas Piggin <[email protected]>--- .../selftests/powerpc/tm/tm-syscall-asm.S | 46 +++++++++++++++++++ .../testing/selftests/powerpc/tm/tm-syscall.c | 36 ++++++++++++--- 2 files changed, 75 insertions(+), 7 deletions(-)tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +14
-0@@ -2,6 +2,10 @@ #include <ppc-asm.h> #include <asm/unistd.h> +/* ppc-asm.h does not define r0 or r1 */ +#define r0 0 +#define r1 1 + .text FUNC_START(getppid_tm_active) tbegin.@@ -26,3 +30,45 @@ FUNC_START(getppid_tm_suspended) 1: li r3, -1 blr + +FUNC_START(getppid_scv_tm_active) + mflr r0 + std r0,16(r1) + stdu r1,-32(r1) + tbegin. + beq 1f + li r0, __NR_getppid + scv 0 + tend.
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S FUNC_START(getppid_tm_suspended) · line 52
Quoted 10 lines
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +10
-0+ addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr +1: + li r3, -1 + addi r1,r1,32 + ld r0,16(r1) + mtlr r0 + blr
There's some macros in tools/testing/selftests/powerpc/include/basic_asm.h that can do some of this boiler plate stack setup/teardown.
Incremental diff below to use them, only build tested.
cheers
tools/testing/selftests/powerpc/tm/tm-syscall-asm.S +7 -24
@@ -1,10 +1,5 @@ /* SPDX-License-Identifier: GPL-2.0 */ -#include <ppc-asm.h> -#include <asm/unistd.h> - -/* ppc-asm.h does not define r0 or r1 */ -#define r0 0 -#define r1 1 +#include <basic_asm.h> .text FUNC_START(getppid_tm_active)
@@ -32,29 +27,21 @@ FUNC_START(getppid_tm_suspended) blr FUNC_START(getppid_scv_tm_active) - mflr r0 - std r0,16(r1) - stdu r1,-32(r1) + PUSH_BASIC_STACK(0) tbegin. beq 1f li r0, __NR_getppid scv 0 tend. - addi r1,r1,32 - ld r0,16(r1) - mtlr r0 + POP_BASIC_STACK(0) blr 1: li r3, -1 - addi r1,r1,32 - ld r0,16(r1) - mtlr r0 + POP_BASIC_STACK(0) blr FUNC_START(getppid_scv_tm_suspended) - mflr r0 - std r0,16(r1) - stdu r1,-32(r1) + PUSH_BASIC_STACK(0) tbegin. beq 1f li r0, __NR_getppid
@@ -62,13 +49,9 @@ FUNC_START(getppid_scv_tm_suspended) scv 0 tresume. tend. - addi r1,r1,32 - ld r0,16(r1) - mtlr r0 + POP_BASIC_STACK(0) blr 1: li r3, -1 - addi r1,r1,32 - ld r0,16(r1) - mtlr r0 + POP_BASIC_STACK(0) blr
Le 01/09/2021 à 18:54, Nicholas Piggin a écrit :
Quoted 27 lines
If a system call is made with a transaction active, the kernel immediately aborts it and returns. scv system calls disable irqs even earlier in their interrupt handler, and
tabort_syscalldoes not fix this up.This can result in irq soft-mask state being messed up on the next kernel entry, and crashing at BUG_ON(arch_irq_disabled_regs(regs)) in the kernel exit handlers, or possibly worse.
Fix this by having
tabort_syscallsetting irq soft-mask back to enabled (which requires MSR[EE] be disabled first).Reported-by Eirik Fuller <[email protected]>Fixes 7fa95f9adaee7 ("powerpc/64s: system call support for scv/rfscv instructions")Signed-off-by Nicholas Piggin <[email protected]>---
Tested the wrong kernel before sending v1 and missed a bug, sorry.
arch/powerpc/kernel/interrupt_64.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/powerpc/kernel/interrupt_64.S +0
-0
arch/powerpc/kernel/interrupt_64.S RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) · line 436
Quoted 10 lines
arch/powerpc/kernel/interrupt_64.S +3
-1@@ -428,16 +428,22 @@ RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) #ifdef CONFIG_PPC_TRANSACTIONAL_MEM tabort_syscall: _ASM_NOKPROBE_SYMBOL(tabort_syscall) - /* Firstly we need to enable TM in the kernel */ + /* We need to enable TM in the kernel, and disable EE (for scv) */ mfmsr r10 li r9, 1 rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG + LOAD_REG_IMMEDIATE(r9, MSR_EE) + andc r10, r10, r9
Why not use 'rlwinm' to mask out MSR_EE ?
Something like
rlwinm r10, r10, 0, ~MSR_EE
Quoted 14 lines
arch/powerpc/kernel/interrupt_64.S +4
-0mtmsrd r10, 0 /* tabort, this dooms the transaction, nothing else */ li r9, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT) TABORT(R9) + /* scv has disabled irqs so must re-enable. sc just remains enabled */ + li r9,IRQS_ENABLED + stb r9,PACAIRQSOFTMASK(r13) + /* * Return directly to userspace. We have corrupted user register state, * but userspace will never see that register state. Execution will
Nicholas Piggin
reviewerExcerpts from Christophe Leroy's message of September 2, 2021 3:21 am:
Quoted 43 lines
Le 01/09/2021 à 18:54, Nicholas Piggin a écrit :
Quoted 27 lines
If a system call is made with a transaction active, the kernel immediately aborts it and returns. scv system calls disable irqs even earlier in their interrupt handler, and
tabort_syscalldoes not fix this up.This can result in irq soft-mask state being messed up on the next kernel entry, and crashing at BUG_ON(arch_irq_disabled_regs(regs)) in the kernel exit handlers, or possibly worse.
Fix this by having
tabort_syscallsetting irq soft-mask back to enabled (which requires MSR[EE] be disabled first).Reported-by Eirik Fuller <[email protected]>Fixes 7fa95f9adaee7 ("powerpc/64s: system call support for scv/rfscv instructions")Signed-off-by Nicholas Piggin <[email protected]>---
Tested the wrong kernel before sending v1 and missed a bug, sorry.
arch/powerpc/kernel/interrupt_64.S | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)arch/powerpc/kernel/interrupt_64.S +0
-0arch/powerpc/kernel/interrupt_64.S RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) · line 436
Quoted 10 lines
arch/powerpc/kernel/interrupt_64.S +3
-1@@ -428,16 +428,22 @@ RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) #ifdef CONFIG_PPC_TRANSACTIONAL_MEM tabort_syscall: _ASM_NOKPROBE_SYMBOL(tabort_syscall) - /* Firstly we need to enable TM in the kernel */ + /* We need to enable TM in the kernel, and disable EE (for scv) */ mfmsr r10 li r9, 1 rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG + LOAD_REG_IMMEDIATE(r9, MSR_EE) + andc r10, r10, r9Why not use 'rlwinm' to mask out
MSR_EE?
Quoted 3 lines
Something like
rlwinm r10, r10, 0, ~MSR_EE
Mainly because I'm bad at powerpc assembly. Why do you think I'm trying to change as much as possible to C?
Actually there should really be no need for mfmsr either, I wanted to rewrite the thing entirely as
ld r10,PACAKMSR(r13) LOAD_REG_IMMEDIATE(r9, MSR_TM) or r10,r10,r9 mtmsrd r10
But I thought that's not a minimal bug fix.
Thanks,
Nick
Quoted 16 lines
Quoted 15 lines
arch/powerpc/kernel/interrupt_64.S +4
-0mtmsrd r10, 0 /* tabort, this dooms the transaction, nothing else */ li r9, (TM_CAUSE_SYSCALL|TM_CAUSE_PERSISTENT) TABORT(R9) + /* scv has disabled irqs so must re-enable. sc just remains enabled */ + li r9,IRQS_ENABLED + stb r9,PACAIRQSOFTMASK(r13) + /* * Return directly to userspace. We have corrupted user register state, * but userspace will never see that register state. Execution will
Quoted 11 lines · Nicholas Piggin
Excerpts from Christophe Leroy's message of September 2, 2021 3:21 am:
Quoted 10 lines
arch/powerpc/kernel/interrupt_64.S RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) · line 436
Quoted 7 lines
arch/powerpc/kernel/interrupt_64.S +3
-1- /* Firstly we need to enable TM in the kernel */ + /* We need to enable TM in the kernel, and disable EE (for scv) */ mfmsr r10 li r9, 1 rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG + LOAD_REG_IMMEDIATE(r9, MSR_EE) + andc r10, r10, r9Why not use 'rlwinm' to mask out
MSR_EE?
Quoted 6 lines
Quoted 3 lines
Something like
rlwinm r10, r10, 0, ~MSR_EEMainly because I'm bad at powerpc assembly. Why do you think I'm trying to change as much as possible to C?
The actual bit (bit 31, i.e. with value 1UL << 32) cannot be cleared with rlwinm (only the low 32 bits can). There are many ways to do it using two insns of course.
Quoted 9 lines
Actually there should really be no need for mfmsr either, I wanted to rewrite the thing entirely as
ld r10,PACAKMSR(r13) LOAD_REG_IMMEDIATE(r9, MSR_TM) or r10,r10,r9 mtmsrd r10But I thought that's not a minimal bug fix.
That (LOAD_REG_IMMEDIATE+or) can be done with just two insns, not three as written:
li r0,1
rldimi r10,r0,32,31
(you can write that last insns as
rldimi r10,r0,MSR_TM_LG,MSR_TM_LG-1
if you insist :-) )
It isn't like a few integer computational insns will kill you here of course, there are much more important cycles to shave off :-)
Segher
Quoted 14 lines · Segher Boessenkool
Quoted 13 lines · Nicholas Piggin
Excerpts from Christophe Leroy's message of September 2, 2021 3:21 am:
Quoted 12 lines
arch/powerpc/kernel/interrupt_64.S RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) · line 436
Quoted 7 lines
arch/powerpc/kernel/interrupt_64.S +3
-1- /* Firstly we need to enable TM in the kernel */ + /* We need to enable TM in the kernel, and disable EE (for scv) */ mfmsr r10 li r9, 1 rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG + LOAD_REG_IMMEDIATE(r9, MSR_EE) + andc r10, r10, r9Why not use 'rlwinm' to mask out
MSR_EE?Something like
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
rlwinm r10, r10, 0, ~MSR_EEMainly because I'm bad at powerpc assembly. Why do you think I'm trying to change as much as possible to C?
The actual bit (bit 31, i.e. with value 1UL << 32) cannot be cleared with rlwinm (only the low 32 bits can). There are many ways to do it using two insns of course.
Wow I misread that, you want to clear MSR[EE] really, not MSR[TM].
You cannot use rlwinm and keep the high 32 bits of the target register intact. You either clear all to 0 or set them to a copy of the rotated value in the low 32 bits.
Segher
Le 03/09/2021 à 00:20, Segher Boessenkool a écrit :
Quoted 24 lines · Segher Boessenkool
Quoted 14 lines · Nicholas Piggin
Quoted 13 lines
Excerpts from Christophe Leroy's message of September 2, 2021 3:21 am:
Quoted 12 lines
arch/powerpc/kernel/interrupt_64.S RESTART_TABLE(.Lsyscall_rst_start, .Lsyscall_rst_end, syscall_restart) · line 436
Quoted 7 lines
arch/powerpc/kernel/interrupt_64.S +3
-1- /* Firstly we need to enable TM in the kernel */ + /* We need to enable TM in the kernel, and disable EE (for scv) */ mfmsr r10 li r9, 1 rldimi r10, r9, MSR_TM_LG, 63-MSR_TM_LG + LOAD_REG_IMMEDIATE(r9, MSR_EE) + andc r10, r10, r9Why not use 'rlwinm' to mask out
MSR_EE?Something like
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
rlwinm r10, r10, 0, ~MSR_EEMainly because I'm bad at powerpc assembly. Why do you think I'm trying to change as much as possible to C?
The actual bit (bit 31, i.e. with value 1UL << 32) cannot be cleared with rlwinm (only the low 32 bits can). There are many ways to do it using two insns of course.
Quoted 6 lines
Wow I misread that, you want to clear MSR[EE] really, not MSR[TM].
You cannot use rlwinm and keep the high 32 bits of the target register intact. You either clear all to 0 or set them to a copy of the rotated value in the low 32 bits.
Oops, my mistake. When I tested it in C to see what was generated by GCC I forgot the ~ so I got rlwinm r3,r3,0,16,16 and didn't realise it was different from rlwinm r3,r3,0,~(1<<15)
By the way it would be more explicit if objdump could display the mask instead of the mask boundaries. Is there a way to do that ?
Christophe