All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/7] KVM :PPC: Userspace Debug support
@ 2013-02-28  4:25 ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:13 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

This patchset adds the userspace debug support for booke/bookehv.
this is tested on powerpc e500v2/e500mc devices.

Bharat Bhushan (7):
  KVM: PPC: booke: Added debug handler
  Added ONE_REG interface for debug instruction
  KVM: PPC: debug stub interface parameter defined
  booke: Save and restore debug registers on guest entry and exit
  bookehv: Save and restore debug registers on guest entry and exit
  Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
  KVM: PPC: Add userspace debug stub support

 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/asm/kvm_host.h   |    6 ++
 arch/powerpc/include/asm/kvm_ppc.h    |    2 +-
 arch/powerpc/include/uapi/asm/kvm.h   |   41 +++++++++
 arch/powerpc/kernel/asm-offsets.c     |   27 ++++++
 arch/powerpc/kvm/book3s.c             |   12 +++
 arch/powerpc/kvm/book3s_emulate.c     |    2 +-
 arch/powerpc/kvm/book3s_pr.c          |    2 +-
 arch/powerpc/kvm/booke.c              |  153 +++++++++++++++++++++++++++++---
 arch/powerpc/kvm/booke_interrupts.S   |  156 ++++++++++++++++++++++++++++++++-
 arch/powerpc/kvm/bookehv_interrupts.S |  145 +++++++++++++++++++++++++++++-
 arch/powerpc/kvm/e500_emulate.c       |    6 ++
 arch/powerpc/kvm/e500mc.c             |    3 +-
 arch/powerpc/kvm/powerpc.c            |    6 --
 16 files changed, 535 insertions(+), 30 deletions(-)



^ permalink raw reply	[flat|nested] 72+ messages in thread

* [PATCH 1/7] KVM: PPC: booke: Added debug handler
  2013-02-28  4:25 ` Bharat Bhushan
@ 2013-02-28  4:25   ` Bharat Bhushan
  -1 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:13 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: 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 <yu.liu@freescale.com>
[bharat.bhushan@freescale.com: Substantial changes]
Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
---
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/kernel/asm-offsets.c   |    1 +
 arch/powerpc/kvm/booke_interrupts.S |   42 ++++++++++++++++++++++++++++++++--
 3 files changed, 41 insertions(+), 3 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 f4bb55c..2c6deb5 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -54,8 +54,7 @@
                        (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
                        (1<<BOOKE_INTERRUPT_ALIGNMENT))
 
-.macro KVM_HANDLER ivor_nr scratch srr0
-_GLOBAL(kvmppc_handler_\ivor_nr)
+.macro __KVM_HANDLER ivor_nr scratch srr0
 	/* Get pointer to vcpu and record exit number. */
 	mtspr	\scratch , r4
 	mfspr   r4, SPRN_SPRG_THREAD
@@ -76,6 +75,43 @@ _GLOBAL(kvmppc_handler_\ivor_nr)
 	bctr
 .endm
 
+.macro KVM_HANDLER ivor_nr scratch srr0
+_GLOBAL(kvmppc_handler_\ivor_nr)
+	__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)
+	mfcr	r3
+	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, 0xffff
+	ori	r4, r4, 0xffff
+	mtspr	SPRN_DBSR, r4
+	mfspr	r4, SPRN_SPRG_THREAD
+	lwz	r4, THREAD_KVM_VCPU(r4)
+	mtcr	r3
+	lwz     r3, VCPU_CRIT_SAVE(r4)
+	mfspr   r4, \scratch
+	rfci
+1:	/* debug interrupt happened in guest */
+	mtcr	r3
+	mfspr	r4, SPRN_SPRG_THREAD
+	lwz	r4, THREAD_KVM_VCPU(r4)
+	lwz     r3, VCPU_CRIT_SAVE(r4)
+	mfspr   r4, \scratch
+	__KVM_HANDLER \ivor_nr \scratch \srr0
+.endm
+
 .macro KVM_HANDLER_ADDR ivor_nr
 	.long	kvmppc_handler_\ivor_nr
 .endm
@@ -100,7 +136,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

^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 2/7] Added ONE_REG interface for debug instruction
  2013-02-28  4:25 ` Bharat Bhushan
@ 2013-02-28  4:25   ` Bharat Bhushan
  -1 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:13 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.bhushan@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				0x7c000008
 
 /* 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_LPIDS                        64
 
+#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



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-02-28  4:25 ` Bharat Bhushan
@ 2013-02-28  4:25   ` Bharat Bhushan
  -1 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:13 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.bhushan@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		0x00010000
+#define KVM_GUESTDBG_USE_HW_BP		0x00020000
+
 /* 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

^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
  2013-02-28  4:25 ` Bharat Bhushan
@ 2013-02-28  4:25   ` Bharat Bhushan
  -1 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:13 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.

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.bhushan@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 ((1<<BOOKE_INTERRUPT_PROGRAM) | \
                         (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
@@ -54,6 +56,8 @@
                        (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
                        (1<<BOOKE_INTERRUPT_ALIGNMENT))
 
+#define NEED_DEBUG_SAVE (1<<BOOKE_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, DBCR0_AC_BITS@h
+	li	r9, 0
+	mtspr	SPRN_DBCR0, r9		/* disable all debug event */
+	beq	skip_load_hw_bkpts
+	lwz	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
+	lwz	r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
+	mtspr	SPRN_DBCR1, r7
+	mtspr	SPRN_DBCR2, r9
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
+	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
+	mtspr	SPRN_IAC1, r7
+	mtspr	SPRN_IAC2, r9
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
+	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
+	mtspr	SPRN_IAC3, r3
+	mtspr	SPRN_IAC4, r4
+#endif
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
+	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
+	mtspr	SPRN_DAC1, r7
+	mtspr	SPRN_DAC2, r9
+skip_load_hw_bkpts:
+	/* Clear h/w DBSR and save current(guest) DBSR */
+	mfspr	r9, SPRN_DBSR
+	mtspr	SPRN_DBSR, r9
+	isync
+	andi.	r7, r6, NEED_DEBUG_SAVE
+	beq	skip_dbsr_save
+	/*
+	 * If vcpu->guest_debug flag is set then do not check for
+	 * shared->msr.DE as this debugging (say by QEMU) does not
+	 * depends on shared->msr.de. In these scanerios MSR.DE is
+	 * always set using shared_msr and should be handled always.
+	 */
+	lwz	r7, VCPU_GUEST_DEBUG(r4)
+	cmpwi	r7, 0
+	bne	skip_save_trap_event
+	PPC_LL	r3, VCPU_SHARED(r4)
+	PPC_LD(r3, VCPU_SHARED_MSR, r3)
+	andi.	r3, r3, MSR_DE
+	bne	skip_save_trap_event
+	andis.	r9, r9, DBSR_TIE@h
+skip_save_trap_event:
+	stw	r9, VCPU_DBSR(r4)
+skip_dbsr_save:
+	mtspr	SPRN_DBCR0, r8
+skip_load_host_debug:
+
 	/* Save remaining volatile guest register state to vcpu. */
 	stw	r0, VCPU_GPR(R0)(r4)
 	stw	r1, VCPU_GPR(R1)(r4)
@@ -468,6 +525,63 @@ lightweight_exit:
 	PPC_LD(r3, VCPU_SHARED_SPRG7, r5)
 	mtspr	SPRN_SPRG7W, r3
 
+	mfmsr	r7
+	rlwinm	r7, r7, 0, ~MSR_DE
+	mtmsr	r7
+	lwz	r6, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
+	rlwinm.	r7, r6, 0, ~DBCR0_IDM
+	beq	skip_load_guest_debug
+	mfspr	r8, SPRN_DBCR0
+	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
+	andis.	r3, r6, DBCR0_AC_BITS@h
+	beq	skip_hw_bkpts
+	mfspr	r7, SPRN_DBCR1
+	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
+	mfspr	r8, SPRN_DBCR2
+	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
+	mfspr	r7, SPRN_IAC1
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
+	mfspr	r8, SPRN_IAC2
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	mfspr	r7, SPRN_IAC3
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
+	mfspr	r8, SPRN_IAC4
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
+#endif
+	mfspr	r7, SPRN_DAC1
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
+	mfspr	r8, SPRN_DAC2
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
+	li	r8, 0
+	mtspr	SPRN_DBCR0, r8		/* disable all debug event */
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR1, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR2, r4)
+	mtspr	SPRN_DBCR1, r7
+	mtspr	SPRN_DBCR2, r8
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC1, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC2, r4)
+	mtspr	SPRN_IAC1, r7
+	mtspr	SPRN_IAC2, r8
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC3, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC4, r4)
+	mtspr	SPRN_IAC3, r7
+	mtspr	SPRN_IAC4, r8
+#endif
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC1, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC2, r4)
+	mtspr	SPRN_DAC1, r7
+	mtspr	SPRN_DAC2, r8
+skip_hw_bkpts:
+	/* Clear if any deferred debug event */
+	mfspr	r8, SPRN_DBSR
+	mtspr	SPRN_DBSR, r8
+	isync
+	/* Restore guest DBCR */
+	mtspr	SPRN_DBCR0, r6
+skip_load_guest_debug:
+
 #ifdef CONFIG_KVM_EXIT_TIMING
 	/* save enter time */
 1:
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 5/7] bookehv: Save and restore debug registers on guest entry and exit
  2013-02-28  4:25 ` Bharat Bhushan
@ 2013-02-28  4:25   ` Bharat Bhushan
  -1 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:13 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.

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.bhushan@freescale.com>
---
 arch/powerpc/kvm/bookehv_interrupts.S |  145 ++++++++++++++++++++++++++++++++-
 1 files changed, 141 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S b/arch/powerpc/kvm/bookehv_interrupts.S
index e8ed7d6..0d830cc 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -62,6 +62,10 @@
 #define NEED_EMU		0x00000001 /* emulation -- save nv regs */
 #define NEED_DEAR		0x00000002 /* save faulting DEAR */
 #define NEED_ESR		0x00000004 /* save faulting ESR */
+#define NEED_DBSR		0x00000008 /* save DBSR */
+
+#define DBCR0_AC_BITS	(DBCR0_IAC1 | DBCR0_IAC2 | DBCR0_IAC3 | DBCR0_IAC4 | \
+			 DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W)
 
 /*
  * On entry:
@@ -201,6 +205,11 @@
 	PPC_STL	r9, VCPU_FAULT_DEAR(r4)
 	.endif
 
+	.if	\flags & NEED_DBSR
+	mfspr	r9, SPRN_DBSR
+	stw	r9, VCPU_DBSR(r4)
+	.endif
+
 	b	kvmppc_resume_host
 .endm
 
@@ -316,9 +325,9 @@ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, EX_PARAMS(GDBELL), \
 kvm_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, EX_PARAMS(CRIT), \
 	SPRN_CSRR0, SPRN_CSRR1, 0
 kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(DBG), \
-	SPRN_DSRR0, SPRN_DSRR1, 0
+	SPRN_DSRR0, SPRN_DSRR1, NEED_DBSR
 kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(CRIT), \
-	SPRN_CSRR0, SPRN_CSRR1, 0
+	SPRN_CSRR0, SPRN_CSRR1, NEED_DBSR
 #else
 /*
  * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h
@@ -411,9 +420,9 @@ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, SPRN_GSRR0, SPRN_GSRR1, 0
 kvm_lvl_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, \
 	SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
 kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
-	SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
+	SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, NEED_DBSR
 kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
-	SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, 0
+	SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, NEED_DBSR
 #endif
 
 /* Registers:
@@ -423,6 +432,56 @@ kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
  *  r14: KVM exit number
  */
 _GLOBAL(kvmppc_resume_host)
+	/*
+	 * If guest not used debug facility then hw debug registers
+	 * already have proper host values. If guest used debug
+	 * facility then restore host debug registers.
+	 * No Need to save guest debug registers as they are already intact
+	 * in guest/shadow registers.
+	 */
+	lwz	r9, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
+	rlwinm.	r8, r9, 0, ~DBCR0_IDM
+	beq	skip_load_host_debug
+	lwz	r3, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
+	andis.	r9, r9, DBCR0_AC_BITS@h
+	li	r9, 0
+	mtspr	SPRN_DBCR0, r9		/* disable all debug event */
+	beq	skip_load_hw_bkpts
+	lwz	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
+	lwz	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
+	lwz	r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR4(r4)
+	mtspr	SPRN_DBCR1, r7
+	PPC_LD(r6, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
+	mtspr	SPRN_DBCR2, r8
+	mtspr	SPRN_DBCR4, r9
+	mtspr	SPRN_IAC1, r6
+	mtspr	SPRN_IAC2, r7
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
+	PPC_LD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
+	mtspr	SPRN_IAC3, r7
+	mtspr	SPRN_IAC4, r8
+#endif
+	PPC_LD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
+	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
+	mtspr	SPRN_DAC1, r8
+	mtspr	SPRN_DAC2, r9
+skip_load_hw_bkpts:
+	isync
+	/* Clear h/w DBSR */
+	mfspr	r8, SPRN_DBSR
+	mtspr	SPRN_DBSR, r8
+	isync
+	/* Clear EPCR.DUVD and set host DBCR0 */
+	mfspr	r8, SPRN_EPCR
+	rlwinm	r8, r8, 0, ~SPRN_EPCR_DUVD
+	mtspr	SPRN_EPCR, r8
+	isync
+	mtspr	SPRN_DBCR0, r3
+	isync
+skip_load_host_debug:
+
 	/* Save remaining volatile guest register state to vcpu. */
 	mfspr	r3, SPRN_VRSAVE
 	PPC_STL	r0, VCPU_GPR(R0)(r4)
@@ -662,6 +721,84 @@ lightweight_exit:
 	mtspr	SPRN_SPRG6W, r7
 	mtspr	SPRN_SPRG7W, r8
 
+	mfmsr	r7
+	rlwinm	r7, r7, 0, ~MSR_DE
+	mtmsr	r7
+	/*
+	 * Load hw debug registers with guest(shadow) debug registers
+	 * if guest is using the debug facility and also set EPCR.DUVD
+	 * to not allow debug events in HV mode. Do not change the
+	 * debug registers if guest is not using the debug facility.
+	 */
+	lwz	r6, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
+	rlwinm.	r7, r6, 0, ~DBCR0_IDM
+	beq	skip_load_guest_debug
+	/* Save host DBCR0 */
+	mfspr	r8, SPRN_DBCR0
+	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
+	/*
+	 * Save host DBCR1/2, IACx and DACx and load guest DBCR1/2,
+	 * IACx and DACx if guest using hw breakpoint/watchpoints.
+	 */
+	andis.	r3, r6, DBCR0_AC_BITS@h
+	beq	skip_hw_bkpts
+	mfspr	r7, SPRN_DBCR1
+	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
+	mfspr	r8, SPRN_DBCR2
+	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
+	mfspr	r7, SPRN_DBCR4
+	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR4(r4)
+	mfspr	r8, SPRN_IAC1
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
+	mfspr	r7, SPRN_IAC2
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	mfspr	r8, SPRN_IAC3
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
+	mfspr	r7, SPRN_IAC4
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
+#endif
+	mfspr	r8, SPRN_DAC1
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
+	mfspr	r7, SPRN_DAC2
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
+	li	r8, 0
+	mtspr	SPRN_DBCR0, r8		/* disable all debug event */
+	lwz	r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR1(r4)
+	lwz	r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR2(r4)
+	lwz	r9, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR4(r4)
+	mtspr	SPRN_DBCR1, r7
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC1, r4)
+	PPC_LD(r3, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC2, r4)
+	mtspr	SPRN_DBCR2, r8
+	mtspr	SPRN_DBCR4, r9
+	mtspr	SPRN_IAC1, r7
+	mtspr	SPRN_IAC2, r3
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC3, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC4, r4)
+	mtspr	SPRN_IAC3, r7
+	mtspr	SPRN_IAC4, r8
+#endif
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC1, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC2, r4)
+	mtspr	SPRN_DAC1, r7
+	mtspr	SPRN_DAC2, r8
+skip_hw_bkpts:
+	/* Set EPCR.DUVD and guest DBCR0 */
+	mfspr	r7, SPRN_EPCR
+	oris	r7, r7, SPRN_EPCR_DUVD@h
+	mtspr	SPRN_EPCR, r7
+	isync
+	/* Clear if any deferred debug event */
+	mfspr	r8, SPRN_DBSR
+	mtspr	SPRN_DBSR, r8
+	isync
+	/* Restore guest DBCR */
+	mtspr	SPRN_DBCR0, r6
+	isync
+skip_load_guest_debug:
+
 	/* Load some guest volatiles. */
 	PPC_LL	r3, VCPU_LR(r4)
 	PPC_LL	r5, VCPU_XER(r4)
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
  2013-02-28  4:25 ` Bharat Bhushan
@ 2013-02-28  4:25   ` Bharat Bhushan
  -1 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:13 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.bhushan@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;
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 7/7] KVM: PPC: Add userspace debug stub support
  2013-02-28  4:25 ` Bharat Bhushan
@ 2013-02-28  4:25   ` Bharat Bhushan
  -1 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:13 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: 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.

Signed-off-by: Bharat Bhushan <bharat.bhushan@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_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_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);
+		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;
+
+	if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
+		run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
+	} else {
+		if (dbsr & (DBSR_DAC1W | DBSR_DAC2W))
+			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
+		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
+			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
+		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
+			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
+		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
+			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
+	}
+
+	return RESUME_HOST;
+}
+
 static void kvmppc_fill_pt_regs(struct pt_regs *regs)
 {
 	ulong r1, ip, msr, lr;
@@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	}
 
 	case BOOKE_INTERRUPT_DEBUG: {
-		u32 dbsr;
-
-		vcpu->arch.pc = mfspr(SPRN_CSRR0);
-
-		/* clear IAC events in DBSR register */
-		dbsr = mfspr(SPRN_DBSR);
-		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
-		mtspr(SPRN_DBSR, dbsr);
-
-		run->exit_reason = KVM_EXIT_DEBUG;
+		r = kvmppc_handle_debug(run, vcpu);
+		if (r == RESUME_HOST) {
+			run->exit_reason = KVM_EXIT_DEBUG;
+		}
 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
-		r = RESUME_HOST;
 		break;
 	}
 
@@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 	kvmppc_set_msr(vcpu, 0);
 
 #ifndef CONFIG_KVM_BOOKE_HV
-	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
+	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
 	vcpu->arch.shadow_pid = 1;
 	vcpu->arch.shared->msr = 0;
 #endif
@@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
 	return r;
 }
 
+#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
+#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
+
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					 struct kvm_guest_debug *dbg)
 {
-	return -EINVAL;
+
+	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
+		/* Clear All debug events */
+		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
+		vcpu->guest_debug = 0;
+		return 0;
+	}
+
+	vcpu->guest_debug = dbg->control;
+	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
+	/* Set DBCR0_EDM in guest visible DBCR0 register. */
+	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
+
+	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
+		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
+
+	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
+		struct kvmppc_booke_debug_reg *gdbgr =
+				&(vcpu->arch.shadow_dbg_reg);
+		int n, b = 0, w = 0;
+		const u32 bp_code[] = {
+			DBCR0_IAC1 | DBCR0_IDM,
+			DBCR0_IAC2 | DBCR0_IDM,
+			DBCR0_IAC3 | DBCR0_IDM,
+			DBCR0_IAC4 | DBCR0_IDM
+		};
+		const u32 wp_code[] = {
+			DBCR0_DAC1W | DBCR0_IDM,
+			DBCR0_DAC2W | DBCR0_IDM,
+			DBCR0_DAC1R | DBCR0_IDM,
+			DBCR0_DAC2R | DBCR0_IDM
+		};
+
+#ifndef CONFIG_KVM_BOOKE_HV
+		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
+				DBCR1_IAC3US | DBCR1_IAC4US;
+		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
+#else
+		gdbgr->dbcr1 = 0;
+		gdbgr->dbcr2 = 0;
+#endif
+
+		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
+			u32 type = dbg->arch.bp[n].type;
+
+			if (!type)
+				break;
+
+			if (type & (KVMPPC_DEBUG_WATCH_READ |
+				    KVMPPC_DEBUG_WATCH_WRITE)) {
+				if (w < WP_NUM) {
+					if (type & KVMPPC_DEBUG_WATCH_READ)
+						gdbgr->dbcr0 |= wp_code[w + 2];
+					if (type & KVMPPC_DEBUG_WATCH_WRITE)
+						gdbgr->dbcr0 |= wp_code[w];
+					gdbgr->dac[w] = dbg->arch.bp[n].addr;
+					w++;
+				}
+			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
+				if (b < BP_NUM) {
+					gdbgr->dbcr0 |= bp_code[b];
+					gdbgr->iac[b] = dbg->arch.bp[n].addr;
+					b++;
+				}
+			}
+		}
+	}
+	return 0;
 }
 
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index e78f353..83ac877 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -26,6 +26,7 @@
 #define XOP_TLBRE   946
 #define XOP_TLBWE   978
 #define XOP_TLBILX  18
+#define XOP_EHPRIV  270
 
 #ifdef CONFIG_KVM_E500MC
 static int dbell2prio(ulong param)
@@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
 			break;
 
+		case XOP_EHPRIV:
+			emulated = EMULATE_EXIT_USER;
+			*advance = 0;
+			break;
+
 		default:
 			emulated = EMULATE_FAIL;
 		}
diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index 1f89d26..f5fc6f5 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
 {
 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
 
-	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
-				 SPRN_EPCR_DUVD;
+	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;
 #ifdef CONFIG_64BIT
 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM;
 #endif
-- 
1.7.0.4

^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 0/7] KVM :PPC: Userspace Debug support
@ 2013-02-28  4:25 ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:25 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

This patchset adds the userspace debug support for booke/bookehv.
this is tested on powerpc e500v2/e500mc devices.

