Skip to contentSkip to conversation

powerpc/kvm: support to handle sw breakpoint

PATCH Superseded Madhavan Srinivasan 2 participants 4 messages Aug 20, 2014 – Aug 23, 2014

Subsystems (3)

v4 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 powerpc/kvm: support to handle sw breakpoint

This patch adds kernel side support for software breakpoint. Design is that, by using an illegal instruction, we trap to hypervisor via Emulation Assistance interrupt, where we check for the illegal instruction and accordingly we return to Host or Guest. Patch also adds support for software breakpoint in PR KVM.

Changes v3->v4:
Made changes to code comments and removed #define of zero opcode Added a new function to handle the debug instruction emulation in book3s_hv Rebased the code to latest upstream source.

Changes v2->v3:
Changed the debug instructions. Using the all zero opcode in the instruction word
as illegal instruction as mentioned in Power ISA instead of ABS
Removed reg updated in emulation assist and added a call to
kvmppc_emulate_instruction for reg update.

Changes v1->v2:

Moved the debug instruction #def to kvm_book3s.h. This way PR_KVM can also share it. Added code to use KVM get one reg infrastructure to get debug opcode. Updated emulate.c to include emulation of debug instruction incase of PR_KVM. Made changes to commit message.

---
 arch/powerpc/include/asm/kvm_book3s.h |  7 +++++++
 arch/powerpc/kvm/book3s.c             |  3 ++-
 arch/powerpc/kvm/book3s_hv.c          | 32 ++++++++++++++++++++++++++++++--
 arch/powerpc/kvm/book3s_pr.c          |  3 +++
 arch/powerpc/kvm/emulate.c            | 11 +++++++++++
 5 files changed, 53 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +7 -0
index 6acf0c2..a1944f8 100644
@@ -24,6 +24,13 @@
 #include <linux/kvm_host.h>
 #include <asm/kvm_book3s_asm.h>
 
+/*
+ * KVMPPC_INST_BOOK3S_DEBUG is debug Instruction for supporting Software Breakpoint.
+ * Based on PowerISA v2.07, Instruction with primary opcode 0 will be treated as illegal
+ * instruction.
+ */
+#define KVMPPC_INST_BOOK3S_DEBUG	0x00dddd00
+
 struct kvmppc_bat {
 	u64 raw;
 	u32 bepi;
arch/powerpc/kvm/book3s.c +2 -1
index dd03f6b..00e9c9f 100644
@@ -778,7 +778,8 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					struct kvm_guest_debug *dbg)
 {
-	return -EINVAL;
+	vcpu->guest_debug = dbg->control;
+	return 0;
 }
 
 void kvmppc_decrementer_func(unsigned long data)
arch/powerpc/kvm/book3s_hv.c +30 -2
index 27cced9..0a92e45 100644
@@ -725,6 +725,14 @@ static int kvmppc_hcall_impl_hv(unsigned long cmd)
 	return kvmppc_hcall_impl_hv_realmode(cmd);
 }
 
+static int kvmppc_emulate_debug_instruction_hv(struct kvm_run *run,
+					struct kvm_vcpu *vcpu)
+{
+	run->exit_reason = KVM_EXIT_DEBUG;
+	run->debug.arch.address = kvmppc_get_pc(vcpu);
+	return 0;
+}
+
 static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
 				 struct task_struct *tsk)
 {
@@ -811,9 +819,26 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	 * we don't emulate any guest instructions at this stage.
 	 */
 	case BOOK3S_INTERRUPT_H_EMUL_ASSIST:
-		kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
-		r = RESUME_GUEST;
+	{
+		u32 last_inst;
+		if(kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst) !=
+					EMULATE_DONE) {
+			/*
+			 * Fetch failed, so return to guest and
+			 * try executing it again.
+			 */
+			r = RESUME_GUEST;
+		} else {
+			if (last_inst == KVMPPC_INST_BOOK3S_DEBUG) {
+				kvmppc_emulate_debug_instruction_hv(run, vcpu);
+				r = RESUME_HOST;
+			} else {
+				kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
+				r = RESUME_GUEST;
+			}
+		}
 		break;
+	}
 	/*
 	 * This occurs if the guest (kernel or userspace), does something that
 	 * is prohibited by HFSCR.  We just generate a program interrupt to
@@ -922,6 +947,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	long int i;
 
 	switch (id) {
+	case KVM_REG_PPC_DEBUG_INST:
+		*val = get_reg_val(id, KVMPPC_INST_BOOK3S_DEBUG);
+		break;
 	case KVM_REG_PPC_HIOR:
 		*val = get_reg_val(id, 0);
 		break;
arch/powerpc/kvm/book3s_pr.c +3 -0
index faffb27..cd2a39d 100644
@@ -1319,6 +1319,9 @@ static int kvmppc_get_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,
 	int r = 0;
 
 	switch (id) {
+	case KVM_REG_PPC_DEBUG_INST:
+		*val = get_reg_val(id, KVMPPC_INST_BOOK3S_DEBUG);
+		break;
 	case KVM_REG_PPC_HIOR:
 		*val = get_reg_val(id, to_book3s(vcpu)->hior);
 		break;
arch/powerpc/kvm/emulate.c +11 -0
index e96b50d..68f38b2 100644
@@ -274,6 +274,17 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
 		}
 		break;
 
+	case 0:
+		/*
+		 * Instruction with primary opcode 0. Based on PowerISA
+		 * these are illegal instructions.
+		 */
+		run->exit_reason = KVM_EXIT_DEBUG;
+		run->debug.arch.address = kvmppc_get_pc(vcpu);
+		emulated = EMULATE_EXIT_USER;
+		advance = 0;
+		break;
+
 	default:
 		emulated = EMULATE_FAIL;
 	}
Signature · 1 line
1.7.11.4
#1 lore raw
Quoted 38 lines · Madhavan Srinivasan

This patch adds kernel side support for software breakpoint. Design is that, by using an illegal instruction, we trap to hypervisor via Emulation Assistance interrupt, where we check for the illegal instruction and accordingly we return to Host or Guest. Patch also adds support for software breakpoint in PR KVM.

Changes v3->v4:
Made changes to code comments and removed #define of zero opcode Added a new function to handle the debug instruction emulation in book3s_hv Rebased the code to latest upstream source.

Changes v2->v3:
Changed the debug instructions. Using the all zero opcode in the instruction word
as illegal instruction as mentioned in Power ISA instead of ABS
Removed reg updated in emulation assist and added a call to
kvmppc_emulate_instruction for reg update.

Changes v1->v2:

Moved the debug instruction #def to kvm_book3s.h. This way PR_KVM can also share it. Added code to use KVM get one reg infrastructure to get debug opcode. Updated emulate.c to include emulation of debug instruction incase of PR_KVM. Made changes to commit message.

---
 arch/powerpc/include/asm/kvm_book3s.h |  7 +++++++
 arch/powerpc/kvm/book3s.c             |  3 ++-
 arch/powerpc/kvm/book3s_hv.c          | 32 ++++++++++++++++++++++++++++++--
 arch/powerpc/kvm/book3s_pr.c          |  3 +++
 arch/powerpc/kvm/emulate.c            | 11 +++++++++++
 5 files changed, 53 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -0
index 6acf0c2..a1944f8 100644

arch/powerpc/include/asm/kvm_book3s.h line 32

Quoted 9 lines
arch/powerpc/include/asm/kvm_book3s.h +6 -0
@@ -24,6 +24,13 @@
 #include <linux/kvm_host.h>
 #include <asm/kvm_book3s_asm.h>
 
+/*
+ * KVMPPC_INST_BOOK3S_DEBUG is debug Instruction for supporting Software Breakpoint.
+ * Based on PowerISA v2.07, Instruction with primary opcode 0 will be treated as illegal
+ * instruction.
+ */
+#define KVMPPC_INST_BOOK3S_DEBUG	0x00dddd00

Please change the BookE version of this as well, put the define in a common header and use a non book specific name.

Quoted 38 lines
arch/powerpc/include/asm/kvm_book3s.h +1 -0
+
 struct kvmppc_bat {
 	u64 raw;
 	u32 bepi;
arch/powerpc/kvm/book3s.c +2 -1
index dd03f6b..00e9c9f 100644
@@ -778,7 +778,8 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					struct kvm_guest_debug *dbg)
 {
-	return -EINVAL;
+	vcpu->guest_debug = dbg->control;
+	return 0;
 }
 
 void kvmppc_decrementer_func(unsigned long data)
arch/powerpc/kvm/book3s_hv.c +8 -0
index 27cced9..0a92e45 100644
@@ -725,6 +725,14 @@ static int kvmppc_hcall_impl_hv(unsigned long cmd)
 	return kvmppc_hcall_impl_hv_realmode(cmd);
 }
 
+static int kvmppc_emulate_debug_instruction_hv(struct kvm_run *run,
+					struct kvm_vcpu *vcpu)
+{
+	run->exit_reason = KVM_EXIT_DEBUG;
+	run->debug.arch.address = kvmppc_get_pc(vcpu);
+	return 0;
+}
+
 static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
 				 struct task_struct *tsk)
 {

arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 819

Quoted 1 line
arch/powerpc/kvm/book3s_hv.c +0 -0
@@ -811,9 +819,26 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	 * we don't emulate any guest instructions at this stage.

This comment is no longer true, it should get changed.

arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 825

Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +4 -2
 	 */
 	case BOOK3S_INTERRUPT_H_EMUL_ASSIST:
-		kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
-		r = RESUME_GUEST;
+	{
+		u32 last_inst;
+		if(kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst) !=
+					EMULATE_DONE) {

Please only do this if debugging is active.

Quoted 48 lines
arch/powerpc/kvm/book3s_hv.c +18 -0
+			/*
+			 * Fetch failed, so return to guest and
+			 * try executing it again.
+			 */
+			r = RESUME_GUEST;
+		} else {
+			if (last_inst == KVMPPC_INST_BOOK3S_DEBUG) {
+				kvmppc_emulate_debug_instruction_hv(run, vcpu);
+				r = RESUME_HOST;
+			} else {
+				kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
+				r = RESUME_GUEST;
+			}
+		}
 		break;
+	}
 	/*
 	 * This occurs if the guest (kernel or userspace), does something that
 	 * is prohibited by HFSCR.  We just generate a program interrupt to
@@ -922,6 +947,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	long int i;
 
 	switch (id) {
+	case KVM_REG_PPC_DEBUG_INST:
+		*val = get_reg_val(id, KVMPPC_INST_BOOK3S_DEBUG);
+		break;
 	case KVM_REG_PPC_HIOR:
 		*val = get_reg_val(id, 0);
 		break;
arch/powerpc/kvm/book3s_pr.c +3 -0
index faffb27..cd2a39d 100644
@@ -1319,6 +1319,9 @@ static int kvmppc_get_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,
 	int r = 0;
 
 	switch (id) {
+	case KVM_REG_PPC_DEBUG_INST:
+		*val = get_reg_val(id, KVMPPC_INST_BOOK3S_DEBUG);
+		break;
 	case KVM_REG_PPC_HIOR:
 		*val = get_reg_val(id, to_book3s(vcpu)->hior);
 		break;
arch/powerpc/kvm/emulate.c +0 -0
index e96b50d..68f38b2 100644

arch/powerpc/kvm/emulate.c int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) · line 282

Quoted 9 lines
arch/powerpc/kvm/emulate.c +6 -0
@@ -274,6 +274,17 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
 		}
 		break;
 
+	case 0:
+		/*
+		 * Instruction with primary opcode 0. Based on PowerISA
+		 * these are illegal instructions.
+		 */
+		run->exit_reason = KVM_EXIT_DEBUG;

This is wrong. We need to check that the instruction is 0x00dddd00. Any other op0 instruction should trigger an invalid instruction trap.

Alex

Quoted 9 lines
arch/powerpc/kvm/emulate.c +5 -0
+		run->debug.arch.address = kvmppc_get_pc(vcpu);
+		emulated = EMULATE_EXIT_USER;
+		advance = 0;
+		break;
+
 	default:
 		emulated = EMULATE_FAIL;
 	}
