]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
KVM: selftests: Add CPU vendor detection for Hygon
authorZhiquan Li <zhiquan_li@163.com>
Thu, 12 Feb 2026 10:38:38 +0000 (18:38 +0800)
committerSean Christopherson <seanjc@google.com>
Mon, 2 Mar 2026 21:16:19 +0000 (13:16 -0800)
Currently some KVM selftests are failed on Hygon CPUs due to missing
vendor detection and edge-case handling specific to Hygon's
architecture.

Add CPU vendor detection for Hygon and add a global variable
"host_cpu_is_hygon" as the basic facility for the following fixes.

Signed-off-by: Zhiquan Li <zhiquan_li@163.com>
Link: https://patch.msgid.link/20260212103841.171459-2-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

index 4ebae4269e68113a71172e2a0d4ace0fd13f9002..1338de7111e794f91e48f52506101411b56d15e3 100644 (file)
@@ -21,6 +21,7 @@
 
 extern bool host_cpu_is_intel;
 extern bool host_cpu_is_amd;
+extern bool host_cpu_is_hygon;
 extern uint64_t guest_tsc_khz;
 
 #ifndef MAX_NR_CPUID_ENTRIES
@@ -694,6 +695,11 @@ static inline bool this_cpu_is_amd(void)
        return this_cpu_vendor_string_is("AuthenticAMD");
 }
 
+static inline bool this_cpu_is_hygon(void)
+{
+       return this_cpu_vendor_string_is("HygonGenuine");
+}
+
 static inline uint32_t __this_cpu_has(uint32_t function, uint32_t index,
                                      uint8_t reg, uint8_t lo, uint8_t hi)
 {
index fab18e9be66c9821bf064ce70f99bbf10f369534..f6b1c5324931e662603a85b429739ed1b2cad42e 100644 (file)
@@ -23,6 +23,7 @@
 vm_vaddr_t exception_handlers;
 bool host_cpu_is_amd;
 bool host_cpu_is_intel;
+bool host_cpu_is_hygon;
 bool is_forced_emulation_enabled;
 uint64_t guest_tsc_khz;
 
@@ -792,6 +793,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, is_forced_emulation_enabled);
        sync_global_to_guest(vm, pmu_errata_mask);
 
@@ -1424,6 +1426,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();
        is_forced_emulation_enabled = kvm_is_forced_emulation_enabled();
 
        kvm_init_pmu_errata();