From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jan Kiszka Subject: Re: [PATCH] KVM: VMX: Do not overwrite vcpu->srcu_idx in vmx_vcpu_reset Date: Thu, 14 Mar 2013 16:03:22 +0100 Message-ID: <5141E6BA.2060404@siemens.com> References: <5141E41B.8080804@siemens.com> <20130314150004.GX11223@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Marcelo Tosatti , kvm , Paolo Bonzini To: Gleb Natapov Return-path: Received: from thoth.sbs.de ([192.35.17.2]:34500 "EHLO thoth.sbs.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757801Ab3CNPDd (ORCPT ); Thu, 14 Mar 2013 11:03:33 -0400 In-Reply-To: <20130314150004.GX11223@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On 2013-03-14 16:00, Gleb Natapov wrote: > On Thu, Mar 14, 2013 at 03:52:11PM +0100, Jan Kiszka wrote: >> vmx_vcpu_reset may now be called while already holding the srcu lock, so >> we may overwrite what was already saved there. Also, we lock and unlock >> in the same context, thus there was no need to save to the vcpu anyway. >> >> Signed-off-by: Jan Kiszka >> --- >> >> Marcelo just suggested this as the simplest fix for the issue caused by >> the INIT/SIPI patch. Avoiding srcu lock for TSS handling might still be >> possible but more tricky. >> >> arch/x86/kvm/vmx.c | 5 +++-- >> 1 files changed, 3 insertions(+), 2 deletions(-) >> >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> index 958ac3a..be5b1dc 100644 >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -4117,6 +4117,7 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu) >> { >> struct vcpu_vmx *vmx = to_vmx(vcpu); >> u64 msr; >> + int idx; >> >> vmx->rmode.vm86_active = 0; >> >> @@ -4190,9 +4191,9 @@ static void vmx_vcpu_reset(struct kvm_vcpu *vcpu) >> vmcs_write16(VIRTUAL_PROCESSOR_ID, vmx->vpid); >> >> vmx->vcpu.arch.cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET; >> - vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); >> + idx = srcu_read_lock(&vcpu->kvm->srcu); >> vmx_set_cr0(&vmx->vcpu, kvm_read_cr0(vcpu)); /* enter rmode */ >> - srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); >> + srcu_read_unlock(&vcpu->kvm->srcu, idx); > vmx_set_cr0() does: > srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); > vmx_set_tss_addr(vcpu->kvm, 0xfeffd000); > vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); > So with this change the sequence will be: > > vcpu->srcu_idx = srcu_read_lock() > idx = srcu_read_lock(&vcpu->kvm->srcu); > srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); > vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu); > srcu_read_unlock(&vcpu->kvm->srcu, idx); > srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx); > > Not sure this is valid. Grmbl, likely not. Jan -- Siemens AG, Corporate Technology, CT RTC ITP SDP-DE Corporate Competence Center Embedded Linux