Bharat Bhushan (7):
  KVM: PPC: booke: Added debug handler
  Added ONE_REG interface for debug instruction
  KVM: PPC: debug stub interface parameter defined
  booke: Save and restore debug registers on guest entry and exit
  bookehv: Save and restore debug registers on guest entry and exit
  Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
  KVM: PPC: Add userspace debug stub support

 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/asm/kvm_host.h   |    6 ++
 arch/powerpc/include/asm/kvm_ppc.h    |    2 +-
 arch/powerpc/include/uapi/asm/kvm.h   |   41 +++++++++
 arch/powerpc/kernel/asm-offsets.c     |   27 ++++++
 arch/powerpc/kvm/book3s.c             |   12 +++
 arch/powerpc/kvm/book3s_emulate.c     |    2 +-
 arch/powerpc/kvm/book3s_pr.c          |    2 +-
 arch/powerpc/kvm/booke.c              |  153 +++++++++++++++++++++++++++++---
 arch/powerpc/kvm/booke_interrupts.S   |  156 ++++++++++++++++++++++++++++++++-
 arch/powerpc/kvm/bookehv_interrupts.S |  145 +++++++++++++++++++++++++++++-
 arch/powerpc/kvm/e500_emulate.c       |    6 ++
 arch/powerpc/kvm/e500mc.c             |    3 +-
 arch/powerpc/kvm/powerpc.c            |    6 --
 16 files changed, 535 insertions(+), 30 deletions(-)



^ permalink raw reply	[flat|nested] 72+ messages in thread

* [PATCH 1/7] KVM: PPC: booke: Added debug handler
@ 2013-02-28  4:25   ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:25 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: 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 <yu.liu@freescale.com>
[bharat.bhushan@freescale.com: Substantial changes]
Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
---
 arch/powerpc/include/asm/kvm_host.h |    1 +
 arch/powerpc/kernel/asm-offsets.c   |    1 +
 arch/powerpc/kvm/booke_interrupts.S |   42 ++++++++++++++++++++++++++++++++--
 3 files changed, 41 insertions(+), 3 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 f4bb55c..2c6deb5 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -54,8 +54,7 @@
                        (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
                        (1<<BOOKE_INTERRUPT_ALIGNMENT))
 
-.macro KVM_HANDLER ivor_nr scratch srr0
-_GLOBAL(kvmppc_handler_\ivor_nr)
+.macro __KVM_HANDLER ivor_nr scratch srr0
 	/* Get pointer to vcpu and record exit number. */
 	mtspr	\scratch , r4
 	mfspr   r4, SPRN_SPRG_THREAD
@@ -76,6 +75,43 @@ _GLOBAL(kvmppc_handler_\ivor_nr)
 	bctr
 .endm
 
+.macro KVM_HANDLER ivor_nr scratch srr0
+_GLOBAL(kvmppc_handler_\ivor_nr)
+	__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)
+	mfcr	r3
+	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, 0xffff
+	ori	r4, r4, 0xffff
+	mtspr	SPRN_DBSR, r4
+	mfspr	r4, SPRN_SPRG_THREAD
+	lwz	r4, THREAD_KVM_VCPU(r4)
+	mtcr	r3
+	lwz     r3, VCPU_CRIT_SAVE(r4)
+	mfspr   r4, \scratch
+	rfci
+1:	/* debug interrupt happened in guest */
+	mtcr	r3
+	mfspr	r4, SPRN_SPRG_THREAD
+	lwz	r4, THREAD_KVM_VCPU(r4)
+	lwz     r3, VCPU_CRIT_SAVE(r4)
+	mfspr   r4, \scratch
+	__KVM_HANDLER \ivor_nr \scratch \srr0
+.endm
+
 .macro KVM_HANDLER_ADDR ivor_nr
 	.long	kvmppc_handler_\ivor_nr
 .endm
@@ -100,7 +136,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



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 2/7] Added ONE_REG interface for debug instruction
@ 2013-02-28  4:25   ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:25 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.bhushan@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				0x7c000008
 
 /* 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_LPIDS                        64
 
+#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



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-02-28  4:25   ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:25 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.bhushan@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		0x00010000
+#define KVM_GUESTDBG_USE_HW_BP		0x00020000
+
 /* 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



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
@ 2013-02-28  4:25   ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:25 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.

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.bhushan@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 ((1<<BOOKE_INTERRUPT_PROGRAM) | \
                         (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
@@ -54,6 +56,8 @@
                        (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
                        (1<<BOOKE_INTERRUPT_ALIGNMENT))
 
+#define NEED_DEBUG_SAVE (1<<BOOKE_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, DBCR0_AC_BITS@h
+	li	r9, 0
+	mtspr	SPRN_DBCR0, r9		/* disable all debug event */
+	beq	skip_load_hw_bkpts
+	lwz	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
+	lwz	r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
+	mtspr	SPRN_DBCR1, r7
+	mtspr	SPRN_DBCR2, r9
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
+	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
+	mtspr	SPRN_IAC1, r7
+	mtspr	SPRN_IAC2, r9
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
+	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
+	mtspr	SPRN_IAC3, r3
+	mtspr	SPRN_IAC4, r4
+#endif
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
+	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
+	mtspr	SPRN_DAC1, r7
+	mtspr	SPRN_DAC2, r9
+skip_load_hw_bkpts:
+	/* Clear h/w DBSR and save current(guest) DBSR */
+	mfspr	r9, SPRN_DBSR
+	mtspr	SPRN_DBSR, r9
+	isync
+	andi.	r7, r6, NEED_DEBUG_SAVE
+	beq	skip_dbsr_save
+	/*
+	 * If vcpu->guest_debug flag is set then do not check for
+	 * shared->msr.DE as this debugging (say by QEMU) does not
+	 * depends on shared->msr.de. In these scanerios MSR.DE is
+	 * always set using shared_msr and should be handled always.
+	 */
+	lwz	r7, VCPU_GUEST_DEBUG(r4)
+	cmpwi	r7, 0
+	bne	skip_save_trap_event
+	PPC_LL	r3, VCPU_SHARED(r4)
+	PPC_LD(r3, VCPU_SHARED_MSR, r3)
+	andi.	r3, r3, MSR_DE
+	bne	skip_save_trap_event
+	andis.	r9, r9, DBSR_TIE@h
+skip_save_trap_event:
+	stw	r9, VCPU_DBSR(r4)
+skip_dbsr_save:
+	mtspr	SPRN_DBCR0, r8
+skip_load_host_debug:
+
 	/* Save remaining volatile guest register state to vcpu. */
 	stw	r0, VCPU_GPR(R0)(r4)
 	stw	r1, VCPU_GPR(R1)(r4)
@@ -468,6 +525,63 @@ lightweight_exit:
 	PPC_LD(r3, VCPU_SHARED_SPRG7, r5)
 	mtspr	SPRN_SPRG7W, r3
 
+	mfmsr	r7
+	rlwinm	r7, r7, 0, ~MSR_DE
+	mtmsr	r7
+	lwz	r6, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
+	rlwinm.	r7, r6, 0, ~DBCR0_IDM
+	beq	skip_load_guest_debug
+	mfspr	r8, SPRN_DBCR0
+	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
+	andis.	r3, r6, DBCR0_AC_BITS@h
+	beq	skip_hw_bkpts
+	mfspr	r7, SPRN_DBCR1
+	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
+	mfspr	r8, SPRN_DBCR2
+	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
+	mfspr	r7, SPRN_IAC1
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
+	mfspr	r8, SPRN_IAC2
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	mfspr	r7, SPRN_IAC3
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
+	mfspr	r8, SPRN_IAC4
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
+#endif
+	mfspr	r7, SPRN_DAC1
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
+	mfspr	r8, SPRN_DAC2
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
+	li	r8, 0
+	mtspr	SPRN_DBCR0, r8		/* disable all debug event */
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR1, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR2, r4)
+	mtspr	SPRN_DBCR1, r7
+	mtspr	SPRN_DBCR2, r8
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC1, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC2, r4)
+	mtspr	SPRN_IAC1, r7
+	mtspr	SPRN_IAC2, r8
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC3, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC4, r4)
+	mtspr	SPRN_IAC3, r7
+	mtspr	SPRN_IAC4, r8
+#endif
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC1, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC2, r4)
+	mtspr	SPRN_DAC1, r7
+	mtspr	SPRN_DAC2, r8
+skip_hw_bkpts:
+	/* Clear if any deferred debug event */
+	mfspr	r8, SPRN_DBSR
+	mtspr	SPRN_DBSR, r8
+	isync
+	/* Restore guest DBCR */
+	mtspr	SPRN_DBCR0, r6
+skip_load_guest_debug:
+
 #ifdef CONFIG_KVM_EXIT_TIMING
 	/* save enter time */
 1:
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 5/7] bookehv: Save and restore debug registers on guest entry and exit
@ 2013-02-28  4:25   ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:25 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.

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.bhushan@freescale.com>
---
 arch/powerpc/kvm/bookehv_interrupts.S |  145 ++++++++++++++++++++++++++++++++-
 1 files changed, 141 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kvm/bookehv_interrupts.S b/arch/powerpc/kvm/bookehv_interrupts.S
index e8ed7d6..0d830cc 100644
--- a/arch/powerpc/kvm/bookehv_interrupts.S
+++ b/arch/powerpc/kvm/bookehv_interrupts.S
@@ -62,6 +62,10 @@
 #define NEED_EMU		0x00000001 /* emulation -- save nv regs */
 #define NEED_DEAR		0x00000002 /* save faulting DEAR */
 #define NEED_ESR		0x00000004 /* save faulting ESR */
+#define NEED_DBSR		0x00000008 /* save DBSR */
+
+#define DBCR0_AC_BITS	(DBCR0_IAC1 | DBCR0_IAC2 | DBCR0_IAC3 | DBCR0_IAC4 | \
+			 DBCR0_DAC1R | DBCR0_DAC1W | DBCR0_DAC2R | DBCR0_DAC2W)
 
 /*
  * On entry:
@@ -201,6 +205,11 @@
 	PPC_STL	r9, VCPU_FAULT_DEAR(r4)
 	.endif
 
+	.if	\flags & NEED_DBSR
+	mfspr	r9, SPRN_DBSR
+	stw	r9, VCPU_DBSR(r4)
+	.endif
+
 	b	kvmppc_resume_host
 .endm
 
@@ -316,9 +325,9 @@ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, EX_PARAMS(GDBELL), \
 kvm_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, EX_PARAMS(CRIT), \
 	SPRN_CSRR0, SPRN_CSRR1, 0
 kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(DBG), \
-	SPRN_DSRR0, SPRN_DSRR1, 0
+	SPRN_DSRR0, SPRN_DSRR1, NEED_DBSR
 kvm_handler BOOKE_INTERRUPT_DEBUG, EX_PARAMS(CRIT), \
-	SPRN_CSRR0, SPRN_CSRR1, 0
+	SPRN_CSRR0, SPRN_CSRR1, NEED_DBSR
 #else
 /*
  * For input register values, see arch/powerpc/include/asm/kvm_booke_hv_asm.h
@@ -411,9 +420,9 @@ kvm_handler BOOKE_INTERRUPT_GUEST_DBELL, SPRN_GSRR0, SPRN_GSRR1, 0
 kvm_lvl_handler BOOKE_INTERRUPT_GUEST_DBELL_CRIT, \
 	SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
 kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
-	SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, 0
+	SPRN_SPRG_RSCRATCH_CRIT, SPRN_CSRR0, SPRN_CSRR1, NEED_DBSR
 kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
-	SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, 0
+	SPRN_SPRG_RSCRATCH_DBG, SPRN_DSRR0, SPRN_DSRR1, NEED_DBSR
 #endif
 
 /* Registers:
@@ -423,6 +432,56 @@ kvm_lvl_handler BOOKE_INTERRUPT_DEBUG, \
  *  r14: KVM exit number
  */
 _GLOBAL(kvmppc_resume_host)
+	/*
+	 * If guest not used debug facility then hw debug registers
+	 * already have proper host values. If guest used debug
+	 * facility then restore host debug registers.
+	 * No Need to save guest debug registers as they are already intact
+	 * in guest/shadow registers.
+	 */
+	lwz	r9, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
+	rlwinm.	r8, r9, 0, ~DBCR0_IDM
+	beq	skip_load_host_debug
+	lwz	r3, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
+	andis.	r9, r9, DBCR0_AC_BITS@h
+	li	r9, 0
+	mtspr	SPRN_DBCR0, r9		/* disable all debug event */
+	beq	skip_load_hw_bkpts
+	lwz	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
+	lwz	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
+	lwz	r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR4(r4)
+	mtspr	SPRN_DBCR1, r7
+	PPC_LD(r6, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
+	mtspr	SPRN_DBCR2, r8
+	mtspr	SPRN_DBCR4, r9
+	mtspr	SPRN_IAC1, r6
+	mtspr	SPRN_IAC2, r7
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
+	PPC_LD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
+	mtspr	SPRN_IAC3, r7
+	mtspr	SPRN_IAC4, r8
+#endif
+	PPC_LD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
+	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
+	mtspr	SPRN_DAC1, r8
+	mtspr	SPRN_DAC2, r9
+skip_load_hw_bkpts:
+	isync
+	/* Clear h/w DBSR */
+	mfspr	r8, SPRN_DBSR
+	mtspr	SPRN_DBSR, r8
+	isync
+	/* Clear EPCR.DUVD and set host DBCR0 */
+	mfspr	r8, SPRN_EPCR
+	rlwinm	r8, r8, 0, ~SPRN_EPCR_DUVD
+	mtspr	SPRN_EPCR, r8
+	isync
+	mtspr	SPRN_DBCR0, r3
+	isync
+skip_load_host_debug:
+
 	/* Save remaining volatile guest register state to vcpu. */
 	mfspr	r3, SPRN_VRSAVE
 	PPC_STL	r0, VCPU_GPR(R0)(r4)
@@ -662,6 +721,84 @@ lightweight_exit:
 	mtspr	SPRN_SPRG6W, r7
 	mtspr	SPRN_SPRG7W, r8
 
+	mfmsr	r7
+	rlwinm	r7, r7, 0, ~MSR_DE
+	mtmsr	r7
+	/*
+	 * Load hw debug registers with guest(shadow) debug registers
+	 * if guest is using the debug facility and also set EPCR.DUVD
+	 * to not allow debug events in HV mode. Do not change the
+	 * debug registers if guest is not using the debug facility.
+	 */
+	lwz	r6, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
+	rlwinm.	r7, r6, 0, ~DBCR0_IDM
+	beq	skip_load_guest_debug
+	/* Save host DBCR0 */
+	mfspr	r8, SPRN_DBCR0
+	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
+	/*
+	 * Save host DBCR1/2, IACx and DACx and load guest DBCR1/2,
+	 * IACx and DACx if guest using hw breakpoint/watchpoints.
+	 */
+	andis.	r3, r6, DBCR0_AC_BITS@h
+	beq	skip_hw_bkpts
+	mfspr	r7, SPRN_DBCR1
+	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
+	mfspr	r8, SPRN_DBCR2
+	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
+	mfspr	r7, SPRN_DBCR4
+	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR4(r4)
+	mfspr	r8, SPRN_IAC1
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
+	mfspr	r7, SPRN_IAC2
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	mfspr	r8, SPRN_IAC3
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
+	mfspr	r7, SPRN_IAC4
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
+#endif
+	mfspr	r8, SPRN_DAC1
+	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
+	mfspr	r7, SPRN_DAC2
+	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
+	li	r8, 0
+	mtspr	SPRN_DBCR0, r8		/* disable all debug event */
+	lwz	r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR1(r4)
+	lwz	r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR2(r4)
+	lwz	r9, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR4(r4)
+	mtspr	SPRN_DBCR1, r7
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC1, r4)
+	PPC_LD(r3, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC2, r4)
+	mtspr	SPRN_DBCR2, r8
+	mtspr	SPRN_DBCR4, r9
+	mtspr	SPRN_IAC1, r7
+	mtspr	SPRN_IAC2, r3
+#if CONFIG_PPC_ADV_DEBUG_IACS > 2
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC3, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC4, r4)
+	mtspr	SPRN_IAC3, r7
+	mtspr	SPRN_IAC4, r8
+#endif
+	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC1, r4)
+	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC2, r4)
+	mtspr	SPRN_DAC1, r7
+	mtspr	SPRN_DAC2, r8
+skip_hw_bkpts:
+	/* Set EPCR.DUVD and guest DBCR0 */
+	mfspr	r7, SPRN_EPCR
+	oris	r7, r7, SPRN_EPCR_DUVD@h
+	mtspr	SPRN_EPCR, r7
+	isync
+	/* Clear if any deferred debug event */
+	mfspr	r8, SPRN_DBSR
+	mtspr	SPRN_DBSR, r8
+	isync
+	/* Restore guest DBCR */
+	mtspr	SPRN_DBCR0, r6
+	isync
+skip_load_guest_debug:
+
 	/* Load some guest volatiles. */
 	PPC_LL	r3, VCPU_LR(r4)
 	PPC_LL	r5, VCPU_XER(r4)
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
@ 2013-02-28  4:25   ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:25 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: Bharat Bhushan

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.bhushan@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;
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* [PATCH 7/7] KVM: PPC: Add userspace debug stub support
@ 2013-02-28  4:25   ` Bharat Bhushan
  0 siblings, 0 replies; 72+ messages in thread
From: Bharat Bhushan @ 2013-02-28  4:25 UTC (permalink / raw)
  To: kvm-ppc, kvm, agraf, scottwood; +Cc: 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.

Signed-off-by: Bharat Bhushan <bharat.bhushan@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_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_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);
+		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;
+
+	if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
+		run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
+	} else {
+		if (dbsr & (DBSR_DAC1W | DBSR_DAC2W))
+			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
+		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
+			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
+		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
+			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
+		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
+			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
+	}
+
+	return RESUME_HOST;
+}
+
 static void kvmppc_fill_pt_regs(struct pt_regs *regs)
 {
 	ulong r1, ip, msr, lr;
@@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	}
 
 	case BOOKE_INTERRUPT_DEBUG: {
-		u32 dbsr;
-
-		vcpu->arch.pc = mfspr(SPRN_CSRR0);
-
-		/* clear IAC events in DBSR register */
-		dbsr = mfspr(SPRN_DBSR);
-		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
-		mtspr(SPRN_DBSR, dbsr);
-
-		run->exit_reason = KVM_EXIT_DEBUG;
+		r = kvmppc_handle_debug(run, vcpu);
+		if (r = RESUME_HOST) {
+			run->exit_reason = KVM_EXIT_DEBUG;
+		}
 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
-		r = RESUME_HOST;
 		break;
 	}
 
@@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
 	kvmppc_set_msr(vcpu, 0);
 
 #ifndef CONFIG_KVM_BOOKE_HV
-	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
+	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
 	vcpu->arch.shadow_pid = 1;
 	vcpu->arch.shared->msr = 0;
 #endif
@@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
 	return r;
 }
 
+#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
+#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
+
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					 struct kvm_guest_debug *dbg)
 {
-	return -EINVAL;
+
+	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
+		/* Clear All debug events */
+		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
+		vcpu->guest_debug = 0;
+		return 0;
+	}
+
+	vcpu->guest_debug = dbg->control;
+	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
+	/* Set DBCR0_EDM in guest visible DBCR0 register. */
+	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
+
+	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
+		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
+
+	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
+		struct kvmppc_booke_debug_reg *gdbgr +				&(vcpu->arch.shadow_dbg_reg);
+		int n, b = 0, w = 0;
+		const u32 bp_code[] = {
+			DBCR0_IAC1 | DBCR0_IDM,
+			DBCR0_IAC2 | DBCR0_IDM,
+			DBCR0_IAC3 | DBCR0_IDM,
+			DBCR0_IAC4 | DBCR0_IDM
+		};
+		const u32 wp_code[] = {
+			DBCR0_DAC1W | DBCR0_IDM,
+			DBCR0_DAC2W | DBCR0_IDM,
+			DBCR0_DAC1R | DBCR0_IDM,
+			DBCR0_DAC2R | DBCR0_IDM
+		};
+
+#ifndef CONFIG_KVM_BOOKE_HV
+		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
+				DBCR1_IAC3US | DBCR1_IAC4US;
+		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
+#else
+		gdbgr->dbcr1 = 0;
+		gdbgr->dbcr2 = 0;
+#endif
+
+		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
+			u32 type = dbg->arch.bp[n].type;
+
+			if (!type)
+				break;
+
+			if (type & (KVMPPC_DEBUG_WATCH_READ |
+				    KVMPPC_DEBUG_WATCH_WRITE)) {
+				if (w < WP_NUM) {
+					if (type & KVMPPC_DEBUG_WATCH_READ)
+						gdbgr->dbcr0 |= wp_code[w + 2];
+					if (type & KVMPPC_DEBUG_WATCH_WRITE)
+						gdbgr->dbcr0 |= wp_code[w];
+					gdbgr->dac[w] = dbg->arch.bp[n].addr;
+					w++;
+				}
+			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
+				if (b < BP_NUM) {
+					gdbgr->dbcr0 |= bp_code[b];
+					gdbgr->iac[b] = dbg->arch.bp[n].addr;
+					b++;
+				}
+			}
+		}
+	}
+	return 0;
 }
 
 int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
index e78f353..83ac877 100644
--- a/arch/powerpc/kvm/e500_emulate.c
+++ b/arch/powerpc/kvm/e500_emulate.c
@@ -26,6 +26,7 @@
 #define XOP_TLBRE   946
 #define XOP_TLBWE   978
 #define XOP_TLBILX  18
+#define XOP_EHPRIV  270
 
 #ifdef CONFIG_KVM_E500MC
 static int dbell2prio(ulong param)
@@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
 			break;
 
+		case XOP_EHPRIV:
+			emulated = EMULATE_EXIT_USER;
+			*advance = 0;
+			break;
+
 		default:
 			emulated = EMULATE_FAIL;
 		}
diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
index 1f89d26..f5fc6f5 100644
--- a/arch/powerpc/kvm/e500mc.c
+++ b/arch/powerpc/kvm/e500mc.c
@@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
 {
 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
 
-	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
-				 SPRN_EPCR_DUVD;
+	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;
 #ifdef CONFIG_64BIT
 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM;
 #endif
-- 
1.7.0.4



^ permalink raw reply related	[flat|nested] 72+ messages in thread

* Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
  2013-02-28  4:25   ` Bharat Bhushan
