Skip to content

Commit 13c7bb3

Browse files
iamjpnmpe
authored andcommitted
powerpc/64s: Set reserved PCR bits
Currently the reserved bits of the Processor Compatibility Register (PCR) are cleared as per the Programming Note in Section 1.3.3 of version 3.0B of the Power ISA. This causes all new architecture features to be made available when running on newer processors with new architecture features added to the PCR as bits must be set to disable a given feature. For example to disable new features added as part of Version 2.07 of the ISA the corresponding bit in the PCR needs to be set. As new processor features generally require explicit kernel support they should be disabled until such support is implemented. Therefore kernels should set all unknown/reserved bits in the PCR such that any new architecture features which the kernel does not currently know about get disabled. An update is planned to the ISA to clarify that the PCR is an exception to the Programming Note on reserved bits in Section 1.3.3. Signed-off-by: Alistair Popple <alistair@popple.id.au> Signed-off-by: Jordan Niethe <jniethe5@gmail.com> Tested-by: Joel Stanley <joel@jms.id.au> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Link: https://lore.kernel.org/r/20190917004605.22471-2-alistair@popple.id.au
1 parent c6fadab commit 13c7bb3

6 files changed

Lines changed: 27 additions & 12 deletions

File tree

‎arch/powerpc/include/asm/reg.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@
478478
#define PCR_VEC_DIS (__MASK(63-0)) /* Vec. disable (bit NA since POWER8) */
479479
#define PCR_VSX_DIS (__MASK(63-1)) /* VSX disable (bit NA since POWER8) */
480480
#define PCR_TM_DIS (__MASK(63-2)) /* Trans. memory disable (POWER8) */
481+
#define PCR_HIGH_BITS (PCR_VEC_DIS | PCR_VSX_DIS | PCR_TM_DIS)
481482
/*
482483
* These bits are used in the function kvmppc_set_arch_compat() to specify and
483484
* determine both the compatibility level which we want to emulate and the
@@ -486,6 +487,8 @@
486487
#define PCR_ARCH_207 0x8 /* Architecture 2.07 */
487488
#define PCR_ARCH_206 0x4 /* Architecture 2.06 */
488489
#define PCR_ARCH_205 0x2 /* Architecture 2.05 */
490+
#define PCR_LOW_BITS (PCR_ARCH_207 | PCR_ARCH_206 | PCR_ARCH_205)
491+
#define PCR_MASK ~(PCR_HIGH_BITS | PCR_LOW_BITS) /* PCR Reserved Bits */
489492
#define SPRN_HEIR 0x153 /* Hypervisor Emulated Instruction Register */
490493
#define SPRN_TLBINDEXR 0x154 /* P7 TLB control register */
491494
#define SPRN_TLBVPNR 0x155 /* P7 TLB control register */

‎arch/powerpc/kernel/cpu_setup_power.S‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ _GLOBAL(__setup_cpu_power7)
2323
beqlr
2424
li r0,0
2525
mtspr SPRN_LPID,r0
26+
LOAD_REG_IMMEDIATE(r0, PCR_MASK)
2627
mtspr SPRN_PCR,r0
2728
mfspr r3,SPRN_LPCR
2829
li r4,(LPCR_LPES1 >> LPCR_LPES_SH)
@@ -37,6 +38,7 @@ _GLOBAL(__restore_cpu_power7)
3738
beqlr
3839
li r0,0
3940
mtspr SPRN_LPID,r0
41+
LOAD_REG_IMMEDIATE(r0, PCR_MASK)
4042
mtspr SPRN_PCR,r0
4143
mfspr r3,SPRN_LPCR
4244
li r4,(LPCR_LPES1 >> LPCR_LPES_SH)
@@ -54,6 +56,7 @@ _GLOBAL(__setup_cpu_power8)
5456
beqlr
5557
li r0,0
5658
mtspr SPRN_LPID,r0
59+
LOAD_REG_IMMEDIATE(r0, PCR_MASK)
5760
mtspr SPRN_PCR,r0
5861
mfspr r3,SPRN_LPCR
5962
ori r3, r3, LPCR_PECEDH
@@ -76,6 +79,7 @@ _GLOBAL(__restore_cpu_power8)
7679
beqlr
7780
li r0,0
7881
mtspr SPRN_LPID,r0
82+
LOAD_REG_IMMEDIATE(r0, PCR_MASK)
7983
mtspr SPRN_PCR,r0
8084
mfspr r3,SPRN_LPCR
8185
ori r3, r3, LPCR_PECEDH
@@ -98,6 +102,7 @@ _GLOBAL(__setup_cpu_power9)
98102
mtspr SPRN_PSSCR,r0
99103
mtspr SPRN_LPID,r0
100104
mtspr SPRN_PID,r0
105+
LOAD_REG_IMMEDIATE(r0, PCR_MASK)
101106
mtspr SPRN_PCR,r0
102107
mfspr r3,SPRN_LPCR
103108
LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC)
@@ -123,6 +128,7 @@ _GLOBAL(__restore_cpu_power9)
123128
mtspr SPRN_PSSCR,r0
124129
mtspr SPRN_LPID,r0
125130
mtspr SPRN_PID,r0
131+
LOAD_REG_IMMEDIATE(r0, PCR_MASK)
126132
mtspr SPRN_PCR,r0
127133
mfspr r3,SPRN_LPCR
128134
LOAD_REG_IMMEDIATE(r4, LPCR_PECEDH | LPCR_PECE_HVEE | LPCR_HVICE | LPCR_HEIC)

