powerpc/64s: Clear PCR on boot
Quoted 9 lines · Michael Neuling
Clear the PCR (Processor Compatibility Register) on boot to ensure we are not running in a compatibility mode.
We've seen this cause problems when a crash (and kdump) occurs while running compat mode guests. The kdump kernel then runs with the PCR set and causes problems. The symptom in the kdump kernel (also seen in petitboot after fast-reboot) is early userspace programs taking sigills on newer instructions (seen in libc).
Hi folks,
this patch causes qemu to bail out with
Trying to write privileged spr 338 (0x152) at c000000000033454
when running it with "-M powernv -cpu POWER8" and powernv_defconfig.
Can you confirm that this is a bug in qemu ?
Thanks,
Guenter
Quoted 74 lines
Signed-off-by Michael Neuling <[email protected]>Signed-off-by Michael Ellerman <[email protected]>--- arch/powerpc/kernel/cpu_setup_power.S | 6 ++++++ arch/powerpc/kernel/dt_cpu_ftrs.c | 1 + 2 files changed, 7 insertions(+)arch/powerpc/kernel/cpu_setup_power.S +6
-0@@ -28,6 +28,7 @@ _GLOBAL(__setup_cpu_power7) beqlr li r0,0 mtspr SPRN_LPID,r0 + mtspr SPRN_PCR,r0 mfspr r3,SPRN_LPCR li r4,(LPCR_LPES1 >> LPCR_LPES_SH) bl __init_LPCR_ISA206@@ -41,6 +42,7 @@ _GLOBAL(__restore_cpu_power7) beqlr li r0,0 mtspr SPRN_LPID,r0 + mtspr SPRN_PCR,r0 mfspr r3,SPRN_LPCR li r4,(LPCR_LPES1 >> LPCR_LPES_SH) bl __init_LPCR_ISA206@@ -57,6 +59,7 @@ _GLOBAL(__setup_cpu_power8) beqlr li r0,0 mtspr SPRN_LPID,r0 + mtspr SPRN_PCR,r0 mfspr r3,SPRN_LPCR ori r3, r3, LPCR_PECEDH li r4,0 /* LPES = 0 */@@ -78,6 +81,7 @@ _GLOBAL(__restore_cpu_power8) beqlr li r0,0 mtspr SPRN_LPID,r0 + mtspr SPRN_PCR,r0 mfspr r3,SPRN_LPCR ori r3, r3, LPCR_PECEDH li r4,0 /* LPES = 0 */@@ -99,6 +103,7 @@ _GLOBAL(__setup_cpu_power9) mtspr SPRN_PSSCR,r0 mtspr SPRN_LPID,r0 mtspr SPRN_PID,r0 + mtspr SPRN_PCR,r0 mfspr r3,SPRN_LPCR LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC) or r3, r3, r4@@ -123,6 +128,7 @@ _GLOBAL(__restore_cpu_power9) mtspr SPRN_PSSCR,r0 mtspr SPRN_LPID,r0 mtspr SPRN_PID,r0 + mtspr SPRN_PCR,r0 mfspr r3,SPRN_LPCR LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC) or r3, r3, r4arch/powerpc/kernel/dt_cpu_ftrs.c +1
-0@@ -101,6 +101,7 @@ static void __restore_cpu_cpufeatures(void)if (hv_mode) {mtspr (SPRN_LPID ,0 );mtspr (SPRN_HFSCR , system_registers.hfscr); +mtspr (SPRN_PCR ,0 ); }mtspr (SPRN_FSCR , system_registers.fscr);Signature · 1 line
2.7.4
On 25 May 2018 11:33:08 pm AEST, Guenter Roeck <linux@roeck-us=2Enet> wrot= e:
Quoted 14 lines · Michael Neuling
Quoted 6 lines
Clear the PCR (Processor Compatibility Register) on boot to ensure we are not running in a compatibility mode=2E
=20
We've seen this cause problems when a crash (and kdump) occurs while running compat mode guests=2E The kdump kernel then runs with the PCR set and causes problems=2E The symptom in the kdump kernel (also seenin
Quoted 3 lines
petitboot after fast-reboot) is early userspace programs taking sigills on newer instructions (seen in libc)=2E
=20Hi folks,
Quoted 7 lines
this patch causes qemu to bail out with
Trying to write privileged spr 338 (
0x152) atc000000000033454when running it with "-M powernv -cpu POWER8" and powernv_defconfig=2E
Can you confirm that this is a bug in qemu ?
Hi Guenter,
Thanks for the report=2E As far as I'm concerned this is a qemu bug, that = register should exist on a bare metal Power8=2E
Will try and get you a qemu patch to fix it=2E
cheers
--=20
Sent from my Android phone with K-9 Mail=2E Please excuse my brevity=2E
Hi Michael,
Quoted 23 lines · Michael Ellerman
Quoted 20 lines · Guenter Roeck
Quoted 6 lines · Michael Neuling
Clear the PCR (Processor Compatibility Register) on boot to ensure we are not running in a compatibility mode.
We've seen this cause problems when a crash (and kdump) occurs while running compat mode guests. The kdump kernel then runs with the PCR set and causes problems. The symptom in the kdump kernel (also seen
in
Quoted 3 lines
petitboot after fast-reboot) is early userspace programs taking sigills on newer instructions (seen in libc).
Hi folks,
this patch causes qemu to bail out with
Trying to write privileged spr 338 (
0x152) atc000000000033454when running it with "-M powernv -cpu POWER8" and
powernv_defconfig.
Quoted 8 lines
Quoted 1 line
Can you confirm that this is a bug in qemu ?
Hi Guenter,
Thanks for the report. As far as I'm concerned this is a qemu bug, that register should exist on a bare metal Power8.
Will try and get you a qemu patch to fix it.
I already have a patch, or at least one that does the trick for me. Getting qemu patched was not the problem. I just want to be sure that the problem is indeed a qemu problem.
Thanks,
Guenter
---
Quoted 1 line
From
1617bac264b4c49d817b6947611affa9b73318f6Mon Sep 17 00:00:00 2001
From: Guenter Roeck <[email protected]>
Date: Fri, 25 May 2018 06:38:40 -0700
Subject: [PATCH] PowerPC: Permit privileged access to SPR_PCR for POWER7+
Without this access, Linux mainline bails out.
--- target/ppc/translate_init.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
target/ppc/translate_init.c +3 -2
@@ -7953,11 +7953,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 privileged +* access. */ spr_register (env,SPR_PCR ,"PCR" ,SPR_NOACCESS ,SPR_NOACCESS , -SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_generic,0x00000000 ); }
Signature · 1 line
2.7.4
Quoted 4 lines · Guenter Roeck
I already have a patch, or at least one that does the trick for me. Getting qemu patched was not the problem. I just want to be sure that the problem is indeed a qemu problem.
Hey Guenter !
It's not quite the right patch though. The PCR is a hypervisor priviledged register, your patch makes it supervisor accessible.
I don't have all my stuff at hand to provide a "proper" or tested patch but it should look like
spr_register_hv(env, SPR_PCR, "PCR",
SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS, SPR_NOACCESS, &spr_read_generic, &spr_write_generic, 0);
Additionally the TCG ppc instruction decoder should be made to check the PCR for varous instructions (that or use a specific write callback that affects the CPU flags) but that's less urgent.
Cheers,
Ben.
Quoted 36 lines
Thanks,
Guenter---
Quoted 1 line
From
1617bac264b4c49d817b6947611affa9b73318f6Mon Sep 17 00:00:00 2001From: Guenter Roeck <[email protected]>
Date: Fri, 25 May 2018 06:38:40 -0700
Subject: [PATCH] PowerPC: Permit privileged access toSPR_PCRfor POWER7+Without this access, Linux mainline bails out.
Signed-off-by Guenter Roeck <[email protected]>--- target/ppc/translate_init.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)target/ppc/translate_init.c +3
-2@@ -7953,11 +7953,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 privileged +* access. */ spr_register (env,SPR_PCR ,"PCR" ,SPR_NOACCESS ,SPR_NOACCESS , -SPR_NOACCESS ,SPR_NOACCESS , + &spr_read_generic, &spr_write_generic,0x00000000 ); }