@ 2013-02-28 16:23     ` Scott Wood
  -1 siblings, 0 replies; 72+ messages in thread
From: Scott Wood @ 2013-02-28 16:23 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, agraf, Bharat Bhushan

On 02/27/2013 10:13:11 PM, Bharat Bhushan wrote:
> 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;
> +	}

We're using ehpriv even for PR-mode KVM (e.g. e500v2)?

-Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
@ 2013-02-28 16:23     ` Scott Wood
  0 siblings, 0 replies; 72+ messages in thread
From: Scott Wood @ 2013-02-28 16:23 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, agraf, Bharat Bhushan

On 02/27/2013 10:13:11 PM, Bharat Bhushan wrote:
> 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;
> +	}

We're using ehpriv even for PR-mode KVM (e.g. e500v2)?

-Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
  2013-02-28  4:25   ` Bharat Bhushan
@ 2013-02-28 16:31     ` Scott Wood
  -1 siblings, 0 replies; 72+ messages in thread
From: Scott Wood @ 2013-02-28 16:31 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, agraf, Bharat Bhushan

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.bhushan@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 means more than  
just "return to user"; it indicates what sort of exit reason should be  
passed back.  What if book3s later wants to be able to return  
KVM_EXIT_DEBUG, or we want to have userspace-handled hcalls on booke?

-Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
@ 2013-02-28 16:31     ` Scott Wood
  0 siblings, 0 replies; 72+ messages in thread
From: Scott Wood @ 2013-02-28 16:31 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, agraf, Bharat Bhushan

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.bhushan@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 means more than  
just "return to user"; it indicates what sort of exit reason should be  
passed back.  What if book3s later wants to be able to return  
KVM_EXIT_DEBUG, or we want to have userspace-handled hcalls on booke?

-Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
  2013-02-28 16:31     ` Scott Wood
@ 2013-02-28 16:51       ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-02-28 16:51 UTC (permalink / raw)
  To: Scott Wood; +Cc: Bharat Bhushan, kvm-ppc, kvm, Bharat Bhushan


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.bhushan@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. The question is basically whether we want to have another layer of abstraction inside our own emulator / kvm interface. I don't have a strong feeling either way.


Alex

> It means more than just "return to user"; it indicates what sort of exit reason should be passed back.  What if book3s later wants to be able to return KVM_EXIT_DEBUG, or we want to have userspace-handled hcalls on booke?
> 
> -Scott
> --
> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
@ 2013-02-28 16:51       ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-02-28 16:51 UTC (permalink / raw)
  To: Scott Wood; +Cc: Bharat Bhushan, kvm-ppc, kvm, Bharat Bhushan


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.bhushan@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. The question is basically whether we want to have another layer of abstraction inside our own emulator / kvm interface. I don't have a strong feeling either way.


Alex

> It means more than just "return to user"; it indicates what sort of exit reason should be passed back.  What if book3s later wants to be able to return KVM_EXIT_DEBUG, or we want to have userspace-handled hcalls on booke?
> 
> -Scott
> --
> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
  2013-02-28 16:23     ` Scott Wood
@ 2013-02-28 16:52       ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-02-28 16:52 UTC (permalink / raw)
  To: Scott Wood; +Cc: Bharat Bhushan, kvm-ppc, kvm, Bharat Bhushan


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

> On 02/27/2013 10:13:11 PM, Bharat Bhushan wrote:
>> 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;
>> +	}
> 
> We're using ehpriv even for PR-mode KVM (e.g. e500v2)?

If it's a reserved instruction, that should work. Since we need to use a single instruction to replace the debugged one with, any reserved opcode should be as good as any other, right?


Alex

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
@ 2013-02-28 16:52       ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-02-28 16:52 UTC (permalink / raw)
  To: Scott Wood; +Cc: Bharat Bhushan, kvm-ppc, kvm, Bharat Bhushan


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

> On 02/27/2013 10:13:11 PM, Bharat Bhushan wrote:
>> 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;
>> +	}
> 
> We're using ehpriv even for PR-mode KVM (e.g. e500v2)?

If it's a reserved instruction, that should work. Since we need to use a single instruction to replace the debugged one with, any reserved opcode should be as good as any other, right?


Alex


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
  2013-02-28 16:51       ` Alexander Graf
@ 2013-02-28 16:53         ` Scott Wood
  -1 siblings, 0 replies; 72+ messages in thread
From: Scott Wood @ 2013-02-28 16:53 UTC (permalink / raw)
  To: Alexander Graf; +Cc: Bharat Bhushan, kvm-ppc, kvm, Bharat Bhushan

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.bhushan@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.

-Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
@ 2013-02-28 16:53         ` Scott Wood
  0 siblings, 0 replies; 72+ messages in thread
From: Scott Wood @ 2013-02-28 16:53 UTC (permalink / raw)
  To: Alexander Graf; +Cc: Bharat Bhushan, kvm-ppc, kvm, Bharat Bhushan

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.bhushan@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.

-Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 2/7] Added ONE_REG interface for debug instruction
  2013-02-28 16:52       ` Alexander Graf
@ 2013-03-01  5:28         ` Bhushan Bharat-R65777
  -1 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-01  5:28 UTC (permalink / raw)
  To: Alexander Graf, Wood Scott-B07421; +Cc: kvm-ppc, kvm



> -----Original Message-----
> From: kvm-ppc-owner@vger.kernel.org [mailto:kvm-ppc-
> owner@vger.kernel.org] On Behalf Of Alexander Graf
> Sent: Thursday, February 28, 2013 10:22 PM
> To: Wood Scott-B07421
> Cc: Bhushan Bharat-R65777; kvm-ppc@vger.kernel.org; kvm@vger.kernel.org;
> Bhushan Bharat-R65777
> Subject: Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
> 
> 
> On 28.02.2013, at 17:23, Scott Wood wrote:
> 
> > On 02/27/2013 10:13:11 PM, Bharat Bhushan wrote:
> >> 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;
> >> +	}
> >
> > We're using ehpriv even for PR-mode KVM (e.g. e500v2)?
> 
> If it's a reserved instruction, that should work. Since we need to use a
> single instruction to replace the debugged one with, any reserved opcode
> should be as good as any other, right?

Right, that has been the idea here.

Thanks
-Bharat

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

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 2/7] Added ONE_REG interface for debug instruction
@ 2013-03-01  5:28         ` Bhushan Bharat-R65777
  0 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-01  5:28 UTC (permalink / raw)
  To: Alexander Graf, Wood Scott-B07421; +Cc: kvm-ppc, kvm



> -----Original Message-----
> From: kvm-ppc-owner@vger.kernel.org [mailto:kvm-ppc-
> owner@vger.kernel.org] On Behalf Of Alexander Graf
> Sent: Thursday, February 28, 2013 10:22 PM
> To: Wood Scott-B07421
> Cc: Bhushan Bharat-R65777; kvm-ppc@vger.kernel.org; kvm@vger.kernel.org;
> Bhushan Bharat-R65777
> Subject: Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
> 
> 
> On 28.02.2013, at 17:23, Scott Wood wrote:
> 
> > On 02/27/2013 10:13:11 PM, Bharat Bhushan wrote:
> >> 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;
> >> +	}
> >
> > We're using ehpriv even for PR-mode KVM (e.g. e500v2)?
> 
> If it's a reserved instruction, that should work. Since we need to use a
> single instruction to replace the debugged one with, any reserved opcode
> should be as good as any other, right?

Right, that has been the idea here.

Thanks
-Bharat

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



^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
  2013-02-28 16:53         ` Scott Wood
@ 2013-03-07 10:47           ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 10:47 UTC (permalink / raw)
  To: Scott Wood; +Cc: Bharat Bhushan, kvm-ppc, kvm, Bharat Bhushan


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.bhushan@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

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
@ 2013-03-07 10:47           ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 10:47 UTC (permalink / raw)
  To: Scott Wood; +Cc: Bharat Bhushan, kvm-ppc, kvm, Bharat Bhushan


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.bhushan@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


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
  2013-02-28  4:25   ` Bharat Bhushan
@ 2013-03-07 13:07     ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 13:07 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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.bhushan@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				0x7c000008

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_LPIDS                        64
> 
> +#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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
@ 2013-03-07 13:07     ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 13:07 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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.bhushan@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				0x7c000008

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_LPIDS                        64
> 
> +#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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-02-28  4:25   ` Bharat Bhushan
@ 2013-03-07 13:20     ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 13:20 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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.bhushan@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		0x00010000
> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000

You only need

#define KVM_GUESTDBG_HW_BP 0x00010000

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
> 
> 

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-03-07 13:20     ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 13:20 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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.bhushan@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		0x00010000
> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000

You only need

#define KVM_GUESTDBG_HW_BP 0x00010000

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
> 
> 


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
  2013-02-28  4:25   ` Bharat Bhushan
@ 2013-03-07 13:25     ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 13:25 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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.bhushan@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 ((1<<BOOKE_INTERRUPT_PROGRAM) | \
>                         (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
> @@ -54,6 +56,8 @@
>                        (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
>                        (1<<BOOKE_INTERRUPT_ALIGNMENT))
> 
> +#define NEED_DEBUG_SAVE (1<<BOOKE_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, DBCR0_AC_BITS@h
> +	li	r9, 0
> +	mtspr	SPRN_DBCR0, r9		/* disable all debug event */
> +	beq	skip_load_hw_bkpts
> +	lwz	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
> +	lwz	r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
> +	mtspr	SPRN_DBCR1, r7
> +	mtspr	SPRN_DBCR2, r9
> +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
> +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
> +	mtspr	SPRN_IAC1, r7
> +	mtspr	SPRN_IAC2, r9
> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
> +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
> +	mtspr	SPRN_IAC3, r3
> +	mtspr	SPRN_IAC4, r4
> +#endif
> +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
> +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
> +	mtspr	SPRN_DAC1, r7
> +	mtspr	SPRN_DAC2, r9
> +skip_load_hw_bkpts:
> +	/* Clear h/w DBSR and save current(guest) DBSR */
> +	mfspr	r9, SPRN_DBSR
> +	mtspr	SPRN_DBSR, r9
> +	isync
> +	andi.	r7, r6, NEED_DEBUG_SAVE
> +	beq	skip_dbsr_save
> +	/*
> +	 * If vcpu->guest_debug flag is set then do not check for
> +	 * shared->msr.DE as this debugging (say by QEMU) does not
> +	 * depends on shared->msr.de. In these scanerios MSR.DE is
> +	 * always set using shared_msr and should be handled always.
> +	 */
> +	lwz	r7, VCPU_GUEST_DEBUG(r4)
> +	cmpwi	r7, 0
> +	bne	skip_save_trap_event
> +	PPC_LL	r3, VCPU_SHARED(r4)
> +	PPC_LD(r3, VCPU_SHARED_MSR, r3)
> +	andi.	r3, r3, MSR_DE
> +	bne	skip_save_trap_event
> +	andis.	r9, r9, DBSR_TIE@h
> +skip_save_trap_event:
> +	stw	r9, VCPU_DBSR(r4)
> +skip_dbsr_save:
> +	mtspr	SPRN_DBCR0, r8
> +skip_load_host_debug:
> +
> 	/* Save remaining volatile guest register state to vcpu. */
> 	stw	r0, VCPU_GPR(R0)(r4)
> 	stw	r1, VCPU_GPR(R1)(r4)
> @@ -468,6 +525,63 @@ lightweight_exit:
> 	PPC_LD(r3, VCPU_SHARED_SPRG7, r5)
> 	mtspr	SPRN_SPRG7W, r3
> 
> +	mfmsr	r7
> +	rlwinm	r7, r7, 0, ~MSR_DE
> +	mtmsr	r7
> +	lwz	r6, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
> +	rlwinm.	r7, r6, 0, ~DBCR0_IDM
> +	beq	skip_load_guest_debug
> +	mfspr	r8, SPRN_DBCR0
> +	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
> +	andis.	r3, r6, DBCR0_AC_BITS@h
> +	beq	skip_hw_bkpts
> +	mfspr	r7, SPRN_DBCR1
> +	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
> +	mfspr	r8, SPRN_DBCR2
> +	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
> +	mfspr	r7, SPRN_IAC1
> +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
> +	mfspr	r8, SPRN_IAC2
> +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> +	mfspr	r7, SPRN_IAC3
> +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
> +	mfspr	r8, SPRN_IAC4
> +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
> +#endif
> +	mfspr	r7, SPRN_DAC1
> +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
> +	mfspr	r8, SPRN_DAC2
> +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
> +	li	r8, 0
> +	mtspr	SPRN_DBCR0, r8		/* disable all debug event */
> +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR1, r4)
> +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR2, r4)
> +	mtspr	SPRN_DBCR1, r7
> +	mtspr	SPRN_DBCR2, r8
> +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC1, r4)
> +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC2, r4)
> +	mtspr	SPRN_IAC1, r7
> +	mtspr	SPRN_IAC2, r8
> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC3, r4)
> +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC4, r4)
> +	mtspr	SPRN_IAC3, r7
> +	mtspr	SPRN_IAC4, r8
> +#endif
> +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC1, r4)
> +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC2, r4)
> +	mtspr	SPRN_DAC1, r7
> +	mtspr	SPRN_DAC2, r8
> +skip_hw_bkpts:
> +	/* Clear if any deferred debug event */
> +	mfspr	r8, SPRN_DBSR
> +	mtspr	SPRN_DBSR, r8
> +	isync
> +	/* Restore guest DBCR */
> +	mtspr	SPRN_DBCR0, r6
> +skip_load_guest_debug:
> +
> #ifdef CONFIG_KVM_EXIT_TIMING
> 	/* save enter time */
> 1:
> -- 
> 1.7.0.4
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
@ 2013-03-07 13:25     ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 13:25 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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.bhushan@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 ((1<<BOOKE_INTERRUPT_PROGRAM) | \
>                         (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
> @@ -54,6 +56,8 @@
>                        (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
>                        (1<<BOOKE_INTERRUPT_ALIGNMENT))
> 
> +#define NEED_DEBUG_SAVE (1<<BOOKE_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, DBCR0_AC_BITS@h
> +	li	r9, 0
> +	mtspr	SPRN_DBCR0, r9		/* disable all debug event */
> +	beq	skip_load_hw_bkpts
> +	lwz	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
> +	lwz	r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
> +	mtspr	SPRN_DBCR1, r7
> +	mtspr	SPRN_DBCR2, r9
> +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
> +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
> +	mtspr	SPRN_IAC1, r7
> +	mtspr	SPRN_IAC2, r9
> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
> +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
> +	mtspr	SPRN_IAC3, r3
> +	mtspr	SPRN_IAC4, r4
> +#endif
> +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
> +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
> +	mtspr	SPRN_DAC1, r7
> +	mtspr	SPRN_DAC2, r9
> +skip_load_hw_bkpts:
> +	/* Clear h/w DBSR and save current(guest) DBSR */
> +	mfspr	r9, SPRN_DBSR
> +	mtspr	SPRN_DBSR, r9
> +	isync
> +	andi.	r7, r6, NEED_DEBUG_SAVE
> +	beq	skip_dbsr_save
> +	/*
> +	 * If vcpu->guest_debug flag is set then do not check for
> +	 * shared->msr.DE as this debugging (say by QEMU) does not
> +	 * depends on shared->msr.de. In these scanerios MSR.DE is
> +	 * always set using shared_msr and should be handled always.
> +	 */
> +	lwz	r7, VCPU_GUEST_DEBUG(r4)
> +	cmpwi	r7, 0
> +	bne	skip_save_trap_event
> +	PPC_LL	r3, VCPU_SHARED(r4)
> +	PPC_LD(r3, VCPU_SHARED_MSR, r3)
> +	andi.	r3, r3, MSR_DE
> +	bne	skip_save_trap_event
> +	andis.	r9, r9, DBSR_TIE@h
> +skip_save_trap_event:
> +	stw	r9, VCPU_DBSR(r4)
> +skip_dbsr_save:
> +	mtspr	SPRN_DBCR0, r8
> +skip_load_host_debug:
> +
> 	/* Save remaining volatile guest register state to vcpu. */
> 	stw	r0, VCPU_GPR(R0)(r4)
> 	stw	r1, VCPU_GPR(R1)(r4)
> @@ -468,6 +525,63 @@ lightweight_exit:
> 	PPC_LD(r3, VCPU_SHARED_SPRG7, r5)
> 	mtspr	SPRN_SPRG7W, r3
> 
> +	mfmsr	r7
> +	rlwinm	r7, r7, 0, ~MSR_DE
> +	mtmsr	r7
> +	lwz	r6, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
> +	rlwinm.	r7, r6, 0, ~DBCR0_IDM
> +	beq	skip_load_guest_debug
> +	mfspr	r8, SPRN_DBCR0
> +	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
> +	andis.	r3, r6, DBCR0_AC_BITS@h
> +	beq	skip_hw_bkpts
> +	mfspr	r7, SPRN_DBCR1
> +	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
> +	mfspr	r8, SPRN_DBCR2
> +	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
> +	mfspr	r7, SPRN_IAC1
> +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
> +	mfspr	r8, SPRN_IAC2
> +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> +	mfspr	r7, SPRN_IAC3
> +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
> +	mfspr	r8, SPRN_IAC4
> +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
> +#endif
> +	mfspr	r7, SPRN_DAC1
> +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
> +	mfspr	r8, SPRN_DAC2
> +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
> +	li	r8, 0
> +	mtspr	SPRN_DBCR0, r8		/* disable all debug event */
> +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR1, r4)
> +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR2, r4)
> +	mtspr	SPRN_DBCR1, r7
> +	mtspr	SPRN_DBCR2, r8
> +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC1, r4)
> +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC2, r4)
> +	mtspr	SPRN_IAC1, r7
> +	mtspr	SPRN_IAC2, r8
> +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC3, r4)
> +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC4, r4)
> +	mtspr	SPRN_IAC3, r7
> +	mtspr	SPRN_IAC4, r8
> +#endif
> +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC1, r4)
> +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC2, r4)
> +	mtspr	SPRN_DAC1, r7
> +	mtspr	SPRN_DAC2, r8
> +skip_hw_bkpts:
> +	/* Clear if any deferred debug event */
> +	mfspr	r8, SPRN_DBSR
> +	mtspr	SPRN_DBSR, r8
> +	isync
> +	/* Restore guest DBCR */
> +	mtspr	SPRN_DBCR0, r6
> +skip_load_guest_debug:
> +
> #ifdef CONFIG_KVM_EXIT_TIMING
> 	/* save enter time */
> 1:
> -- 
> 1.7.0.4
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
  2013-02-28  4:25   ` Bharat Bhushan
@ 2013-03-07 13:39     ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 13:39 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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.bhushan@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_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_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))
> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
> +		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
> +		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
> +		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
> +	}
> +
> +	return RESUME_HOST;
> +}
> +
> static void kvmppc_fill_pt_regs(struct pt_regs *regs)
> {
> 	ulong r1, ip, msr, lr;
> @@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
> 	}
> 
> 	case BOOKE_INTERRUPT_DEBUG: {
> -		u32 dbsr;
> -
> -		vcpu->arch.pc = mfspr(SPRN_CSRR0);
> -
> -		/* clear IAC events in DBSR register */
> -		dbsr = mfspr(SPRN_DBSR);
> -		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
> -		mtspr(SPRN_DBSR, dbsr);
> -
> -		run->exit_reason = KVM_EXIT_DEBUG;
> +		r = kvmppc_handle_debug(run, vcpu);
> +		if (r == RESUME_HOST) {
> +			run->exit_reason = KVM_EXIT_DEBUG;
> +		}
> 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
> -		r = RESUME_HOST;
> 		break;
> 	}
> 
> @@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
> 	kvmppc_set_msr(vcpu, 0);
> 
> #ifndef CONFIG_KVM_BOOKE_HV
> -	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
> +	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
> 	vcpu->arch.shadow_pid = 1;
> 	vcpu->arch.shared->msr = 0;
> #endif
> @@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
> 	return r;
> }
> 
> +#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
> +#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
> +
> int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
> 					 struct kvm_guest_debug *dbg)
> {
> -	return -EINVAL;
> +
> +	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
> +		/* Clear All debug events */
> +		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> +		vcpu->guest_debug = 0;
> +		return 0;
> +	}
> +
> +	vcpu->guest_debug = dbg->control;
> +	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> +	/* Set DBCR0_EDM in guest visible DBCR0 register. */
> +	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
> +
> +	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
> +		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
> +
> +	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {

if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
    /* Code below handles only HW breakpoints */
    return 0;
}

> +		struct kvmppc_booke_debug_reg *gdbgr =
> +				&(vcpu->arch.shadow_dbg_reg);
> +		int n, b = 0, w = 0;
> +		const u32 bp_code[] = {
> +			DBCR0_IAC1 | DBCR0_IDM,
> +			DBCR0_IAC2 | DBCR0_IDM,
> +			DBCR0_IAC3 | DBCR0_IDM,
> +			DBCR0_IAC4 | DBCR0_IDM
> +		};
> +		const u32 wp_code[] = {
> +			DBCR0_DAC1W | DBCR0_IDM,
> +			DBCR0_DAC2W | DBCR0_IDM,
> +			DBCR0_DAC1R | DBCR0_IDM,
> +			DBCR0_DAC2R | DBCR0_IDM
> +		};
> +
> +#ifndef CONFIG_KVM_BOOKE_HV

Please no double negation. Also, what is this about?

