kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: [PATCH] KVM: Use thread debug register storage instead of kvm specific data
Date: Tue, 01 Sep 2009 14:16:25 +0300	[thread overview]
Message-ID: <4A9D0289.7080201@redhat.com> (raw)
In-Reply-To: <4A9CFA90.50202@siemens.com>

On 09/01/2009 01:42 PM, Jan Kiszka wrote:
>
>> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
>> index 891234b..9e3acbd 100644
>> --- a/arch/x86/kvm/x86.c
>> +++ b/arch/x86/kvm/x86.c
>> @@ -3627,14 +3627,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>>
>>   	kvm_guest_enter();
>>
>> -	get_debugreg(vcpu->arch.host_dr6, 6);
>> -	get_debugreg(vcpu->arch.host_dr7, 7);
>>   	if (unlikely(vcpu->arch.switch_db_regs)) {
>> -		get_debugreg(vcpu->arch.host_db[0], 0);
>> -		get_debugreg(vcpu->arch.host_db[1], 1);
>> -		get_debugreg(vcpu->arch.host_db[2], 2);
>> -		get_debugreg(vcpu->arch.host_db[3], 3);
>> -
>>      
> I'm fine with this for the common case, but we should switch to the safe
> pattern on test_thread_flag(TIF_DEBUG), ie. if someone debugs qemu using
> hardware break/watchpoints.
>    

IIUC, thread.debugregs should be synced with the hardware registers.  
The kernel itself only writes to the debug registers, so we're safe 
doing the same.

>    
>>   		set_debugreg(0, 7);
>>   		set_debugreg(vcpu->arch.eff_db[0], 0);
>>   		set_debugreg(vcpu->arch.eff_db[1], 1);
>> @@ -3645,15 +3638,14 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu)
>>   	trace_kvm_entry(vcpu->vcpu_id);
>>   	kvm_x86_ops->run(vcpu);
>>
>> -	if (unlikely(vcpu->arch.switch_db_regs)) {
>> -		set_debugreg(0, 7);
>> -		set_debugreg(vcpu->arch.host_db[0], 0);
>> -		set_debugreg(vcpu->arch.host_db[1], 1);
>> -		set_debugreg(vcpu->arch.host_db[2], 2);
>> -		set_debugreg(vcpu->arch.host_db[3], 3);
>> +	if (unlikely(vcpu->arch.switch_db_regs || test_thread_flag(TIF_DEBUG))) {
>>      
> IIRC, you must clear dr7 before loading dr0..3 to avoid spurious effects.
>    

Yeah, I thought of it but forgot to implement it.

>> +		set_debugreg(current->thread.debugreg0, 0);
>> +		set_debugreg(current->thread.debugreg1, 1);
>> +		set_debugreg(current->thread.debugreg2, 2);
>> +		set_debugreg(current->thread.debugreg3, 3);
>> +		set_debugreg(current->thread.debugreg6, 6);
>> +		set_debugreg(current->thread.debugreg7, 7);
>>   	}
>> -	set_debugreg(vcpu->arch.host_dr6, 6);
>> -	set_debugreg(vcpu->arch.host_dr7, 7);
>>      
> Unless I miss something ATM, moving this into the if-clause should cause
> troubles if the guest leaves dr7 armed behind. But I need to refresh my
> memory on this.
>    

The hardware will clear dr7 on exit.

Updated patch to follow.

-- 
error compiling committee.c: too many arguments to function


  parent reply	other threads:[~2009-09-01 11:16 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-01  9:44 [PATCH] KVM: Use thread debug register storage instead of kvm specific data Avi Kivity
2009-09-01  9:47 ` Avi Kivity
2009-09-01 18:12   ` Andrew Theurer
2009-09-01 18:23     ` Avi Kivity
2009-09-04 14:48       ` Andrew Theurer
2009-09-04 15:30         ` Brian Jackson
2009-09-04 16:08           ` Andrew Theurer
2009-09-04 17:04             ` Brian Jackson
2009-09-05 11:34               ` Vadim Rozenfeld
2009-09-06 12:49                 ` Yan Vugenfirer
2009-09-06  8:21         ` Avi Kivity
2009-09-01 10:42 ` Jan Kiszka
2009-09-01 11:08   ` Jan Kiszka
2009-09-01 11:16   ` Avi Kivity [this message]
2009-09-01 11:21     ` Avi Kivity
2009-09-01 13:31     ` Jan Kiszka
2009-09-01 13:39       ` Avi Kivity
2009-09-01 11:22 ` Marcelo Tosatti
2009-09-01 11:28   ` Jan Kiszka
2009-09-01 11:32     ` Marcelo Tosatti
2009-09-01 11:35       ` Avi Kivity
2009-09-01 11:33     ` Jan Kiszka
2009-09-01 11:43       ` Avi Kivity
2009-09-01 11:45         ` Jan Kiszka
2009-09-01 11:56           ` Avi Kivity
2009-09-01 12:01             ` Jan Kiszka
2009-09-01 12:02               ` Avi Kivity
2009-09-01 12:27                 ` Avi Kivity
2009-09-01 11:34   ` Avi Kivity

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4A9D0289.7080201@redhat.com \
    --to=avi@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).