From: Scott Wood <scottwood@freescale.com>
To: Alexander Graf <agraf@suse.de>
Cc: linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org,
kvm-ppc@vger.kernel.org
Subject: Re: [PATCH 13/30] KVM: PPC: booke: category E.HV (GS-mode) support
Date: Fri, 17 Feb 2012 15:12:01 -0600 [thread overview]
Message-ID: <4F3EC2A1.7080702@freescale.com> (raw)
In-Reply-To: <1329498837-11717-14-git-send-email-agraf@suse.de>
On 02/17/2012 11:13 AM, Alexander Graf wrote:
> From: Scott Wood <scottwood@freescale.com>
>
> Chips such as e500mc that implement category E.HV in Power ISA 2.06
> provide hardware virtualization features, including a new MSR mode for
> guest state. The guest OS can perform many operations without trapping
> into the hypervisor, including transitions to and from guest userspace.
>
> Since we can use SRR1[GS] to reliably tell whether an exception came from
> guest state, instead of messing around with IVPR, we use DO_KVM similarly
> to book3s.
>
> Current issues include:
> - Machine checks from guest state are not routed to the host handler.
> - The guest can cause a host oops by executing an emulated instruction
> in a page that lacks read permission. Existing e500/4xx support has
> the same problem.
>
> Includes work by Ashish Kalra <Ashish.Kalra@freescale.com>,
> Varun Sethi <Varun.Sethi@freescale.com>, and
> Liu Yu <yu.liu@freescale.com>.
>
> Signed-off-by: Scott Wood <scottwood@freescale.com>
> [agraf: remove pt_regs usage]
> Signed-off-by: Alexander Graf <agraf@suse.de>
> ---
Thanks for picking this up!
> +static unsigned long get_guest_esr(struct kvm_vcpu *vcpu)
> +{
> +#ifdef CONFIG_KVM_BOOKE_HV
> + return mfspr(SPRN_ESR);
> +#else
> + return vcpu->arch.shared->esr;
> +#endif
> +}
s/SPRN_ESR/SPRN_GESR/
> int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
> unsigned int exit_nr)
> {
> - enum emulation_result er;
> int r = RESUME_HOST;
>
> /* update before a new last_exit_type is rewritten */
> kvmppc_update_timing_stats(vcpu);
>
> + switch (exit_nr) {
> + case BOOKE_INTERRUPT_EXTERNAL:
> + do_IRQ(current->thread.regs);
> + break;
What will current->thread.regs point to here? Something on the stack
from the last normal host exception entry?
We probably want to create a pt_regs on the stack and at least provide
PC, LR, and r1 for perfmon interrupts and such.
> @@ -384,30 +558,56 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
>
> switch (exit_nr) {
> case BOOKE_INTERRUPT_MACHINE_CHECK:
> - printk("MACHINE CHECK: %lx\n", mfspr(SPRN_MCSR));
> - kvmppc_dump_vcpu(vcpu);
> - r = RESUME_HOST;
> + kvm_resched(vcpu);
> + r = RESUME_GUEST;
> break;
Leave this bit out (proper machine check handling will come later).
> case BOOKE_INTERRUPT_PROGRAM:
> - if (vcpu->arch.shared->msr & MSR_PR) {
> + if (vcpu->arch.shared->msr & (MSR_PR | MSR_GS)) {
> /* Program traps generated by user-level software must be handled
> * by the guest kernel. */
> kvmppc_core_queue_program(vcpu, vcpu->arch.fault_esr);
Should update the comment for why we're checking GS (i.e. we get a
different trap for emulation with GS-mode).
> +#define SET_VCPU(vcpu) \
> + PPC_STL vcpu, (THREAD + THREAD_KVM_VCPU)(r2)
Change spaces to tab before PPC_STL
> +#define LONGBYTES (BITS_PER_LONG / 8)
> +
> +#define VCPU_GPR(n) (VCPU_GPRS + (n * LONGBYTES))
> +#define VCPU_GUEST_SPRG(n) (VCPU_GUEST_SPRGS + (n * LONGBYTES))
> +
> +/* The host stack layout: */
> +#define HOST_R1 (0 * LONGBYTES) /* Implied by stwu. */
> +#define HOST_CALLEE_LR (1 * LONGBYTES)
> +#define HOST_RUN (2 * LONGBYTES) /* struct kvm_run */
> +/*
> + * r2 is special: it holds 'current', and it made nonvolatile in the
> + * kernel with the -ffixed-r2 gcc option.
> + */
> +#define HOST_R2 (3 * LONGBYTES)
> +#define HOST_NV_GPRS (4 * LONGBYTES)
> +#define HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * LONGBYTES))
> +#define HOST_MIN_STACK_SIZE (HOST_NV_GPR(31) + LONGBYTES)
> +#define HOST_STACK_SIZE ((HOST_MIN_STACK_SIZE + 15) & ~15) /* Align. */
> +#define HOST_STACK_LR (HOST_STACK_SIZE + LONGBYTES) /* In caller stack frame. */
> +
> +#define NEED_EMU 0x00000001 /* emulation -- save nv regs */
> +#define NEED_DEAR 0x00000002 /* save faulting DEAR */
> +#define NEED_ESR 0x00000004 /* save faulting ESR */
> +
> +/*
> + * On entry:
> + * r4 = vcpu, r5 = srr0, r6 = srr1
> + * saved in vcpu: cr, ctr, r3-r13
> + */
> +.macro kvm_handler_common intno, srr0, flags
> + mfspr r10, SPRN_PID
> + lwz r8, VCPU_HOST_PID(r4)
> + PPC_LL r11, VCPU_SHARED(r4)
> + PPC_STL r14, VCPU_GPR(r14)(r4) /* We need a non-volatile GPR. */
> + li r14, \intno
> +
> + stw r10, VCPU_GUEST_PID(r4)
> + mtspr SPRN_PID, r8
> +
> + .if \flags & NEED_EMU
> + lwz r9, VCPU_KVM(r4)
> + .endif
> +
> +#ifdef CONFIG_KVM_EXIT_TIMING
> + /* save exit time */
> +1: mfspr r7, SPRN_TBRU
> + mfspr r8, SPRN_TBRL
> + mfspr r9, SPRN_TBRU
> + cmpw r9, r7
> + PPC_STL r8, VCPU_TIMING_EXIT_TBL(r4)
> + bne- 1b
> + PPC_STL r9, VCPU_TIMING_EXIT_TBU(r4)
> +#endif
As you pointed out to me last time, r9 is clobbered if exit timing is
enabled (but see below, the load of VCPU_KVM can be removed along with
the subsequent load of LVM_LPID(r9)).
> + oris r8, r6, MSR_CE@h
> +#ifndef CONFIG_64BIT
> + stw r6, (VCPU_SHARED_MSR + 4)(r11)
> +#else
> + std r6, (VCPU_SHARED_MSR)(r11)
> +#endif
> + ori r8, r8, MSR_ME | MSR_RI
> + PPC_STL r5, VCPU_PC(r4)
> +
> + /*
> + * Make sure CE/ME/RI are set (if appropriate for exception type)
> + * whether or not the guest had it set. Since mfmsr/mtmsr are
> + * somewhat expensive, skip in the common case where the guest
> + * had all these bits set (and thus they're still set if
> + * appropriate for the exception type).
> + */
> + cmpw r6, r8
> + .if \flags & NEED_EMU
> + lwz r9, KVM_LPID(r9)
> + .endif
Where do we use r9? This is probably left over from something old.
-Scott
next prev parent reply other threads:[~2012-02-17 21:12 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-02-17 17:13 [PATCH 00/30] KVM: PPC: e500mc support Alexander Graf
2012-02-17 17:13 ` [PATCH 01/30] powerpc/booke: Set CPU_FTR_DEBUG_LVL_EXC on 32-bit Alexander Graf
2012-02-17 17:13 ` [PATCH 02/30] powerpc/e500: split CPU_FTRS_ALWAYS/CPU_FTRS_POSSIBLE Alexander Graf
2012-02-17 17:13 ` [PATCH 03/30] KVM: PPC: factor out lpid allocator from book3s_64_mmu_hv Alexander Graf
2012-02-17 17:13 ` [PATCH 04/30] KVM: PPC: booke: add booke-level vcpu load/put Alexander Graf
2012-02-17 17:13 ` [PATCH 05/30] KVM: PPC: booke: Move vm core init/destroy out of booke.c Alexander Graf
2012-02-17 17:13 ` [PATCH 06/30] KVM: PPC: e500: rename e500_tlb.h to e500.h Alexander Graf
2012-02-17 17:13 ` [PATCH 07/30] KVM: PPC: e500: merge <asm/kvm_e500.h> into arch/powerpc/kvm/e500.h Alexander Graf
2012-02-17 17:13 ` [PATCH 08/30] KVM: PPC: e500: clean up arch/powerpc/kvm/e500.h Alexander Graf
2012-02-17 17:13 ` [PATCH 09/30] KVM: PPC: e500: refactor core-specific TLB code Alexander Graf
2012-02-17 17:13 ` [PATCH 10/30] KVM: PPC: e500: Track TLB1 entries with a bitmap Alexander Graf
2012-02-17 17:13 ` [PATCH 11/30] KVM: PPC: e500: emulate tlbilx Alexander Graf
2012-02-17 17:13 ` [PATCH 12/30] powerpc/booke: Provide exception macros with interrupt name Alexander Graf
2012-02-17 17:13 ` [PATCH 13/30] KVM: PPC: booke: category E.HV (GS-mode) support Alexander Graf
2012-02-17 21:12 ` Scott Wood [this message]
2012-02-20 11:40 ` Alexander Graf
2012-02-17 17:13 ` [PATCH 14/30] KVM: PPC: booke: standard PPC floating point support Alexander Graf
2012-02-17 17:13 ` [PATCH 15/30] KVM: PPC: e500mc support Alexander Graf
2012-02-17 17:13 ` [PATCH 16/30] KVM: PPC: e500mc: Add doorbell emulation support Alexander Graf
2012-02-17 21:55 ` Scott Wood
2012-02-17 21:57 ` Scott Wood
2012-02-20 11:49 ` Alexander Graf
2012-02-20 15:39 ` Scott Wood
2012-02-20 15:42 ` Alexander Graf
2012-02-17 17:13 ` [PATCH 17/30] KVM: PPC: e500mc: implicitly set MSR_GS Alexander Graf
2012-02-17 17:13 ` [PATCH 18/30] KVM: PPC: e500mc: Move r1/r2 restoration very early Alexander Graf
2012-02-17 17:13 ` [PATCH 19/30] KVM: PPC: e500mc: add load inst fixup Alexander Graf
2012-02-17 23:17 ` Scott Wood
2012-02-17 17:13 ` [PATCH 20/30] KVM: PPC: rename CONFIG_KVM_E500 -> CONFIG_KVM_E500V2 Alexander Graf
2012-02-17 17:13 ` [PATCH 21/30] KVM: PPC: make e500v2 and e500mc mutually exclusive Alexander Graf
2012-02-17 22:13 ` Scott Wood
2012-02-17 17:13 ` [PATCH 22/30] KVM: PPC: booke: remove leftover debugging Alexander Graf
2012-02-17 17:13 ` [PATCH 23/30] KVM: PPC: booke: deliver program int on emulation failure Alexander Graf
2012-02-17 17:13 ` [PATCH 24/30] KVM: PPC: booke: call resched after every exit Alexander Graf
2012-02-17 23:00 ` Scott Wood
2012-02-20 13:17 ` Alexander Graf
2012-02-20 17:18 ` Scott Wood
2012-02-17 17:13 ` [PATCH 25/30] KVM: PPC: booke: BOOKE_IRQPRIO_MAX is n+1 Alexander Graf
2012-02-17 17:13 ` [PATCH 26/30] KVM: PPC: bookehv: fix exit timing Alexander Graf
2012-02-17 17:13 ` [PATCH 27/30] KVM: PPC: bookehv: remove negation for CONFIG_64BIT Alexander Graf
2012-02-17 17:13 ` [PATCH 28/30] KVM: PPC: bookehv: remove SET_VCPU Alexander Graf
2012-02-17 17:13 ` [PATCH 29/30] KVM: PPC: bookehv: disable MAS register updates early Alexander Graf
2012-02-17 17:13 ` [PATCH 30/30] KVM: PPC: bookehv: add comment about shadow_msr Alexander Graf
-- strict thread matches above, loose matches on Subject: below --
2012-02-17 16:56 [PATCH 00/30] KVM: PPC: e500mc support Alexander Graf
2012-02-17 16:56 ` [PATCH 13/30] KVM: PPC: booke: category E.HV (GS-mode) support Alexander Graf
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=4F3EC2A1.7080702@freescale.com \
--to=scottwood@freescale.com \
--cc=agraf@suse.de \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=linuxppc-dev@lists.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;
as well as URLs for NNTP newsgroup(s).