#2 lore raw
Quoted 44 lines · Alexander Graf
Quoted 41 lines · Madhavan Srinivasan

This patch adds kernel side support for software breakpoint. Design is that, by using an illegal instruction, we trap to hypervisor via Emulation Assistance interrupt, where we check for the illegal instruction and accordingly we return to Host or Guest. Patch also adds support for software breakpoint in PR KVM.

Changes v3->v4:
Made changes to code comments and removed #define of zero opcode Added a new function to handle the debug instruction emulation in book3s_hv Rebased the code to latest upstream source.

Changes v2->v3:
Changed the debug instructions. Using the all zero opcode in the instruction word
as illegal instruction as mentioned in Power ISA instead of ABS
Removed reg updated in emulation assist and added a call to
kvmppc_emulate_instruction for reg update.

Changes v1->v2:

Moved the debug instruction #def to kvm_book3s.h. This way PR_KVM can also share it. Added code to use KVM get one reg infrastructure to get debug opcode. Updated emulate.c to include emulation of debug instruction incase of PR_KVM. Made changes to commit message.

---
 arch/powerpc/include/asm/kvm_book3s.h |  7 +++++++
 arch/powerpc/kvm/book3s.c             |  3 ++-
 arch/powerpc/kvm/book3s_hv.c          | 32 ++++++++++++++++++++++++++++++--
 arch/powerpc/kvm/book3s_pr.c          |  3 +++
 arch/powerpc/kvm/emulate.c            | 11 +++++++++++
 5 files changed, 53 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -0
index 6acf0c2..a1944f8 100644
@@ -24,6 +24,13 @@
 #include <linux/kvm_host.h>
 #include <asm/kvm_book3s_asm.h>
 
Quoted 10 lines

arch/powerpc/include/asm/kvm_book3s.h line 32

Quoted 6 lines
arch/powerpc/include/asm/kvm_book3s.h +6 -0
+/*
+ * KVMPPC_INST_BOOK3S_DEBUG is debug Instruction for supporting Software Breakpoint.
+ * Based on PowerISA v2.07, Instruction with primary opcode 0 will be treated as illegal
+ * instruction.
+ */
+#define KVMPPC_INST_BOOK3S_DEBUG	0x00dddd00

Please change the BookE version of this as well, put the define in a common header and use a non book specific name.

I first wanted to get the server side in and then take up this, but i can do it with this, just concerned incase of booke testing :(

Quoted 26 lines
Quoted 26 lines
arch/powerpc/include/asm/kvm_book3s.h +1 -0
+
 struct kvmppc_bat {
 	u64 raw;
 	u32 bepi;
arch/powerpc/kvm/book3s.c +2 -1
index dd03f6b..00e9c9f 100644
@@ -778,7 +778,8 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
 					struct kvm_guest_debug *dbg)
 {
-	return -EINVAL;
+	vcpu->guest_debug = dbg->control;
+	return 0;
 }
 
 void kvmppc_decrementer_func(unsigned long data)
arch/powerpc/kvm/book3s_hv.c +0 -0
index 27cced9..0a92e45 100644
@@ -725,6 +725,14 @@ static int kvmppc_hcall_impl_hv(unsigned long cmd)
 	return kvmppc_hcall_impl_hv_realmode(cmd);
 }
 
Quoted 16 lines

arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 819

