From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751812AbdJRPk1 (ORCPT ); Wed, 18 Oct 2017 11:40:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59934 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751353AbdJRPkZ (ORCPT ); Wed, 18 Oct 2017 11:40:25 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 38D3361471 Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=pbonzini@redhat.com Subject: Re: [PATCH v3 2/2] KVM: VMX: Fix VPID capability detection To: Jim Mattson , Wanpeng Li Cc: LKML , kvm list , =?UTF-8?B?UmFkaW0gS3LEjW3DocWZ?= , Wanpeng Li References: <1508290980-3525-1-git-send-email-wanpeng.li@hotmail.com> <1508290980-3525-2-git-send-email-wanpeng.li@hotmail.com> From: Paolo Bonzini Message-ID: Date: Wed, 18 Oct 2017 17:40:17 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 18 Oct 2017 15:40:25 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 18/10/2017 17:39, Jim Mattson wrote: > As long as we're taking the "better safe than sorry" approach, why > don't we go ahead and clear vmx_capability.ept/vmx_capability.vpid > along with the warnings? Indeed. Paolo > On Tue, Oct 17, 2017 at 6:43 PM, Wanpeng Li wrote: >> From: Wanpeng Li >> >> In my setup, EPT is not exposed to L1, the VPID capability is exposed and >> can be observed by vmxcap tool in L1: >> INVVPID supported yes >> Individual-address INVVPID yes >> Single-context INVVPID yes >> All-context INVVPID yes >> Single-context-retaining-globals INVVPID yes >> >> However, the module parameter of VPID observed in L1 is always N, the >> cpu_has_vmx_invvpid() check in L1 KVM fails since vmx_capability.vpid >> is 0 and it is not read from MSR due to EPT is not exposed. >> >> The VPID can be used to tag linear mappings when EPT is not enabled. However, >> current logic just detects VPID capability if EPT is enabled, this patch >> fixes it. >> >> Cc: Paolo Bonzini >> Cc: Radim Krčmář >> Cc: Jim Mattson >> Signed-off-by: Wanpeng Li >> --- >> v2 -> v3: >> * add pr_warn_once >> v1 -> v2: >> * rdmsr_safe instead of rdmsr >> * add more explanation to patch description >> >> arch/x86/kvm/vmx.c | 13 ++++++++++--- >> 1 file changed, 10 insertions(+), 3 deletions(-) >> >> diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c >> index 3644540..c14e981 100644 >> --- a/arch/x86/kvm/vmx.c >> +++ b/arch/x86/kvm/vmx.c >> @@ -3681,15 +3681,22 @@ static __init int setup_vmcs_config(struct vmcs_config *vmcs_conf) >> SECONDARY_EXEC_VIRTUALIZE_X2APIC_MODE | >> SECONDARY_EXEC_VIRTUAL_INTR_DELIVERY); >> >> + rdmsr_safe(MSR_IA32_VMX_EPT_VPID_CAP, >> + &vmx_capability.ept, &vmx_capability.vpid); >> + >> if (_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_EPT) { >> /* CR3 accesses and invlpg don't need to cause VM Exits when EPT >> enabled */ >> _cpu_based_exec_control &= ~(CPU_BASED_CR3_LOAD_EXITING | >> CPU_BASED_CR3_STORE_EXITING | >> CPU_BASED_INVLPG_EXITING); >> - rdmsr(MSR_IA32_VMX_EPT_VPID_CAP, >> - vmx_capability.ept, vmx_capability.vpid); >> - } >> + } else if (vmx_capability.ept) >> + pr_warn_once("EPT CAP should not exist if not support " >> + "1-setting enable EPT VM-execution control\n"); >> + if (!(_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_VPID) && >> + vmx_capability.vpid) >> + pr_warn_once("VPID CAP should not exist if not support " >> + "1-setting enable VPID VM-execution control\n"); >> >> min = VM_EXIT_SAVE_DEBUG_CONTROLS | VM_EXIT_ACK_INTR_ON_EXIT; >> #ifdef CONFIG_X86_64 >> -- >> 2.7.4 >>