From nobody Sat Feb 7 18:20:09 2026 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71D452F691F for ; Mon, 10 Nov 2025 23:27:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817226; cv=none; b=ORyQts9oJ26tm41yCnMszprgKYcFqOgOYPv1Ch8Fd5rcNh9g6PUI5OxRrjOhfnvaf82aUBbyNTotkmHQgXuSvBNK3tYBSMwJJDA4CiLbk2cUU6NtNDlg5s4Yxi4aa1dRoK1lEjYRYPGtAzBHZO4kudZBiN1ImWSBltXNtsGPUpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817226; c=relaxed/simple; bh=ogJdXeINqQWlpc3T1UEK6sCoWh8eJk5cHClB8hzYApw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s8w3PVQAj9ar19tfNlymxhbfVoAjNSX5LVt175YtkPhdNedcPT/X3mqZO2N/2axw6QLagrr0cDE2rgAr31h7nfUXv26V+DnYpr8tpX5TlsDz2g8+rKIlxJPkN5b5UjixiSUzmz/u9aX5dzHSGqwJTLDZlEzphv4SSKehhmjwj0c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PUifzqSs; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PUifzqSs" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817222; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UZWKobXDfLkd7eERlrIkQnCB9bLEgjEGKzWLVchtxf0=; b=PUifzqSsCvaC+q98arBe8udyvqY/HJ7NptyD9RL/9QuYJ4VChad7VyBR61qB2+AfGt1RuP C0Z8H1iD+qohsuFjf2Wr76e1xkFvwv3/TdAhnsUyTPP4AxJIpfkqLDTBE6MGCrm2qI6uOD BE2NkUimswhxkXh02YSsGW5W1Ou0boc= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 01/14] scripts: Always return '2' when skipping tests Date: Mon, 10 Nov 2025 23:26:29 +0000 Message-ID: <20251110232642.633672-2-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" runtime.bash always returns 2 (or 77 in one case) when a test is skipped. But two cases are missed and return 0. Fix them. Signed-off-by: Yosry Ahmed --- scripts/runtime.bash | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 6805e97f90c8f..0cbe2695948b8 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -103,13 +103,13 @@ function run() =20 if [ -z "$GEN_SE_HEADER" ] && find_word "pv-host" "$groups"; then print_result "SKIP" $testname "" "no gen-se-header available for p= v-host test" - return + return 2 fi =20 if [ -z "$only_group" ] && find_word nodefault "$groups" && skip_nodefault; then print_result "SKIP" $testname "" "test marked as manual run only" - return; + return 2 fi =20 if [ -n "$arch" ] && [ "$arch" !=3D "$ARCH" ]; then --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2166422FE11 for ; Mon, 10 Nov 2025 23:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817230; cv=none; b=A7Oz1IzExOyI+g36O0WTiTq5yBWma02rvPWidyRZ37Cgj7pVRGjXRIoGLevlZHVM6V8Bjm7kHsyWQH9VtTigTYRqhwMdk3nWmQERQmG6ATmhdJ/SpNJH/pp3UlKqdDZGPch8OEBY00RUC3xT0bcfWnKzLoSSPAoTvS9/YwMkHXs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817230; c=relaxed/simple; bh=WrgPfzyyb/jE9uQS/HLYwnkLtnXNRt0RBtDv5xhqIVI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c3JWBbsC67OF3GeaXv1bxxHy/csvf/DpDO5UHjnYjpxVDomxNiRi/mxNN+3T3nvyNmZ8UwftT3awqdOEB6G91jHLvTbyqWgx9L0NaLzeeIQ4JISFhByM4DFy134k+ZJ3A7JWeQZWMAnsJlRL1WLmlqiMN2AjAwffs4tZBYJ+dxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=wJ1vlVba; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="wJ1vlVba" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817224; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2+2lG7hu9KlvT0KTN68rDvTTKs1ubRL9Fu8DwYe6/Oc=; b=wJ1vlVbazmoSgF+uhn8+wox7Z8BybdpC4UrtnnMmnm6eikuDigHD8GjNe23KDPfEN+AQ1G e0hLVdJHAeqgoJs6R2Z4p9yhFh8Hhjw76FdVREAsH3+VZa7bBRjPnvX7oH1wP37ulemIUL JlfHaS92P0q7iVtNycn8Lj6hct6Hh2Y= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 02/14] x86/vmx: Skip vmx_pf_exception_test_fep early if FEP is not available Date: Mon, 10 Nov 2025 23:26:30 +0000 Message-ID: <20251110232642.633672-3-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" The check to skip the test is currently performed in the guest code. There a few TEST_ASSERTs that happen before the guest is run, which internally call report_passed(). The latter increases the number of passed tests. Hence, when vmx_pf_exception_test_fep is run, report_summary() does not return a "skip" error code because the total number of tests is larger than the number of skipped tests. Skip early if FEP is not available, before any assertions, such that report_summary() finds exactly 1 skipped test and returns the appropriate error code. Signed-off-by: Yosry Ahmed --- x86/vmx_tests.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c index 0b3cfe50c6142..4f214ebdbe1d9 100644 --- a/x86/vmx_tests.c +++ b/x86/vmx_tests.c @@ -10644,7 +10644,10 @@ static void vmx_pf_exception_test(void) =20 static void vmx_pf_exception_forced_emulation_test(void) { - __vmx_pf_exception_test(NULL, NULL, vmx_pf_exception_forced_emulation_tes= t_guest); + if (is_fep_available) + __vmx_pf_exception_test(NULL, NULL, vmx_pf_exception_forced_emulation_te= st_guest); + else + report_skip("Forced emulation prefix (FEP) not available\n"); } =20 static void invalidate_tlb_no_vpid(void *data) --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-172.mta0.migadu.com (out-172.mta0.migadu.com [91.218.175.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25F1A3019B5 for ; Mon, 10 Nov 2025 23:27:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817231; cv=none; b=JjJ0S0epIY6vmsH7E7DADdW9mlLrO0Frpo1LZD2nFSCwgd0K9+xRcOIQXSgnBTIqiTssWVVtFBdWVLqMwXwTbXZvdZ392IxB/SIYwwIntAyRMyN+NBM2mR2qu91Icsr5V9wpLZjPwQzF3s84tgD04fW7c2lS+foVRdKaSdY4xrI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817231; c=relaxed/simple; bh=Mnvx0hvs+X8gRCu7TxR7gtRn1tc4Bkv+4aQoILE9RMc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SOzmuN4+j7TjrIyuFZMMysU6m0FF59qT+2Eo0dgCh6haL7Aj4MeETk2uGYMqLkfxJ1pMH5kkRgqpJ4Oe4Af/pGLRX5ojfRfIhyQPV2ZVQrznCc29bB0PIeiBSd/btmUqrhcBTPpv6btFjj4abTEaK93ja5ykbRpqFI8UNEMl3L0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=qD897F/J; arc=none smtp.client-ip=91.218.175.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="qD897F/J" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817226; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=J+DfU+HZfq/Y/VdBhssZivagiWWiLFSSbh8BkuTuFpM=; b=qD897F/J0lFsuw3FMA6LT56+YEcgSzV/4GMunaliLSQOUbf6NSz3F7FP1N5rhFdiwO3mgj S1lbQzn1USbJ++XvzXRry7G0fv+10S0JvorjiVsdTrQR7q81LIb87Zz5j5SviR8wYmxvx6 30f75FpPtnYDYskAwiUB0ldFGs/RXyQ= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 03/14] x86/svm: Cleanup selective cr0 write intercept test Date: Mon, 10 Nov 2025 23:26:31 +0000 Message-ID: <20251110232642.633672-4-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Rename the test and functions to more general names describing the test more accurately. Use X86_CR0_CD instead of hardcoding the bitmask, and explicitly clear the bit in the prepare() function to make it clearer that it would only be set by the test. Signed-off-by: Yosry Ahmed Reviewed-by: Manali Shukla Tested-by: Manali Shukla --- x86/svm_tests.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 80d5aeb108650..e911659194b3d 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -793,23 +793,19 @@ static bool check_asid_zero(struct svm_test *test) return vmcb->control.exit_code =3D=3D SVM_EXIT_ERR; } =20 -static void sel_cr0_bug_prepare(struct svm_test *test) +static void prepare_sel_cr0_intercept(struct svm_test *test) { + vmcb->save.cr0 &=3D ~X86_CR0_CD; vmcb->control.intercept |=3D (1ULL << INTERCEPT_SELECTIVE_CR0); } =20 -static bool sel_cr0_bug_finished(struct svm_test *test) -{ - return true; -} - -static void sel_cr0_bug_test(struct svm_test *test) +static void test_sel_cr0_write_intercept(struct svm_test *test) { unsigned long cr0; =20 - /* read cr0, clear CD, and write back */ + /* read cr0, set CD, and write back */ cr0 =3D read_cr0(); - cr0 |=3D (1UL << 30); + cr0 |=3D X86_CR0_CD; write_cr0(cr0); =20 /* @@ -821,7 +817,7 @@ static void sel_cr0_bug_test(struct svm_test *test) exit(report_summary()); } =20 -static bool sel_cr0_bug_check(struct svm_test *test) +static bool check_sel_cr0_intercept(struct svm_test *test) { return vmcb->control.exit_code =3D=3D SVM_EXIT_CR0_SEL_WRITE; } @@ -3486,9 +3482,9 @@ struct svm_test svm_tests[] =3D { { "asid_zero", default_supported, prepare_asid_zero, default_prepare_gif_clear, test_asid_zero, default_finished, check_asid_zero }, - { "sel_cr0_bug", default_supported, sel_cr0_bug_prepare, - default_prepare_gif_clear, sel_cr0_bug_test, - sel_cr0_bug_finished, sel_cr0_bug_check }, + { "sel cr0 write intercept", default_supported, + prepare_sel_cr0_intercept, default_prepare_gif_clear, + test_sel_cr0_write_intercept, default_finished, check_sel_cr0_intercept= }, { "tsc_adjust", tsc_adjust_supported, tsc_adjust_prepare, default_prepare_gif_clear, tsc_adjust_test, default_finished, tsc_adjust_check }, --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D4EB9305E1B for ; Mon, 10 Nov 2025 23:27:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817235; cv=none; b=bLB8+19bDoE8Q6cttPXcS8slAYhU+Uz4WLz49CcAxXXVNWBeAfnuVSxllb922oTyI1GWKs5Az7tlm9opKWzfs51jB5EkjEcN6e54CgmFiYQown+vSd7Tm+r5PaAMzkagD183gdze7QvqpUqJIRLgZ0Z6pLx5fA/ssy09d5Wfr/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817235; c=relaxed/simple; bh=W3C5pdfYZHFgFeUhnokR+M97vge8GX96579aJ4+GEf4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B7OoYz7YCxwTciGZCBXqN4nR+HDYLMl6VpnL+VIIGXPJxkC9Zru6Gd9KKZTszOq7CxpnEFl2Wo7ZFlberuYSbgoXVQavvMEkARt2hT7mlP2JZBx+AJZZ+Fa+GFEXG8M78qxG/VfCzl9u1ovzaNRXVlJORr1+gXAEM2PtWSmOTSM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cvuAuyIC; arc=none smtp.client-ip=91.218.175.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cvuAuyIC" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817227; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LI9P4e9el9mzpi8j8pU9wIB0bj2YpZyb/opoDXE9K3I=; b=cvuAuyICT18IiC/H6nEpoq6wYr5k6ivn5bImotxalcbKS02aiQA0JxpOchknWf3M6RQo+a +kIXKTk6SwMb9rGtwgqkeExgVr7PuGD5m7u9ck8zwZzlu/ShGPU7ubabOGW2iljpzJ517Z KUsZuWKQpNuFEd90jxKpJP2aKAdquxM= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 04/14] x86/svm: Move CR0 selective write intercept test near CR3 intercept Date: Mon, 10 Nov 2025 23:26:32 +0000 Message-ID: <20251110232642.633672-5-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" It makes more semantic sense for these tests to be in close proximity. Signed-off-by: Yosry Ahmed Reviewed-by: Manali Shukla --- x86/svm_tests.c | 64 ++++++++++++++++++++++++------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index e911659194b3d..feeb27d61435b 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -112,6 +112,35 @@ static bool finished_rsm_intercept(struct svm_test *te= st) return get_test_stage(test) =3D=3D 2; } =20 +static void prepare_sel_cr0_intercept(struct svm_test *test) +{ + vmcb->save.cr0 &=3D ~X86_CR0_CD; + vmcb->control.intercept |=3D (1ULL << INTERCEPT_SELECTIVE_CR0); +} + +static void test_sel_cr0_write_intercept(struct svm_test *test) +{ + unsigned long cr0; + + /* read cr0, set CD, and write back */ + cr0 =3D read_cr0(); + cr0 |=3D X86_CR0_CD; + write_cr0(cr0); + + /* + * If we are here the test failed, not sure what to do now because we + * are not in guest-mode anymore so we can't trigger an intercept. + * Trigger a tripple-fault for now. + */ + report_fail("sel_cr0 test. Can not recover from this - exiting"); + exit(report_summary()); +} + +static bool check_sel_cr0_intercept(struct svm_test *test) +{ + return vmcb->control.exit_code =3D=3D SVM_EXIT_CR0_SEL_WRITE; +} + static void prepare_cr3_intercept(struct svm_test *test) { default_prepare(test); @@ -793,35 +822,6 @@ static bool check_asid_zero(struct svm_test *test) return vmcb->control.exit_code =3D=3D SVM_EXIT_ERR; } =20 -static void prepare_sel_cr0_intercept(struct svm_test *test) -{ - vmcb->save.cr0 &=3D ~X86_CR0_CD; - vmcb->control.intercept |=3D (1ULL << INTERCEPT_SELECTIVE_CR0); -} - -static void test_sel_cr0_write_intercept(struct svm_test *test) -{ - unsigned long cr0; - - /* read cr0, set CD, and write back */ - cr0 =3D read_cr0(); - cr0 |=3D X86_CR0_CD; - write_cr0(cr0); - - /* - * If we are here the test failed, not sure what to do now because we - * are not in guest-mode anymore so we can't trigger an intercept. - * Trigger a tripple-fault for now. - */ - report_fail("sel_cr0 test. Can not recover from this - exiting"); - exit(report_summary()); -} - -static bool check_sel_cr0_intercept(struct svm_test *test) -{ - return vmcb->control.exit_code =3D=3D SVM_EXIT_CR0_SEL_WRITE; -} - #define TSC_ADJUST_VALUE (1ll << 32) #define TSC_OFFSET_VALUE (~0ull << 48) static bool ok; @@ -3458,6 +3458,9 @@ struct svm_test svm_tests[] =3D { { "rsm", default_supported, prepare_rsm_intercept, default_prepare_gif_clear, test_rsm_intercept, finished_rsm_intercept, check_rsm_intercept }, + { "sel cr0 write intercept", default_supported, + prepare_sel_cr0_intercept, default_prepare_gif_clear, + test_sel_cr0_write_intercept, default_finished, check_sel_cr0_intercept= }, { "cr3 read intercept", default_supported, prepare_cr3_intercept, default_prepare_gif_clear, test_cr3_intercept, default_finished, check_cr3_intercept }, @@ -3482,9 +3485,6 @@ struct svm_test svm_tests[] =3D { { "asid_zero", default_supported, prepare_asid_zero, default_prepare_gif_clear, test_asid_zero, default_finished, check_asid_zero }, - { "sel cr0 write intercept", default_supported, - prepare_sel_cr0_intercept, default_prepare_gif_clear, - test_sel_cr0_write_intercept, default_finished, check_sel_cr0_intercept= }, { "tsc_adjust", tsc_adjust_supported, tsc_adjust_prepare, default_prepare_gif_clear, tsc_adjust_test, default_finished, tsc_adjust_check }, --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-177.mta0.migadu.com (out-177.mta0.migadu.com [91.218.175.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D343307AC6 for ; Mon, 10 Nov 2025 23:27:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817233; cv=none; b=FddwdDeD7y52MedU7pvinuXcWJ/VvYRZmW13xHZVyL5b3CoQXRiFJpTrmixab4zFKN9Ypy2bdSpazBIFy0TKCv25cR0u8bKzXoCB/yiJfky6MIks+o7Vy3jGga7SIke2meIIN8ZNhMNML7dIpRV33GcEI6EZp9tOHZIHL/KkjX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817233; c=relaxed/simple; bh=roYRu1M560hcl695WlAsLYjZC2PQoGNp3VD2CPQ9TNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=f5j9o0QHjZdU7G+GxkC+yOItm+FqnSv55fvqKnQ2s7n85kITv6EauG45hiiDxFV/9yyurPJRyzTw/b09zOnVBRR/sI7EGROn79uTWhq7BvYT+Y3LGKaMRfB77htYDKpKledZXPaw4QZMr+8hhrR6i2xEZ/2Wp/T5L/9IVaeo0yc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=JHxcKIy6; arc=none smtp.client-ip=91.218.175.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="JHxcKIy6" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817229; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oK6NUMeTeGf2gh5AQUB1Dh0KArCUE3th1RWLcmN82Uk=; b=JHxcKIy6Sw4naNIlcI2i/m3gQ2APs8UISFb/TSuKqZf35Ow+w39Ih7x+At35JwPkjXtBSQ fRhgOuqmeG4Y9nrmUtvWE0+E2qPt/ZbwUQeNGcV79Xp/d9K9GCAHGpAc3jlWXnkuBD7GEE tnqn+NHLsfrrugRtADD4b9pR5RCMhic= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 05/14] x86/svm: Add FEP helpers for SVM tests Date: Mon, 10 Nov 2025 23:26:33 +0000 Message-ID: <20251110232642.633672-6-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Add helpers to check if FEP is enabled to use as supported() callbacks in SVM tests for the emulator. Also add a macro that executes an assembly instruction conditionally with FEP, which will make writing SVM tests that run with and without FEP more convenient. Signed-off-by: Yosry Ahmed --- lib/x86/desc.h | 8 ++++++++ x86/svm.c | 5 +++++ x86/svm.h | 1 + 3 files changed, 14 insertions(+) diff --git a/lib/x86/desc.h b/lib/x86/desc.h index 68f38f3d75333..06c8be65221dc 100644 --- a/lib/x86/desc.h +++ b/lib/x86/desc.h @@ -284,6 +284,14 @@ extern unsigned long get_gdt_entry_limit(gdt_entry_t *= entry); #define asm_fep_safe(insn, inputs...) \ __asm_safe_out1(KVM_FEP, insn,, inputs) =20 +#define asm_conditional_fep_safe(fep, insn, inputs...) \ +({ \ + if (fep) \ + asm_fep_safe(insn, inputs); \ + else \ + asm_safe(insn, inputs); \ +}) + #define __asm_safe_out1(fep, insn, output, inputs...) \ ({ \ asm volatile(__ASM_TRY(fep, "1f") \ diff --git a/x86/svm.c b/x86/svm.c index e715e270bc5b7..035367a1e90cf 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -53,6 +53,11 @@ bool default_supported(void) return true; } =20 +bool fep_supported(void) +{ + return is_fep_available; +} + bool vgif_supported(void) { return this_cpu_has(X86_FEATURE_VGIF); diff --git a/x86/svm.h b/x86/svm.h index c1dd84afb25eb..264583a6547ef 100644 --- a/x86/svm.h +++ b/x86/svm.h @@ -417,6 +417,7 @@ u64 *npt_get_pdpe(u64 address); u64 *npt_get_pml4e(void); bool smp_supported(void); bool default_supported(void); +bool fep_supported(void); bool vgif_supported(void); bool lbrv_supported(void); bool tsc_scale_supported(void); --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 80FDD333740 for ; Mon, 10 Nov 2025 23:27:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817236; cv=none; b=u6vnJ2iZddOSO79Tr1h0K+TnTuqp7dPcVlV5Gw0myhyao4TPRwfNFMRlQW5Ye2Z3z591baU8SQrGbScoLL46H0/uN4RGvWUzcgaW1mO65u2MP8DNXlHVvh9eV4QYVCxNheTiuxOTqjPPndtQ/90a5r0BdAQH9gPptIF5oG7DaYE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817236; c=relaxed/simple; bh=qYNpbiWtScHM2zedsmkE9xtTzE1sycYpDCXv2oxicaE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hML2BpsFCast2I+IfXBIjqOAx8gLltoLtbC8u+7vPTkEg/LMnEyOM5tUc12WzOb3mBVp+x/Ryse66eeMwt8DJ6pzRRwWHHHVJEG++qj5pdHa909q9ovWZzoe2HyJSR4luWWvSOk0dKFZDK3EJ4ZbvRedkcKwUWIDOMkvqetE9LM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lPdUVE+M; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lPdUVE+M" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817231; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4STebxdlf1RD+u4wrdJG/8su7c7ySF1xDdKsPn6nKEU=; b=lPdUVE+M8lbOzx3683Ck9oOUnV6omxo/ilDaQhWFbq4Z+V88PynukYc0uWqUU49F+Xr0Uy MhnlRPYTyDm2JdZB0cmrkgIhZbS+joCgj69EzhR+VnpVC4XZieoj3lOmlUI6pTwSmsCK4z yqcwyO9HrlvuhIDl2vk1PmMAJSQbXPo= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 06/14] x86/svm: Report unsupported SVM tests Date: Mon, 10 Nov 2025 23:26:34 +0000 Message-ID: <20251110232642.633672-7-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Print a message when a test is skipped due to being unsupported for better visibility. Signed-off-by: Yosry Ahmed --- x86/svm.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x86/svm.c b/x86/svm.c index 035367a1e90cf..5015339ddb657 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -403,8 +403,10 @@ int run_svm_tests(int ac, char **av, struct svm_test *= svm_tests) for (; svm_tests[i].name !=3D NULL; i++) { if (!test_wanted(svm_tests[i].name, av, ac)) continue; - if (svm_tests[i].supported && !svm_tests[i].supported()) + if (svm_tests[i].supported && !svm_tests[i].supported()) { + report_skip("%s (not supported)", svm_tests[i].name); continue; + } if (svm_tests[i].v2 =3D=3D NULL) { if (svm_tests[i].on_vcpu) { if (cpu_count() <=3D svm_tests[i].on_vcpu) --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 810B733437F for ; Mon, 10 Nov 2025 23:27:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817236; cv=none; b=l1mCot8j46EONlU2JQNDnRy8Sb6fDN6pv58flXbUWR/ggd9bZVtnbxtNAB/pZj4X60J+ycdasuG0EeoW4hMFRhTsdwqeRF0RFRps3ivAVkKyAB/OmWksACKeJehBrEbkVl3+aBPXG/UEr/j+XZ4fAWLg1pC4WHMmlQGyxmRDHBE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817236; c=relaxed/simple; bh=Tf2WOo+nTdA0kHa5juQ5OUWkXPxlWSD/okXr3AMAQic=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mmwFpMOYvB3g2Fp5C7pBiGT2EvRqflHWMGNK0zpXYgsdnSS7DDN0Trp41GUz1+Jp4cnDQyeUZA5t9wsWNJP03E4ecJrdYI1oKSvkbvKBBuMvJclM/rID2wW/3VaT8T+zsu12/i0kOzR7pw+I3Lskmo5BuFoOJyafl3LZP2BntQ4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=EhjnLSZi; arc=none smtp.client-ip=91.218.175.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="EhjnLSZi" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817232; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QN+Jb/sMTKw705goXC8AQxOha75Fi5974iJiM9D+sAM=; b=EhjnLSZi2hbQf2TDrsHHuE9WjfYeOq6pvHrlli78ZzLZedUwedLtc62AsQtHF8jSX5yKc7 /baZJOjHuJIbiRT2n8WyF0nyvLR7L7ZZzySy7WQkO1WqkM/NnpHQm1jYE7xRIjxRp5aHA0 VgqmHjm6h85AIOgtzRjvnEJXaiKMIbA= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 07/14] x86/svm: Move report_svm_guest() to the top of svm_tests.c Date: Mon, 10 Nov 2025 23:26:35 +0000 Message-ID: <20251110232642.633672-8-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Move the macro ahead of other tests that will start using it. Signed-off-by: Yosry Ahmed --- x86/svm_tests.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index feeb27d61435b..61ab63db462dc 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -37,6 +37,21 @@ u64 latclgi_max; u64 latclgi_min; u64 runs; =20 +/* + * Report failures from SVM guest code, and on failure, set the stage to -= 1 and + * do VMMCALL to terminate the test (host side must treat -1 as "finished"= ). + * TODO: fix the tests that don't play nice with a straight report, e.g. t= he + * V_TPR test fails if report() is invoked. + */ +#define report_svm_guest(cond, test, fmt, args...) \ +do { \ + if (!(cond)) { \ + report_fail(fmt, ##args); \ + set_test_stage(test, -1); \ + vmmcall(); \ + } \ +} while (0) + static void null_test(struct svm_test *test) { } @@ -1074,21 +1089,6 @@ static bool lat_svm_insn_check(struct svm_test *test) return true; } =20 -/* - * Report failures from SVM guest code, and on failure, set the stage to -= 1 and - * do VMMCALL to terminate the test (host side must treat -1 as "finished"= ). - * TODO: fix the tests that don't play nice with a straight report, e.g. t= he - * V_TPR test fails if report() is invoked. - */ -#define report_svm_guest(cond, test, fmt, args...) \ -do { \ - if (!(cond)) { \ - report_fail(fmt, ##args); \ - set_test_stage(test, -1); \ - vmmcall(); \ - } \ -} while (0) - bool pending_event_ipi_fired; bool pending_event_guest_run; =20 --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7DD48334C39 for ; Mon, 10 Nov 2025 23:27:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817238; cv=none; b=ZXYU0U5cqYwoXylor7lhvUHuktR1M6p2pYRwDGhjoL/aNKMJ98/CdRzNep98OLbbiEfjhaJmyjZFRO3zdAbfmeaexX+Q1znw5XMPdcexrbyAWVnUVEcdy5wdkn3l0aJzwqejyp7uqygXPqn4d394S3kaSuGxr4/dVa9RSrq8WNc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817238; c=relaxed/simple; bh=rpfDgqidyPWkJvbfQrUH3FWWbV73z2PcFhtllZsBmRU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nIWPl5a5ChS+SgrOGLGPeZXJtZR1fNcgLynsTZXlug1ibHeQXweGECUTNExL0S6V0QiAL9QUnsfTt8o0ANr9hy0h19nrZyJoVB/kMVkp17Ak+kiMK7jIyb/2PdoqWmScuMsJONRCNZhBvqI3L2rwWSb9PmS/B9reig5URf+ZDEU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=J5jS/2vT; arc=none smtp.client-ip=91.218.175.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="J5jS/2vT" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817234; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NvxWO7Z2fxzmqFnB8S5HGEATExYEtFR4E6TDw6nRLGY=; b=J5jS/2vT82L5axIpJdFLpzwfBt4l6S2a3lqbXcGNYf0Kweua6Jw3qLOzmvat+qL3KdDeF7 tTj+P0T9jh8E6ZEd7Cuttf4O1caGv7Ss28oBCAwvcanKeZgOWpx/7Va+c+QY6LikR1ELLE KGLOwHkhBkaDR43Ik0/NnSreZU7jh7I= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 08/14] x86/svm: Print SVM test names before running tests Date: Mon, 10 Nov 2025 23:26:36 +0000 Message-ID: <20251110232642.633672-9-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" When SVM tests are run, the log is a see of PASS/FAIL/SKIPs that are not clearly separated by test. Sometimes it's hard to attribute a failure to a specific test (e.g. if the same helper is reused by multiple tests). Print the test name before running each test. Signed-off-by: Yosry Ahmed --- x86/svm.c | 1 + 1 file changed, 1 insertion(+) diff --git a/x86/svm.c b/x86/svm.c index 5015339ddb657..de9eb19443caa 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -407,6 +407,7 @@ int run_svm_tests(int ac, char **av, struct svm_test *s= vm_tests) report_skip("%s (not supported)", svm_tests[i].name); continue; } + printf("SVM test: %s\n", svm_tests[i].name); if (svm_tests[i].v2 =3D=3D NULL) { if (svm_tests[i].on_vcpu) { if (cpu_count() <=3D svm_tests[i].on_vcpu) --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-174.mta0.migadu.com (out-174.mta0.migadu.com [91.218.175.174]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18B7033F8D3 for ; Mon, 10 Nov 2025 23:27:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817241; cv=none; b=QWdZHMOdlIyfU9/ONr/eQPR65fVjV04o6avqph/u8IBJLPaa8gHeYCSPsBXhAFI+IMzW2blTP2TbLmULPGhxsVO86SU78tkXV5Gw867cFvobvlF/s56s+3T9aBJSE+GMbKwRJs2N1fQIWnrr7BiJ1YoNQd/jZHq1GxNdko2WYvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817241; c=relaxed/simple; bh=R7zwZuvyaSOI5TNY55HsmjnEMbQF0WWfdkvp2+Cwf+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DDP8GNn+LFEIUHMnAuLZvz6YvaK4G5ROwDd6Fo09RgbJvl/7awW6w9wHBH8fCqRGrAle47Aw2qygLYmqIr6LLDzjNHfyWFwbD972io7A1SHA6H7tiBrjYWZThHnyn+sfdze5ik80GamUCDEnmFa+S7LiH3KtVzDQoBVkzBhx8aY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=oCpHJD1S; arc=none smtp.client-ip=91.218.175.174 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="oCpHJD1S" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817236; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1i62BQEu9bU1+io1BGBNbqeSmq/IONYQhgqd3tEle5Y=; b=oCpHJD1StdepXk6QzIESZYYG4zkbkr67kzg1YI1uHG6SP0OQ7rMMyrfGrOfd6nskUGHGek cg0ejxSFJeDkVO/SSJf4/Bo+IqF0CptE9wS1MTl3SfhcaO8064YDeRqCvwBSiY/nC92N3d QlRa5PD/XQ3yPGaN7fdtp2UIvx7rpME= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 09/14] x86/svm: Deflake svm_tsc_scale_test Date: Mon, 10 Nov 2025 23:26:37 +0000 Message-ID: <20251110232642.633672-10-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" On an AMT Turin (EPYC Zen 5), svm_tsc_scale_test flakes on the last test case with 0.0001 TSC scaling ratio, even with the 24-bit shift for stability. On failure, the actual value is 49 instead of the expected 50. Use a higher scaling ratio, 0.001, which makes the test pass consistently. Signed-off-by: Yosry Ahmed --- x86/svm_tests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 61ab63db462dc..1e7556a37adec 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -943,7 +943,7 @@ static void svm_tsc_scale_test(void) } =20 svm_tsc_scale_run_testcase(50, 255, rdrand()); - svm_tsc_scale_run_testcase(50, 0.0001, rdrand()); + svm_tsc_scale_run_testcase(50, 0.001, rdrand()); } =20 static void latency_prepare(struct svm_test *test) --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D65A341648 for ; Mon, 10 Nov 2025 23:27:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817241; cv=none; b=hyjofjTxPGbnK5j21u5CGYl28P+HYG1kzVJnk93h9TvQ8sRKOI9/vBHnHriAIwjytu5rN++qxo/WseuzJ0k3BU/G+6I2eEH5A6WDDZNqfmG8PCHwtlRByDXMBrG+6jWyxJPtqGwqFzb2zQxELf41aq5RRMwzh/RWrmyIogIuVSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817241; c=relaxed/simple; bh=kuLUgZpETFRjmpsSenbVTCVPBEIi0OzIVA9pTK+b1Xk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FFytCxBa/6BhWBIh78XOU6+Sb8sK/SaMCVxhYRfFFsdwFvoNtBh3PFdOF0CFRp+dSvL95+lW88gx4zxORj8eaQri9yIrThq7aq3yZQpXkcGMBftwUXUJHxtlAV6g2xIDF73SgyGIbzhqWHXC7QlusYMZkiLymeX6nCc3vaC2auw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=VTrWYeak; arc=none smtp.client-ip=91.218.175.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="VTrWYeak" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817238; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4JXklTZXG2BQ9ptOoEb+PXLCGrKmuijPP72hNX/U+YI=; b=VTrWYeakq+VPHDdVm62Sd2Wqma0TNFEzuPwDO4ZzWfNmeaFHWJB68JF/ZUNsuZ3c4vfMHI o27aGU1gF2DdgaV7cuA0VqhNI3EncyGO40TwQwwJ4tXxmRP1egxFS4LOtK3WqsLdL9dmwi eEn703H+Yig+ZVZRgLLIdh8YINVXmJQ= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 10/14] x86/svm: Generalize and improve selective CR0 write intercept test Date: Mon, 10 Nov 2025 23:26:38 +0000 Message-ID: <20251110232642.633672-11-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" In preparation for adding more test cases, make the test easier to extend. Create a generic helper that sets an arbitrary bit in CR0, optionally using FEP. The helper also stores the value to be written in test->scratch, making it possible to double check if the write was actually executed or not. Use report_svm_guest() instead of report_fail() + exit(). Make test_sel_cr0_write_intercept() use the generic helper, and add another test case that sets FEP to exercise the interception path in the emulator. Finally, in check_sel_cr0_intercept() also check that the write was not executed by comparing CR0 value in the VMCB12 with the value-to-be-written stored in test->scratch. Signed-off-by: Yosry Ahmed --- x86/svm_tests.c | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 1e7556a37adec..7e292a9a7b4ec 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -133,27 +133,36 @@ static void prepare_sel_cr0_intercept(struct svm_test= *test) vmcb->control.intercept |=3D (1ULL << INTERCEPT_SELECTIVE_CR0); } =20 -static void test_sel_cr0_write_intercept(struct svm_test *test) +static void __test_cr0_write_bit(struct svm_test *test, unsigned long bit, + bool intercept, bool fep) { unsigned long cr0; =20 - /* read cr0, set CD, and write back */ - cr0 =3D read_cr0(); - cr0 |=3D X86_CR0_CD; - write_cr0(cr0); + cr0 =3D read_cr0(); + cr0 |=3D bit; + test->scratch =3D cr0; =20 - /* - * If we are here the test failed, not sure what to do now because we - * are not in guest-mode anymore so we can't trigger an intercept. - * Trigger a tripple-fault for now. - */ - report_fail("sel_cr0 test. Can not recover from this - exiting"); - exit(report_summary()); + asm_conditional_fep_safe(fep, "mov %0,%%cr0", "r"(cr0)); + + /* This code should be unreachable when an intercept is expected */ + report_svm_guest(!intercept, test, "Expected intercept on CR0 write"); +} + +/* MOV-to-CR0 updating CR0.CD is intercepted by the selective intercept */ +static void test_sel_cr0_write_intercept(struct svm_test *test) +{ + __test_cr0_write_bit(test, X86_CR0_CD, true, false); +} + +static void test_sel_cr0_write_intercept_emul(struct svm_test *test) +{ + __test_cr0_write_bit(test, X86_CR0_CD, true, true); } =20 static bool check_sel_cr0_intercept(struct svm_test *test) { - return vmcb->control.exit_code =3D=3D SVM_EXIT_CR0_SEL_WRITE; + return vmcb->control.exit_code =3D=3D SVM_EXIT_CR0_SEL_WRITE && + vmcb->save.cr0 !=3D test->scratch; } =20 static void prepare_cr3_intercept(struct svm_test *test) @@ -3461,6 +3470,9 @@ struct svm_test svm_tests[] =3D { { "sel cr0 write intercept", default_supported, prepare_sel_cr0_intercept, default_prepare_gif_clear, test_sel_cr0_write_intercept, default_finished, check_sel_cr0_intercept= }, + { "sel cr0 write intercept emulate", fep_supported, + prepare_sel_cr0_intercept, default_prepare_gif_clear, + test_sel_cr0_write_intercept_emul, default_finished, check_sel_cr0_inte= rcept}, { "cr3 read intercept", default_supported, prepare_cr3_intercept, default_prepare_gif_clear, test_cr3_intercept, default_finished, check_cr3_intercept }, --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-180.mta0.migadu.com (out-180.mta0.migadu.com [91.218.175.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEBCD341AAE for ; Mon, 10 Nov 2025 23:27:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817243; cv=none; b=ZjqX0OT+vmDD1YSMhYbBcxiKKS+yziz2BIfJ/JdRdyOgOYh/DJ11METRUKYe2NMmARcI7AkS+2dTKw14N1f7I9KzIQyNW5MsIYflUi9SQWdT4379ZAZ4kii17Jq6QF8pHMvk5ihn/BwV1ybHHk/0vfM1gYvKPSvwEdft4N5IeZk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817243; c=relaxed/simple; bh=Rucw9D3TcLRz5AjfTNpMt8tn3W5wafCBNOW5cGRGYkU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=avPgQa3850ILUmYAuFDVdNhPN6pw3CmyJqhk0sTr/6QlefcffCS5g1BJky6HhfOnFkeCKCqR/vGImpDTwbQL3plNZDxaso9OYDvZuzvD6T8TEvIeX+kVASWg54snqRQWfOO8VI9DuEPKeqSmiZ69rcDiqSoGRCOGiMeoHyA6nnw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=fiNLNQ5o; arc=none smtp.client-ip=91.218.175.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="fiNLNQ5o" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817239; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jEeYW2EG2zqYgc+9p7eyqQy/S2qen7/wAZxccpbjeOk=; b=fiNLNQ5oXGbU7C3mxRmd6XjSkt5POjfTDGMRLO72ZPurQRTWrQZE0JHQVGaWebiaCFqOrq UrJShXnNXTpRMzUmiZ2LejUrEjAUMwT0Kv1CCBCvDh65HRyJnCA+NRdB5sXYNMGU0nn6Q1 RR5SO1ZmdU9qITRrUMUwQnEiUcm0hyU= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 11/14] x86/svm: Add more selective CR0 write and LMSW test cases Date: Mon, 10 Nov 2025 23:26:39 +0000 Message-ID: <20251110232642.633672-12-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Add more test cases that cover: - The priority between selective and non-selective CR0 intercepts. - Writes to CR0 that should not intercept (e.g. CR0.MP). - Writes to CR0 using LMSW, which should always intercept (even when updating CR0.MP). Emulator variants of all test cases are added as well. The new tests exercises bugs fixed by: https://lore.kernel.org/kvm/20251024192918.3191141-1-yosry.ahmed@linux.dev/. Signed-off-by: Yosry Ahmed --- x86/svm_tests.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 7e292a9a7b4ec..40e9e7e344ed8 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -129,20 +129,36 @@ static bool finished_rsm_intercept(struct svm_test *t= est) =20 static void prepare_sel_cr0_intercept(struct svm_test *test) { + /* Clear CR0.MP and CR0.CD as the tests will set either of them */ + vmcb->save.cr0 &=3D ~X86_CR0_MP; vmcb->save.cr0 &=3D ~X86_CR0_CD; vmcb->control.intercept |=3D (1ULL << INTERCEPT_SELECTIVE_CR0); } =20 +static void prepare_sel_nonsel_cr0_intercepts(struct svm_test *test) +{ + /* Clear CR0.MP and CR0.CD as the tests will set either of them */ + vmcb->save.cr0 &=3D ~X86_CR0_MP; + vmcb->save.cr0 &=3D ~X86_CR0_CD; + vmcb->control.intercept_cr_write |=3D (1ULL << 0); + vmcb->control.intercept |=3D (1ULL << INTERCEPT_SELECTIVE_CR0); +} + static void __test_cr0_write_bit(struct svm_test *test, unsigned long bit, - bool intercept, bool fep) + bool is_lmsw, bool intercept, bool fep) { + unsigned short msw; unsigned long cr0; =20 cr0 =3D read_cr0(); cr0 |=3D bit; + msw =3D cr0 & 0xfUL; test->scratch =3D cr0; =20 - asm_conditional_fep_safe(fep, "mov %0,%%cr0", "r"(cr0)); + if (is_lmsw) + asm_conditional_fep_safe(fep, "lmsw %0", "r"(msw)); + else + asm_conditional_fep_safe(fep, "mov %0,%%cr0", "r"(cr0)); =20 /* This code should be unreachable when an intercept is expected */ report_svm_guest(!intercept, test, "Expected intercept on CR0 write"); @@ -151,12 +167,34 @@ static void __test_cr0_write_bit(struct svm_test *tes= t, unsigned long bit, /* MOV-to-CR0 updating CR0.CD is intercepted by the selective intercept */ static void test_sel_cr0_write_intercept(struct svm_test *test) { - __test_cr0_write_bit(test, X86_CR0_CD, true, false); + __test_cr0_write_bit(test, X86_CR0_CD, false, true, false); } =20 static void test_sel_cr0_write_intercept_emul(struct svm_test *test) { - __test_cr0_write_bit(test, X86_CR0_CD, true, true); + __test_cr0_write_bit(test, X86_CR0_CD, false, true, true); +} + +/* MOV-to-CR0 updating CR0.MP is NOT intercepted by the selective intercep= t */ +static void test_sel_cr0_write_nointercept(struct svm_test *test) +{ + __test_cr0_write_bit(test, X86_CR0_MP, false, false, false); +} + +static void test_sel_cr0_write_nointercept_emul(struct svm_test *test) +{ + __test_cr0_write_bit(test, X86_CR0_MP, false, false, true); +} + +/* LMSW updating CR0.MP is intercepted by the selective intercept */ +static void test_sel_cr0_lmsw_intercept(struct svm_test *test) +{ + __test_cr0_write_bit(test, X86_CR0_MP, true, false, false); +} + +static void test_sel_cr0_lmsw_intercept_emul(struct svm_test *test) +{ + __test_cr0_write_bit(test, X86_CR0_MP, true, false, true); } =20 static bool check_sel_cr0_intercept(struct svm_test *test) @@ -165,6 +203,18 @@ static bool check_sel_cr0_intercept(struct svm_test *t= est) vmcb->save.cr0 !=3D test->scratch; } =20 +static bool check_nonsel_cr0_intercept(struct svm_test *test) +{ + return vmcb->control.exit_code =3D=3D SVM_EXIT_WRITE_CR0 && + vmcb->save.cr0 !=3D test->scratch; +} + +static bool check_cr0_nointercept(struct svm_test *test) +{ + return vmcb->control.exit_code =3D=3D SVM_EXIT_VMMCALL && + vmcb->save.cr0 =3D=3D test->scratch; +} + static void prepare_cr3_intercept(struct svm_test *test) { default_prepare(test); @@ -3473,6 +3523,24 @@ struct svm_test svm_tests[] =3D { { "sel cr0 write intercept emulate", fep_supported, prepare_sel_cr0_intercept, default_prepare_gif_clear, test_sel_cr0_write_intercept_emul, default_finished, check_sel_cr0_inte= rcept}, + { "sel cr0 write intercept priority", default_supported, + prepare_sel_nonsel_cr0_intercepts, default_prepare_gif_clear, + test_sel_cr0_write_intercept, default_finished, check_nonsel_cr0_interc= ept}, + { "sel cr0 write intercept priority emulate", fep_supported, + prepare_sel_nonsel_cr0_intercepts, default_prepare_gif_clear, + test_sel_cr0_write_intercept_emul, default_finished, check_nonsel_cr0_i= ntercept}, + { "sel cr0 write nointercept", default_supported, + prepare_sel_cr0_intercept, default_prepare_gif_clear, + test_sel_cr0_write_nointercept, default_finished, check_cr0_nointercept= }, + { "sel cr0 write nointercept emulate", fep_supported, + prepare_sel_cr0_intercept, default_prepare_gif_clear, + test_sel_cr0_write_nointercept_emul, default_finished, check_cr0_nointe= rcept}, + { "sel cr0 lmsw intercept", default_supported, + prepare_sel_cr0_intercept, default_prepare_gif_clear, + test_sel_cr0_lmsw_intercept, default_finished, check_sel_cr0_intercept}, + { "sel cr0 lmsw intercept emulate", fep_supported, + prepare_sel_cr0_intercept, default_prepare_gif_clear, + test_sel_cr0_lmsw_intercept_emul, default_finished, check_sel_cr0_inter= cept}, { "cr3 read intercept", default_supported, prepare_cr3_intercept, default_prepare_gif_clear, test_cr3_intercept, default_finished, check_cr3_intercept }, --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B0AF634321D for ; Mon, 10 Nov 2025 23:27:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817247; cv=none; b=GoPNOaS+El6C6zizmtk02sdJNVq+UyHGSuxAZ9R7o+z6FiHZ+2xgIfrTgiN4zqmRSIq3SV95rI+yMfvmieYUq7KXj7QisR8uE6TZl9yET8DZnziC+OZAyGy0mreNhI3mJysnyGQ8v0u1NkuCxsCpSFDOlOvpuY+ubmFHEHOq5sI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817247; c=relaxed/simple; bh=MyCaylPcd6jL0fIRkiI4QdgSLFfZ2xzQS4bB56Mbxgc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cd3ds8Oye7f/EPotHrBq31PMpevze2Ho2qdLhNgx1D1KA8zI4bpqAHafr7zHK7oACjS6K8dPzo+NxX1CPlSXAIZF/FjpeTzySBB60u7QuLK2uVAygWzo46sgb2JMAKpUHbif3Q33PVsF1LXvIFA2y/qqESY9/P7gkkZXYV0zJ2k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PcjpC3Rl; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PcjpC3Rl" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817241; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AJL9VPq8VyFGZh9HkMtyxbYE/+SCo1Ep+KzagzKZdJ8=; b=PcjpC3RlbL4DgCATn6T1Bu68WMVT3+Uk74PwQclGz/QBdPSthJ7VrpGFs5AUwEsYK+4iQj xT42a21N2CgSfq7cqKJty6ps2qwUgSxOk2yDkwAa6iiVxrK++jqZMNWOycLy40bKmLEiQc M+9xfGGc69VPQjWdvl8kYBiT1m1/Bhg= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 12/14] x86/svm: Cleanup LBRV tests Date: Mon, 10 Nov 2025 23:26:40 +0000 Message-ID: <20251110232642.633672-13-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" In LBRV tests, failures in the guest trigger a #UD and do not convey useful debugging info (i.e. expected and actual values of MSRs). Also, a lot of macros are used to perform branch checks, obscuring the tests to an extent. Instead, add a helper to read the branch IPs, and remove the check macros. Consistently use TEST_EXPECT_EQ() in both virtual host and guest code, instead of a mix of report(), TEST_EXPECT_EQ(), and #UD. Opportunisitcally slightly reorder test checks to improve semantics, and replace the report(true, ..) calls that document the test with comments. Signed-off-by: Yosry Ahmed Reviewed-by: Shivansh Dhiman Tested-by: Shivansh Dhiman --- x86/svm_tests.c | 138 +++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 73 deletions(-) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 40e9e7e344ed8..33c92b17c87db 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -3006,34 +3006,17 @@ static void svm_no_nm_test(void) "fnop with CR0.TS and CR0.EM unset no #NM exception"); } =20 -static u64 amd_get_lbr_rip(u32 msr) +/* These functions have to be inlined to avoid affecting LBR registers */ +static __always_inline u64 amd_get_lbr_rip(u32 msr) { return rdmsr(msr) & ~AMD_LBR_RECORD_MISPREDICT; } =20 -#define HOST_CHECK_LBR(from_expected, to_expected) \ -do { \ - TEST_EXPECT_EQ((u64)from_expected, amd_get_lbr_rip(MSR_IA32_LASTBRANCHFRO= MIP)); \ - TEST_EXPECT_EQ((u64)to_expected, amd_get_lbr_rip(MSR_IA32_LASTBRANCHTOIP)= ); \ -} while (0) - -/* - * FIXME: Do something other than generate an exception to communicate fai= lure. - * Debugging without expected vs. actual is an absolute nightmare. - */ -#define GUEST_CHECK_LBR(from_expected, to_expected) \ -do { \ - if ((u64)(from_expected) !=3D amd_get_lbr_rip(MSR_IA32_LASTBRANCHFROMIP))= \ - asm volatile("ud2"); \ - if ((u64)(to_expected) !=3D amd_get_lbr_rip(MSR_IA32_LASTBRANCHTOIP)) \ - asm volatile("ud2"); \ -} while (0) - -#define REPORT_GUEST_LBR_ERROR(vmcb) \ - report(false, "LBR guest test failed. Exit reason 0x%x, RIP =3D %lx, fro= m =3D %lx, to =3D %lx, ex from =3D %lx, ex to =3D %lx", \ - vmcb->control.exit_code, vmcb->save.rip, \ - vmcb->save.br_from, vmcb->save.br_to, \ - vmcb->save.last_excp_from, vmcb->save.last_excp_to) +static __always_inline void get_lbr_ips(u64 *from, u64 *to) +{ + *from =3D amd_get_lbr_rip(MSR_IA32_LASTBRANCHFROMIP); + *to =3D amd_get_lbr_rip(MSR_IA32_LASTBRANCHTOIP); +} =20 #define DO_BRANCH(branch_name) \ asm volatile ( \ @@ -3058,55 +3041,64 @@ u64 dbgctl; =20 static void svm_lbrv_test_guest1(void) { + u64 from_ip, to_ip; + /* * This guest expects the LBR to be already enabled when it starts, * it does a branch, and then disables the LBR and then checks. */ + dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + TEST_EXPECT_EQ(dbgctl, DEBUGCTLMSR_LBR); =20 DO_BRANCH(guest_branch0); =20 - dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + /* Disable LBR before the checks to avoid changing the last branch */ wrmsr(MSR_IA32_DEBUGCTLMSR, 0); + dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + TEST_EXPECT_EQ(dbgctl, 0); =20 - if (dbgctl !=3D DEBUGCTLMSR_LBR) - asm volatile("ud2\n"); - if (rdmsr(MSR_IA32_DEBUGCTLMSR) !=3D 0) - asm volatile("ud2\n"); + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&guest_branch0_from, from_ip); + TEST_EXPECT_EQ((u64)&guest_branch0_to, to_ip); =20 - GUEST_CHECK_LBR(&guest_branch0_from, &guest_branch0_to); asm volatile ("vmmcall\n"); } =20 static void svm_lbrv_test_guest2(void) { + u64 from_ip, to_ip; + /* * This guest expects the LBR to be disabled when it starts, * enables it, does a branch, disables it and then checks. */ - - DO_BRANCH(guest_branch1); dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + TEST_EXPECT_EQ(dbgctl, 0); =20 - if (dbgctl !=3D 0) - asm volatile("ud2\n"); + DO_BRANCH(guest_branch1); =20 - GUEST_CHECK_LBR(&host_branch2_from, &host_branch2_to); + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&host_branch2_from, from_ip); + TEST_EXPECT_EQ((u64)&host_branch2_to, to_ip); =20 wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + TEST_EXPECT_EQ(dbgctl, DEBUGCTLMSR_LBR); + DO_BRANCH(guest_branch2); wrmsr(MSR_IA32_DEBUGCTLMSR, 0); =20 - if (dbgctl !=3D DEBUGCTLMSR_LBR) - asm volatile("ud2\n"); - GUEST_CHECK_LBR(&guest_branch2_from, &guest_branch2_to); + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&guest_branch2_from, from_ip); + TEST_EXPECT_EQ((u64)&guest_branch2_to, to_ip); =20 asm volatile ("vmmcall\n"); } =20 static void svm_lbrv_test0(void) { - report(true, "Basic LBR test"); + u64 from_ip, to_ip; + wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); DO_BRANCH(host_branch0); dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); @@ -3116,12 +3108,15 @@ static void svm_lbrv_test0(void) dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); TEST_EXPECT_EQ(dbgctl, 0); =20 - HOST_CHECK_LBR(&host_branch0_from, &host_branch0_to); + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&host_branch0_from, from_ip); + TEST_EXPECT_EQ((u64)&host_branch0_to, to_ip); } =20 +/* Test that without LBRV enabled, guest LBR state does 'leak' to the host= (1) */ static void svm_lbrv_test1(void) { - report(true, "Test that without LBRV enabled, guest LBR state does 'leak'= to the host(1)"); + u64 from_ip, to_ip; =20 svm_setup_vmrun((u64)svm_lbrv_test_guest1); vmcb->control.virt_ext =3D 0; @@ -3130,19 +3125,19 @@ static void svm_lbrv_test1(void) DO_BRANCH(host_branch1); SVM_BARE_VMRUN; dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + TEST_EXPECT_EQ(dbgctl, 0); =20 - if (vmcb->control.exit_code !=3D SVM_EXIT_VMMCALL) { - REPORT_GUEST_LBR_ERROR(vmcb); - return; - } + TEST_EXPECT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL); =20 - TEST_EXPECT_EQ(dbgctl, 0); - HOST_CHECK_LBR(&guest_branch0_from, &guest_branch0_to); + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&guest_branch0_from, from_ip); + TEST_EXPECT_EQ((u64)&guest_branch0_to, to_ip); } =20 +/* Test that without LBRV enabled, guest LBR state does 'leak' to the host= (2) */ static void svm_lbrv_test2(void) { - report(true, "Test that without LBRV enabled, guest LBR state does 'leak'= to the host(2)"); + u64 from_ip, to_ip; =20 svm_setup_vmrun((u64)svm_lbrv_test_guest2); vmcb->control.virt_ext =3D 0; @@ -3152,25 +3147,25 @@ static void svm_lbrv_test2(void) wrmsr(MSR_IA32_DEBUGCTLMSR, 0); SVM_BARE_VMRUN; dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); - wrmsr(MSR_IA32_DEBUGCTLMSR, 0); + TEST_EXPECT_EQ(dbgctl, 0); =20 - if (vmcb->control.exit_code !=3D SVM_EXIT_VMMCALL) { - REPORT_GUEST_LBR_ERROR(vmcb); - return; - } + TEST_EXPECT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL); =20 - TEST_EXPECT_EQ(dbgctl, 0); - HOST_CHECK_LBR(&guest_branch2_from, &guest_branch2_to); + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&guest_branch2_from, from_ip); + TEST_EXPECT_EQ((u64)&guest_branch2_to, to_ip); } =20 +/* Test that with LBRV enabled, guest LBR state doesn't leak (1) */ static void svm_lbrv_nested_test1(void) { + u64 from_ip, to_ip; + if (!lbrv_supported()) { report_skip("LBRV not supported in the guest"); return; } =20 - report(true, "Test that with LBRV enabled, guest LBR state doesn't leak (= 1)"); svm_setup_vmrun((u64)svm_lbrv_test_guest1); vmcb->control.virt_ext =3D LBR_CTL_ENABLE_MASK; vmcb->save.dbgctl =3D DEBUGCTLMSR_LBR; @@ -3181,28 +3176,26 @@ static void svm_lbrv_nested_test1(void) dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); wrmsr(MSR_IA32_DEBUGCTLMSR, 0); =20 - if (vmcb->control.exit_code !=3D SVM_EXIT_VMMCALL) { - REPORT_GUEST_LBR_ERROR(vmcb); - return; - } - - if (vmcb->save.dbgctl !=3D 0) { - report(false, "unexpected virtual guest MSR_IA32_DEBUGCTLMSR value 0x%lx= ", vmcb->save.dbgctl); - return; - } + TEST_EXPECT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL); =20 TEST_EXPECT_EQ(dbgctl, DEBUGCTLMSR_LBR); - HOST_CHECK_LBR(&host_branch3_from, &host_branch3_to); + TEST_EXPECT_EQ(vmcb->save.dbgctl, 0); + + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&host_branch3_from, from_ip); + TEST_EXPECT_EQ((u64)&host_branch3_to, to_ip); } =20 +/* Test that with LBRV enabled, guest LBR state doesn't leak (2) */ static void svm_lbrv_nested_test2(void) { + u64 from_ip, to_ip; + if (!lbrv_supported()) { report_skip("LBRV not supported in the guest"); return; } =20 - report(true, "Test that with LBRV enabled, guest LBR state doesn't leak (= 2)"); svm_setup_vmrun((u64)svm_lbrv_test_guest2); vmcb->control.virt_ext =3D LBR_CTL_ENABLE_MASK; =20 @@ -3215,14 +3208,13 @@ static void svm_lbrv_nested_test2(void) SVM_BARE_VMRUN; dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); wrmsr(MSR_IA32_DEBUGCTLMSR, 0); + TEST_EXPECT_EQ(dbgctl, DEBUGCTLMSR_LBR); =20 - if (vmcb->control.exit_code !=3D SVM_EXIT_VMMCALL) { - REPORT_GUEST_LBR_ERROR(vmcb); - return; - } + TEST_EXPECT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL); =20 - TEST_EXPECT_EQ(dbgctl, DEBUGCTLMSR_LBR); - HOST_CHECK_LBR(&host_branch4_from, &host_branch4_to); + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&host_branch4_from, from_ip); + TEST_EXPECT_EQ((u64)&host_branch4_to, to_ip); } =20 =20 --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7201B339B58 for ; Mon, 10 Nov 2025 23:27:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817247; cv=none; b=phnLC9ru6EsWDCJbg8qgfxFNrbrh1p6/ggLp5I4w5Y5hfK6nHK4ebYEf8LMLu81PVOyfdtxx/rlSVNB3AgaSHBOoyOy6X9gGlZglgzaPoTTVuhSrocebCXncmICwsUANURn5Angm1WKASaUId+8IhixsPN50SlEKjGrfkrK1SRg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817247; c=relaxed/simple; bh=6cMSkWiFcxCeUdr+GFhK5aJIyWWK4/bAle6E3Rq/rYg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Ii5EoGixM6eaOU7clrseZeoZ6y6mZPV8qXtuWsZur+juYZYewlnro/sceElO4wlR3QF+4VolMhR/6RiPMNUYyGTiObmJpOhdaVJXLfkhwc5i+btfkAJ1XoZlWRGOc4U1RMbCU8COxC+S0yMr/EkxSEmJUWjckZg7eHAA0y6/Pw4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=hsALnKYI; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="hsALnKYI" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817243; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RFlZ027NSXi28xsnB5O4aQTD9p2O2sueEXLrszMepZA=; b=hsALnKYIK6Zg7jwDtnqJ6ONAuEjzQaOwHKV6R4UNEHU5M4VVE6FVKJ1J+9uD4b2CU/WUyT X5UqZWK/2iTzVoQmljw8jcW0plF3JPcNESfFHYq8zC8tr3BSCVlt7I8voxoPT+v01nEiN7 Sdjt/Lsidft8m0pJIB+7hehSOVlF8pU= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 13/14] x86/svm: Add more LBRV test cases Date: Mon, 10 Nov 2025 23:26:41 +0000 Message-ID: <20251110232642.633672-14-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Add tests exercising using LBR, disabling it, then running a guest which enables and uses LBR but does not disable it. Make sure that when LBRV is disabled by virtual host, the guest state correctly leaks into virtual host, but not when LBRV is enabled. This also exercises KVM disabling intercepts for LBRs in L2 but re-enabling them when exiting to L1. Signed-off-by: Yosry Ahmed --- x86/svm_tests.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 33c92b17c87db..47a2edfbb6c9b 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -3031,11 +3031,14 @@ static __always_inline void get_lbr_ips(u64 *from, = u64 *to) =20 extern u64 guest_branch0_from, guest_branch0_to; extern u64 guest_branch2_from, guest_branch2_to; +extern u64 guest_branch3_from, guest_branch3_to; =20 extern u64 host_branch0_from, host_branch0_to; extern u64 host_branch2_from, host_branch2_to; extern u64 host_branch3_from, host_branch3_to; extern u64 host_branch4_from, host_branch4_to; +extern u64 host_branch5_from, host_branch5_to; +extern u64 host_branch6_from, host_branch6_to; =20 u64 dbgctl; =20 @@ -3095,6 +3098,23 @@ static void svm_lbrv_test_guest2(void) asm volatile ("vmmcall\n"); } =20 +static void svm_lbrv_test_guest3(void) +{ + /* + * This guest expects LBR to be disabled, it enables LBR and does a + * branch, then exits to L1 without disabling LBR or doing more + * branches. + */ + dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + TEST_EXPECT_EQ(dbgctl, 0); + + wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); + DO_BRANCH(guest_branch3); + + /* Do not call the vmmcall() fn to avoid overriding the last branch */ + asm volatile ("vmmcall\n\t"); +} + static void svm_lbrv_test0(void) { u64 from_ip, to_ip; @@ -3156,6 +3176,33 @@ static void svm_lbrv_test2(void) TEST_EXPECT_EQ((u64)&guest_branch2_to, to_ip); } =20 +/* + * Test that without LBRV enabled, enabling LBR in the guest then exiting = will + * keep LBR enabled and 'leak' state to the host correctly. + */ +static void svm_lbrv_test3(void) +{ + u64 from_ip, to_ip; + + svm_setup_vmrun((u64)svm_lbrv_test_guest3); + vmcb->control.virt_ext =3D 0; + + wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); + DO_BRANCH(host_branch5); + wrmsr(MSR_IA32_DEBUGCTLMSR, 0); + + SVM_BARE_VMRUN; + dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + wrmsr(MSR_IA32_DEBUGCTLMSR, 0); + TEST_EXPECT_EQ(dbgctl, DEBUGCTLMSR_LBR); + + TEST_EXPECT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL); + + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&guest_branch3_from, from_ip); + TEST_EXPECT_EQ((u64)&guest_branch3_to, to_ip); +} + /* Test that with LBRV enabled, guest LBR state doesn't leak (1) */ static void svm_lbrv_nested_test1(void) { @@ -3217,6 +3264,37 @@ static void svm_lbrv_nested_test2(void) TEST_EXPECT_EQ((u64)&host_branch4_to, to_ip); } =20 +/* + * Test that with LBRV enabled, enabling LBR in the guest then exiting doe= s not + * 'leak' state to the host. + */ +static void svm_lbrv_nested_test3(void) +{ + u64 from_ip, to_ip; + + if (!lbrv_supported()) { + report_skip("LBRV not supported in the guest"); + return; + } + + svm_setup_vmrun((u64)svm_lbrv_test_guest3); + vmcb->control.virt_ext =3D LBR_CTL_ENABLE_MASK; + vmcb->save.dbgctl =3D 0; + + wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); + DO_BRANCH(host_branch6); + wrmsr(MSR_IA32_DEBUGCTLMSR, 0); + + SVM_BARE_VMRUN; + dbgctl =3D rdmsr(MSR_IA32_DEBUGCTLMSR); + TEST_EXPECT_EQ(dbgctl, 0); + + TEST_EXPECT_EQ(vmcb->control.exit_code, SVM_EXIT_VMMCALL); + + get_lbr_ips(&from_ip, &to_ip); + TEST_EXPECT_EQ((u64)&host_branch6_from, from_ip); + TEST_EXPECT_EQ((u64)&host_branch6_to, to_ip); +} =20 // test that a nested guest which does enable INTR interception // but doesn't enable virtual interrupt masking works @@ -3622,8 +3700,10 @@ struct svm_test svm_tests[] =3D { TEST(svm_lbrv_test0), TEST(svm_lbrv_test1), TEST(svm_lbrv_test2), + TEST(svm_lbrv_test3), TEST(svm_lbrv_nested_test1), TEST(svm_lbrv_nested_test2), + TEST(svm_lbrv_nested_test3), TEST(svm_intr_intercept_mix_if), TEST(svm_intr_intercept_mix_gif), TEST(svm_intr_intercept_mix_gif2), --=20 2.51.2.1041.gc1ab5b90ca-goog From nobody Sat Feb 7 18:20:09 2026 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 08D66343D8C for ; Mon, 10 Nov 2025 23:27:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817249; cv=none; b=szWirUQpsUuUzQcRbvvIQjyV05z2lrnRJUFRfVP9OlVfmA1WaIc9ybAZc6DD19Rau8mDYL6pK5C84tc3ZXCBPMCaqbfD4ang8XiRoWKq3OSG3Y9cFL0rp6qGnbOoqBf5mtAvpEsTIqdju/rGfCcOlZwI/BQOHSo1GYfgAcL+uOg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762817249; c=relaxed/simple; bh=1nnldSyEvUMxdV3DKPZB9q5uBddTFGvYWQ+A5Gk4ElM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=lyc3Sky4W5LOD0lNgt4X7lRGA72n6iP7601qGgGF+crsrn5RQ76bOM3kQzhcy+rw0iN3DygWolDOt9l6FNoegOzEnEw5g2myk2vfHSknj9r10EPoD/dI8v8E0I62mK9MuIChX7K6pXeMZRXM3JFIrrUSigytzSJqSQW4+w7xFWw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=BwWIMQVa; arc=none smtp.client-ip=91.218.175.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="BwWIMQVa" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1762817245; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3vRe2/SJRKLIb78m7r5C5J3c6BhgOIpUIxQ+bEHV9RQ=; b=BwWIMQVaAl13BoMv9/NJv+GhfuwUnn53OtluxqiPKy/xZVYaz+kcjuibSOhBmIewv4ha/6 ePzp2J1uFwPxYgauZZB0McSZofHSDHBpOFy3mSs/5Gq+U/qPXEr2yq6oUyOw3s/cufKUxG NNC4GbQlmwkD9yqNTZjTg5HAWC9RTGw= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Kevin Cheng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v3 14/14] x86/svm: Rename VMCB fields to match KVM Date: Mon, 10 Nov 2025 23:26:42 +0000 Message-ID: <20251110232642.633672-15-yosry.ahmed@linux.dev> In-Reply-To: <20251110232642.633672-1-yosry.ahmed@linux.dev> References: <20251110232642.633672-1-yosry.ahmed@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Rename nested_ctl and virt_ext to misc_ctl and misc_ctl2, respectively, to match new names in KVM code. Signed-off-by: Yosry Ahmed --- x86/svm.c | 2 +- x86/svm.h | 6 +++--- x86/svm_tests.c | 12 ++++++------ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/x86/svm.c b/x86/svm.c index de9eb19443caa..c40ef154bcacd 100644 --- a/x86/svm.c +++ b/x86/svm.c @@ -200,7 +200,7 @@ void vmcb_ident(struct vmcb *vmcb) ctrl->msrpm_base_pa =3D virt_to_phys(msr_bitmap); =20 if (npt_supported()) { - ctrl->nested_ctl =3D 1; + ctrl->misc_ctl =3D 1; ctrl->nested_cr3 =3D (u64)pml4e; ctrl->tlb_ctl =3D TLB_CONTROL_FLUSH_ALL_ASID; } diff --git a/x86/svm.h b/x86/svm.h index 264583a6547ef..00d28199f65f5 100644 --- a/x86/svm.h +++ b/x86/svm.h @@ -94,12 +94,12 @@ struct __attribute__ ((__packed__)) vmcb_control_area { u64 exit_info_2; u32 exit_int_info; u32 exit_int_info_err; - u64 nested_ctl; + u64 misc_ctl; u8 reserved_4[16]; u32 event_inj; u32 event_inj_err; u64 nested_cr3; - u64 virt_ext; + u64 misc_ctl2; u32 clean; u32 reserved_5; u64 next_rip; @@ -370,7 +370,7 @@ struct __attribute__ ((__packed__)) vmcb { =20 #define MSR_BITMAP_SIZE 8192 =20 -#define LBR_CTL_ENABLE_MASK BIT_ULL(0) +#define SVM_MISC_CTL2_LBR_CTL_ENABLE BIT_ULL(0) =20 struct svm_test { const char *name; diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 47a2edfbb6c9b..49b5906965b7e 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -3139,7 +3139,7 @@ static void svm_lbrv_test1(void) u64 from_ip, to_ip; =20 svm_setup_vmrun((u64)svm_lbrv_test_guest1); - vmcb->control.virt_ext =3D 0; + vmcb->control.misc_ctl2 =3D 0; =20 wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); DO_BRANCH(host_branch1); @@ -3160,7 +3160,7 @@ static void svm_lbrv_test2(void) u64 from_ip, to_ip; =20 svm_setup_vmrun((u64)svm_lbrv_test_guest2); - vmcb->control.virt_ext =3D 0; + vmcb->control.misc_ctl2 =3D 0; =20 wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); DO_BRANCH(host_branch2); @@ -3185,7 +3185,7 @@ static void svm_lbrv_test3(void) u64 from_ip, to_ip; =20 svm_setup_vmrun((u64)svm_lbrv_test_guest3); - vmcb->control.virt_ext =3D 0; + vmcb->control.misc_ctl2 =3D 0; =20 wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); DO_BRANCH(host_branch5); @@ -3214,7 +3214,7 @@ static void svm_lbrv_nested_test1(void) } =20 svm_setup_vmrun((u64)svm_lbrv_test_guest1); - vmcb->control.virt_ext =3D LBR_CTL_ENABLE_MASK; + vmcb->control.misc_ctl2 =3D SVM_MISC_CTL2_LBR_CTL_ENABLE; vmcb->save.dbgctl =3D DEBUGCTLMSR_LBR; =20 wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); @@ -3244,7 +3244,7 @@ static void svm_lbrv_nested_test2(void) } =20 svm_setup_vmrun((u64)svm_lbrv_test_guest2); - vmcb->control.virt_ext =3D LBR_CTL_ENABLE_MASK; + vmcb->control.misc_ctl2 =3D SVM_MISC_CTL2_LBR_CTL_ENABLE; =20 vmcb->save.dbgctl =3D 0; vmcb->save.br_from =3D (u64)&host_branch2_from; @@ -3278,7 +3278,7 @@ static void svm_lbrv_nested_test3(void) } =20 svm_setup_vmrun((u64)svm_lbrv_test_guest3); - vmcb->control.virt_ext =3D LBR_CTL_ENABLE_MASK; + vmcb->control.misc_ctl2 =3D SVM_MISC_CTL2_LBR_CTL_ENABLE; vmcb->save.dbgctl =3D 0; =20 wrmsr(MSR_IA32_DEBUGCTLMSR, DEBUGCTLMSR_LBR); --=20 2.51.2.1041.gc1ab5b90ca-goog