Quoted 13 lines
arch/powerpc/kvm/book3s_hv.c +8 -0
+static int kvmppc_emulate_debug_instruction_hv(struct kvm_run *run,
+					struct kvm_vcpu *vcpu)
+{
+	run->exit_reason = KVM_EXIT_DEBUG;
+	run->debug.arch.address = kvmppc_get_pc(vcpu);
+	return 0;
+}
+
 static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
 				 struct task_struct *tsk)
 {
@@ -811,9 +819,26 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	 * we don't emulate any guest instructions at this stage.

This comment is no longer true, it should get changed.

Will change it.

Quoted 11 lines

arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 825

Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +4 -2
 	 */
 	case BOOK3S_INTERRUPT_H_EMUL_ASSIST:
-		kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
-		r = RESUME_GUEST;
+	{
+		u32 last_inst;
+		if(kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst) !=
+					EMULATE_DONE) {

Please only do this if debugging is active.

Ok sure. But i will add in the else part of the check. Since we do the instruction check there.

Quoted 51 lines
Quoted 51 lines
arch/powerpc/kvm/book3s_hv.c +18 -0
+			/*
+			 * Fetch failed, so return to guest and
+			 * try executing it again.
+			 */
+			r = RESUME_GUEST;
+		} else {
+			if (last_inst == KVMPPC_INST_BOOK3S_DEBUG) {
+				kvmppc_emulate_debug_instruction_hv(run, vcpu);
+				r = RESUME_HOST;
+			} else {
+				kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
+				r = RESUME_GUEST;
+			}
+		}
 		break;
+	}
 	/*
 	 * This occurs if the guest (kernel or userspace), does something that
 	 * is prohibited by HFSCR.  We just generate a program interrupt to
@@ -922,6 +947,9 @@ static int kvmppc_get_one_reg_hv(struct kvm_vcpu *vcpu, u64 id,
 	long int i;
 
 	switch (id) {
+	case KVM_REG_PPC_DEBUG_INST:
+		*val = get_reg_val(id, KVMPPC_INST_BOOK3S_DEBUG);
+		break;
 	case KVM_REG_PPC_HIOR:
 		*val = get_reg_val(id, 0);
 		break;
arch/powerpc/kvm/book3s_pr.c +3 -0
index faffb27..cd2a39d 100644
@@ -1319,6 +1319,9 @@ static int kvmppc_get_one_reg_pr(struct kvm_vcpu *vcpu, u64 id,
 	int r = 0;
 
 	switch (id) {
+	case KVM_REG_PPC_DEBUG_INST:
+		*val = get_reg_val(id, KVMPPC_INST_BOOK3S_DEBUG);
+		break;
 	case KVM_REG_PPC_HIOR:
 		*val = get_reg_val(id, to_book3s(vcpu)->hior);
 		break;
arch/powerpc/kvm/emulate.c +0 -0
index e96b50d..68f38b2 100644
@@ -274,6 +274,17 @@ int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu)
 		}
 		break;
 
Quoted 10 lines

arch/powerpc/kvm/emulate.c int kvmppc_emulate_instruction(struct kvm_run *run, struct kvm_vcpu *vcpu) · line 282

Quoted 6 lines
arch/powerpc/kvm/emulate.c +6 -0
+	case 0:
+		/*
+		 * Instruction with primary opcode 0. Based on PowerISA
+		 * these are illegal instructions.
+		 */
+		run->exit_reason = KVM_EXIT_DEBUG;

This is wrong. We need to check that the instruction is 0x00dddd00. Any other op0 instruction should trigger an invalid instruction trap.

Ok.

Thanks for review
Regards
Maddy

Quoted 13 lines

Alex

Quoted 9 lines
arch/powerpc/kvm/emulate.c +5 -0
+		run->debug.arch.address = kvmppc_get_pc(vcpu);
+		emulated = EMULATE_EXIT_USER;
+		advance = 0;
+		break;
+
 	default:
 		emulated = EMULATE_FAIL;
 	}
#3 lore raw
Quoted 59 lines

Am 23.08.2014 um 12:17 schrieb Madhavan Srinivasan <[email protected]>:

Quoted 45 lines · Alexander Graf
Quoted 44 lines · Madhavan Srinivasan

This patch adds kernel side support for software breakpoint. Design is that, by using an illegal instruction, we trap to hypervisor via Emulation Assistance interrupt, where we check for the illegal instruction and accordingly we return to Host or Guest. Patch also adds support for software breakpoint in PR KVM.

Changes v3->v4:
Made changes to code comments and removed #define of zero opcode Added a new function to handle the debug instruction emulation in book3s_hv Rebased the code to latest upstream source.

Changes v2->v3:
Changed the debug instructions. Using the all zero opcode in the instruction word
as illegal instruction as mentioned in Power ISA instead of ABS
Removed reg updated in emulation assist and added a call to
kvmppc_emulate_instruction for reg update.

