Skip to contentSkip to conversation

KVM: arm64: Fix reporting of endianess when the access originates at EL0

PATCH Applied Marc Zyngier 2 participants 4 messages Oct 12, 2021 – Oct 17, 2021

Subsystems (3)
lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

PATCH 1/1 KVM: arm64: Fix reporting of endianess when the access originates at EL0

We currently check SCTLR_EL1.EE when computing the address of a faulting guest access. However, the fault could have occured at EL0, in which case the right bit to check would be SCTLR_EL1.E0E.

This is pretty unlikely to cause any issue in practice: You'd have to have a guest with a LE EL1 and a BE EL0 (or the other way around), and have mapped a device into the EL0 page tables.

Good luck with that!

---
 arch/arm64/include/asm/kvm_emulate.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_emulate.h +4 -1
index 1fadb5d98a36..14ee8319b1ce 100644
@@ -396,7 +396,10 @@ static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
 	if (vcpu_mode_is_32bit(vcpu))
 		return !!(*vcpu_cpsr(vcpu) & PSR_AA32_E_BIT);
 
-	return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & (1 << 25));
+	if (vcpu_mode_priv(vcpu))
+		return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_ELx_EE);
+	else
+		return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_EL1_E0E);
 }
 
 static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,
Signature · 1 line
2.30.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Marc Zyngier

We currently check SCTLR_EL1.EE when computing the address of a faulting guest access. However, the fault could have occured at EL0, in which case the right bit to check would be SCTLR_EL1.E0E.

This is pretty unlikely to cause any issue in practice: You'd have to have a guest with a LE EL1 and a BE EL0 (or the other way around), and have mapped a device into the EL0 page tables.

I wonder if that's something a usermode network driver might want?

Quoted 27 lines

Good luck with that!

---
 arch/arm64/include/asm/kvm_emulate.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_emulate.h +4 -1
index 1fadb5d98a36..14ee8319b1ce 100644
@@ -396,7 +396,10 @@ static inline bool kvm_vcpu_is_be(struct kvm_vcpu *vcpu)
 	if (vcpu_mode_is_32bit(vcpu))
 		return !!(*vcpu_cpsr(vcpu) & PSR_AA32_E_BIT);
 
-	return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & (1 << 25));
+	if (vcpu_mode_priv(vcpu))
+		return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_ELx_EE);
+	else
+		return !!(vcpu_read_sys_reg(vcpu, SCTLR_EL1) & SCTLR_EL1_E0E);
 }
 
 static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu,
Signature · 1 line
2.30.2
author maintainer
#2 lore raw
Quoted 11 lines · Andrew Jones
Quoted 7 lines · Marc Zyngier

We currently check SCTLR_EL1.EE when computing the address of a faulting guest access. However, the fault could have occured at EL0, in which case the right bit to check would be SCTLR_EL1.E0E.

This is pretty unlikely to cause any issue in practice: You'd have to have a guest with a LE EL1 and a BE EL0 (or the other way around), and have mapped a device into the EL0 page tables.

I wonder if that's something a usermode network driver might want?

I don't know what it wants, but I don't want it the first place! Think of what a kernel would need to do to run its userspace in a different endianness... Userspace device access is just an additional headache.

Whoever does this needs urgent medical attention!

Quoted 1 line

Thanks,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
author maintainer Applied
#3 lore raw
In reply to Marc Zyngier
Quoted 9 lines · Marc Zyngier

We currently check SCTLR_EL1.EE when computing the address of a faulting guest access. However, the fault could have occured at EL0, in which case the right bit to check would be SCTLR_EL1.E0E.

This is pretty unlikely to cause any issue in practice: You'd have to have a guest with a LE EL1 and a BE EL0 (or the other way around), and have mapped a device into the EL0 page tables.

[...]

Applied to next, thanks!

[1/1] KVM: arm64: Fix reporting of endianess when the access originates at EL0

      commit: 69adec18e94ff3ca20447916a3bd23ab1d06b878

Cheers,

	M.
Signature · 7 lines
Without deviation from the norm, progress is not possible.


_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm