From: Scott Wood <scottwood@freescale.com>
To: Alexander Graf <agraf@suse.de>
Cc: Bhushan Bharat-R65777 <R65777@freescale.com>,
"kvm-ppc@vger.kernel.org" <kvm-ppc@vger.kernel.org>,
"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: [PATCH 8/8] KVM:PPC:booke: Allow debug interrupt injection to guest
Date: Fri, 1 Feb 2013 16:38:50 -0600 [thread overview]
Message-ID: <1359758330.23561.8@snotra> (raw)
In-Reply-To: <FEA566E6-687E-46DD-9B64-73038645A9E2@suse.de> (from agraf@suse.de on Thu Jan 31 18:11:32 2013)
On 01/31/2013 06:11:32 PM, Alexander Graf wrote:
>
> On 31.01.2013, at 23:40, Scott Wood wrote:
>
> > On 01/31/2013 01:20:39 PM, Alexander Graf wrote:
> >> On 31.01.2013, at 20:05, Alexander Graf wrote:
> >> >
> >> > On 31.01.2013, at 19:54, Scott Wood wrote:
> >> >
> >> >> On 01/31/2013 12:52:41 PM, Alexander Graf wrote:
> >> >>> On 31.01.2013, at 19:43, Scott Wood wrote:
> >> >>>> On 01/31/2013 12:21:07 PM, Alexander Graf wrote:
> >> >>>>> How about something like this? Then both targets at least
> suck as much :).
> >> >>>>
> >> >>>> I'm not sure that should be the goal...
> >> >>>>
> >> >>>>> Thanks to e500mc's awful hardware design, we don't know who
> sets the MSR_DE bit. Once we forced it onto the guest, we have no
> change to know whether the guest also set it or not. We could only
> guess.
> >> >>>>
> >> >>>> MSRP[DEP] can prevent the guest from modifying MSR[DE] -- but
> we still need to set it in the first place.
> >> >>>>
> >> >>>> According to ISA V2.06B, the hypervisor should set DBCR0[EDM]
> to let the guest know that the debug resources are not available, and
> that "the value of MSR[DE] is not specified and not modifiable".
> >> >>> So what would the guest do then to tell the hypervisor that it
> actually wants to know about debug events?
> >> >>
> >> >> The guest is out of luck, just as if a JTAG were in use.
> >> >
> >> > Hrm.
> >> >
> >> > Can we somehow generalize this "out of luck" behavior?
> >> >
> >> > Every time we would set or clear an MSR bit in shadow_msr on
> e500v2, we would instead set or clear it in the real MSR. That way
> only e500mc is out of luck, but the code would still be shared.
> >
> > I don't follow. e500v2 is just as out-of-luck. The mechanism
> simply does not support sharing debug resources.
>
> For e500v2 we have 2 fields
>
> * MSR as the guest sees it
> * MSR as we execute when the guest runs
>
> Since we know the MSR when the guest sees it, we can decide what to
> do when we get an unhandled debug interrupt.
That's not the same thing as making the real MSR[DE] show up in the
guest MSR[DE].
There are other problems with sharing -- what happens when both host
and guest try to write to a particular IAC or DAC?
Also, performance would be pretty awful if the guest has e.g. single
stepping in DBCR0 enabled but MSR[DE]=0, and the host doesn't care
about single stepping (but does want debugging enabled in general).
> > What do you mean by "the real MSR"? The real MSR is shadow_msr,
> and MSR_DE must always be set there if the host is debugging the
> guest. As for reflecting it into the guest MSR, we could, but I
> don't really see the point. We're never going to actually send a
> debug exception to the guest when the host owns the debug resources.
>
> Why not? That's the whole point of jumping through user space.
That's still needed for software breakpoints, which don't rely on the
debug resources.
> 1) guest exits with debug interrupt
> 2) QEMU gets a debug exit
> 3) QEMU checks in its list whether it belongs to its own debug
> points
> 4) if not, it reinjects the interrupt into the guest
>
> Step 4 is pretty difficult to do when we don't know whether the guest
> is actually capable of handling debug interrupts at that moment.
Software breakpoints take a Program interrupt rather than a Debug
interrupt, unless MSR[DE]=1 and DBCR0[TRAP]=1. If the guest does not
own debug resources we should always send it to the Program interrupt,
so MSR[DE] doesn't matter.
> > The "&= ~MSR_DE" line is pointless on bookehv, and makes it harder
> to read. I had to stare at it a while before noticing that you
> initially set is_debug from the guest MSR and that you'd never really
> clear MSR_DE here on bookehv.
>
> Well, I'm mostly bouncing ideas here to find a way to express what
> we're trying to say in a way that someone who hasn't read this email
> thread would still understand what's going on :).
I think it's already straightforward enough if you accept that shared
debug resources aren't supported, and that we are either in a mode
where the real MSR[DE] reflects the guest MSR[DE], or a mode where the
real MSR[DE] is always on in guest mode and the guest MSR[DE] is
irrelevant.
> How about this version?
>
>
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index 38a62ef..9929c41 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c
> @@ -133,6 +133,28 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu
> *vcpu)
> #endif
> }
>
> +static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu)
> +{
> +#ifndef CONFIG_KVM_BOOKE_HV
> + /* Synchronize guest's desire to get debug interrupts into
> shadow MSR */
> + vcpu->arch.shadow_msr &= ~MSR_DE;
> + vcpu->arch.shadow_msr |= vcpu->arch.shared->msr & MSR_DE;
> +#endif
> +
> + /* Force enable debug interrupts when user space wants to debug
> */
> + if (vcpu->guest_debug) {
> +#ifdef CONFIG_KVM_BOOKE_HV
> + /*
> + * Since there is no shadow MSR, sync MSR_DE into the
> guest
> + * visible MSR.
> + */
> + vcpu->arch.shared->msr |= MSR_DE;
> +#else
> + vcpu->arch.shadow_msr |= MSR_DE;
> +#endif
> + }
> +}
This shows "guest's desire to get debug interrupts" in a context that
is not specifically for !vcpu->guest_debug, which is misleading.
> +
> /*
> * Helper function for "full" MSR writes. No need to call this if
> only
> * EE/CE/ME/DE/RI are changing.
> @@ -150,6 +172,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32
> new_msr)
> kvmppc_mmu_msr_notify(vcpu, old_msr);
> kvmppc_vcpu_sync_spe(vcpu);
> kvmppc_vcpu_sync_fpu(vcpu);
> + kvmppc_vcpu_sync_debug(vcpu);
> }
>
> static void kvmppc_booke_queue_irqprio(struct kvm_vcpu *vcpu,
>
>
> My main concern here is that we don't know when to remove MSR_DE
> again from the (shadow) MSR. So how about this one instead?
Why wouldn't you know this? if (vcpu->guest_debug) { you never remove
it } else { just copy whatever's in guest MSR }
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index 38a62ef..2676703 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c
> @@ -142,7 +142,7 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32
> new_msr)
> u32 old_msr = vcpu->arch.shared->msr;
>
> #ifdef CONFIG_KVM_BOOKE_HV
> - new_msr |= MSR_GS;
> + new_msr |= MSR_GS | MSR_DE;
> #endif
>
> vcpu->arch.shared->msr = new_msr;
>
>
> That would semantically move e500mc to the same logic as e500v2. With
> the main difference that we have no idea what MSR_DE value the guest
> really wanted to have set.
This would break the case where the guest owns the debug resources.
> If I read the spec correctly, rfci traps.
rfdi is the relevant one for e500mc, but yes.
> So we know the time frame from [inject debug interrupt ... rfci].
> During that time we know for sure that the guest thinks MSR_DE is 0.
No, we don't. The guest could have tried to use mtmsr or rfi to enable
MSR[DE]. It could have seen the context it came from was userspace,
and scheduled to another process, etc.
> Outside of that context, we just have to assume the guest can always
> receive debug interrupts if it configured them.
No.
-Scott
next prev parent reply other threads:[~2013-02-01 22:38 UTC|newest]
Thread overview: 59+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 8:24 [PATCH 2/8] KVM: PPC: booke: Allow multiple exception types Bharat Bhushan
2013-01-16 8:24 ` [PATCH 3/8] KVM: PPC: booke: Added debug handler Bharat Bhushan
2013-01-25 11:42 ` Alexander Graf
2013-01-30 11:30 ` Bhushan Bharat-R65777
2013-01-31 12:17 ` Alexander Graf
2013-01-31 16:58 ` Bhushan Bharat-R65777
2013-01-31 17:08 ` Alexander Graf
2013-01-31 17:11 ` Alexander Graf
2013-02-01 5:04 ` Bhushan Bharat-R65777
2013-02-01 8:06 ` Alexander Graf
2013-02-01 9:07 ` Bhushan Bharat-R65777
2013-02-07 14:21 ` Alexander Graf
2013-02-07 14:48 ` Bhushan Bharat-R65777
2013-02-07 15:01 ` Alexander Graf
2013-01-16 8:24 ` [PATCH 4/8] Added ONE_REG interface for debug instruction Bharat Bhushan
2013-01-25 11:48 ` Alexander Graf
2013-01-31 17:44 ` Bhushan Bharat-R65777
2013-01-31 17:52 ` Alexander Graf
2013-01-31 17:58 ` Bhushan Bharat-R65777
2013-01-31 18:22 ` Alexander Graf
2013-02-04 0:41 ` Paul Mackerras
2013-02-07 14:29 ` Alexander Graf
2013-02-11 0:22 ` Paul Mackerras
2013-01-16 8:24 ` [PATCH 5/8] KVM: PPC: debug stub interface parameter defined Bharat Bhushan
2013-01-17 7:22 ` Paul Mackerras
2013-01-17 11:11 ` Bhushan Bharat-R65777
2013-01-25 11:53 ` Alexander Graf
2013-01-30 14:15 ` Bhushan Bharat-R65777
2013-01-31 13:01 ` Alexander Graf
2013-01-31 14:05 ` Bhushan Bharat-R65777
2013-01-31 14:27 ` Alexander Graf
2013-01-31 14:44 ` Bhushan Bharat-R65777
2013-01-16 8:24 ` [PATCH 6/8] booke: Added DBCR4 SPR number Bharat Bhushan
2013-01-16 8:24 ` [PATCH 7/8] KVM: PPC: booke/bookehv: Add debug stub support Bharat Bhushan
2013-01-25 12:07 ` Alexander Graf
2013-02-01 6:31 ` Bhushan Bharat-R65777
2013-02-01 8:21 ` Alexander Graf
2013-01-16 8:24 ` [PATCH 8/8] KVM:PPC:booke: Allow debug interrupt injection to guest Bharat Bhushan
2013-01-25 12:13 ` Alexander Graf
2013-01-30 11:12 ` Bhushan Bharat-R65777
2013-01-31 12:04 ` Alexander Graf
2013-01-31 17:59 ` Bhushan Bharat-R65777
2013-01-31 18:21 ` Alexander Graf
2013-01-31 18:43 ` Scott Wood
2013-01-31 18:52 ` Alexander Graf
2013-01-31 18:54 ` Scott Wood
2013-01-31 19:05 ` Alexander Graf
2013-01-31 19:20 ` Alexander Graf
2013-01-31 22:40 ` Scott Wood
2013-02-01 0:11 ` Alexander Graf
2013-02-01 22:38 ` Scott Wood [this message]
2013-02-04 4:48 ` Bhushan Bharat-R65777
2013-02-04 19:47 ` Scott Wood
2013-02-07 14:58 ` Alexander Graf
2013-02-07 15:25 ` Bhushan Bharat-R65777
2013-02-07 15:53 ` Alexander Graf
2013-02-07 15:00 ` Bhushan Bharat-R65777
2013-02-07 15:08 ` Alexander Graf
2013-01-31 18:03 ` Scott Wood
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=1359758330.23561.8@snotra \
--to=scottwood@freescale.com \
--cc=R65777@freescale.com \
--cc=agraf@suse.de \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.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