KVM: PPC: Book3S HV: H_ENTER filter out reserved HPTE[B] value
authorNicholas Piggin <npiggin@gmail.com>
Mon, 4 Oct 2021 14:57:49 +0000 (00:57 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 13 Oct 2021 02:08:16 +0000 (13:08 +1100)
The HPTE B field is a 2-bit field with values 0b10 and 0b11 reserved.
This field is also taken from the HPTE and used when KVM executes
TLBIEs to set the B field of those instructions.

Disallow the guest setting B to a reserved value with H_ENTER by
rejecting it. This is the same approach already taken for rejecting
reserved (unsupported) LLP values. This prevents the guest from being
able to induce the host to execute TLBIE with reserved values, which
is not known to be a problem with current processors but in theory it
could prevent the TLBIE from working correctly in a future processor.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Fabiano Rosas <farosas@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211004145749.1331331-1-npiggin@gmail.com
arch/powerpc/include/asm/kvm_book3s_64.h
arch/powerpc/kvm/book3s_hv_rm_mmu.c

index 19b6942c6969a354610af046ba2b21b784be745f..fff391b9b97bc572ab3b8a5c7dbfcbd12eb3b49f 100644 (file)
@@ -378,6 +378,10 @@ static inline unsigned long compute_tlbie_rb(unsigned long v, unsigned long r,
                rb |= 1;                /* L field */
                rb |= r & 0xff000 & ((1ul << a_pgshift) - 1); /* LP field */
        }
+       /*
+        * This sets both bits of the B field in the PTE. 0b1x values are
+        * reserved, but those will have been filtered by kvmppc_do_h_enter.
+        */
        rb |= (v >> HPTE_V_SSIZE_SHIFT) << 8;   /* B field */
        return rb;
 }
index 632b2545072b8af727f19ee537774571ad2e2823..2c1f3c6e72d18892d6f8ed82208a35ec8f707635 100644 (file)
@@ -207,6 +207,15 @@ long kvmppc_do_h_enter(struct kvm *kvm, unsigned long flags,
 
        if (kvm_is_radix(kvm))
                return H_FUNCTION;
+       /*
+        * The HPTE gets used by compute_tlbie_rb() to set TLBIE bits, so
+        * these functions should work together -- must ensure a guest can not
+        * cause problems with the TLBIE that KVM executes.
+        */
+       if ((pteh >> HPTE_V_SSIZE_SHIFT) & 0x2) {
+               /* B=0b1x is a reserved value, disallow it. */
+               return H_PARAMETER;
+       }
        psize = kvmppc_actual_pgsz(pteh, ptel);
        if (!psize)
                return H_PARAMETER;