Skip to contentSkip to conversation

arm64: KVM: Obey RES0/1 reserved bits when setting CPTR_EL2

PATCH In review Dave Martin 2 participants 2 messages Jan 19, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: KVM: Obey RES0/1 reserved bits when setting CPTR_EL2

Some bits in CPTR are defined as RES1 in the architecture. Setting these bits to zero may unintentionally enable future architecture extensions, allowing guests to use them without supervision by the host.

This would be bad: for forwards compatibility, this patch makes sure the affected bits are always written with 1, not 0.

This patch only addresses CPTR_EL2. Initialisation of other system registers may still need review.

---
 arch/arm64/include/asm/kvm_arm.h |    1 +
 arch/arm64/kvm/hyp/switch.c      |    8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)
arch/arm64/include/asm/kvm_arm.h +1 -0
index 738a95f..7d858fe 100644
@@ -182,6 +182,7 @@
 #define CPTR_EL2_TCPAC	(1 << 31)
 #define CPTR_EL2_TTA	(1 << 20)
 #define CPTR_EL2_TFP	(1 << CPTR_EL2_TFP_SHIFT)
+#define CPTR_EL2_DEFAULT	0x000033ff
 
 /* Hyp Debug Configuration Register bits */
 #define MDCR_EL2_TDRA		(1 << 11)
arch/arm64/kvm/hyp/switch.c +6 -2
index ca8f5a5..63aa74a 100644
@@ -36,7 +36,11 @@ static void __hyp_text __activate_traps(struct kvm_vcpu *vcpu)
 	write_sysreg(val, hcr_el2);
 	/* Trap on AArch32 cp15 c15 accesses (EL1 or EL0) */
 	write_sysreg(1 << 15, hstr_el2);
-	write_sysreg(CPTR_EL2_TTA | CPTR_EL2_TFP, cptr_el2);
+
+	val = CPTR_EL2_DEFAULT;
+	val |= CPTR_EL2_TTA | CPTR_EL2_TFP;
+	write_sysreg(val, cptr_el2);
+
 	write_sysreg(vcpu->arch.mdcr_el2, mdcr_el2);
 }
 
@@ -45,7 +49,7 @@ static void __hyp_text __deactivate_traps(struct kvm_vcpu *vcpu)
 	write_sysreg(HCR_RW, hcr_el2);
 	write_sysreg(0, hstr_el2);
 	write_sysreg(read_sysreg(mdcr_el2) & MDCR_EL2_HPMN_MASK, mdcr_el2);
-	write_sysreg(0, cptr_el2);
+	write_sysreg(CPTR_EL2_DEFAULT, cptr_el2);
 }
 
 static void __hyp_text __activate_vm(struct kvm_vcpu *vcpu)
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Dave Martin

Some bits in CPTR are defined as RES1 in the architecture. Setting these bits to zero may unintentionally enable future architecture extensions, allowing guests to use them without supervision by the host.

This would be bad: for forwards compatibility, this patch makes sure the affected bits are always written with 1, not 0.

This patch only addresses CPTR_EL2. Initialisation of other system registers may still need review.

Thanks for putting this together:

Unless someone has an objection, I plan to queue this post -rc1.

	M.
Signature · 1 line
Jazz is not dead. It just smells funny...