* [PATCH] KVM: VMX: Conditionally reload debug register 6
@ 2009-09-01 11:40 Avi Kivity
2009-09-01 11:43 ` Jan Kiszka
0 siblings, 1 reply; 5+ messages in thread
From: Avi Kivity @ 2009-09-01 11:40 UTC (permalink / raw)
To: Marcelo Tosatti; +Cc: kvm, Jan Kiszka
Only reload debug register 6 if we're running with the guest's
debug registers. Saves around 150 cycles from the guest lightweight
exit path.
Signed-off-by: Avi Kivity <avi@redhat.com>
---
arch/x86/kvm/vmx.c | 6 ++++--
1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 05cd554..70b0c54 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3629,7 +3629,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
*/
vmcs_writel(HOST_CR0, read_cr0());
- set_debugreg(vcpu->arch.dr6, 6);
+ if (vcpu->arch.switch_db_regs)
+ set_debugreg(vcpu->arch.dr6, 6);
asm(
/* Store host registers */
@@ -3731,7 +3732,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
| (1 << VCPU_EXREG_PDPTR));
vcpu->arch.regs_dirty = 0;
- get_debugreg(vcpu->arch.dr6, 6);
+ if (vcpu->arch.switch_db_regs)
+ get_debugreg(vcpu->arch.dr6, 6);
vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
if (vmx->rmode.irq.pending)
--
1.6.4.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: VMX: Conditionally reload debug register 6
2009-09-01 11:40 [PATCH] KVM: VMX: Conditionally reload debug register 6 Avi Kivity
@ 2009-09-01 11:43 ` Jan Kiszka
2009-09-01 11:53 ` Avi Kivity
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2009-09-01 11:43 UTC (permalink / raw)
To: Avi Kivity; +Cc: Marcelo Tosatti, kvm@vger.kernel.org
Avi Kivity wrote:
> Only reload debug register 6 if we're running with the guest's
> debug registers. Saves around 150 cycles from the guest lightweight
> exit path.
>
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
> arch/x86/kvm/vmx.c | 6 ++++--
> 1 files changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index 05cd554..70b0c54 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3629,7 +3629,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
> */
> vmcs_writel(HOST_CR0, read_cr0());
>
> - set_debugreg(vcpu->arch.dr6, 6);
> + if (vcpu->arch.switch_db_regs)
> + set_debugreg(vcpu->arch.dr6, 6);
>
> asm(
> /* Store host registers */
> @@ -3731,7 +3732,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
> | (1 << VCPU_EXREG_PDPTR));
> vcpu->arch.regs_dirty = 0;
>
> - get_debugreg(vcpu->arch.dr6, 6);
> + if (vcpu->arch.switch_db_regs)
> + get_debugreg(vcpu->arch.dr6, 6);
>
> vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
> if (vmx->rmode.irq.pending)
That reduces the emulation quality as vcpu->arch.switch_db_regs is only
set if some breakpoint is active while dr6 has its use also when that is
not the case).
Jan
--
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: VMX: Conditionally reload debug register 6
2009-09-01 11:43 ` Jan Kiszka
@ 2009-09-01 11:53 ` Avi Kivity
2009-09-01 12:32 ` Jan Kiszka
0 siblings, 1 reply; 5+ messages in thread
From: Avi Kivity @ 2009-09-01 11:53 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Marcelo Tosatti, kvm@vger.kernel.org
On 09/01/2009 02:43 PM, Jan Kiszka wrote:
> @@ -3731,7 +3732,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
>> | (1<< VCPU_EXREG_PDPTR));
>> vcpu->arch.regs_dirty = 0;
>>
>> - get_debugreg(vcpu->arch.dr6, 6);
>> + if (vcpu->arch.switch_db_regs)
>> + get_debugreg(vcpu->arch.dr6, 6);
>>
>> vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
>> if (vmx->rmode.irq.pending)
>>
> That reduces the emulation quality as vcpu->arch.switch_db_regs is only
> set if some breakpoint is active while dr6 has its use also when that is
> not the case).
>
True - there's the TF reason reporting bits.
How about this then:
- if !switch_db_regs, trap #DB
- on #DB trap, copy DR6.BS and DR6.BT to vcpu->arch.dr6, and reinject
the #DB
?
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: VMX: Conditionally reload debug register 6
2009-09-01 11:53 ` Avi Kivity
@ 2009-09-01 12:32 ` Jan Kiszka
2009-09-01 12:54 ` Avi Kivity
0 siblings, 1 reply; 5+ messages in thread
From: Jan Kiszka @ 2009-09-01 12:32 UTC (permalink / raw)
To: Avi Kivity; +Cc: Marcelo Tosatti, kvm@vger.kernel.org
Avi Kivity wrote:
> On 09/01/2009 02:43 PM, Jan Kiszka wrote:
>> @@ -3731,7 +3732,8 @@ static void vmx_vcpu_run(struct kvm_vcpu *vcpu)
>>> | (1<< VCPU_EXREG_PDPTR));
>>> vcpu->arch.regs_dirty = 0;
>>>
>>> - get_debugreg(vcpu->arch.dr6, 6);
>>> + if (vcpu->arch.switch_db_regs)
>>> + get_debugreg(vcpu->arch.dr6, 6);
>>>
>>> vmx->idt_vectoring_info = vmcs_read32(IDT_VECTORING_INFO_FIELD);
>>> if (vmx->rmode.irq.pending)
>>>
>> That reduces the emulation quality as vcpu->arch.switch_db_regs is only
>> set if some breakpoint is active while dr6 has its use also when that is
>> not the case).
>>
>
> True - there's the TF reason reporting bits.
>
> How about this then:
>
> - if !switch_db_regs, trap #DB
> - on #DB trap, copy DR6.BS and DR6.BT to vcpu->arch.dr6, and reinject
> the #DB
>
> ?
I'm worried about vm-exits that may take precedence over the #db trap.
If we skip to save/restore dr6 for them, the value that the interception
handler sees later on will be bogus. Or is this architecturally impossible?
Jan
--
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] KVM: VMX: Conditionally reload debug register 6
2009-09-01 12:32 ` Jan Kiszka
@ 2009-09-01 12:54 ` Avi Kivity
0 siblings, 0 replies; 5+ messages in thread
From: Avi Kivity @ 2009-09-01 12:54 UTC (permalink / raw)
To: Jan Kiszka; +Cc: Marcelo Tosatti, kvm@vger.kernel.org
On 09/01/2009 03:32 PM, Jan Kiszka wrote:
> I'm worried about vm-exits that may take precedence over the #db trap.
> If we skip to save/restore dr6 for them, the value that the interception
> handler sees later on will be bogus. Or is this architecturally impossible?
>
I think it's architectually impossible. Debug traps take effect after
the instruction executed, so if we made it to that point, nothing else
can cause the vmexit.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-09-01 12:55 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-01 11:40 [PATCH] KVM: VMX: Conditionally reload debug register 6 Avi Kivity
2009-09-01 11:43 ` Jan Kiszka
2009-09-01 11:53 ` Avi Kivity
2009-09-01 12:32 ` Jan Kiszka
2009-09-01 12:54 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox