Skip to contentSkip to conversation

x86/vmexit: Add WBINVD and INVD VM-Exit latency testcases

PATCH Applied Sean Christopherson 2 participants 3 messages Nov 13, 2025 – Nov 18, 2025 KVM

lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

PATCH 1/1 x86/vmexit: Add WBINVD and INVD VM-Exit latency testcases

Add WBINVD and INVD testcase to the VM-Exit performance/latency test so that it's easy to measure latency of VM-Exits that are handled in KVM's fastpath on both Intel and AMD (INVD), and so that a direct comparison can be made to an exit with no meaningful emulation (WBINVD).

Don't create entries in x86/unittests.cfg, as running the INVD test on bare metal (or a hypervisor that emulates INVD) would likely corrupt memory (and similarly, WBINVD can have a massively negative impact on the system).

---
 x86/vmexit.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
x86/vmexit.c +12 -0
index 48a38f60..46cc4c92 100644
@@ -36,6 +36,16 @@ static void vmcall(void)
 	asm volatile ("vmcall" : "+a"(a), "=b"(b), "=c"(c), "=d"(d));
 }
 
+static void wbinvd(void)
+{
+	asm volatile ("wbinvd");
+}
+
+static void invd(void)
+{
+	asm volatile ("invd");
+}
+
 #define MSR_EFER 0xc0000080
 #define EFER_NX_MASK            (1ull << 11)
 
@@ -482,6 +492,8 @@ static void toggle_cr4_pge(void)
 static struct test tests[] = {
 	{ cpuid_test, "cpuid", .parallel = 1,  },
 	{ vmcall, "vmcall", .parallel = 1, },
+	{ wbinvd, "wbinvd", .parallel = 1, },
+	{ invd, "invd", .parallel = 1, },
 #ifdef __x86_64__
 	{ mov_from_cr8, "mov_from_cr8", .parallel = 1, },
 	{ mov_to_cr8, "mov_to_cr8" , .parallel = 1, },

base-commit: af582a4ebaf7828c200dc7150aa0dbccb60b08a7

Signature · 1 line
2.52.0.rc1.455.g30608eb744-goog
Tested-by on v1 1/1
#1 lore raw
Quoted 46 lines · Sean Christopherson

Add WBINVD and INVD testcase to the VM-Exit performance/latency test so that it's easy to measure latency of VM-Exits that are handled in KVM's fastpath on both Intel and AMD (INVD), and so that a direct comparison can be made to an exit with no meaningful emulation (WBINVD).

Don't create entries in x86/unittests.cfg, as running the INVD test on bare metal (or a hypervisor that emulates INVD) would likely corrupt memory (and similarly, WBINVD can have a massively negative impact on the system).

---
 x86/vmexit.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
x86/vmexit.c +12 -0
index 48a38f60..46cc4c92 100644
@@ -36,6 +36,16 @@ static void vmcall(void)
 	asm volatile ("vmcall" : "+a"(a), "=b"(b), "=c"(c), "=d"(d));
 }
 
+static void wbinvd(void)
+{
+	asm volatile ("wbinvd");
+}
+
+static void invd(void)
+{
+	asm volatile ("invd");
+}
+
 #define MSR_EFER 0xc0000080
 #define EFER_NX_MASK            (1ull << 11)
 
@@ -482,6 +492,8 @@ static void toggle_cr4_pge(void)
 static struct test tests[] = {
 	{ cpuid_test, "cpuid", .parallel = 1,  },
 	{ vmcall, "vmcall", .parallel = 1, },
+	{ wbinvd, "wbinvd", .parallel = 1, },
+	{ invd, "invd", .parallel = 1, },
 #ifdef __x86_64__
 	{ mov_from_cr8, "mov_from_cr8", .parallel = 1, },
 	{ mov_to_cr8, "mov_to_cr8" , .parallel = 1, },
Quoted 1 line

base-commit: af582a4ebaf7828c200dc7150aa0dbccb60b08a7

I have tested this on AMD EPYC-Genoa and EPYC-Turin machine on 6.18-rc5.

Both the tests work as expected.

Results:
---------------------------------------
| | wbinvd | invd |
----------------------------------------
| AMD EPYC-Genoa | 2.6k | 2.1k |
----------------------------------------
| AMD EPYC-Turin | 2.0k | 1.8k |
----------------------------------------

Feel free to add

-Manali

author reviewer Applied
#2 lore raw
In reply to Sean Christopherson
Quoted 11 lines · Sean Christopherson

Add WBINVD and INVD testcase to the VM-Exit performance/latency test so that it's easy to measure latency of VM-Exits that are handled in KVM's fastpath on both Intel and AMD (INVD), and so that a direct comparison can be made to an exit with no meaningful emulation (WBINVD).

Don't create entries in x86/unittests.cfg, as running the INVD test on bare metal (or a hypervisor that emulates INVD) would likely corrupt memory (and similarly, WBINVD can have a massively negative impact on the system).

[...]

Applied to kvm-x86 next, thanks!

[1/1] x86/vmexit: Add WBINVD and INVD VM-Exit latency testcases

      https://github.com/kvm-x86/kvm-unit-tests/commit/70e7bc408e10

--
https://github.com/kvm-x86/kvm-unit-tests/tree/next