All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] arm64: KVM: Obey RES0/1 reserved bits when setting CPTR_EL2
@ 2016-01-19 16:20 ` Dave Martin
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Martin @ 2016-01-19 16:20 UTC (permalink / raw)
  To: kvmarm; +Cc: Marc Zyngier, Geoff Levand, linux-arm-kernel

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.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
---
 arch/arm64/include/asm/kvm_arm.h |    1 +
 arch/arm64/kvm/hyp/switch.c      |    8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 738a95f..7d858fe 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -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)
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index ca8f5a5..63aa74a 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -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)
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] arm64: KVM: Obey RES0/1 reserved bits when setting CPTR_EL2
@ 2016-01-19 16:20 ` Dave Martin
  0 siblings, 0 replies; 4+ messages in thread
From: Dave Martin @ 2016-01-19 16:20 UTC (permalink / raw)
  To: linux-arm-kernel

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.

Signed-off-by: Dave Martin <Dave.Martin@arm.com>
---
 arch/arm64/include/asm/kvm_arm.h |    1 +
 arch/arm64/kvm/hyp/switch.c      |    8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_arm.h b/arch/arm64/include/asm/kvm_arm.h
index 738a95f..7d858fe 100644
--- a/arch/arm64/include/asm/kvm_arm.h
+++ b/arch/arm64/include/asm/kvm_arm.h
@@ -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)
diff --git a/arch/arm64/kvm/hyp/switch.c b/arch/arm64/kvm/hyp/switch.c
index ca8f5a5..63aa74a 100644
--- a/arch/arm64/kvm/hyp/switch.c
+++ b/arch/arm64/kvm/hyp/switch.c
@@ -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)
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] arm64: KVM: Obey RES0/1 reserved bits when setting CPTR_EL2
  2016-01-19 16:20 ` Dave Martin
@ 2016-01-19 16:32   ` Marc Zyngier
  -1 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2016-01-19 16:32 UTC (permalink / raw)
  To: Dave Martin, kvmarm; +Cc: Geoff Levand, linux-arm-kernel

On 19/01/16 16:20, Dave Martin wrote:
> 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.
> 
> Signed-off-by: Dave Martin <Dave.Martin@arm.com>

Thanks for putting this together:

Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>

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

	M.
-- 
Jazz is not dead. It just smells funny...

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] arm64: KVM: Obey RES0/1 reserved bits when setting CPTR_EL2
@ 2016-01-19 16:32   ` Marc Zyngier
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2016-01-19 16:32 UTC (permalink / raw)
  To: linux-arm-kernel

On 19/01/16 16:20, Dave Martin wrote:
> 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.
> 
> Signed-off-by: Dave Martin <Dave.Martin@arm.com>

Thanks for putting this together:

Reviewed-by: Marc Zyngier <marc.zyngier@arm.com>

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

	M.
-- 
Jazz is not dead. It just smells funny...

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-01-19 16:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-19 16:20 [PATCH] arm64: KVM: Obey RES0/1 reserved bits when setting CPTR_EL2 Dave Martin
2016-01-19 16:20 ` Dave Martin
2016-01-19 16:32 ` Marc Zyngier
2016-01-19 16:32   ` Marc Zyngier

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.