Re: [PATCH 0/8] KVM: BOOKE/BOOKEHV : Added debug stub support

2013-01-25 Thread Alexander Graf

On 16.01.2013, at 09:20, Bharat Bhushan wrote:

> This patchset adds the QEMU debug stub support for powerpc (booke/bookehv).
> [1/8] KVM: PPC: booke: use vcpu reference from thread_struct
>   - This is a cleanup patch to use vcpu reference from thread struct
> [2/8] KVM: PPC: booke: Allow multiple exception types
> [3/8] KVM: PPC: booke: Added debug handler
>   - These two patches install the KVM debug handler.
> [4/8] Added ONE_REG interface for debug instruction
>   - Add the ioctl interface to get the debug instruction for
> setting software breakpoint from QEMU debug stub.
> [5/8] KVM: PPC: debug stub interface parameter defined
> [6/8] booke: Added DBCR4 SPR number
> [7/8] KVM: booke/bookehv: Add debug stub support
>   - Add the debug stub interface on booke/bookehv
> [8/8] KVM:PPC:booke: Allow debug interrupt injection to guest
>   -- with this qemu can inject debug interrupt to guest

Thanks, applied 1/8, 2/8, 6/8.


Alex

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


Re: [PATCH 8/8] KVM:PPC:booke: Allow debug interrupt injection to guest

2013-01-25 Thread Alexander Graf

On 16.01.2013, at 09:24, Bharat Bhushan wrote:

> Allow userspace to inject debug interrupt to guest. QEMU can

s/QEMU/user space.

> inject the debug interrupt to guest if it is not able to handle
> the debug interrupt.
> 
> Signed-off-by: Bharat Bhushan 
> ---
> arch/powerpc/kvm/booke.c  |   32 +++-
> arch/powerpc/kvm/e500mc.c |   10 +-
> 2 files changed, 40 insertions(+), 2 deletions(-)
> 
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index faa0a0b..547797f 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c
> @@ -133,6 +133,13 @@ static void kvmppc_vcpu_sync_fpu(struct kvm_vcpu *vcpu)
> #endif
> }
> 
> +#ifdef CONFIG_KVM_BOOKE_HV
> +static int kvmppc_core_pending_debug(struct kvm_vcpu *vcpu)
> +{
> + return test_bit(BOOKE_IRQPRIO_DEBUG, &vcpu->arch.pending_exceptions);
> +}
> +#endif
> +
> /*
>  * Helper function for "full" MSR writes.  No need to call this if only
>  * EE/CE/ME/DE/RI are changing.
> @@ -144,7 +151,11 @@ void kvmppc_set_msr(struct kvm_vcpu *vcpu, u32 new_msr)
> #ifdef CONFIG_KVM_BOOKE_HV
>   new_msr |= MSR_GS;
> 
> - if (vcpu->guest_debug)
> + /*
> +  * Set MSR_DE if the hardware debug resources are owned by user-space
> +  * and there is no debug interrupt pending for guest to handle.

Why? And why is this whole thing only executed on HV?


Alex

> +  */
> + if (vcpu->guest_debug && !kvmppc_core_pending_debug(vcpu))
>   new_msr |= MSR_DE;
> #endif
> 
> @@ -234,6 +245,16 @@ static void kvmppc_core_dequeue_watchdog(struct kvm_vcpu 
> *vcpu)
>   clear_bit(BOOKE_IRQPRIO_WATCHDOG, &vcpu->arch.pending_exceptions);
> }
> 
> +static void kvmppc_core_queue_debug(struct kvm_vcpu *vcpu)
> +{
> + kvmppc_booke_queue_irqprio(vcpu, BOOKE_IRQPRIO_DEBUG);
> +}
> +
> +static void kvmppc_core_dequeue_debug(struct kvm_vcpu *vcpu)
> +{
> + clear_bit(BOOKE_IRQPRIO_DEBUG, &vcpu->arch.pending_exceptions);
> +}
> +
> static void set_guest_srr(struct kvm_vcpu *vcpu, unsigned long srr0, u32 srr1)
> {
> #ifdef CONFIG_KVM_BOOKE_HV
> @@ -1278,6 +1299,7 @@ static void get_sregs_base(struct kvm_vcpu *vcpu,
>   sregs->u.e.dec = kvmppc_get_dec(vcpu, tb);
>   sregs->u.e.tb = tb;
>   sregs->u.e.vrsave = vcpu->arch.vrsave;
> + sregs->u.e.dbsr = vcpu->arch.dbsr;
> }
> 
> static int set_sregs_base(struct kvm_vcpu *vcpu,
> @@ -1310,6 +1332,14 @@ static int set_sregs_base(struct kvm_vcpu *vcpu,
>   update_timer_ints(vcpu);
>   }
> 
> + if (sregs->u.e.update_special & KVM_SREGS_E_UPDATE_DBSR) {
> + vcpu->arch.dbsr = sregs->u.e.dbsr;
> + if (vcpu->arch.dbsr)
> + kvmppc_core_queue_debug(vcpu);
> + else
> + kvmppc_core_dequeue_debug(vcpu);
> + }
> +
>   return 0;
> }
> 
> diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
> index 81abe92..7d90622 100644
> --- a/arch/powerpc/kvm/e500mc.c
> +++ b/arch/powerpc/kvm/e500mc.c
> @@ -208,7 +208,7 @@ void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct 
> kvm_sregs *sregs)
>   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> 
>   sregs->u.e.features |= KVM_SREGS_E_ARCH206_MMU | KVM_SREGS_E_PM |
> -KVM_SREGS_E_PC;
> +KVM_SREGS_E_PC | KVM_SREGS_E_ED;
>   sregs->u.e.impl_id = KVM_SREGS_E_IMPL_FSL;
> 
>   sregs->u.e.impl.fsl.features = 0;
> @@ -216,6 +216,9 @@ void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct 
> kvm_sregs *sregs)
>   sregs->u.e.impl.fsl.hid0 = vcpu_e500->hid0;
>   sregs->u.e.impl.fsl.mcar = vcpu_e500->mcar;
> 
> + sregs->u.e.dsrr0 = vcpu->arch.dsrr0;
> + sregs->u.e.dsrr1 = vcpu->arch.dsrr1;
> +
>   kvmppc_get_sregs_e500_tlb(vcpu, sregs);
> 
>   sregs->u.e.ivor_high[3] =
> @@ -256,6 +259,11 @@ int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct 
> kvm_sregs *sregs)
>   sregs->u.e.ivor_high[5];
>   }
> 
> + if (sregs->u.e.features & KVM_SREGS_E_ED) {
> + vcpu->arch.dsrr0 = sregs->u.e.dsrr0;
> + vcpu->arch.dsrr1 = sregs->u.e.dsrr1;
> + }
> +
>   return kvmppc_set_sregs_ivor(vcpu, sregs);
> }
> 
> -- 
> 1.7.0.4
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" 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-ppc" 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/8] KVM: PPC: booke/bookehv: Add debug stub support

2013-01-25 Thread Alexander Graf

On 16.01.2013, at 09:24, Bharat Bhushan wrote:

