RE: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-05 Thread Bhushan Bharat-R65777


> -Original Message-
> From: kvm-ow...@vger.kernel.org [mailto:kvm-ow...@vger.kernel.org] On Behalf 
> Of
> Alexander Graf
> Sent: Friday, May 03, 2013 6:48 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421
> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support
> 
> 
> On 03.05.2013, at 15:11, Bhushan Bharat-R65777 wrote:
> 
> >
> >
> >> -Original Message-
> >> From: Alexander Graf [mailto:ag...@suse.de]
> >> Sent: Friday, May 03, 2013 6:00 PM
> >> To: Bhushan Bharat-R65777
> >> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421
> >> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub
> >> support
> >>
> >>
> >> On 03.05.2013, at 13:08, Alexander Graf wrote:
> >>
> >>>
> >>>
> >>> Am 03.05.2013 um 12:48 schrieb Bhushan Bharat-R65777 
> >>> :
> >>>
> >>>>>>>> +static void kvmppc_booke_vcpu_load_debug_regs(struct kvm_vcpu
> >>>>>>>> +*vcpu) {
> >>>>>>>> +if (!vcpu->arch.debug_active)
> >>>>>>>> +return;
> >>>>>>>> +
> >>>>>>>> +/* Disable all debug events and clead pending debug events */
> >>>>>>>> +mtspr(SPRN_DBCR0, 0x0);
> >>>>>>>> +kvmppc_clear_dbsr();
> >>>>>>>> +
> >>>>>>>> +/*
> >>>>>>>> + * Check whether guest still need debug resource, if not then
> there
> >>>>>>>> + * is no need to restore guest context.
> >>>>>>>> + */
> >>>>>>>> +if (!vcpu->arch.shadow_dbg_reg.dbcr0)
> >>>>>>>> +return;
> >>>>>>>> +
> >>>>>>>> +/* Load Guest Context */
> >>>>>>>> +mtspr(SPRN_DBCR1, vcpu->arch.shadow_dbg_reg.dbcr1);
> >>>>>>>> +mtspr(SPRN_DBCR2, vcpu->arch.shadow_dbg_reg.dbcr2); #ifdef
> >>>>>>>> +CONFIG_KVM_E500MC
> >>>>>>>> +mtspr(SPRN_DBCR4, vcpu->arch.shadow_dbg_reg.dbcr4);
> >>>>>>>
> >>>>>>> You need to make sure DBCR4 is 0 when you leave things back to
> >>>>>>> normal user space. Otherwise guest debug can interfere with host 
> >>>>>>> debug.
> >>>>>>
> >>>>>>
> >>>>>> ok
> >>>>>>
> >>>>>>>
> >>>>>>>> +#endif
> >>>>>>>> +mtspr(SPRN_IAC1, vcpu->arch.shadow_dbg_reg.iac[0]);
> >>>>>>>> +mtspr(SPRN_IAC2, vcpu->arch.shadow_dbg_reg.iac[1]);
> >>>>>>>> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> >>>>>>>> +mtspr(SPRN_IAC3, vcpu->arch.shadow_dbg_reg.iac[2]);
> >>>>>>>> +mtspr(SPRN_IAC4, vcpu->arch.shadow_dbg_reg.iac[3]);
> >>>>>>>> +#endif
> >>>>>>>> +mtspr(SPRN_DAC1, vcpu->arch.shadow_dbg_reg.dac[0]);
> >>>>>>>> +mtspr(SPRN_DAC2, vcpu->arch.shadow_dbg_reg.dac[1]);
> >>>>>>>> +
> >>>>>>>> +/* Enable debug events after other debug registers restored */
> >>>>>>>> +mtspr(SPRN_DBCR0, vcpu->arch.shadow_dbg_reg.dbcr0); }
> >>>>>>>
> >>>>>>> All of the code above looks suspiciously similar to
> >>>>>>> prime_debug_regs();. Can't we somehow reuse that?
> >>>>>>
> >>>>>> I think we can if
> >>>>>> - Save thread->debug_regs in local data structure
> >>>>>
> >>>>> Yes, it can even be on the stack.
> >>>>>
> >>>>>> - Load vcpu->arch->debug_regs in thread->debug_regs
> >>>>>> - Call prime_debug_regs();
> >>>>>> - Restore thread->debug_regs from local save values in first step
> >>>>>
> >>>>> On heavyweight exit, based on the values on stack, yes.
> >>>>
> >>>> This is how I think we can save/restore debug context. Please
> >>>> correct if I am
> >> missing something.
> >>>
> >>> Sounds about right :)
> >>
> >> Actually, what happens if a guest breakpoint is set to a kernel
> >> address that happens to be within the scope of kvm code?
> >
> > You mean address of kvm code in guest or host?
> >
> > If host, we already mentioned that we do not support that. Right?
> 
> QEMU wants to debug the guest at address 0xc123. kvm_run happens to be at
> that address. We switch the debug registers through prime_debug_regs. Will the
> host kernel receive a debug interrupt when it runs kvm_run()?

No,
On e500v2, we uses DBCR1 and DBCR2 to not allow debug events when MSR.PR = 0
On e500mc+, we uses EPCR.DUVD to not allow debug events when in hypervisor mode.

-Bharat

> 
> 
> Alex
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm" in the body of 
> a
> message to majord...@vger.kernel.org More majordomo info at
> http://vger.kernel.org/majordomo-info.html


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-03 Thread Alexander Graf

On 03.05.2013, at 15:11, Bhushan Bharat-R65777 wrote:

> 
> 
>> -Original Message-
>> From: Alexander Graf [mailto:ag...@suse.de]
>> Sent: Friday, May 03, 2013 6:00 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421
>> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support
>> 
>> 
>> On 03.05.2013, at 13:08, Alexander Graf wrote:
>> 
>>> 
>>> 
>>> Am 03.05.2013 um 12:48 schrieb Bhushan Bharat-R65777 :
>>> 
>>>>>>>> +static void kvmppc_booke_vcpu_load_debug_regs(struct kvm_vcpu
>>>>>>>> +*vcpu) {
>>>>>>>> +if (!vcpu->arch.debug_active)
>>>>>>>> +return;
>>>>>>>> +
>>>>>>>> +/* Disable all debug events and clead pending debug events */
>>>>>>>> +mtspr(SPRN_DBCR0, 0x0);
>>>>>>>> +kvmppc_clear_dbsr();
>>>>>>>> +
>>>>>>>> +/*
>>>>>>>> + * Check whether guest still need debug resource, if not then 
>>>>>>>> there
>>>>>>>> + * is no need to restore guest context.
>>>>>>>> + */
>>>>>>>> +if (!vcpu->arch.shadow_dbg_reg.dbcr0)
>>>>>>>> +return;
>>>>>>>> +
>>>>>>>> +/* Load Guest Context */
>>>>>>>> +mtspr(SPRN_DBCR1, vcpu->arch.shadow_dbg_reg.dbcr1);
>>>>>>>> +mtspr(SPRN_DBCR2, vcpu->arch.shadow_dbg_reg.dbcr2); #ifdef
>>>>>>>> +CONFIG_KVM_E500MC
>>>>>>>> +mtspr(SPRN_DBCR4, vcpu->arch.shadow_dbg_reg.dbcr4);
>>>>>>> 
>>>>>>> You need to make sure DBCR4 is 0 when you leave things back to
>>>>>>> normal user space. Otherwise guest debug can interfere with host debug.
>>>>>> 
>>>>>> 
>>>>>> ok
>>>>>> 
>>>>>>> 
>>>>>>>> +#endif
>>>>>>>> +mtspr(SPRN_IAC1, vcpu->arch.shadow_dbg_reg.iac[0]);
>>>>>>>> +mtspr(SPRN_IAC2, vcpu->arch.shadow_dbg_reg.iac[1]);
>>>>>>>> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
>>>>>>>> +mtspr(SPRN_IAC3, vcpu->arch.shadow_dbg_reg.iac[2]);
>>>>>>>> +mtspr(SPRN_IAC4, vcpu->arch.shadow_dbg_reg.iac[3]);
>>>>>>>> +#endif
>>>>>>>> +mtspr(SPRN_DAC1, vcpu->arch.shadow_dbg_reg.dac[0]);
>>>>>>>> +mtspr(SPRN_DAC2, vcpu->arch.shadow_dbg_reg.dac[1]);
>>>>>>>> +
>>>>>>>> +/* Enable debug events after other debug registers restored */
>>>>>>>> +mtspr(SPRN_DBCR0, vcpu->arch.shadow_dbg_reg.dbcr0); }
>>>>>>> 
>>>>>>> All of the code above looks suspiciously similar to
>>>>>>> prime_debug_regs();. Can't we somehow reuse that?
>>>>>> 
>>>>>> I think we can if
>>>>>> - Save thread->debug_regs in local data structure
>>>>> 
>>>>> Yes, it can even be on the stack.
>>>>> 
>>>>>> - Load vcpu->arch->debug_regs in thread->debug_regs
>>>>>> - Call prime_debug_regs();
>>>>>> - Restore thread->debug_regs from local save values in first step
>>>>> 
>>>>> On heavyweight exit, based on the values on stack, yes.
>>>> 
>>>> This is how I think we can save/restore debug context. Please correct if I 
>>>> am
>> missing something.
>>> 
>>> Sounds about right :)
>> 
>> Actually, what happens if a guest breakpoint is set to a kernel address that
>> happens to be within the scope of kvm code?
> 
> You mean address of kvm code in guest or host?
> 
> If host, we already mentioned that we do not support that. Right?

QEMU wants to debug the guest at address 0xc123. kvm_run happens to be at 
that address. We switch the debug registers through prime_debug_regs. Will the 
host kernel receive a debug interrupt when it runs kvm_run()?


Alex

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-03 Thread Bhushan Bharat-R65777


