git: 011a3493610c - main - x86: add cpu_stdext_feature4

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Sun, 27 Apr 2025 22:32:46 UTC
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=011a3493610cc69e9337c857d4947b0bbc462c0a

commit 011a3493610cc69e9337c857d4947b0bbc462c0a
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2024-10-24 02:28:05 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-04-27 22:24:33 +0000

    x86: add cpu_stdext_feature4
    
    which corresponds to CPUID leaf 7 %ecx = 1 %eax report.  Decode only
    LASS and LAM for now.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
---
 sys/x86/include/x86_var.h |  1 +
 sys/x86/x86/identcpu.c    | 21 ++++++++++++++++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/sys/x86/include/x86_var.h b/sys/x86/include/x86_var.h
index dbb4e9557ed0..701b982e6afb 100644
--- a/sys/x86/include/x86_var.h
+++ b/sys/x86/include/x86_var.h
@@ -50,6 +50,7 @@ extern	u_int	cpu_clflush_line_size;
 extern	u_int	cpu_stdext_feature;
 extern	u_int	cpu_stdext_feature2;
 extern	u_int	cpu_stdext_feature3;
+extern	u_int	cpu_stdext_feature4;
 extern	uint64_t cpu_ia32_arch_caps;
 extern	u_int	cpu_high;
 extern	u_int	cpu_id;
diff --git a/sys/x86/x86/identcpu.c b/sys/x86/x86/identcpu.c
index 3f8f11fda011..4d64eaf78b29 100644
--- a/sys/x86/x86/identcpu.c
+++ b/sys/x86/x86/identcpu.c
@@ -111,9 +111,12 @@ char	cpu_vendor[20];		/* CPU Origin code */
 u_int	cpu_vendor_id;		/* CPU vendor ID */
 u_int	cpu_mxcsr_mask;		/* Valid bits in mxcsr */
 u_int	cpu_clflush_line_size = 32;
+/* leaf 7 %ecx = 0 */
 u_int	cpu_stdext_feature;	/* %ebx */
 u_int	cpu_stdext_feature2;	/* %ecx */
 u_int	cpu_stdext_feature3;	/* %edx */
+/* leaf 7 %ecx = 1 */
+u_int	cpu_stdext_feature4;	/* %eax */
 uint64_t cpu_ia32_arch_caps;
 u_int	cpu_max_ext_state_size;
 u_int	cpu_mon_mwait_flags;	/* MONITOR/MWAIT flags (CPUID.05H.ECX) */
@@ -1043,6 +1046,16 @@ printcpuinfo(void)
 				       "\040SSBD"
 				       );
 			}
+#define	STDEXT4_MASK	(CPUID_STDEXT4_LASS | CPUID_STDEXT4_LAM)
+			if ((cpu_stdext_feature4 & STDEXT4_MASK) != 0) {
+				printf("\n  Structured Extended Features4=0x%b",
+				    cpu_stdext_feature4 & STDEXT4_MASK,
+				       "\020"
+				       "\007LASS"
+				       "\033LAM"
+				       );
+			}
+#undef STDEXT4_MASK
 
 			if ((cpu_feature2 & CPUID2_XSAVE) != 0) {
 				cpuid_count(0xd, 0x1, regs);
@@ -1562,7 +1575,7 @@ identify_cpu1(void)
 void
 identify_cpu2(void)
 {
-	u_int regs[4], cpu_stdext_disable;
+	u_int regs[4], cpu_stdext_disable, max_eax_l7;
 
 	if (cpu_high >= 6) {
 		cpuid_count(6, 0, regs);
@@ -1575,6 +1588,7 @@ identify_cpu2(void)
 	if (cpu_high >= 7) {
 		cpuid_count(7, 0, regs);
 		cpu_stdext_feature = regs[1];
+		max_eax_l7 = regs[0];
 
 		/*
 		 * Some hypervisors failed to filter out unsupported
@@ -1591,6 +1605,11 @@ identify_cpu2(void)
 
 		if ((cpu_stdext_feature3 & CPUID_STDEXT3_ARCH_CAP) != 0)
 			cpu_ia32_arch_caps = rdmsr(MSR_IA32_ARCH_CAP);
+
+		if (max_eax_l7 >= 1) {
+			cpuid_count(7, 1, regs);
+			cpu_stdext_feature4 = regs[0];
+		}
 	}
 }