target/ppc: Allow privileged access to SPR_PCR
PATCH v2 1/1 target/ppc: Allow privileged access to SPR_PCR
The powerpc Linux kernel[1] and skiboot firmware[2] recently gained changes that cause the Processor Compatibility Register (PCR) SPR to be cleared.
These changes cause Linux to fail to boot on the Qemu powernv machine with an error:
Trying to write privileged spr 338 (0x152) at 0000000030017f0c
With this patch Qemu makes this register available as a hypervisor privileged register.
Note that bits set in this register disable features of the processor. Currently the only register state that is supported is when the register is zeroed (enable all features). This is sufficient for guests to once again boot.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://patchwork.ozlabs.org/patch/915932/
---
v2:
- Change error message to say Invalid instead of Unimplemented
- Fix compile warning on other powerpc targets, thanks patchew
--- target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 10 ++++++++++ target/ppc/translate_init.inc.c | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-)
target/ppc/helper.h +1 -0
@@ -17,6 +17,7 @@ DEF_HELPER_2(pminsn, void, env, i32) DEF_HELPER_1(rfid, void, env) DEF_HELPER_1(hrfid, void, env) DEF_HELPER_2(store_lpcr, void, env, tl) +DEF_HELPER_2(store_pcr, void, env, tl)#endif DEF_HELPER_1(check_tlb_flush_local, void, env)DEF_HELPER_1 (check_tlb_flush_global, void, env)
target/ppc/misc_helper.c +10 -0
@@ -20,6 +20,7 @@#include "cpu.h" #include "exec/exec-all.h" #include "exec/helper-proto.h" +#include "qemu/error-report.h" #include "helper_regs.h"
@@ -98,6 +99,15 @@ void helper_store_ptcr(CPUPPCState *env, target_ulong val) tlb_flush(CPU(cpu)); } } + +void helper_store_pcr (CPUPPCState *env,target_ulong value) +{ +if (value !=0 ) { +error_report ("Invalid PCR value 0x" TARGET_FMT_lx, value); +return ; + } + env->spr[SPR_PCR ] = value; +}#endif /* defined(TARGET_PPC64) */ void helper_store_pidr (CPUPPCState *env,target_ulong val)
target/ppc/translate_init.inc.c +7 -2
@@ -424,6 +424,10 @@ static void spr_write_ptcr(DisasContext *ctx, int sprn, int gprn)gen_helper_store_ptcr (cpu_env, cpu_gpr[gprn]); } +static void spr_write_pcr (DisasContext *ctx,int sprn,int gprn) +{ +gen_helper_store_pcr (cpu_env, cpu_gpr[gprn]); +}#endif #endif
@@ -7957,11 +7961,12 @@ static void gen_spr_power6_common(CPUPPCState *env)#endif /* * Register PCR to report POWERPC_EXCP_PRIV_REG instead of -* POWERPC_EXCP_INVAL_SPR. +* POWERPC_EXCP_INVAL_SPR in userspace. Permit hypervisor access. */ -spr_register (env,SPR_PCR ,"PCR" , +spr_register_hv (env,SPR_PCR ,"PCR" ,SPR_NOACCESS ,SPR_NOACCESS ,SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_pcr,0x00000000 ); }
Signature · 1 line
2.17.0
Quoted 19 lines · On Thu, 31 May 2018 22:34:29 +0930 Joel Stanley <[email protected]> wrote:
The powerpc Linux kernel[1] and skiboot firmware[2] recently gained changes that cause the Processor Compatibility Register (PCR) SPR to be cleared.
These changes cause Linux to fail to boot on the Qemu powernv machine with an error:
Trying to write privileged spr 338 (
0x152) at0000000030017f0cWith this patch Qemu makes this register available as a hypervisor privileged register.
Note that bits set in this register disable features of the processor. Currently the only register state that is supported is when the register is zeroed (enable all features). This is sufficient for guests to once again boot.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://patchwork.ozlabs.org/patch/915932/
Quoted 6 lines
Signed-off-by Joel Stanley <[email protected]>---
v2:
- Change error message to say Invalid instead of Unimplemented
- Fix compile warning on other powerpc targets, thanks patchew
---
Quoted 75 lines
target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 10 ++++++++++ target/ppc/translate_init.inc.c | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-)target/ppc/helper.h +1
-0@@ -17,6 +17,7 @@ DEF_HELPER_2(pminsn, void, env, i32) DEF_HELPER_1(rfid, void, env) DEF_HELPER_1(hrfid, void, env) DEF_HELPER_2(store_lpcr, void, env, tl) +DEF_HELPER_2(store_pcr, void, env, tl)#endif DEF_HELPER_1(check_tlb_flush_local, void, env)DEF_HELPER_1 (check_tlb_flush_global, void, env)target/ppc/misc_helper.c +10
-0@@ -20,6 +20,7 @@#include "cpu.h" #include "exec/exec-all.h" #include "exec/helper-proto.h" +#include "qemu/error-report.h" #include "helper_regs.h" @@ -98,6 +99,15 @@ void helper_store_ptcr(CPUPPCState *env, target_ulong val) tlb_flush(CPU(cpu)); } } + +void helper_store_pcr (CPUPPCState *env,target_ulong value) +{ +if (value !=0 ) { +error_report ("Invalid PCR value 0x" TARGET_FMT_lx, value); +return ; + } + env->spr[SPR_PCR ] = value; +}#endif /* defined(TARGET_PPC64) */ void helper_store_pidr (CPUPPCState *env,target_ulong val)target/ppc/translate_init.inc.c +7
-2@@ -424,6 +424,10 @@ static void spr_write_ptcr(DisasContext *ctx, int sprn, int gprn)gen_helper_store_ptcr (cpu_env, cpu_gpr[gprn]); } +static void spr_write_pcr (DisasContext *ctx,int sprn,int gprn) +{ +gen_helper_store_pcr (cpu_env, cpu_gpr[gprn]); +}#endif #endif @@ -7957,11 +7961,12 @@ static void gen_spr_power6_common(CPUPPCState *env)#endif /* * Register PCR to report POWERPC_EXCP_PRIV_REG instead of -* POWERPC_EXCP_INVAL_SPR. +* POWERPC_EXCP_INVAL_SPR in userspace. Permit hypervisor access. */ -spr_register (env,SPR_PCR ,"PCR" , +spr_register_hv (env,SPR_PCR ,"PCR" ,SPR_NOACCESS ,SPR_NOACCESS ,SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_pcr,0x00000000 ); }
Quoted 55 lines · Joel Stanley
The powerpc Linux kernel[1] and skiboot firmware[2] recently gained changes that cause the Processor Compatibility Register (PCR) SPR to be cleared.
These changes cause Linux to fail to boot on the Qemu powernv machine with an error:
Trying to write privileged spr 338 (
0x152) at0000000030017f0cWith this patch Qemu makes this register available as a hypervisor privileged register.
Note that bits set in this register disable features of the processor. Currently the only register state that is supported is when the register is zeroed (enable all features). This is sufficient for guests to once again boot.
[1] https://lkml.kernel.org/r/[email protected]
[2] https://patchwork.ozlabs.org/patch/915932/Signed-off-by Joel Stanley <[email protected]>---
v2:
- Change error message to say Invalid instead of Unimplemented
- Fix compile warning on other powerpc targets, thanks patchew--- target/ppc/helper.h | 1 + target/ppc/misc_helper.c | 10 ++++++++++ target/ppc/translate_init.inc.c | 9 +++++++-- 3 files changed, 18 insertions(+), 2 deletions(-)target/ppc/helper.h +1
-0@@ -17,6 +17,7 @@ DEF_HELPER_2(pminsn, void, env, i32) DEF_HELPER_1(rfid, void, env) DEF_HELPER_1(hrfid, void, env) DEF_HELPER_2(store_lpcr, void, env, tl) +DEF_HELPER_2(store_pcr, void, env, tl)#endif DEF_HELPER_1(check_tlb_flush_local, void, env)DEF_HELPER_1 (check_tlb_flush_global, void, env)target/ppc/misc_helper.c +1
-0@@ -20,6 +20,7 @@#include "cpu.h" #include "exec/exec-all.h" #include "exec/helper-proto.h" +#include "qemu/error-report.h" #include "helper_regs.h"
target/ppc/misc_helper.c void helper_store_ptcr(CPUPPCState *env, target_ulong val) · line 108
Quoted 10 lines
target/ppc/misc_helper.c +7
-0@@ -98,6 +99,15 @@ void helper_store_ptcr(CPUPPCState *env, target_ulong val)tlb_flush (CPU (cpu)); } } + +void helper_store_pcr (CPUPPCState *env,target_ulong value) +{ +if (value !=0 ) { +error_report ("Invalid PCR value 0x" TARGET_FMT_lx, value); +return ; + }
I don't see a lot of point to this check. For now the only user just clears the PCR, but why limit yourself to that explicitly?
target/ppc/misc_helper.c void helper_store_ptcr(CPUPPCState *env, target_ulong val) · line 109
Quoted 1 line
target/ppc/misc_helper.c +1
-0+ env->spr[SPR_PCR ] = value;
You definitely should be masking against pcr_mask too.
Quoted 34 lines
target/ppc/misc_helper.c +1
-0+}#endif /* defined(TARGET_PPC64) */ void helper_store_pidr (CPUPPCState *env,target_ulong val)target/ppc/translate_init.inc.c +7
-2@@ -424,6 +424,10 @@ static void spr_write_ptcr(DisasContext *ctx, int sprn, int gprn)gen_helper_store_ptcr (cpu_env, cpu_gpr[gprn]); } +static void spr_write_pcr (DisasContext *ctx,int sprn,int gprn) +{ +gen_helper_store_pcr (cpu_env, cpu_gpr[gprn]); +}#endif #endif @@ -7957,11 +7961,12 @@ static void gen_spr_power6_common(CPUPPCState *env)#endif /* * Register PCR to report POWERPC_EXCP_PRIV_REG instead of -* POWERPC_EXCP_INVAL_SPR. +* POWERPC_EXCP_INVAL_SPR in userspace. Permit hypervisor access. */ -spr_register (env,SPR_PCR ,"PCR" , +spr_register_hv (env,SPR_PCR ,"PCR" ,SPR_NOACCESS ,SPR_NOACCESS ,SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_pcr,0x00000000 ); }
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Quoted 15 lines · David Gibson
target/ppc/misc_helper.c void helper_store_ptcr(CPUPPCState *env, target_ulong val) · line 108
Quoted 11 lines · Joel Stanley
target/ppc/misc_helper.c +7
-0@@ -98,6 +99,15 @@ void helper_store_ptcr(CPUPPCState *env, target_ulong val)tlb_flush (CPU (cpu)); } } + +void helper_store_pcr (CPUPPCState *env,target_ulong value) +{ +if (value !=0 ) { +error_report ("Invalid PCR value 0x" TARGET_FMT_lx, value); +return ; + }I don't see a lot of point to this check. For now the only user just clears the PCR, but why limit yourself to that explicitly?
As we're not emulating the features of the register when the value is non-zero, I thought it would make make sense to do something.
I'll drop it in v3.
Quoted 4 lines
target/ppc/misc_helper.c void helper_store_ptcr(CPUPPCState *env, target_ulong val) · line 109
Quoted 2 lines
target/ppc/misc_helper.c +1
-0+ env->spr[SPR_PCR ] = value;You definitely should be masking against
pcr_masktoo.
Okay. Thanks for the review.
Cheers,
Joel
Quoted 17 lines · Joel Stanley
Quoted 15 lines · David Gibson
target/ppc/misc_helper.c void helper_store_ptcr(CPUPPCState *env, target_ulong val) · line 108
Quoted 11 lines · Joel Stanley
target/ppc/misc_helper.c +7
-0@@ -98,6 +99,15 @@ void helper_store_ptcr(CPUPPCState *env, target_ulong val)tlb_flush (CPU (cpu)); } } + +void helper_store_pcr (CPUPPCState *env,target_ulong value) +{ +if (value !=0 ) { +error_report ("Invalid PCR value 0x" TARGET_FMT_lx, value); +return ; + }I don't see a lot of point to this check. For now the only user just clears the PCR, but why limit yourself to that explicitly?
Quoted 2 lines
As we're not emulating the features of the register when the value is non-zero, I thought it would make make sense to do something.
Ah.. I see what you mean.
Ok, the check makes sense in that case - but it needs a comment saying it should go away once we actually put the proper PCR checks in the various bits of TCG that should have them.
Quoted 10 lines
I'll drop it in v3.
Quoted 4 lines
target/ppc/misc_helper.c void helper_store_ptcr(CPUPPCState *env, target_ulong val) · line 109
Quoted 2 lines
target/ppc/misc_helper.c +1
-0+ env->spr[SPR_PCR ] = value;You definitely should be masking against
pcr_masktoo.Okay. Thanks for the review.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson