Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER

2013-03-07 Thread Alexander Graf

On 28.02.2013, at 17:53, Scott Wood wrote:

 On 02/28/2013 10:51:10 AM, Alexander Graf wrote:
 On 28.02.2013, at 17:31, Scott Wood wrote:
  On 02/27/2013 10:13:15 PM, Bharat Bhushan wrote:
  Instruction emulation return EMULATE_DO_PAPR when it requires
  exit to userspace on book3s. Similar return is required
  for booke. EMULATE_DO_PAPR reads out to be confusing so it is
  renamed to EMULATE_EXIT_USER.
  Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
  ---
  arch/powerpc/include/asm/kvm_ppc.h |2 +-
  arch/powerpc/kvm/book3s_emulate.c  |2 +-
  arch/powerpc/kvm/book3s_pr.c   |2 +-
  3 files changed, 3 insertions(+), 3 deletions(-)
  diff --git a/arch/powerpc/include/asm/kvm_ppc.h 
  b/arch/powerpc/include/asm/kvm_ppc.h
  index 44a657a..8b81468 100644
  --- a/arch/powerpc/include/asm/kvm_ppc.h
  +++ b/arch/powerpc/include/asm/kvm_ppc.h
  @@ -44,7 +44,7 @@ enum emulation_result {
EMULATE_DO_DCR,   /* kvm_run filled with DCR request */
EMULATE_FAIL, /* can't emulate this instruction */
EMULATE_AGAIN,/* something went wrong. go again */
  - EMULATE_DO_PAPR,  /* kvm_run filled with PAPR request */
  + EMULATE_EXIT_USER,/* emulation requires exit to user-space */
  };
  extern int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu 
  *vcpu);
  diff --git a/arch/powerpc/kvm/book3s_emulate.c 
  b/arch/powerpc/kvm/book3s_emulate.c
  index 836c569..cdd19d6 100644
  --- a/arch/powerpc/kvm/book3s_emulate.c
  +++ b/arch/powerpc/kvm/book3s_emulate.c
  @@ -194,7 +194,7 @@ int kvmppc_core_emulate_op(struct kvm_run *run, 
  struct kvm_vcpu *vcpu,
run-papr_hcall.args[i] = gpr;
}
  - emulated = EMULATE_DO_PAPR;
  + emulated = EMULATE_EXIT_USER;
break;
}
  #endif
  diff --git a/arch/powerpc/kvm/book3s_pr.c b/arch/powerpc/kvm/book3s_pr.c
  index 73ed11c..8df2d2d 100644
  --- a/arch/powerpc/kvm/book3s_pr.c
  +++ b/arch/powerpc/kvm/book3s_pr.c
  @@ -760,7 +760,7 @@ program_interrupt:
run-exit_reason = KVM_EXIT_MMIO;
r = RESUME_HOST_NV;
break;
  - case EMULATE_DO_PAPR:
  + case EMULATE_EXIT_USER:
run-exit_reason = KVM_EXIT_PAPR_HCALL;
vcpu-arch.hcall_needed = 1;
r = RESUME_HOST_NV;
 
  I don't think it makes sense to genericize this.
 It makes sense if the run-exit_reason = ... and hcall_needed = ... lines 
 get pulled into the emulator.
 
 That would be fine.

Bharat, did I miss a new patch version with that mess up there fixed?


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 2/7] Added ONE_REG interface for debug instruction

2013-03-07 Thread Alexander Graf

On 28.02.2013, at 05:13, 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 bharat.bhus...@freescale.com
 ---
 Documentation/virtual/kvm/api.txt |1 +
 arch/powerpc/include/asm/kvm_book3s.h |1 +
 arch/powerpc/include/asm/kvm_booke.h  |2 ++
 arch/powerpc/include/uapi/asm/kvm.h   |4 
 arch/powerpc/kvm/book3s.c |6 ++
 arch/powerpc/kvm/booke.c  |6 ++
 6 files changed, 20 insertions(+), 0 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index cce500a..dbfcc04 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -1766,6 +1766,7 @@ registers, find a list below:
   PPC   | KVM_REG_PPC_TSR | 32
   PPC   | KVM_REG_PPC_OR_TSR  | 32
   PPC   | KVM_REG_PPC_CLEAR_TSR   | 32
 +  PPC   | KVM_REG_PPC_DEBUG_INST| 32
 
 4.69 KVM_GET_ONE_REG
 
 diff --git a/arch/powerpc/include/asm/kvm_book3s.h 
 b/arch/powerpc/include/asm/kvm_book3s.h
 index 5a56e1c..36164cc 100644
 --- a/arch/powerpc/include/asm/kvm_book3s.h
 +++ b/arch/powerpc/include/asm/kvm_book3s.h
 @@ -458,6 +458,7 @@ static inline bool kvmppc_critical_section(struct 
 kvm_vcpu *vcpu)
 #define OSI_SC_MAGIC_R4   0x77810F9B
 
 #define INS_DCBZ  0x7c0007ec
 +#define INS_TW   0x7c08

This one should be trap, so TO needs to be 31. The instruction as it's here 
is a nop if I read the spec correctly.

Alex

 
 /* LPIDs we support with this build -- runtime limit may be lower */
 #define KVMPPC_NR_LPIDS   (LPID_RSVD + 1)
 diff --git a/arch/powerpc/include/asm/kvm_booke.h 
 b/arch/powerpc/include/asm/kvm_booke.h
 index b7cd335..d3c1eb3 100644
 --- a/arch/powerpc/include/asm/kvm_booke.h
 +++ b/arch/powerpc/include/asm/kvm_booke.h
 @@ -26,6 +26,8 @@
 /* LPIDs we support with this build -- runtime limit may be lower */
 #define KVMPPC_NR_LPIDS64
 
 +#define KVMPPC_INST_EHPRIV   0x7c00021c
 +
 static inline void kvmppc_set_gpr(struct kvm_vcpu *vcpu, int num, ulong val)
 {
   vcpu-arch.gpr[num] = val;
 diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
 b/arch/powerpc/include/uapi/asm/kvm.h
 index ef072b1..c2ff99c 100644
 --- a/arch/powerpc/include/uapi/asm/kvm.h
 +++ b/arch/powerpc/include/uapi/asm/kvm.h
 @@ -422,4 +422,8 @@ struct kvm_get_htab_header {
 #define KVM_REG_PPC_CLEAR_TSR (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x88)
 #define KVM_REG_PPC_TCR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x89)
 #define KVM_REG_PPC_TSR   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x8a)
 +
 +/* Debugging: Special instruction for software breakpoint */
 +#define KVM_REG_PPC_DEBUG_INST   (KVM_REG_PPC | KVM_REG_SIZE_U32 | 0x8b)
 +
 #endif /* __LINUX_KVM_POWERPC_H */
 diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
 index a4b6452..975a401 100644
 --- a/arch/powerpc/kvm/book3s.c
 +++ b/arch/powerpc/kvm/book3s.c
 @@ -530,6 +530,12 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
 struct kvm_one_reg *reg)
   val = get_reg_val(reg-id, vcpu-arch.vscr.u[3]);
   break;
 #endif /* CONFIG_ALTIVEC */
 + case KVM_REG_PPC_DEBUG_INST: {
 + u32 opcode = INS_TW;
 + r = copy_to_user((u32 __user *)(long)reg-addr,
 +  opcode, sizeof(u32));
 + break;
 + }
   default:
   r = -EINVAL;
   break;
 diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
 index 8b553c0..a41cd6d 100644
 --- a/arch/powerpc/kvm/booke.c
 +++ b/arch/powerpc/kvm/booke.c
 @@ -1448,6 +1448,12 @@ int kvm_vcpu_ioctl_get_one_reg(struct kvm_vcpu *vcpu, 
 struct kvm_one_reg *reg)
   case KVM_REG_PPC_TSR:
   r = put_user(vcpu-arch.tsr, (u32 __user *)(long)reg-addr);
   break;
 + case KVM_REG_PPC_DEBUG_INST: {
 + u32 opcode = KVMPPC_INST_EHPRIV;
 + r = copy_to_user((u32 __user *)(long)reg-addr,
 +  opcode, sizeof(u32));
 + break;
 + }
   default:
   break;
   }
 -- 
 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 3/7] KVM: PPC: debug stub interface parameter defined

2013-03-07 Thread Alexander Graf

On 28.02.2013, at 05:13, 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.
 
 Also kvm_arch_vcpu_ioctl_set_guest_debug() is brought one level below.
 This is because I am not sure what is required for book3s. So this ioctl
 behaviour will not change for book3s.
 
 Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
 ---
 arch/powerpc/include/uapi/asm/kvm.h |   23 +++
 arch/powerpc/kvm/book3s.c   |6 ++
 arch/powerpc/kvm/booke.c|6 ++
 arch/powerpc/kvm/powerpc.c  |6 --
 4 files changed, 35 insertions(+), 6 deletions(-)
 
 diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
 b/arch/powerpc/include/uapi/asm/kvm.h
 index c2ff99c..15f9a00 100644
 --- a/arch/powerpc/include/uapi/asm/kvm.h
 +++ b/arch/powerpc/include/uapi/asm/kvm.h
 @@ -272,8 +272,31 @@ struct kvm_debug_exit_arch {
 
 /* for KVM_SET_GUEST_DEBUG */
 struct kvm_guest_debug_arch {
 + struct {
 + /* H/W breakpoint/watchpoint address */
 + __u64 addr;
 + /*
 +  * 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];
 };
 
 +/* Debug related defines */
 +/*
 + * kvm_guest_debug-control is a 32 bit field. The lower 16 bits are generic
 + * and upper 16 bits are architecture specific. Architecture specific defines
 + * that ioctl is for setting hardware breakpoint or software breakpoint.
 + */
 +#define KVM_GUESTDBG_USE_SW_BP   0x0001
 +#define KVM_GUESTDBG_USE_HW_BP   0x0002

You only need

#define KVM_GUESTDBG_HW_BP 0x0001

In absence of the flag, it's a SW breakpoint.


Alex

 +
 /* definition of registers in kvm_run */
 struct kvm_sync_regs {
 };
 diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
 index 975a401..cb85d73 100644
 --- a/arch/powerpc/kvm/book3s.c
 +++ b/arch/powerpc/kvm/book3s.c
 @@ -613,6 +613,12 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
   return 0;
 }
 
 +int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 + struct kvm_guest_debug *dbg)
 +{
 + return -EINVAL;
 +}
 +
 void kvmppc_decrementer_func(unsigned long data)
 {
   struct kvm_vcpu *vcpu = (struct kvm_vcpu *)data;
 diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
 index a41cd6d..1de93a8 100644
 --- a/arch/powerpc/kvm/booke.c
 +++ b/arch/powerpc/kvm/booke.c
 @@ -1527,6 +1527,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;
 -}
 -
 static void kvmppc_complete_dcr_load(struct kvm_vcpu *vcpu,
  struct kvm_run *run)
 {
 -- 
 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


Re: [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit

2013-03-07 Thread Alexander Graf

On 28.02.2013, at 05:13, Bharat Bhushan wrote:

 On Guest entry: if guest is wants to use the debug register then
 save h/w debug register in host_dbg_reg and load the debug registers
 with shadow_dbg_reg. Otherwise leave h/w debug registers as is.

Why can't we switch the majority of registers on vcpu_put/get and only enable 
or disable debugging on guest entry/exit?


Alex

 
 On guest exit: If guest/user-space is using the debug resource then
 restore the h/w debug register with host_dbg_reg. No need to save guest
 debug register as shadow_dbg_reg is having required values. If guest is not
 using the debug resources then no need to restore h/w registers.
 
 Signed-off-by: Bharat Bhushan bharat.bhus...@freescale.com
 ---
 arch/powerpc/include/asm/kvm_host.h |5 ++
 arch/powerpc/kernel/asm-offsets.c   |   26 
 arch/powerpc/kvm/booke_interrupts.S |  114 +++
 3 files changed, 145 insertions(+), 0 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/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,
 +   dbcr2));
 +#ifdef CONFIG_KVM_E500MC
 + DEFINE(KVMPPC_DBG_DBCR4, offsetof(struct kvmppc_booke_debug_reg,
 +   dbcr4));
 +#endif
 + DEFINE(KVMPPC_DBG_IAC1, offsetof(struct kvmppc_booke_debug_reg,
 +  iac[0]));
 + DEFINE(KVMPPC_DBG_IAC2, offsetof(struct kvmppc_booke_debug_reg,
 +  iac[1]));
 + DEFINE(KVMPPC_DBG_IAC3, offsetof(struct kvmppc_booke_debug_reg,
 +  iac[2]));
 + DEFINE(KVMPPC_DBG_IAC4, offsetof(struct kvmppc_booke_debug_reg,
 +  iac[3]));
 + DEFINE(KVMPPC_DBG_DAC1, offsetof(struct kvmppc_booke_debug_reg,
 +  dac[0]));
 + DEFINE(KVMPPC_DBG_DAC2, offsetof(struct kvmppc_booke_debug_reg,
 +  dac[1]));
 + DEFINE(VCPU_GUEST_DEBUG, offsetof(struct kvm_vcpu, guest_debug));
 #endif /* CONFIG_PPC_BOOK3S */
 #endif /* CONFIG_KVM */
 
 diff --git a/arch/powerpc/kvm/booke_interrupts.S 
 b/arch/powerpc/kvm/booke_interrupts.S
 index 2c6deb5..6d78e01 100644
 --- a/arch/powerpc/kvm/booke_interrupts.S
 +++ b/arch/powerpc/kvm/booke_interrupts.S
 @@ -39,6 +39,8 @@
 #define HOST_MIN_STACK_SIZE (HOST_NV_GPR(R31) + 4)
 #define HOST_STACK_SIZE (((HOST_MIN_STACK_SIZE + 15) / 16) * 16) /* Align. */
 #define HOST_STACK_LR   (HOST_STACK_SIZE + 4) /* In caller stack frame. */
 +#define DBCR0_AC_BITS(DBCR0_IAC1 | DBCR0_IAC2 | DBCR0_IAC3 | 
 DBCR0_IAC4 | \
 +  DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W)
 
 #define NEED_INST_MASK ((1BOOKE_INTERRUPT_PROGRAM) | \
 (1BOOKE_INTERRUPT_DTLB_MISS) | \
 @@ -54,6 +56,8 @@
