powerpc/kvm: support to handle sw breakpoint
Subsystems (3)
PATCH 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 mandates use of "abs" instruction (primary opcode 31 and extended opcode 360) as sw breakpoint instruction. Based on PowerISA v2.01, ABS instruction has been dropped from the architecture and treated an illegal instruction.
--- arch/powerpc/kvm/book3s.c | 3 ++- arch/powerpc/kvm/book3s_hv.c | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)
arch/powerpc/kvm/book3s.c +2 -1
@@ -789,7 +789,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 +19 -4
@@ -67,6 +67,14 @@/* Used as a "null" value for timebase values */ #define TB_NIL (~(u64)0) +/* +* SW_BRK_DBG_INT is debug Instruction for supporting Software Breakpoint. +* Instruction mnemonic is ABS, primary opcode is 31 and extended opcode is 360. +* Based on PowerISA v2.01, ABS instruction has been dropped from the architecture +* and treated an illegal instruction. +*/ +#define SW_BRK_DBG_INT 0x7c0002d0 +static void kvmppc_end_cede (struct kvm_vcpu *vcpu);static int kvmppc_hv_setup_htab_rma (struct kvm_vcpu *vcpu);
@@ -721,12 +729,19 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,break ;/* * This occurs if the guest executes an illegal instruction. -* We just generate a program interrupt to the guest, since -* we don't emulate any guest instructions at this stage. +* To support software breakpoint, we check for the sw breakpoint +* instruction to return back to host, if not we just generate a +* program interrupt to the guest. */ case BOOK3S_INTERRUPT_H_EMUL_ASSIST : -kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); - r =RESUME_GUEST ; +if (vcpu->arch.last_inst ==SW_BRK_DBG_INT ) { + run->exit_reason =KVM_EXIT_DEBUG ; + run->debug.arch.address = vcpu->arch.pc; + r =RESUME_HOST ; + }else { +kvmppc_core_queue_program (vcpu,0x80000 ); + r =RESUME_GUEST ; + }break ;/* * This occurs if the guest (kernel or userspace), does something that
Signature · 1 line
1.8.3.1
Quoted 33 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 mandates use of "abs" instruction (primary opcode 31 and extended opcode 360) as sw breakpoint instruction. Based on PowerISA v2.01, ABS instruction has been dropped from the architecture and treated an illegal instruction.Signed-off-by Madhavan Srinivasan <[email protected]>--- arch/powerpc/kvm/book3s.c | 3 ++- arch/powerpc/kvm/book3s_hv.c | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)arch/powerpc/kvm/book3s.c +2
-1@@ -789,7 +789,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
arch/powerpc/kvm/book3s_hv.c line 76
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +7
-0@@ -67,6 +67,14 @@/* Used as a "null" value for timebase values */ #define TB_NIL (~(u64)0) +/* +* SW_BRK_DBG_INT is debug Instruction for supporting Software Breakpoint. +* Instruction mnemonic is ABS, primary opcode is 31 and extended opcode is 360. +* Based on PowerISA v2.01, ABS instruction has been dropped from the architecture +* and treated an illegal instruction. +*/ +#define SW_BRK_DBG_INT 0x7c0002d0
The instruction we use to trap needs to get exposed to user space via a ONE_REG property.
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with book3s_32 PR.
Quoted 8 lines
arch/powerpc/kvm/book3s_hv.c +1
-0+static void kvmppc_end_cede (struct kvm_vcpu *vcpu);static int kvmppc_hv_setup_htab_rma (struct kvm_vcpu *vcpu);@@ -721,12 +729,19 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu,break ;/* * This occurs if the guest executes an illegal instruction.
arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 737
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +4
-4-* We just generate a program interrupt to the guest, since -* we don't emulate any guest instructions at this stage. +* To support software breakpoint, we check for the sw breakpoint +* instruction to return back to host, if not we just generate a +* program interrupt to the guest. */ case BOOK3S_INTERRUPT_H_EMUL_ASSIST : -kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); - r =RESUME_GUEST ; +if (vcpu->arch.last_inst ==SW_BRK_DBG_INT ) {
Don't access last_inst directly. Instead use the provided helpers.
arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 742
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +5
-0+ run->exit_reason =KVM_EXIT_DEBUG ; + run->debug.arch.address = vcpu->arch.pc; + r =RESUME_HOST ; + }else { +kvmppc_core_queue_program (vcpu,0x80000 );
magic numbers
arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 747
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +2
-0+ r =RESUME_GUEST ; + }break ;/* * This occurs if the guest (kernel or userspace), does something that
Please enable PR KVM as well while you're at it.
Alex
Quoted 4 lines · Alexander Graf
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.
twi will be directed to the guest on HV no ? We want a real illegal because those go to the host (for potential emulation by the HV). I'm trying to see if I can get the architect to set one in stone in a future proof way.
Cheers,
Ben.
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines · Alexander Graf
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.twi will be directed to the guest on HV no ? We want a real illegal because those go to the host (for potential emulation by the HV).
Ah, good point. I guess we need different one for PR and HV then to ensure compatibility with older ISAs on PR.
Alex
Quoted 7 lines
I'm
trying to see if I can get the architect to set one in stone in a future proof way.Cheers,
Ben.
Quoted 10 lines · Alexander Graf
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 3 lines · Alexander Graf
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.twi will be directed to the guest on HV no ? We want a real illegal because those go to the host (for potential emulation by the HV).
Ah, good point. I guess we need different one for PR and HV then to ensure compatibility with older ISAs on PR.
Well, we also need to be careful with what happens if a PR guest puts that instruction in, do that stop its HV guest/host ?
What if it's done in userspace ? Do that stop the kernel ? :-)
Maddy, I haven't checked, does your patch ensure that we only ever stop if the instruction is at a recorded bkpt address ? It still means that a userspace process can practically DOS its kernel by issuing a lot of these causing a crapload of exits.
Cheers,
Ben.
Quoted 14 lines
Alex
Quoted 7 lines
I'm
trying to see if I can get the architect to set one in stone in a future proof way.Cheers,
Ben.--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · Alexander Graf
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Alexander Graf
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
twi will be directed to the guest on HV no ? We want a real illegal because those go to the host (for potential emulation by the HV).
Ah, good point. I guess we need different one for PR and HV then to ensure compatibility with older ISAs on PR.
Well, we also need to be careful with what happens if a PR guest puts that instruction in, do that stop its HV guest/host ?
What if it's done in userspace ? Do that stop the kernel ? :-)
The way SW breakpointing is handled is that when we see one, it gets deflected into user space. User space then has an array of breakpoints it configured itself. If the breakpoint is part of that list, it consumes it. If not, it injects a debug interrupt (program in this case) into the guest.
That way we can overlay that one instruction with as many layers as we like :). We only get a performance hit on execution of that instruction.
Quoted 4 lines
Maddy, I haven't checked, does your patch ensure that we only ever stop if the instruction is at a recorded bkpt address ? It still means that a userspace process can practically DOS its kernel by issuing a lot of these causing a crapload of exits.
Only user space knows about its breakpoint addresses, so we have to deflect. However since time still ticks on, we only increase jitter of the guest. The process would still get scheduled away after the same amount of real time, no?
Alex
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · Alexander Graf
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Alexander Graf
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.
Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
twi will be directed to the guest on HV no ? We want a real illegal because those go to the host (for potential emulation by the HV).
Ah, good point. I guess we need different one for PR and HV then to ensure compatibility with older ISAs on PR.
Well, we also need to be careful with what happens if a PR guest puts that instruction in, do that stop its HV guest/host ?
Damn, my mail client is messed up. did not see the mail till now.
I havent tried this incase of PR guest kernel. I will need to try this before commenting.
Quoted 2 lines
What if it's done in userspace ? Do that stop the kernel ? :-)
Basically flow is that, when we see this instruction, we return to host, and host checks for address in the SW array and if not it returns to kernel.
Quoted 5 lines
Maddy, I haven't checked, does your patch ensure that we only ever stop if the instruction is at a recorded bkpt address ? It still means that a userspace process can practically DOS its kernel by issuing a lot of these causing a crapload of exits.
This is valid, userspace can create a mess, need to handle this, meaning incase if we dont find a valid SW breakpoint for this address in the HOST, we need to route it to guest and kill it at app.
Regards
Maddy
Quoted 19 lines
Cheers,
Ben.Quoted 14 lines
Alex
Quoted 7 lines
I'm
trying to see if I can get the architect to set one in stone in a future proof way.Cheers,
Ben.--
To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 45 lines · Alexander Graf
Quoted 43 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 mandates use of "abs" instruction
(primary opcode 31 and extended opcode 360) as sw breakpoint instruction. Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
and treated an illegal instruction.Signed-off-by Madhavan Srinivasan <[email protected]>--- arch/powerpc/kvm/book3s.c | 3 ++- arch/powerpc/kvm/book3s_hv.c | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)arch/powerpc/kvm/book3s.c +2
-1@@ -789,7 +789,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 +1
-0@@ -67,6 +67,14 @@/* Used as a "null" value for timebase values */ #define TB_NIL (~(u64)0) +/* +* SW_BRK_DBG_INT is debug Instruction for supporting Software Breakpoint.
+ * Instruction mnemonic is ABS, primary opcode is 31 and extended opcode is 360.
Quoted 9 lines
Quoted 5 lines
+ * Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
+ * and treated an illegal instruction.
+ */
+#defineSW_BRK_DBG_INT0x7c0002d0The instruction we use to trap needs to get exposed to user space via a
ONE_REGproperty.
Yes. I got to know about that from Bharat (patchset "ppc debug: Add debug stub support"). I will change it.
Quoted 23 lines
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.Quoted 8 lines
+
static voidkvmppc_end_cede(struct kvm_vcpu *vcpu); static intkvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu); @@ -721,12 +729,19 @@ static int kvmppc_handle_exit_hv(structkvm_run*run, structkvm_vcpu*vcpu,break; /* * This occurs if the guest executes an illegal instruction.arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 737
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +4
-4-* We just generate a program interrupt to the guest, since -* we don't emulate any guest instructions at this stage. +* To support software breakpoint, we check for the sw breakpoint +* instruction to return back to host, if not we just generate a +* program interrupt to the guest. */ case BOOK3S_INTERRUPT_H_EMUL_ASSIST : -kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); - r =RESUME_GUEST ; +if (vcpu->arch.last_inst ==SW_BRK_DBG_INT ) {
Quoted 2 lines
Don't access
last_instdirectly. Instead use the provided helpers.
Ok. Will look and replace it.
Quoted 7 lines
arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 742
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +5
-0+ run->exit_reason =KVM_EXIT_DEBUG ; + run->debug.arch.address = vcpu->arch.pc; + r =RESUME_HOST ; + }else { +kvmppc_core_queue_program (vcpu,0x80000 );magic numbers
^^^^^
I did not understand this?
Quoted 9 lines
Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c +2
-0+ r =RESUME_GUEST ; + }break ;/* * This occurs if the guest (kernel or userspace), does something that
Please enable PR KVM as well while you're at it.
My bad, I did not try the PR KVM. I will try it out.
Quoted 3 lines
Alex
Thanks for review
Regards
Maddy
Quoted 82 lines · Madhavan Srinivasan
Quoted 43 lines · Alexander Graf
Quoted 42 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 mandates use of "abs" instruction
(primary opcode 31 and extended opcode 360) as sw breakpoint instruction. Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
and treated an illegal instruction.Signed-off-by Madhavan Srinivasan <[email protected]>--- arch/powerpc/kvm/book3s.c | 3 ++- arch/powerpc/kvm/book3s_hv.c | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)arch/powerpc/kvm/book3s.c +2
-1@@ -789,7 +789,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 +1
-0@@ -67,6 +67,14 @@/* Used as a "null" value for timebase values */ #define TB_NIL (~(u64)0) +/* +* SW_BRK_DBG_INT is debug Instruction for supporting Software Breakpoint.
+ * Instruction mnemonic is ABS, primary opcode is 31 and extendedQuoted 9 lines
Quoted 6 lines
opcode is 360.
+ * Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
+ * and treated an illegal instruction.
+ */
+#defineSW_BRK_DBG_INT0x7c0002d0The instruction we use to trap needs to get exposed to user space via a
ONE_REGproperty.Yes. I got to know about that from Bharat (patchset "ppc debug: Add debug stub support"). I will change it.
Quoted 22 lines
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.Quoted 8 lines
+
static void kvmppc_end_cede(struct kvm_vcpu *vcpu); static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu); @@ -721,12 +729,19 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, break; /* * This occurs if the guest executes an illegal instruction.arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 737
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +4
-4-* We just generate a program interrupt to the guest, since -* we don't emulate any guest instructions at this stage. +* To support software breakpoint, we check for the sw breakpoint +* instruction to return back to host, if not we just generate a +* program interrupt to the guest. */ case BOOK3S_INTERRUPT_H_EMUL_ASSIST : -kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); - r =RESUME_GUEST ; +if (vcpu->arch.last_inst ==SW_BRK_DBG_INT ) {Quoted 2 lines
Don't access
last_instdirectly. Instead use the provided helpers.Ok. Will look and replace it.
Quoted 8 lines
Quoted 6 lines
arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 742
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +5
-0+ run->exit_reason =KVM_EXIT_DEBUG ; + run->debug.arch.address = vcpu->arch.pc; + r =RESUME_HOST ; + }else { +kvmppc_core_queue_program (vcpu,0x80000 );magic numbers
^^^^^
I did not understand this?
You're replacing the readable SRR1_PROGILL with the unreadable 0x80000. That's bad.
Alex
Quoted 91 lines · Alexander Graf
Quoted 89 lines · Madhavan Srinivasan
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 mandates use of "abs" instruction
(primary opcode 31 and extended opcode 360) as sw breakpoint instruction.
Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
and treated an illegal instruction.Signed-off-by Madhavan Srinivasan <[email protected]>--- arch/powerpc/kvm/book3s.c | 3 ++- arch/powerpc/kvm/book3s_hv.c | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)arch/powerpc/kvm/book3s.c +2
-1@@ -789,7 +789,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 +1
-0@@ -67,6 +67,14 @@/* Used as a "null" value for timebase values */ #define TB_NIL (~(u64)0) +/* +* SW_BRK_DBG_INT is debug Instruction for supporting Software Breakpoint.
+ * Instruction mnemonic is ABS, primary opcode is 31 and extendedQuoted 9 lines
Quoted 6 lines
opcode is 360.
+ * Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
+ * and treated an illegal instruction.
+ */
+#defineSW_BRK_DBG_INT0x7c0002d0The instruction we use to trap needs to get exposed to user space via a
ONE_REGproperty.Yes. I got to know about that from Bharat (patchset "ppc debug: Add debug stub support"). I will change it.
Quoted 22 lines
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.Quoted 8 lines
+
static void kvmppc_end_cede(struct kvm_vcpu *vcpu); static int kvmppc_hv_setup_htab_rma(struct kvm_vcpu *vcpu); @@ -721,12 +729,19 @@ static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, break; /* * This occurs if the guest executes an illegal instruction.arch/powerpc/kvm/book3s_hv.c static int kvmppc_handle_exit_hv(struct kvm_run *run, struct kvm_vcpu *vcpu, · line 737
Quoted 10 lines
arch/powerpc/kvm/book3s_hv.c +4
-4-* We just generate a program interrupt to the guest, since -* we don't emulate any guest instructions at this stage. +* To support software breakpoint, we check for the sw breakpoint +* instruction to return back to host, if not we just generate a +* program interrupt to the guest. */ case BOOK3S_INTERRUPT_H_EMUL_ASSIST : -kvmppc_core_queue_program (vcpu,SRR1_PROGILL ); - r =RESUME_GUEST ; +if (vcpu->arch.last_inst ==SW_BRK_DBG_INT ) {Quoted 2 lines
Don't access
last_instdirectly. Instead use the provided helpers.Ok. Will look and replace it.
Quoted 5 lines
Quoted 5 lines
arch/powerpc/kvm/book3s_hv.c +5
-0+ run->exit_reason =KVM_EXIT_DEBUG ; + run->debug.arch.address = vcpu->arch.pc; + r =RESUME_HOST ; + }else { +kvmppc_core_queue_program (vcpu,0x80000 );
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
magic numbers
^^^^^
I did not understand this?You're replacing the readable
SRR1_PROGILLwith the unreadable0x80000. That's bad.
Oops. My bad. Will undo that. I guess I messed up when was re basing it.
Quoted 3 lines
Alex
Thanks for review
Regards
Maddy
Quoted 26 lines · Alexander Graf
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · Alexander Graf
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Alexander Graf
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
twi will be directed to the guest on HV no ? We want a real illegal because those go to the host (for potential emulation by the HV).
Ah, good point. I guess we need different one for PR and HV then to ensure compatibility with older ISAs on PR.
Well, we also need to be careful with what happens if a PR guest puts that instruction in, do that stop its HV guest/host ?
What if it's done in userspace ? Do that stop the kernel ? :-)
The way SW breakpointing is handled is that when we see one, it gets deflected into user space. User space then has an array of breakpoints it configured itself. If the breakpoint is part of that list, it consumes it. If not, it injects a debug interrupt (program in this case) into the guest.
That way we can overlay that one instruction with as many layers as we like :). We only get a performance hit on execution of that instruction.
Quoted 8 lines
Quoted 4 lines
Maddy, I haven't checked, does your patch ensure that we only ever stop if the instruction is at a recorded bkpt address ? It still means that a userspace process can practically DOS its kernel by issuing a lot of these causing a crapload of exits.
Only user space knows about its breakpoint addresses, so we have to deflect. However since time still ticks on, we only increase jitter of the guest. The process would still get scheduled away after the same
^^^ Where is this taken care. I am still trying to understand. Kindly
can you explain or point to the code. Will help.
Quoted 5 lines
amount of real time, no?
Alex
Thanks for review.
Regards
Maddy
Quoted 29 lines · Madhavan Srinivasan
Quoted 28 lines · Alexander Graf
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 5 lines · Alexander Graf
Quoted 4 lines · Benjamin Herrenschmidt
Quoted 3 lines · Alexander Graf
Also, why don't we use twi always or something else that actually is defined as illegal instruction? I would like to see this shared with
book3s_32PR.Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
twi will be directed to the guest on HV no ? We want a real illegal because those go to the host (for potential emulation by the HV).
Ah, good point. I guess we need different one for PR and HV then to ensure compatibility with older ISAs on PR.
Well, we also need to be careful with what happens if a PR guest puts that instruction in, do that stop its HV guest/host ?
What if it's done in userspace ? Do that stop the kernel ? :-)
The way SW breakpointing is handled is that when we see one, it gets deflected into user space. User space then has an array of breakpoints it configured itself. If the breakpoint is part of that list, it consumes it. If not, it injects a debug interrupt (program in this case) into the guest.
That way we can overlay that one instruction with as many layers as we like :). We only get a performance hit on execution of that instruction.
Quoted 4 lines
Maddy, I haven't checked, does your patch ensure that we only ever stop if the instruction is at a recorded bkpt address ? It still means that a userspace process can practically DOS its kernel by issuing a lot of these causing a crapload of exits.
Quoted 5 lines
Quoted 3 lines
Only user space knows about its breakpoint addresses, so we have to deflect. However since time still ticks on, we only increase jitter of the guest. The process would still get scheduled away after the same
^^^ Where is this taken care. I am still trying to understand. Kindly
can you explain or point to the code. Will help.
We tell the guest via VPA about its steal time which includes QEMU time.
Alex
Quoted 57 lines · Madhavan Srinivasan
Quoted 56 lines · Alexander Graf
Quoted 55 lines · Madhavan Srinivasan
Quoted 54 lines · Alexander Graf
Quoted 42 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 mandates use of "abs" instruction
(primary opcode 31 and extended opcode 360) as sw breakpoint instruction.
Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
and treated an illegal instruction.Signed-off-by Madhavan Srinivasan <[email protected]>--- arch/powerpc/kvm/book3s.c | 3 ++- arch/powerpc/kvm/book3s_hv.c | 23 +++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-)arch/powerpc/kvm/book3s.c +2
-1@@ -789,7 +789,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 +1
-0@@ -67,6 +67,14 @@/* Used as a "null" value for timebase values */ #define TB_NIL (~(u64)0) +/* +* SW_BRK_DBG_INT is debug Instruction for supporting Software Quoted 8 lines
Breakpoint.
+ * Instruction mnemonic is ABS, primary opcode is 31 and extended opcode is 360.
+ * Based on PowerISA v2.01, ABS instruction has been dropped from the architecture
+ * and treated an illegal instruction.
+ */
+#defineSW_BRK_DBG_INT0x7c0002d0The instruction we use to trap needs to get exposed to user space via a
ONE_REGproperty.
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Yes. I got to know about that from Bharat (patchset "ppc debug: Add debug stub support"). I will change it.
Also please make sure to pick an instruction that preferably looks identical regardless of guest endianness. Segher suggested 0x00dddd00. Does that trap properly for you?
Alex