All of lore.kernel.org
 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 <kvm@vger.kernel.org>,
	"Roedel, Joerg" <Joerg.Roedel@amd.com>
Subject: Re: [PATCH] KVM: x86: Fix guest debug across vcpu INIT reset
Date: Thu, 20 Sep 2012 14:39:22 +0300	[thread overview]
Message-ID: <505B006A.2030604@redhat.com> (raw)
In-Reply-To: <505A1F1F.1010606@siemens.com>

On 09/19/2012 10:38 PM, Jan Kiszka wrote:
> If we reset a vcpu on INIT, make sure to not touch dr7 as stored in the
> VMCS/VMCB and also switch_db_regs if guest debugging is using hardware
> breakpoints. Otherwise, the vcpu will not trigger hardware breakpoints
> until userspace issues another KVM_SET_GUEST_DEBUG IOCTL for it.
> 
> Found while trying to stop on start_secondary.
> 
> @@ -1146,7 +1146,8 @@ static void init_vmcb(struct vcpu_svm *svm)
>  
>  	svm_set_efer(&svm->vcpu, 0);
>  	save->dr6 = 0xffff0ff0;
> -	save->dr7 = 0x400;
> +	if (!(svm->vcpu.guest_debug & KVM_GUESTDBG_USE_HW_BP))
> +		save->dr7 = 0x400;

Whenever we multiplex a resource foo for several users, we should have a
function update_foo() that recalculates foo from all its sources:

        vcpu->arch.dr7 = 0x400;
        update_dr7(&svm->vcpu);

(don't know if the first line really belongs here)

>  	kvm_set_rflags(&svm->vcpu, 2);
>  	save->rip = 0x0000fff0;
>  	svm->vcpu.arch.regs[VCPU_REGS_RIP] = save->rip;
> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
> index d62b413..37f68f7 100644
> --- a/arch/x86/kvm/vmx.c
> +++ b/arch/x86/kvm/vmx.c
> @@ -3959,7 +3959,8 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
>  		kvm_rip_write(vcpu, 0);
>  	kvm_register_write(vcpu, VCPU_REGS_RSP, 0);
>  
> -	vmcs_writel(GUEST_DR7, 0x400);
> +	if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP))
> +		vmcs_writel(GUEST_DR7, 0x400);
>  

Ditto. update_dr7() could even be generic and use ->set_dr7().

>  	vmcs_writel(GUEST_GDTR_BASE, 0);
>  	vmcs_write32(GUEST_GDTR_LIMIT, 0xffff);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index c4d451e..7c8c2b8 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -6043,7 +6043,8 @@ int kvm_arch_vcpu_reset(struct kvm_vcpu *vcpu)
>  	vcpu->arch.nmi_pending = 0;
>  	vcpu->arch.nmi_injected = false;
>  
> -	vcpu->arch.switch_db_regs = 0;
> +	if (!(vcpu->guest_debug & KVM_GUESTDBG_USE_HW_BP))
> +		vcpu->arch.switch_db_regs = 0;
>  	memset(vcpu->arch.db, 0, sizeof(vcpu->arch.db));
>  	vcpu->arch.dr6 = DR6_FIXED_1;
>  	vcpu->arch.dr7 = DR7_FIXED_1;
> 

You could move the switch_db_regs calculation into update_dr7(), and
move the update_dr7() call after assigning it here.  This fixes
everything neatly (and obviates the need for the first line in the
snippet above).


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

  reply	other threads:[~2012-09-20 11:39 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-19 19:38 [PATCH] KVM: x86: Fix guest debug across vcpu INIT reset Jan Kiszka
2012-09-20 11:39 ` Avi Kivity [this message]
2012-09-21  3:42   ` [PATCH v2] " Jan Kiszka
2012-09-23 13:01     ` 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=505B006A.2030604@redhat.com \
    --to=avi@redhat.com \
    --cc=Joerg.Roedel@amd.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 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.