Skip to content

Commit

Permalink
KVM: PPC: Book3S HV nestedv2: Register the VPA with the L0
Browse files Browse the repository at this point in the history
In the nestedv2 case, the L1 may register the L2's VPA with the L0. This
allows the L0 to manage the L2's dispatch count, as well as enable
possible performance optimisations by seeing if certain resources are
not being used by the L2 (such as the PMCs).

Use the H_GUEST_SET_STATE call to inform the L0 of the L2's VPA
address. This can not be done in the H_GUEST_VCPU_RUN input buffer.

Signed-off-by: Jordan Niethe <[email protected]>
Signed-off-by: Michael Ellerman <[email protected]>
Link: https://msgid.link/[email protected]
  • Loading branch information
iamjpn authored and mpe committed Dec 7, 2023
1 parent 4bc8ff6 commit db1dcfa
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions arch/powerpc/include/asm/kvm_book3s_64.h
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ void kvmhv_nestedv2_vcpu_free(struct kvm_vcpu *vcpu, struct kvmhv_nestedv2_io *i
int kvmhv_nestedv2_flush_vcpu(struct kvm_vcpu *vcpu, u64 time_limit);
int kvmhv_nestedv2_set_ptbl_entry(unsigned long lpid, u64 dw0, u64 dw1);
int kvmhv_nestedv2_parse_output(struct kvm_vcpu *vcpu);
int kvmhv_nestedv2_set_vpa(struct kvm_vcpu *vcpu, unsigned long vpa);

#endif /* CONFIG_KVM_BOOK3S_HV_POSSIBLE */

Expand Down
38 changes: 29 additions & 9 deletions arch/powerpc/kvm/book3s_hv.c
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,8 @@ static unsigned long do_h_register_vpa(struct kvm_vcpu *vcpu,
return err;
}

static void kvmppc_update_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *vpap)
static void kvmppc_update_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *vpap,
struct kvmppc_vpa *old_vpap)
{
struct kvm *kvm = vcpu->kvm;
void *va;
Expand Down Expand Up @@ -690,9 +691,8 @@ static void kvmppc_update_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *vpap)
kvmppc_unpin_guest_page(kvm, va, gpa, false);
va = NULL;
}
if (vpap->pinned_addr)
kvmppc_unpin_guest_page(kvm, vpap->pinned_addr, vpap->gpa,
vpap->dirty);
*old_vpap = *vpap;

vpap->gpa = gpa;
vpap->pinned_addr = va;
vpap->dirty = false;
Expand All @@ -702,24 +702,44 @@ static void kvmppc_update_vpa(struct kvm_vcpu *vcpu, struct kvmppc_vpa *vpap)

static void kvmppc_update_vpas(struct kvm_vcpu *vcpu)
{
struct kvm *kvm = vcpu->kvm;
struct kvmppc_vpa old_vpa = { 0 };

if (!(vcpu->arch.vpa.update_pending ||
vcpu->arch.slb_shadow.update_pending ||
vcpu->arch.dtl.update_pending))
return;

spin_lock(&vcpu->arch.vpa_update_lock);
if (vcpu->arch.vpa.update_pending) {
kvmppc_update_vpa(vcpu, &vcpu->arch.vpa);
if (vcpu->arch.vpa.pinned_addr)
kvmppc_update_vpa(vcpu, &vcpu->arch.vpa, &old_vpa);
if (old_vpa.pinned_addr) {
if (kvmhv_is_nestedv2())
kvmhv_nestedv2_set_vpa(vcpu, ~0ull);
kvmppc_unpin_guest_page(kvm, old_vpa.pinned_addr, old_vpa.gpa,
old_vpa.dirty);
}
if (vcpu->arch.vpa.pinned_addr) {
init_vpa(vcpu, vcpu->arch.vpa.pinned_addr);
if (kvmhv_is_nestedv2())
kvmhv_nestedv2_set_vpa(vcpu, __pa(vcpu->arch.vpa.pinned_addr));
}
}
if (vcpu->arch.dtl.update_pending) {
kvmppc_update_vpa(vcpu, &vcpu->arch.dtl);
kvmppc_update_vpa(vcpu, &vcpu->arch.dtl, &old_vpa);
if (old_vpa.pinned_addr)
kvmppc_unpin_guest_page(kvm, old_vpa.pinned_addr, old_vpa.gpa,
old_vpa.dirty);
vcpu->arch.dtl_ptr = vcpu->arch.dtl.pinned_addr;
vcpu->arch.dtl_index = 0;
}
if (vcpu->arch.slb_shadow.update_pending)
kvmppc_update_vpa(vcpu, &vcpu->arch.slb_shadow);
if (vcpu->arch.slb_shadow.update_pending) {
kvmppc_update_vpa(vcpu, &vcpu->arch.slb_shadow, &old_vpa);
if (old_vpa.pinned_addr)
kvmppc_unpin_guest_page(kvm, old_vpa.pinned_addr, old_vpa.gpa,
old_vpa.dirty);
}

spin_unlock(&vcpu->arch.vpa_update_lock);
}

Expand Down
29 changes: 29 additions & 0 deletions arch/powerpc/kvm/book3s_hv_nestedv2.c
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,35 @@ int kvmhv_nestedv2_set_ptbl_entry(unsigned long lpid, u64 dw0, u64 dw1)
}
EXPORT_SYMBOL_GPL(kvmhv_nestedv2_set_ptbl_entry);

/**
* kvmhv_nestedv2_set_vpa() - register L2 VPA with L0
* @vcpu: vcpu
* @vpa: L1 logical real address
*/
int kvmhv_nestedv2_set_vpa(struct kvm_vcpu *vcpu, unsigned long vpa)
{
struct kvmhv_nestedv2_io *io;
struct kvmppc_gs_buff *gsb;
int rc = 0;

io = &vcpu->arch.nestedv2_io;
gsb = io->vcpu_run_input;

kvmppc_gsb_reset(gsb);
rc = kvmppc_gse_put_u64(gsb, KVMPPC_GSID_VPA, vpa);
if (rc < 0)
goto out;

rc = kvmppc_gsb_send(gsb, 0);
if (rc < 0)
pr_err("KVM-NESTEDv2: couldn't register the L2 VPA (rc=%d)\n", rc);

out:
kvmppc_gsb_reset(gsb);
return rc;
}
EXPORT_SYMBOL_GPL(kvmhv_nestedv2_set_vpa);

/**
* kvmhv_nestedv2_parse_output() - receive values from H_GUEST_RUN_VCPU output
* @vcpu: vcpu
Expand Down

0 comments on commit db1dcfa

Please sign in to comment.