(1BOOKE_INTERRUPT_DTLB_MISS) | \
(1BOOKE_INTERRUPT_ALIGNMENT))
 
 +#define NEED_DEBUG_SAVE (1BOOKE_INTERRUPT_DEBUG)
 +
 .macro __KVM_HANDLER ivor_nr scratch srr0
   /* Get pointer to vcpu and record exit number. */
   mtspr   \scratch , r4
 @@ -215,6 +219,59 @@ _GLOBAL(kvmppc_resume_host)
   stw r9, VCPU_FAULT_ESR(r4)
 ..skip_esr:
 
 + lwz r9, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
 + rlwinm. r8, r9, 0, ~DBCR0_IDM
 + beq skip_load_host_debug
 + lwz r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
 + andis.  r9, r9, 

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

2013-03-07 Thread Alexander Graf

On 28.02.2013, at 05:13, 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 bharat.bhus...@freescale.com
 ---
 arch/powerpc/include/uapi/asm/kvm.h |   22 +-
 arch/powerpc/kvm/booke.c|  143 +++---
 arch/powerpc/kvm/e500_emulate.c |6 ++
 arch/powerpc/kvm/e500mc.c   |3 +-
 4 files changed, 155 insertions(+), 19 deletions(-)
 
 diff --git a/arch/powerpc/include/uapi/asm/kvm.h 
 b/arch/powerpc/include/uapi/asm/kvm.h
 index 15f9a00..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 linux/kvm.h */
 #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/kvm/booke.c b/arch/powerpc/kvm/booke.c
 index 1de93a8..21b0313 100644
 --- a/arch/powerpc/kvm/booke.c
 +++ b/arch/powerpc/kvm/booke.c
 @@ -133,6 +133,30 @@ 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. Do not allow guest to change MSR[DE].
 +  */
 + vcpu-arch.shared-msr |= MSR_DE;
 + mtspr(SPRN_MSRP, mfspr(SPRN_MSRP) | MSRP_DEP);
 +#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 +174,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,
 @@ -736,6 +761,13 @@ static int emulation_exit(struct kvm_run *run, struct 
 kvm_vcpu *vcpu)
   run-exit_reason = KVM_EXIT_DCR;
   return RESUME_HOST;
 
 + case EMULATE_EXIT_USER:
 + run-exit_reason = KVM_EXIT_DEBUG;
 + run-debug.arch.address = vcpu-arch.pc;
 + run-debug.arch.status = 0;
 + kvmppc_account_exit(vcpu, DEBUG_EXITS);

