]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
KVM: arm64: Only sign-extend MMIO up to register width
authorChristoffer Dall <christoffer.dall@arm.com>
Thu, 12 Dec 2019 19:50:55 +0000 (20:50 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 22 May 2020 20:19:29 +0000 (21:19 +0100)
commit b6ae256afd32f96bec0117175b329d0dd617655e upstream.

On AArch64 you can do a sign-extended load to either a 32-bit or 64-bit
register, and we should only sign extend the register up to the width of
the register as specified in the operation (by using the 32-bit Wn or
64-bit Xn register specifier).

As it turns out, the architecture provides this decoding information in
the SF ("Sixty-Four" -- how cute...) bit.

Let's take advantage of this with the usual 32-bit/64-bit header file
dance and do the right thing on AArch64 hosts.

Signed-off-by: Christoffer Dall <christoffer.dall@arm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20191212195055.5541-1-christoffer.dall@arm.com
[bwh: Backported to 3.16:
 - Use ESR_EL2_SF
 - Adjust filename, context]
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
arch/arm/include/asm/kvm_emulate.h
arch/arm/include/asm/kvm_mmio.h
arch/arm/kvm/mmio.c
arch/arm64/include/asm/kvm_emulate.h
arch/arm64/include/asm/kvm_mmio.h

index 853e2becad18e9abef52b8df3d3d39d09f9ae029..8d704db1ce966ea76c85f79d662873d17b5d1c6f 100644 (file)
@@ -105,6 +105,11 @@ static inline bool kvm_vcpu_dabt_issext(struct kvm_vcpu *vcpu)
        return kvm_vcpu_get_hsr(vcpu) & HSR_SSE;
 }
 
+static inline bool kvm_vcpu_dabt_issf(const struct kvm_vcpu *vcpu)
+{
+       return false;
+}
+
 static inline int kvm_vcpu_dabt_get_rd(struct kvm_vcpu *vcpu)
 {
        return (kvm_vcpu_get_hsr(vcpu) & HSR_SRT_MASK) >> HSR_SRT_SHIFT;
index adcc0d7d317571b7b0b8f62af262b67180c4aa1d..e28cef4beae864b6ec8379757f469b8113099805 100644 (file)
@@ -26,6 +26,8 @@
 struct kvm_decode {
        unsigned long rt;
        bool sign_extend;
+       /* Not used on 32-bit arm */
+       bool sixty_four;
 };
 
 /*
index c47f108c2b8aa2e89295789bd21b99aaa166e5bb..c480bd438fd0f954ecceca0c19909ab8a381905c 100644 (file)
@@ -112,6 +112,9 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run)
                        data = (data ^ mask) - mask;
                }
 
+               if (!vcpu->arch.mmio_decode.sixty_four)
+                       data = data & 0xffffffff;
+
                trace_kvm_mmio(KVM_TRACE_MMIO_READ, len, run->mmio.phys_addr,
                               &data);
                data = vcpu_data_host_to_guest(vcpu, data, len);
@@ -127,6 +130,7 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
        unsigned long rt;
        int len;
        bool is_write, sign_extend;
+       bool sixty_four;
 
        if (kvm_vcpu_dabt_isextabt(vcpu)) {
                /* cache operation on I/O addr, tell guest unsupported */
@@ -146,6 +150,7 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
 
        is_write = kvm_vcpu_dabt_iswrite(vcpu);
        sign_extend = kvm_vcpu_dabt_issext(vcpu);
+       sixty_four = kvm_vcpu_dabt_issf(vcpu);
        rt = kvm_vcpu_dabt_get_rd(vcpu);
 
        mmio->is_write = is_write;
@@ -153,6 +158,7 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa,
        mmio->len = len;
        vcpu->arch.mmio_decode.sign_extend = sign_extend;
        vcpu->arch.mmio_decode.rt = rt;
+       vcpu->arch.mmio_decode.sixty_four = sixty_four;
 
        /*
         * The MMIO instruction is emulated and should not be re-executed
index ef490a55cdf1526848f5c0c91e0822587a9fa05d..9e1f3250bd7397823ae2aa1036dac95f917f92f5 100644 (file)
@@ -140,6 +140,11 @@ static inline bool kvm_vcpu_dabt_issext(const struct kvm_vcpu *vcpu)
        return !!(kvm_vcpu_get_hsr(vcpu) & ESR_EL2_SSE);
 }
 
+static inline bool kvm_vcpu_dabt_issf(const struct kvm_vcpu *vcpu)
+{
+       return !!(kvm_vcpu_get_hsr(vcpu) & ESR_EL2_SF);
+}
+
 static inline int kvm_vcpu_dabt_get_rd(const struct kvm_vcpu *vcpu)
 {
        return (kvm_vcpu_get_hsr(vcpu) & ESR_EL2_SRT_MASK) >> ESR_EL2_SRT_SHIFT;
index fc2f689c0694eb65e74e7a43474e32fc9a24df74..09923122c4c9550997bf15148bbd2d11ff5c78ab 100644 (file)
 #include <asm/kvm_asm.h>
 #include <asm/kvm_arm.h>
 
-/*
- * This is annoying. The mmio code requires this, even if we don't
- * need any decoding. To be fixed.
- */
 struct kvm_decode {
        unsigned long rt;
        bool sign_extend;
+       /* Witdth of the register accessed by the faulting instruction is 64-bits */
+       bool sixty_four;
 };
 
 /*