> +		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> +				DBCR1_IAC3US | DBCR1_IAC4US;
> +		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
> +#else
> +		gdbgr->dbcr1 = 0;
> +		gdbgr->dbcr2 = 0;
> +#endif
> +
> +		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
> +			u32 type = dbg->arch.bp[n].type;
> +
> +			if (!type)
> +				break;
> +
> +			if (type & (KVMPPC_DEBUG_WATCH_READ |
> +				    KVMPPC_DEBUG_WATCH_WRITE)) {
> +				if (w < WP_NUM) {
> +					if (type & KVMPPC_DEBUG_WATCH_READ)
> +						gdbgr->dbcr0 |= wp_code[w + 2];
> +					if (type & KVMPPC_DEBUG_WATCH_WRITE)
> +						gdbgr->dbcr0 |= wp_code[w];
> +					gdbgr->dac[w] = dbg->arch.bp[n].addr;
> +					w++;
> +				}
> +			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
> +				if (b < BP_NUM) {
> +					gdbgr->dbcr0 |= bp_code[b];
> +					gdbgr->iac[b] = dbg->arch.bp[n].addr;
> +					b++;
> +				}
> +			}
> +		}
> +	}
> +	return 0;
> }
> 
> int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
> diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
> index e78f353..83ac877 100644
> --- a/arch/powerpc/kvm/e500_emulate.c
> +++ b/arch/powerpc/kvm/e500_emulate.c
> @@ -26,6 +26,7 @@
> #define XOP_TLBRE   946
> #define XOP_TLBWE   978
> #define XOP_TLBILX  18
> +#define XOP_EHPRIV  270
> 
> #ifdef CONFIG_KVM_E500MC
> static int dbell2prio(ulong param)
> @@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
> 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
> 			break;
> 
> +		case XOP_EHPRIV:
> +			emulated = EMULATE_EXIT_USER;
> +			*advance = 0;
> +			break;
> +
> 		default:
> 			emulated = EMULATE_FAIL;
> 		}
> diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
> index 1f89d26..f5fc6f5 100644
> --- a/arch/powerpc/kvm/e500mc.c
> +++ b/arch/powerpc/kvm/e500mc.c
> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
> {
> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> 
> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
> -				 SPRN_EPCR_DUVD;
> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;

Doesn't this route all debug events through the host?


Alex

> #ifdef CONFIG_64BIT
> 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM;
> #endif
> -- 
> 1.7.0.4
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
@ 2013-03-07 13:39     ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 13:39 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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.bhushan@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_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_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))
> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
> +		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
> +		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
> +		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
> +	}
> +
> +	return RESUME_HOST;
> +}
> +
> static void kvmppc_fill_pt_regs(struct pt_regs *regs)
> {
> 	ulong r1, ip, msr, lr;
> @@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
> 	}
> 
> 	case BOOKE_INTERRUPT_DEBUG: {
> -		u32 dbsr;
> -
> -		vcpu->arch.pc = mfspr(SPRN_CSRR0);
> -
> -		/* clear IAC events in DBSR register */
> -		dbsr = mfspr(SPRN_DBSR);
> -		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
> -		mtspr(SPRN_DBSR, dbsr);
> -
> -		run->exit_reason = KVM_EXIT_DEBUG;
> +		r = kvmppc_handle_debug(run, vcpu);
> +		if (r = RESUME_HOST) {
> +			run->exit_reason = KVM_EXIT_DEBUG;
> +		}
> 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
> -		r = RESUME_HOST;
> 		break;
> 	}
> 
> @@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
> 	kvmppc_set_msr(vcpu, 0);
> 
> #ifndef CONFIG_KVM_BOOKE_HV
> -	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
> +	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
> 	vcpu->arch.shadow_pid = 1;
> 	vcpu->arch.shared->msr = 0;
> #endif
> @@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu, struct kvm_one_reg *reg)
> 	return r;
> }
> 
> +#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
> +#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
> +
> int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
> 					 struct kvm_guest_debug *dbg)
> {
> -	return -EINVAL;
> +
> +	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
> +		/* Clear All debug events */
> +		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> +		vcpu->guest_debug = 0;
> +		return 0;
> +	}
> +
> +	vcpu->guest_debug = dbg->control;
> +	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> +	/* Set DBCR0_EDM in guest visible DBCR0 register. */
> +	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
> +
> +	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
> +		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
> +
> +	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {

if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
    /* Code below handles only HW breakpoints */
    return 0;
}

> +		struct kvmppc_booke_debug_reg *gdbgr > +				&(vcpu->arch.shadow_dbg_reg);
> +		int n, b = 0, w = 0;
> +		const u32 bp_code[] = {
> +			DBCR0_IAC1 | DBCR0_IDM,
> +			DBCR0_IAC2 | DBCR0_IDM,
> +			DBCR0_IAC3 | DBCR0_IDM,
> +			DBCR0_IAC4 | DBCR0_IDM
> +		};
> +		const u32 wp_code[] = {
> +			DBCR0_DAC1W | DBCR0_IDM,
> +			DBCR0_DAC2W | DBCR0_IDM,
> +			DBCR0_DAC1R | DBCR0_IDM,
> +			DBCR0_DAC2R | DBCR0_IDM
> +		};
> +
> +#ifndef CONFIG_KVM_BOOKE_HV

Please no double negation. Also, what is this about?

> +		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> +				DBCR1_IAC3US | DBCR1_IAC4US;
> +		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
> +#else
> +		gdbgr->dbcr1 = 0;
> +		gdbgr->dbcr2 = 0;
> +#endif
> +
> +		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
> +			u32 type = dbg->arch.bp[n].type;
> +
> +			if (!type)
> +				break;
> +
> +			if (type & (KVMPPC_DEBUG_WATCH_READ |
> +				    KVMPPC_DEBUG_WATCH_WRITE)) {
> +				if (w < WP_NUM) {
> +					if (type & KVMPPC_DEBUG_WATCH_READ)
> +						gdbgr->dbcr0 |= wp_code[w + 2];
> +					if (type & KVMPPC_DEBUG_WATCH_WRITE)
> +						gdbgr->dbcr0 |= wp_code[w];
> +					gdbgr->dac[w] = dbg->arch.bp[n].addr;
> +					w++;
> +				}
> +			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
> +				if (b < BP_NUM) {
> +					gdbgr->dbcr0 |= bp_code[b];
> +					gdbgr->iac[b] = dbg->arch.bp[n].addr;
> +					b++;
> +				}
> +			}
> +		}
> +	}
> +	return 0;
> }
> 
> int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu *fpu)
> diff --git a/arch/powerpc/kvm/e500_emulate.c b/arch/powerpc/kvm/e500_emulate.c
> index e78f353..83ac877 100644
> --- a/arch/powerpc/kvm/e500_emulate.c
> +++ b/arch/powerpc/kvm/e500_emulate.c
> @@ -26,6 +26,7 @@
> #define XOP_TLBRE   946
> #define XOP_TLBWE   978
> #define XOP_TLBILX  18
> +#define XOP_EHPRIV  270
> 
> #ifdef CONFIG_KVM_E500MC
> static int dbell2prio(ulong param)
> @@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct kvm_vcpu *vcpu,
> 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
> 			break;
> 
> +		case XOP_EHPRIV:
> +			emulated = EMULATE_EXIT_USER;
> +			*advance = 0;
> +			break;
> +
> 		default:
> 			emulated = EMULATE_FAIL;
> 		}
> diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
> index 1f89d26..f5fc6f5 100644
> --- a/arch/powerpc/kvm/e500mc.c
> +++ b/arch/powerpc/kvm/e500mc.c
> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
> {
> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> 
> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
> -				 SPRN_EPCR_DUVD;
> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;

Doesn't this route all debug events through the host?


Alex

> #ifdef CONFIG_64BIT
> 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM;
> #endif
> -- 
> 1.7.0.4
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 1/7] KVM: PPC: booke: Added debug handler
  2013-02-28  4:25   ` Bharat Bhushan
@ 2013-03-07 14:02     ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 14:02 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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

> 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 <yu.liu@freescale.com>
> [bharat.bhushan@freescale.com: Substantial changes]
> Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>

Thanks, applied to kvm-ppc-queue.


Alex

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 1/7] KVM: PPC: booke: Added debug handler
@ 2013-03-07 14:02     ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-07 14:02 UTC (permalink / raw)
  To: Bharat Bhushan; +Cc: kvm-ppc, kvm, scottwood, Bharat Bhushan


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

> 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 <yu.liu@freescale.com>
> [bharat.bhushan@freescale.com: Substantial changes]
> Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>

Thanks, applied to kvm-ppc-queue.


Alex


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 2/7] Added ONE_REG interface for debug instruction
  2013-03-07 13:07     ` Alexander Graf
  (?)
@ 2013-03-14  4:30     ` Bhushan Bharat-R65777
  2013-03-14 11:56         ` Alexander Graf
  -1 siblings, 1 reply; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14  4:30 UTC (permalink / raw)
  To: Alexander Graf; +Cc: kvm-ppc, kvm, Wood Scott-B07421



> -----Original Message-----
> From: Alexander Graf [mailto:agraf@suse.de]
> Sent: Thursday, March 07, 2013 6:38 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
> Bharat-R65777
> Subject: Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
> 
> 
> 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.bhushan@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				0x7c000008
> 
> 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.

Yes I missed this.
BTW rather than setting TO = 31, what if we set TO = 2 as RA and RB is same here.

-Bharat

> 
> 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_LPIDS                        64
> >
> > +#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 majordomo@vger.kernel.org More majordomo info
> > at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-03-07 13:20     ` Alexander Graf
  (?)
@ 2013-03-14  4:42     ` Bhushan Bharat-R65777
  2013-03-14 11:54         ` Alexander Graf
  -1 siblings, 1 reply; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14  4:42 UTC (permalink / raw)
  To: Alexander Graf; +Cc: kvm-ppc, kvm, Wood Scott-B07421



> -----Original Message-----
> From: Alexander Graf [mailto:agraf@suse.de]
> Sent: Thursday, March 07, 2013 6:51 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
> Bharat-R65777
> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
> 
> 
> 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.bhushan@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		0x00010000
> > +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
> 
> You only need
> 
> #define KVM_GUESTDBG_HW_BP 0x00010000
> 
> In absence of the flag, it's a SW breakpoint.

We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.

If you want than I can code this as you described.

-Bharat

> 
> 
> 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
> >
> >
> 



^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
  2013-03-07 13:25     ` Alexander Graf
  (?)
@ 2013-03-14  4:50     ` Bhushan Bharat-R65777
  2013-03-14 11:52         ` Alexander Graf
  -1 siblings, 1 reply; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14  4:50 UTC (permalink / raw)
  To: Alexander Graf; +Cc: kvm-ppc, kvm, Wood Scott-B07421



> -----Original Message-----
> From: Alexander Graf [mailto:agraf@suse.de]
> Sent: Thursday, March 07, 2013 6:56 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
> Bharat-R65777
> Subject: Re: [PATCH 4/7] booke: Save and restore debug registers on guest entry
> and exit
> 
> 
> 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?


One of the reason for not doing this is that the KVM is a host kernel module and let this be debugged by host (I do not this how much useful this is :)) 
So I am not able to recall the specific reason, maybe we have just coded this like this and tried to keep overhead as low as possible by switching registers only when they are used.

As we discussed before, we can keep this option open for future.

-Bharat

> 
> 
> 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.bhushan@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 ((1<<BOOKE_INTERRUPT_PROGRAM) | \
> >                         (1<<BOOKE_INTERRUPT_DTLB_MISS) | \ @@ -54,6
> > +56,8 @@
> >                        (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
> >                        (1<<BOOKE_INTERRUPT_ALIGNMENT))
> >
> > +#define NEED_DEBUG_SAVE (1<<BOOKE_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, DBCR0_AC_BITS@h
> > +	li	r9, 0
> > +	mtspr	SPRN_DBCR0, r9		/* disable all debug event */
> > +	beq	skip_load_hw_bkpts
> > +	lwz	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
> > +	lwz	r9, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
> > +	mtspr	SPRN_DBCR1, r7
> > +	mtspr	SPRN_DBCR2, r9
> > +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
> > +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4)
> > +	mtspr	SPRN_IAC1, r7
> > +	mtspr	SPRN_IAC2, r9
> > +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> > +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
> > +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4)
> > +	mtspr	SPRN_IAC3, r3
> > +	mtspr	SPRN_IAC4, r4
> > +#endif
> > +	PPC_LD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
> > +	PPC_LD(r9, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
> > +	mtspr	SPRN_DAC1, r7
> > +	mtspr	SPRN_DAC2, r9
> > +skip_load_hw_bkpts:
> > +	/* Clear h/w DBSR and save current(guest) DBSR */
> > +	mfspr	r9, SPRN_DBSR
> > +	mtspr	SPRN_DBSR, r9
> > +	isync
> > +	andi.	r7, r6, NEED_DEBUG_SAVE
> > +	beq	skip_dbsr_save
> > +	/*
> > +	 * If vcpu->guest_debug flag is set then do not check for
> > +	 * shared->msr.DE as this debugging (say by QEMU) does not
> > +	 * depends on shared->msr.de. In these scanerios MSR.DE is
> > +	 * always set using shared_msr and should be handled always.
> > +	 */
> > +	lwz	r7, VCPU_GUEST_DEBUG(r4)
> > +	cmpwi	r7, 0
> > +	bne	skip_save_trap_event
> > +	PPC_LL	r3, VCPU_SHARED(r4)
> > +	PPC_LD(r3, VCPU_SHARED_MSR, r3)
> > +	andi.	r3, r3, MSR_DE
> > +	bne	skip_save_trap_event
> > +	andis.	r9, r9, DBSR_TIE@h
> > +skip_save_trap_event:
> > +	stw	r9, VCPU_DBSR(r4)
> > +skip_dbsr_save:
> > +	mtspr	SPRN_DBCR0, r8
> > +skip_load_host_debug:
> > +
> > 	/* Save remaining volatile guest register state to vcpu. */
> > 	stw	r0, VCPU_GPR(R0)(r4)
> > 	stw	r1, VCPU_GPR(R1)(r4)
> > @@ -468,6 +525,63 @@ lightweight_exit:
> > 	PPC_LD(r3, VCPU_SHARED_SPRG7, r5)
> > 	mtspr	SPRN_SPRG7W, r3
> >
> > +	mfmsr	r7
> > +	rlwinm	r7, r7, 0, ~MSR_DE
> > +	mtmsr	r7
> > +	lwz	r6, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR0(r4)
> > +	rlwinm.	r7, r6, 0, ~DBCR0_IDM
> > +	beq	skip_load_guest_debug
> > +	mfspr	r8, SPRN_DBCR0
> > +	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR0(r4)
> > +	andis.	r3, r6, DBCR0_AC_BITS@h
> > +	beq	skip_hw_bkpts
> > +	mfspr	r7, SPRN_DBCR1
> > +	stw	r7, VCPU_HOST_DBG+KVMPPC_DBG_DBCR1(r4)
> > +	mfspr	r8, SPRN_DBCR2
> > +	stw	r8, VCPU_HOST_DBG+KVMPPC_DBG_DBCR2(r4)
> > +	mfspr	r7, SPRN_IAC1
> > +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC1, r4)
> > +	mfspr	r8, SPRN_IAC2
> > +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC2, r4) #if
> > +CONFIG_PPC_ADV_DEBUG_IACS > 2
> > +	mfspr	r7, SPRN_IAC3
> > +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_IAC3, r4)
> > +	mfspr	r8, SPRN_IAC4
> > +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_IAC4, r4) #endif
> > +	mfspr	r7, SPRN_DAC1
> > +	PPC_STD(r7, VCPU_HOST_DBG+KVMPPC_DBG_DAC1, r4)
> > +	mfspr	r8, SPRN_DAC2
> > +	PPC_STD(r8, VCPU_HOST_DBG+KVMPPC_DBG_DAC2, r4)
> > +	li	r8, 0
> > +	mtspr	SPRN_DBCR0, r8		/* disable all debug event */
> > +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR1, r4)
> > +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DBCR2, r4)
> > +	mtspr	SPRN_DBCR1, r7
> > +	mtspr	SPRN_DBCR2, r8
> > +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC1, r4)
> > +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC2, r4)
> > +	mtspr	SPRN_IAC1, r7
> > +	mtspr	SPRN_IAC2, r8
> > +#if CONFIG_PPC_ADV_DEBUG_IACS > 2
> > +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC3, r4)
> > +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_IAC4, r4)
> > +	mtspr	SPRN_IAC3, r7
> > +	mtspr	SPRN_IAC4, r8
> > +#endif
> > +	PPC_LD(r7, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC1, r4)
> > +	PPC_LD(r8, VCPU_SHADOW_DBG+KVMPPC_DBG_DAC2, r4)
> > +	mtspr	SPRN_DAC1, r7
> > +	mtspr	SPRN_DAC2, r8
> > +skip_hw_bkpts:
> > +	/* Clear if any deferred debug event */
> > +	mfspr	r8, SPRN_DBSR
> > +	mtspr	SPRN_DBSR, r8
> > +	isync
> > +	/* Restore guest DBCR */
> > +	mtspr	SPRN_DBCR0, r6
> > +skip_load_guest_debug:
> > +
> > #ifdef CONFIG_KVM_EXIT_TIMING
> > 	/* save enter time */
> > 1:
> > --
> > 1.7.0.4
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> > the body of a message to majordomo@vger.kernel.org More majordomo info
> > at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
  2013-03-07 13:39     ` Alexander Graf
@ 2013-03-14  5:18       ` Bhushan Bharat-R65777
  -1 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14  5:18 UTC (permalink / raw)
  To: Alexander Graf; +Cc: kvm-ppc, kvm, Wood Scott-B07421



> -----Original Message-----
> From: Alexander Graf [mailto:agraf@suse.de]
> Sent: Thursday, March 07, 2013 7:09 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
> Bharat-R65777
> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
> 
> 
> 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.bhushan@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_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_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.

ok

> 
> > +		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.

Can there be the case when do breakpoint and debug interrupt happen?

> 
> > +
> > +	if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
> > +		run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
> > +	} else {
> > +		if (dbsr & (DBSR_DAC1W | DBSR_DAC2W))
> > +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
> > +		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
> > +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
> > +		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
> > +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
> > +		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
> > +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
> > +	}
> > +
> > +	return RESUME_HOST;
> > +}
> > +
> > static void kvmppc_fill_pt_regs(struct pt_regs *regs) {
> > 	ulong r1, ip, msr, lr;
> > @@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct
> kvm_vcpu *vcpu,
> > 	}
> >
> > 	case BOOKE_INTERRUPT_DEBUG: {
> > -		u32 dbsr;
> > -
> > -		vcpu->arch.pc = mfspr(SPRN_CSRR0);
> > -
> > -		/* clear IAC events in DBSR register */
> > -		dbsr = mfspr(SPRN_DBSR);
> > -		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
> > -		mtspr(SPRN_DBSR, dbsr);
> > -
> > -		run->exit_reason = KVM_EXIT_DEBUG;
> > +		r = kvmppc_handle_debug(run, vcpu);
> > +		if (r == RESUME_HOST) {
> > +			run->exit_reason = KVM_EXIT_DEBUG;
> > +		}
> > 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
> > -		r = RESUME_HOST;
> > 		break;
> > 	}
> >
> > @@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
> > 	kvmppc_set_msr(vcpu, 0);
> >
> > #ifndef CONFIG_KVM_BOOKE_HV
> > -	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
> > +	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
> > 	vcpu->arch.shadow_pid = 1;
> > 	vcpu->arch.shared->msr = 0;
> > #endif
> > @@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
> struct kvm_one_reg *reg)
> > 	return r;
> > }
> >
> > +#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
> > +#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
> > +
> > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
> > 					 struct kvm_guest_debug *dbg)
> > {
> > -	return -EINVAL;
> > +
> > +	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
> > +		/* Clear All debug events */
> > +		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> > +		vcpu->guest_debug = 0;
> > +		return 0;
> > +	}
> > +
> > +	vcpu->guest_debug = dbg->control;
> > +	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> > +	/* Set DBCR0_EDM in guest visible DBCR0 register. */
> > +	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
> > +
> > +	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
> > +		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
> > +
> > +	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
> 
> if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
>     /* Code below handles only HW breakpoints */
>     return 0;
> }

ok

> 
> > +		struct kvmppc_booke_debug_reg *gdbgr =
> > +				&(vcpu->arch.shadow_dbg_reg);
> > +		int n, b = 0, w = 0;
> > +		const u32 bp_code[] = {
> > +			DBCR0_IAC1 | DBCR0_IDM,
> > +			DBCR0_IAC2 | DBCR0_IDM,
> > +			DBCR0_IAC3 | DBCR0_IDM,
> > +			DBCR0_IAC4 | DBCR0_IDM
> > +		};
> > +		const u32 wp_code[] = {
> > +			DBCR0_DAC1W | DBCR0_IDM,
> > +			DBCR0_DAC2W | DBCR0_IDM,
> > +			DBCR0_DAC1R | DBCR0_IDM,
> > +			DBCR0_DAC2R | DBCR0_IDM
> > +		};
> > +
> > +#ifndef CONFIG_KVM_BOOKE_HV
> 
> Please no double negation. 
You mean we should use
#ifdef CONFIG_KVM_BOOKE_HV
		gdbgr->dbcr1 = 0;
		gdbgr->dbcr2 = 0;
#else
		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
				DBCR1_IAC3US | DBCR1_IAC4US;
		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
#endif

> Also, what is this about?

This These bits says that IAC1-4 and DAC1-2 can happen when MSR.PR is set of not. 
On BOOKE (e500v2); MSR.PR = 1 when guest is running. So we need to set these bits
On BOOKE-HV (e500mc+); MSR.PR = 0 when guest is running. So we do not need these bits to be set.