> -Original Message-
> From: Alexander Graf [mailto:ag...@suse.de]
> Sent: Friday, May 03, 2013 6:00 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421
> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support
> 
> 
> On 03.05.2013, at 13:08, Alexander Graf wrote:
> 
> >
> >
> > Am 03.05.2013 um 12:48 schrieb Bhushan Bharat-R65777 :
> >
> >>>>>> +static void kvmppc_booke_vcpu_load_debug_regs(struct kvm_vcpu
> >>>>>> +*vcpu) {
> >>>>>> +if (!vcpu->arch.debug_active)
> >>>>>> +return;
> >>>>>> +
> >>>>>> +/* Disable all debug events and clead pending debug events */
> >>>>>> +mtspr(SPRN_DBCR0, 0x0);
> >>>>>> +kvmppc_clear_dbsr();
> >>>>>> +
> >>>>>> +/*
> >>>>>> + * Check whether guest still need debug resource, if not then 
> >>>>>> there
> >>>>>> + * is no need to restore guest context.
> >>>>>> + */
> >>>>>> +if (!vcpu->arch.shadow_dbg_reg.dbcr0)
> >>>>>> +return;
> >>>>>> +
> >>>>>> +/* Load Guest Context */
> >>>>>> +mtspr(SPRN_DBCR1, vcpu->arch.shadow_dbg_reg.dbcr1);
> >>>>>> +mtspr(SPRN_DBCR2, vcpu->arch.shadow_dbg_reg.dbcr2); #ifdef
> >>>>>> +CONFIG_KVM_E500MC
> >>>>>> +mtspr(SPRN_DBCR4, vcpu->arch.shadow_dbg_reg.dbcr4);
> >>>>>
> >>>>> You need to make sure DBCR4 is 0 when you leave things back to
> >>>>> normal user space. Otherwise guest debug can interfere with host debug.
> >>>>
> >>>>
> >>>> ok
> >>>>
> >>>>>
> >>>>>> +#endif
> >>>>>> +mtspr(SPRN_IAC1, vcpu->arch.shadow_dbg_reg.iac[0]);
> >>>>>> +mtspr(SPRN_IAC2, vcpu->arch.shadow_dbg_reg.iac[1]);
> >>>>>> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> >>>>>> +mtspr(SPRN_IAC3, vcpu->arch.shadow_dbg_reg.iac[2]);
> >>>>>> +mtspr(SPRN_IAC4, vcpu->arch.shadow_dbg_reg.iac[3]);
> >>>>>> +#endif
> >>>>>> +mtspr(SPRN_DAC1, vcpu->arch.shadow_dbg_reg.dac[0]);
> >>>>>> +mtspr(SPRN_DAC2, vcpu->arch.shadow_dbg_reg.dac[1]);
> >>>>>> +
> >>>>>> +/* Enable debug events after other debug registers restored */
> >>>>>> +mtspr(SPRN_DBCR0, vcpu->arch.shadow_dbg_reg.dbcr0); }
> >>>>>
> >>>>> All of the code above looks suspiciously similar to
> >>>>> prime_debug_regs();. Can't we somehow reuse that?
> >>>>
> >>>> I think we can if
> >>>> - Save thread->debug_regs in local data structure
> >>>
> >>> Yes, it can even be on the stack.
> >>>
> >>>> - Load vcpu->arch->debug_regs in thread->debug_regs
> >>>> - Call prime_debug_regs();
> >>>> - Restore thread->debug_regs from local save values in first step
> >>>
> >>> On heavyweight exit, based on the values on stack, yes.
> >>
> >> This is how I think we can save/restore debug context. Please correct if I 
> >> am
> missing something.
> >
> > Sounds about right :)
> 
> Actually, what happens if a guest breakpoint is set to a kernel address that
> happens to be within the scope of kvm code?

You mean address of kvm code in guest or host?

If host, we already mentioned that we do not support that. Right?

-Bharat

> We do accept debug events between
> vcpu_run and the assembly code, right?
> 
> 
> Alex
> 


--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-03 Thread Alexander Graf

On 03.05.2013, at 13:08, Alexander Graf wrote:

> 
> 
> Am 03.05.2013 um 12:48 schrieb Bhushan Bharat-R65777 :
> 
>> +static void kvmppc_booke_vcpu_load_debug_regs(struct kvm_vcpu
>> +*vcpu) {
>> +if (!vcpu->arch.debug_active)
>> +return;
>> +
>> +/* Disable all debug events and clead pending debug events */
>> +mtspr(SPRN_DBCR0, 0x0);
>> +kvmppc_clear_dbsr();
>> +
>> +/*
>> + * Check whether guest still need debug resource, if not then there
>> + * is no need to restore guest context.
>> + */
>> +if (!vcpu->arch.shadow_dbg_reg.dbcr0)
>> +return;
>> +
>> +/* Load Guest Context */
>> +mtspr(SPRN_DBCR1, vcpu->arch.shadow_dbg_reg.dbcr1);
>> +mtspr(SPRN_DBCR2, vcpu->arch.shadow_dbg_reg.dbcr2); #ifdef
>> +CONFIG_KVM_E500MC
>> +mtspr(SPRN_DBCR4, vcpu->arch.shadow_dbg_reg.dbcr4);
> 
> You need to make sure DBCR4 is 0 when you leave things back to normal
> user space. Otherwise guest debug can interfere with host debug.
 
 
 ok
 
> 
>> +#endif
>> +mtspr(SPRN_IAC1, vcpu->arch.shadow_dbg_reg.iac[0]);
>> +mtspr(SPRN_IAC2, vcpu->arch.shadow_dbg_reg.iac[1]);
>> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
>> +mtspr(SPRN_IAC3, vcpu->arch.shadow_dbg_reg.iac[2]);
>> +mtspr(SPRN_IAC4, vcpu->arch.shadow_dbg_reg.iac[3]);
>> +#endif
>> +mtspr(SPRN_DAC1, vcpu->arch.shadow_dbg_reg.dac[0]);
>> +mtspr(SPRN_DAC2, vcpu->arch.shadow_dbg_reg.dac[1]);
>> +
>> +/* Enable debug events after other debug registers restored */
>> +mtspr(SPRN_DBCR0, vcpu->arch.shadow_dbg_reg.dbcr0); }
> 
> All of the code above looks suspiciously similar to
> prime_debug_regs();. Can't we somehow reuse that?
 
 I think we can if
 - Save thread->debug_regs in local data structure
>>> 
>>> Yes, it can even be on the stack.
>>> 
 - Load vcpu->arch->debug_regs in thread->debug_regs
 - Call prime_debug_regs();
 - Restore thread->debug_regs from local save values in first step
>>> 
>>> On heavyweight exit, based on the values on stack, yes.
>> 
>> This is how I think we can save/restore debug context. Please correct if I 
>> am missing something.
> 
> Sounds about right :)

Actually, what happens if a guest breakpoint is set to a kernel address that 
happens to be within the scope of kvm code? We do accept debug events between 
vcpu_run and the assembly code, right?


Alex

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-03 Thread Alexander Graf


Am 03.05.2013 um 12:48 schrieb Bhushan Bharat-R65777 :

