kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: arm64: Fix reporting of endianess when the access originates at EL0
@ 2021-10-12 11:23 Marc Zyngier
  2021-10-12 12:00 ` Andrew Jones
  2021-10-17 10:20 ` Marc Zyngier
  0 siblings, 2 replies; 4+ messages in thread
From: Marc Zyngier @ 2021-10-12 11:23 UTC (permalink / raw)
  To: kvm, kvmarm, linux-arm-kernel
  Cc: James Morse, Suzuki K Poulose, Alexandru Elisei, Fuad Tabba, kernel-team

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!

Signed-off-by: Marc Zyngier <maz@kernel.org>
---
 arch/arm64/include/asm/kvm_emulate.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
index 1fadb5d98a36..14ee8319b1ce 100644
--- a/arch/arm64/include/asm/kvm_emulate.h
+++ b/arch/arm64/include/asm/kvm_emulate.h
@@ -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,
-- 
2.30.2


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

* Re: [PATCH] KVM: arm64: Fix reporting of endianess when the access originates at EL0
  2021-10-12 11:23 [PATCH] KVM: arm64: Fix reporting of endianess when the access originates at EL0 Marc Zyngier
@ 2021-10-12 12:00 ` Andrew Jones
  2021-10-12 14:20   ` Marc Zyngier
  2021-10-17 10:20 ` Marc Zyngier
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Jones @ 2021-10-12 12:00 UTC (permalink / raw)
  To: Marc Zyngier; +Cc: kvm, kvmarm, linux-arm-kernel, kernel-team

On Tue, Oct 12, 2021 at 12:23:12PM +0100, Marc Zyngier wrote:
> 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?

> 
> Good luck with that!
> 
> Signed-off-by: Marc Zyngier <maz@kernel.org>
> ---
>  arch/arm64/include/asm/kvm_emulate.h | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h
> index 1fadb5d98a36..14ee8319b1ce 100644
> --- a/arch/arm64/include/asm/kvm_emulate.h
> +++ b/arch/arm64/include/asm/kvm_emulate.h
> @@ -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,
> -- 
> 2.30.2
>

Reviewed-by: Andrew Jones <drjones@redhat.com>


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

* Re: [PATCH] KVM: arm64: Fix reporting of endianess when the access originates at EL0
  2021-10-12 12:00 ` Andrew Jones
@ 2021-10-12 14:20   ` Marc Zyngier
  0 siblings, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2021-10-12 14:20 UTC (permalink / raw)
  To: Andrew Jones; +Cc: kvm, kvmarm, linux-arm-kernel, kernel-team

On Tue, 12 Oct 2021 13:00:40 +0100,
Andrew Jones <drjones@redhat.com> wrote:
> 
> On Tue, Oct 12, 2021 at 12:23:12PM +0100, Marc Zyngier wrote:
> > 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!

> Reviewed-by: Andrew Jones <drjones@redhat.com>

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.

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

* Re: [PATCH] KVM: arm64: Fix reporting of endianess when the access originates at EL0
  2021-10-12 11:23 [PATCH] KVM: arm64: Fix reporting of endianess when the access originates at EL0 Marc Zyngier
  2021-10-12 12:00 ` Andrew Jones
@ 2021-10-17 10:20 ` Marc Zyngier
  1 sibling, 0 replies; 4+ messages in thread
From: Marc Zyngier @ 2021-10-17 10:20 UTC (permalink / raw)
  To: Marc Zyngier, kvmarm, kvm, linux-arm-kernel
  Cc: kernel-team, Suzuki K Poulose, Alexandru Elisei, Fuad Tabba, James Morse

On Tue, 12 Oct 2021 12:23:12 +0100, Marc Zyngier wrote:
> 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.
-- 
Without deviation from the norm, progress is not possible.



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

end of thread, other threads:[~2021-10-17 10:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12 11:23 [PATCH] KVM: arm64: Fix reporting of endianess when the access originates at EL0 Marc Zyngier
2021-10-12 12:00 ` Andrew Jones
2021-10-12 14:20   ` Marc Zyngier
2021-10-17 10:20 ` Marc Zyngier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).