mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosry.ahmed@linux.dev>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Jim Mattson <jmattson@google.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Yosry Ahmed <yosryahmed@google.com>
Subject: [kvm-unit-tests 3/7] x86/svm: Add FEP helpers for SVM tests
Date: Fri, 24 Oct 2025 19:49:21 +0000	[thread overview]
Message-ID: <20251024194925.3201933-4-yosry.ahmed@linux.dev> (raw)
In-Reply-To: <20251024194925.3201933-1-yosry.ahmed@linux.dev>

From: Yosry Ahmed <yosryahmed@google.com>

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 <yosryahmed@google.com>
---
 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)
 
+#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;
 }
 
+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);
-- 
2.51.1.821.gb6fe4d2222-goog


  parent reply	other threads:[~2025-10-24 19:49 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-24 19:49 [kvm-unit-tests 0/7] More tests for selective CR0 intercept Yosry Ahmed
2025-10-24 19:49 ` [kvm-unit-tests 1/7] x86/svm: Cleanup selective cr0 write intercept test Yosry Ahmed
2025-10-24 19:49 ` [kvm-unit-tests 2/7] x86/svm: Move CR0 selective write intercept test near CR3 intercept Yosry Ahmed
2025-10-24 19:49 ` Yosry Ahmed [this message]
2025-10-24 19:49 ` [kvm-unit-tests 4/7] x86/svm: Report unsupported SVM tests Yosry Ahmed
2025-10-24 19:49 ` [kvm-unit-tests 5/7] x86/svm: Move report_svm_guest() to the top of svm_tests.c Yosry Ahmed
2025-10-24 19:49 ` [kvm-unit-tests 6/7] x86/svm: Generalize and improve selective CR0 write intercept test Yosry Ahmed
2025-10-24 19:49 ` [kvm-unit-tests 7/7] x86/svm: Add more selective CR0 write and LMSW test cases Yosry Ahmed
2025-10-24 20:02 ` [kvm-unit-tests 0/7] More tests for selective CR0 intercept Yosry Ahmed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251024194925.3201933-4-yosry.ahmed@linux.dev \
    --to=yosry.ahmed@linux.dev \
    --cc=jmattson@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=yosryahmed@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®