Check for KVM_FEATURE_PV_SEND_IPI before running the PV IPI test to avoid false failures or potential #UD exceptions in environments where KVM PV features are disabled, not supported by the host, or when running on non-KVM hypervisors or bare metal. Define the KVM_FEATURE_PV_SEND_IPI macro (bit 11 of EAX in KVM CPUID leaf 0x40000001) in processor.h to facilitate this check. Additionally, update the [xapic] and [x2apic] configurations in unittests.cfg to advertise PV IPIs (+kvm-pv-ipi) in the guest CPUID, ensuring the PV IPI tests are not skipped in standard test runs. Fixes: de8d3fcc5b63 ("x86: apic: pv ipis out-of-bounds access testing") Assisted-by: Gemini:gemini-3.1-pro Signed-off-by: Jim Mattson --- lib/x86/processor.h | 1 + x86/apic.c | 5 +++++ x86/unittests.cfg | 4 ++-- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/x86/processor.h b/lib/x86/processor.h index b2726d939a47..c2bc0a3d9ef5 100644 --- a/lib/x86/processor.h +++ b/lib/x86/processor.h @@ -354,6 +354,7 @@ struct x86_cpu_feature { */ #define KVM_FEATURE_CLOCKSOURCE2 X86_CPU_FEATURE(0x40000001, 0, EAX, 3) #define KVM_FEATURE_ASYNC_PF X86_CPU_FEATURE(0x40000001, 0, EAX, 4) +#define KVM_FEATURE_PV_SEND_IPI X86_CPU_FEATURE(0x40000001, 0, EAX, 11) #define KVM_FEATURE_ASYNC_PF_INT X86_CPU_FEATURE(0x40000001, 0, EAX, 14) /* diff --git a/x86/apic.c b/x86/apic.c index 1c37cb295209..fee1b7893185 100644 --- a/x86/apic.c +++ b/x86/apic.c @@ -642,6 +642,11 @@ static void test_pv_ipi(void) int ret; unsigned long a0 = 0xFFFFFFFF, a1 = 0, a2 = 0xFFFFFFFF, a3 = 0x0; + if (!this_cpu_has_kvm() || !this_cpu_has(KVM_FEATURE_PV_SEND_IPI)) { + report_skip("PV IPIs are not supported"); + return; + } + if (!test_device_enabled()) return; diff --git a/x86/unittests.cfg b/x86/unittests.cfg index b9cbcc596c3f..0c433ac29e5f 100644 --- a/x86/unittests.cfg +++ b/x86/unittests.cfg @@ -10,7 +10,7 @@ [x2apic] file = apic.flat smp = 2 -qemu_params = -cpu qemu64,+x2apic,+tsc-deadline +qemu_params = -cpu qemu64,+x2apic,+tsc-deadline,+kvm-pv-ipi arch = x86_64 timeout = 30 groups = apic @@ -19,7 +19,7 @@ groups = apic [xapic] file = apic.flat smp = 2 -qemu_params = -cpu qemu64,-x2apic,+tsc-deadline +qemu_params = -cpu qemu64,-x2apic,+tsc-deadline,+kvm-pv-ipi arch = x86_64 timeout = 60 groups = apic -- 2.55.0.rc0.799.gd6f94ed593-goog