> 
> > +		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> > +				DBCR1_IAC3US | DBCR1_IAC4US;
> > +		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; #else
> > +		gdbgr->dbcr1 = 0;
> > +		gdbgr->dbcr2 = 0;
> > +#endif
> > +
> > +		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
> > +			u32 type = dbg->arch.bp[n].type;
> > +
> > +			if (!type)
> > +				break;
> > +
> > +			if (type & (KVMPPC_DEBUG_WATCH_READ |
> > +				    KVMPPC_DEBUG_WATCH_WRITE)) {
> > +				if (w < WP_NUM) {
> > +					if (type & KVMPPC_DEBUG_WATCH_READ)
> > +						gdbgr->dbcr0 |= wp_code[w + 2];
> > +					if (type & KVMPPC_DEBUG_WATCH_WRITE)
> > +						gdbgr->dbcr0 |= wp_code[w];
> > +					gdbgr->dac[w] = dbg->arch.bp[n].addr;
> > +					w++;
> > +				}
> > +			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
> > +				if (b < BP_NUM) {
> > +					gdbgr->dbcr0 |= bp_code[b];
> > +					gdbgr->iac[b] = dbg->arch.bp[n].addr;
> > +					b++;
> > +				}
> > +			}
> > +		}
> > +	}
> > +	return 0;
> > }
> >
> > int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu
> > *fpu) diff --git a/arch/powerpc/kvm/e500_emulate.c
> > b/arch/powerpc/kvm/e500_emulate.c index e78f353..83ac877 100644
> > --- a/arch/powerpc/kvm/e500_emulate.c
> > +++ b/arch/powerpc/kvm/e500_emulate.c
> > @@ -26,6 +26,7 @@
> > #define XOP_TLBRE   946
> > #define XOP_TLBWE   978
> > #define XOP_TLBILX  18
> > +#define XOP_EHPRIV  270
> >
> > #ifdef CONFIG_KVM_E500MC
> > static int dbell2prio(ulong param)
> > @@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct
> kvm_vcpu *vcpu,
> > 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
> > 			break;
> >
> > +		case XOP_EHPRIV:
> > +			emulated = EMULATE_EXIT_USER;
> > +			*advance = 0;
> > +			break;
> > +
> > 		default:
> > 			emulated = EMULATE_FAIL;
> > 		}
> > diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
> > index 1f89d26..f5fc6f5 100644
> > --- a/arch/powerpc/kvm/e500mc.c
> > +++ b/arch/powerpc/kvm/e500mc.c
> > @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
> > {
> > 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> >
> > -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
> > -				 SPRN_EPCR_DUVD;
> > +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;
> 
> Doesn't this route all debug events through the host?

No; This means that debug events can occur in hypervisor state or not.

EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.

EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.

So we allow debug events to occur in hypervisor state. On lightweight exit we set ECPU.DUVD (if guest using debug facility) so debug events will not come during guest entry/exit code. On guest exit we clear this bit (after restoring host state) so hypervisor can use debug features.

Thanks
-Bharat
> 
> 
> Alex
> 
> > #ifdef CONFIG_64BIT
> > 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM; #endif
> > --
> > 1.7.0.4
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
@ 2013-03-14  5:18       ` Bhushan Bharat-R65777
  0 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14  5:18 UTC (permalink / raw)
  To: Alexander Graf; +Cc: kvm-ppc, kvm, Wood Scott-B07421



> -----Original Message-----
> From: Alexander Graf [mailto:agraf@suse.de]
> Sent: Thursday, March 07, 2013 7:09 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
> Bharat-R65777
> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
> 
> 
> 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.bhushan@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_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_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.

ok

> 
> > +		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.

Can there be the case when do breakpoint and debug interrupt happen?

> 
> > +
> > +	if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
> > +		run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
> > +	} else {
> > +		if (dbsr & (DBSR_DAC1W | DBSR_DAC2W))
> > +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
> > +		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
> > +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
> > +		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
> > +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
> > +		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
> > +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
> > +	}
> > +
> > +	return RESUME_HOST;
> > +}
> > +
> > static void kvmppc_fill_pt_regs(struct pt_regs *regs) {
> > 	ulong r1, ip, msr, lr;
> > @@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct
> kvm_vcpu *vcpu,
> > 	}
> >
> > 	case BOOKE_INTERRUPT_DEBUG: {
> > -		u32 dbsr;
> > -
> > -		vcpu->arch.pc = mfspr(SPRN_CSRR0);
> > -
> > -		/* clear IAC events in DBSR register */
> > -		dbsr = mfspr(SPRN_DBSR);
> > -		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
> > -		mtspr(SPRN_DBSR, dbsr);
> > -
> > -		run->exit_reason = KVM_EXIT_DEBUG;
> > +		r = kvmppc_handle_debug(run, vcpu);
> > +		if (r = RESUME_HOST) {
> > +			run->exit_reason = KVM_EXIT_DEBUG;
> > +		}
> > 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
> > -		r = RESUME_HOST;
> > 		break;
> > 	}
> >
> > @@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
> > 	kvmppc_set_msr(vcpu, 0);
> >
> > #ifndef CONFIG_KVM_BOOKE_HV
> > -	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
> > +	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
> > 	vcpu->arch.shadow_pid = 1;
> > 	vcpu->arch.shared->msr = 0;
> > #endif
> > @@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
> struct kvm_one_reg *reg)
> > 	return r;
> > }
> >
> > +#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
> > +#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
> > +
> > int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
> > 					 struct kvm_guest_debug *dbg)
> > {
> > -	return -EINVAL;
> > +
> > +	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
> > +		/* Clear All debug events */
> > +		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> > +		vcpu->guest_debug = 0;
> > +		return 0;
> > +	}
> > +
> > +	vcpu->guest_debug = dbg->control;
> > +	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> > +	/* Set DBCR0_EDM in guest visible DBCR0 register. */
> > +	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
> > +
> > +	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
> > +		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
> > +
> > +	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
> 
> if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
>     /* Code below handles only HW breakpoints */
>     return 0;
> }

ok

> 
> > +		struct kvmppc_booke_debug_reg *gdbgr > > +				&(vcpu->arch.shadow_dbg_reg);
> > +		int n, b = 0, w = 0;
> > +		const u32 bp_code[] = {
> > +			DBCR0_IAC1 | DBCR0_IDM,
> > +			DBCR0_IAC2 | DBCR0_IDM,
> > +			DBCR0_IAC3 | DBCR0_IDM,
> > +			DBCR0_IAC4 | DBCR0_IDM
> > +		};
> > +		const u32 wp_code[] = {
> > +			DBCR0_DAC1W | DBCR0_IDM,
> > +			DBCR0_DAC2W | DBCR0_IDM,
> > +			DBCR0_DAC1R | DBCR0_IDM,
> > +			DBCR0_DAC2R | DBCR0_IDM
> > +		};
> > +
> > +#ifndef CONFIG_KVM_BOOKE_HV
> 
> Please no double negation. 
You mean we should use
#ifdef CONFIG_KVM_BOOKE_HV
		gdbgr->dbcr1 = 0;
		gdbgr->dbcr2 = 0;
#else
		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
				DBCR1_IAC3US | DBCR1_IAC4US;
		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
#endif

> Also, what is this about?

This These bits says that IAC1-4 and DAC1-2 can happen when MSR.PR is set of not. 
On BOOKE (e500v2); MSR.PR = 1 when guest is running. So we need to set these bits
On BOOKE-HV (e500mc+); MSR.PR = 0 when guest is running. So we do not need these bits to be set.

> 
> > +		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> > +				DBCR1_IAC3US | DBCR1_IAC4US;
> > +		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; #else
> > +		gdbgr->dbcr1 = 0;
> > +		gdbgr->dbcr2 = 0;
> > +#endif
> > +
> > +		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
> > +			u32 type = dbg->arch.bp[n].type;
> > +
> > +			if (!type)
> > +				break;
> > +
> > +			if (type & (KVMPPC_DEBUG_WATCH_READ |
> > +				    KVMPPC_DEBUG_WATCH_WRITE)) {
> > +				if (w < WP_NUM) {
> > +					if (type & KVMPPC_DEBUG_WATCH_READ)
> > +						gdbgr->dbcr0 |= wp_code[w + 2];
> > +					if (type & KVMPPC_DEBUG_WATCH_WRITE)
> > +						gdbgr->dbcr0 |= wp_code[w];
> > +					gdbgr->dac[w] = dbg->arch.bp[n].addr;
> > +					w++;
> > +				}
> > +			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
> > +				if (b < BP_NUM) {
> > +					gdbgr->dbcr0 |= bp_code[b];
> > +					gdbgr->iac[b] = dbg->arch.bp[n].addr;
> > +					b++;
> > +				}
> > +			}
> > +		}
> > +	}
> > +	return 0;
> > }
> >
> > int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu
> > *fpu) diff --git a/arch/powerpc/kvm/e500_emulate.c
> > b/arch/powerpc/kvm/e500_emulate.c index e78f353..83ac877 100644
> > --- a/arch/powerpc/kvm/e500_emulate.c
> > +++ b/arch/powerpc/kvm/e500_emulate.c
> > @@ -26,6 +26,7 @@
> > #define XOP_TLBRE   946
> > #define XOP_TLBWE   978
> > #define XOP_TLBILX  18
> > +#define XOP_EHPRIV  270
> >
> > #ifdef CONFIG_KVM_E500MC
> > static int dbell2prio(ulong param)
> > @@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct
> kvm_vcpu *vcpu,
> > 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
> > 			break;
> >
> > +		case XOP_EHPRIV:
> > +			emulated = EMULATE_EXIT_USER;
> > +			*advance = 0;
> > +			break;
> > +
> > 		default:
> > 			emulated = EMULATE_FAIL;
> > 		}
> > diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
> > index 1f89d26..f5fc6f5 100644
> > --- a/arch/powerpc/kvm/e500mc.c
> > +++ b/arch/powerpc/kvm/e500mc.c
> > @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
> > {
> > 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> >
> > -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
> > -				 SPRN_EPCR_DUVD;
> > +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;
> 
> Doesn't this route all debug events through the host?

No; This means that debug events can occur in hypervisor state or not.

EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.

EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.

So we allow debug events to occur in hypervisor state. On lightweight exit we set ECPU.DUVD (if guest using debug facility) so debug events will not come during guest entry/exit code. On guest exit we clear this bit (after restoring host state) so hypervisor can use debug features.

Thanks
-Bharat
> 
> 
> Alex
> 
> > #ifdef CONFIG_64BIT
> > 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM; #endif
> > --
> > 1.7.0.4
> >
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 



^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
  2013-03-07 10:47           ` Alexander Graf
  (?)
@ 2013-03-14  5:59           ` Bhushan Bharat-R65777
  -1 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14  5:59 UTC (permalink / raw)
  To: Alexander Graf, Wood Scott-B07421; +Cc: kvm-ppc, kvm



> -----Original Message-----
> From: kvm-ppc-owner@vger.kernel.org [mailto:kvm-ppc-owner@vger.kernel.org] On
> Behalf Of Alexander Graf
> Sent: Thursday, March 07, 2013 4:17 PM
> To: Wood Scott-B07421
> Cc: Bhushan Bharat-R65777; kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Bhushan
> Bharat-R65777
> Subject: Re: [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER
> 
> 
> 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.bhushan@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?

Do you mean moving run->exit_reason = ... and vcpu->arch.hcall_needed = ... into arch/powerpc/kvm/book3s_emulate.c ? If yes, then no you did not miss :) as I have not sent.
I will send the new patch with other patches in the patch-set.

-Bharat

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

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
  2013-03-14  5:18       ` Bhushan Bharat-R65777
@ 2013-03-14 11:50         ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 11:50 UTC (permalink / raw)
  To: Bhushan Bharat-R65777; +Cc: kvm-ppc, kvm, Wood Scott-B07421


On 14.03.2013, at 06:18, Bhushan Bharat-R65777 wrote:

> 
> 
>> -----Original Message-----
>> From: Alexander Graf [mailto:agraf@suse.de]
>> Sent: Thursday, March 07, 2013 7:09 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
>> 
>> 
>> 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.bhushan@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_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_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.
> 
> ok
> 
>> 
>>> +		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.
> 
> Can there be the case when do breakpoint and debug interrupt happen?

At least not according to the code below :). If that's a valid case, then quite a bit of code would need to be remodeled. I'd say ignore the possibility for now.

> 
>> 
>>> +
>>> +	if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
>>> +		run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
>>> +	} else {
>>> +		if (dbsr & (DBSR_DAC1W | DBSR_DAC2W))
>>> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
>>> +		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
>>> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
>>> +		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
>>> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
>>> +		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
>>> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
>>> +	}
>>> +
>>> +	return RESUME_HOST;
>>> +}
>>> +
>>> static void kvmppc_fill_pt_regs(struct pt_regs *regs) {
>>> 	ulong r1, ip, msr, lr;
>>> @@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct
>> kvm_vcpu *vcpu,
>>> 	}
>>> 
>>> 	case BOOKE_INTERRUPT_DEBUG: {
>>> -		u32 dbsr;
>>> -
>>> -		vcpu->arch.pc = mfspr(SPRN_CSRR0);
>>> -
>>> -		/* clear IAC events in DBSR register */
>>> -		dbsr = mfspr(SPRN_DBSR);
>>> -		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
>>> -		mtspr(SPRN_DBSR, dbsr);
>>> -
>>> -		run->exit_reason = KVM_EXIT_DEBUG;
>>> +		r = kvmppc_handle_debug(run, vcpu);
>>> +		if (r == RESUME_HOST) {
>>> +			run->exit_reason = KVM_EXIT_DEBUG;
>>> +		}
>>> 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
>>> -		r = RESUME_HOST;
>>> 		break;
>>> 	}
>>> 
>>> @@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
>>> 	kvmppc_set_msr(vcpu, 0);
>>> 
>>> #ifndef CONFIG_KVM_BOOKE_HV
>>> -	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
>>> +	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
>>> 	vcpu->arch.shadow_pid = 1;
>>> 	vcpu->arch.shared->msr = 0;
>>> #endif
>>> @@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
>> struct kvm_one_reg *reg)
>>> 	return r;
>>> }
>>> 
>>> +#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
>>> +#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
>>> +
>>> int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
>>> 					 struct kvm_guest_debug *dbg)
>>> {
>>> -	return -EINVAL;
>>> +
>>> +	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
>>> +		/* Clear All debug events */
>>> +		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
>>> +		vcpu->guest_debug = 0;
>>> +		return 0;
>>> +	}
>>> +
>>> +	vcpu->guest_debug = dbg->control;
>>> +	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
>>> +	/* Set DBCR0_EDM in guest visible DBCR0 register. */
>>> +	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
>>> +
>>> +	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
>>> +		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
>>> +
>>> +	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
>> 
>> if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
>>    /* Code below handles only HW breakpoints */
>>    return 0;
>> }
> 
> ok
> 
>> 
>>> +		struct kvmppc_booke_debug_reg *gdbgr =
>>> +				&(vcpu->arch.shadow_dbg_reg);
>>> +		int n, b = 0, w = 0;
>>> +		const u32 bp_code[] = {
>>> +			DBCR0_IAC1 | DBCR0_IDM,
>>> +			DBCR0_IAC2 | DBCR0_IDM,
>>> +			DBCR0_IAC3 | DBCR0_IDM,
>>> +			DBCR0_IAC4 | DBCR0_IDM
>>> +		};
>>> +		const u32 wp_code[] = {
>>> +			DBCR0_DAC1W | DBCR0_IDM,
>>> +			DBCR0_DAC2W | DBCR0_IDM,
>>> +			DBCR0_DAC1R | DBCR0_IDM,
>>> +			DBCR0_DAC2R | DBCR0_IDM
>>> +		};
>>> +
>>> +#ifndef CONFIG_KVM_BOOKE_HV
>> 
>> Please no double negation. 
> You mean we should use
> #ifdef CONFIG_KVM_BOOKE_HV
> 		gdbgr->dbcr1 = 0;
> 		gdbgr->dbcr2 = 0;
> #else
> 		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> 				DBCR1_IAC3US | DBCR1_IAC4US;
> 		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
> #endif
> 
>> Also, what is this about?
> 
> This These bits says that IAC1-4 and DAC1-2 can happen when MSR.PR is set of not. 
> On BOOKE (e500v2); MSR.PR = 1 when guest is running. So we need to set these bits
> On BOOKE-HV (e500mc+); MSR.PR = 0 when guest is running. So we do not need these bits to be set.

Ah, please add a comment explaining this here.

> 
>> 
>>> +		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
>>> +				DBCR1_IAC3US | DBCR1_IAC4US;
>>> +		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; #else
>>> +		gdbgr->dbcr1 = 0;
>>> +		gdbgr->dbcr2 = 0;
>>> +#endif
>>> +
>>> +		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
>>> +			u32 type = dbg->arch.bp[n].type;
>>> +
>>> +			if (!type)
>>> +				break;
>>> +
>>> +			if (type & (KVMPPC_DEBUG_WATCH_READ |
>>> +				    KVMPPC_DEBUG_WATCH_WRITE)) {
>>> +				if (w < WP_NUM) {
>>> +					if (type & KVMPPC_DEBUG_WATCH_READ)
>>> +						gdbgr->dbcr0 |= wp_code[w + 2];
>>> +					if (type & KVMPPC_DEBUG_WATCH_WRITE)
>>> +						gdbgr->dbcr0 |= wp_code[w];
>>> +					gdbgr->dac[w] = dbg->arch.bp[n].addr;
>>> +					w++;
>>> +				}
>>> +			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
>>> +				if (b < BP_NUM) {
>>> +					gdbgr->dbcr0 |= bp_code[b];
>>> +					gdbgr->iac[b] = dbg->arch.bp[n].addr;
>>> +					b++;
>>> +				}
>>> +			}
>>> +		}
>>> +	}
>>> +	return 0;
>>> }
>>> 
>>> int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu
>>> *fpu) diff --git a/arch/powerpc/kvm/e500_emulate.c
>>> b/arch/powerpc/kvm/e500_emulate.c index e78f353..83ac877 100644
>>> --- a/arch/powerpc/kvm/e500_emulate.c
>>> +++ b/arch/powerpc/kvm/e500_emulate.c
>>> @@ -26,6 +26,7 @@
>>> #define XOP_TLBRE   946
>>> #define XOP_TLBWE   978
>>> #define XOP_TLBILX  18
>>> +#define XOP_EHPRIV  270
>>> 
>>> #ifdef CONFIG_KVM_E500MC
>>> static int dbell2prio(ulong param)
>>> @@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct
>> kvm_vcpu *vcpu,
>>> 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
>>> 			break;
>>> 
>>> +		case XOP_EHPRIV:
>>> +			emulated = EMULATE_EXIT_USER;
>>> +			*advance = 0;
>>> +			break;
>>> +
>>> 		default:
>>> 			emulated = EMULATE_FAIL;
>>> 		}
>>> diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
>>> index 1f89d26..f5fc6f5 100644
>>> --- a/arch/powerpc/kvm/e500mc.c
>>> +++ b/arch/powerpc/kvm/e500mc.c
>>> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
>>> {
>>> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
>>> 
>>> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
>>> -				 SPRN_EPCR_DUVD;
>>> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;
>> 
>> Doesn't this route all debug events through the host?
> 
> No; This means that debug events can occur in hypervisor state or not.
> 
> EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.
> 
> EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.
> 
> So we allow debug events to occur in hypervisor state.

Why do we care about debug events in our entry/exit code and didn't care about them before? If anything, this is a completely separate patch, orthogonal to this patch series, and requires a good bit of explanation.


Alex

> On lightweight exit we set ECPU.DUVD (if guest using debug facility) so debug events will not come during guest entry/exit code. On guest exit we clear this bit (after restoring host state) so hypervisor can use debug features.
> 
> Thanks
> -Bharat
>> 
>> 
>> Alex
>> 
>>> #ifdef CONFIG_64BIT
>>> 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM; #endif
>>> --
>>> 1.7.0.4
>>> 
>>> 
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> 
> 
> 


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
@ 2013-03-14 11:50         ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 11:50 UTC (permalink / raw)
  To: Bhushan Bharat-R65777; +Cc: kvm-ppc, kvm, Wood Scott-B07421


On 14.03.2013, at 06:18, Bhushan Bharat-R65777 wrote:

> 
> 
>> -----Original Message-----
>> From: Alexander Graf [mailto:agraf@suse.de]
>> Sent: Thursday, March 07, 2013 7:09 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
>> 
>> 
>> 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.bhushan@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_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_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.
> 
> ok
> 
>> 
>>> +		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.
> 
> Can there be the case when do breakpoint and debug interrupt happen?

At least not according to the code below :). If that's a valid case, then quite a bit of code would need to be remodeled. I'd say ignore the possibility for now.

> 
>> 
>>> +
>>> +	if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
>>> +		run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
>>> +	} else {
>>> +		if (dbsr & (DBSR_DAC1W | DBSR_DAC2W))
>>> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
>>> +		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
>>> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
>>> +		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
>>> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
>>> +		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
>>> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
>>> +	}
>>> +
>>> +	return RESUME_HOST;
>>> +}
>>> +
>>> static void kvmppc_fill_pt_regs(struct pt_regs *regs) {
>>> 	ulong r1, ip, msr, lr;
>>> @@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run, struct
>> kvm_vcpu *vcpu,
>>> 	}
>>> 
>>> 	case BOOKE_INTERRUPT_DEBUG: {
>>> -		u32 dbsr;
>>> -
>>> -		vcpu->arch.pc = mfspr(SPRN_CSRR0);
>>> -
>>> -		/* clear IAC events in DBSR register */
>>> -		dbsr = mfspr(SPRN_DBSR);
>>> -		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
>>> -		mtspr(SPRN_DBSR, dbsr);
>>> -
>>> -		run->exit_reason = KVM_EXIT_DEBUG;
>>> +		r = kvmppc_handle_debug(run, vcpu);
>>> +		if (r = RESUME_HOST) {
>>> +			run->exit_reason = KVM_EXIT_DEBUG;
>>> +		}
>>> 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
>>> -		r = RESUME_HOST;
>>> 		break;
>>> 	}
>>> 
>>> @@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
>>> 	kvmppc_set_msr(vcpu, 0);
>>> 
>>> #ifndef CONFIG_KVM_BOOKE_HV
>>> -	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
>>> +	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
>>> 	vcpu->arch.shadow_pid = 1;
>>> 	vcpu->arch.shared->msr = 0;
>>> #endif
>>> @@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct kvm_vcpu *vcpu,
>> struct kvm_one_reg *reg)
>>> 	return r;
>>> }
>>> 
>>> +#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
>>> +#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
>>> +
>>> int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
>>> 					 struct kvm_guest_debug *dbg)
>>> {
>>> -	return -EINVAL;
>>> +
>>> +	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
>>> +		/* Clear All debug events */
>>> +		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
>>> +		vcpu->guest_debug = 0;
>>> +		return 0;
>>> +	}
>>> +
>>> +	vcpu->guest_debug = dbg->control;
>>> +	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
>>> +	/* Set DBCR0_EDM in guest visible DBCR0 register. */
>>> +	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
>>> +
>>> +	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
>>> +		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
>>> +
>>> +	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
>> 
>> if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
>>    /* Code below handles only HW breakpoints */
>>    return 0;
>> }
> 
> ok
> 
>> 
>>> +		struct kvmppc_booke_debug_reg *gdbgr >>> +				&(vcpu->arch.shadow_dbg_reg);
>>> +		int n, b = 0, w = 0;
>>> +		const u32 bp_code[] = {
>>> +			DBCR0_IAC1 | DBCR0_IDM,
>>> +			DBCR0_IAC2 | DBCR0_IDM,
>>> +			DBCR0_IAC3 | DBCR0_IDM,
>>> +			DBCR0_IAC4 | DBCR0_IDM
>>> +		};
>>> +		const u32 wp_code[] = {
>>> +			DBCR0_DAC1W | DBCR0_IDM,
>>> +			DBCR0_DAC2W | DBCR0_IDM,
>>> +			DBCR0_DAC1R | DBCR0_IDM,
>>> +			DBCR0_DAC2R | DBCR0_IDM
>>> +		};
>>> +
>>> +#ifndef CONFIG_KVM_BOOKE_HV
>> 
>> Please no double negation. 
> You mean we should use
> #ifdef CONFIG_KVM_BOOKE_HV
> 		gdbgr->dbcr1 = 0;
> 		gdbgr->dbcr2 = 0;
> #else
> 		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> 				DBCR1_IAC3US | DBCR1_IAC4US;
> 		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US;
> #endif
> 
>> Also, what is this about?
> 
> This These bits says that IAC1-4 and DAC1-2 can happen when MSR.PR is set of not. 
> On BOOKE (e500v2); MSR.PR = 1 when guest is running. So we need to set these bits
> On BOOKE-HV (e500mc+); MSR.PR = 0 when guest is running. So we do not need these bits to be set.