> 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.
> 
> Signed-off-by: Bharat Bhushan 
> ---
> arch/powerpc/include/asm/kvm_host.h   |5 +
> arch/powerpc/include/asm/kvm_ppc.h|2 +
> arch/powerpc/include/uapi/asm/kvm.h   |   22 -
> arch/powerpc/kernel/asm-offsets.c |   26 ++
> arch/powerpc/kvm/booke.c  |  124 +
> arch/powerpc/kvm/booke_interrupts.S   |  114 ++
> arch/powerpc/kvm/bookehv_interrupts.S |  145 -
> arch/powerpc/kvm/e500_emulate.c   |6 ++
> arch/powerpc/kvm/e500mc.c |3 +-
> 9 files changed, 422 insertions(+), 25 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/kvm_host.h 
> b/arch/powerpc/include/asm/kvm_host.h
> index f4ba881..a9feeb0 100644
> --- a/arch/powerpc/include/asm/kvm_host.h
> +++ b/arch/powerpc/include/asm/kvm_host.h
> @@ -504,7 +504,12 @@ struct kvm_vcpu_arch {
>   u32 mmucfg;
>   u32 epr;
>   u32 crit_save;
> + /* guest debug registers*/
>   struct kvmppc_booke_debug_reg dbg_reg;
> + /* shadow debug registers */
> + struct kvmppc_booke_debug_reg shadow_dbg_reg;
> + /* host debug registers*/
> + struct kvmppc_booke_debug_reg host_dbg_reg;
> #endif
>   gpa_t paddr_accessed;
>   gva_t vaddr_accessed;
> diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
> b/arch/powerpc/include/asm/kvm_ppc.h
> index b3c481e..e4b3398 100644
> --- a/arch/powerpc/include/asm/kvm_ppc.h
> +++ b/arch/powerpc/include/asm/kvm_ppc.h
> @@ -45,6 +45,8 @@ enum emulation_result {
>   EMULATE_FAIL, /* can't emulate this instruction */
>   EMULATE_AGAIN,/* something went wrong. go again */
>   EMULATE_DO_PAPR,  /* kvm_run filled with PAPR request */
> + EMULATE_DEBUG_INST,   /* debug instruction for software
> +  breakpoint, exit to userspace */

Does this do something different from DO_PAPR? Maybe it makes sense to have an 
exit code EMULATE_EXIT_USER?

> };
> 
> extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu);
> diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
> b/arch/powerpc/include/uapi/asm/kvm.h
> index e8842ed..a81ab29 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_NOTYPE  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/kernel/asm-offsets.c 
> b/arch/powerpc/kernel/asm-offsets.c
> index 02048f3..22deda7 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -563,6 +563,32 @@ int main(void)
>   DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
>   DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
>   DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save));
> + DEFINE(VCPU_DBSR, offsetof(struct kvm_vcpu, arch.dbsr));
> + DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg));
> + DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg));
> + DEFINE(KVMPPC_DBG_DBCR0, offsetof(struct kvmppc_booke_debug_reg,
> +   dbcr0));
> + DEFINE(KVMPPC_DBG_DBCR1, offsetof(struct kvmppc_booke_debug_reg,
> +   dbcr1));
> + DEFINE(KVMPPC_DBG_DBCR2, offsetof(struct kvmppc_booke_debug_reg,
> +  

Re: [PATCH 5/8] KVM: PPC: debug stub interface parameter defined

2013-01-25 Thread Alexander Graf

On 17.01.2013, at 12:11, Bhushan Bharat-R65777 wrote:

> 
> 
>> -Original Message-
>> From: Paul Mackerras [mailto:pau...@samba.org]
>> Sent: Thursday, January 17, 2013 12:53 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; k...@vger.kernel.org; ag...@suse.de; Bhushan 
>> Bharat-
>> R65777
>> Subject: Re: [PATCH 5/8] KVM: PPC: debug stub interface parameter defined
>> 
>> On Wed, Jan 16, 2013 at 01:54:42PM +0530, Bharat Bhushan wrote:
>>> This patch defines the interface parameter for KVM_SET_GUEST_DEBUG
>>> ioctl support. Follow up patches will use this for setting up hardware
>>> breakpoints, watchpoints and software breakpoints.
>> 
>> [snip]
>> 
>>> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index
>>> 453a10f..7d5a51c 100644
>>> --- a/arch/powerpc/kvm/booke.c
>>> +++ b/arch/powerpc/kvm/booke.c
>>> @@ -1483,6 +1483,12 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
>> struct kvm_one_reg *reg)
>>> return r;
>>> }
>>> 
>>> +int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
>>> +struct kvm_guest_debug *dbg)
>>> +{
>>> +   return -EINVAL;
>>> +}
>>> +
>>> int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu
>>> *fpu)  {
>>> return -ENOTSUPP;
>>> diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
>>> index 934413c..4c94ca9 100644
>>> --- a/arch/powerpc/kvm/powerpc.c
>>> +++ b/arch/powerpc/kvm/powerpc.c
>>> @@ -532,12 +532,6 @@ void kvm_arch_vcpu_put(struct kvm_vcpu *vcpu)
>>> #endif  }
>>> 
>>> -int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
>>> -struct kvm_guest_debug *dbg)
>>> -{
>>> -   return -EINVAL;
>>> -}
>>> -
>> 
>> This will break the build for non-book E machines, since
>> kvm_arch_vcpu_ioctl_set_guest_debug() is referenced from generic code.
>> You need to add it to arch/powerpc/kvm/book3s.c as well.
> 
> right,  I will correct this.

