From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bandan Das Subject: Re: [PATCH] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode Date: Tue, 03 Mar 2015 12:39:08 -0500 Message-ID: References: <1425353417-2060-1-git-send-email-fanwenyi0529@gmail.com> Mime-Version: 1.0 Content-Type: text/plain Cc: mtosatti@redhat.com, pbonzini@redhat.com, gleb@kernel.org, yang.z.zhang@intel.com, wanpeng.li@linux.intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, jan.kiszka@web.de, yong.y.wang@linux.intel.com To: Wincy Van Return-path: In-Reply-To: <1425353417-2060-1-git-send-email-fanwenyi0529@gmail.com> (Wincy Van's message of "Tue, 3 Mar 2015 11:30:17 +0800") Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org Wincy Van writes: > In commit 3af18d9c5fe9 ("KVM: nVMX: Prepare for using hardware MSR bitmap"), > we are setting MSR_BITMAP in prepare_vmcs02 if we should use hardware. This > is not enough since the field will be modified by following vmx_set_efer. > > Fix this by setting vmx_msr_bitmap_nested in vmx_set_msr_bitmap if vcpu is > in guest mode. > > Signed-off-by: Wincy Van > --- > arch/x86/kvm/vmx.c | 5 ++++- > 1 files changed, 4 insertions(+), 1 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index f7b20b4..f6e3457 100644 > --- a/arch/x86/kvm/vmx.c > +++ b/arch/x86/kvm/vmx.c > @@ -2168,7 +2168,10 @@ static void vmx_set_msr_bitmap(struct kvm_vcpu *vcpu) > { > unsigned long *msr_bitmap; > > - if (irqchip_in_kernel(vcpu->kvm) && apic_x2apic_mode(vcpu->arch.apic)) { > + if (is_guest_mode(vcpu)) > + msr_bitmap = vmx_msr_bitmap_nested; > + else if (irqchip_in_kernel(vcpu->kvm) && > + apic_x2apic_mode(vcpu->arch.apic)) { So, we end up writing the MSR_BITMAP field twice - once when we call nested_vmx_merge_msr_bitmap() and another here. Why don't we just remove the former since prepare_vmcs02 will call vmx_set_efer anyway ? Bandan > if (is_long_mode(vcpu)) > msr_bitmap = vmx_msr_bitmap_longmode_x2apic; > else