From: Paul Mackerras <paulus@ozlabs.org>
To: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
Cc: aik@ozlabs.ru, linuxppc-dev@lists.ozlabs.org,
kvm@vger.kernel.org, kvm-ppc@vger.kernel.org
Subject: Re: [PATCH V2 7/8] KVM: PPC: Introduce new hcall H_COPY_TOFROM_GUEST to access quadrants 1 & 2
Date: Thu, 13 Dec 2018 16:24:18 +1100 [thread overview]
Message-ID: <20181213052417.GA8827@blackberry> (raw)
In-Reply-To: <20181210035825.29404-8-sjitindarsingh@gmail.com>
On Mon, Dec 10, 2018 at 02:58:24PM +1100, Suraj Jitindar Singh wrote:
> A guest cannot access quadrants 1 or 2 as this would result in an
> exception. Thus introduce the hcall H_COPY_TOFROM_GUEST to be used by a
> guest when it wants to perform an access to quadrants 1 or 2, for
> example when it wants to access memory for one of its nested guests.
>
> Also provide an implementation for the kvm-hv module.
>
> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
[snip]
> /*
> + * Handle the H_COPY_TOFROM_GUEST hcall.
> + * r4 = L1 lpid of nested guest
> + * r5 = pid
> + * r6 = eaddr to access
> + * r7 = to buffer (L1 gpa)
> + * r8 = from buffer (L1 gpa)
Comment says these are GPAs...
> + * r9 = n bytes to copy
> + */
> +long kvmhv_copy_tofrom_guest_nested(struct kvm_vcpu *vcpu)
> +{
> + struct kvm_nested_guest *gp;
> + int l1_lpid = kvmppc_get_gpr(vcpu, 4);
> + int pid = kvmppc_get_gpr(vcpu, 5);
> + gva_t eaddr = kvmppc_get_gpr(vcpu, 6);
> + void *gp_to = (void *) kvmppc_get_gpr(vcpu, 7);
> + void *gp_from = (void *) kvmppc_get_gpr(vcpu, 8);
> + void *buf;
> + unsigned long n = kvmppc_get_gpr(vcpu, 9);
> + bool is_load = !!gp_to;
> + long rc;
> +
> + if (gp_to && gp_from) /* One must be NULL to determine the direction */
> + return H_PARAMETER;
> +
> + if (eaddr & (0xFFFUL << 52))
> + return H_PARAMETER;
> +
> + buf = kzalloc(n, GFP_KERNEL);
> + if (!buf)
> + return H_NO_MEM;
> +
> + gp = kvmhv_get_nested(vcpu->kvm, l1_lpid, false);
> + if (!gp) {
> + rc = H_PARAMETER;
> + goto out_free;
> + }
> +
> + mutex_lock(&gp->tlb_lock);
> +
> + if (is_load) {
> + /* Load from the nested guest into our buffer */
> + rc = __kvmhv_copy_tofrom_guest_radix(gp->shadow_lpid, pid,
> + eaddr, buf, NULL, n);
> + if (rc)
> + goto not_found;
> +
> + /* Write what was loaded into our buffer back to the L1 guest */
> + rc = kvmppc_st(vcpu, (ulong *) &gp_to, n, buf, true);
but using kvmppc_st implies that it is an EA (and in fact when you
call it in the next patch you pass an EA).
It would be more like other hcalls to pass a GPA, meaning that you
would use kvm_write_guest() here. On the other hand, with the
quadrant access, kvmppc_st() might well be faster than
kvm_write_guest.
So you need to decide which it is and either fix the comment or change
the code.
Paul.
next prev parent reply other threads:[~2018-12-13 5:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-10 3:58 [PATCH V2 0/8] KVM: PPC: Implement passthrough of emulated devices for nested guests Suraj Jitindar Singh
2018-12-10 3:58 ` [PATCH V2 1/8] KVM: PPC: Only report KVM_CAP_SPAPR_TCE_VFIO on powernv machines Suraj Jitindar Singh
2018-12-10 3:58 ` [PATCH V2 2/8] KVM: PPC: Book3S HV: Add function kvmhv_vcpu_is_radix() Suraj Jitindar Singh
2018-12-10 3:58 ` [PATCH V2 3/8] KVM: PPC: Book3S HV: Implement functions to access quadrants 1 & 2 Suraj Jitindar Singh
2018-12-10 3:58 ` [PATCH V2 4/8] KVM: PPC: Add load_from_eaddr and store_to_eaddr to the kvmppc_ops struct Suraj Jitindar Singh
2018-12-10 3:58 ` [PATCH V2 5/8] KVM: PPC: Update kvmppc_st and kvmppc_ld to use quadrants Suraj Jitindar Singh
2018-12-10 3:58 ` [PATCH V2 6/8] KVM: PPC: Book3S HV: Allow passthrough of an emulated device to an L2 guest Suraj Jitindar Singh
2018-12-10 3:58 ` [PATCH V2 7/8] KVM: PPC: Introduce new hcall H_COPY_TOFROM_GUEST to access quadrants 1 & 2 Suraj Jitindar Singh
2018-12-13 5:24 ` Paul Mackerras [this message]
2018-12-14 2:04 ` Suraj Jitindar Singh
2018-12-10 3:58 ` [PATCH V2 8/8] KVM: PPC: Book3S HV: Allow passthrough of an emulated device to an L3 guest Suraj Jitindar Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20181213052417.GA8827@blackberry \
--to=paulus@ozlabs.org \
--cc=aik@ozlabs.ru \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=sjitindarsingh@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).