From patchwork Tue Oct 17 04:03:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Wanpeng Li X-Patchwork-Id: 10010623 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 281FB601E7 for ; Tue, 17 Oct 2017 04:04:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14736251F9 for ; Tue, 17 Oct 2017 04:04:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 091FF27E63; Tue, 17 Oct 2017 04:04:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 09570251F9 for ; Tue, 17 Oct 2017 04:04:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752222AbdJQEEH (ORCPT ); Tue, 17 Oct 2017 00:04:07 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:50218 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751039AbdJQEEF (ORCPT ); Tue, 17 Oct 2017 00:04:05 -0400 Received: by mail-pf0-f194.google.com with SMTP id b6so402487pfh.7; Mon, 16 Oct 2017 21:04:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BTp1EZROjxyeSG1xLF2NxVpzeixpYjxcP6Gi0YkL0k8=; b=NPtKSD6aq6B7IC8Cq7ghojOD6gbApm4XgQkjLDkWXZvpX1vaWDOcZUFGAPZcfNM/7H KwQxZHcc5J5qlcnuLg+OJLdup0tg/x8pHgmuiznKBBJ1uwfOo9ihiJ2AMgOt9eWB+MBH OwwkmHUNl24jNyUAvmZ6tVgOvgAdBJbAzukfp3vnMo/XVIrW6tUcf+pTU75A9yfYcQ+3 cIG2vwd6yBpbKfLMhbpTZY4nyGbVIT9MA0zH/Y0Vj53XCEN9m+GFIdOY85Mts2fjVAUM +xQKZxQRzITmPd9C+LbTetjH8wJEoT7anCASNjYaqQn4eoHhyehT+7jmfS3HhE65lu/r fJKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BTp1EZROjxyeSG1xLF2NxVpzeixpYjxcP6Gi0YkL0k8=; b=T8aN0nfGqhanlv/hte3te8ACh567d5mD2M5NvnrpGv1dEQ2OJXhh20fslO6DTxCcu7 ecWEMsTcmPdSVZDsLVymPgTnzxlHLr3WtCr15y6pqMM+Q3VbKFUvXXKfPOzHd+i0/oCd 65vtfZsgNGf3z3t6VMgjSPgM2pUv/717B3mxp8aDI3Akn6xVZSVWhQEB9kvCOie0/TVS SZSkOzcAQUxS9U+6ofa4rf5zcJhdDmS/KJFKp+NjN20Ux5/jZVxfI/fniiKfsPaaUB+t CarMsYQ9dUYxKOSjiYUElqHyynlocD9qt9gVVv3jDqgnpQLhkpCJelUmc/U4fh+Ulb5V 2RIg== X-Gm-Message-State: AMCzsaUxvLuQuxzuDZEyzUAlmfbQsAHIie6n0R/paMI9i89VlhK/X2+s xDYd5wiPjxeamK2NtEzHRXh1DQ== X-Google-Smtp-Source: AOwi7QA3vTyvh4nWP8ZJzgnanGmMJFPLZMEHX6IsId3NwUXpvzhFLQF09CS5ATgByDCz4gnog0HqXg== X-Received: by 10.84.244.2 with SMTP id g2mr11043027pll.400.1508213044569; Mon, 16 Oct 2017 21:04:04 -0700 (PDT) Received: from localhost ([203.205.141.123]) by smtp.gmail.com with ESMTPSA id j6sm17673223pfk.159.2017.10.16.21.04.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 16 Oct 2017 21:04:04 -0700 (PDT) From: Wanpeng Li X-Google-Original-From: Wanpeng Li To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Wanpeng Li , Jim Mattson Subject: [PATCH v2 2/2] KVM: VMX: Fix VPID capability detection Date: Mon, 16 Oct 2017 21:03:58 -0700 Message-Id: <1508213038-5593-2-git-send-email-wanpeng.li@hotmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1508213038-5593-1-git-send-email-wanpeng.li@hotmail.com> References: <1508213038-5593-1-git-send-email-wanpeng.li@hotmail.com> MIME-Version: 1.0 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- v1 -> v2: * rdmsr_safe instead of rdmsr * add more explanation to patch description arch/x86/kvm/vmx.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index a6861ca..bf804e5 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -3684,15 +3684,19 @@ 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 + vmx_capability.ept = 0; + if (!(_cpu_based_2nd_exec_control & SECONDARY_EXEC_ENABLE_VPID)) + vmx_capability.vpid = 0; min = VM_EXIT_SAVE_DEBUG_CONTROLS | VM_EXIT_ACK_INTR_ON_EXIT; #ifdef CONFIG_X86_64