> +static void kvmppc_booke_vcpu_load_debug_regs(struct kvm_vcpu
> +*vcpu) {
> +if (!vcpu->arch.debug_active)
> +return;
> +
> +/* Disable all debug events and clead pending debug events */
> +mtspr(SPRN_DBCR0, 0x0);
> +kvmppc_clear_dbsr();
> +
> +/*
> + * Check whether guest still need debug resource, if not then there
> + * is no need to restore guest context.
> + */
> +if (!vcpu->arch.shadow_dbg_reg.dbcr0)
> +return;
> +
> +/* Load Guest Context */
> +mtspr(SPRN_DBCR1, vcpu->arch.shadow_dbg_reg.dbcr1);
> +mtspr(SPRN_DBCR2, vcpu->arch.shadow_dbg_reg.dbcr2); #ifdef
> +CONFIG_KVM_E500MC
> +mtspr(SPRN_DBCR4, vcpu->arch.shadow_dbg_reg.dbcr4);
 
 You need to make sure DBCR4 is 0 when you leave things back to normal
 user space. Otherwise guest debug can interfere with host debug.
>>> 
>>> 
>>> ok
>>> 
 
> +#endif
> +mtspr(SPRN_IAC1, vcpu->arch.shadow_dbg_reg.iac[0]);
> +mtspr(SPRN_IAC2, vcpu->arch.shadow_dbg_reg.iac[1]);
> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> +mtspr(SPRN_IAC3, vcpu->arch.shadow_dbg_reg.iac[2]);
> +mtspr(SPRN_IAC4, vcpu->arch.shadow_dbg_reg.iac[3]);
> +#endif
> +mtspr(SPRN_DAC1, vcpu->arch.shadow_dbg_reg.dac[0]);
> +mtspr(SPRN_DAC2, vcpu->arch.shadow_dbg_reg.dac[1]);
> +
> +/* Enable debug events after other debug registers restored */
> +mtspr(SPRN_DBCR0, vcpu->arch.shadow_dbg_reg.dbcr0); }
 
 All of the code above looks suspiciously similar to
 prime_debug_regs();. Can't we somehow reuse that?
>>> 
>>> I think we can if
>>> - Save thread->debug_regs in local data structure
>> 
>> Yes, it can even be on the stack.
>> 
>>> - Load vcpu->arch->debug_regs in thread->debug_regs
>>> - Call prime_debug_regs();
>>> - Restore thread->debug_regs from local save values in first step
>> 
>> On heavyweight exit, based on the values on stack, yes.
> 
> This is how I think we can save/restore debug context. Please correct if I am 
> missing something.

Sounds about right :)

Alex

> 
> 1) When QEMU is running
> 
> -> thread->debug_reg == QEMU debug register context.
> -> Kernel will handle switching the debug register on context switch.
> -> no vcpu_load() called
> 
> 2) QEMU makes ioctls (except RUN) 
> -> This will call vcpu_load()
> -> should not change context.
> -> Some ioctls can change vcpu debug register, context saved in 
> vcpu->debug_regs
> 
> 3) QEMU Makes RUN ioctl
> -> Save thread->debug_reg on STACK
> -> Store thread->debug_reg == vcpu->debug_reg
> -> load thread->debug_reg 
> -> RUN VCPU ( So thread points to vcpu context )
> 
> 4) Context switch happens When VCPU running
> -> makes vcpu_load() should not load any context
> -> kernel loads the vcpu context as thread->debug_regs points to vcpu context.
> 
> 5) On heavyweight_exit
> -> Load the context saved on stack in thread->debug_reg
> 
> Thanks
> -Bharat
> 
> 
> 
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-03 Thread Bhushan Bharat-R65777
> >>> +static void kvmppc_booke_vcpu_load_debug_regs(struct kvm_vcpu
> >>> +*vcpu) {
> >>> + if (!vcpu->arch.debug_active)
> >>> + return;
> >>> +
> >>> + /* Disable all debug events and clead pending debug events */
> >>> + mtspr(SPRN_DBCR0, 0x0);
> >>> + kvmppc_clear_dbsr();
> >>> +
> >>> + /*
> >>> +  * Check whether guest still need debug resource, if not then there
> >>> +  * is no need to restore guest context.
> >>> +  */
> >>> + if (!vcpu->arch.shadow_dbg_reg.dbcr0)
> >>> + return;
> >>> +
> >>> + /* Load Guest Context */
> >>> + mtspr(SPRN_DBCR1, vcpu->arch.shadow_dbg_reg.dbcr1);
> >>> + mtspr(SPRN_DBCR2, vcpu->arch.shadow_dbg_reg.dbcr2); #ifdef
> >>> +CONFIG_KVM_E500MC
> >>> + mtspr(SPRN_DBCR4, vcpu->arch.shadow_dbg_reg.dbcr4);
> >>
> >> You need to make sure DBCR4 is 0 when you leave things back to normal
> >> user space. Otherwise guest debug can interfere with host debug.
> >
> >
> > ok
> >
> >>
> >>> +#endif
> >>> + mtspr(SPRN_IAC1, vcpu->arch.shadow_dbg_reg.iac[0]);
> >>> + mtspr(SPRN_IAC2, vcpu->arch.shadow_dbg_reg.iac[1]);
> >>> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> >>> + mtspr(SPRN_IAC3, vcpu->arch.shadow_dbg_reg.iac[2]);
> >>> + mtspr(SPRN_IAC4, vcpu->arch.shadow_dbg_reg.iac[3]);
> >>> +#endif
> >>> + mtspr(SPRN_DAC1, vcpu->arch.shadow_dbg_reg.dac[0]);
> >>> + mtspr(SPRN_DAC2, vcpu->arch.shadow_dbg_reg.dac[1]);
> >>> +
> >>> + /* Enable debug events after other debug registers restored */
> >>> + mtspr(SPRN_DBCR0, vcpu->arch.shadow_dbg_reg.dbcr0); }
> >>
> >> All of the code above looks suspiciously similar to
> >> prime_debug_regs();. Can't we somehow reuse that?
> >
> > I think we can if
> > - Save thread->debug_regs in local data structure
> 
> Yes, it can even be on the stack.
> 
> > - Load vcpu->arch->debug_regs in thread->debug_regs
> > - Call prime_debug_regs();
> > - Restore thread->debug_regs from local save values in first step
> 
> On heavyweight exit, based on the values on stack, yes.

