KVM: PPC: Book3S HV Nested: Fix nested HFSCR being clobbered with multiple vCPUs
authorNicholas Piggin <npiggin@gmail.com>
Sat, 22 Jan 2022 10:55:30 +0000 (20:55 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 25 Jan 2022 05:39:41 +0000 (16:39 +1100)
The L0 is storing HFSCR requested by the L1 for the L2 in struct
kvm_nested_guest when the L1 requests a vCPU enter L2. kvm_nested_guest
is not a per-vCPU structure. Hilarity ensues.

Fix it by moving the nested hfscr into the vCPU structure together with
the other per-vCPU nested fields.

Fixes: 8b210a880b35 ("KVM: PPC: Book3S HV Nested: Make nested HFSCR state accessible")
Cc: stable@vger.kernel.org # v5.15+
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/20220122105530.3477250-1-npiggin@gmail.com
arch/powerpc/include/asm/kvm_book3s_64.h
arch/powerpc/include/asm/kvm_host.h
arch/powerpc/kvm/book3s_hv.c
arch/powerpc/kvm/book3s_hv_nested.c

index fe07558..827038a 100644 (file)
@@ -39,7 +39,6 @@ struct kvm_nested_guest {
        pgd_t *shadow_pgtable;          /* our page table for this guest */
        u64 l1_gr_to_hr;                /* L1's addr of part'n-scoped table */
        u64 process_table;              /* process table entry for this guest */
-       u64 hfscr;                      /* HFSCR that the L1 requested for this nested guest */
        long refcnt;                    /* number of pointers to this struct */
        struct mutex tlb_lock;          /* serialize page faults and tlbies */
        struct kvm_nested_guest *next;
index a770443..d9bf60b 100644 (file)
@@ -818,6 +818,7 @@ struct kvm_vcpu_arch {
 
        /* For support of nested guests */
        struct kvm_nested_guest *nested;
+       u64 nested_hfscr;       /* HFSCR that the L1 requested for the nested guest */
        u32 nested_vcpu_id;
        gpa_t nested_io_gpr;
 #endif
index d1817cd..84c89f0 100644 (file)
@@ -1816,7 +1816,6 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,
 
 static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu)
 {
-       struct kvm_nested_guest *nested = vcpu->arch.nested;
        int r;
        int srcu_idx;
 
@@ -1922,7 +1921,7 @@ static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu)
                 * it into a HEAI.
                 */
                if (!(vcpu->arch.hfscr_permitted & (1UL << cause)) ||
-                                       (nested->hfscr & (1UL << cause))) {
+                               (vcpu->arch.nested_hfscr & (1UL << cause))) {
                        vcpu->arch.trap = BOOK3S_INTERRUPT_H_EMUL_ASSIST;
 
                        /*
index 8f8daae..9d373f8 100644 (file)
@@ -363,7 +363,7 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
        /* set L1 state to L2 state */
        vcpu->arch.nested = l2;
        vcpu->arch.nested_vcpu_id = l2_hv.vcpu_token;
-       l2->hfscr = l2_hv.hfscr;
+       vcpu->arch.nested_hfscr = l2_hv.hfscr;
        vcpu->arch.regs = l2_regs;
 
        /* Guest must always run with ME enabled, HV disabled. */