From: David Gibson <david@gibson.dropbear.id.au>
To: Paul Mackerras <paulus@ozlabs.org>
Cc: linuxppc-dev@ozlabs.org, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH v3 29/33] KVM: PPC: Book3S HV: Handle differing endianness for H_ENTER_NESTED
Date: Wed, 3 Oct 2018 16:13:36 +1000 [thread overview]
Message-ID: <20181003061336.GV1886@umbus.fritz.box> (raw)
In-Reply-To: <1538479892-14835-30-git-send-email-paulus@ozlabs.org>
[-- Attachment #1: Type: text/plain, Size: 4557 bytes --]
On Tue, Oct 02, 2018 at 09:31:28PM +1000, Paul Mackerras wrote:
> From: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
>
> The hcall H_ENTER_NESTED takes as the two parameters the address in
> L1 guest memory of a hv_regs struct and a pt_regs struct which the
> L1 guest would like to use to run a L2 guest and in which are returned
> the exit state of the L2 guest. For efficiency, these are in the
> endianness of the L1 guest, rather than being always big-endian as is
> usually the case for PAPR hypercalls.
Does that actually make a difference for efficiency? I thought the
presence of the byte-reversing loads and stores meant byteswapping was
basically zero-cost on POWER.
> When reading/writing these structures, this patch handles the case
> where the endianness of the L1 guest differs from that of the L0
> hypervisor, by byteswapping the structures after reading and before
> writing them back.
>
> Since all the fields of the pt_regs are of the same type, i.e.,
> unsigned long, we treat it as an array of unsigned longs. The fields
> of struct hv_guest_state are not all the same, so its fields are
> byteswapped individually.
>
> Signed-off-by: Suraj Jitindar Singh <sjitindarsingh@gmail.com>
> Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
Looks correct, though, so
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> arch/powerpc/kvm/book3s_hv_nested.c | 51 ++++++++++++++++++++++++++++++++++++-
> 1 file changed, 50 insertions(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/kvm/book3s_hv_nested.c b/arch/powerpc/kvm/book3s_hv_nested.c
> index 7b1088a..228dc11 100644
> --- a/arch/powerpc/kvm/book3s_hv_nested.c
> +++ b/arch/powerpc/kvm/book3s_hv_nested.c
> @@ -51,6 +51,48 @@ void kvmhv_save_hv_regs(struct kvm_vcpu *vcpu, struct hv_guest_state *hr)
> hr->ppr = vcpu->arch.ppr;
> }
>
> +static void byteswap_pt_regs(struct pt_regs *regs)
> +{
> + unsigned long *addr = (unsigned long *) regs;
> +
> + for (; addr < ((unsigned long *) (regs + 1)); addr++)
> + *addr = swab64(*addr);
> +}
> +
> +static void byteswap_hv_regs(struct hv_guest_state *hr)
> +{
> + hr->version = swab64(hr->version);
> + hr->lpid = swab32(hr->lpid);
> + hr->vcpu_token = swab32(hr->vcpu_token);
> + hr->lpcr = swab64(hr->lpcr);
> + hr->pcr = swab64(hr->pcr);
> + hr->amor = swab64(hr->amor);
> + hr->dpdes = swab64(hr->dpdes);
> + hr->hfscr = swab64(hr->hfscr);
> + hr->tb_offset = swab64(hr->tb_offset);
> + hr->dawr0 = swab64(hr->dawr0);
> + hr->dawrx0 = swab64(hr->dawrx0);
> + hr->ciabr = swab64(hr->ciabr);
> + hr->hdec_expiry = swab64(hr->hdec_expiry);
> + hr->purr = swab64(hr->purr);
> + hr->spurr = swab64(hr->spurr);
> + hr->ic = swab64(hr->ic);
> + hr->vtb = swab64(hr->vtb);
> + hr->hdar = swab64(hr->hdar);
> + hr->hdsisr = swab64(hr->hdsisr);
> + hr->heir = swab64(hr->heir);
> + hr->asdr = swab64(hr->asdr);
> + hr->srr0 = swab64(hr->srr0);
> + hr->srr1 = swab64(hr->srr1);
> + hr->sprg[0] = swab64(hr->sprg[0]);
> + hr->sprg[1] = swab64(hr->sprg[1]);
> + hr->sprg[2] = swab64(hr->sprg[2]);
> + hr->sprg[3] = swab64(hr->sprg[3]);
> + hr->pidr = swab64(hr->pidr);
> + hr->cfar = swab64(hr->cfar);
> + hr->ppr = swab64(hr->ppr);
> +}
> +
> static void save_hv_return_state(struct kvm_vcpu *vcpu, int trap,
> struct hv_guest_state *hr)
> {
> @@ -175,6 +217,8 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
> sizeof(struct hv_guest_state));
> if (err)
> return H_PARAMETER;
> + if (kvmppc_need_byteswap(vcpu))
> + byteswap_hv_regs(&l2_hv);
> if (l2_hv.version != HV_GUEST_STATE_VERSION)
> return H_P2;
>
> @@ -183,7 +227,8 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
> sizeof(struct pt_regs));
> if (err)
> return H_PARAMETER;
> -
> + if (kvmppc_need_byteswap(vcpu))
> + byteswap_pt_regs(&l2_regs);
> if (l2_hv.vcpu_token >= NR_CPUS)
> return H_PARAMETER;
>
> @@ -255,6 +300,10 @@ long kvmhv_enter_nested_guest(struct kvm_vcpu *vcpu)
> kvmhv_put_nested(l2);
>
> /* copy l2_hv_state and regs back to guest */
> + if (kvmppc_need_byteswap(vcpu)) {
> + byteswap_hv_regs(&l2_hv);
> + byteswap_pt_regs(&l2_regs);
> + }
> err = kvm_vcpu_write_guest(vcpu, hv_ptr, &l2_hv,
> sizeof(struct hv_guest_state));
> if (err)
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2018-10-03 6:13 UTC|newest]
Thread overview: 54+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-02 11:30 [PATCH v3 00/33] KVM: PPC: Book3S HV: Nested HV virtualization Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 01/33] powerpc: Turn off CPU_FTR_P9_TM_HV_ASSIST in non-hypervisor mode Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 02/33] KVM: PPC: Book3S: Simplify external interrupt handling Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 03/33] KVM: PPC: Book3S HV: Remove left-over code in XICS-on-XIVE emulation Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 04/33] KVM: PPC: Book3S HV: Move interrupt delivery on guest entry to C code Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 05/33] KVM: PPC: Book3S HV: Extract PMU save/restore operations as C-callable functions Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 06/33] KVM: PPC: Book3S HV: Simplify real-mode interrupt handling Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 07/33] KVM: PPC: Book3S: Rework TM save/restore code and make it C-callable Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 08/33] KVM: PPC: Book3S HV: Call kvmppc_handle_exit_hv() with vcore unlocked Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 09/33] KVM: PPC: Book3S HV: Streamlined guest entry/exit path on P9 for radix guests Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 10/33] KVM: PPC: Book3S HV: Handle hypervisor instruction faults better Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 11/33] KVM: PPC: Book3S HV: Add a debugfs file to dump radix mappings Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 12/33] KVM: PPC: Use ccr field in pt_regs struct embedded in vcpu struct Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 13/33] KVM: PPC: Book3S HV: Clear partition table entry on vm teardown Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 14/33] KVM: PPC: Book3S HV: Make kvmppc_mmu_radix_xlate process/partition table agnostic Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 15/33] KVM: PPC: Book3S HV: Refactor radix page fault handler Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 16/33] KVM: PPC: Book3S HV: Use kvmppc_unmap_pte() in kvm_unmap_radix() Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 17/33] KVM: PPC: Book3S HV: Framework and hcall stubs for nested virtualization Paul Mackerras
2018-10-03 3:17 ` David Gibson
2018-10-02 11:31 ` [PATCH v3 18/33] KVM: PPC: Book3S HV: Nested guest entry via hypercall Paul Mackerras
2018-10-03 5:12 ` David Gibson
2018-10-02 11:31 ` [PATCH v3 19/33] KVM: PPC: Book3S HV: Use XICS hypercalls when running as a nested hypervisor Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 20/33] KVM: PPC: Book3S HV: Handle hypercalls correctly when nested Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 21/33] KVM: PPC: Book3S HV: Framework to handle HV Emulation Assist Interrupt Paul Mackerras
2018-10-03 5:13 ` David Gibson
2018-10-02 11:31 ` [PATCH v3 22/33] KVM: PPC: Book3S HV: Handle page fault for a nested guest Paul Mackerras
2018-10-03 5:39 ` David Gibson
2018-10-03 5:42 ` David Gibson
2018-10-04 9:21 ` Paul Mackerras
2018-10-05 2:46 ` David Gibson
2018-10-02 11:31 ` [PATCH v3 23/33] KVM: PPC: Book3S HV: Introduce rmap to track nested guest mappings Paul Mackerras
2018-10-03 5:56 ` David Gibson
2018-10-04 3:05 ` Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 24/33] KVM: PPC: Book3S HV: Emulate Privileged TLBIE for guest hypervisors Paul Mackerras
2018-10-03 5:56 ` David Gibson
2018-10-02 11:31 ` [PATCH v3 25/33] KVM: PPC: Book3S HV: Invalidate TLB when nested vcpu moves physical cpu Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 26/33] KVM: PPC: Book3S HV: Don't access HFSCR, LPIDR or LPCR when running nested Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 27/33] KVM: PPC: Book3S HV: Add one-reg interface to virtual PTCR register Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 28/33] KVM: PPC: Book3S HV: Sanitise hv_regs on nested guest entry Paul Mackerras
2018-10-03 6:07 ` David Gibson
2018-10-02 11:31 ` [PATCH v3 29/33] KVM: PPC: Book3S HV: Handle differing endianness for H_ENTER_NESTED Paul Mackerras
2018-10-03 6:13 ` David Gibson [this message]
2018-10-04 9:29 ` Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 30/33] KVM: PPC: Book3S HV: Allow HV module to load without hypervisor mode Paul Mackerras
2018-10-03 6:15 ` David Gibson
2018-10-04 3:03 ` Paul Mackerras
2018-10-05 3:05 ` David Gibson
2018-10-02 11:31 ` [PATCH v3 31/33] KVM: PPC: Book3S HV: Add nested shadow page tables to debugfs Paul Mackerras
2018-10-02 11:31 ` [PATCH v3 32/33] KVM: PPC: Book3S HV: Use hypercalls for TLB invalidation when nested Paul Mackerras
2018-10-03 6:17 ` David Gibson
2018-10-02 11:31 ` [PATCH v3 33/33] KVM: PPC: Book3S HV: Add a VM capability to enable nested virtualization Paul Mackerras
2018-10-03 6:21 ` David Gibson
2018-10-04 9:48 ` Paul Mackerras
2018-10-05 3:29 ` David Gibson
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=20181003061336.GV1886@umbus.fritz.box \
--to=david@gibson.dropbear.id.au \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=paulus@ozlabs.org \
/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