Ah, please add a comment explaining this here.

> 
>> 
>>> +		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
>>> +				DBCR1_IAC3US | DBCR1_IAC4US;
>>> +		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; #else
>>> +		gdbgr->dbcr1 = 0;
>>> +		gdbgr->dbcr2 = 0;
>>> +#endif
>>> +
>>> +		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
>>> +			u32 type = dbg->arch.bp[n].type;
>>> +
>>> +			if (!type)
>>> +				break;
>>> +
>>> +			if (type & (KVMPPC_DEBUG_WATCH_READ |
>>> +				    KVMPPC_DEBUG_WATCH_WRITE)) {
>>> +				if (w < WP_NUM) {
>>> +					if (type & KVMPPC_DEBUG_WATCH_READ)
>>> +						gdbgr->dbcr0 |= wp_code[w + 2];
>>> +					if (type & KVMPPC_DEBUG_WATCH_WRITE)
>>> +						gdbgr->dbcr0 |= wp_code[w];
>>> +					gdbgr->dac[w] = dbg->arch.bp[n].addr;
>>> +					w++;
>>> +				}
>>> +			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
>>> +				if (b < BP_NUM) {
>>> +					gdbgr->dbcr0 |= bp_code[b];
>>> +					gdbgr->iac[b] = dbg->arch.bp[n].addr;
>>> +					b++;
>>> +				}
>>> +			}
>>> +		}
>>> +	}
>>> +	return 0;
>>> }
>>> 
>>> int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct kvm_fpu
>>> *fpu) diff --git a/arch/powerpc/kvm/e500_emulate.c
>>> b/arch/powerpc/kvm/e500_emulate.c index e78f353..83ac877 100644
>>> --- a/arch/powerpc/kvm/e500_emulate.c
>>> +++ b/arch/powerpc/kvm/e500_emulate.c
>>> @@ -26,6 +26,7 @@
>>> #define XOP_TLBRE   946
>>> #define XOP_TLBWE   978
>>> #define XOP_TLBILX  18
>>> +#define XOP_EHPRIV  270
>>> 
>>> #ifdef CONFIG_KVM_E500MC
>>> static int dbell2prio(ulong param)
>>> @@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run, struct
>> kvm_vcpu *vcpu,
>>> 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
>>> 			break;
>>> 
>>> +		case XOP_EHPRIV:
>>> +			emulated = EMULATE_EXIT_USER;
>>> +			*advance = 0;
>>> +			break;
>>> +
>>> 		default:
>>> 			emulated = EMULATE_FAIL;
>>> 		}
>>> diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
>>> index 1f89d26..f5fc6f5 100644
>>> --- a/arch/powerpc/kvm/e500mc.c
>>> +++ b/arch/powerpc/kvm/e500mc.c
>>> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu *vcpu)
>>> {
>>> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
>>> 
>>> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
>>> -				 SPRN_EPCR_DUVD;
>>> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;
>> 
>> Doesn't this route all debug events through the host?
> 
> No; This means that debug events can occur in hypervisor state or not.
> 
> EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.
> 
> EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.
> 
> So we allow debug events to occur in hypervisor state.

Why do we care about debug events in our entry/exit code and didn't care about them before? If anything, this is a completely separate patch, orthogonal to this patch series, and requires a good bit of explanation.


Alex

> On lightweight exit we set ECPU.DUVD (if guest using debug facility) so debug events will not come during guest entry/exit code. On guest exit we clear this bit (after restoring host state) so hypervisor can use debug features.
> 
> Thanks
> -Bharat
>> 
>> 
>> Alex
>> 
>>> #ifdef CONFIG_64BIT
>>> 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM; #endif
>>> --
>>> 1.7.0.4
>>> 
>>> 
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
>>> the body of a message to majordomo@vger.kernel.org
>>> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>> 
> 
> 


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
  2013-03-14  4:50     ` Bhushan Bharat-R65777
@ 2013-03-14 11:52         ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 11:52 UTC (permalink / raw)
  To: Bhushan Bharat-R65777; +Cc: kvm-ppc, kvm, Wood Scott-B07421


On 14.03.2013, at 05:50, Bhushan Bharat-R65777 wrote:

> 
> 
>> -----Original Message-----
>> From: Alexander Graf [mailto:agraf@suse.de]
>> Sent: Thursday, March 07, 2013 6:56 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 4/7] booke: Save and restore debug registers on guest entry
>> and exit
>> 
>> 
>> 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?
> 
> 
> One of the reason for not doing this is that the KVM is a host kernel module and let this be debugged by host (I do not this how much useful this is :)) 
> So I am not able to recall the specific reason, maybe we have just coded this like this and tried to keep overhead as low as possible by switching registers only when they are used.

My point is that the overhead is _higher_ this way, because we need to do checks and switches on every guest entry/exit, which happens a _lot_ more often than a host context switch.

> As we discussed before, we can keep this option open for future.

What future? Just ignore debug events in the entry/exit code path and suddenly a lot of the code becomes a lot easier.


Alex

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
@ 2013-03-14 11:52         ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 11:52 UTC (permalink / raw)
  To: Bhushan Bharat-R65777; +Cc: kvm-ppc, kvm, Wood Scott-B07421


On 14.03.2013, at 05:50, Bhushan Bharat-R65777 wrote:

> 
> 
>> -----Original Message-----
>> From: Alexander Graf [mailto:agraf@suse.de]
>> Sent: Thursday, March 07, 2013 6:56 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 4/7] booke: Save and restore debug registers on guest entry
>> and exit
>> 
>> 
>> 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?
> 
> 
> One of the reason for not doing this is that the KVM is a host kernel module and let this be debugged by host (I do not this how much useful this is :)) 
> So I am not able to recall the specific reason, maybe we have just coded this like this and tried to keep overhead as low as possible by switching registers only when they are used.

My point is that the overhead is _higher_ this way, because we need to do checks and switches on every guest entry/exit, which happens a _lot_ more often than a host context switch.

> As we discussed before, we can keep this option open for future.

What future? Just ignore debug events in the entry/exit code path and suddenly a lot of the code becomes a lot easier.


Alex


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-03-14  4:42     ` Bhushan Bharat-R65777
@ 2013-03-14 11:54         ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 11:54 UTC (permalink / raw)
  To: Bhushan Bharat-R65777
  Cc: kvm-ppc, kvm@vger.kernel.org list:Overall, Wood Scott-B07421, Jan Kiszka


On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:

> 
> 
>> -----Original Message-----
>> From: Alexander Graf [mailto:agraf@suse.de]
>> Sent: Thursday, March 07, 2013 6:51 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>> 
>> 
>> 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.bhushan@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		0x00010000
>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>> 
>> You only need
>> 
>> #define KVM_GUESTDBG_HW_BP 0x00010000
>> 
>> In absence of the flag, it's a SW breakpoint.
> 
> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.

Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?


Alex

> 
> If you want than I can code this as you described.
> 
> -Bharat
> 
>> 
>> 
>> 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-03-14 11:54         ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 11:54 UTC (permalink / raw)
  To: Bhushan Bharat-R65777
  Cc: kvm-ppc, kvm@vger.kernel.org list:Overall, Wood Scott-B07421, Jan Kiszka


On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:

> 
> 
>> -----Original Message-----
>> From: Alexander Graf [mailto:agraf@suse.de]
>> Sent: Thursday, March 07, 2013 6:51 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>> 
>> 
>> 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.bhushan@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		0x00010000
>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>> 
>> You only need
>> 
>> #define KVM_GUESTDBG_HW_BP 0x00010000
>> 
>> In absence of the flag, it's a SW breakpoint.
> 
> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.

Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?


Alex

> 
> If you want than I can code this as you described.
> 
> -Bharat
> 
>> 
>> 
>> 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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
  2013-03-14  4:30     ` Bhushan Bharat-R65777
@ 2013-03-14 11:56         ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 11:56 UTC (permalink / raw)
  To: Bhushan Bharat-R65777; +Cc: kvm-ppc, kvm, Wood Scott-B07421


On 14.03.2013, at 05:30, Bhushan Bharat-R65777 wrote:

> 
> 
>> -----Original Message-----
>> From: Alexander Graf [mailto:agraf@suse.de]
>> Sent: Thursday, March 07, 2013 6:38 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
>> 
>> 
>> 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.bhushan@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				0x7c000008
>> 
>> 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.
> 
> Yes I missed this.
> BTW rather than setting TO = 31, what if we set TO = 2 as RA and RB is same here.

Well, the unconditional "trap" instruction is simply defined as TO = 31, so I'd stick to that :)


Alex

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
@ 2013-03-14 11:56         ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 11:56 UTC (permalink / raw)
  To: Bhushan Bharat-R65777; +Cc: kvm-ppc, kvm, Wood Scott-B07421


On 14.03.2013, at 05:30, Bhushan Bharat-R65777 wrote:

> 
> 
>> -----Original Message-----
>> From: Alexander Graf [mailto:agraf@suse.de]
>> Sent: Thursday, March 07, 2013 6:38 PM
>> To: Bhushan Bharat-R65777
>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>> Bharat-R65777
>> Subject: Re: [PATCH 2/7] Added ONE_REG interface for debug instruction
>> 
>> 
>> 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.bhushan@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				0x7c000008
>> 
>> 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.
> 
> Yes I missed this.
> BTW rather than setting TO = 31, what if we set TO = 2 as RA and RB is same here.

Well, the unconditional "trap" instruction is simply defined as TO = 31, so I'd stick to that :)


Alex


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-03-14 11:54         ` Alexander Graf
@ 2013-03-14 11:57           ` Jan Kiszka
  -1 siblings, 0 replies; 72+ messages in thread
From: Jan Kiszka @ 2013-03-14 11:57 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421

On 2013-03-14 12:54, Alexander Graf wrote:
> 
> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
> 
>>
>>
>>> -----Original Message-----
>>> From: Alexander Graf [mailto:agraf@suse.de]
>>> Sent: Thursday, March 07, 2013 6:51 PM
>>> To: Bhushan Bharat-R65777
>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>> Bharat-R65777
>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>
>>>
>>> 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.bhushan@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		0x00010000
>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>
>>> You only need
>>>
>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>
>>> In absence of the flag, it's a SW breakpoint.
>>
>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
> 
> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?

Different mechanics on x86: HW goes via debug registers and shows up as
INT1, SW is INT3 (plus guest patching done by user land).

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-03-14 11:57           ` Jan Kiszka
  0 siblings, 0 replies; 72+ messages in thread
From: Jan Kiszka @ 2013-03-14 11:57 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421

On 2013-03-14 12:54, Alexander Graf wrote:
> 
> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
> 
>>
>>
>>> -----Original Message-----
>>> From: Alexander Graf [mailto:agraf@suse.de]
>>> Sent: Thursday, March 07, 2013 6:51 PM
>>> To: Bhushan Bharat-R65777
>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>> Bharat-R65777
>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>
>>>
>>> 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.bhushan@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		0x00010000
>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>
>>> You only need
>>>
>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>
>>> In absence of the flag, it's a SW breakpoint.
>>
>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
> 
> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?

Different mechanics on x86: HW goes via debug registers and shows up as
INT1, SW is INT3 (plus guest patching done by user land).

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-03-14 11:57           ` Jan Kiszka
@ 2013-03-14 12:09             ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 12:09 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421


On 14.03.2013, at 12:57, Jan Kiszka wrote:

> On 2013-03-14 12:54, Alexander Graf wrote:
>> 
>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>> 
>>> 
>>> 
>>>> -----Original Message-----
>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>> To: Bhushan Bharat-R65777
>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>> Bharat-R65777
>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>> 
>>>> 
>>>> 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.bhushan@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		0x00010000
>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>> 
>>>> You only need
>>>> 
>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>> 
>>>> In absence of the flag, it's a SW breakpoint.
>>> 
>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>> 
>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
> 
> Different mechanics on x86: HW goes via debug registers and shows up as
> INT1, SW is INT3 (plus guest patching done by user land).

Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did

    #define KVM_GUESTDBG_USE_SW_BP               0x00010000
    #define KVM_GUESTDBG_USE_HW_BP               0x00020000

rather than

    #define KVM_GUESTDBG_BP_TYPE			0x00010000
    #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
    #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000

:)


Alex

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-03-14 12:09             ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 12:09 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421


On 14.03.2013, at 12:57, Jan Kiszka wrote:

> On 2013-03-14 12:54, Alexander Graf wrote:
>> 
>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>> 
>>> 
>>> 
>>>> -----Original Message-----
>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>> To: Bhushan Bharat-R65777
>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>> Bharat-R65777
>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>> 
>>>> 
>>>> 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.bhushan@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		0x00010000
>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>> 
>>>> You only need
>>>> 
>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>> 
>>>> In absence of the flag, it's a SW breakpoint.
>>> 
>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>> 
>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
> 
> Different mechanics on x86: HW goes via debug registers and shows up as
> INT1, SW is INT3 (plus guest patching done by user land).

Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did

    #define KVM_GUESTDBG_USE_SW_BP               0x00010000
    #define KVM_GUESTDBG_USE_HW_BP               0x00020000

rather than

    #define KVM_GUESTDBG_BP_TYPE			0x00010000
    #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
    #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000

:)


Alex


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-03-14 12:09             ` Alexander Graf
@ 2013-03-14 12:13               ` Jan Kiszka
  -1 siblings, 0 replies; 72+ messages in thread
From: Jan Kiszka @ 2013-03-14 12:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421

On 2013-03-14 13:09, Alexander Graf wrote:
> 
> On 14.03.2013, at 12:57, Jan Kiszka wrote:
> 
>> On 2013-03-14 12:54, Alexander Graf wrote:
>>>
>>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>>> To: Bhushan Bharat-R65777
>>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>>> Bharat-R65777
>>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>>>
>>>>>
>>>>> 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.bhushan@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		0x00010000
>>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>>>
>>>>> You only need
>>>>>
>>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>>>
>>>>> In absence of the flag, it's a SW breakpoint.
>>>>
>>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>>>
>>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
>>
>> Different mechanics on x86: HW goes via debug registers and shows up as
>> INT1, SW is INT3 (plus guest patching done by user land).
> 
> Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did
> 
>     #define KVM_GUESTDBG_USE_SW_BP               0x00010000
>     #define KVM_GUESTDBG_USE_HW_BP               0x00020000
> 
> rather than
> 
>     #define KVM_GUESTDBG_BP_TYPE			0x00010000
>     #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
>     #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000
> 
> :)

Those bits enable or disable the features separately. You may also leave
both off if you like (and just use single stepping).

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-03-14 12:13               ` Jan Kiszka
  0 siblings, 0 replies; 72+ messages in thread
From: Jan Kiszka @ 2013-03-14 12:13 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421

On 2013-03-14 13:09, Alexander Graf wrote:
> 
> On 14.03.2013, at 12:57, Jan Kiszka wrote:
> 
>> On 2013-03-14 12:54, Alexander Graf wrote:
>>>
>>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>>>
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>>> To: Bhushan Bharat-R65777
>>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>>> Bharat-R65777
>>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>>>
>>>>>
>>>>> 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.bhushan@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		0x00010000
>>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>>>
>>>>> You only need
>>>>>
>>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>>>
>>>>> In absence of the flag, it's a SW breakpoint.
>>>>
>>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>>>
>>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
>>
>> Different mechanics on x86: HW goes via debug registers and shows up as
>> INT1, SW is INT3 (plus guest patching done by user land).
> 
> Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did
> 
>     #define KVM_GUESTDBG_USE_SW_BP               0x00010000
>     #define KVM_GUESTDBG_USE_HW_BP               0x00020000
> 
> rather than
> 
>     #define KVM_GUESTDBG_BP_TYPE			0x00010000
>     #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
>     #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000
> 
> :)

Those bits enable or disable the features separately. You may also leave
both off if you like (and just use single stepping).

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-03-14 12:13               ` Jan Kiszka
@ 2013-03-14 12:19                 ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 12:19 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421


On 14.03.2013, at 13:13, Jan Kiszka wrote:

> On 2013-03-14 13:09, Alexander Graf wrote:
>> 
>> On 14.03.2013, at 12:57, Jan Kiszka wrote:
>> 
>>> On 2013-03-14 12:54, Alexander Graf wrote:
>>>> 
>>>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>>>> 
>>>>> 
>>>>> 
>>>>>> -----Original Message-----
>>>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>>>> To: Bhushan Bharat-R65777
>>>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>>>> Bharat-R65777
>>>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>>>> 
>>>>>> 
>>>>>> 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.bhushan@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		0x00010000
>>>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>>>> 
>>>>>> You only need
>>>>>> 
>>>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>>>> 
>>>>>> In absence of the flag, it's a SW breakpoint.
>>>>> 
>>>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>>>> 
>>>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
>>> 
>>> Different mechanics on x86: HW goes via debug registers and shows up as
>>> INT1, SW is INT3 (plus guest patching done by user land).
>> 
>> Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did
>> 
>>    #define KVM_GUESTDBG_USE_SW_BP               0x00010000
>>    #define KVM_GUESTDBG_USE_HW_BP               0x00020000
>> 
>> rather than
>> 
>>    #define KVM_GUESTDBG_BP_TYPE			0x00010000
>>    #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
>>    #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000
>> 
>> :)
> 
> Those bits enable or disable the features separately. You may also leave
> both off if you like (and just use single stepping).

Ah, so these are global configuration bits, not per-breakpoint configuration?


Alex

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-03-14 12:19                 ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 12:19 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421


On 14.03.2013, at 13:13, Jan Kiszka wrote:

> On 2013-03-14 13:09, Alexander Graf wrote:
>> 
>> On 14.03.2013, at 12:57, Jan Kiszka wrote:
>> 
>>> On 2013-03-14 12:54, Alexander Graf wrote:
>>>> 
>>>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>>>> 
>>>>> 
>>>>> 
>>>>>> -----Original Message-----
>>>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>>>> To: Bhushan Bharat-R65777
>>>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>>>> Bharat-R65777
>>>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>>>> 
>>>>>> 
>>>>>> 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.bhushan@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		0x00010000
>>>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>>>> 
>>>>>> You only need
>>>>>> 
>>>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>>>> 
>>>>>> In absence of the flag, it's a SW breakpoint.
>>>>> 
>>>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>>>> 
>>>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
>>> 
>>> Different mechanics on x86: HW goes via debug registers and shows up as
>>> INT1, SW is INT3 (plus guest patching done by user land).
>> 
>> Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did
>> 
>>    #define KVM_GUESTDBG_USE_SW_BP               0x00010000
>>    #define KVM_GUESTDBG_USE_HW_BP               0x00020000
>> 
>> rather than
>> 
>>    #define KVM_GUESTDBG_BP_TYPE			0x00010000
>>    #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
>>    #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000
>> 
>> :)
> 
> Those bits enable or disable the features separately. You may also leave
> both off if you like (and just use single stepping).

Ah, so these are global configuration bits, not per-breakpoint configuration?


Alex


^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-03-14 12:19                 ` Alexander Graf
@ 2013-03-14 12:22                   ` Jan Kiszka
  -1 siblings, 0 replies; 72+ messages in thread
From: Jan Kiszka @ 2013-03-14 12:22 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421

On 2013-03-14 13:19, Alexander Graf wrote:
> 
> On 14.03.2013, at 13:13, Jan Kiszka wrote:
> 
>> On 2013-03-14 13:09, Alexander Graf wrote:
>>>
>>> On 14.03.2013, at 12:57, Jan Kiszka wrote:
>>>
>>>> On 2013-03-14 12:54, Alexander Graf wrote:
>>>>>
>>>>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>>>>> To: Bhushan Bharat-R65777
>>>>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>>>>> Bharat-R65777
>>>>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>>>>>
>>>>>>>
>>>>>>> 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.bhushan@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		0x00010000
>>>>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>>>>>
>>>>>>> You only need
>>>>>>>
>>>>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>>>>>
>>>>>>> In absence of the flag, it's a SW breakpoint.
>>>>>>
>>>>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>>>>>
>>>>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
>>>>
>>>> Different mechanics on x86: HW goes via debug registers and shows up as
>>>> INT1, SW is INT3 (plus guest patching done by user land).
>>>
>>> Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did
>>>
>>>    #define KVM_GUESTDBG_USE_SW_BP               0x00010000
>>>    #define KVM_GUESTDBG_USE_HW_BP               0x00020000
>>>
>>> rather than
>>>
>>>    #define KVM_GUESTDBG_BP_TYPE			0x00010000
>>>    #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
>>>    #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000
>>>
>>> :)
>>
>> Those bits enable or disable the features separately. You may also leave
>> both off if you like (and just use single stepping).
> 
> Ah, so these are global configuration bits, not per-breakpoint configuration?

Yes, the are meant for kvm_guest_debug.control on x86. I see that this
is apparently different for ppc. Those bits you cited just control the
general enabling of hard or soft BPs, not the activation of individual
one. That is encoded into the BP registers on x86.

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-03-14 12:22                   ` Jan Kiszka
  0 siblings, 0 replies; 72+ messages in thread