As mentioned previously, this is wrong and needs to go into the instruction 
emulation code for that opcode.

 + return RESUME_HOST;
 +
   case EMULATE_FAIL:
   printk(KERN_CRIT %s: emulation at %lx failed (%08x)\n,
  __func__, vcpu-arch.pc, vcpu-arch.last_inst);
 @@ -751,6 +783,28 @@ static int emulation_exit(struct kvm_run *run, struct 
 kvm_vcpu *vcpu)
   }
 }
 
 +static int kvmppc_handle_debug(struct kvm_run *run, struct kvm_vcpu *vcpu)
 +{
 + u32 dbsr = vcpu-arch.dbsr;
 + run-debug.arch.status = 0;
 + run-debug.arch.address = vcpu-arch.pc;

This should go into the if(breakpoint) branch.

 +
 + if (dbsr  (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
 + run-debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
 + } else {
 + if (dbsr  (DBSR_DAC1W | DBSR_DAC2W))
 + 

Re: [STRAWMAN PATCH] KVM: PPC: Add ioctl to specify interrupt controller architecture to emulate

2013-03-07 Thread Alexander Graf

On 07.03.2013, at 04:29, Paul Mackerras wrote:

 This adds a new ioctl, KVM_SET_IRQ_ARCHITECTURE, which is intended to
 be called by userspace to specify that it wishes the kernel to emulate
 a specific interrupt controller architecture.  This doesn't imply the
 creation of any specific device, but does indicate that when vcpus are
 created, space for per-vcpu interrupt controller state should be
 allocated.  Having this ioctl enables userspace to defer creation of
 the actual interrupt controller device(s) until after the vcpus are
 created.
 
 The KVM_SET_IRQ_ARCHITECTURE ioctl takes a single 32-bit unsigned int
 as its parameter.  Values for this parameter will be defined in
 subsequent patches.  The value of 0 means no in-kernel interrupt
 controller emulation.
 
 In order to ensure that this ioctl will fail once any vcpu has been
 created, we use an arch.vcpus_created field to indicate that vcpu
 creation has commenced.  We don't use the online_vcpus field because
 that is only incremented after vcpu creation; if we used that there
 would be a window during the first KVM_CREATE_VCPU ioctl where the
 first vcpu had been created but the interrupt architecture could still
 be changed.
 
 Signed-off-by: Paul Mackerras pau...@samba.org

Could you please (in a quick and drafty way) try and see if setting the IRQ 
arch (using enable_cap) after the vcpu got created would work for you?

That enable_cap would then have to loop through all devices and notify irq 
controllers that a new cpu got spawned.
All vcpu local payloads would have to get allocated and initialized outside of 
vcpu_create too then.

I don't have a good feeling for how hard this would be and whether locking 
would become overly difficult. I think it's fair to restrict the enable_cap to 
only work when no other vcpu is running. Of course, not requiring a stopped 
machine would make hotplug easier for user space :).

If it turns out to be hard and / or so complex that it's likely to make things 
more buggy than is worth, this patch is the way to go IMHO.


Alex

 ---
 So, should this all be done in generic code?
 
 Documentation/virtual/kvm/api.txt   |   22 
 arch/powerpc/include/asm/kvm_host.h |2 ++
 arch/powerpc/kvm/powerpc.c  |   66 +--
 include/uapi/linux/kvm.h|3 ++
 4 files changed, 90 insertions(+), 3 deletions(-)
 
 diff --git a/Documentation/virtual/kvm/api.txt 
 b/Documentation/virtual/kvm/api.txt
 index cce500a..d550313 100644
 --- a/Documentation/virtual/kvm/api.txt
 +++ b/Documentation/virtual/kvm/api.txt
 @@ -2126,6 +2126,28 @@ header; first `n_valid' valid entries with contents 
 from the data
 written, then `n_invalid' invalid entries, invalidating any previously
 valid entries found.
 
 +4.79 KVM_SET_IRQ_ARCHITECTURE
 +
 +Capability: KVM_CAP_IRQ_ARCH
 +Architecture: powerpc
 +Type: vm ioctl
 +Parameters: Pointer to u32 (in)
 +Returns: 0 on success, -1 on error
 +
 +This is called before any vcpus are created, if in-kernel interrupt
 +controller emulation is desired, to specify what overall interrupt
 +controller architecture should be emulated.  Having this called before
 +any vcpus are created allows per-vcpu interrupt controller state to be
 +allocated at vcpu creation time, and allows the creation of the actual
 +interrupt controller device to be deferred until after the vcpus are
 +created.
 +
 +The parameter is a 32-bit unsigned integer specifying the
 +architecture, or the value 0 to specify that no emulation should be
 +done.  If the requested architecture is not supported by the kernel,
 +this ioctl returns an EINVAL error.  Otherwise, if this ioctl is
 +called after any vcpus have been created, it returns an EBUSY error.
 +
 
 5. The kvm_run structure
 
 diff --git a/arch/powerpc/include/asm/kvm_host.h 
 b/arch/powerpc/include/asm/kvm_host.h
 index 8a72d59..e21ea1f 100644
 --- a/arch/powerpc/include/asm/kvm_host.h
 +++ b/arch/powerpc/include/asm/kvm_host.h
 @@ -227,6 +227,8 @@ struct kvm_arch_memory_slot {
 };
 
 struct kvm_arch {
 + unsigned int irq_arch;
 + int vcpus_created;
   unsigned int lpid;
 #ifdef CONFIG_KVM_BOOK3S_64_HV
   unsigned long hpt_virt;
 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
 index 934413c..b681746 100644
 --- a/arch/powerpc/kvm/powerpc.c
 +++ b/arch/powerpc/kvm/powerpc.c
 @@ -441,10 +441,21 @@ struct kvm_vcpu *kvm_arch_vcpu_create(struct kvm *kvm, 
 unsigned int id)
 {
   struct kvm_vcpu *vcpu;
   vcpu = kvmppc_core_vcpu_create(kvm, id);
 - if (!IS_ERR(vcpu)) {
 - vcpu-arch.wqp = vcpu-wq;
 - kvmppc_create_vcpu_debugfs(vcpu, id);
 + if (IS_ERR(vcpu))
 + goto out;
 +
 + /* Create per-vcpu irq controller state if needed */
 + mutex_lock(kvm-lock);
 + kvm-arch.vcpus_created = 1;
 + switch (kvm-arch.irq_arch) {
 + default:
 + break;
   }
 + mutex_unlock(kvm-lock);
 +
 +