Skip to contentSkip to conversation

KVM: arm64: nv: Fix handling of XN[0] when !FEAT_XNX

PATCH Superseded Oliver Upton 2 participants 2 messages Jun 2

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Oliver Upton

author maintainer
#0 lore raw

PATCH 1/1 KVM: arm64: nv: Fix handling of XN[0] when !FEAT_XNX

XN has already been extracted from its bitfield position so using FIELD_PREP() on the mask that clears XN[0] is completely broken, having the effect of unconditionally granting execute permissions...

Fix the obvious mistake by manipulating the right bit.

Fixes d93febe2ed2e ("KVM: arm64: nv: Forward FEAT_XNX permissions to the shadow stage-2")
---
 arch/arm64/include/asm/kvm_nested.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/kvm_nested.h +2 -2
index 091544e6af44..f5d4eb925198 100644
@@ -131,7 +131,7 @@ static inline bool kvm_s2_trans_exec_el0(struct kvm *kvm, struct kvm_s2_trans *t
 	u8 xn = FIELD_GET(KVM_PTE_LEAF_ATTR_HI_S2_XN, trans->desc);
 
 	if (!kvm_has_xnx(kvm))
-		xn &= FIELD_PREP(KVM_PTE_LEAF_ATTR_HI_S2_XN, 0b10);
+		xn &= BIT(1);
 
 	switch (xn) {
 	case 0b00:
@@ -147,7 +147,7 @@ static inline bool kvm_s2_trans_exec_el1(struct kvm *kvm, struct kvm_s2_trans *t
 	u8 xn = FIELD_GET(KVM_PTE_LEAF_ATTR_HI_S2_XN, trans->desc);
 
 	if (!kvm_has_xnx(kvm))
-		xn &= FIELD_PREP(KVM_PTE_LEAF_ATTR_HI_S2_XN, 0b10);
+		xn &= BIT(1);
 
 	switch (xn) {
 	case 0b00:

base-commit: 5d6919055dec134de3c40167a490f33c74c12581

Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#1 lore raw
Quoted 27 lines · Oliver Upton

XN has already been extracted from its bitfield position so using FIELD_PREP() on the mask that clears XN[0] is completely broken, having the effect of unconditionally granting execute permissions...

Fix the obvious mistake by manipulating the right bit.

Fixes d93febe2ed2e ("KVM: arm64: nv: Forward FEAT_XNX permissions to the shadow stage-2")
---
 arch/arm64/include/asm/kvm_nested.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/include/asm/kvm_nested.h +1 -1
index 091544e6af44..f5d4eb925198 100644
@@ -131,7 +131,7 @@ static inline bool kvm_s2_trans_exec_el0(struct kvm *kvm, struct kvm_s2_trans *t
 	u8 xn = FIELD_GET(KVM_PTE_LEAF_ATTR_HI_S2_XN, trans->desc);
 
 	if (!kvm_has_xnx(kvm))
-		xn &= FIELD_PREP(KVM_PTE_LEAF_ATTR_HI_S2_XN, 0b10);
+		xn &= BIT(1);
 
 	switch (xn) {
 	case 0b00:

arch/arm64/include/asm/kvm_nested.h static inline bool kvm_s2_trans_exec_el1(struct kvm *kvm, struct kvm_s2_trans *t · line 150

Quoted 5 lines
arch/arm64/include/asm/kvm_nested.h +1 -1
@@ -147,7 +147,7 @@ static inline bool kvm_s2_trans_exec_el1(struct kvm *kvm, struct kvm_s2_trans *t
 	u8 xn = FIELD_GET(KVM_PTE_LEAF_ATTR_HI_S2_XN, trans->desc);
 
 	if (!kvm_has_xnx(kvm))
-		xn &= FIELD_PREP(KVM_PTE_LEAF_ATTR_HI_S2_XN, 0b10);
+		xn &= BIT(1);

I think using 0b10 here can improve styling consistency very slightly, but either way,

Quoted 8 lines
arch/arm64/include/asm/kvm_nested.h +0 -0
 	switch (xn) {
 	case 0b00:
 

base-commit: 5d6919055dec134de3c40167a490f33c74c12581

Signature · 1 line
2.47.3