From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=79.135.106.113 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796341803; b=OCvOQtvam6NSMRlM4t4cb/1AKtOaC9L8sJ4pmLoFbuPYUGnQ+PwkpoR48y2Hz90CwM6m maySyDGD2z0wglPa8DRimk8mtziGhXW8Wutaxv/tbORYVoTG3Tl6vtgyI6Y1SnC4Rdxwt W9NB7Qb4RExjEWjaJwhyxCcIlFUMw4nT96GX12s7seCmjkHN294wvwcdJfmthRN+T3Zg0 KhDkXnoRBb/2JtXmF+BSBSF4BUg/ZOj1fYCOeFVdZXVTE2igcm2iVRtRJ1kpdIgGjCNOT 7yTesZzEziLFqOkQhXYZGUwV5K2cX2ucpgXZcf5nGsuiN1DWzmqytdBNxni06ZlQ6tQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796341803; h=DMARC-Filter:DKIM-Signature:X-Pm-Submission-Id:From:Date:Subject: MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id: References:In-Reply-To:To:Cc:X-Mailer:X-Developer-Signature: X-Developer-Key; bh=a7TJredtR13QZ18XTfH56R1sRdd9XyEvpz5AROD6F30=; b=S02agpbsYbuttKmpMR5yu2PcY2QT+uSqtwD1ALI8K4t7tI+qqbIrFx1sOqv4JyqjgVRT LKklF7nGTYHVLo3XMbFhT4+JSQX7ZjYx6PnGr/eKDbiehAuQDPGA1Kh2481/jSLUMao5p NKiragsE1woVclYZvprVEuQS/lIDijLfj4HtdfPzBLWaG6CruqBKg2bHvlfCFcKaQFcZt eHG77qm6lh1b48bvKWnny8uTtHtnZTeey9lBAntaSczFzoh6VO9zqHwBBEPjV8T4ekk/1 4Tl1t9TEmU3COo2epi0JZQyPaojyQUAwIQJncZsonUUahfZW0pLW9W8Pu2P5ulBPVIw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=reusswig.codes; spf=pass smtp.mailfrom=reusswig.codes; dkim=pass header.d=reusswig.codes header.i=@reusswig.codes header.a=rsa-sha256 header.s=protonmail3 header.b=uJ4kScUR; arc=none smtp.remote-ip=79.135.106.113 Received: from mail-106113.protonmail.ch (mail-106113.protonmail.ch [79.135.106.113]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 32CEB60A262C; Thu, 3 Dec 2026 23:50:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 32CEB60A262C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=reusswig.codes Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=reusswig.codes Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=reusswig.codes header.i=@reusswig.codes header.a=rsa-sha256 header.s=protonmail3 header.b=uJ4kScUR DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=reusswig.codes; s=protonmail3; t=1796341801; x=1796601001; bh=a7TJredtR13QZ18XTfH56R1sRdd9XyEvpz5AROD6F30=; h=From:Date:Subject:Message-Id:References:In-Reply-To:To:Cc:From:To: Cc:Date:Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=uJ4kScURWmbatxhdb8z3mgtQadbdLrinakuSh6GGxnYHzC8RsiSrknXBJ8k/pbLZB VuQ3rUDdzsNJYVYCGXdj5kypJulT3jKiJoH6BugUHM1bhPgL/qKIBsspK472Cm8y/j FkTx+MS4qfOUskVxgAkomTIbXh5bde2C7pQbn4cShPCyhW9tKj9ILX4OssU+jgXexm CQ/C+JiR2Nog1RKALH/BRuZwwQ0Y31rod+urnxoGk/doCpAfvc/TEjEUBEeqIKRPNE ODQZFa4O/uikev3uPf5cM3XOgM3Huxv66jvOpizbzvWBnoUcPiJOUiBupGSXIntlQ/ zgONzmBjiFoBg== X-Pm-Submission-Id: 4jgWZZ2mDBz2ScNb From: =?utf-8?q?Dennis_Reu=C3=9Fwig?= Date: Fri, 04 Dec 2026 00:49:23 +0100 Subject: [PATCH 10/10] KVM: selftests: Check VMX capabilities for CET in L2 with MBEC X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Message-Id: <20261204-nested-sss-v1-10-57de06f58b2b@reusswig.codes> References: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes> In-Reply-To: <20261204-nested-sss-v1-0-57de06f58b2b@reusswig.codes> To: Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Jon Kohler , Jonathan Corbet , Shuah Khan , Randy Dunlap , Shuah Khan Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Chao Gao , Maxim Levitsky , Vitaly Kuznetsov , Panayotis Katsaloulis , =?utf-8?q?Dennis_Reu=C3=9Fwig?= X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=4565; i=dennis@reusswig.codes; h=from:subject:message-id; bh=iCC+K2dyWrqWMcclTYho7/38GZYb9nSyw8SKH3jU5eU=; b=owEBbQKS/ZANAwAIAWBucoRlTGuCAcsmYgBrEgATqOZqn/x1bHBROCzHONaIX/EHjgabMZfiW IkfXGD/EbWJAjMEAAEIAB0WIQS59eJ1vy/tsv/LkIBgbnKEZUxrggUCaxIAEwAKCRBgbnKEZUxr ghDFD/0YOEyCgl0Sx11SMZcJ/MFdkNwHzIY+QXGsKitKQXTcXiAJ5MDHoL9IFCb80SNYaRlXSKt 49QeLJC7+hvSUAl+4zpbpeBQD7Zq2cGSibSCFTgMe2fOQdAfOS8uf96M3ZDOEkp3CF9AQ3Ztlq4 Mh5mfCFitCI2JSXp2p7+tTRnt1Eew24O5UgLfsw6xXQgBQiqPpf84q3J5TNsJVYjMEuCl13Qjr6 SsXPUyqOJikfYDEl+21r1mhm6Nk9x18c6yDVlEScjrR3cOTRYPrNRo3fjGAVOB4bEIXKwHAVGzC LBjmFunhIyhPtGAw8THvJ8om6UYf1065nGQ4F0bL2NNVUnv+zq/LE0NLxraDCLXtUj69shHlHam OFOxWxywrM156Lb9E8mmnjarn2F7bSn5u+K4dpcqL2RPGaH5Iij5kYPcMqILwGq25M/h5KP52qG tcqksfva/MCTIRirFk1u8n/e5FgkJXl6RzPHRXJjdzc9IMjukgWNHbzJ0lGE6PqikJSj8XkpWSP lKFaoNIH7KbPMyy8Cc0cuLxlkIEF1JXRyZ6HV+DpY/jDZ+XkQgJ87BCdX35qGNSlQExWDXyIjQ4 3gvjxXNRRriGJmi8+jS/PKpHxqMr5RfgMIoB13aN3UF/1XeMK06nariucOv2vxuJzEpwoFeCapx 4IEfPB6pLMz8/ZA== X-Developer-Key: i=dennis@reusswig.codes; a=openpgp; fpr=D8E955E3BCD7A0A0DEDE55D1B92D668A3A02E8CA Hyper-V enables CET for its guests when L1 is offered mode-based execute control. It then needs supervisor shadow-stack control for nested EPT and the VM-entry and VM-exit controls that load CET state, with and without the enlightened VMCS. Read the capabilities from L1, once without and once with eVMCS, since KVM filters the control MSRs for eVMCS only for reads by the guest. Without the fixes in this series the test fails: supervisor shadow-stack control is missing, and with eVMCS also the CET controls. Signed-off-by: Dennis Reußwig --- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/x86/vmx_nested_cet_caps_test.c | 90 ++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/tools/testing/selftests/kvm/Makefile.kvm b/tools/testing/selftests/kvm/Makefile.kvm index 2b502c9ec7cb..9e62ed2bec1a 100644 --- a/tools/testing/selftests/kvm/Makefile.kvm +++ b/tools/testing/selftests/kvm/Makefile.kvm @@ -148,6 +148,7 @@ TEST_GEN_PROGS_x86 += x86/vmx_invalid_nested_guest_state TEST_GEN_PROGS_x86 += x86/vmx_nested_la57_state_test TEST_GEN_PROGS_x86 += x86/vmx_nested_mbec_test TEST_GEN_PROGS_x86 += x86/vmx_nested_sss_test +TEST_GEN_PROGS_x86 += x86/vmx_nested_cet_caps_test TEST_GEN_PROGS_x86 += x86/apic_bus_clock_test TEST_GEN_PROGS_x86 += x86/apic_id_routing_test TEST_GEN_PROGS_x86 += x86/xapic_ipi_test diff --git a/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c b/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c new file mode 100644 index 000000000000..cb9135df5d13 --- /dev/null +++ b/tools/testing/selftests/kvm/x86/vmx_nested_cet_caps_test.c @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * VMX capabilities that L1 needs to run L2 guests with CET. + * + * Hyper-V enables CET for its guests when L1 is offered mode-based execute + * control (MBEC). It then needs supervisor shadow-stack control for nested + * EPT (IA32_VMX_EPT_VPID_CAP bit 23) and the VM-entry/VM-exit controls that + * load CET state, with and without the enlightened VMCS. KVM filters the + * control MSRs for eVMCS only when the guest reads them, so L1 reads them + * itself. + */ +#include "test_util.h" +#include "kvm_util.h" +#include "processor.h" +#include "hyperv.h" +#include "vmx.h" + +static void guest_code(void) +{ + u64 ctls2 = rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2); + u64 ept_cap = rdmsr(MSR_IA32_VMX_EPT_VPID_CAP); + u64 exit_ctls = rdmsr(MSR_IA32_VMX_TRUE_EXIT_CTLS); + u64 entry_ctls = rdmsr(MSR_IA32_VMX_TRUE_ENTRY_CTLS); + + /* Without MBEC, Hyper-V does not enable CET and nothing is required. */ + if (!((ctls2 >> 32) & SECONDARY_EXEC_MODE_BASED_EPT_EXEC)) + GUEST_DONE(); + + __GUEST_ASSERT((exit_ctls >> 32) & VM_EXIT_LOAD_CET_STATE, + "MBEC offered but the VM-exit control to load CET state is not, exit controls 0x%lx", + exit_ctls); + __GUEST_ASSERT((entry_ctls >> 32) & VM_ENTRY_LOAD_CET_STATE, + "MBEC offered but the VM-entry control to load CET state is not, entry controls 0x%lx", + entry_ctls); + + /* Supervisor shadow-stack control needs advanced VM-exit information. */ + if (ept_cap & VMX_EPT_VPID_CAP_ADVANCED_VMEXIT_INFO) + __GUEST_ASSERT(ept_cap & VMX_EPT_VPID_CAP_SSS, + "MBEC offered but supervisor shadow-stack control is not, EPT capabilities 0x%lx", + ept_cap); + + GUEST_DONE(); +} + +static void run_test(bool evmcs) +{ + struct kvm_vcpu *vcpu; + struct kvm_vm *vm; + struct ucall uc; + + pr_info("Checking the VMX capabilities L1 sees %s eVMCS\n", evmcs ? "with" : "without"); + + vm = vm_create_with_one_vcpu(&vcpu, guest_code); + if (evmcs) { + vcpu_set_hv_cpuid(vcpu); + vcpu_enable_evmcs(vcpu); + } + + vcpu_run(vcpu); + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); + + switch (get_ucall(vcpu, &uc)) { + case UCALL_ABORT: + REPORT_GUEST_ASSERT(uc); + break; + case UCALL_DONE: + break; + default: + TEST_FAIL("Unexpected ucall %lu", uc.cmd); + } + + kvm_vm_free(vm); +} + +int main(int argc, char *argv[]) +{ + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_VMX)); + TEST_REQUIRE(kvm_cpu_has_ept()); + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SHSTK)); + TEST_REQUIRE(kvm_cpu_has_secondary_exec_control(SECONDARY_EXEC_MODE_BASED_EPT_EXEC)); + + run_test(false); + + if (kvm_has_cap(KVM_CAP_HYPERV_ENLIGHTENED_VMCS)) + run_test(true); + else + pr_info("eVMCS not supported, skipping the eVMCS case\n"); + + return 0; +} -- 2.53.0