From nobody Sun Apr 26 22:57:00 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 9B3C6CCA473 for ; Tue, 21 Jun 2022 15:59:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353317AbiFUP7b (ORCPT ); Tue, 21 Jun 2022 11:59:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353472AbiFUP6n (ORCPT ); Tue, 21 Jun 2022 11:58:43 -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 0C4BFB96 for ; Tue, 21 Jun 2022 08:58:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827121; 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=fEdjnqcwdrP4ky6Ydkpn9hPwr/5/PhNfBhkdDi68CEI=; b=cF0TZF9RhTW8GEvG8CWIibGiyF9uRkI6rSm+OnGy1iingZfymzQekxRhUh+78Df9zotfKE B5xpILAPHBOlNs/KZZkdBKIb/lkbiwWsgnI7+PC1u+ZDqHuCqjUN1DEUplNEfAxpK7hZ6X lF4Cx/GHuLMB2V/M88OUwbXoDmDTKQg= 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-577-QwavBVFYP1iX3GUw0rbBlQ-1; Tue, 21 Jun 2022 11:58:36 -0400 X-MC-Unique: QwavBVFYP1iX3GUw0rbBlQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 66DFE895683; Tue, 21 Jun 2022 15:58:36 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 512CB2026985; Tue, 21 Jun 2022 15:58:34 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/11] KVM: x86: hyper-v: Expose access to debug MSRs in the partition privilege flags Date: Tue, 21 Jun 2022 17:58:20 +0200 Message-Id: <20220621155830.60115-2-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" For some features, Hyper-V spec defines two separate CPUID bits: one listing whether the feature is supported or not and another one showing whether guest partition was granted access to the feature ("partition privilege mask"). 'Debug MSRs available' is one of such features. Add the missing 'access' bit. Fixes: f97f5a56f597 ("x86/kvm/hyper-v: Add support for synthetic debugger i= nterface") Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/hyperv.c | 1 + include/asm-generic/hyperv-tlfs.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index e2e95a6fccfd..e08189211d9a 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -2496,6 +2496,7 @@ int kvm_get_hv_cpuid(struct kvm_vcpu *vcpu, struct kv= m_cpuid2 *cpuid, ent->eax |=3D HV_MSR_RESET_AVAILABLE; ent->eax |=3D HV_MSR_REFERENCE_TSC_AVAILABLE; ent->eax |=3D HV_ACCESS_FREQUENCY_MSRS; + ent->eax |=3D HV_ACCESS_DEBUG_MSRS; ent->eax |=3D HV_ACCESS_REENLIGHTENMENT; =20 ent->ebx |=3D HV_POST_MESSAGES; diff --git a/include/asm-generic/hyperv-tlfs.h b/include/asm-generic/hyperv= -tlfs.h index fdce7a4cfc6f..1d99dd296a76 100644 --- a/include/asm-generic/hyperv-tlfs.h +++ b/include/asm-generic/hyperv-tlfs.h @@ -70,6 +70,8 @@ #define HV_MSR_GUEST_IDLE_AVAILABLE BIT(10) /* Partition local APIC and TSC frequency registers available */ #define HV_ACCESS_FREQUENCY_MSRS BIT(11) +/* Debug MSRs available */ +#define HV_ACCESS_DEBUG_MSRS BIT(12) /* AccessReenlightenmentControls privilege */ #define HV_ACCESS_REENLIGHTENMENT BIT(13) /* AccessTscInvariantControls privilege */ --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 1D750C433EF for ; Tue, 21 Jun 2022 15:59:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353477AbiFUP7l (ORCPT ); Tue, 21 Jun 2022 11:59:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353479AbiFUP6o (ORCPT ); Tue, 21 Jun 2022 11:58:44 -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 8D8C3C56 for ; Tue, 21 Jun 2022 08:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827122; 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=+8vUSQrDAvTlo9lTqBRicNMYXJXENHDUMVIYZB5FKsI=; b=ZWdjlcAe6WBnyu3SCxCUBgadzt40gP3zsB0EjHuK+NqEu9LcKGmuRiYPq6f0VGMtOhFKed QXHHusbfLoImdLOYUjjY4NjVY8TLXbYji2SMDou3U95qQWVlEOneC+WSj4xtD7+NYVtlkc bKr1nz679Wzicrofwg07FFPmITKGdSY= 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-623-uk7UD30DNjiivtp7VBsyNg-1; Tue, 21 Jun 2022 11:58:39 -0400 X-MC-Unique: uk7UD30DNjiivtp7VBsyNg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D66FE3C10231; Tue, 21 Jun 2022 15:58:38 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id C7DDE2026D64; Tue, 21 Jun 2022 15:58:36 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/11] x86/hyperv: Fix 'struct hv_enlightened_vmcs' definition Date: Tue, 21 Jun 2022 17:58:21 +0200 Message-Id: <20220621155830.60115-3-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Section 1.9 of TLFS v6.0b says: "All structures are padded in such a way that fields are aligned naturally (that is, an 8-byte field is aligned to an offset of 8 bytes and so on)". 'struct enlightened_vmcs' has a glitch: ... struct { u32 nested_flush_hypercall:1; /* 836: 0 4= */ u32 msr_bitmap:1; /* 836: 1 4 */ u32 reserved:30; /* 836: 2 4 */ } hv_enlightenments_control; /* 836 4 */ u32 hv_vp_id; /* 840 4 */ u64 hv_vm_id; /* 844 8 */ u64 partition_assist_page; /* 852 8 */ ... And the observed values in 'partition_assist_page' make no sense at all. Fix the layout by padding the structure properly. Fixes: 68d1eb72ee99 ("x86/hyper-v: define struct hv_enlightened_vmcs and cl= ean field bits") Reviewed-by: Maxim Levitsky Reviewed-by: Michael Kelley Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/hyperv-tlfs.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hype= rv-tlfs.h index 0a9407dc0859..6f0acc45e67a 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -546,7 +546,7 @@ struct hv_enlightened_vmcs { u64 guest_rip; =20 u32 hv_clean_fields; - u32 hv_padding_32; + u32 padding32_1; u32 hv_synthetic_controls; struct { u32 nested_flush_hypercall:1; @@ -554,7 +554,7 @@ struct hv_enlightened_vmcs { u32 reserved:30; } __packed hv_enlightenments_control; u32 hv_vp_id; - + u32 padding32_2; u64 hv_vm_id; u64 partition_assist_page; u64 padding64_4[4]; --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 7A336CCA473 for ; Tue, 21 Jun 2022 15:59:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353537AbiFUP7r (ORCPT ); Tue, 21 Jun 2022 11:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353488AbiFUP6o (ORCPT ); Tue, 21 Jun 2022 11:58: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 CC32FB96 for ; Tue, 21 Jun 2022 08:58:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827123; 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=qqM0GdHyxcksDuwznBTEVlvia7GmEG1xLhXl8yuf6VA=; b=Q3HMEmMrGp9i/pZ6sXJxaVM/RAFRdBGtDcYxTnQw+pJlua2Wp4zZtDYZkTv/9ogWp+Jisc g6Wik4FI8hjA5oRT8Z3dH0M9O/dpc9R4C6XweQ5w9y0Kfj5BesiSexRGg6xIS5PSd89BSd D3sLCHC+ZKJ8nNsUvRolu1+jGeoVu4k= 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-460-k49aEdnVPc2jT38wNtTONw-1; Tue, 21 Jun 2022 11:58:41 -0400 X-MC-Unique: k49aEdnVPc2jT38wNtTONw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 207C21C08965; Tue, 21 Jun 2022 15:58:41 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2A0D82026D64; Tue, 21 Jun 2022 15:58:39 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/11] x86/hyperv: Update 'struct hv_enlightened_vmcs' definition Date: Tue, 21 Jun 2022 17:58:22 +0200 Message-Id: <20220621155830.60115-4-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Updated Hyper-V Enlightened VMCS specification lists several new fields for the following features: - PerfGlobalCtrl - EnclsExitingBitmap - Tsc Scaling - GuestLbrCtl - CET - SSP Update the definition. Note: The latest TLFS is available at https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/tlfs/tlfs Signed-off-by: Vitaly Kuznetsov --- arch/x86/include/asm/hyperv-tlfs.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/hyperv-tlfs.h b/arch/x86/include/asm/hype= rv-tlfs.h index 6f0acc45e67a..fd334e8defb7 100644 --- a/arch/x86/include/asm/hyperv-tlfs.h +++ b/arch/x86/include/asm/hyperv-tlfs.h @@ -559,9 +559,20 @@ struct hv_enlightened_vmcs { u64 partition_assist_page; u64 padding64_4[4]; u64 guest_bndcfgs; - u64 padding64_5[7]; + u64 guest_ia32_perf_global_ctrl; + u64 guest_ia32_s_cet; + u64 guest_ssp; + u64 guest_ia32_int_ssp_table_addr; + u64 guest_ia32_lbr_ctl; + u64 padding64_5[2]; u64 xss_exit_bitmap; - u64 padding64_6[7]; + u64 host_ia32_perf_global_ctrl; + u64 encls_exiting_bitmap; + u64 tsc_multiplier; + u64 host_ia32_s_cet; + u64 host_ssp; + u64 host_ia32_int_ssp_table_addr; + u64 padding64_6; } __packed; =20 #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE 0 --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 B4BE9C433EF for ; Tue, 21 Jun 2022 15:59:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353446AbiFUP7x (ORCPT ); Tue, 21 Jun 2022 11:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353536AbiFUP6t (ORCPT ); Tue, 21 Jun 2022 11:58:49 -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 D26F1B96 for ; Tue, 21 Jun 2022 08:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827128; 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=PNBrmWnN3XnulCkQsAu4oIaBrmhBegkKO8NaBiEN1js=; b=OlVjr7MZuLuvh8mkRj2jO7aJ8rhToms7QOFDz/drB9Akjn5Q+Jo5b0ZGcKW+xMQl7DGxKO pSWvwDN2Lxnntrfz+uanLj/rw+/ynYDb4vR+QLu0h8/zyDX3YPgcP2Cgce99IOouCzQARO IabEJgcZaNeygOaz2aTChpAo3l/ijz0= 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-235-TCTk5-TjO9iOqGzTs-VyqQ-1; Tue, 21 Jun 2022 11:58:44 -0400 X-MC-Unique: TCTk5-TjO9iOqGzTs-VyqQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 76C4E101E989; Tue, 21 Jun 2022 15:58:43 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F0362026D64; Tue, 21 Jun 2022 15:58:41 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/11] KVM: VMX: Define VMCS-to-EVMCS conversion for the new fields Date: Tue, 21 Jun 2022 17:58:23 +0200 Message-Id: <20220621155830.60115-5-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Enlightened VMCS v1 definition was updated with new fields, support them in KVM by defining VMCS-to-EVMCS conversion. Note: SSP, CET and Guest LBR features are not supported by KVM yet and the corresponding fields are not defined in 'enum vmcs_field', leave them commented out for now. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/evmcs.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/x86/kvm/vmx/evmcs.c b/arch/x86/kvm/vmx/evmcs.c index 6a61b1ae7942..8bea5dea0341 100644 --- a/arch/x86/kvm/vmx/evmcs.c +++ b/arch/x86/kvm/vmx/evmcs.c @@ -28,6 +28,8 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] =3D { HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), EVMCS1_FIELD(HOST_IA32_EFER, host_ia32_efer, HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), + EVMCS1_FIELD(HOST_IA32_PERF_GLOBAL_CTRL, host_ia32_perf_global_ctrl, + HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), EVMCS1_FIELD(HOST_CR0, host_cr0, HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), EVMCS1_FIELD(HOST_CR3, host_cr3, @@ -78,6 +80,8 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] =3D { HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), EVMCS1_FIELD(GUEST_IA32_EFER, guest_ia32_efer, HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), + EVMCS1_FIELD(GUEST_IA32_PERF_GLOBAL_CTRL, guest_ia32_perf_global_ctrl, + HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), EVMCS1_FIELD(GUEST_PDPTR0, guest_pdptr0, HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), EVMCS1_FIELD(GUEST_PDPTR1, guest_pdptr1, @@ -126,6 +130,28 @@ const struct evmcs_field vmcs_field_to_evmcs_1[] =3D { HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), EVMCS1_FIELD(XSS_EXIT_BITMAP, xss_exit_bitmap, HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2), + EVMCS1_FIELD(ENCLS_EXITING_BITMAP, encls_exiting_bitmap, + HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2), + EVMCS1_FIELD(TSC_MULTIPLIER, tsc_multiplier, + HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONTROL_GRP2), + /* + * Not used by KVM: + * + * EVMCS1_FIELD(0x00006828, guest_ia32_s_cet, + * HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), + * EVMCS1_FIELD(0x0000682A, guest_ssp, + * HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_BASIC), + * EVMCS1_FIELD(0x0000682C, guest_ia32_int_ssp_table_addr, + * HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), + * EVMCS1_FIELD(0x00002816, guest_ia32_lbr_ctl, + * HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUEST_GRP1), + * EVMCS1_FIELD(0x00006C18, host_ia32_s_cet, + * HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), + * EVMCS1_FIELD(0x00006C1A, host_ssp, + * HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), + * EVMCS1_FIELD(0x00006C1C, host_ia32_int_ssp_table_addr, + * HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST_GRP1), + */ =20 /* 64 bit read only */ EVMCS1_FIELD(GUEST_PHYSICAL_ADDRESS, guest_physical_address, --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 088EAC43334 for ; Tue, 21 Jun 2022 15:59:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353304AbiFUP7v (ORCPT ); Tue, 21 Jun 2022 11:59:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353533AbiFUP6t (ORCPT ); Tue, 21 Jun 2022 11:58:49 -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 91EC0B60 for ; Tue, 21 Jun 2022 08:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827127; 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=4rgW4mfoueEcPk9tm2t1FQw4zly3B1VmZPYs7WOmIpY=; b=NoMkzK2gWcEZcgNijJ50q3OcFuI03dLCJqqhyz6DVWe+0XRdUqF5rCP8lCt7swvPwsL8a+ AHYpijNcmzqnQbK9zis59oo8LNfZ7Y6xcsDP9bIq0y8+O33c1iQoniF3lam6LgEYvX2QUz y5uyx4bAVqCp/5HIQWpDWVtp2J3gR3g= 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-558-tbG6flEhNpOvoNDqDUKB8w-1; Tue, 21 Jun 2022 11:58:46 -0400 X-MC-Unique: tbG6flEhNpOvoNDqDUKB8w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0B90A2999B36; Tue, 21 Jun 2022 15:58:46 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id D72FC2026D64; Tue, 21 Jun 2022 15:58:43 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/11] KVM: nVMX: Support several new fields in eVMCSv1 Date: Tue, 21 Jun 2022 17:58:24 +0200 Message-Id: <20220621155830.60115-6-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Enlightened VMCS v1 definition was updated with new fields, add support for them for Hyper-V on KVM. Note: SSP, CET and Guest LBR features are not supported by KVM yet and 'struct vmcs12' has no corresponding fields. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/nested.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 7d8cd0ebcc75..162f4b4502e1 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -1602,6 +1602,10 @@ static void copy_enlightened_to_vmcs12(struct vcpu_v= mx *vmx, u32 hv_clean_fields vmcs12->guest_rflags =3D evmcs->guest_rflags; vmcs12->guest_interruptibility_info =3D evmcs->guest_interruptibility_info; + /* + * Not present in struct vmcs12: + * vmcs12->guest_ssp =3D evmcs->guest_ssp; + */ } =20 if (unlikely(!(hv_clean_fields & @@ -1648,6 +1652,13 @@ static void copy_enlightened_to_vmcs12(struct vcpu_v= mx *vmx, u32 hv_clean_fields vmcs12->host_fs_selector =3D evmcs->host_fs_selector; vmcs12->host_gs_selector =3D evmcs->host_gs_selector; vmcs12->host_tr_selector =3D evmcs->host_tr_selector; + vmcs12->host_ia32_perf_global_ctrl =3D evmcs->host_ia32_perf_global_ctrl; + /* + * Not present in struct vmcs12: + * vmcs12->host_ia32_s_cet =3D evmcs->host_ia32_s_cet; + * vmcs12->host_ssp =3D evmcs->host_ssp; + * vmcs12->host_ia32_int_ssp_table_addr =3D evmcs->host_ia32_int_ssp_tab= le_addr; + */ } =20 if (unlikely(!(hv_clean_fields & @@ -1715,6 +1726,8 @@ static void copy_enlightened_to_vmcs12(struct vcpu_vm= x *vmx, u32 hv_clean_fields vmcs12->tsc_offset =3D evmcs->tsc_offset; vmcs12->virtual_apic_page_addr =3D evmcs->virtual_apic_page_addr; vmcs12->xss_exit_bitmap =3D evmcs->xss_exit_bitmap; + vmcs12->encls_exiting_bitmap =3D evmcs->encls_exiting_bitmap; + vmcs12->tsc_multiplier =3D evmcs->tsc_multiplier; } =20 if (unlikely(!(hv_clean_fields & @@ -1762,6 +1775,13 @@ static void copy_enlightened_to_vmcs12(struct vcpu_v= mx *vmx, u32 hv_clean_fields vmcs12->guest_bndcfgs =3D evmcs->guest_bndcfgs; vmcs12->guest_activity_state =3D evmcs->guest_activity_state; vmcs12->guest_sysenter_cs =3D evmcs->guest_sysenter_cs; + vmcs12->guest_ia32_perf_global_ctrl =3D evmcs->guest_ia32_perf_global_ct= rl; + /* + * Not present in struct vmcs12: + * vmcs12->guest_ia32_s_cet =3D evmcs->guest_ia32_s_cet; + * vmcs12->guest_ia32_lbr_ctl =3D evmcs->guest_ia32_lbr_ctl; + * vmcs12->guest_ia32_int_ssp_table_addr =3D evmcs->guest_ia32_int_ssp_t= able_addr; + */ } =20 /* @@ -1864,12 +1884,23 @@ static void copy_vmcs12_to_enlightened(struct vcpu_= vmx *vmx) * evmcs->vm_exit_msr_store_count =3D vmcs12->vm_exit_msr_store_count; * evmcs->vm_exit_msr_load_count =3D vmcs12->vm_exit_msr_load_count; * evmcs->vm_entry_msr_load_count =3D vmcs12->vm_entry_msr_load_count; + * evmcs->guest_ia32_perf_global_ctrl =3D vmcs12->guest_ia32_perf_global_= ctrl; + * evmcs->host_ia32_perf_global_ctrl =3D vmcs12->host_ia32_perf_global_ct= rl; + * evmcs->encls_exiting_bitmap =3D vmcs12->encls_exiting_bitmap; + * evmcs->tsc_multiplier =3D vmcs12->tsc_multiplier; * * Not present in struct vmcs12: * evmcs->exit_io_instruction_ecx =3D vmcs12->exit_io_instruction_ecx; * evmcs->exit_io_instruction_esi =3D vmcs12->exit_io_instruction_esi; * evmcs->exit_io_instruction_edi =3D vmcs12->exit_io_instruction_edi; * evmcs->exit_io_instruction_eip =3D vmcs12->exit_io_instruction_eip; + * evmcs->host_ia32_s_cet =3D vmcs12->host_ia32_s_cet; + * evmcs->host_ssp =3D vmcs12->host_ssp; + * evmcs->host_ia32_int_ssp_table_addr =3D vmcs12->host_ia32_int_ssp_tabl= e_addr; + * evmcs->guest_ia32_s_cet =3D vmcs12->guest_ia32_s_cet; + * evmcs->guest_ia32_lbr_ctl =3D vmcs12->guest_ia32_lbr_ctl; + * evmcs->guest_ia32_int_ssp_table_addr =3D vmcs12->guest_ia32_int_ssp_ta= ble_addr; + * evmcs->guest_ssp =3D vmcs12->guest_ssp; */ =20 evmcs->guest_es_selector =3D vmcs12->guest_es_selector; --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 93CF5C433EF for ; Tue, 21 Jun 2022 16:00:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353509AbiFUQAH (ORCPT ); Tue, 21 Jun 2022 12:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353552AbiFUP6y (ORCPT ); Tue, 21 Jun 2022 11:58:54 -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 62E65C56 for ; Tue, 21 Jun 2022 08:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827132; 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=Y9f+5hJejFOP7LVQYOM+alkQkCfaW5L37ESdvjKAjl4=; b=aZKKoCCc3idA/jAw7iOk63sRmQtH3F1lJ2yL2XFyesrRQn0eQlE2hHZS34B98yhlULG1YH +rPh8gWu98Tcq3+EKQ6Bu8bN+CsQJw9Ig2Q9yrxiDEYE6YRPoGIZC0tv/oDJtBfGqJMt9c au6n3w3LuyXoRqkpx5hrD7llti0+//0= 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-511-gVrb6TzzNWWxa7Poj3eyyg-1; Tue, 21 Jun 2022 11:58:49 -0400 X-MC-Unique: gVrb6TzzNWWxa7Poj3eyyg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C7D41100BADC; Tue, 21 Jun 2022 15:58:48 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6BF992026985; Tue, 21 Jun 2022 15:58:46 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/11] KVM: nVMX: Introduce KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 Date: Tue, 21 Jun 2022 17:58:25 +0200 Message-Id: <20220621155830.60115-7-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Turns out Enlightened VMCS can gain new fields without version change and KVM_CAP_HYPERV_ENLIGHTENED_VMCS which KVM currently has cant's handle this reliably. In particular, just updating the current definition of eVMCSv1 with the new fields and adjusting the VMX MSR filtering will inevitably break live migration to older KVMs. Note: enabling eVMCS and setting VMX feature MSR can happen in any order. Introduce a notion of KVM internal "Enlightened VMCS revision" and add a new capability allowing to add fields to Enlightened VMCS while keeping its version. Signed-off-by: Vitaly Kuznetsov --- Documentation/virt/kvm/api.rst | 42 ++++++++++++++++++++++++++++++++- arch/x86/include/asm/kvm_host.h | 2 +- arch/x86/kvm/vmx/evmcs.c | 20 +++++++++++----- arch/x86/kvm/vmx/evmcs.h | 13 ++++++++-- arch/x86/kvm/vmx/nested.c | 10 ++++---- arch/x86/kvm/vmx/vmx.c | 2 +- arch/x86/kvm/vmx/vmx.h | 15 ++++++------ arch/x86/kvm/x86.c | 15 +++++++++++- include/uapi/linux/kvm.h | 3 ++- 9 files changed, 97 insertions(+), 25 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index 84c486ce6279..248386247bbf 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -4974,7 +4974,7 @@ version has the following quirks: =20 - HYPERV_CPUID_NESTED_FEATURES leaf and HV_X64_ENLIGHTENED_VMCS_RECOMMENDED feature bit are only exposed when Enlightened VMCS was previously enabled - on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS). + on the corresponding vCPU (KVM_CAP_HYPERV_ENLIGHTENED_VMCS2). - HV_STIMER_DIRECT_MODE_AVAILABLE bit is only exposed with in-kernel LAPIC. (presumes KVM_CREATE_IRQCHIP has already been called). =20 @@ -8193,6 +8193,46 @@ PV guests. The `KVM_PV_DUMP` command is available fo= r the dump related UV data. Also the vcpu ioctl `KVM_S390_PV_CPU_COMMAND` is available and supports the `KVM_PV_DUMP_CPU` subcommand. =20 +8.38 KVM_CAP_HYPERV_ENLIGHTENED_VMCS +------------------------------------ + +:Capability: KVM_CAP_HYPERV_ENLIGHTENED_VMCS +:Architectures: x86 +:Type: vcpu +:Parameters: arg[0] is a pointer to uint16_t where the supported Enlighten= ed +VMCS version range will be stored by KVM. +:Returns: 0 on success, -EINVAL when Enlightened VMCS is already enabled, +-EFAULT when write to arg[0] fails. + +This capability enables Enlightened VMCS interface. Obsolete, use +KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 instead. + +8.39 KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 +------------------------------------- + +:Capability: KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 +:Architectures: x86 +:Type: vcpu +:Parameters: arg[0] is the desired Enlightened VMCS revision (uint32_t). S= pecial +value 'U32_MAX' indicates the latest supported revision. (Optional) arg[1]= is a +pointer to 'uint16_t' where the supported Enlightened VMCS version range w= ill be +stored by KVM. +:Returns: 0 on success, -ENOTTY on SVM, -EINVAL when Enlightened VMCS is a= lready +enabled or the requested revision is not supported, -EFAULT when write to = arg[1] +fails. + +This capability enables Hyper-V Enlightened VMCS interface as described in +Hyper-V Top Level Functional Specification (TLFS). Note: when the interfac= e is +enabled, L1 guest doesn't necessarily have to use it, however, the exposed= VMX +features will be limited to what the particular revision of the Enlightene= d VMCS +supports. + +Enlightened VMCS version range (optionally written to arg[1]) is encoded i= n the +following way: + ((uint8_t)HIGHEST_SUPPORTED_VERSION << 8) | (uint8_t)LOWEST_SUPPORTED_VER= SION + +The interface is only available on VMX. Once set, changing the supported +Enlightened VMCS revision not supported. =20 9. Known KVM API problems =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index 7e98b2876380..f6c087b10472 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1629,7 +1629,7 @@ struct kvm_x86_nested_ops { bool (*get_nested_state_pages)(struct kvm_vcpu *vcpu); int (*write_log_dirty)(struct kvm_vcpu *vcpu, gpa_t l2_gpa); =20 - int (*enable_evmcs)(struct kvm_vcpu *vcpu, + int (*enable_evmcs)(struct kvm_vcpu *vcpu, u32 evmcs_revision, uint16_t *vmcs_version); uint16_t (*get_evmcs_version)(struct kvm_vcpu *vcpu); }; diff --git a/arch/x86/kvm/vmx/evmcs.c b/arch/x86/kvm/vmx/evmcs.c index 8bea5dea0341..21d9f0ed4bd2 100644 --- a/arch/x86/kvm/vmx/evmcs.c +++ b/arch/x86/kvm/vmx/evmcs.c @@ -362,7 +362,7 @@ uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu) * KVM_EVMCS_VERSION. */ if (kvm_cpu_cap_get(X86_FEATURE_VMX) && - (!vcpu || to_vmx(vcpu)->nested.enlightened_vmcs_enabled)) + (!vcpu || to_vmx(vcpu)->nested.active_evmcs_revision)) return (KVM_EVMCS_VERSION << 8) | 1; =20 return 0; @@ -453,15 +453,23 @@ int nested_evmcs_check_controls(struct vmcs12 *vmcs12) return ret; } =20 -int nested_enable_evmcs(struct kvm_vcpu *vcpu, - uint16_t *vmcs_version) +int nested_enable_evmcs(struct kvm_vcpu *vcpu, u32 evmcs_revision, uint16_= t *evmcs_version) { struct vcpu_vmx *vmx =3D to_vmx(vcpu); =20 - vmx->nested.enlightened_vmcs_enabled =3D true; + if (evmcs_revision > KVM_EVMCS_REVISION && evmcs_revision !=3D U32_MAX) + return -EINVAL; =20 - if (vmcs_version) - *vmcs_version =3D nested_get_evmcs_version(vcpu); + /* Disabling or changing active eVMCS version is not supported */ + if (vmx->nested.active_evmcs_revision) + return -EINVAL; + + if (evmcs_revision !=3D U32_MAX) + vmx->nested.active_evmcs_revision =3D evmcs_revision; + else + vmx->nested.active_evmcs_revision =3D KVM_EVMCS_REVISION; + + *evmcs_version =3D nested_get_evmcs_version(vcpu); =20 return 0; } diff --git a/arch/x86/kvm/vmx/evmcs.h b/arch/x86/kvm/vmx/evmcs.h index f886a8ff0342..022a51ae81e4 100644 --- a/arch/x86/kvm/vmx/evmcs.h +++ b/arch/x86/kvm/vmx/evmcs.h @@ -18,8 +18,18 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs); =20 #define current_evmcs ((struct hv_enlightened_vmcs *)this_cpu_read(current= _vmcs)) =20 +/* + * Maximum supported eVMCS version as described in TLFS, gets reported to = the + * guest. + */ #define KVM_EVMCS_VERSION 1 =20 +/* + * Internal KVM eVMCS revision number, gets bumped when eVMCS needs to be + * updated but its version remain intact. + */ +#define KVM_EVMCS_REVISION 1 + /* * Enlightened VMCSv1 doesn't support these: * @@ -241,8 +251,7 @@ enum nested_evmptrld_status { =20 bool nested_enlightened_vmentry(struct kvm_vcpu *vcpu, u64 *evmcs_gpa); uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu); -int nested_enable_evmcs(struct kvm_vcpu *vcpu, - uint16_t *vmcs_version); +int nested_enable_evmcs(struct kvm_vcpu *vcpu, u32 evmcs_revision, uint16_= t *vmcs_version); void nested_evmcs_filter_control_msr(u32 msr_index, u64 *pdata); int nested_evmcs_check_controls(struct vmcs12 *vmcs12); =20 diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index 162f4b4502e1..be019c3c5eab 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -2008,7 +2008,7 @@ static enum nested_evmptrld_status nested_vmx_handle_= enlightened_vmptrld( bool evmcs_gpa_changed =3D false; u64 evmcs_gpa; =20 - if (likely(!vmx->nested.enlightened_vmcs_enabled)) + if (likely(!vmx->nested.active_evmcs_revision)) return EVMPTRLD_DISABLED; =20 if (!nested_enlightened_vmentry(vcpu, &evmcs_gpa)) { @@ -2889,7 +2889,7 @@ static int nested_vmx_check_controls(struct kvm_vcpu = *vcpu, nested_check_vm_entry_controls(vcpu, vmcs12)) return -EINVAL; =20 - if (to_vmx(vcpu)->nested.enlightened_vmcs_enabled) + if (to_vmx(vcpu)->nested.active_evmcs_revision) return nested_evmcs_check_controls(vmcs12); =20 return 0; @@ -3171,7 +3171,7 @@ static bool nested_get_evmcs_page(struct kvm_vcpu *vc= pu) * L2 was running), map it here to make sure vmcs12 changes are * properly reflected. */ - if (vmx->nested.enlightened_vmcs_enabled && + if (vmx->nested.active_evmcs_revision && vmx->nested.hv_evmcs_vmptr =3D=3D EVMPTR_MAP_PENDING) { enum nested_evmptrld_status evmptrld_status =3D nested_vmx_handle_enlightened_vmptrld(vcpu, false); @@ -5125,7 +5125,7 @@ static int handle_vmclear(struct kvm_vcpu *vcpu) * state. It is possible that the area will stay mapped as * vmx->nested.hv_evmcs but this shouldn't be a problem. */ - if (likely(!vmx->nested.enlightened_vmcs_enabled || + if (likely(!vmx->nested.active_evmcs_revision || !nested_enlightened_vmentry(vcpu, &evmcs_gpa))) { if (vmptr =3D=3D vmx->nested.current_vmptr) nested_release_vmcs12(vcpu); @@ -6414,7 +6414,7 @@ static int vmx_set_nested_state(struct kvm_vcpu *vcpu, return -EINVAL; =20 if ((kvm_state->flags & KVM_STATE_NESTED_EVMCS) && - (!nested_vmx_allowed(vcpu) || !vmx->nested.enlightened_vmcs_enabled)) + (!nested_vmx_allowed(vcpu) || !vmx->nested.active_evmcs_revision)) return -EINVAL; =20 vmx_leave_nested(vcpu); diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index 5e14e4c40007..e892956850ee 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1857,7 +1857,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct = msr_data *msr_info) * features out. */ if (!msr_info->host_initiated && - vmx->nested.enlightened_vmcs_enabled) + vmx->nested.active_evmcs_revision) nested_evmcs_filter_control_msr(msr_info->index, &msr_info->data); break; diff --git a/arch/x86/kvm/vmx/vmx.h b/arch/x86/kvm/vmx/vmx.h index 71bcb486e73f..f9948a2a6432 100644 --- a/arch/x86/kvm/vmx/vmx.h +++ b/arch/x86/kvm/vmx/vmx.h @@ -185,13 +185,6 @@ struct nested_vmx { bool update_vmcs01_cpu_dirty_logging; bool update_vmcs01_apicv_status; =20 - /* - * Enlightened VMCS has been enabled. It does not mean that L1 has to - * use it. However, VMX features available to L1 will be limited based - * on what the enlightened VMCS supports. - */ - bool enlightened_vmcs_enabled; - /* L2 must run next, and mustn't decide to exit to L1. */ bool nested_run_pending; =20 @@ -239,6 +232,14 @@ struct nested_vmx { bool guest_mode; } smm; =20 + /* + * Enlightened VMCS revision enabled (1..KVM_EVMCS_REVISION) on the vCPU. + * When, enabled, L1 doesn't necessarily have to use eVMCS interface, + * however, the exposed VMX features will be limited to what the particul= ar + * revision of eVMCS supports. + */ + u32 active_evmcs_revision; + gpa_t hv_evmcs_vmptr; struct kvm_host_map hv_evmcs_map; struct hv_enlightened_vmcs *hv_evmcs; diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2318a99139fa..b5b7d43a39e7 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4376,6 +4376,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, lon= g ext) r =3D kvm_x86_ops.enable_direct_tlbflush !=3D NULL; break; case KVM_CAP_HYPERV_ENLIGHTENED_VMCS: + case KVM_CAP_HYPERV_ENLIGHTENED_VMCS2: r =3D kvm_x86_ops.nested_ops->enable_evmcs !=3D NULL; break; case KVM_CAP_SMALLER_MAXPHYADDR: @@ -5307,7 +5308,8 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu = *vcpu, case KVM_CAP_HYPERV_ENLIGHTENED_VMCS: if (!kvm_x86_ops.nested_ops->enable_evmcs) return -ENOTTY; - r =3D kvm_x86_ops.nested_ops->enable_evmcs(vcpu, &vmcs_version); + /* Legacy: enable rev.1 */ + r =3D kvm_x86_ops.nested_ops->enable_evmcs(vcpu, 1, &vmcs_version); if (!r) { user_ptr =3D (void __user *)(uintptr_t)cap->args[0]; if (copy_to_user(user_ptr, &vmcs_version, @@ -5315,6 +5317,17 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu= *vcpu, r =3D -EFAULT; } return r; + case KVM_CAP_HYPERV_ENLIGHTENED_VMCS2: + if (!kvm_x86_ops.nested_ops->enable_evmcs) + return -ENOTTY; + r =3D kvm_x86_ops.nested_ops->enable_evmcs(vcpu, cap->args[0], &vmcs_ver= sion); + if (!r && cap->args[1]) { + user_ptr =3D (void __user *)(uintptr_t)cap->args[1]; + if (copy_to_user(user_ptr, &vmcs_version, + sizeof(vmcs_version))) + r =3D -EFAULT; + } + return r; case KVM_CAP_HYPERV_DIRECT_TLBFLUSH: if (!kvm_x86_ops.enable_direct_tlbflush) return -ENOTTY; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 7569b4ec199c..d3267b7be9b0 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1109,7 +1109,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_PPC_NESTED_HV 160 #define KVM_CAP_HYPERV_SEND_IPI 161 #define KVM_CAP_COALESCED_PIO 162 -#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163 +#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163 /* Obsolete */ #define KVM_CAP_EXCEPTION_PAYLOAD 164 #define KVM_CAP_ARM_VM_IPA_SIZE 165 #define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166 /* Obsolete */ @@ -1166,6 +1166,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_S390_PROTECTED_DUMP 217 #define KVM_CAP_X86_TRIPLE_FAULT_EVENT 218 #define KVM_CAP_X86_NOTIFY_VMEXIT 219 +#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 220 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 6F9D8C43334 for ; Tue, 21 Jun 2022 16:00:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353294AbiFUQAD (ORCPT ); Tue, 21 Jun 2022 12:00:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353561AbiFUP6z (ORCPT ); Tue, 21 Jun 2022 11:58:55 -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 0AA20B96 for ; Tue, 21 Jun 2022 08:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827133; 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=EmEzVaoMAZSsUe/5lbRI/mv6YdcXtXL+W5zafkz/96I=; b=Coj4odrLJkK7sHiVHAW8GQ3sN/e19XpsSL/4WWFUVZC4P4WhP89JPrbOcmZHwHVPBj4DcD mzPRgMAGk7nlxDdDttkOz26F/2qjJbfF/+7VFQHapDaQK7X2lHCrFFVQk3dA3pxeysVXwv pKA976Yz23JSpqYF0c9BSzWxehd0Qm4= 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-344-mg2ovC4pPmuAadO-8QTN3g-1; Tue, 21 Jun 2022 11:58:51 -0400 X-MC-Unique: mg2ovC4pPmuAadO-8QTN3g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5AE933815D28; Tue, 21 Jun 2022 15:58:51 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 199812026D64; Tue, 21 Jun 2022 15:58:48 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/11] KVM: selftests: Switch to KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 Date: Tue, 21 Jun 2022 17:58:26 +0200 Message-Id: <20220621155830.60115-8-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" KVM_CAP_HYPERV_ENLIGHTENED_VMCS was obsoleted by KVM_CAP_HYPERV_ENLIGHTENED_VMCS2, use it in selftests. Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/include/kvm_util_base.h | 8 ++++++++ tools/testing/selftests/kvm/include/x86_64/evmcs.h | 1 + tools/testing/selftests/kvm/lib/x86_64/vmx.c | 5 +++-- tools/testing/selftests/kvm/x86_64/evmcs_test.c | 2 +- tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c | 2 +- .../selftests/kvm/x86_64/vmx_set_nested_state_test.c | 2 +- 6 files changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/te= sting/selftests/kvm/include/kvm_util_base.h index cdaea2383543..3b5d25d6baae 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -348,6 +348,14 @@ static inline void vcpu_enable_cap(struct kvm_vcpu *vc= pu, uint32_t cap, vcpu_ioctl(vcpu, KVM_ENABLE_CAP, &enable_cap); } =20 +static inline void vcpu_enable_cap2(struct kvm_vcpu *vcpu, uint32_t cap, + uint64_t arg0, uint64_t arg1) +{ + struct kvm_enable_cap enable_cap =3D { .cap =3D cap, .args =3D { arg0, ar= g1 } }; + + vcpu_ioctl(vcpu, KVM_ENABLE_CAP, &enable_cap); +} + static inline void vcpu_guest_debug_set(struct kvm_vcpu *vcpu, struct kvm_guest_debug *debug) { diff --git a/tools/testing/selftests/kvm/include/x86_64/evmcs.h b/tools/tes= ting/selftests/kvm/include/x86_64/evmcs.h index 3c9260f8e116..b6d6c73f68dc 100644 --- a/tools/testing/selftests/kvm/include/x86_64/evmcs.h +++ b/tools/testing/selftests/kvm/include/x86_64/evmcs.h @@ -17,6 +17,7 @@ #define u64 uint64_t =20 #define EVMCS_VERSION 1 +#define EVMCS_REVISION 1 =20 extern bool enable_evmcs; =20 diff --git a/tools/testing/selftests/kvm/lib/x86_64/vmx.c b/tools/testing/s= elftests/kvm/lib/x86_64/vmx.c index 381432741df4..1a0b9334f8d4 100644 --- a/tools/testing/selftests/kvm/lib/x86_64/vmx.c +++ b/tools/testing/selftests/kvm/lib/x86_64/vmx.c @@ -42,12 +42,13 @@ struct eptPageTablePointer { uint64_t address:40; uint64_t reserved_63_52:12; }; + int vcpu_enable_evmcs(struct kvm_vcpu *vcpu) { uint16_t evmcs_ver; =20 - vcpu_enable_cap(vcpu, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, - (unsigned long)&evmcs_ver); + vcpu_enable_cap2(vcpu, KVM_CAP_HYPERV_ENLIGHTENED_VMCS2, + EVMCS_REVISION, (unsigned long)&evmcs_ver); =20 /* KVM should return supported EVMCS version range */ TEST_ASSERT(((evmcs_ver >> 8) >=3D (evmcs_ver & 0xff)) && diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testin= g/selftests/kvm/x86_64/evmcs_test.c index 8dda527cc080..a546d1cad146 100644 --- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c +++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c @@ -210,7 +210,7 @@ int main(int argc, char *argv[]) =20 TEST_REQUIRE(nested_vmx_supported()); TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE)); - TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)); + TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS2)); =20 vcpu_set_hv_cpuid(vcpu); vcpu_enable_evmcs(vcpu); diff --git a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c b/tools/test= ing/selftests/kvm/x86_64/hyperv_cpuid.c index cbd4a7d36189..f19859f1956e 100644 --- a/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c +++ b/tools/testing/selftests/kvm/x86_64/hyperv_cpuid.c @@ -149,7 +149,7 @@ int main(int argc, char *argv[]) free(hv_cpuid_entries); =20 if (!nested_vmx_supported() || - !kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) { + !kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS2)) { print_skip("Enlightened VMCS is unsupported"); goto do_sys; } diff --git a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c= b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c index b564b86dfc1d..b624a08a5574 100644 --- a/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c +++ b/tools/testing/selftests/kvm/x86_64/vmx_set_nested_state_test.c @@ -265,7 +265,7 @@ int main(int argc, char *argv[]) struct kvm_nested_state state; struct kvm_vcpu *vcpu; =20 - have_evmcs =3D kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS); + have_evmcs =3D kvm_check_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS2); =20 TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE)); =20 --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 4A416C433EF for ; Tue, 21 Jun 2022 16:00:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353552AbiFUQAJ (ORCPT ); Tue, 21 Jun 2022 12:00:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353619AbiFUP67 (ORCPT ); Tue, 21 Jun 2022 11:58:59 -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 EAE37764F for ; Tue, 21 Jun 2022 08:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827137; 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=z5COxjc7RU/sinI/h5wZgYmnBQRLq7MbxUrxyrEVl98=; b=Gpi2umSGTaiSso0Bejw3SarRTD2Ldayyf565wgTdr0QgsGLOrKpWtDoEC2zVeHshrhKOWJ sW4QXqftOcAY4vdp93BtiSDjZqXqm/4/puc7dn3ly8zKnatsc3B4vbyR90YeycYTwH95t6 WY9XXDJsMRSFj56XNxNageDW+F/dg9s= 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-513-G_U6KJUhNWmi3Xvk9iOI_g-1; Tue, 21 Jun 2022 11:58:54 -0400 X-MC-Unique: G_U6KJUhNWmi3Xvk9iOI_g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CBB862999B38; Tue, 21 Jun 2022 15:58:53 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 998912026D64; Tue, 21 Jun 2022 15:58:51 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/11] KVM: VMX: Support TSC scaling with enlightened VMCS Date: Tue, 21 Jun 2022 17:58:27 +0200 Message-Id: <20220621155830.60115-9-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Enlightened VMCS v1 now includes the required field for TSC scaling feature so SECONDARY_EXEC_TSC_SCALING doesn't need to be filtered out, both for KVM on Hyper-V and Hyper-V on KVM cases. Note: Hyper-V on KVM case requires bumping KVM_EVMCS_REVISION revision so VMMs can specify if SECONDARY_EXEC_TSC_SCALING needs to be filtered out or not, this is required to support live migration. While on it, update the comment why VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL/ VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL are kept filtered out and add missing spaces in trace_kvm_nested_vmenter_failed() strings making the output ugly. Signed-off-by: Vitaly Kuznetsov --- arch/x86/kvm/vmx/evmcs.c | 70 +++++++++++++++++++++++++++++---------- arch/x86/kvm/vmx/evmcs.h | 17 ++++------ arch/x86/kvm/vmx/nested.c | 2 +- arch/x86/kvm/vmx/vmx.c | 2 +- 4 files changed, 62 insertions(+), 29 deletions(-) diff --git a/arch/x86/kvm/vmx/evmcs.c b/arch/x86/kvm/vmx/evmcs.c index 21d9f0ed4bd2..4fe65b6a9a92 100644 --- a/arch/x86/kvm/vmx/evmcs.c +++ b/arch/x86/kvm/vmx/evmcs.c @@ -368,7 +368,42 @@ uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcp= u) return 0; } =20 -void nested_evmcs_filter_control_msr(u32 msr_index, u64 *pdata) +enum evmcs_unsupported_ctrl_type { + EVMCS_EXIT_CTLS, + EVMCS_ENTRY_CTLS, + EVMCS_2NDEXEC, + EVMCS_PINCTRL, + EVMCS_VMFUNC, +}; + +static u32 evmcs_get_unsupported_ctls(struct kvm_vcpu *vcpu, + enum evmcs_unsupported_ctrl_type ctrl_type) +{ + u32 evmcs_rev =3D to_vmx(vcpu)->nested.active_evmcs_revision; + + if (!evmcs_rev) + return 0; + + switch (ctrl_type) { + case EVMCS_EXIT_CTLS: + return EVMCS1_UNSUPPORTED_VMEXIT_CTRL; + case EVMCS_ENTRY_CTLS: + return EVMCS1_UNSUPPORTED_VMENTRY_CTRL; + case EVMCS_2NDEXEC: + if (evmcs_rev =3D=3D 1) + return EVMCS1_UNSUPPORTED_2NDEXEC | SECONDARY_EXEC_TSC_SCALING; + else + return EVMCS1_UNSUPPORTED_2NDEXEC; + case EVMCS_PINCTRL: + return EVMCS1_UNSUPPORTED_PINCTRL; + case EVMCS_VMFUNC: + return EVMCS1_UNSUPPORTED_VMFUNC; + } + + return 0; +} + +void nested_evmcs_filter_control_msr(struct kvm_vcpu *vcpu, u32 msr_index,= u64 *pdata) { u32 ctl_low =3D (u32)*pdata; u32 ctl_high =3D (u32)(*pdata >> 32); @@ -380,72 +415,73 @@ void nested_evmcs_filter_control_msr(u32 msr_index, u= 64 *pdata) switch (msr_index) { case MSR_IA32_VMX_EXIT_CTLS: case MSR_IA32_VMX_TRUE_EXIT_CTLS: - ctl_high &=3D ~EVMCS1_UNSUPPORTED_VMEXIT_CTRL; + ctl_high &=3D ~evmcs_get_unsupported_ctls(vcpu, EVMCS_EXIT_CTLS); break; case MSR_IA32_VMX_ENTRY_CTLS: case MSR_IA32_VMX_TRUE_ENTRY_CTLS: - ctl_high &=3D ~EVMCS1_UNSUPPORTED_VMENTRY_CTRL; + ctl_high &=3D ~evmcs_get_unsupported_ctls(vcpu, EVMCS_ENTRY_CTLS); break; case MSR_IA32_VMX_PROCBASED_CTLS2: - ctl_high &=3D ~EVMCS1_UNSUPPORTED_2NDEXEC; + ctl_high &=3D ~evmcs_get_unsupported_ctls(vcpu, EVMCS_2NDEXEC); break; case MSR_IA32_VMX_TRUE_PINBASED_CTLS: case MSR_IA32_VMX_PINBASED_CTLS: - ctl_high &=3D ~EVMCS1_UNSUPPORTED_PINCTRL; + ctl_high &=3D ~evmcs_get_unsupported_ctls(vcpu, EVMCS_PINCTRL); break; case MSR_IA32_VMX_VMFUNC: - ctl_low &=3D ~EVMCS1_UNSUPPORTED_VMFUNC; + ctl_low &=3D ~evmcs_get_unsupported_ctls(vcpu, EVMCS_VMFUNC); break; } =20 *pdata =3D ctl_low | ((u64)ctl_high << 32); } =20 -int nested_evmcs_check_controls(struct vmcs12 *vmcs12) +int nested_evmcs_check_controls(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs= 12) { int ret =3D 0; u32 unsupp_ctl; =20 unsupp_ctl =3D vmcs12->pin_based_vm_exec_control & - EVMCS1_UNSUPPORTED_PINCTRL; + evmcs_get_unsupported_ctls(vcpu, EVMCS_PINCTRL); if (unsupp_ctl) { trace_kvm_nested_vmenter_failed( - "eVMCS: unsupported pin-based VM-execution controls", + "eVMCS: unsupported pin-based VM-execution controls: ", unsupp_ctl); ret =3D -EINVAL; } =20 unsupp_ctl =3D vmcs12->secondary_vm_exec_control & - EVMCS1_UNSUPPORTED_2NDEXEC; + evmcs_get_unsupported_ctls(vcpu, EVMCS_2NDEXEC); if (unsupp_ctl) { trace_kvm_nested_vmenter_failed( - "eVMCS: unsupported secondary VM-execution controls", + "eVMCS: unsupported secondary VM-execution controls: ", unsupp_ctl); ret =3D -EINVAL; } =20 unsupp_ctl =3D vmcs12->vm_exit_controls & - EVMCS1_UNSUPPORTED_VMEXIT_CTRL; + evmcs_get_unsupported_ctls(vcpu, EVMCS_EXIT_CTLS); if (unsupp_ctl) { trace_kvm_nested_vmenter_failed( - "eVMCS: unsupported VM-exit controls", + "eVMCS: unsupported VM-exit controls: ", unsupp_ctl); ret =3D -EINVAL; } =20 unsupp_ctl =3D vmcs12->vm_entry_controls & - EVMCS1_UNSUPPORTED_VMENTRY_CTRL; + evmcs_get_unsupported_ctls(vcpu, EVMCS_ENTRY_CTLS); if (unsupp_ctl) { trace_kvm_nested_vmenter_failed( - "eVMCS: unsupported VM-entry controls", + "eVMCS: unsupported VM-entry controls: ", unsupp_ctl); ret =3D -EINVAL; } =20 - unsupp_ctl =3D vmcs12->vm_function_control & EVMCS1_UNSUPPORTED_VMFUNC; + unsupp_ctl =3D vmcs12->vm_function_control & + evmcs_get_unsupported_ctls(vcpu, EVMCS_VMFUNC); if (unsupp_ctl) { trace_kvm_nested_vmenter_failed( - "eVMCS: unsupported VM-function controls", + "eVMCS: unsupported VM-function controls: ", unsupp_ctl); ret =3D -EINVAL; } diff --git a/arch/x86/kvm/vmx/evmcs.h b/arch/x86/kvm/vmx/evmcs.h index 022a51ae81e4..2992e29b81b7 100644 --- a/arch/x86/kvm/vmx/evmcs.h +++ b/arch/x86/kvm/vmx/evmcs.h @@ -28,7 +28,7 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs); * Internal KVM eVMCS revision number, gets bumped when eVMCS needs to be * updated but its version remain intact. */ -#define KVM_EVMCS_REVISION 1 +#define KVM_EVMCS_REVISION 2 =20 /* * Enlightened VMCSv1 doesn't support these: @@ -47,16 +47,14 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs); * EPTP_LIST_ADDRESS =3D 0x00002024, * VMREAD_BITMAP =3D 0x00002026, * VMWRITE_BITMAP =3D 0x00002028, - * - * TSC_MULTIPLIER =3D 0x00002032, * PLE_GAP =3D 0x00004020, * PLE_WINDOW =3D 0x00004022, * VMX_PREEMPTION_TIMER_VALUE =3D 0x0000482E, - * GUEST_IA32_PERF_GLOBAL_CTRL =3D 0x00002808, - * HOST_IA32_PERF_GLOBAL_CTRL =3D 0x00002c04, * - * Currently unsupported in KVM: - * GUEST_IA32_RTIT_CTL =3D 0x00002814, + * While GUEST_IA32_PERF_GLOBAL_CTRL and HOST_IA32_PERF_GLOBAL_CTRL + * are present in eVMCSv1, Windows 11 still has issues booting when + * VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL/VM_ENTRY_LOAD_IA32_PERF_GLOBAL_CTRL + * are exposed to it, keep them filtered out. */ #define EVMCS1_UNSUPPORTED_PINCTRL (PIN_BASED_POSTED_INTR | \ PIN_BASED_VMX_PREEMPTION_TIMER) @@ -68,7 +66,6 @@ DECLARE_STATIC_KEY_FALSE(enable_evmcs); SECONDARY_EXEC_ENABLE_PML | \ SECONDARY_EXEC_ENABLE_VMFUNC | \ SECONDARY_EXEC_SHADOW_VMCS | \ - SECONDARY_EXEC_TSC_SCALING | \ SECONDARY_EXEC_PAUSE_LOOP_EXITING) #define EVMCS1_UNSUPPORTED_VMEXIT_CTRL \ (VM_EXIT_LOAD_IA32_PERF_GLOBAL_CTRL | \ @@ -252,7 +249,7 @@ enum nested_evmptrld_status { bool nested_enlightened_vmentry(struct kvm_vcpu *vcpu, u64 *evmcs_gpa); uint16_t nested_get_evmcs_version(struct kvm_vcpu *vcpu); int nested_enable_evmcs(struct kvm_vcpu *vcpu, u32 evmcs_revision, uint16_= t *vmcs_version); -void nested_evmcs_filter_control_msr(u32 msr_index, u64 *pdata); -int nested_evmcs_check_controls(struct vmcs12 *vmcs12); +void nested_evmcs_filter_control_msr(struct kvm_vcpu *vcpu, u32 msr_index,= u64 *pdata); +int nested_evmcs_check_controls(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs= 12); =20 #endif /* __KVM_X86_VMX_EVMCS_H */ diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c index be019c3c5eab..ed4923a04e80 100644 --- a/arch/x86/kvm/vmx/nested.c +++ b/arch/x86/kvm/vmx/nested.c @@ -2890,7 +2890,7 @@ static int nested_vmx_check_controls(struct kvm_vcpu = *vcpu, return -EINVAL; =20 if (to_vmx(vcpu)->nested.active_evmcs_revision) - return nested_evmcs_check_controls(vmcs12); + return nested_evmcs_check_controls(vcpu, vmcs12); =20 return 0; } diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c index e892956850ee..eda467367dae 100644 --- a/arch/x86/kvm/vmx/vmx.c +++ b/arch/x86/kvm/vmx/vmx.c @@ -1858,7 +1858,7 @@ static int vmx_get_msr(struct kvm_vcpu *vcpu, struct = msr_data *msr_info) */ if (!msr_info->host_initiated && vmx->nested.active_evmcs_revision) - nested_evmcs_filter_control_msr(msr_info->index, + nested_evmcs_filter_control_msr(vcpu, msr_info->index, &msr_info->data); break; case MSR_IA32_RTIT_CTL: --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 71B0EC43334 for ; Tue, 21 Jun 2022 16:00:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353608AbiFUQAR (ORCPT ); Tue, 21 Jun 2022 12:00:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43696 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353627AbiFUP7B (ORCPT ); Tue, 21 Jun 2022 11:59:01 -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 EF3F5BF0 for ; Tue, 21 Jun 2022 08:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827140; 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=NjkLB4A+R0viOg+bQbca/divUcEXpQYDgr2soMIUIog=; b=BaGsS6aTxhTp/x6XJe8+RKfZLxYmrXv5TdzWPmmpERNkGqRbhwQMFUhesxOMpvPjD7ZHH4 4gDh3TigJyPDchusSBvfoJT7Z52838a025e/nBkcl4i7mbyBH5nCQzYTWWKvlblmev8/uk OZ18AX0CcRnLxI6vNc1yfSA7X0S2JGY= 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-663-a3PUNEvvNnGvPX_q0DnMlA-1; Tue, 21 Jun 2022 11:58:57 -0400 X-MC-Unique: a3PUNEvvNnGvPX_q0DnMlA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 54FD285A581; Tue, 21 Jun 2022 15:58:56 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24A7C2026985; Tue, 21 Jun 2022 15:58:54 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/11] KVM: selftests: Add ENCLS_EXITING_BITMAP{,HIGH} VMCS fields Date: Tue, 21 Jun 2022 17:58:28 +0200 Message-Id: <20220621155830.60115-10-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The updated Enlightened VMCS definition has 'encls_exiting_bitmap' field which needs mapping to VMCS, add the missing encoding. Signed-off-by: Vitaly Kuznetsov --- tools/testing/selftests/kvm/include/x86_64/vmx.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/vmx.h b/tools/testi= ng/selftests/kvm/include/x86_64/vmx.h index cc3604f8f1d3..5292d30fb7f2 100644 --- a/tools/testing/selftests/kvm/include/x86_64/vmx.h +++ b/tools/testing/selftests/kvm/include/x86_64/vmx.h @@ -208,6 +208,8 @@ enum vmcs_field { VMWRITE_BITMAP_HIGH =3D 0x00002029, XSS_EXIT_BITMAP =3D 0x0000202C, XSS_EXIT_BITMAP_HIGH =3D 0x0000202D, + ENCLS_EXITING_BITMAP =3D 0x0000202E, + ENCLS_EXITING_BITMAP_HIGH =3D 0x0000202F, TSC_MULTIPLIER =3D 0x00002032, TSC_MULTIPLIER_HIGH =3D 0x00002033, GUEST_PHYSICAL_ADDRESS =3D 0x00002400, --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 D7D6EC43334 for ; Tue, 21 Jun 2022 16:00:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353619AbiFUQAT (ORCPT ); Tue, 21 Jun 2022 12:00:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353636AbiFUP7C (ORCPT ); Tue, 21 Jun 2022 11:59:02 -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 A81F138B4 for ; Tue, 21 Jun 2022 08:59:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827140; 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=RaB1fq3wTWP/kZS7ooNpBTL5jS+GbfNO15gG3YtTEOw=; b=emiF9SeSAt+VMXue8WNt/4NoCjZnf5uKTII34wt9a+igLSrtagHCzoiLkft5JVkXLrWDp4 u1vXQ1Xn5X+jKkX6cKOOm0C0LphZ2PH3iApdNVBiA4Xyfqu9i5MkQ4i1I/CISOajJ/R1bc QSLfrlDmK8+aEk4FwWtX6spAsJ0lGGc= 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-62-4V274_tFNp-ocWYns6yT3Q-1; Tue, 21 Jun 2022 11:58:59 -0400 X-MC-Unique: 4V274_tFNp-ocWYns6yT3Q-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E7C5689568C; Tue, 21 Jun 2022 15:58:58 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id A68312026D07; Tue, 21 Jun 2022 15:58:56 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/11] KVM: selftests: Switch to updated eVMCSv1 definition Date: Tue, 21 Jun 2022 17:58:29 +0200 Message-Id: <20220621155830.60115-11-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Update Enlightened VMCS definition in selftests from KVM and switch to using EVMCS_REVISION 2 which supports these new fields. Signed-off-by: Vitaly Kuznetsov --- .../selftests/kvm/include/x86_64/evmcs.h | 47 +++++++++++++++++-- 1 file changed, 43 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/kvm/include/x86_64/evmcs.h b/tools/tes= ting/selftests/kvm/include/x86_64/evmcs.h index b6d6c73f68dc..ee95286159d1 100644 --- a/tools/testing/selftests/kvm/include/x86_64/evmcs.h +++ b/tools/testing/selftests/kvm/include/x86_64/evmcs.h @@ -17,7 +17,7 @@ #define u64 uint64_t =20 #define EVMCS_VERSION 1 -#define EVMCS_REVISION 1 +#define EVMCS_REVISION 2 =20 extern bool enable_evmcs; =20 @@ -204,14 +204,25 @@ struct hv_enlightened_vmcs { u32 reserved:30; } hv_enlightenments_control; u32 hv_vp_id; - + u32 padding32_2; u64 hv_vm_id; u64 partition_assist_page; u64 padding64_4[4]; u64 guest_bndcfgs; - u64 padding64_5[7]; + u64 guest_ia32_perf_global_ctrl; + u64 guest_ia32_s_cet; + u64 guest_ssp; + u64 guest_ia32_int_ssp_table_addr; + u64 guest_ia32_lbr_ctl; + u64 padding64_5[2]; u64 xss_exit_bitmap; - u64 padding64_6[7]; + u64 host_ia32_perf_global_ctrl; + u64 encls_exiting_bitmap; + u64 tsc_multiplier; + u64 host_ia32_s_cet; + u64 host_ssp; + u64 host_ia32_int_ssp_table_addr; + u64 padding64_6; }; =20 #define HV_VMX_ENLIGHTENED_CLEAN_FIELD_NONE 0 @@ -657,6 +668,18 @@ static inline int evmcs_vmread(uint64_t encoding, uint= 64_t *value) case VIRTUAL_PROCESSOR_ID: *value =3D current_evmcs->virtual_processor_id; break; + case HOST_IA32_PERF_GLOBAL_CTRL: + *value =3D current_evmcs->host_ia32_perf_global_ctrl; + break; + case GUEST_IA32_PERF_GLOBAL_CTRL: + *value =3D current_evmcs->guest_ia32_perf_global_ctrl; + break; + case ENCLS_EXITING_BITMAP: + *value =3D current_evmcs->encls_exiting_bitmap; + break; + case TSC_MULTIPLIER: + *value =3D current_evmcs->tsc_multiplier; + break; default: return 1; } =20 @@ -1170,6 +1193,22 @@ static inline int evmcs_vmwrite(uint64_t encoding, u= int64_t value) current_evmcs->virtual_processor_id =3D value; current_evmcs->hv_clean_fields &=3D ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONT= ROL_XLAT; break; + case HOST_IA32_PERF_GLOBAL_CTRL: + current_evmcs->host_ia32_perf_global_ctrl =3D value; + current_evmcs->hv_clean_fields &=3D ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_HOST= _GRP1; + break; + case GUEST_IA32_PERF_GLOBAL_CTRL: + current_evmcs->guest_ia32_perf_global_ctrl =3D value; + current_evmcs->hv_clean_fields &=3D ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_GUES= T_GRP1; + break; + case ENCLS_EXITING_BITMAP: + current_evmcs->encls_exiting_bitmap =3D value; + current_evmcs->hv_clean_fields &=3D ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONT= ROL_GRP2; + break; + case TSC_MULTIPLIER: + current_evmcs->tsc_multiplier =3D value; + current_evmcs->hv_clean_fields &=3D ~HV_VMX_ENLIGHTENED_CLEAN_FIELD_CONT= ROL_GRP2; + break; default: return 1; } =20 --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 8F1B6C433EF for ; Tue, 21 Jun 2022 16:00:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353635AbiFUQAX (ORCPT ); Tue, 21 Jun 2022 12:00:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353675AbiFUP7I (ORCPT ); Tue, 21 Jun 2022 11:59:08 -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 2F4E0B96 for ; Tue, 21 Jun 2022 08:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827146; 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=htoeiSOxyUzFpsJTMoKaIIRqirMAGQqe1AGkD2m/3Rw=; b=FopbbOCjA/4+kMAnfk+k/f1gqoxRFTgl+PlcxcttME1I7mYvbdn+Xmz/CGOveymHvReKP2 6bk3d/1KMnG/CDuJ3/dQ2HpQpTbZML0rsyUq5L5WKDRfUqFcl35habX6OTqDkRLgPeDh6M 6a/lSTohvAX9lPoDIIUREDDgw0sko7g= 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-329-LYDBHk3JP26glAd33eoBKQ-1; Tue, 21 Jun 2022 11:59:02 -0400 X-MC-Unique: LYDBHk3JP26glAd33eoBKQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 96141811E9B; Tue, 21 Jun 2022 15:59:01 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4020D2026D64; Tue, 21 Jun 2022 15:58:59 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/11] KVM: selftests: Enable TSC scaling in evmcs selftest Date: Tue, 21 Jun 2022 17:58:30 +0200 Message-Id: <20220621155830.60115-12-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The updated Enlightened VMCS v1 definition enables TSC scaling, test that SECONDARY_EXEC_TSC_SCALING can now be enabled. Signed-off-by: Vitaly Kuznetsov --- .../testing/selftests/kvm/x86_64/evmcs_test.c | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/kvm/x86_64/evmcs_test.c b/tools/testin= g/selftests/kvm/x86_64/evmcs_test.c index a546d1cad146..b25e6f57b41c 100644 --- a/tools/testing/selftests/kvm/x86_64/evmcs_test.c +++ b/tools/testing/selftests/kvm/x86_64/evmcs_test.c @@ -18,6 +18,9 @@ =20 #include "vmx.h" =20 +/* Test flags */ +#define HOST_HAS_TSC_SCALING BIT(0) + static int ud_count; =20 static void guest_ud_handler(struct ex_regs *regs) @@ -64,11 +67,14 @@ void l2_guest_code(void) vmcall(); rdmsr_gs_base(); /* intercepted */ =20 + /* TSC scaling */ + vmcall(); + /* Done, exit to L1 and never come back. */ vmcall(); } =20 -void guest_code(struct vmx_pages *vmx_pages) +void guest_code(struct vmx_pages *vmx_pages, u64 test_flags) { #define L2_GUEST_STACK_SIZE 64 unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; @@ -150,6 +156,18 @@ void guest_code(struct vmx_pages *vmx_pages) GUEST_ASSERT(vmreadz(VM_EXIT_REASON) =3D=3D EXIT_REASON_VMCALL); GUEST_SYNC(11); =20 + if (test_flags & HOST_HAS_TSC_SCALING) { + GUEST_ASSERT((rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2) >> 32) & + SECONDARY_EXEC_TSC_SCALING); + /* Try enabling TSC scaling */ + vmwrite(SECONDARY_VM_EXEC_CONTROL, vmreadz(SECONDARY_VM_EXEC_CONTROL) | + SECONDARY_EXEC_TSC_SCALING); + vmwrite(TSC_MULTIPLIER, 1); + } + GUEST_ASSERT(!vmresume()); + GUEST_ASSERT(vmreadz(VM_EXIT_REASON) =3D=3D EXIT_REASON_VMCALL); + GUEST_SYNC(12); + /* Try enlightened vmptrld with an incorrect GPA */ evmcs_vmptrld(0xdeadbeef, vmx_pages->enlightened_vmcs); GUEST_ASSERT(vmlaunch()); @@ -204,6 +222,7 @@ int main(int argc, char *argv[]) struct kvm_vm *vm; struct kvm_run *run; struct ucall uc; + u64 test_flags =3D 0; int stage; =20 vm =3D vm_create_with_one_vcpu(&vcpu, guest_code); @@ -212,11 +231,19 @@ int main(int argc, char *argv[]) TEST_REQUIRE(kvm_has_cap(KVM_CAP_NESTED_STATE)); TEST_REQUIRE(kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS2)); =20 + if ((kvm_get_feature_msr(MSR_IA32_VMX_PROCBASED_CTLS2) >> 32) & + SECONDARY_EXEC_TSC_SCALING) { + test_flags |=3D HOST_HAS_TSC_SCALING; + pr_info("TSC scaling is supported, adding to test\n"); + } else { + pr_info("TSC scaling is not supported\n"); + } + vcpu_set_hv_cpuid(vcpu); vcpu_enable_evmcs(vcpu); =20 vcpu_alloc_vmx(vm, &vmx_pages_gva); - vcpu_args_set(vcpu, 1, vmx_pages_gva); + vcpu_args_set(vcpu, 2, vmx_pages_gva, test_flags); =20 vm_init_descriptor_tables(vm); vcpu_init_descriptor_tables(vcpu); --=20 2.35.3 From nobody Sun Apr 26 22:57:00 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 8A32BC433EF for ; Tue, 21 Jun 2022 16:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353639AbiFUQA0 (ORCPT ); Tue, 21 Jun 2022 12:00:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353449AbiFUP72 (ORCPT ); Tue, 21 Jun 2022 11:59:28 -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 A432A2C675 for ; Tue, 21 Jun 2022 08:59:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1655827162; 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=UjEldryvLCy/WHpx7p0LM+I4QvjiWXCdE7G7gkYSdrY=; b=TRtTksswJBcsUlSTkNmU/8EEWvRX7R8lqSOP0gjk7QYd3zIjU6VLkcs6K4eF/23eGgqQFk ceXeiy5V+Q0Nxh0Ri/WitZvbnFOcy7659d8+u407H3km2oKXvRbp+8lB22jC8IGkEu0Api dn21c9XG2heMuj8OoMe1ZWA76XEJeto= 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-635-7WDh9h20MUqEuFWu4B56Lw-1; Tue, 21 Jun 2022 11:59:17 -0400 X-MC-Unique: 7WDh9h20MUqEuFWu4B56Lw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 8F38D8956A5; Tue, 21 Jun 2022 15:59:15 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.40.195.134]) by smtp.corp.redhat.com (Postfix) with ESMTP id 715E72026D07; Tue, 21 Jun 2022 15:59:13 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Anirudh Rayabharam , Sean Christopherson , Wanpeng Li , Jim Mattson , Maxim Levitsky , linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH QEMU EXAMPLE] i386: Support Enlightened VMCS revisions Date: Tue, 21 Jun 2022 17:59:12 +0200 Message-Id: <20220621155912.60245-1-vkuznets@redhat.com> In-Reply-To: <20220621155830.60115-1-vkuznets@redhat.com> References: <20220621155830.60115-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Vitaly Kuznetsov --- docs/system/i386/hyperv.rst | 4 ++++ linux-headers/linux/kvm.h | 3 ++- target/i386/cpu.c | 1 + target/i386/cpu.h | 1 + target/i386/kvm/kvm.c | 17 ++++++++++++++--- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/docs/system/i386/hyperv.rst b/docs/system/i386/hyperv.rst index 2505dc4c86e0..967acc6814f6 100644 --- a/docs/system/i386/hyperv.rst +++ b/docs/system/i386/hyperv.rst @@ -278,6 +278,10 @@ Supplementary features feature alters this behavior and only allows the guest to use exposed Hy= per-V enlightenments. =20 +``hv-evmcs-rev=3D{revision}`` + When Enlightened VMCS definitinon changes, KVM increases the supported + 'revision' to make live migration to older hosts possible. Note: + ``hv-passthrough`` mode enables the latest supported revision. =20 Useful links ------------ diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h index 0d05d02ee4fe..425ec0d636df 100644 --- a/linux-headers/linux/kvm.h +++ b/linux-headers/linux/kvm.h @@ -1097,7 +1097,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_PPC_NESTED_HV 160 #define KVM_CAP_HYPERV_SEND_IPI 161 #define KVM_CAP_COALESCED_PIO 162 -#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163 +#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS 163 /* Obsolete */ #define KVM_CAP_EXCEPTION_PAYLOAD 164 #define KVM_CAP_ARM_VM_IPA_SIZE 165 #define KVM_CAP_MANUAL_DIRTY_LOG_PROTECT 166 /* Obsolete */ @@ -1150,6 +1150,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_DISABLE_QUIRKS2 213 /* #define KVM_CAP_VM_TSC_CONTROL 214 */ #define KVM_CAP_SYSTEM_EVENT_DATA 215 +#define KVM_CAP_HYPERV_ENLIGHTENED_VMCS2 220 =20 #ifdef KVM_CAP_IRQ_ROUTING =20 diff --git a/target/i386/cpu.c b/target/i386/cpu.c index 6a57ef13af86..0d8b43f570f8 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -6994,6 +6994,7 @@ static Property x86_cpu_properties[] =3D { HYPERV_FEAT_SYNDBG, 0), DEFINE_PROP_BOOL("hv-passthrough", X86CPU, hyperv_passthrough, false), DEFINE_PROP_BOOL("hv-enforce-cpuid", X86CPU, hyperv_enforce_cpuid, fal= se), + DEFINE_PROP_UINT32("hv-evmcs-rev", X86CPU, hyperv_evmcs_rev, 1), =20 /* WS2008R2 identify by default */ DEFINE_PROP_UINT32("hv-version-id-build", X86CPU, hyperv_ver_id_build, diff --git a/target/i386/cpu.h b/target/i386/cpu.h index 82004b65b944..d7a069703943 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1805,6 +1805,7 @@ struct ArchCPU { uint64_t hyperv_features; bool hyperv_passthrough; OnOffAuto hyperv_no_nonarch_cs; + uint32_t hyperv_evmcs_rev; uint32_t hyperv_vendor_id[3]; uint32_t hyperv_interface_id[4]; uint32_t hyperv_limits[3]; diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index e5331662b63b..490fa4582f8c 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -1635,9 +1635,20 @@ static int hyperv_init_vcpu(X86CPU *cpu) if (hyperv_feat_enabled(cpu, HYPERV_FEAT_EVMCS)) { uint16_t evmcs_version =3D DEFAULT_EVMCS_VERSION; uint16_t supported_evmcs_version; - - ret =3D kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMCS, 0, - (uintptr_t)&supported_evmcs_version); + uint32_t evmcs_revision =3D + cpu->hyperv_passthrough ? UINT32_MAX : cpu->hyperv_evmcs_rev; + + if (kvm_check_extension(cs->kvm_state, + KVM_CAP_HYPERV_ENLIGHTENED_VMCS2)) { + ret =3D kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMC= S2, 0, + evmcs_revision, + (uintptr_t)&supported_evmcs_version); + } else if (cpu->hyperv_evmcs_rev =3D=3D 1) { + ret =3D kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_ENLIGHTENED_VMC= S, 0, + (uintptr_t)&supported_evmcs_version); + } else { + ret =3D -ENOTSUP; + } =20 /* * KVM is required to support EVMCS ver.1. as that's what 'hv-evmc= s' --=20 2.35.3