git: 06e0d2934d5c - stable/14 - LinuxKPI: Add x86_vendor field to struct cpuinfo_x86

From: Vladimir Kondratyev <wulf_at_FreeBSD.org>
Date: Sat, 17 Feb 2024 21:33:15 UTC
The branch stable/14 has been updated by wulf:

URL: https://cgit.FreeBSD.org/src/commit/?id=06e0d2934d5c38f8f7ae1fc2e6a38e5c464742be

commit 06e0d2934d5c38f8f7ae1fc2e6a38e5c464742be
Author:     Vladimir Kondratyev <wulf@FreeBSD.org>
AuthorDate: 2023-12-24 08:20:00 +0000
Commit:     Vladimir Kondratyev <wulf@FreeBSD.org>
CommitDate: 2024-02-17 20:58:39 +0000

    LinuxKPI: Add x86_vendor field to struct cpuinfo_x86
    
    and initialize it at linuxkpi module load.
    
    Sponsored by:   Serenity Cyber Security, LLC
    Reviewed by:    manu
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D42820
    
    (cherry picked from commit b8c88a61750174f62db45784d6b4dc98de4073b1)
---
 sys/compat/linuxkpi/common/include/asm/processor.h | 13 +++++++++++++
 sys/compat/linuxkpi/common/src/linux_compat.c      | 21 +++++++++++++++++++++
 2 files changed, 34 insertions(+)

diff --git a/sys/compat/linuxkpi/common/include/asm/processor.h b/sys/compat/linuxkpi/common/include/asm/processor.h
index 9e784396c63a..1165702e0652 100644
--- a/sys/compat/linuxkpi/common/include/asm/processor.h
+++ b/sys/compat/linuxkpi/common/include/asm/processor.h
@@ -33,11 +33,24 @@
 #include <machine/cpu.h>
 
 #if defined(__i386__) || defined(__amd64__)
+#define	X86_VENDOR_INTEL	0
+#define	X86_VENDOR_CYRIX	1
+#define	X86_VENDOR_AMD		2
+#define	X86_VENDOR_UMC		3
+#define	X86_VENDOR_CENTAUR	5
+#define	X86_VENDOR_TRANSMETA	7
+#define	X86_VENDOR_NSC		8
+#define	X86_VENDOR_HYGON	9
+#define	X86_VENDOR_NUM		12
+
+#define	X86_VENDOR_UNKNOWN	0xff
+
 struct cpuinfo_x86 {
 	uint8_t		x86;
 	uint8_t		x86_model;
 	uint16_t	x86_clflush_size;
 	uint16_t	x86_max_cores;
+	uint8_t		x86_vendor;
 };
 
 extern struct cpuinfo_x86	boot_cpu_data;
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c
index b076a66ded77..c74021e32561 100644
--- a/sys/compat/linuxkpi/common/src/linux_compat.c
+++ b/sys/compat/linuxkpi/common/src/linux_compat.c
@@ -63,6 +63,7 @@
 #include <machine/stdarg.h>
 
 #if defined(__i386__) || defined(__amd64__)
+#include <machine/cputypes.h>
 #include <machine/md_var.h>
 #endif
 
@@ -2633,17 +2634,37 @@ linux_compat_init(void *arg)
 	int i;
 
 #if defined(__i386__) || defined(__amd64__)
+	static const uint32_t x86_vendors[X86_VENDOR_NUM] = {
+		[X86_VENDOR_INTEL] = CPU_VENDOR_INTEL,
+		[X86_VENDOR_CYRIX] = CPU_VENDOR_CYRIX,
+		[X86_VENDOR_AMD] = CPU_VENDOR_AMD,
+		[X86_VENDOR_UMC] = CPU_VENDOR_UMC,
+		[X86_VENDOR_CENTAUR] = CPU_VENDOR_CENTAUR,
+		[X86_VENDOR_TRANSMETA] = CPU_VENDOR_TRANSMETA,
+		[X86_VENDOR_NSC] = CPU_VENDOR_NSC,
+		[X86_VENDOR_HYGON] = CPU_VENDOR_HYGON,
+	};
+	uint8_t x86_vendor = X86_VENDOR_UNKNOWN;
+
+	for (i = 0; i < X86_VENDOR_NUM; i++) {
+		if (cpu_vendor_id != 0 && cpu_vendor_id == x86_vendors[i]) {
+			x86_vendor = i;
+			break;
+		}
+	}
 	linux_cpu_has_clflush = (cpu_feature & CPUID_CLFSH);
 	boot_cpu_data.x86_clflush_size = cpu_clflush_line_size;
 	boot_cpu_data.x86_max_cores = mp_ncpus;
 	boot_cpu_data.x86 = CPUID_TO_FAMILY(cpu_id);
 	boot_cpu_data.x86_model = CPUID_TO_MODEL(cpu_id);
+	boot_cpu_data.x86_vendor = x86_vendor;
 
 	for (i = 0; i < MAXCPU; i++) {
 		__cpu_data[i].x86_clflush_size = cpu_clflush_line_size;
 		__cpu_data[i].x86_max_cores = mp_ncpus;
 		__cpu_data[i].x86 = CPUID_TO_FAMILY(cpu_id);
 		__cpu_data[i].x86_model = CPUID_TO_MODEL(cpu_id);
+		__cpu_data[i].x86_vendor = x86_vendor;
 	}
 #endif
 	rw_init(&linux_vma_lock, "lkpi-vma-lock");