From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758963AbbCDP7D (ORCPT ); Wed, 4 Mar 2015 10:59:03 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56555 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758261AbbCDP7A (ORCPT ); Wed, 4 Mar 2015 10:59:00 -0500 From: Bandan Das To: Wincy Van 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 Subject: Re: [PATCH v2] KVM: vmx: Set msr bitmap correctly if vcpu is in guest mode References: <1425450716-2216-1-git-send-email-fanwenyi0529@gmail.com> Date: Wed, 04 Mar 2015 10:58:52 -0500 In-Reply-To: <1425450716-2216-1-git-send-email-fanwenyi0529@gmail.com> (Wincy Van's message of "Wed, 4 Mar 2015 14:31:56 +0800") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Wincy, 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 | 11 +++++++---- > 1 files changed, 7 insertions(+), 4 deletions(-) > > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index f7b20b4..10a481b 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; Do you think this should be (is_guest_mode(vcpu) & (exec_control & CPU_BASED_USE_MSR_BITMAPS)) ? > + else if (irqchip_in_kernel(vcpu->kvm) && > + apic_x2apic_mode(vcpu->arch.apic)) { > if (is_long_mode(vcpu)) > msr_bitmap = vmx_msr_bitmap_longmode_x2apic; > else > @@ -9218,9 +9221,9 @@ static void prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12) > } > > if (cpu_has_vmx_msr_bitmap() && > - exec_control & CPU_BASED_USE_MSR_BITMAPS && > - nested_vmx_merge_msr_bitmap(vcpu, vmcs12)) { > - vmcs_write64(MSR_BITMAP, __pa(vmx_msr_bitmap_nested)); > + exec_control & CPU_BASED_USE_MSR_BITMAPS) { > + nested_vmx_merge_msr_bitmap(vcpu, vmcs12); > + /* MSR_BITMAP will be set by following vmx_set_efer. */ > } else > exec_control &= ~CPU_BASED_USE_MSR_BITMAPS;