Skip to content

Commit 22f7ff0

Browse files
npigginmpe
authored andcommitted
KVM: PPC: Book3S HV Nested: Fix nested HFSCR being clobbered with multiple vCPUs
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: 8b210a8 ("KVM: PPC: Book3S HV Nested: Make nested HFSCR state accessible") Cc: [email protected] # v5.15+ Signed-off-by: Nicholas Piggin <[email protected]> Reviewed-by: Fabiano Rosas <[email protected]> Signed-off-by: Michael Ellerman <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fb6433b commit 22f7ff0

File tree

4 files changed

+3
-4
lines changed

4 files changed

+3
-4
lines changed

arch/powerpc/include/asm/kvm_book3s_64.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ struct kvm_nested_guest {
3939
pgd_t *shadow_pgtable; /* our page table for this guest */
4040
u64 l1_gr_to_hr; /* L1's addr of part'n-scoped table */
4141
u64 process_table; /* process table entry for this guest */
42-
u64 hfscr; /* HFSCR that the L1 requested for this nested guest */
4342
long refcnt; /* number of pointers to this struct */
4443
struct mutex tlb_lock; /* serialize page faults and tlbies */
4544
struct kvm_nested_guest *next;

arch/powerpc/include/asm/kvm_host.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,7 @@ struct kvm_vcpu_arch {
818818

819819
/* For support of nested guests */
820820
struct kvm_nested_guest *nested;
821+
u64 nested_hfscr; /* HFSCR that the L1 requested for the nested guest */
821822
u32 nested_vcpu_id;
822823
gpa_t nested_io_gpr;
823824
#endif

arch/powerpc/kvm/book3s_hv.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,6 @@ static int kvmppc_handle_exit_hv(struct kvm_vcpu *vcpu,
18161816

18171817
static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu)
18181818
{
1819-
struct kvm_nested_guest *nested = vcpu->arch.nested;
18201819
int r;
18211820
int srcu_idx;
18221821

@@ -1922,7 +1921,7 @@ static int kvmppc_handle_nested_exit(struct kvm_vcpu *vcpu)
19221921
* it into a HEAI.
19231922
*/
19241923
if (!(vcpu->arch.hfscr_permitted & (1UL << cause)) ||
1925-
(nested->hfscr & (1UL << cause))) {
1924+
(vcpu->arch.nested_hfscr & (1UL << cause))) {
19261925
vcpu->arch.trap = BOOK3S_INTERRUPT_H_EMUL_ASSIST;
19271926

19281927
/*

arch/powerpc/kvm/book3s_hv_nested.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
363363
/* set L1 state to L2 state */
364364
vcpu->arch.nested = l2;
365365
vcpu->arch.nested_vcpu_id = l2_hv.vcpu_token;
366-
l2->hfscr = l2_hv.hfscr;
366+
vcpu->arch.nested_hfscr = l2_hv.hfscr;
367367
vcpu->arch.regs = l2_regs;
368368

369369
/* Guest must always run with ME enabled, HV disabled. */

0 commit comments

Comments
 (0)