From: Jan Kiszka @ 2013-03-14 12:22 UTC (permalink / raw)
  To: Alexander Graf
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421

On 2013-03-14 13:19, Alexander Graf wrote:
> 
> On 14.03.2013, at 13:13, Jan Kiszka wrote:
> 
>> On 2013-03-14 13:09, Alexander Graf wrote:
>>>
>>> On 14.03.2013, at 12:57, Jan Kiszka wrote:
>>>
>>>> On 2013-03-14 12:54, Alexander Graf wrote:
>>>>>
>>>>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>>>>>
>>>>>>
>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>>>>> To: Bhushan Bharat-R65777
>>>>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>>>>> Bharat-R65777
>>>>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>>>>>
>>>>>>>
>>>>>>> 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.bhushan@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		0x00010000
>>>>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>>>>>
>>>>>>> You only need
>>>>>>>
>>>>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>>>>>
>>>>>>> In absence of the flag, it's a SW breakpoint.
>>>>>>
>>>>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>>>>>
>>>>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
>>>>
>>>> Different mechanics on x86: HW goes via debug registers and shows up as
>>>> INT1, SW is INT3 (plus guest patching done by user land).
>>>
>>> Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did
>>>
>>>    #define KVM_GUESTDBG_USE_SW_BP               0x00010000
>>>    #define KVM_GUESTDBG_USE_HW_BP               0x00020000
>>>
>>> rather than
>>>
>>>    #define KVM_GUESTDBG_BP_TYPE			0x00010000
>>>    #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
>>>    #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000
>>>
>>> :)
>>
>> Those bits enable or disable the features separately. You may also leave
>> both off if you like (and just use single stepping).
> 
> Ah, so these are global configuration bits, not per-breakpoint configuration?

Yes, the are meant for kvm_guest_debug.control on x86. I see that this
is apparently different for ppc. Those bits you cited just control the
general enabling of hard or soft BPs, not the activation of individual
one. That is encoded into the BP registers on x86.

Jan

-- 
Siemens AG, Corporate Technology, CT RTC ITP SDP-DE
Corporate Competence Center Embedded Linux

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
  2013-03-14 12:22                   ` Jan Kiszka
@ 2013-03-14 12:28                     ` Alexander Graf
  -1 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 12:28 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421


On 14.03.2013, at 13:22, Jan Kiszka wrote:

> On 2013-03-14 13:19, Alexander Graf wrote:
>> 
>> On 14.03.2013, at 13:13, Jan Kiszka wrote:
>> 
>>> On 2013-03-14 13:09, Alexander Graf wrote:
>>>> 
>>>> On 14.03.2013, at 12:57, Jan Kiszka wrote:
>>>> 
>>>>> On 2013-03-14 12:54, Alexander Graf wrote:
>>>>>> 
>>>>>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>>> -----Original Message-----
>>>>>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>>>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>>>>>> To: Bhushan Bharat-R65777
>>>>>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>>>>>> Bharat-R65777
>>>>>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 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.bhushan@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		0x00010000
>>>>>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>>>>>> 
>>>>>>>> You only need
>>>>>>>> 
>>>>>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>>>>>> 
>>>>>>>> In absence of the flag, it's a SW breakpoint.
>>>>>>> 
>>>>>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>>>>>> 
>>>>>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
>>>>> 
>>>>> Different mechanics on x86: HW goes via debug registers and shows up as
>>>>> INT1, SW is INT3 (plus guest patching done by user land).
>>>> 
>>>> Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did
>>>> 
>>>>   #define KVM_GUESTDBG_USE_SW_BP               0x00010000
>>>>   #define KVM_GUESTDBG_USE_HW_BP               0x00020000
>>>> 
>>>> rather than
>>>> 
>>>>   #define KVM_GUESTDBG_BP_TYPE			0x00010000
>>>>   #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
>>>>   #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000
>>>> 
>>>> :)
>>> 
>>> Those bits enable or disable the features separately. You may also leave
>>> both off if you like (and just use single stepping).
>> 
>> Ah, so these are global configuration bits, not per-breakpoint configuration?
> 
> Yes, the are meant for kvm_guest_debug.control on x86. I see that this
> is apparently different for ppc. Those bits you cited just control the
> general enabling of hard or soft BPs, not the activation of individual
> one. That is encoded into the BP registers on x86.

I suppose the same thing applies for PPC and I simply didn't realize it :).

So Bharat, if these bits are used for global configuration whether a specific debug type is routed to user space, having separate bits is the way to go.


Alex

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
@ 2013-03-14 12:28                     ` Alexander Graf
  0 siblings, 0 replies; 72+ messages in thread
From: Alexander Graf @ 2013-03-14 12:28 UTC (permalink / raw)
  To: Jan Kiszka
  Cc: Bhushan Bharat-R65777, kvm-ppc, kvm@vger.kernel.org list:Overall,
	Wood Scott-B07421


On 14.03.2013, at 13:22, Jan Kiszka wrote:

> On 2013-03-14 13:19, Alexander Graf wrote:
>> 
>> On 14.03.2013, at 13:13, Jan Kiszka wrote:
>> 
>>> On 2013-03-14 13:09, Alexander Graf wrote:
>>>> 
>>>> On 14.03.2013, at 12:57, Jan Kiszka wrote:
>>>> 
>>>>> On 2013-03-14 12:54, Alexander Graf wrote:
>>>>>> 
>>>>>> On 14.03.2013, at 05:42, Bhushan Bharat-R65777 wrote:
>>>>>> 
>>>>>>> 
>>>>>>> 
>>>>>>>> -----Original Message-----
>>>>>>>> From: Alexander Graf [mailto:agraf@suse.de]
>>>>>>>> Sent: Thursday, March 07, 2013 6:51 PM
>>>>>>>> To: Bhushan Bharat-R65777
>>>>>>>> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421; Bhushan
>>>>>>>> Bharat-R65777
>>>>>>>> Subject: Re: [PATCH 3/7] KVM: PPC: debug stub interface parameter defined
>>>>>>>> 
>>>>>>>> 
>>>>>>>> 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.bhushan@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		0x00010000
>>>>>>>>> +#define KVM_GUESTDBG_USE_HW_BP		0x00020000
>>>>>>>> 
>>>>>>>> You only need
>>>>>>>> 
>>>>>>>> #define KVM_GUESTDBG_HW_BP 0x00010000
>>>>>>>> 
>>>>>>>> In absence of the flag, it's a SW breakpoint.
>>>>>>> 
>>>>>>> We kept this for 2 reasons; 1) Same logic is applied for i386, so trying to keep consistent 2) better clarity.
>>>>>> 
>>>>>> Jan, was there any special reason to have 2 flags for HW/SW breakpoint on x86 rather than one bit that indicates which one is used?
>>>>> 
>>>>> Different mechanics on x86: HW goes via debug registers and shows up as
>>>>> INT1, SW is INT3 (plus guest patching done by user land).
>>>> 
>>>> Well, the same thing goes for us. What I'm asking is whether there is a specific reason (extensibility, oversight, taste, ...) that you did
>>>> 
>>>>   #define KVM_GUESTDBG_USE_SW_BP               0x00010000
>>>>   #define KVM_GUESTDBG_USE_HW_BP               0x00020000
>>>> 
>>>> rather than
>>>> 
>>>>   #define KVM_GUESTDBG_BP_TYPE			0x00010000
>>>>   #define KVM_GUESTDBG_BP_TYPE_SW		0x00010000
>>>>   #define KVM_GUESTDBG_BP_TYPE_HW		0x00000000
>>>> 
>>>> :)
>>> 
>>> Those bits enable or disable the features separately. You may also leave
>>> both off if you like (and just use single stepping).
>> 
>> Ah, so these are global configuration bits, not per-breakpoint configuration?
> 
> Yes, the are meant for kvm_guest_debug.control on x86. I see that this
> is apparently different for ppc. Those bits you cited just control the
> general enabling of hard or soft BPs, not the activation of individual
> one. That is encoded into the BP registers on x86.

I suppose the same thing applies for PPC and I simply didn't realize it :).

So Bharat, if these bits are used for global configuration whether a specific debug type is routed to user space, having separate bits is the way to go.


Alex


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
  2013-03-14 11:50         ` Alexander Graf
@ 2013-03-14 13:57           ` Bhushan Bharat-R65777
  -1 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14 13:57 UTC (permalink / raw)
  To: Alexander Graf; +Cc: kvm-ppc, kvm, Wood Scott-B07421



> -----Original Message-----
> From: kvm-ppc-owner@vger.kernel.org [mailto:kvm-ppc-owner@vger.kernel.org] On
> Behalf Of Alexander Graf
> Sent: Thursday, March 14, 2013 5:20 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421
> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
> 
> 
> On 14.03.2013, at 06:18, Bhushan Bharat-R65777 wrote:
> 
> >
> >
> >> -----Original Message-----
> >> From: Alexander Graf [mailto:agraf@suse.de]
> >> Sent: Thursday, March 07, 2013 7:09 PM
> >> To: Bhushan Bharat-R65777
> >> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421;
> >> Bhushan
> >> Bharat-R65777
> >> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
> >>
> >>
> >> 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.bhushan@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_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_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.
> >
> > ok
> >
> >>
> >>> +		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.
> >
> > Can there be the case when do breakpoint and debug interrupt happen?
> 
> At least not according to the code below :). If that's a valid case, then quite
> a bit of code would need to be remodeled. I'd say ignore the possibility for
> now.

ok

> 
> >
> >>
> >>> +
> >>> +	if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
> >>> +		run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
> >>> +	} else {
> >>> +		if (dbsr & (DBSR_DAC1W | DBSR_DAC2W))
> >>> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
> >>> +		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
> >>> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
> >>> +		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
> >>> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
> >>> +		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
> >>> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
> >>> +	}
> >>> +
> >>> +	return RESUME_HOST;
> >>> +}
> >>> +
> >>> static void kvmppc_fill_pt_regs(struct pt_regs *regs) {
> >>> 	ulong r1, ip, msr, lr;
> >>> @@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run,
> >>> struct
> >> kvm_vcpu *vcpu,
> >>> 	}
> >>>
> >>> 	case BOOKE_INTERRUPT_DEBUG: {
> >>> -		u32 dbsr;
> >>> -
> >>> -		vcpu->arch.pc = mfspr(SPRN_CSRR0);
> >>> -
> >>> -		/* clear IAC events in DBSR register */
> >>> -		dbsr = mfspr(SPRN_DBSR);
> >>> -		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
> >>> -		mtspr(SPRN_DBSR, dbsr);
> >>> -
> >>> -		run->exit_reason = KVM_EXIT_DEBUG;
> >>> +		r = kvmppc_handle_debug(run, vcpu);
> >>> +		if (r == RESUME_HOST) {
> >>> +			run->exit_reason = KVM_EXIT_DEBUG;
> >>> +		}
> >>> 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
> >>> -		r = RESUME_HOST;
> >>> 		break;
> >>> 	}
> >>>
> >>> @@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
> >>> 	kvmppc_set_msr(vcpu, 0);
> >>>
> >>> #ifndef CONFIG_KVM_BOOKE_HV
> >>> -	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
> >>> +	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
> >>> 	vcpu->arch.shadow_pid = 1;
> >>> 	vcpu->arch.shared->msr = 0;
> >>> #endif
> >>> @@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct
> >>> kvm_vcpu *vcpu,
> >> struct kvm_one_reg *reg)
> >>> 	return r;
> >>> }
> >>>
> >>> +#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
> >>> +#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
> >>> +
> >>> int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
> >>> 					 struct kvm_guest_debug *dbg)
> >>> {
> >>> -	return -EINVAL;
> >>> +
> >>> +	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
> >>> +		/* Clear All debug events */
> >>> +		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> >>> +		vcpu->guest_debug = 0;
> >>> +		return 0;
> >>> +	}
> >>> +
> >>> +	vcpu->guest_debug = dbg->control;
> >>> +	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> >>> +	/* Set DBCR0_EDM in guest visible DBCR0 register. */
> >>> +	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
> >>> +
> >>> +	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
> >>> +		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
> >>> +
> >>> +	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
> >>
> >> if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
> >>    /* Code below handles only HW breakpoints */
> >>    return 0;
> >> }
> >
> > ok
> >
> >>
> >>> +		struct kvmppc_booke_debug_reg *gdbgr =
> >>> +				&(vcpu->arch.shadow_dbg_reg);
> >>> +		int n, b = 0, w = 0;
> >>> +		const u32 bp_code[] = {
> >>> +			DBCR0_IAC1 | DBCR0_IDM,
> >>> +			DBCR0_IAC2 | DBCR0_IDM,
> >>> +			DBCR0_IAC3 | DBCR0_IDM,
> >>> +			DBCR0_IAC4 | DBCR0_IDM
> >>> +		};
> >>> +		const u32 wp_code[] = {
> >>> +			DBCR0_DAC1W | DBCR0_IDM,
> >>> +			DBCR0_DAC2W | DBCR0_IDM,
> >>> +			DBCR0_DAC1R | DBCR0_IDM,
> >>> +			DBCR0_DAC2R | DBCR0_IDM
> >>> +		};
> >>> +
> >>> +#ifndef CONFIG_KVM_BOOKE_HV
> >>
> >> Please no double negation.
> > You mean we should use
> > #ifdef CONFIG_KVM_BOOKE_HV
> > 		gdbgr->dbcr1 = 0;
> > 		gdbgr->dbcr2 = 0;
> > #else
> > 		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> > 				DBCR1_IAC3US | DBCR1_IAC4US;
> > 		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; #endif
> >
> >> Also, what is this about?
> >
> > This These bits says that IAC1-4 and DAC1-2 can happen when MSR.PR is set of
> not.
> > On BOOKE (e500v2); MSR.PR = 1 when guest is running. So we need to set
> > these bits On BOOKE-HV (e500mc+); MSR.PR = 0 when guest is running. So we do
> not need these bits to be set.
> 
> Ah, please add a comment explaining this here.

ok

> 
> >
> >>
> >>> +		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> >>> +				DBCR1_IAC3US | DBCR1_IAC4US;
> >>> +		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; #else
> >>> +		gdbgr->dbcr1 = 0;
> >>> +		gdbgr->dbcr2 = 0;
> >>> +#endif
> >>> +
> >>> +		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
> >>> +			u32 type = dbg->arch.bp[n].type;
> >>> +
> >>> +			if (!type)
> >>> +				break;
> >>> +
> >>> +			if (type & (KVMPPC_DEBUG_WATCH_READ |
> >>> +				    KVMPPC_DEBUG_WATCH_WRITE)) {
> >>> +				if (w < WP_NUM) {
> >>> +					if (type & KVMPPC_DEBUG_WATCH_READ)
> >>> +						gdbgr->dbcr0 |= wp_code[w + 2];
> >>> +					if (type & KVMPPC_DEBUG_WATCH_WRITE)
> >>> +						gdbgr->dbcr0 |= wp_code[w];
> >>> +					gdbgr->dac[w] = dbg->arch.bp[n].addr;
> >>> +					w++;
> >>> +				}
> >>> +			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
> >>> +				if (b < BP_NUM) {
> >>> +					gdbgr->dbcr0 |= bp_code[b];
> >>> +					gdbgr->iac[b] = dbg->arch.bp[n].addr;
> >>> +					b++;
> >>> +				}
> >>> +			}
> >>> +		}
> >>> +	}
> >>> +	return 0;
> >>> }
> >>>
> >>> int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct
> >>> kvm_fpu
> >>> *fpu) diff --git a/arch/powerpc/kvm/e500_emulate.c
> >>> b/arch/powerpc/kvm/e500_emulate.c index e78f353..83ac877 100644
> >>> --- a/arch/powerpc/kvm/e500_emulate.c
> >>> +++ b/arch/powerpc/kvm/e500_emulate.c
> >>> @@ -26,6 +26,7 @@
> >>> #define XOP_TLBRE   946
> >>> #define XOP_TLBWE   978
> >>> #define XOP_TLBILX  18
> >>> +#define XOP_EHPRIV  270
> >>>
> >>> #ifdef CONFIG_KVM_E500MC
> >>> static int dbell2prio(ulong param)
> >>> @@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run,
> >>> struct
> >> kvm_vcpu *vcpu,
> >>> 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
> >>> 			break;
> >>>
> >>> +		case XOP_EHPRIV:
> >>> +			emulated = EMULATE_EXIT_USER;
> >>> +			*advance = 0;
> >>> +			break;
> >>> +
> >>> 		default:
> >>> 			emulated = EMULATE_FAIL;
> >>> 		}
> >>> diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
> >>> index 1f89d26..f5fc6f5 100644
> >>> --- a/arch/powerpc/kvm/e500mc.c
> >>> +++ b/arch/powerpc/kvm/e500mc.c
> >>> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu
> >>> *vcpu) {
> >>> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> >>>
> >>> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
> >>> -				 SPRN_EPCR_DUVD;
> >>> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;
> >>
> >> Doesn't this route all debug events through the host?
> >
> > No; This means that debug events can occur in hypervisor state or not.
> >
> > EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.
> >
> > EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.
> >
> > So we allow debug events to occur in hypervisor state.
> 
> Why do we care about debug events in our entry/exit code and didn't care about
> them before?

We care for single stepping in guest to not step in KVM code.

> If anything, this is a completely separate patch, orthogonal to
> this patch series, and requires a good bit of explanation.

Not sure why you think separate patch; this patch add support for single stepping and also takes care that debug event does not comes in host when doing single stepping.

-Bharat

> 
> 
> Alex
> 
> > On lightweight exit we set ECPU.DUVD (if guest using debug facility) so debug
> events will not come during guest entry/exit code. On guest exit we clear this
> bit (after restoring host state) so hypervisor can use debug features.
> >
> > Thanks
> > -Bharat
> >>
> >>
> >> Alex
> >>
> >>> #ifdef CONFIG_64BIT
> >>> 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM; #endif
> >>> --
> >>> 1.7.0.4
> >>>
> >>>
> >>> --
> >>> To unsubscribe from this list: send the line "unsubscribe kvm-ppc"
> >>> in the body of a message to majordomo@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 majordomo@vger.kernel.org More majordomo info at
> http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
@ 2013-03-14 13:57           ` Bhushan Bharat-R65777
  0 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14 13:57 UTC (permalink / raw)
  To: Alexander Graf; +Cc: kvm-ppc, kvm, Wood Scott-B07421



> -----Original Message-----
> From: kvm-ppc-owner@vger.kernel.org [mailto:kvm-ppc-owner@vger.kernel.org] On
> Behalf Of Alexander Graf
> Sent: Thursday, March 14, 2013 5:20 PM
> To: Bhushan Bharat-R65777
> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421
> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
> 
> 
> On 14.03.2013, at 06:18, Bhushan Bharat-R65777 wrote:
> 
> >
> >
> >> -----Original Message-----
> >> From: Alexander Graf [mailto:agraf@suse.de]
> >> Sent: Thursday, March 07, 2013 7:09 PM
> >> To: Bhushan Bharat-R65777
> >> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421;
> >> Bhushan
> >> Bharat-R65777
> >> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
> >>
> >>
> >> 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.bhushan@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_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_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.
> >
> > ok
> >
> >>
> >>> +		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.
> >
> > Can there be the case when do breakpoint and debug interrupt happen?
> 
> At least not according to the code below :). If that's a valid case, then quite
> a bit of code would need to be remodeled. I'd say ignore the possibility for
> now.

ok