‎arch/powerpc/kernel/dt_cpu_ftrs.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ static void __restore_cpu_cpufeatures(void)
101101
if (hv_mode) {
102102
mtspr(SPRN_LPID, 0);
103103
mtspr(SPRN_HFSCR, system_registers.hfscr);
104-
mtspr(SPRN_PCR, 0);
104+
mtspr(SPRN_PCR, PCR_MASK);
105105
}
106106
mtspr(SPRN_FSCR, system_registers.fscr);
107107

@@ -144,6 +144,7 @@ static void __init cpufeatures_setup_cpu(void)
144144
mtspr(SPRN_HFSCR, 0);
145145
}
146146
mtspr(SPRN_FSCR, 0);
147+
mtspr(SPRN_PCR, PCR_MASK);
147148

148149
/*
149150
* LPCR does not get cleared, to match behaviour with secondaries

‎arch/powerpc/kvm/book3s_hv.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,11 @@ static int kvmppc_set_arch_compat(struct kvm_vcpu *vcpu, u32 arch_compat)
401401

402402
spin_lock(&vc->lock);
403403
vc->arch_compat = arch_compat;
404-
/* Set all PCR bits for which guest_pcr_bit <= bit < host_pcr_bit */
405-
vc->pcr = host_pcr_bit - guest_pcr_bit;
404+
/*
405+
* Set all PCR bits for which guest_pcr_bit <= bit < host_pcr_bit
406+
* Also set all reserved PCR bits
407+
*/
408+
vc->pcr = (host_pcr_bit - guest_pcr_bit) | PCR_MASK;
406409
spin_unlock(&vc->lock);
407410

408411
return 0;
@@ -3410,7 +3413,7 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,
34103413
}
34113414

34123415
if (vc->pcr)
3413-
mtspr(SPRN_PCR, vc->pcr);
3416+
mtspr(SPRN_PCR, vc->pcr | PCR_MASK);
34143417
mtspr(SPRN_DPDES, vc->dpdes);
34153418
mtspr(SPRN_VTB, vc->vtb);
34163419

@@ -3490,7 +3493,7 @@ static int kvmhv_load_hv_regs_and_go(struct kvm_vcpu *vcpu, u64 time_limit,
34903493
vc->vtb = mfspr(SPRN_VTB);
34913494
mtspr(SPRN_DPDES, 0);
34923495
if (vc->pcr)
3493-
mtspr(SPRN_PCR, 0);
3496+
mtspr(SPRN_PCR, PCR_MASK);
34943497

34953498
if (vc->tb_offset_applied) {
34963499
u64 new_tb = mftb() - vc->tb_offset_applied;

‎arch/powerpc/kvm/book3s_hv_nested.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void kvmhv_save_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr)
2929
{
3030
struct kvmppc_vcore *vc = vcpu->arch.vcore;
3131

32-
hr->pcr = vc->pcr;
32+
hr->pcr = vc->pcr | PCR_MASK;
3333
hr->dpdes = vc->dpdes;
3434
hr->hfscr = vcpu->arch.hfscr;
3535
hr->tb_offset = vc->tb_offset;
@@ -65,7 +65,7 @@ static void byteswap_hv_regs(struct hv_guest_state *hr)
6565
hr->lpid = swab32(hr->lpid);
6666
hr->vcpu_token = swab32(hr->vcpu_token);
6767
hr->lpcr = swab64(hr->lpcr);
68-
hr->pcr = swab64(hr->pcr);
68+
hr->pcr = swab64(hr->pcr) | PCR_MASK;
6969
hr->amor = swab64(hr->amor);
7070
hr->dpdes = swab64(hr->dpdes);
7171
hr->hfscr = swab64(hr->hfscr);
@@ -148,7 +148,7 @@ static void restore_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr)
148148
{
149149
struct kvmppc_vcore *vc = vcpu->arch.vcore;
150150

151-
vc->pcr = hr->pcr;
151+
vc->pcr = hr->pcr | PCR_MASK;
152152
vc->dpdes = hr->dpdes;
153153
vcpu->arch.hfscr = hr->hfscr;
154154
vcpu->arch.dawr = hr->dawr0;

‎arch/powerpc/kvm/book3s_hv_rmhandlers.S‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,10 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
644644

645645
/* Load guest PCR value to select appropriate compat mode */
646646
37: ld r7, VCORE_PCR(r5)
647-
cmpdi r7, 0
647+
LOAD_REG_IMMEDIATE(r6, PCR_MASK)
648+
cmpld r7, r6
648649
beq 38f
650+
or r7, r7, r6
649651
mtspr SPRN_PCR, r7
650652
38:
651653

@@ -1913,10 +1915,10 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
19131915

19141916
/* Reset PCR */
19151917
ld r0, VCORE_PCR(r5)
1916-
cmpdi r0, 0
1918+
LOAD_REG_IMMEDIATE(r6, PCR_MASK)
1919+
cmpld r0, r6
19171920
beq 18f
1918-
li r0, 0
1919-
mtspr SPRN_PCR, r0
1921+
mtspr SPRN_PCR, r6
19201922
18:
19211923
/* Signal secondary CPUs to continue */
19221924
stb r0,VCORE_IN_GUEST(r5)

0 commit comments

Comments
 (0)