Changes v1->v2:

Moved the debug instruction #def to kvm_book3s.h. This way PR_KVM can also share it. Added code to use KVM get one reg infrastructure to get debug opcode. Updated emulate.c to include emulation of debug instruction incase of PR_KVM. Made changes to commit message.

---

arch/powerpc/include/asm/kvm_book3s.h |  7 +++++++
arch/powerpc/kvm/book3s.c             |  3 ++-
arch/powerpc/kvm/book3s_hv.c          | 32 ++++++++++++++++++++++++++++++--
arch/powerpc/kvm/book3s_pr.c          |  3 +++
arch/powerpc/kvm/emulate.c            | 11 +++++++++++
5 files changed, 53 insertions(+), 3 deletions(-)
arch/powerpc/include/asm/kvm_book3s.h +0 -0
index 6acf0c2..a1944f8 100644
@@ -24,6 +24,13 @@
 #include <linux/kvm_host.h>
 #include <asm/kvm_book3s_asm.h>
 
Quoted 9 lines

arch/powerpc/include/asm/kvm_book3s.h line 32

Quoted 6 lines
arch/powerpc/include/asm/kvm_book3s.h +6 -0
+/*
+ * KVMPPC_INST_BOOK3S_DEBUG is debug Instruction for supporting Software Breakpoint.
+ * Based on PowerISA v2.07, Instruction with primary opcode 0 will be treated as illegal
+ * instruction.
+ */
+#define KVMPPC_INST_BOOK3S_DEBUG    0x00dddd00

Please change the BookE version of this as well, put the define in a common header and use a non book specific name.

Quoted 2 lines

I first wanted to get the server side in and then take up this, but i can do it with this, just concerned incase of booke testing :(

I can test, no problem. You can at least do compile tests on your side already ;)

Quoted 54 lines
Quoted 27 lines
Quoted 27 lines
arch/powerpc/include/asm/kvm_book3s.h +1 -0
+
 struct kvmppc_bat {
   u64 raw;
   u32 bepi;
arch/powerpc/kvm/book3s.c +2 -1
index dd03f6b..00e9c9f 100644
@@ -778,7 +778,8 @@ int kvm_arch_vcpu_ioctl_translate(struct kvm_vcpu *vcpu,
 int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
                   struct kvm_guest_debug *dbg)
 {
-    return -EINVAL;
+    vcpu->guest_debug = dbg->control;
+    return 0;
 }
 
 void kvmppc_decrementer_func(unsigned long data)
arch/powerpc/kvm/book3s_hv.c +0 -0
index 27cced9..0a92e45 100644
@@ -725,6 +725,14 @@ static int kvmppc_hcall_impl_hv(unsigned long cmd)
   return kvmppc_hcall_impl_hv_realmode(cmd);
 }
 
Quoted 15 lines

arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 819

Quoted 13 lines
arch/powerpc/kvm/book3s_hv.c +8 -0
+static int kvmppc_emulate_debug_instruction_hv(struct kvm_run *run,
+                    struct kvm_vcpu *vcpu)
+{
+    run->exit_reason = KVM_EXIT_DEBUG;
+    run->debug.arch.address = kvmppc_get_pc(vcpu);
+    return 0;
+}
+
 static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
                struct task_struct *tsk)
 {
@@ -811,9 +819,26 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,
    * we don't emulate any guest instructions at this stage.

This comment is no longer true, it should get changed.

Will change it.

Quoted 9 lines
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +4 -2
    */
   case BOOK3S_INTERRUPT_H_EMUL_ASSIST:
-        kvmppc_core_queue_program(vcpu, SRR1_PROGILL);
-        r = RESUME_GUEST;
+    {
+        u32 last_inst;
+        if(kvmppc_get_last_inst(vcpu, INST_GENERIC, &last_inst) !=
+                    EMULATE_DONE) {
Quoted 4 lines
Quoted 1 line

Please only do this if debugging is active.

Ok sure. But i will add in the else part of the check. Since we do the instruction check there.

We should only fetch the instruction if sw breakpoint debugging is active.

Alex