Would the implementation actually be different on booke vs book3s? My feeling 
is that powerpc.c is actually the right place for this.


Alex

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


Re: [PATCH 4/8] Added ONE_REG interface for debug instruction

2013-01-25 Thread Alexander Graf

On 16.01.2013, at 09:24, Bharat Bhushan wrote:

> This patch adds the one_reg interface to get the special instruction
> to be used for setting software breakpoint from userspace.
> 
> Signed-off-by: Bharat Bhushan 
> ---
> Documentation/virtual/kvm/api.txt   |1 +
> arch/powerpc/include/asm/kvm_ppc.h  |1 +
> arch/powerpc/include/uapi/asm/kvm.h |3 +++
> arch/powerpc/kvm/44x.c  |5 +
> arch/powerpc/kvm/booke.c|   10 ++
> arch/powerpc/kvm/e500.c |5 +
> arch/powerpc/kvm/e500.h |9 +
> arch/powerpc/kvm/e500mc.c   |5 +
> 8 files changed, 39 insertions(+), 0 deletions(-)
> 
> diff --git a/Documentation/virtual/kvm/api.txt 
> b/Documentation/virtual/kvm/api.txt
> index 09905cb..7e8be9e 100644
> --- a/Documentation/virtual/kvm/api.txt
> +++ b/Documentation/virtual/kvm/api.txt
> @@ -1775,6 +1775,7 @@ registers, find a list below:
>   PPC   | KVM_REG_PPC_VPA_DTL   | 128
>   PPC   | KVM_REG_PPC_EPCR| 32
>   PPC   | KVM_REG_PPC_EPR | 32
> +  PPC   | KVM_REG_PPC_DEBUG_INST| 32
> 
> 4.69 KVM_GET_ONE_REG
> 
> diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
> b/arch/powerpc/include/asm/kvm_ppc.h
> index 44a657a..b3c481e 100644
> --- a/arch/powerpc/include/asm/kvm_ppc.h
> +++ b/arch/powerpc/include/asm/kvm_ppc.h
> @@ -235,6 +235,7 @@ union kvmppc_one_reg {
> 
> void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
> int kvmppc_core_set_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
> +u32 kvmppc_core_debug_inst_op(void);
> 
> void kvmppc_get_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
> int kvmppc_set_sregs_ivor(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs);
> diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
> b/arch/powerpc/include/uapi/asm/kvm.h
> index 16064d0..e81ae5b 100644
> --- a/arch/powerpc/include/uapi/asm/kvm.h
> +++ b/arch/powerpc/include/uapi/asm/kvm.h
> @@ -417,4 +417,7 @@ struct kvm_get_htab_header {
> #define KVM_REG_PPC_EPCR  (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x85)
> #define KVM_REG_PPC_EPR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x86)
> 
> +/* Debugging: Special instruction for software breakpoint */
> +#define KVM_REG_PPC_DEBUG_INST (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x87)
> +
> #endif /* __LINUX_KVM_POWERPC_H */
> diff --git a/arch/powerpc/kvm/44x.c b/arch/powerpc/kvm/44x.c
> index 3d7fd21..41501be 100644
> --- a/arch/powerpc/kvm/44x.c
> +++ b/arch/powerpc/kvm/44x.c
> @@ -114,6 +114,11 @@ int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
>   return 0;
> }
> 
> +u32 kvmppc_core_debug_inst_op(void)
> +{
> + return -1;
> +}
> +
> void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
> {
>   kvmppc_get_sregs_ivor(vcpu, sregs);
> diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
> index d2f502d..453a10f 100644
> --- a/arch/powerpc/kvm/booke.c
> +++ b/arch/powerpc/kvm/booke.c

Please provide the DEBUG_INST on a more global level - across all ppc subarchs.

> @@ -1424,6 +1424,12 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
> struct kvm_one_reg *reg)
>   r = put_user(vcpu->arch.epcr, (u32 __user *)(long)reg->addr);
>   break;
> #endif
> + case KVM_REG_PPC_DEBUG_INST: {
> + u32 opcode = kvmppc_core_debug_inst_op();
> + r = copy_to_user((u32 __user *)(long)reg->addr,
> +  &opcode, sizeof(u32));
> + break;
> + }
>   default:
>   break;
>   }
> @@ -1467,6 +1473,10 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, 
> struct kvm_one_reg *reg)
>   break;
>   }
> #endif
> + case KVM_REG_PPC_DEBUG_INST:
> + /* This is read only, so write to this is nop*/
> + r = 0;
> + break;