This is how I think we can save/restore debug context. Please correct if I am 
missing something.

1) When QEMU is running

-> thread->debug_reg == QEMU debug register context.
-> Kernel will handle switching the debug register on context switch.
-> no vcpu_load() called

2) QEMU makes ioctls (except RUN) 
 -> This will call vcpu_load()
 -> should not change context.
 -> Some ioctls can change vcpu debug register, context saved in 
vcpu->debug_regs

3) QEMU Makes RUN ioctl
 -> Save thread->debug_reg on STACK
 -> Store thread->debug_reg == vcpu->debug_reg
 -> load thread->debug_reg 
 -> RUN VCPU ( So thread points to vcpu context )

4) Context switch happens When VCPU running
 -> makes vcpu_load() should not load any context
 -> kernel loads the vcpu context as thread->debug_regs points to vcpu context.

5) On heavyweight_exit
 -> Load the context saved on stack in thread->debug_reg

Thanks
-Bharat



--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-02 Thread Alexander Graf

On 02.05.2013, at 16:00, Bhushan Bharat-R65777 wrote:

> 
> 
>> -Original Message-
>> From: Alexander Graf [mailto:ag...@suse.de]
>> Sent: Thursday, May 02, 2013 4:35 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421
>> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support
>> 
>> 
>> On 02.05.2013, at 11:46, Bhushan Bharat-R65777 wrote:

[...]

>>> 
>>>> 
>>>>> +#endif
>>>>> + mtspr(SPRN_IAC1, vcpu->arch.shadow_dbg_reg.iac[0]);
>>>>> + mtspr(SPRN_IAC2, vcpu->arch.shadow_dbg_reg.iac[1]);
>>>>> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
>>>>> + mtspr(SPRN_IAC3, vcpu->arch.shadow_dbg_reg.iac[2]);
>>>>> + mtspr(SPRN_IAC4, vcpu->arch.shadow_dbg_reg.iac[3]);
>>>>> +#endif
>>>>> + mtspr(SPRN_DAC1, vcpu->arch.shadow_dbg_reg.dac[0]);
>>>>> + mtspr(SPRN_DAC2, vcpu->arch.shadow_dbg_reg.dac[1]);
>>>>> +
>>>>> + /* Enable debug events after other debug registers restored */
>>>>> + mtspr(SPRN_DBCR0, vcpu->arch.shadow_dbg_reg.dbcr0); }
>>>> 
>>>> All of the code above looks suspiciously similar to
>>>> prime_debug_regs();. Can't we somehow reuse that?
>>> 
>>> I think we can if
>>> - Save thread->debug_regs in local data structure
>> 
>> Yes, it can even be on the stack.
> 
> Thread->denug_regs is not struct , so memcpy() will not work, it is assigning 
> all registers one by one.

We could make it a struct, no? Then it's a matter of a = b; :)


Alex

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-02 Thread Bhushan Bharat-R65777