> 
> >
> >>
> >>> +
> >>> +	if (dbsr & (DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4)) {
> >>> +		run->debug.arch.status |= KVMPPC_DEBUG_BREAKPOINT;
> >>> +	} else {
> >>> +		if (dbsr & (DBSR_DAC1W | DBSR_DAC2W))
> >>> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_WRITE;
> >>> +		else if (dbsr & (DBSR_DAC1R | DBSR_DAC2R))
> >>> +			run->debug.arch.status |= KVMPPC_DEBUG_WATCH_READ;
> >>> +		if (dbsr & (DBSR_DAC1R | DBSR_DAC1W))
> >>> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[0];
> >>> +		else if (dbsr & (DBSR_DAC2R | DBSR_DAC2W))
> >>> +			run->debug.arch.address = vcpu->arch.shadow_dbg_reg.dac[1];
> >>> +	}
> >>> +
> >>> +	return RESUME_HOST;
> >>> +}
> >>> +
> >>> static void kvmppc_fill_pt_regs(struct pt_regs *regs) {
> >>> 	ulong r1, ip, msr, lr;
> >>> @@ -1110,18 +1164,11 @@ int kvmppc_handle_exit(struct kvm_run *run,
> >>> struct
> >> kvm_vcpu *vcpu,
> >>> 	}
> >>>
> >>> 	case BOOKE_INTERRUPT_DEBUG: {
> >>> -		u32 dbsr;
> >>> -
> >>> -		vcpu->arch.pc = mfspr(SPRN_CSRR0);
> >>> -
> >>> -		/* clear IAC events in DBSR register */
> >>> -		dbsr = mfspr(SPRN_DBSR);
> >>> -		dbsr &= DBSR_IAC1 | DBSR_IAC2 | DBSR_IAC3 | DBSR_IAC4;
> >>> -		mtspr(SPRN_DBSR, dbsr);
> >>> -
> >>> -		run->exit_reason = KVM_EXIT_DEBUG;
> >>> +		r = kvmppc_handle_debug(run, vcpu);
> >>> +		if (r = RESUME_HOST) {
> >>> +			run->exit_reason = KVM_EXIT_DEBUG;
> >>> +		}
> >>> 		kvmppc_account_exit(vcpu, DEBUG_EXITS);
> >>> -		r = RESUME_HOST;
> >>> 		break;
> >>> 	}
> >>>
> >>> @@ -1172,7 +1219,7 @@ int kvm_arch_vcpu_setup(struct kvm_vcpu *vcpu)
> >>> 	kvmppc_set_msr(vcpu, 0);
> >>>
> >>> #ifndef CONFIG_KVM_BOOKE_HV
> >>> -	vcpu->arch.shadow_msr = MSR_USER | MSR_DE | MSR_IS | MSR_DS;
> >>> +	vcpu->arch.shadow_msr = MSR_USER | MSR_IS | MSR_DS;
> >>> 	vcpu->arch.shadow_pid = 1;
> >>> 	vcpu->arch.shared->msr = 0;
> >>> #endif
> >>> @@ -1527,10 +1574,80 @@ int kvm_vcpu_ioctl_set_one_reg(struct
> >>> kvm_vcpu *vcpu,
> >> struct kvm_one_reg *reg)
> >>> 	return r;
> >>> }
> >>>
> >>> +#define BP_NUM	KVMPPC_BOOKE_IAC_NUM
> >>> +#define WP_NUM	KVMPPC_BOOKE_DAC_NUM
> >>> +
> >>> int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
> >>> 					 struct kvm_guest_debug *dbg)
> >>> {
> >>> -	return -EINVAL;
> >>> +
> >>> +	if (!(dbg->control & KVM_GUESTDBG_ENABLE)) {
> >>> +		/* Clear All debug events */
> >>> +		vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> >>> +		vcpu->guest_debug = 0;
> >>> +		return 0;
> >>> +	}
> >>> +
> >>> +	vcpu->guest_debug = dbg->control;
> >>> +	vcpu->arch.shadow_dbg_reg.dbcr0 = 0;
> >>> +	/* Set DBCR0_EDM in guest visible DBCR0 register. */
> >>> +	vcpu->arch.dbg_reg.dbcr0 = DBCR0_EDM;
> >>> +
> >>> +	if (vcpu->guest_debug & KVM_GUESTDBG_SINGLESTEP)
> >>> +		vcpu->arch.shadow_dbg_reg.dbcr0 |= DBCR0_IDM | DBCR0_IC;
> >>> +
> >>> +	if (vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP) {
> >>
> >> if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP)) {
> >>    /* Code below handles only HW breakpoints */
> >>    return 0;
> >> }
> >
> > ok
> >
> >>
> >>> +		struct kvmppc_booke_debug_reg *gdbgr > >>> +				&(vcpu->arch.shadow_dbg_reg);
> >>> +		int n, b = 0, w = 0;
> >>> +		const u32 bp_code[] = {
> >>> +			DBCR0_IAC1 | DBCR0_IDM,
> >>> +			DBCR0_IAC2 | DBCR0_IDM,
> >>> +			DBCR0_IAC3 | DBCR0_IDM,
> >>> +			DBCR0_IAC4 | DBCR0_IDM
> >>> +		};
> >>> +		const u32 wp_code[] = {
> >>> +			DBCR0_DAC1W | DBCR0_IDM,
> >>> +			DBCR0_DAC2W | DBCR0_IDM,
> >>> +			DBCR0_DAC1R | DBCR0_IDM,
> >>> +			DBCR0_DAC2R | DBCR0_IDM
> >>> +		};
> >>> +
> >>> +#ifndef CONFIG_KVM_BOOKE_HV
> >>
> >> Please no double negation.
> > You mean we should use
> > #ifdef CONFIG_KVM_BOOKE_HV
> > 		gdbgr->dbcr1 = 0;
> > 		gdbgr->dbcr2 = 0;
> > #else
> > 		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> > 				DBCR1_IAC3US | DBCR1_IAC4US;
> > 		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; #endif
> >
> >> Also, what is this about?
> >
> > This These bits says that IAC1-4 and DAC1-2 can happen when MSR.PR is set of
> not.
> > On BOOKE (e500v2); MSR.PR = 1 when guest is running. So we need to set
> > these bits On BOOKE-HV (e500mc+); MSR.PR = 0 when guest is running. So we do
> not need these bits to be set.
> 
> Ah, please add a comment explaining this here.

ok

> 
> >
> >>
> >>> +		gdbgr->dbcr1 = DBCR1_IAC1US | DBCR1_IAC2US |
> >>> +				DBCR1_IAC3US | DBCR1_IAC4US;
> >>> +		gdbgr->dbcr2 = DBCR2_DAC1US | DBCR2_DAC2US; #else
> >>> +		gdbgr->dbcr1 = 0;
> >>> +		gdbgr->dbcr2 = 0;
> >>> +#endif
> >>> +
> >>> +		for (n = 0; n < (BP_NUM + WP_NUM); n++) {
> >>> +			u32 type = dbg->arch.bp[n].type;
> >>> +
> >>> +			if (!type)
> >>> +				break;
> >>> +
> >>> +			if (type & (KVMPPC_DEBUG_WATCH_READ |
> >>> +				    KVMPPC_DEBUG_WATCH_WRITE)) {
> >>> +				if (w < WP_NUM) {
> >>> +					if (type & KVMPPC_DEBUG_WATCH_READ)
> >>> +						gdbgr->dbcr0 |= wp_code[w + 2];
> >>> +					if (type & KVMPPC_DEBUG_WATCH_WRITE)
> >>> +						gdbgr->dbcr0 |= wp_code[w];
> >>> +					gdbgr->dac[w] = dbg->arch.bp[n].addr;
> >>> +					w++;
> >>> +				}
> >>> +			} else if (type & KVMPPC_DEBUG_BREAKPOINT) {
> >>> +				if (b < BP_NUM) {
> >>> +					gdbgr->dbcr0 |= bp_code[b];
> >>> +					gdbgr->iac[b] = dbg->arch.bp[n].addr;
> >>> +					b++;
> >>> +				}
> >>> +			}
> >>> +		}
> >>> +	}
> >>> +	return 0;
> >>> }
> >>>
> >>> int kvm_arch_vcpu_ioctl_get_fpu(struct kvm_vcpu *vcpu, struct
> >>> kvm_fpu
> >>> *fpu) diff --git a/arch/powerpc/kvm/e500_emulate.c
> >>> b/arch/powerpc/kvm/e500_emulate.c index e78f353..83ac877 100644
> >>> --- a/arch/powerpc/kvm/e500_emulate.c
> >>> +++ b/arch/powerpc/kvm/e500_emulate.c
> >>> @@ -26,6 +26,7 @@
> >>> #define XOP_TLBRE   946
> >>> #define XOP_TLBWE   978
> >>> #define XOP_TLBILX  18
> >>> +#define XOP_EHPRIV  270
> >>>
> >>> #ifdef CONFIG_KVM_E500MC
> >>> static int dbell2prio(ulong param)
> >>> @@ -130,6 +131,11 @@ int kvmppc_core_emulate_op(struct kvm_run *run,
> >>> struct
> >> kvm_vcpu *vcpu,
> >>> 			emulated = kvmppc_e500_emul_tlbivax(vcpu, ea);
> >>> 			break;
> >>>
> >>> +		case XOP_EHPRIV:
> >>> +			emulated = EMULATE_EXIT_USER;
> >>> +			*advance = 0;
> >>> +			break;
> >>> +
> >>> 		default:
> >>> 			emulated = EMULATE_FAIL;
> >>> 		}
> >>> diff --git a/arch/powerpc/kvm/e500mc.c b/arch/powerpc/kvm/e500mc.c
> >>> index 1f89d26..f5fc6f5 100644
> >>> --- a/arch/powerpc/kvm/e500mc.c
> >>> +++ b/arch/powerpc/kvm/e500mc.c
> >>> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu
> >>> *vcpu) {
> >>> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> >>>
> >>> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI | \
> >>> -				 SPRN_EPCR_DUVD;
> >>> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS | SPRN_EPCR_DGTMI;
> >>
> >> Doesn't this route all debug events through the host?
> >
> > No; This means that debug events can occur in hypervisor state or not.
> >
> > EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.
> >
> > EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.
> >
> > So we allow debug events to occur in hypervisor state.
> 
> Why do we care about debug events in our entry/exit code and didn't care about
> them before?

We care for single stepping in guest to not step in KVM code.

> If anything, this is a completely separate patch, orthogonal to
> this patch series, and requires a good bit of explanation.

Not sure why you think separate patch; this patch add support for single stepping and also takes care that debug event does not comes in host when doing single stepping.

-Bharat

> 
> 
> Alex
> 
> > On lightweight exit we set ECPU.DUVD (if guest using debug facility) so debug
> events will not come during guest entry/exit code. On guest exit we clear this
> bit (after restoring host state) so hypervisor can use debug features.
> >
> > Thanks
> > -Bharat
> >>
> >>
> >> Alex
> >>
> >>> #ifdef CONFIG_64BIT
> >>> 	vcpu->arch.shadow_epcr |= SPRN_EPCR_ICM; #endif
> >>> --
> >>> 1.7.0.4
> >>>
> >>>
> >>> --
> >>> To unsubscribe from this list: send the line "unsubscribe kvm-ppc"
> >>> in the body of a message to majordomo@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 majordomo@vger.kernel.org More majordomo info at
> http://vger.kernel.org/majordomo-info.html



^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit
  2013-03-14 11:52         ` Alexander Graf
  (?)
@ 2013-03-14 14:44         ` Bhushan Bharat-R65777
  -1 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14 14:44 UTC (permalink / raw)
  To: Alexander Graf, Wood Scott-B07421; +Cc: kvm-ppc, kvm

> >> -----Original Message-----
> >> From: Alexander Graf [mailto:agraf@suse.de]
> >> Sent: Thursday, March 07, 2013 6:56 PM
> >> To: Bhushan Bharat-R65777
> >> Cc: kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-B07421;
> >> Bhushan
> >> Bharat-R65777
> >> Subject: Re: [PATCH 4/7] booke: Save and restore debug registers on
> >> guest entry and exit
> >>
> >>
> >> 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?
> >
> >
> > One of the reason for not doing this is that the KVM is a host kernel
> > module and let this be debugged by host (I do not this how much useful this is
> :)) So I am not able to recall the specific reason, maybe we have just coded
> this like this and tried to keep overhead as low as possible by switching
> registers only when they are used.
> 
> My point is that the overhead is _higher_ this way, because we need to do checks
> and switches on every guest entry/exit, which happens a _lot_ more often than a
> host context switch.
> 
> > As we discussed before, we can keep this option open for future.
> 
> What future? Just ignore debug events in the entry/exit code path and suddenly a
> lot of the code becomes a lot easier.

Just to summarize what we agreed upon:

- Save/restore will happen on vcpu_get()/vcpu_put(). This will happen only if guest is using debug registers. Probably using a flag to indicate guest is using debug APU. 
- On debug register access from QEMU, always set value in h/w debug register.
- On guest access of debug register, also save xxx h/w register in vcpu->host_debug_reg.xxx and load guest provided value in h/w debug register, ensure this happen on first access only, probably all debug registers once debug events enabled in dbcr0. Direct access from guest was not part of this patchset and support for this will be done separately.

Thanks
-Bharat

> 
> 
> Alex
> 

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
  2013-03-14 13:57           ` Bhushan Bharat-R65777
@ 2013-03-14 16:05             ` Scott Wood
  -1 siblings, 0 replies; 72+ messages in thread
From: Scott Wood @ 2013-03-14 16:05 UTC (permalink / raw)
  To: Bhushan Bharat-R65777; +Cc: Alexander Graf, kvm-ppc, kvm, Wood Scott-B07421

On 03/14/2013 08:57:53 AM, Bhushan Bharat-R65777 wrote:
> > >>> diff --git a/arch/powerpc/kvm/e500mc.c  
> b/arch/powerpc/kvm/e500mc.c
> > >>> index 1f89d26..f5fc6f5 100644
> > >>> --- a/arch/powerpc/kvm/e500mc.c
> > >>> +++ b/arch/powerpc/kvm/e500mc.c
> > >>> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu
> > >>> *vcpu) {
> > >>> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> > >>>
> > >>> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS |  
> SPRN_EPCR_DGTMI | \
> > >>> -				 SPRN_EPCR_DUVD;
> > >>> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS |  
> SPRN_EPCR_DGTMI;
> > >>
> > >> Doesn't this route all debug events through the host?
> > >
> > > No; This means that debug events can occur in hypervisor state or  
> not.
> > >
> > > EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.
> > >
> > > EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.
> > >
> > > So we allow debug events to occur in hypervisor state.
> >
> > Why do we care about debug events in our entry/exit code and didn't  
> care about
> > them before?
> 
> We care for single stepping in guest to not step in KVM code.
> 
> > If anything, this is a completely separate patch, orthogonal to
> > this patch series, and requires a good bit of explanation.
> 
> Not sure why you think separate patch; this patch add support for  
> single stepping and also takes care that debug event does not comes  
> in host when doing single stepping.

How does *removing* DUVD ensure that?

-Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
@ 2013-03-14 16:05             ` Scott Wood
  0 siblings, 0 replies; 72+ messages in thread
From: Scott Wood @ 2013-03-14 16:05 UTC (permalink / raw)
  To: Bhushan Bharat-R65777; +Cc: Alexander Graf, kvm-ppc, kvm, Wood Scott-B07421

On 03/14/2013 08:57:53 AM, Bhushan Bharat-R65777 wrote:
> > >>> diff --git a/arch/powerpc/kvm/e500mc.c  
> b/arch/powerpc/kvm/e500mc.c
> > >>> index 1f89d26..f5fc6f5 100644
> > >>> --- a/arch/powerpc/kvm/e500mc.c
> > >>> +++ b/arch/powerpc/kvm/e500mc.c
> > >>> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu
> > >>> *vcpu) {
> > >>> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> > >>>
> > >>> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS |  
> SPRN_EPCR_DGTMI | \
> > >>> -				 SPRN_EPCR_DUVD;
> > >>> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS |  
> SPRN_EPCR_DGTMI;
> > >>
> > >> Doesn't this route all debug events through the host?
> > >
> > > No; This means that debug events can occur in hypervisor state or  
> not.
> > >
> > > EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.
> > >
> > > EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.
> > >
> > > So we allow debug events to occur in hypervisor state.
> >
> > Why do we care about debug events in our entry/exit code and didn't  
> care about
> > them before?
> 
> We care for single stepping in guest to not step in KVM code.
> 
> > If anything, this is a completely separate patch, orthogonal to
> > this patch series, and requires a good bit of explanation.
> 
> Not sure why you think separate patch; this patch add support for  
> single stepping and also takes care that debug event does not comes  
> in host when doing single stepping.

How does *removing* DUVD ensure that?

-Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
  2013-03-14 16:05             ` Scott Wood
  (?)
@ 2013-03-14 16:11             ` Bhushan Bharat-R65777
  -1 siblings, 0 replies; 72+ messages in thread
From: Bhushan Bharat-R65777 @ 2013-03-14 16:11 UTC (permalink / raw)
  To: Wood Scott-B07421; +Cc: Alexander Graf, kvm-ppc, kvm



> -----Original Message-----
> From: Wood Scott-B07421
> Sent: Thursday, March 14, 2013 9:36 PM
> To: Bhushan Bharat-R65777
> Cc: Alexander Graf; kvm-ppc@vger.kernel.org; kvm@vger.kernel.org; Wood Scott-
> B07421
> Subject: Re: [PATCH 7/7] KVM: PPC: Add userspace debug stub support
> 
> On 03/14/2013 08:57:53 AM, Bhushan Bharat-R65777 wrote:
> > > >>> diff --git a/arch/powerpc/kvm/e500mc.c
> > b/arch/powerpc/kvm/e500mc.c
> > > >>> index 1f89d26..f5fc6f5 100644
> > > >>> --- a/arch/powerpc/kvm/e500mc.c
> > > >>> +++ b/arch/powerpc/kvm/e500mc.c
> > > >>> @@ -182,8 +182,7 @@ int kvmppc_core_vcpu_setup(struct kvm_vcpu
> > > >>> *vcpu) {
> > > >>> 	struct kvmppc_vcpu_e500 *vcpu_e500 = to_e500(vcpu);
> > > >>>
> > > >>> -	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS |
> > SPRN_EPCR_DGTMI | \
> > > >>> -				 SPRN_EPCR_DUVD;
> > > >>> +	vcpu->arch.shadow_epcr = SPRN_EPCR_DSIGS |
> > SPRN_EPCR_DGTMI;
> > > >>
> > > >> Doesn't this route all debug events through the host?
> > > >
> > > > No; This means that debug events can occur in hypervisor state or
> > not.
> > > >
> > > > EPCR.DUVD = 0 ; Debug events can occur in the hypervisor state.
> > > >
> > > > EPCR.DUVD = 1 ; Debug events cannot occur in the hypervisor state.
> > > >
> > > > So we allow debug events to occur in hypervisor state.
> > >
> > > Why do we care about debug events in our entry/exit code and didn't
> > care about
> > > them before?
> >
> > We care for single stepping in guest to not step in KVM code.
> >
> > > If anything, this is a completely separate patch, orthogonal to this
> > > patch series, and requires a good bit of explanation.
> >
> > Not sure why you think separate patch; this patch add support for
> > single stepping and also takes care that debug event does not comes in
> > host when doing single stepping.
> 
> How does *removing* DUVD ensure that?

By default we clear DUVD, so debug events can come in hypervisor state. But on lightweight exit, when restoring guest debug context, we set DUVD so the debug interrupt will not come in hypervisor state as debug resource are taken by guest.

On guest exit, when restoring the host context we clear DUVD so now debug resource are having host context.

With proposed change of save and restore on vcpu_get/vcpu_put this switching witching will be done in vcpu_get/set().

Thanks
-Bharat

> 
> -Scott

^ permalink raw reply	[flat|nested] 72+ messages in thread

end of thread, other threads:[~2013-03-14 16:11 UTC | newest]

Thread overview: 72+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-02-28  4:13 [PATCH 0/7] KVM :PPC: Userspace Debug support Bharat Bhushan
2013-02-28  4:25 ` Bharat Bhushan
2013-02-28  4:13 ` [PATCH 1/7] KVM: PPC: booke: Added debug handler Bharat Bhushan
2013-02-28  4:25   ` Bharat Bhushan
2013-03-07 14:02   ` Alexander Graf
2013-03-07 14:02     ` Alexander Graf
2013-02-28  4:13 ` [PATCH 2/7] Added ONE_REG interface for debug instruction Bharat Bhushan
2013-02-28  4:25   ` Bharat Bhushan
2013-02-28 16:23   ` Scott Wood
2013-02-28 16:23     ` Scott Wood
2013-02-28 16:52     ` Alexander Graf
2013-02-28 16:52       ` Alexander Graf
2013-03-01  5:28       ` Bhushan Bharat-R65777
2013-03-01  5:28         ` Bhushan Bharat-R65777
2013-03-07 13:07   ` Alexander Graf
2013-03-07 13:07     ` Alexander Graf
2013-03-14  4:30     ` Bhushan Bharat-R65777
2013-03-14 11:56       ` Alexander Graf
2013-03-14 11:56         ` Alexander Graf
2013-02-28  4:13 ` [PATCH 3/7] KVM: PPC: debug stub interface parameter defined Bharat Bhushan
2013-02-28  4:25   ` Bharat Bhushan
2013-03-07 13:20   ` Alexander Graf
2013-03-07 13:20     ` Alexander Graf
2013-03-14  4:42     ` Bhushan Bharat-R65777
2013-03-14 11:54       ` Alexander Graf
2013-03-14 11:54         ` Alexander Graf
2013-03-14 11:57         ` Jan Kiszka
2013-03-14 11:57           ` Jan Kiszka
2013-03-14 12:09           ` Alexander Graf
2013-03-14 12:09             ` Alexander Graf
2013-03-14 12:13             ` Jan Kiszka
2013-03-14 12:13               ` Jan Kiszka
2013-03-14 12:19               ` Alexander Graf
2013-03-14 12:19                 ` Alexander Graf
2013-03-14 12:22                 ` Jan Kiszka
2013-03-14 12:22                   ` Jan Kiszka
2013-03-14 12:28                   ` Alexander Graf
2013-03-14 12:28                     ` Alexander Graf
2013-02-28  4:13 ` [PATCH 4/7] booke: Save and restore debug registers on guest entry and exit Bharat Bhushan
2013-02-28  4:25   ` Bharat Bhushan
2013-03-07 13:25   ` Alexander Graf
2013-03-07 13:25     ` Alexander Graf
2013-03-14  4:50     ` Bhushan Bharat-R65777
2013-03-14 11:52       ` Alexander Graf
2013-03-14 11:52         ` Alexander Graf
2013-03-14 14:44         ` Bhushan Bharat-R65777
2013-02-28  4:13 ` [PATCH 5/7] bookehv: " Bharat Bhushan
2013-02-28  4:25   ` Bharat Bhushan
2013-02-28  4:13 ` [PATCH 6/7] Rename EMULATE_DO_PAPR to EMULATE_EXIT_USER Bharat Bhushan
2013-02-28  4:25   ` Bharat Bhushan
2013-02-28 16:31   ` Scott Wood
2013-02-28 16:31     ` Scott Wood
2013-02-28 16:51     ` Alexander Graf
2013-02-28 16:51       ` Alexander Graf
2013-02-28 16:53       ` Scott Wood
2013-02-28 16:53         ` Scott Wood
2013-03-07 10:47         ` Alexander Graf
2013-03-07 10:47           ` Alexander Graf
2013-03-14  5:59           ` Bhushan Bharat-R65777
2013-02-28  4:13 ` [PATCH 7/7] KVM: PPC: Add userspace debug stub support Bharat Bhushan
2013-02-28  4:25   ` Bharat Bhushan
2013-03-07 13:39   ` Alexander Graf
2013-03-07 13:39     ` Alexander Graf
2013-03-14  5:18     ` Bhushan Bharat-R65777
2013-03-14  5:18       ` Bhushan Bharat-R65777
2013-03-14 11:50       ` Alexander Graf
2013-03-14 11:50         ` Alexander Graf
2013-03-14 13:57         ` Bhushan Bharat-R65777
2013-03-14 13:57           ` Bhushan Bharat-R65777
2013-03-14 16:05           ` Scott Wood
2013-03-14 16:05             ` Scott Wood
2013-03-14 16:11             ` Bhushan Bharat-R65777

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.