From nobody Sat Feb 7 21:24:11 2026 Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 A4BAA2C3242 for ; Fri, 24 Oct 2025 19:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335384; cv=none; b=WN7HKI6WjeRHGNDT/ZfQ2Z3D2bZ1Dme0WDZTOg+zNCa8Tq5DgMHtC/JRevXbrX8f+YS1pQmdKZXjtCrnpUxFII0rJS1/SAdNxOFAHDQaDh1ertEXphOJV1f+5unYa3t4fiV4Gr5aPL/7yIM+kzUPdreak7l84wAuXILcIBWMVAw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335384; c=relaxed/simple; bh=QH29zgZGFcZKWba6DgL9VJdCpR+8hm+YSLE/pZSJuzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JBcdV85w81xfoEaW+fCQuSwyDiBdwrfux//ysX4sbBIGcq5OpClxUKCb7uxli/L9dhU56o28OpACxXGxhpep03TpqIxuaw3VCQQcSYd9L1iRn5b2lB4PBRbUJhJRDEt7Cllyy21zeFyUfx6R5cb6B//IakMkFvFvgzDwPVRz3K8= 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=CBJfugn1; arc=none smtp.client-ip=91.218.175.184 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="CBJfugn1" 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=1761335380; 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=J1kh3wzJ2IyZ2rSYc2w+/9+gZYIO+ejKEv2FW4QM4RE=; b=CBJfugn13F5y49v/bEdH+arwdtiS9mVh8cz7On7jIURPyGIFEpdQpfCrd4+dxDcpMm1Zsy cwUXp17YMlJbsZQDJDV0DramZco25CyAVr32ITWAnlkH1pYU0rNGgpTORIrwL0hYAUJ43z bA4ji4IndPKBxzxlq2x0XCifPWk+zEM= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [kvm-unit-tests 1/7] x86/svm: Cleanup selective cr0 write intercept test Date: Fri, 24 Oct 2025 19:49:19 +0000 Message-ID: <20251024194925.3201933-2-yosry.ahmed@linux.dev> In-Reply-To: <20251024194925.3201933-1-yosry.ahmed@linux.dev> References: <20251024194925.3201933-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" From: Yosry Ahmed 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 --- 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 80d5aeb1..e9116591 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.1.821.gb6fe4d2222-goog From nobody Sat Feb 7 21:24:11 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 C101D2D0275 for ; Fri, 24 Oct 2025 19:49:44 +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=1761335386; cv=none; b=TRc1ywcB9DiLLy+PjTiV8q4pwtpbPIA8k6x/ETZ8NNY6YjN58guLX3+79rFccBxaqe2WGTiKdmnPfuhxXzkzGMvJeglGIXh+QjPaHhQMNEhk6wL09EmUZAWHAqo3/OwnzsIMnsegS2Y2s+iaCQQ9PIxXocV/cl6yJUD1uB9rLmw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335386; c=relaxed/simple; bh=7eVLdnWog4oNMoNDToK8BFBIsLxBRoXrAGcaOu0s5pQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O2UBiz+dl/+m3enTXYWLKjZlWWI9lxA6CMyfz8EX2VW3UG7p0Ydgj6uX9v97uwwS80HSHfup4OGM68uJCGy0bDLOJGTioDVZDpNBbLlFkyArDL2XCIdAP5vfhN6IYpAxUHDjQQ37uT0xqnGOMKL5Fi5xfzKhXpuTa7mNkoHyk/M= 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=EF7LmO6p; 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="EF7LmO6p" 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=1761335382; 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=VCd85GkbXnF6v6GDXBj+7W6E44YyBkTjCVDJUwJsyIc=; b=EF7LmO6pNk/NUI781PWL0iBj0kVnAhPlBNLM+hhv1y01XJRka2Q2yKfJWt2d4UFsenIERq FI1TpFtNn61UVExdqn7QlGk98ZcnaTqznTBpPlBYKTMArqFOcoVlL4qp9dlI5cmVjA4rWW Z0lSyND3vmd0ISw7xs3BF68tPScThp8= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [kvm-unit-tests 2/7] x86/svm: Move CR0 selective write intercept test near CR3 intercept Date: Fri, 24 Oct 2025 19:49:20 +0000 Message-ID: <20251024194925.3201933-3-yosry.ahmed@linux.dev> In-Reply-To: <20251024194925.3201933-1-yosry.ahmed@linux.dev> References: <20251024194925.3201933-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" From: Yosry Ahmed It makes more semantic sense for these tests to be in close proximity. Signed-off-by: Yosry Ahmed --- 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 e9116591..feeb27d6 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.1.821.gb6fe4d2222-goog From nobody Sat Feb 7 21:24:11 2026 Received: from out-183.mta0.migadu.com (out-183.mta0.migadu.com [91.218.175.183]) (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 462992D3212 for ; Fri, 24 Oct 2025 19:49:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.183 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335388; cv=none; b=k1SgQlm0J25/dgi/f4DrBp0tSarqWWiQKJ3dYaHiWTHchfkLu+n60f8S2eHkdQr/9TiYwWUuXCHGjkEIazcrkzz0Qi3jfnWs4QcqxlxuKhQfRzmdONLvemSNb2qSTUVTfiW9o8/7hy1sQye72CEkq1hY0snExYZvAWoB9OqC9kU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335388; c=relaxed/simple; bh=q6WXN/g/vZdHIGuGo25oA9ZyJR19gqZ7QVt+uudtNuM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fUr5C8s/jWz/lXdCrqE0MFuFS/RIgVQsU1jxeVuxAw+R+INen8p9Tp2prbQk6Ls28kq1LrtFe9k/FAJrBi1PF0lUGfkVkZcAooYxQhFQR6KU3BKV4TXl6kpyWqPmRVeTJ6L++fyHEdWzboGv8hdVyx7RO1bioJrMw3lPhvAU0CM= 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=Bf9JyU84; arc=none smtp.client-ip=91.218.175.183 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="Bf9JyU84" 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=1761335384; 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=egwTkK7S1Ygl+Ixphf3Iag59BjjN0yBTItSy9/vEdn4=; b=Bf9JyU84iJEeAA/pjzwGzCMJ5/TUKvfupRuTRRWjmXyVmnN7WeEnRzU5LzKcDN9qWKiRzt NXfCN32/v091GRzc8tljm0HXTvLrfp8+N2rrUg6ueWoyzRoaGs8tTy09LZz6GGuT/HD3WS Si3heYHmMezDb2Vbzj+EkOTPT3urNgg= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [kvm-unit-tests 3/7] x86/svm: Add FEP helpers for SVM tests Date: Fri, 24 Oct 2025 19:49:21 +0000 Message-ID: <20251024194925.3201933-4-yosry.ahmed@linux.dev> In-Reply-To: <20251024194925.3201933-1-yosry.ahmed@linux.dev> References: <20251024194925.3201933-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" From: Yosry Ahmed 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 68f38f3d..06c8be65 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 e715e270..035367a1 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 c1dd84af..264583a6 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.1.821.gb6fe4d2222-goog From nobody Sat Feb 7 21:24:11 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 3C7E12D6626 for ; Fri, 24 Oct 2025 19:49:47 +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=1761335390; cv=none; b=ZC40TVyFLEi4cUNEjg6f6KvlwViuUl7GK5D3DAjiC3BBq5DFaOgKz6SjaFvz12o1w2MNnPp4NTp3IblDuGDAvVlDzWnMieRHNki0efx2fuOfcjH4CGIr9fs0OYCwoHFCkFvxN2bZOz8EHUWuqEjtwKUTDBGUmGowIC5FbfpG/E0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335390; c=relaxed/simple; bh=4ozopBQCOr+4A4xunh8wzuEkxCFaoeLGgcagJMJZYsk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A/+CnHGscDSvKCr/0U0mnhH5fJ0HRNU8uvC2MNKgqDDhaWpKPsRTNqCOX3qHH9Qs4gLj+tzmEKn/cbzD9sVJtsAM/JUPpeBXZ0wOnjCtxZ/7jzNmtr/8VvQcWatZU5jPsux5nlbUaRiXNz6w8NO6qHLq85SQoZ3tbtcSznT7+WQ= 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=sbPXDR6Q; 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="sbPXDR6Q" 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=1761335386; 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=nN1soDEyI2u6t2kSBSe7sxou7WUwrfYHXJmCe3aJNpQ=; b=sbPXDR6QgPwMtZRcjVD2Uhj3B+9PbYBPOTQRklo4Y9qmtk2Mcj1qjSQxTf5aVNsypW2VF0 AmA+DYVHiUeFhJ6JvivnJVf2nvFT/PFNhbMCLeBmZvxTpYX9ndFG0vLCPfE0QSKiHIPX0Y ZIC4fDnpxbJsb+6Wj0mn6dvQIPcElmY= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [kvm-unit-tests 4/7] x86/svm: Report unsupported SVM tests Date: Fri, 24 Oct 2025 19:49:22 +0000 Message-ID: <20251024194925.3201933-5-yosry.ahmed@linux.dev> In-Reply-To: <20251024194925.3201933-1-yosry.ahmed@linux.dev> References: <20251024194925.3201933-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" From: Yosry Ahmed 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 035367a1..5015339d 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.1.821.gb6fe4d2222-goog From nobody Sat Feb 7 21:24:11 2026 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 151222D877C; Fri, 24 Oct 2025 19:49:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335391; cv=none; b=X0UGzJ+BzqgYksDx4F9V3EJz2FWi53IY63hJifmcnufQinnWb/8RHWOAZ0aBuESIrjOi/hgkBGbof+QAvLIcsYlHDqpkb9THtdz1Fa+lEjpmYijRR7BQEo1/i+4XSp3zunfK8usSX5NZpSVIjyWoj3K0xoiDaW+BRRklct3GJHU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335391; c=relaxed/simple; bh=+F7ij+vEsbAm2wdn42Abhvi+JQ8gS80qyP155wctWD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZWhhOt1tF/YKi44T4EFHEkZyZijEOLwh5L3ZGuK15c+jLTAjUrNYb8fbTQQNpeFr8icJVmw8AWgfDY/LW7ZEvXm/uNQUrlHh68MaCycbHui8sIyItPfyqBtW8EwdS726t2WzaCCT/v1HRY4NNc2BdNN7tTtbUCLcuQzYNlS5cQQ= 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=i3U737rN; arc=none smtp.client-ip=91.218.175.188 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="i3U737rN" 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=1761335388; 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=pr2b/97PTZcMzhNxqU5YG5YL4UQWiEMP6139KzQTUy8=; b=i3U737rNACxpeGjwiC75NITgX9iA+Zr5U/Zf8mWyELLxd9CGPkiAcckzj2HBEwJvWCOEgY BNd6J6pSUGAPRaZkh0Ke0wg1ep9nztlCOTqc7IyJCIt+mY67vP0J2jwZk87VDKZoScD5Zd M4nIleYYlLtTqMfcsIVIp7+T5d0wbMY= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [kvm-unit-tests 5/7] x86/svm: Move report_svm_guest() to the top of svm_tests.c Date: Fri, 24 Oct 2025 19:49:23 +0000 Message-ID: <20251024194925.3201933-6-yosry.ahmed@linux.dev> In-Reply-To: <20251024194925.3201933-1-yosry.ahmed@linux.dev> References: <20251024194925.3201933-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" From: Yosry Ahmed 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 feeb27d6..61ab63db 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.1.821.gb6fe4d2222-goog From nobody Sat Feb 7 21:24:11 2026 Received: from out-188.mta0.migadu.com (out-188.mta0.migadu.com [91.218.175.188]) (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 F31FD2DA750 for ; Fri, 24 Oct 2025 19:49:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335394; cv=none; b=sZBw7eNFGEep1Jcl8yTidxc9aLW9GG1ydfiL3U+8xr6PX5ZJsY4yqdOwuLr4RjFv/j+tjMn/0OIIA8PR9sXmZpurkUMeMRmfmrSDPw+h3HF55iFK6x487xrv01qycjxJOCS8GaBavdu/D0Ne2kEioQILffuOMYjn5pdebhrzQA0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335394; c=relaxed/simple; bh=3EkpC5FSbV63UBafl+vhHBNafoJEbdjtouKLV6FlxMI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=urgPakSOtK0YSliWAE/+B2nGwCShgpAApLdo6p1DukUj6RyIxE79pEFXVrGyhYBlovHHxlKWM6+cnC4OQhSWXurjDSR41eF8ncOPxnIPsaUmYZimnrsT5/sfBBaAsoWF9HWJnlmwjzSNS9hweDCGrNKC9k/+potBnmQQbQC9DdY= 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=uhFVEnob; arc=none smtp.client-ip=91.218.175.188 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="uhFVEnob" 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=1761335390; 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=N14hn83q9UZed7PeCnEY8nEK1bZdDBBqceHnhlCiyh8=; b=uhFVEnob9fpld+Hfip6q7A83Mho4kH4E0D8WzjlCHYIG+iL5CDH3V7LyepHrNLsi3jjge2 KjqFXfkOmkEdO0YLtMTfa3bqzfOYuB0wJl3nig6N/WUXr27x9DKlx6+qJiBbccBfk4MPA7 LpP7+T/ShqvEIXTrCW67cfyMq7ZAbug= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [kvm-unit-tests 6/7] x86/svm: Generalize and improve selective CR0 write intercept test Date: Fri, 24 Oct 2025 19:49:24 +0000 Message-ID: <20251024194925.3201933-7-yosry.ahmed@linux.dev> In-Reply-To: <20251024194925.3201933-1-yosry.ahmed@linux.dev> References: <20251024194925.3201933-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" From: Yosry Ahmed 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 61ab63db..71afb38a 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.1.821.gb6fe4d2222-goog From nobody Sat Feb 7 21:24:11 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 096992DE71C for ; Fri, 24 Oct 2025 19:49:53 +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=1761335396; cv=none; b=gkdTwpkPPQlVPbmkMG40MZGwhKSCVOK4vDr09+OIuEK/qOz+UO3v0VEPfiNP7+TVux83X+2mSRwsQTpCDOxAaTxKSHIjrE5pymIy6fsiTrRtWiOAU4iFKxHjyR2nMsxjjNDSIdwUutZLTJcqaV+kKu7TWf7iCZs5ccc/MPxAIvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761335396; c=relaxed/simple; bh=yyP+Tm7kJTp/FTPHWDY2cJ/4N/U3YBzgLhdCGhkG+P8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wiv+SbSEZTLeFFjHf//HAGA/fvfXaxllyMeCYbzL22B7KxuuTML1AIpUaV3cP/mHlh7oVZgN+x6F89GLeqDAA/rAroJk9AxkfaUVigg1m6/qK6omCYxcaw2xDKfUMUynUEGWbJRjy02t9ZyBu68nPv+QIGoC6tuCVzo1e1sW+5g= 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=I82LRSAv; 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="I82LRSAv" 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=1761335392; 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=1D4C7XeA5DQr9nxyfEg72e4UDxEu6XdeNiVsHiBcXX8=; b=I82LRSAvUCFKGjt9gSFfL4FntKtfgW+sRZuk/XVBPOYvpz05zbApt/aji7gANXKpuxMP3X 2kh7phvkrpKoFryGPhHLQXWagzM/r/KY0p44frp1OTsRShGmUC7s2YtfhyMgpxahMV+qk3 DecBd5ff/gRb3isDwKrkZB8DOLIP8O0= From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [kvm-unit-tests 7/7] x86/svm: Add more selective CR0 write and LMSW test cases Date: Fri, 24 Oct 2025 19:49:25 +0000 Message-ID: <20251024194925.3201933-8-yosry.ahmed@linux.dev> In-Reply-To: <20251024194925.3201933-1-yosry.ahmed@linux.dev> References: <20251024194925.3201933-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" From: Yosry Ahmed 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 71afb38a..2981f459 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.1.821.gb6fe4d2222-goog