> -Original Message-
> From: Alexander Graf [mailto:ag...@suse.de]
> Sent: Thursday, May 02, 2013 4:35 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421
> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support
> 
> 
> On 02.05.2013, at 11:46, Bhushan Bharat-R65777 wrote:
> 
> >
> >
> >> -Original Message-
> >> From: Alexander Graf [mailto:ag...@suse.de]
> >> Sent: Friday, April 26, 2013 4:46 PM
> >> To: Bhushan Bharat-R65777
> >> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421;
> >> Bhushan
> >> Bharat-R65777
> >> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub
> >> support
> >>
> >>
> >> On 08.04.2013, at 12:32, Bharat Bhushan wrote:
> >>
> >>> From: Bharat Bhushan 
> >>>
> >>> This patch adds the debug stub support on booke/bookehv.
> >>> Now QEMU debug stub can use hw breakpoint, watchpoint and software
> >>> breakpoint to debug guest.
> >>>
> >>> Debug registers are saved/restored on vcpu_put()/vcpu_get().
> >>> Also the debug registers are saved restored only if guest is using
> >>> debug resources.
> >>>
> >>> Currently we do not support debug resource emulation to guest, so
> >>> always exit to user space irrespective of user space is expecting
> >>> the debug exception or not. This is unexpected event and let us
> >>> leave the action on user space. This is similar to what it was
> >>> before, only thing is that now we have proper exit state available to user
> space.
> >>>
> >>> Signed-off-by: Bharat Bhushan 
> >>> ---
> >>> arch/powerpc/include/asm/kvm_host.h |8 +
> >>> arch/powerpc/include/uapi/asm/kvm.h |   22 +++-
> >>> arch/powerpc/kvm/booke.c|  242 
> >>> -
> --
> >>> arch/powerpc/kvm/booke.h|5 +
> >>> 4 files changed, 255 insertions(+), 22 deletions(-)
> >>>
> >>> diff --git a/arch/powerpc/include/asm/kvm_host.h
> >> b/arch/powerpc/include/asm/kvm_host.h
> >>> index e34f8fe..b9ad20f 100644
> >>> --- a/arch/powerpc/include/asm/kvm_host.h
> >>> +++ b/arch/powerpc/include/asm/kvm_host.h
> >>> @@ -505,7 +505,15 @@ struct kvm_vcpu_arch {
> >>>   u32 mmucfg;
> >>>   u32 epr;
> >>>   u32 crit_save;
> >>> +
> >>> + /* Flag indicating that debug registers are used by guest */
> >>> + bool debug_active;
> >>> + /* for save/restore thread->dbcr0 on vcpu run/heavyweight_exit */
> >>> + u32 saved_dbcr0;
> >>> + /* guest debug registers*/
> >>>   struct kvmppc_booke_debug_reg dbg_reg;
> >>> + /* shadow debug registers */
> >>> + struct kvmppc_booke_debug_reg shadow_dbg_reg;
> >>> #endif
> >>>   gpa_t paddr_accessed;
> >>>   gva_t vaddr_accessed;
> >>> diff --git a/arch/powerpc/include/uapi/asm/kvm.h
> >> b/arch/powerpc/include/uapi/asm/kvm.h
> >>> index c0c38ed..d7ce449 100644
> >>> --- a/arch/powerpc/include/uapi/asm/kvm.h
> >>> +++ b/arch/powerpc/include/uapi/asm/kvm.h
> >>> @@ -25,6 +25,7 @@
> >>> /* Select powerpc specific features in  */ #define
> >>> __KVM_HAVE_SPAPR_TCE #define __KVM_HAVE_PPC_SMT
> >>> +#define __KVM_HAVE_GUEST_DEBUG
> >>>
> >>> struct kvm_regs {
> >>>   __u64 pc;
> >>> @@ -267,7 +268,24 @@ struct kvm_fpu {
> >>>   __u64 fpr[32];
> >>> };
> >>>
> >>> +/*
> >>> + * Defines for h/w breakpoint, watchpoint (read, write or both) and
> >>> + * software breakpoint.
> >>> + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
> >>> + * for KVM_DEBUG_EXIT.
> >>> + */
> >>> +#define KVMPPC_DEBUG_NONE0x0
> >>> +#define KVMPPC_DEBUG_BREAKPOINT  (1UL << 1)
> >>> +#define KVMPPC_DEBUG_WATCH_WRITE (1UL << 2)
> >>> +#define KVMPPC_DEBUG_WATCH_READ  (1UL << 3)
> >>> struct kvm_debug_exit_arch {
> >>> + __u64 address;
> >>> + /*
> >>> +  * exiting to userspace because of h/w breakpoint, watchpoint
> >>> +  * (read, write or both) and software breakpoint.
> &g

Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-02 Thread Alexander Graf

On 02.05.2013, at 11:46, Bhushan Bharat-R65777 wrote:

> 
> 
>> -Original Message-
>> From: Alexander Graf [mailto:ag...@suse.de]
>> Sent: Friday, April 26, 2013 4:46 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support
>> 
>> 
>> On 08.04.2013, at 12:32, Bharat Bhushan wrote:
>> 
>>> From: Bharat Bhushan 
>>> 
>>> This patch adds the debug stub support on booke/bookehv.
>>> Now QEMU debug stub can use hw breakpoint, watchpoint and software
>>> breakpoint to debug guest.
>>> 
>>> Debug registers are saved/restored on vcpu_put()/vcpu_get().
>>> Also the debug registers are saved restored only if guest
>>> is using debug resources.
>>> 
>>> Currently we do not support debug resource emulation to guest,
>>> so always exit to user space irrespective of user space is expecting
>>> the debug exception or not. This is unexpected event and let us
>>> leave the action on user space. This is similar to what it was before,
>>> only thing is that now we have proper exit state available to user space.
>>> 
>>> Signed-off-by: Bharat Bhushan 
>>> ---
>>> arch/powerpc/include/asm/kvm_host.h |8 +
>>> arch/powerpc/include/uapi/asm/kvm.h |   22 +++-
>>> arch/powerpc/kvm/booke.c|  242 
>>> ---
>>> arch/powerpc/kvm/booke.h|5 +
>>> 4 files changed, 255 insertions(+), 22 deletions(-)
>>> 
>>> diff --git a/arch/powerpc/include/asm/kvm_host.h
>> b/arch/powerpc/include/asm/kvm_host.h
>>> index e34f8fe..b9ad20f 100644
>>> --- a/arch/powerpc/include/asm/kvm_host.h
>>> +++ b/arch/powerpc/include/asm/kvm_host.h
>>> @@ -505,7 +505,15 @@ struct kvm_vcpu_arch {
>>> u32 mmucfg;
>>> u32 epr;
>>> u32 crit_save;
>>> +
>>> +   /* Flag indicating that debug registers are used by guest */
>>> +   bool debug_active;
>>> +   /* for save/restore thread->dbcr0 on vcpu run/heavyweight_exit */
>>> +   u32 saved_dbcr0;
>>> +   /* guest debug registers*/
>>> struct kvmppc_booke_debug_reg dbg_reg;
>>> +   /* shadow debug registers */
>>> +   struct kvmppc_booke_debug_reg shadow_dbg_reg;
>>> #endif
>>> gpa_t paddr_accessed;
>>> gva_t vaddr_accessed;
>>> diff --git a/arch/powerpc/include/uapi/asm/kvm.h
>> b/arch/powerpc/include/uapi/asm/kvm.h
>>> index c0c38ed..d7ce449 100644
>>> --- a/arch/powerpc/include/uapi/asm/kvm.h
>>> +++ b/arch/powerpc/include/uapi/asm/kvm.h
>>> @@ -25,6 +25,7 @@
>>> /* Select powerpc specific features in  */
>>> #define __KVM_HAVE_SPAPR_TCE
>>> #define __KVM_HAVE_PPC_SMT
>>> +#define __KVM_HAVE_GUEST_DEBUG
>>> 
>>> struct kvm_regs {
>>> __u64 pc;
>>> @@ -267,7 +268,24 @@ struct kvm_fpu {
>>> __u64 fpr[32];
>>> };
>>> 
>>> +/*
>>> + * Defines for h/w breakpoint, watchpoint (read, write or both) and
>>> + * software breakpoint.
>>> + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
>>> + * for KVM_DEBUG_EXIT.
>>> + */
>>> +#define KVMPPC_DEBUG_NONE  0x0
>>> +#define KVMPPC_DEBUG_BREAKPOINT(1UL << 1)
>>> +#define KVMPPC_DEBUG_WATCH_WRITE   (1UL << 2)
>>> +#define KVMPPC_DEBUG_WATCH_READ(1UL << 3)
>>> struct kvm_debug_exit_arch {
>>> +   __u64 address;
>>> +   /*
>>> +* exiting to userspace because of h/w breakpoint, watchpoint
>>> +* (read, write or both) and software breakpoint.
>>> +*/
>>> +   __u32 status;
>>> +   __u32 reserved;
>>> };
>>> 
>>> /* for KVM_SET_GUEST_DEBUG */
>>> @@ -279,10 +297,6 @@ struct kvm_guest_debug_arch {
>>>  * Type denotes h/w breakpoint, read watchpoint, write
>>>  * watchpoint or watchpoint (both read and write).
>>>  */
>>> -#define KVMPPC_DEBUG_NONE  0x0
>>> -#define KVMPPC_DEBUG_BREAKPOINT(1UL << 1)
>>> -#define KVMPPC_DEBUG_WATCH_WRITE   (1UL << 2)
>>> -#define KVMPPC_DEBUG_WATCH_READ(1UL << 3)
>>> __u32 type;
>>> __u32 reserved;
&

RE: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-05-02 Thread Bhushan Bharat-R65777


> -Original Message-
> From: Alexander Graf [mailto:ag...@suse.de]
> Sent: Friday, April 26, 2013 4:46 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-...@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
> Bharat-R65777
> Subject: Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support
> 
> 
> On 08.04.2013, at 12:32, Bharat Bhushan wrote:
> 
> > From: Bharat Bhushan 
> >
> > This patch adds the debug stub support on booke/bookehv.
> > Now QEMU debug stub can use hw breakpoint, watchpoint and software
> > breakpoint to debug guest.
> >
> > Debug registers are saved/restored on vcpu_put()/vcpu_get().
> > Also the debug registers are saved restored only if guest
> > is using debug resources.
> >
> > Currently we do not support debug resource emulation to guest,
> > so always exit to user space irrespective of user space is expecting
> > the debug exception or not. This is unexpected event and let us
> > leave the action on user space. This is similar to what it was before,
> > only thing is that now we have proper exit state available to user space.
> >
> > Signed-off-by: Bharat Bhushan 
> > ---
> > arch/powerpc/include/asm/kvm_host.h |8 +
> > arch/powerpc/include/uapi/asm/kvm.h |   22 +++-
> > arch/powerpc/kvm/booke.c|  242 
> > ---
> > arch/powerpc/kvm/booke.h|5 +
> > 4 files changed, 255 insertions(+), 22 deletions(-)
> >
> > diff --git a/arch/powerpc/include/asm/kvm_host.h
> b/arch/powerpc/include/asm/kvm_host.h
> > index e34f8fe..b9ad20f 100644
> > --- a/arch/powerpc/include/asm/kvm_host.h
> > +++ b/arch/powerpc/include/asm/kvm_host.h
> > @@ -505,7 +505,15 @@ struct kvm_vcpu_arch {
> > u32 mmucfg;
> > u32 epr;
> > u32 crit_save;
> > +
> > +   /* Flag indicating that debug registers are used by guest */
> > +   bool debug_active;
> > +   /* for save/restore thread->dbcr0 on vcpu run/heavyweight_exit */
> > +   u32 saved_dbcr0;
> > +   /* guest debug registers*/
> > struct kvmppc_booke_debug_reg dbg_reg;
> > +   /* shadow debug registers */
> > +   struct kvmppc_booke_debug_reg shadow_dbg_reg;
> > #endif
> > gpa_t paddr_accessed;
> > gva_t vaddr_accessed;
> > diff --git a/arch/powerpc/include/uapi/asm/kvm.h
> b/arch/powerpc/include/uapi/asm/kvm.h
> > index c0c38ed..d7ce449 100644
> > --- a/arch/powerpc/include/uapi/asm/kvm.h
> > +++ b/arch/powerpc/include/uapi/asm/kvm.h
> > @@ -25,6 +25,7 @@
> > /* Select powerpc specific features in  */
> > #define __KVM_HAVE_SPAPR_TCE
> > #define __KVM_HAVE_PPC_SMT
> > +#define __KVM_HAVE_GUEST_DEBUG
> >
> > struct kvm_regs {
> > __u64 pc;
> > @@ -267,7 +268,24 @@ struct kvm_fpu {
> > __u64 fpr[32];
> > };
> >
> > +/*
> > + * Defines for h/w breakpoint, watchpoint (read, write or both) and
> > + * software breakpoint.
> > + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
> > + * for KVM_DEBUG_EXIT.
> > + */
> > +#define KVMPPC_DEBUG_NONE  0x0
> > +#define KVMPPC_DEBUG_BREAKPOINT(1UL << 1)
> > +#define KVMPPC_DEBUG_WATCH_WRITE   (1UL << 2)
> > +#define KVMPPC_DEBUG_WATCH_READ(1UL << 3)
> > struct kvm_debug_exit_arch {
> > +   __u64 address;
> > +   /*
> > +* exiting to userspace because of h/w breakpoint, watchpoint
> > +* (read, write or both) and software breakpoint.
> > +*/
> > +   __u32 status;
> > +   __u32 reserved;
> > };
> >
> > /* for KVM_SET_GUEST_DEBUG */
> > @@ -279,10 +297,6 @@ struct kvm_guest_debug_arch {
> >  * Type denotes h/w breakpoint, read watchpoint, write
> >  * watchpoint or watchpoint (both read and write).
> >  */
> > -#define KVMPPC_DEBUG_NONE  0x0
> > -#define KVMPPC_DEBUG_BREAKPOINT(1UL << 1)
> > -#define KVMPPC_DEBUG_WATCH_WRITE   (1UL << 2)
> > -#define KVMPPC_DEBUG_WATCH_READ(1UL << 3)
> > __u32 type;
> > __u32 reserved;
> > } bp[16];
> > diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> > index 97ae158..0e93416 100644
> > --- a/arch/powerpc/kvm/booke.c
> > +++ b/arch/powerpc/kvm/booke.c
> > @@ -133,6 +133,29 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
> > #endif
> > }
> >
> > +static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vc

Re: [PATCH 7/7 v3] KVM: PPC: Add userspace debug stub support

2013-04-26 Thread Alexander Graf

On 08.04.2013, at 12:32, Bharat Bhushan wrote:

> From: Bharat Bhushan 
> 
> This patch adds the debug stub support on booke/bookehv.
> Now QEMU debug stub can use hw breakpoint, watchpoint and software
> breakpoint to debug guest.
> 
> Debug registers are saved/restored on vcpu_put()/vcpu_get().
> Also the debug registers are saved restored only if guest
> is using debug resources.
> 
> Currently we do not support debug resource emulation to guest,
> so always exit to user space irrespective of user space is expecting
> the debug exception or not. This is unexpected event and let us
> leave the action on user space. This is similar to what it was before,
> only thing is that now we have proper exit state available to user space.
> 
> Signed-off-by: Bharat Bhushan 
> ---
> arch/powerpc/include/asm/kvm_host.h |8 +
> arch/powerpc/include/uapi/asm/kvm.h |   22 +++-
> arch/powerpc/kvm/booke.c|  242 ---
> arch/powerpc/kvm/booke.h|5 +
> 4 files changed, 255 insertions(+), 22 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/kvm_host.h 
> b/arch/powerpc/include/asm/kvm_host.h
> index e34f8fe..b9ad20f 100644
> --- a/arch/powerpc/include/asm/kvm_host.h
> +++ b/arch/powerpc/include/asm/kvm_host.h
> @@ -505,7 +505,15 @@ struct kvm_vcpu_arch {
>   u32 mmucfg;
>   u32 epr;
>   u32 crit_save;
> +
> + /* Flag indicating that debug registers are used by guest */
> + bool debug_active;
> + /* for save/restore thread->dbcr0 on vcpu run/heavyweight_exit */
> + u32 saved_dbcr0;
> + /* guest debug registers*/
>   struct kvmppc_booke_debug_reg dbg_reg;
> + /* shadow debug registers */
> + struct kvmppc_booke_debug_reg shadow_dbg_reg;
> #endif
>   gpa_t paddr_accessed;
>   gva_t vaddr_accessed;
> diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
> b/arch/powerpc/include/uapi/asm/kvm.h
> index c0c38ed..d7ce449 100644
> --- a/arch/powerpc/include/uapi/asm/kvm.h
> +++ b/arch/powerpc/include/uapi/asm/kvm.h
> @@ -25,6 +25,7 @@
> /* Select powerpc specific features in  */
> #define __KVM_HAVE_SPAPR_TCE
> #define __KVM_HAVE_PPC_SMT
> +#define __KVM_HAVE_GUEST_DEBUG
> 
> struct kvm_regs {
>   __u64 pc;
> @@ -267,7 +268,24 @@ struct kvm_fpu {
>   __u64 fpr[32];
> };
> 
> +/*
> + * Defines for h/w breakpoint, watchpoint (read, write or both) and
> + * software breakpoint.
> + * These are used as "type" in KVM_SET_GUEST_DEBUG ioctl and "status"
> + * for KVM_DEBUG_EXIT.
> + */
> +#define KVMPPC_DEBUG_NONE0x0
> +#define KVMPPC_DEBUG_BREAKPOINT  (1UL << 1)
> +#define KVMPPC_DEBUG_WATCH_WRITE (1UL << 2)
> +#define KVMPPC_DEBUG_WATCH_READ  (1UL << 3)
> struct kvm_debug_exit_arch {
> + __u64 address;
> + /*
> +  * exiting to userspace because of h/w breakpoint, watchpoint
> +  * (read, write or both) and software breakpoint.
> +  */
> + __u32 status;
> + __u32 reserved;
> };
> 
> /* for KVM_SET_GUEST_DEBUG */
> @@ -279,10 +297,6 @@ struct kvm_guest_debug_arch {
>* Type denotes h/w breakpoint, read watchpoint, write
>* watchpoint or watchpoint (both read and write).
>*/
> -#define KVMPPC_DEBUG_NONE0x0
> -#define KVMPPC_DEBUG_BREAKPOINT  (1UL << 1)
> -#define KVMPPC_DEBUG_WATCH_WRITE (1UL << 2)
> -#define KVMPPC_DEBUG_WATCH_READ  (1UL << 3)
>   __u32 type;
>   __u32 reserved;
>   } bp[16];
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index 97ae158..0e93416 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c
> @@ -133,6 +133,29 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
> #endif
> }
> 
> +static void kvmppc_vcpu_sync_debug(struct kvm_vcpu *vcpu)
> +{
> + /* Synchronize guest's desire to get debug interrupts into shadow MSR */
> +#ifndef CONFIG_KVM_BOOKE_HV
> + 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;
> + vcpu->arch.shared->msr &= ~MSR_DE;
> +#endif
> + }
> +}
> +
> /*
>  * Helper function for "full" MSR writes.  No need to call this if only
>  * EE/CE/ME/DE/RI are changing.
> @@ -150,6 +173,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,
> @@ -646,6 +670,46 @@ in