]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: selftests: Add a flag to identify AMD compatible test cases
authorZhiquan Li <zhiquan_li@163.com>
Thu, 12 Feb 2026 10:38:39 +0000 (18:38 +0800)
committerSean Christopherson <seanjc@google.com>
Mon, 2 Mar 2026 21:16:36 +0000 (13:16 -0800)
Most of KVM x86 selftests for AMD are compatible with Hygon architecture
(but not all), add a flag "host_cpu_is_amd_compatible" to figure out
these cases.

Following test failures on Hygon platform can be fixed:

* Fix hypercall test: Hygon architecture also uses VMMCALL as guest
  hypercall instruction.

* Following test failures due to access reserved memory address regions:
  - access_tracking_perf_test
  - demand_paging_test
  - dirty_log_perf_test
  - dirty_log_test
  - kvm_page_table_test
  - memslot_modification_stress_test
  - pre_fault_memory_test
  - x86/dirty_log_page_splitting_test

Hygon CSV also makes the "physical address space width reduction", the
reduced physical address bits are reported by bits 11:6 of
CPUID[0x8000001f].EBX as well, so the existed logic is totally
applicable for Hygon processors.  Mapping memory into these regions and
accessing to them results in a #PF.

Signed-off-by: Zhiquan Li <zhiquan_li@163.com>
Link: https://patch.msgid.link/20260212103841.171459-3-zhiquan_li@163.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
tools/testing/selftests/kvm/include/x86/processor.h
tools/testing/selftests/kvm/lib/x86/processor.c
tools/testing/selftests/kvm/x86/fix_hypercall_test.c
tools/testing/selftests/kvm/x86/msrs_test.c
tools/testing/selftests/kvm/x86/xapic_state_test.c

index 1338de7111e794f91e48f52506101411b56d15e3..40e3deb648120691099801bb29e794e61e53a4b6 100644 (file)
@@ -22,6 +22,7 @@
 extern bool host_cpu_is_intel;
 extern bool host_cpu_is_amd;
 extern bool host_cpu_is_hygon;
+extern bool host_cpu_is_amd_compatible;
 extern uint64_t guest_tsc_khz;
 
 #ifndef MAX_NR_CPUID_ENTRIES
index f6b1c5324931e662603a85b429739ed1b2cad42e..f4e8649071b625cf7fc500873203077ea18da804 100644 (file)
@@ -24,6 +24,7 @@ vm_vaddr_t exception_handlers;
 bool host_cpu_is_amd;
 bool host_cpu_is_intel;
 bool host_cpu_is_hygon;
+bool host_cpu_is_amd_compatible;
 bool is_forced_emulation_enabled;
 uint64_t guest_tsc_khz;
 
@@ -794,6 +795,7 @@ void kvm_arch_vm_post_create(struct kvm_vm *vm, unsigned int nr_vcpus)
        sync_global_to_guest(vm, host_cpu_is_intel);
        sync_global_to_guest(vm, host_cpu_is_amd);
        sync_global_to_guest(vm, host_cpu_is_hygon);
+       sync_global_to_guest(vm, host_cpu_is_amd_compatible);
        sync_global_to_guest(vm, is_forced_emulation_enabled);
        sync_global_to_guest(vm, pmu_errata_mask);
 
@@ -1350,7 +1352,8 @@ const struct kvm_cpuid_entry2 *get_cpuid_entry(const struct kvm_cpuid2 *cpuid,
                     "1: vmmcall\n\t"                                   \
                     "2:"                                               \
                     : "=a"(r)                                          \
-                    : [use_vmmcall] "r" (host_cpu_is_amd), inputs);    \
+                    : [use_vmmcall] "r" (host_cpu_is_amd_compatible),  \
+                      inputs);                                         \
                                                                        \
        r;                                                              \
 })
@@ -1390,8 +1393,8 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm)
 
        max_gfn = (1ULL << (guest_maxphyaddr - vm->page_shift)) - 1;
 
-       /* Avoid reserved HyperTransport region on AMD processors.  */
-       if (!host_cpu_is_amd)
+       /* Avoid reserved HyperTransport region on AMD or Hygon processors. */
+       if (!host_cpu_is_amd_compatible)
                return max_gfn;
 
        /* On parts with <40 physical address bits, the area is fully hidden */
@@ -1405,7 +1408,7 @@ unsigned long vm_compute_max_gfn(struct kvm_vm *vm)
 
        /*
         * Otherwise it's at the top of the physical address space, possibly
-        * reduced due to SME by bits 11:6 of CPUID[0x8000001f].EBX.  Use
+        * reduced due to SME or CSV by bits 11:6 of CPUID[0x8000001f].EBX.  Use
         * the old conservative value if MAXPHYADDR is not enumerated.
         */
        if (!this_cpu_has_p(X86_PROPERTY_MAX_PHY_ADDR))
@@ -1427,6 +1430,7 @@ void kvm_selftest_arch_init(void)
        host_cpu_is_intel = this_cpu_is_intel();
        host_cpu_is_amd = this_cpu_is_amd();
        host_cpu_is_hygon = this_cpu_is_hygon();
+       host_cpu_is_amd_compatible = host_cpu_is_amd || host_cpu_is_hygon;
        is_forced_emulation_enabled = kvm_is_forced_emulation_enabled();
 
        kvm_init_pmu_errata();
index 762628f7d4ba38d93431023300edeeae540f801a..00b6e85735dd01c5f8bb060ac3708dcab02b30a3 100644 (file)
@@ -52,7 +52,7 @@ static void guest_main(void)
        if (host_cpu_is_intel) {
                native_hypercall_insn = vmx_vmcall;
                other_hypercall_insn  = svm_vmmcall;
-       } else if (host_cpu_is_amd) {
+       } else if (host_cpu_is_amd_compatible) {
                native_hypercall_insn = svm_vmmcall;
                other_hypercall_insn  = vmx_vmcall;
        } else {
index 40d918aedce672c073d16bf9ca37216ca56cf615..4c97444fdefec07345fd1ce514af8c26ead7753b 100644 (file)
@@ -81,7 +81,7 @@ static u64 fixup_rdmsr_val(u32 msr, u64 want)
         * is supposed to emulate that behavior based on guest vendor model
         * (which is the same as the host vendor model for this test).
         */
-       if (!host_cpu_is_amd)
+       if (!host_cpu_is_amd_compatible)
                return want;
 
        switch (msr) {
index 3b4814c55722bc902a1c4bb0ace2ec558e7439a5..0c5e12f5f14ed50dd8edbd2f3c421e54e9acd65c 100644 (file)
@@ -248,7 +248,7 @@ int main(int argc, char *argv[])
         * drops writes, AMD does not).  Account for the errata when checking
         * that KVM reads back what was written.
         */
-       x.has_xavic_errata = host_cpu_is_amd &&
+       x.has_xavic_errata = host_cpu_is_amd_compatible &&
                             get_kvm_amd_param_bool("avic");
 
        vcpu_clear_cpuid_feature(x.vcpu, X86_FEATURE_X2APIC);