Just don't support set_one_reg on this reg.

>   default:
>   break;
>   }
> diff --git a/arch/powerpc/kvm/e500.c b/arch/powerpc/kvm/e500.c
> index 6dd4de7..d8a5e8e 100644
> --- a/arch/powerpc/kvm/e500.c
> +++ b/arch/powerpc/kvm/e500.c
> @@ -367,6 +367,11 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
>   return 0;
> }
> 
> +u32 kvmppc_core_debug_inst_op(void)
> +{
> + return KVMPPC_INST_GUEST_GDB;
> +}
> +
> void kvmppc_core_get_sregs(struct kvm_vcpu *vcpu, struct kvm_sregs *sregs)
> {
>   struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> diff --git a/arch/powerpc/kvm/e500.h b/arch/powerpc/kvm/e500.h
> index c70d37e..17942d2 100644
> --- a/arch/powerpc/kvm/e500.h
> +++ b/arch/powerpc/kvm/e500.h
> @@ -302,4 +302,13 @@ static inline unsigned int get_tlbmiss_tid(struct 
> kvm_vcpu *vcpu)
> #define get_tlb_sts(gtlbe)  (MAS1_TS)
> #endif /* !BOOKE_HV */
> 
> +/* When setting software breakpoint, Change the software breakpoint
> + * instruction to special trap/invalid instruction and set
> + * KVM_GUESTDBG_USE_SW_BP flag in kvm_guest_debug->control. KVM does
> + * keep track of softwa

Re: [PATCH 3/8] KVM: PPC: booke: Added debug handler

2013-01-25 Thread Alexander Graf

On 16.01.2013, at 09:24, Bharat Bhushan wrote:

> From: Bharat Bhushan 
> 
> Installed debug handler will be used for guest debug support
> and debug facility emulation features (patches for these
> features will follow this patch).
> 
> Signed-off-by: Liu Yu 
> [bharat.bhus...@freescale.com: Substantial changes]
> Signed-off-by: Bharat Bhushan 
> ---
> arch/powerpc/include/asm/kvm_host.h |1 +
> arch/powerpc/kernel/asm-offsets.c   |1 +
> arch/powerpc/kvm/booke_interrupts.S |   49 ++-
> 3 files changed, 44 insertions(+), 7 deletions(-)
> 
> diff --git a/arch/powerpc/include/asm/kvm_host.h 
> b/arch/powerpc/include/asm/kvm_host.h
> index 8a72d59..f4ba881 100644
> --- a/arch/powerpc/include/asm/kvm_host.h
> +++ b/arch/powerpc/include/asm/kvm_host.h
> @@ -503,6 +503,7 @@ struct kvm_vcpu_arch {
>   u32 tlbcfg[4];
>   u32 mmucfg;
>   u32 epr;
> + u32 crit_save;
>   struct kvmppc_booke_debug_reg dbg_reg;
> #endif
>   gpa_t paddr_accessed;
> diff --git a/arch/powerpc/kernel/asm-offsets.c 
> b/arch/powerpc/kernel/asm-offsets.c
> index 46f6afd..02048f3 100644
> --- a/arch/powerpc/kernel/asm-offsets.c
> +++ b/arch/powerpc/kernel/asm-offsets.c
> @@ -562,6 +562,7 @@ int main(void)
>   DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
>   DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
>   DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
> + DEFINE(VCPU_CRIT_SAVE, offsetof(struct kvm_vcpu, arch.crit_save));
> #endif /* CONFIG_PPC_BOOK3S */
> #endif /* CONFIG_KVM */
> 
> diff --git a/arch/powerpc/kvm/booke_interrupts.S 
> b/arch/powerpc/kvm/booke_interrupts.S
> index eae8483..dd9c5d4 100644
> --- a/arch/powerpc/kvm/booke_interrupts.S
> +++ b/arch/powerpc/kvm/booke_interrupts.S
> @@ -52,12 +52,7 @@
>(1<(1< 
> -.macro KVM_HANDLER ivor_nr scratch srr0
> -_GLOBAL(kvmppc_handler_\ivor_nr)
> - /* Get pointer to vcpu and record exit number. */
> - mtspr   \scratch , r4
> - mfspr   r4, SPRN_SPRG_THREAD
> - lwz r4, THREAD_KVM_VCPU(r4)
> +.macro __KVM_HANDLER ivor_nr scratch srr0
>   stw r3, VCPU_GPR(R3)(r4)
>   stw r5, VCPU_GPR(R5)(r4)
>   stw r6, VCPU_GPR(R6)(r4)
> @@ -74,6 +69,46 @@ _GLOBAL(kvmppc_handler_\ivor_nr)
>   bctr
> .endm
> 
> +.macro KVM_HANDLER ivor_nr scratch srr0
> +_GLOBAL(kvmppc_handler_\ivor_nr)
> + /* Get pointer to vcpu and record exit number. */
> + mtspr   \scratch , r4
> + mfspr   r4, SPRN_SPRG_THREAD
> + lwz r4, THREAD_KVM_VCPU(r4)
> + __KVM_HANDLER \ivor_nr \scratch \srr0
> +.endm
> +
> +.macro KVM_DBG_HANDLER ivor_nr scratch srr0
> +_GLOBAL(kvmppc_handler_\ivor_nr)
> + mtspr   \scratch, r4
> + mfspr   r4, SPRN_SPRG_THREAD
> + lwz r4, THREAD_KVM_VCPU(r4)
> + stw r3, VCPU_CRIT_SAVE(r4)
> + mfcrr3
> + mfspr   r4, SPRN_CSRR1
> + andi.   r4, r4, MSR_PR
> + bne 1f


> + /* debug interrupt happened in enter/exit path */
> + mfspr   r4, SPRN_CSRR1
> + rlwinm  r4, r4, 0, ~MSR_DE
> + mtspr   SPRN_CSRR1, r4
> + lis r4, 0x
> + ori r4, r4, 0x
> + mtspr   SPRN_DBSR, r4
> + mfspr   r4, SPRN_SPRG_THREAD
> + lwz r4, THREAD_KVM_VCPU(r4)
> + mtcrr3
> + lwz r3, VCPU_CRIT_SAVE(r4)
> + mfspr   r4, \scratch
> + rfci

What is this part doing? Try to ignore the debug exit? Why would we have MSR_DE 
enabled in the first place when we can't handle it?

> +1:   /* debug interrupt happened in guest */
> + mtcrr3
> + mfspr   r4, SPRN_SPRG_THREAD
> + lwz r4, THREAD_KVM_VCPU(r4)
> + lwz r3, VCPU_CRIT_SAVE(r4)
> + __KVM_HANDLER \ivor_nr \scratch \srr0

I don't think you need the __KVM_HANDLER split. This should be quite easily 
refactorable into a simple DBG prolog.


Alex

> +.endm
> +
> .macro KVM_HANDLER_ADDR ivor_nr
>   .long   kvmppc_handler_\ivor_nr
> .endm
> @@ -98,7 +133,7 @@ KVM_HANDLER BOOKE_INTERRUPT_FIT SPRN_SPRG_RSCRATCH0 
> SPRN_SRR0
> KVM_HANDLER BOOKE_INTERRUPT_WATCHDOG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0
> KVM_HANDLER BOOKE_INTERRUPT_DTLB_MISS SPRN_SPRG_RSCRATCH0 SPRN_SRR0
> KVM_HANDLER BOOKE_INTERRUPT_ITLB_MISS SPRN_SPRG_RSCRATCH0 SPRN_SRR0
> -KVM_HANDLER BOOKE_INTERRUPT_DEBUG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0
> +KVM_DBG_HANDLER BOOKE_INTERRUPT_DEBUG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0
> KVM_HANDLER BOOKE_INTERRUPT_SPE_UNAVAIL SPRN_SPRG_RSCRATCH0 SPRN_SRR0
> KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_DATA SPRN_SPRG_RSCRATCH0 SPRN_SRR0
> KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_ROUND SPRN_SPRG_RSCRATCH0 SPRN_SRR0
> -- 
> 1.7.0.4
> 
> 

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