From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A0C3C433EF for ; Wed, 22 Jun 2022 16:44:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359147AbiFVQoq (ORCPT ); Wed, 22 Jun 2022 12:44:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359095AbiFVQom (ORCPT ); Wed, 22 Jun 2022 12:44:42 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8604033E19 for ; Wed, 22 Jun 2022 09:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916280; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TnNOuD5PLcP1eVchfr8bmV1vgpmm+EQNFnXXdb5fqjc=; b=cA4pCTvric2h4VUj38EO1XiIA9ylzkfDXpjiDFTOmB7IqdZXzKbiLHXnpTTVfH85+7Mevo 1n3l3Lz25YSeZD1q+C6HPM69bkpMxbXId5O+bwAfh8qh/yskE8Cq+v+mkw0lAQgrYOiarf z2iioEh4BtN5+nw4M5PxTNmogVngEto= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-216-2wVQuZinPYKc1pIz9A9f6A-1; Wed, 22 Jun 2022 12:44:37 -0400 X-MC-Unique: 2wVQuZinPYKc1pIz9A9f6A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 21E4C185A7A4; Wed, 22 Jun 2022 16:44:37 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3261040CFD0A; Wed, 22 Jun 2022 16:44:35 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 01/10] KVM: VMX: Move CPU_BASED_CR8_{LOAD,STORE}_EXITING filtering out of setup_vmcs_config() Date: Wed, 22 Jun 2022 18:44:23 +0200 Message-Id: <20220622164432.194640-2-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/vmx.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 5e14e4c40007..24da9e93bdab 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2490,11 +2490,6 @@ static __init int setup_vmcs_config(struct vmcs_conf= ig *vmcs_conf, if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS, &_cpu_based_exec_control) < 0) return -EIO; -#ifdef CONFIG_X86_64 - if (_cpu_based_exec_control & CPU_BASED_TPR_SHADOW) - _cpu_based_exec_control &=3D ~CPU_BASED_CR8_LOAD_EXITING & - ~CPU_BASED_CR8_STORE_EXITING; -#endif if (_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) { min2 =3D 0; opt2 =3D SECONDARY_EXEC_VIRTUALIZE_APIC_ACCESSES | @@ -4285,6 +4280,12 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx) { u32 exec_control =3D vmcs_config.cpu_based_exec_ctrl; =20 +#ifdef CONFIG_X86_64 + if (exec_control & CPU_BASED_TPR_SHADOW) + exec_control &=3D ~CPU_BASED_CR8_LOAD_EXITING & + ~CPU_BASED_CR8_STORE_EXITING; +#endif + if (vmx->vcpu.arch.switch_db_regs & KVM_DEBUGREG_WONT_EXIT) exec_control &=3D ~CPU_BASED_MOV_DR_EXITING; =20 --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93EBDC433EF for ; Wed, 22 Jun 2022 16:44:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376274AbiFVQov (ORCPT ); Wed, 22 Jun 2022 12:44:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236563AbiFVQoo (ORCPT ); Wed, 22 Jun 2022 12:44:44 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE73931917 for ; Wed, 22 Jun 2022 09:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qAGjG0pbpGd/rh2Rbpr2drl+brFnF3phOBJXafg5QB8=; b=FsTSG7Ff07B9ymjx1VVq3zP0va5bSN+o2TFy39L21vtJn1FBOMfyyxna24Bylf7xCWsQqA 7n2H2KXXW19b+DWhg1MjPhbiexJ/Jay4hR0MIdBWRtjm6ZES0eUJIfS/AMuuvy6oWh8P7M H+3ne6vIlE5JSMooXSLg6UBRkHmTzqY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-612-geKJJIBENcKhCbbMkcSdGw-1; Wed, 22 Jun 2022 12:44:40 -0400 X-MC-Unique: geKJJIBENcKhCbbMkcSdGw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4C3E7811E76; Wed, 22 Jun 2022 16:44:39 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EF5B40CFD0A; Wed, 22 Jun 2022 16:44:37 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 02/10] KVM: VMX: Add missing CPU based VM execution controls to vmcs_config Date: Wed, 22 Jun 2022 18:44:24 +0200 Message-Id: <20220622164432.194640-3-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/vmx.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 24da9e93bdab..01294a2fc1c1 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2483,8 +2483,14 @@ static __init int setup_vmcs_config(struct vmcs_conf= ig *vmcs_conf, CPU_BASED_INVLPG_EXITING | CPU_BASED_RDPMC_EXITING; =20 - opt =3D CPU_BASED_TPR_SHADOW | + opt =3D CPU_BASED_INTR_WINDOW_EXITING | + CPU_BASED_RDTSC_EXITING | + CPU_BASED_TPR_SHADOW | + CPU_BASED_NMI_WINDOW_EXITING | + CPU_BASED_USE_IO_BITMAPS | + CPU_BASED_MONITOR_TRAP_FLAG | CPU_BASED_USE_MSR_BITMAPS | + CPU_BASED_PAUSE_EXITING | CPU_BASED_ACTIVATE_SECONDARY_CONTROLS | CPU_BASED_ACTIVATE_TERTIARY_CONTROLS; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS, @@ -4280,6 +4286,13 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx) { u32 exec_control =3D vmcs_config.cpu_based_exec_ctrl; =20 + exec_control &=3D ~(CPU_BASED_INTR_WINDOW_EXITING | + CPU_BASED_RDTSC_EXITING | + CPU_BASED_NMI_WINDOW_EXITING | + CPU_BASED_USE_IO_BITMAPS | + CPU_BASED_MONITOR_TRAP_FLAG | + CPU_BASED_PAUSE_EXITING); + #ifdef CONFIG_X86_64 if (exec_control & CPU_BASED_TPR_SHADOW) exec_control &=3D ~CPU_BASED_CR8_LOAD_EXITING & --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A82BCCA47D for ; Wed, 22 Jun 2022 16:44:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376431AbiFVQo4 (ORCPT ); Wed, 22 Jun 2022 12:44:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359504AbiFVQop (ORCPT ); Wed, 22 Jun 2022 12:44:45 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8D9E5369D4 for ; Wed, 22 Jun 2022 09:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916283; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pPzUDtn7MUBOJvHbms5ez003D0L9U3ISPpMur3dPFnU=; b=Ezdlr1SoVVfsazHtc1kcQ8PF4wEUZ9K8/l70i2LdhheLVAUlN+PiEHI/z55ttiVPR3lJBn nbopVxEYMgXhgo921KhMH7/773SwbH6FiAEwLfrjbNISNYTLDHyvMmjwktFiYtjQzuYYOd F+kAA8REiBVRzZwz/8sk5o0T337soKc= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-241-OWK7qWCaNfm25c58Cceq7w-1; Wed, 22 Jun 2022 12:44:42 -0400 X-MC-Unique: OWK7qWCaNfm25c58Cceq7w-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C3A5129DD9A2; Wed, 22 Jun 2022 16:44:41 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 94FA640CFD0A; Wed, 22 Jun 2022 16:44:39 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 03/10] KVM: VMX: Move CPU_BASED_{CR3_LOAD,CR3_STORE,INVLPG}_EXITING filtering out of setup_vmcs_config() Date: Wed, 22 Jun 2022 18:44:25 +0200 Message-Id: <20220622164432.194640-4-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/vmx.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 01294a2fc1c1..4583de7f0324 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -4293,6 +4293,16 @@ static u32 vmx_exec_control(struct vcpu_vmx *vmx) CPU_BASED_MONITOR_TRAP_FLAG | CPU_BASED_PAUSE_EXITING); =20 + if (vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_ENABLE_EPT) { + /* + * CR3 accesses and invlpg don't need to cause VM Exits when EPT + * enabled. + */ + exec_control &=3D ~(CPU_BASED_CR3_LOAD_EXITING | + CPU_BASED_CR3_STORE_EXITING | + CPU_BASED_INVLPG_EXITING); + } + #ifdef CONFIG_X86_64 if (exec_control & CPU_BASED_TPR_SHADOW) exec_control &=3D ~CPU_BASED_CR8_LOAD_EXITING & --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 80382C43334 for ; Wed, 22 Jun 2022 16:45:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376541AbiFVQpA (ORCPT ); Wed, 22 Jun 2022 12:45:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376285AbiFVQou (ORCPT ); Wed, 22 Jun 2022 12:44:50 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C44C53617F for ; Wed, 22 Jun 2022 09:44:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GSBtSdSu4LlouvqjWZ6Inmz3gyUFbCQzH8RlRUwvO7g=; b=Q9k2L4HOQ01dTjOglGcM32xAzjll5IaEs5eWPf5ZzpAU89Jp9uhNYT/wtwezbKXKnv8U+6 aP2d/g03etLTb4CluNJV2ePkxVLU4y/jWr8xON6F7QYqU0QOR/YHnKGR8qDn9GiLCsnB9z g5bHc4Ie32TU9WAeiT6rLCV96hz0+qk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-373-6ykKyNHVPQODf8Nl97aXcg-1; Wed, 22 Jun 2022 12:44:44 -0400 X-MC-Unique: 6ykKyNHVPQODf8Nl97aXcg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 31C3D811E7A; Wed, 22 Jun 2022 16:44:44 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2214A40CFD0A; Wed, 22 Jun 2022 16:44:41 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 04/10] KVM: VMX: Add missing VMEXIT controls to vmcs_config Date: Wed, 22 Jun 2022 18:44:26 +0200 Message-Id: <20220622164432.194640-5-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/vmx.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 4583de7f0324..829d66ab6956 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2582,8 +2582,11 @@ static __init int setup_vmcs_config(struct vmcs_conf= ig *vmcs_conf, min |=3D VM_EXIT_HOST_ADDR_SPACE_SIZE; #endif opt =3D VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | + VM_EXIT_SAVE_IA32_PAT | VM_EXIT_LOAD_IA32_PAT | + VM_EXIT_SAVE_IA32_EFER | VM_EXIT_LOAD_IA32_EFER | + VM_EXIT_SAVE_VMX_PREEMPTION_TIMER | VM_EXIT_CLEAR_BNDCFGS | VM_EXIT_PT_CONCEAL_PIP | VM_EXIT_CLEAR_IA32_RTIT_CTL; @@ -4246,6 +4249,9 @@ static u32 vmx_vmexit_ctrl(void) { u32 vmexit_ctrl =3D vmcs_config.vmexit_ctrl; =20 + vmexit_ctrl &=3D ~(VM_EXIT_SAVE_IA32_PAT | VM_EXIT_SAVE_IA32_EFER | + VM_EXIT_SAVE_VMX_PREEMPTION_TIMER); + if (vmx_pt_mode_is_system()) vmexit_ctrl &=3D ~(VM_EXIT_PT_CONCEAL_PIP | VM_EXIT_CLEAR_IA32_RTIT_CTL); --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34377C433EF for ; Wed, 22 Jun 2022 16:45:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376624AbiFVQpC (ORCPT ); Wed, 22 Jun 2022 12:45:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358323AbiFVQow (ORCPT ); Wed, 22 Jun 2022 12:44:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E758337BDC for ; Wed, 22 Jun 2022 09:44:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dEd4vE77h1Pw+d5XhGtnzL5zzBP/vPs44XvuPaKduTs=; b=XxYpWiBep/m0Vt7+9sXfzRACA9d+AfoF4XPr6/rkyfb2DB+EWsRN6Me6UoocYbbrGTSyDE PMKP3GEAq3yNCO7cEe1UOhosu1KYIVt3l2quUYfiBJNJGI4CDABSMD3IeTEjjOSzZNKJV/ x1GzMvrlj069L1lMZP4noj5YIxVeDkA= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-74-BdX0B2MvNlWtPcqhe9Kqjw-1; Wed, 22 Jun 2022 12:44:47 -0400 X-MC-Unique: BdX0B2MvNlWtPcqhe9Kqjw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D3C3980029D; Wed, 22 Jun 2022 16:44:46 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8023A40CFD0A; Wed, 22 Jun 2022 16:44:44 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 05/10] KVM: VMX: Add missing VMENTRY controls to vmcs_config Date: Wed, 22 Jun 2022 18:44:27 +0200 Message-Id: <20220622164432.194640-6-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/vmx.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 829d66ab6956..7aab9225c4c3 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2608,7 +2608,10 @@ static __init int setup_vmcs_config(struct vmcs_conf= ig *vmcs_conf, _pin_based_exec_control &=3D ~PIN_BASED_POSTED_INTR; =20 min =3D VM_ENTRY_LOAD_DEBUG_CONTROLS; - opt =3D VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | + opt =3D VM_ENTRY_IA32E_MODE | + VM_ENTRY_SMM | + VM_ENTRY_DEACT_DUAL_MONITOR | + VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL | VM_ENTRY_LOAD_IA32_PAT | VM_ENTRY_LOAD_IA32_EFER | VM_ENTRY_LOAD_BNDCFGS | @@ -4237,6 +4240,9 @@ static u32 vmx_vmentry_ctrl(void) { u32 vmentry_ctrl =3D vmcs_config.vmentry_ctrl; =20 + vmentry_ctrl &=3D ~(VM_ENTRY_IA32E_MODE | VM_ENTRY_SMM | + VM_ENTRY_DEACT_DUAL_MONITOR); + if (vmx_pt_mode_is_system()) vmentry_ctrl &=3D ~(VM_ENTRY_PT_CONCEAL_PIP | VM_ENTRY_LOAD_IA32_RTIT_CTL); --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B312CCA483 for ; Wed, 22 Jun 2022 16:45:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376669AbiFVQpG (ORCPT ); Wed, 22 Jun 2022 12:45:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359339AbiFVQoy (ORCPT ); Wed, 22 Jun 2022 12:44:54 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0CF7B33E19 for ; Wed, 22 Jun 2022 09:44:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916293; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vmcKRKhFN9648itaEmK7Pyh7ynz/iKVO54dtfVAWN7o=; b=ibJ48XqW5rq+grX/liewg54zQkRCDHyylWj/ABiqaQZRhD5wXCB/1pF88rjj7vLG98LKn1 SvCxYwUZHVAIzDvcm2fZNl45LxC3hDjeTXXr1wLsCWSZ79h614JyiWPtNaBlGQTIgyVlYc urLzNoPTu2Y8nmyiYf32BwhfT8usal8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-34-KlhwBMv5MAixrQeESYeU8Q-1; Wed, 22 Jun 2022 12:44:49 -0400 X-MC-Unique: KlhwBMv5MAixrQeESYeU8Q-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 35CF1811E80; Wed, 22 Jun 2022 16:44:49 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1D4CC40CFD0A; Wed, 22 Jun 2022 16:44:46 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 06/10] KVM: nVMX: Use sanitized allowed-1 bits for VMX control MSRs Date: Wed, 22 Jun 2022 18:44:28 +0200 Message-Id: <20220622164432.194640-7-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Suggested-by: Sean Christopherson Signed-off-by: Vitaly Kuznetsov Reported-by: kernel test robot --- arch/x86/kvm/vmx/nested.c | 34 ++++++++++++++++------------------ arch/x86/kvm/vmx/nested.h | 2 +- arch/x86/kvm/vmx/vmx.c | 5 ++--- 3 files changed, 19 insertions(+), 22 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 7d8cd0ebcc75..8cc2187b5556 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6549,8 +6549,13 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void) * bit in the high half is on if the corresponding bit in the control field * may be on. See also vmx_control_verify(). */ -void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps) +void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_cap= s) { + struct nested_vmx_msrs *msrs =3D &vmcs_conf->nested; + + /* Take the allowed-1 bits from KVM's sanitized VMCS configuration. */ + u32 ignore_high; + /* * Note that as a general rule, the high half of the MSRs (bits in * the control fields which may be 1) should be initialized by the @@ -6567,11 +6572,11 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_m= srs *msrs, u32 ept_caps) */ =20 /* pin-based controls */ - rdmsr(MSR_IA32_VMX_PINBASED_CTLS, - msrs->pinbased_ctls_low, - msrs->pinbased_ctls_high); + rdmsr(MSR_IA32_VMX_PINBASED_CTLS, msrs->pinbased_ctls_low, ignore_high); msrs->pinbased_ctls_low |=3D PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR; + + msrs->pinbased_ctls_high =3D vmcs_conf->pin_based_exec_ctrl; msrs->pinbased_ctls_high &=3D PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING | @@ -6582,12 +6587,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_m= srs *msrs, u32 ept_caps) PIN_BASED_VMX_PREEMPTION_TIMER; =20 /* exit controls */ - rdmsr(MSR_IA32_VMX_EXIT_CTLS, - msrs->exit_ctls_low, - msrs->exit_ctls_high); msrs->exit_ctls_low =3D VM_EXIT_ALWAYSON_WITHOUT_TRUE_MSR; =20 + msrs->exit_ctls_high =3D vmcs_conf->vmexit_ctrl; msrs->exit_ctls_high &=3D #ifdef CONFIG_X86_64 VM_EXIT_HOST_ADDR_SPACE_SIZE | @@ -6603,11 +6606,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_m= srs *msrs, u32 ept_caps) msrs->exit_ctls_low &=3D ~VM_EXIT_SAVE_DEBUG_CONTROLS; =20 /* entry controls */ - rdmsr(MSR_IA32_VMX_ENTRY_CTLS, - msrs->entry_ctls_low, - msrs->entry_ctls_high); msrs->entry_ctls_low =3D VM_ENTRY_ALWAYSON_WITHOUT_TRUE_MSR; + + msrs->entry_ctls_high =3D vmcs_conf->vmentry_ctrl; msrs->entry_ctls_high &=3D #ifdef CONFIG_X86_64 VM_ENTRY_IA32E_MODE | @@ -6621,11 +6623,10 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_m= srs *msrs, u32 ept_caps) msrs->entry_ctls_low &=3D ~VM_ENTRY_LOAD_DEBUG_CONTROLS; =20 /* cpu-based controls */ - rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, - msrs->procbased_ctls_low, - msrs->procbased_ctls_high); msrs->procbased_ctls_low =3D CPU_BASED_ALWAYSON_WITHOUT_TRUE_MSR; + + msrs->procbased_ctls_high =3D vmcs_conf->cpu_based_exec_ctrl; msrs->procbased_ctls_high &=3D CPU_BASED_INTR_WINDOW_EXITING | CPU_BASED_NMI_WINDOW_EXITING | CPU_BASED_USE_TSC_OFFSETTING | @@ -6659,12 +6660,9 @@ void nested_vmx_setup_ctls_msrs(struct nested_vmx_ms= rs *msrs, u32 ept_caps) * depend on CPUID bits, they are added later by * vmx_vcpu_after_set_cpuid. */ - if (msrs->procbased_ctls_high & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) - rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2, - msrs->secondary_ctls_low, - msrs->secondary_ctls_high); - msrs->secondary_ctls_low =3D 0; + + msrs->secondary_ctls_high =3D vmcs_conf->cpu_based_2nd_exec_ctrl; msrs->secondary_ctls_high &=3D SECONDARY_EXEC_DESC | SECONDARY_EXEC_ENABLE_RDTSCP | diff --git a/arch/x86/kvm/vmx/nested.h b/arch/x86/kvm/vmx/nested.h index c92cea0b8ccc..fae047c6204b 100644 --- a/arch/x86/kvm/vmx/nested.h +++ b/arch/x86/kvm/vmx/nested.h @@ -17,7 +17,7 @@ enum nvmx_vmentry_status { }; =20 void vmx_leave_nested(struct kvm_vcpu *vcpu); -void nested_vmx_setup_ctls_msrs(struct nested_vmx_msrs *msrs, u32 ept_caps= ); +void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_cap= s); void nested_vmx_hardware_unsetup(void); __init int nested_vmx_hardware_setup(int (*exit_handlers[])(struct kvm_vcp= u *)); void nested_vmx_set_vmcs_shadowing_bitmap(void); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 7aab9225c4c3..37d5c5bc4cd2 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -7368,7 +7368,7 @@ static int __init vmx_check_processor_compat(void) if (setup_vmcs_config(&vmcs_conf, &vmx_cap) < 0) return -EIO; if (nested) - nested_vmx_setup_ctls_msrs(&vmcs_conf.nested, vmx_cap.ept); + nested_vmx_setup_ctls_msrs(&vmcs_conf, vmx_cap.ept); if (memcmp(&vmcs_config, &vmcs_conf, sizeof(struct vmcs_config)) !=3D 0) { printk(KERN_ERR "kvm: CPU %d feature inconsistency!\n", smp_processor_id()); @@ -8330,8 +8330,7 @@ static __init int hardware_setup(void) setup_default_sgx_lepubkeyhash(); =20 if (nested) { - nested_vmx_setup_ctls_msrs(&vmcs_config.nested, - vmx_capability.ept); + nested_vmx_setup_ctls_msrs(&vmcs_config, vmx_capability.ept); =20 r =3D nested_vmx_hardware_setup(kvm_vmx_exit_handlers); if (r) --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25B0DCCA47D for ; Wed, 22 Jun 2022 16:45:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376694AbiFVQpK (ORCPT ); Wed, 22 Jun 2022 12:45:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376562AbiFVQpA (ORCPT ); Wed, 22 Jun 2022 12:45:00 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7AB1833E19 for ; Wed, 22 Jun 2022 09:44:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916296; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8vrDYrcPrwgVhtqMnVmFlg3M56KevQMzRCP3HTMVToQ=; b=JA7LUsVJdna+Wk2Z9hbDTmAMlzzS3jwdqo8zJY0sYLySoeuippaPYCsgNT4T3MRgQA4wRP 3rpKFsccecfUB+46cILC6u2ncwxd38JLg4Gi6IfGEVzVMnUeH3Um1k9PqGzqZ8iiASfJzm 47y4VbJedAjp2zmMvwwpTtclEwoTz+w= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-AjmGu4D1OviUmzmqzELfEA-1; Wed, 22 Jun 2022 12:44:52 -0400 X-MC-Unique: AjmGu4D1OviUmzmqzELfEA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8CF241C068C0; Wed, 22 Jun 2022 16:44:51 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9611B40CFD0A; Wed, 22 Jun 2022 16:44:49 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 07/10] KVM: VMX: Store required-1 VMX controls in vmcs_config Date: Wed, 22 Jun 2022 18:44:29 +0200 Message-Id: <20220622164432.194640-8-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/capabilities.h | 5 +++++ arch/x86/kvm/vmx/vmx.c | 28 +++++++++++++++++++++------- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilitie= s.h index 069d8d298e1d..2e223440e7ed 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -60,11 +60,16 @@ struct vmcs_config { u32 basic_cap; u32 revision_id; u32 pin_based_exec_ctrl; + u32 pin_based_exec_ctrl_req1; u32 cpu_based_exec_ctrl; + u32 cpu_based_exec_ctrl_req1; u32 cpu_based_2nd_exec_ctrl; + u32 cpu_based_2nd_exec_ctrl_req1; u64 cpu_based_3rd_exec_ctrl; u32 vmexit_ctrl; + u32 vmexit_ctrl_req1; u32 vmentry_ctrl; + u32 vmentry_ctrl_req1; struct nested_vmx_msrs nested; }; extern struct vmcs_config vmcs_config; diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 37d5c5bc4cd2..05a9919a2fec 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2411,7 +2411,7 @@ static bool cpu_has_sgx(void) } =20 static __init int adjust_vmx_controls(u32 ctl_min, u32 ctl_opt, - u32 msr, u32 *result) + u32 msr, u32 *result_high, u32 *result_low) { u32 vmx_msr_low, vmx_msr_high; u32 ctl =3D ctl_min | ctl_opt; @@ -2425,7 +2425,8 @@ static __init int adjust_vmx_controls(u32 ctl_min, u3= 2 ctl_opt, if (ctl_min & ~ctl) return -EIO; =20 - *result =3D ctl; + *result_high =3D ctl; + *result_low =3D vmx_msr_low; return 0; } =20 @@ -2449,6 +2450,11 @@ static __init int setup_vmcs_config(struct vmcs_conf= ig *vmcs_conf, u64 _cpu_based_3rd_exec_control =3D 0; u32 _vmexit_control =3D 0; u32 _vmentry_control =3D 0; + u32 _pin_based_exec_control_low =3D 0; + u32 _cpu_based_exec_control_low =3D 0; + u32 _cpu_based_2nd_exec_control_low =3D 0; + u32 _vmexit_control_low =3D 0; + u32 _vmentry_control_low =3D 0; int i; =20 /* @@ -2494,7 +2500,8 @@ static __init int setup_vmcs_config(struct vmcs_confi= g *vmcs_conf, CPU_BASED_ACTIVATE_SECONDARY_CONTROLS | CPU_BASED_ACTIVATE_TERTIARY_CONTROLS; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PROCBASED_CTLS, - &_cpu_based_exec_control) < 0) + &_cpu_based_exec_control, + &_cpu_based_exec_control_low) < 0) return -EIO; if (_cpu_based_exec_control & CPU_BASED_ACTIVATE_SECONDARY_CONTROLS) { min2 =3D 0; @@ -2526,7 +2533,8 @@ static __init int setup_vmcs_config(struct vmcs_confi= g *vmcs_conf, opt2 |=3D SECONDARY_EXEC_ENCLS_EXITING; if (adjust_vmx_controls(min2, opt2, MSR_IA32_VMX_PROCBASED_CTLS2, - &_cpu_based_2nd_exec_control) < 0) + &_cpu_based_2nd_exec_control, + &_cpu_based_2nd_exec_control_low) < 0) return -EIO; } #ifndef CONFIG_X86_64 @@ -2591,14 +2599,15 @@ static __init int setup_vmcs_config(struct vmcs_con= fig *vmcs_conf, VM_EXIT_PT_CONCEAL_PIP | VM_EXIT_CLEAR_IA32_RTIT_CTL; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_EXIT_CTLS, - &_vmexit_control) < 0) + &_vmexit_control, &_vmexit_control_low) < 0) return -EIO; =20 min =3D PIN_BASED_EXT_INTR_MASK | PIN_BASED_NMI_EXITING; opt =3D PIN_BASED_VIRTUAL_NMIS | PIN_BASED_POSTED_INTR | PIN_BASED_VMX_PREEMPTION_TIMER; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_PINBASED_CTLS, - &_pin_based_exec_control) < 0) + &_pin_based_exec_control, + &_pin_based_exec_control_low) < 0) return -EIO; =20 if (cpu_has_broken_vmx_preemption_timer()) @@ -2618,7 +2627,7 @@ static __init int setup_vmcs_config(struct vmcs_confi= g *vmcs_conf, VM_ENTRY_PT_CONCEAL_PIP | VM_ENTRY_LOAD_IA32_RTIT_CTL; if (adjust_vmx_controls(min, opt, MSR_IA32_VMX_ENTRY_CTLS, - &_vmentry_control) < 0) + &_vmentry_control, &_vmentry_control_low) < 0) return -EIO; =20 for (i =3D 0; i < ARRAY_SIZE(vmcs_entry_exit_pairs); i++) { @@ -2684,11 +2693,16 @@ static __init int setup_vmcs_config(struct vmcs_con= fig *vmcs_conf, vmcs_conf->revision_id =3D vmx_msr_low; =20 vmcs_conf->pin_based_exec_ctrl =3D _pin_based_exec_control; + vmcs_conf->pin_based_exec_ctrl_req1 =3D _pin_based_exec_control_low; vmcs_conf->cpu_based_exec_ctrl =3D _cpu_based_exec_control; + vmcs_conf->cpu_based_exec_ctrl_req1 =3D _cpu_based_exec_control_low; vmcs_conf->cpu_based_2nd_exec_ctrl =3D _cpu_based_2nd_exec_control; + vmcs_conf->cpu_based_2nd_exec_ctrl_req1 =3D _cpu_based_2nd_exec_control_l= ow; vmcs_conf->cpu_based_3rd_exec_ctrl =3D _cpu_based_3rd_exec_control; vmcs_conf->vmexit_ctrl =3D _vmexit_control; + vmcs_conf->vmexit_ctrl_req1 =3D _vmexit_control_low; vmcs_conf->vmentry_ctrl =3D _vmentry_control; + vmcs_conf->vmentry_ctrl_req1 =3D _vmentry_control_low; =20 #if IS_ENABLED(CONFIG_HYPERV) if (enlightened_vmcs) --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EEC2C433EF for ; Wed, 22 Jun 2022 16:45:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376766AbiFVQp1 (ORCPT ); Wed, 22 Jun 2022 12:45:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376416AbiFVQpD (ORCPT ); Wed, 22 Jun 2022 12:45:03 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 488A93B2B9 for ; Wed, 22 Jun 2022 09:45:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916299; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=GaE2U7UBUXPfnfSWAzYbXlkrQKP/iwCTGxkHlUhFsfM=; b=fshTo4sjOSs2a5Ivhe/hBP5Ww0kCEdyrwFk6n/dYVD+au7U/3Re/C0gjXA+SO07sWuhecg g/aTF/1JLRZRfLv87tnQdQxxYXez001fFGQm+ifdOulw/m2B0Qsv13YfNfgnxw6+vlG3bc gBQrmGXMx22shm5DZJbxpBd5g+wu5v4= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-369-UxMJmz7iOCGUodEtfkeeuQ-1; Wed, 22 Jun 2022 12:44:55 -0400 X-MC-Unique: UxMJmz7iOCGUodEtfkeeuQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0ECBD3C1618D; Wed, 22 Jun 2022 16:44:54 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id D3E0B40CFD0A; Wed, 22 Jun 2022 16:44:51 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 08/10] KVM: nVMX: Use sanitized required-1 bits for VMX control MSRs Date: Wed, 22 Jun 2022 18:44:30 +0200 Message-Id: <20220622164432.194640-9-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/nested.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 8cc2187b5556..ede6314a641e 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6553,9 +6553,6 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *v= mcs_conf, u32 ept_caps) { struct nested_vmx_msrs *msrs =3D &vmcs_conf->nested; =20 - /* Take the allowed-1 bits from KVM's sanitized VMCS configuration. */ - u32 ignore_high; - /* * Note that as a general rule, the high half of the MSRs (bits in * the control fields which may be 1) should be initialized by the @@ -6572,8 +6569,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *v= mcs_conf, u32 ept_caps) */ =20 /* pin-based controls */ - rdmsr(MSR_IA32_VMX_PINBASED_CTLS, msrs->pinbased_ctls_low, ignore_high); - msrs->pinbased_ctls_low |=3D + msrs->pinbased_ctls_low =3D vmcs_conf->pin_based_exec_ctrl_req1 | PIN_BASED_ALWAYSON_WITHOUT_TRUE_MSR; =20 msrs->pinbased_ctls_high =3D vmcs_conf->pin_based_exec_ctrl; --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17ADBC433EF for ; Wed, 22 Jun 2022 16:45:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376493AbiFVQpk (ORCPT ); Wed, 22 Jun 2022 12:45:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376651AbiFVQpE (ORCPT ); Wed, 22 Jun 2022 12:45:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 6D7A73B56E for ; Wed, 22 Jun 2022 09:45:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916300; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5VvNXqHl0oOGZeRIwHa6ZjCr17no+OrzJZwyqt7fqv4=; b=b+dI3o2UWY/dAqx3o5Ejtq/71X+r3cTtj9QStPPx2qDHR+qE0aubWHxmiY2VWbZ2WVq7DQ YcLdJ2VKW97Z5FjST42Ayh43gqdNg6CpsKr2KW/1ID0M0ry+yoTVkUyLtzACtbCWURYtdv tRy86CP/Jg8Bb6zXfNn4TlsZahsF9jU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-16-8zpEM2pXPjOH3EZCpPgrwQ-1; Wed, 22 Jun 2022 12:44:57 -0400 X-MC-Unique: 8zpEM2pXPjOH3EZCpPgrwQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEEE785A584; Wed, 22 Jun 2022 16:44:56 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 687C240CFD0A; Wed, 22 Jun 2022 16:44:54 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 09/10] KVM: VMX: Cache MSR_IA32_VMX_MISC in vmcs_config Date: Wed, 22 Jun 2022 18:44:31 +0200 Message-Id: <20220622164432.194640-10-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/capabilities.h | 11 +++-------- arch/x86/kvm/vmx/vmx.c | 8 +++++--- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/arch/x86/kvm/vmx/capabilities.h b/arch/x86/kvm/vmx/capabilitie= s.h index 2e223440e7ed..9a73087c8314 100644 --- a/arch/x86/kvm/vmx/capabilities.h +++ b/arch/x86/kvm/vmx/capabilities.h @@ -70,6 +70,7 @@ struct vmcs_config { u32 vmexit_ctrl_req1; u32 vmentry_ctrl; u32 vmentry_ctrl_req1; + u64 misc; struct nested_vmx_msrs nested; }; extern struct vmcs_config vmcs_config; @@ -229,11 +230,8 @@ static inline bool cpu_has_vmx_vmfunc(void) =20 static inline bool cpu_has_vmx_shadow_vmcs(void) { - u64 vmx_msr; - /* check if the cpu supports writing r/o exit information fields */ - rdmsrl(MSR_IA32_VMX_MISC, vmx_msr); - if (!(vmx_msr & MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS)) + if (!(vmcs_config.misc & MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS)) return false; =20 return vmcs_config.cpu_based_2nd_exec_ctrl & @@ -375,10 +373,7 @@ static inline bool cpu_has_vmx_invvpid_global(void) =20 static inline bool cpu_has_vmx_intel_pt(void) { - u64 vmx_msr; - - rdmsrl(MSR_IA32_VMX_MISC, vmx_msr); - return (vmx_msr & MSR_IA32_VMX_MISC_INTEL_PT) && + return (vmcs_config.misc & MSR_IA32_VMX_MISC_INTEL_PT) && (vmcs_config.cpu_based_2nd_exec_ctrl & SECONDARY_EXEC_PT_USE_GPA) && (vmcs_config.vmentry_ctrl & VM_ENTRY_LOAD_IA32_RTIT_CTL); } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 05a9919a2fec..9d1896184729 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -2455,6 +2455,7 @@ static __init int setup_vmcs_config(struct vmcs_confi= g *vmcs_conf, u32 _cpu_based_2nd_exec_control_low =3D 0; u32 _vmexit_control_low =3D 0; u32 _vmentry_control_low =3D 0; + u64 misc_msr; int i; =20 /* @@ -2687,6 +2688,8 @@ static __init int setup_vmcs_config(struct vmcs_confi= g *vmcs_conf, if (((vmx_msr_high >> 18) & 15) !=3D 6) return -EIO; =20 + rdmsrl(MSR_IA32_VMX_MISC, misc_msr); + vmcs_conf->size =3D vmx_msr_high & 0x1fff; vmcs_conf->basic_cap =3D vmx_msr_high & ~0x1fff; =20 @@ -2703,6 +2706,7 @@ static __init int setup_vmcs_config(struct vmcs_confi= g *vmcs_conf, vmcs_conf->vmexit_ctrl_req1 =3D _vmexit_control_low; vmcs_conf->vmentry_ctrl =3D _vmentry_control; vmcs_conf->vmentry_ctrl_req1 =3D _vmentry_control_low; + vmcs_conf->misc =3D misc_msr; =20 #if IS_ENABLED(CONFIG_HYPERV) if (enlightened_vmcs) @@ -8305,11 +8309,9 @@ static __init int hardware_setup(void) =20 if (enable_preemption_timer) { u64 use_timer_freq =3D 5000ULL * 1000 * 1000; - u64 vmx_msr; =20 - rdmsrl(MSR_IA32_VMX_MISC, vmx_msr); cpu_preemption_timer_multi =3D - vmx_msr & VMX_MISC_PREEMPTION_TIMER_RATE_MASK; + vmcs_config.misc & VMX_MISC_PREEMPTION_TIMER_RATE_MASK; =20 if (tsc_khz) use_timer_freq =3D (u64)tsc_khz * 1000; --=20 2.35.3 From nobody Mon Apr 20 02:56:44 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4AF83C43334 for ; Wed, 22 Jun 2022 16:45:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359470AbiFVQps (ORCPT ); Wed, 22 Jun 2022 12:45:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376655AbiFVQpE (ORCPT ); Wed, 22 Jun 2022 12:45:04 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4505238BE5 for ; Wed, 22 Jun 2022 09:45:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655916301; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=M1HfEPQxq+5K96CtZ+44JB8AWO/RhjdBf/GFDOFx6Kw=; b=XH95acnTrZTqXZnqGU2S4NCkRM7JhqKtRZbOWN6PhQwKY3rmW8+W8Oxc3nQsfY0Y1F77os Eqatl94F+foy3qhdWlo1ORQfIxxH/9j7KeAo/v5Pg9LT9FcI5Js/pYt9Cqa+mr0nJuYHmN Xywv/GCXGWisij/sPrhtSBRQKOtlibw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-421-vsuI_6J9ORaj_Ry56z5AcA-1; Wed, 22 Jun 2022 12:44:59 -0400 X-MC-Unique: vsuI_6J9ORaj_Ry56z5AcA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3F743802D1C; Wed, 22 Jun 2022 16:44:59 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2F28940CFD0A; Wed, 22 Jun 2022 16:44:56 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini , Anirudh Rayabharam , Sean Christopherson Cc: Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RFC v1 10/10] KVM: nVMX: Use cached host MSR_IA32_VMX_MISC value for setting up nested MSR Date: Wed, 22 Jun 2022 18:44:32 +0200 Message-Id: <20220622164432.194640-11-vkuznets@redhat.com> In-Reply-To: <20220622164432.194640-1-vkuznets@redhat.com> References: <20220622164432.194640-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/nested.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index ede6314a641e..97d0c9fa4444 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -6738,10 +6738,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *= vmcs_conf, u32 ept_caps) msrs->secondary_ctls_high |=3D SECONDARY_EXEC_ENCLS_EXITING; =20 /* miscellaneous data */ - rdmsr(MSR_IA32_VMX_MISC, - msrs->misc_low, - msrs->misc_high); - msrs->misc_low &=3D VMX_MISC_SAVE_EFER_LMA; + msrs->misc_low =3D (u32)vmcs_conf->misc & VMX_MISC_SAVE_EFER_LMA; msrs->misc_low |=3D MSR_IA32_VMX_MISC_VMWRITE_SHADOW_RO_FIELDS | VMX_MISC_EMULATED_PREEMPTION_TIMER_RATE | --=20 2.35.3