show x86 cpu patch level in dmesg
authorjsg <jsg@openbsd.org>
Wed, 9 Aug 2023 00:01:44 +0000 (00:01 +0000)
committerjsg <jsg@openbsd.org>
Wed, 9 Aug 2023 00:01:44 +0000 (00:01 +0000)
ok guenther@ deraadt@

sys/arch/amd64/amd64/identcpu.c
sys/arch/i386/i386/machdep.c

index ed87011..557e405 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: identcpu.c,v 1.135 2023/07/27 01:51:35 guenther Exp $ */
+/*     $OpenBSD: identcpu.c,v 1.136 2023/08/09 00:01:44 jsg Exp $      */
 /*     $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $        */
 
 /*
@@ -650,6 +650,21 @@ identifycpu(struct cpu_info *ci)
        printf(", %02x-%02x-%02x", ci->ci_family, ci->ci_model,
            ci->ci_signature & 0x0f);
 
+       if ((cpu_ecxfeature & CPUIDECX_HV) == 0) {
+               uint64_t level = 0;
+               uint32_t dummy;
+
+               if (strcmp(cpu_vendor, "AuthenticAMD") == 0) {
+                       level = rdmsr(MSR_PATCH_LEVEL);
+               } else if (strcmp(cpu_vendor, "GenuineIntel") == 0) {
+                       wrmsr(MSR_BIOS_SIGN, 0);
+                       CPUID(1, dummy, dummy, dummy, dummy);
+                       level = rdmsr(MSR_BIOS_SIGN) >> 32;
+               }
+               if (level != 0)
+                       printf(", patch %08llx", level);
+       }
+
        printf("\n%s: ", ci->ci_dev->dv_xname);
 
        for (i = 0; i < nitems(cpu_cpuid_features); i++)
index bea9622..8f94368 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: machdep.c,v 1.665 2023/07/25 04:42:02 deraadt Exp $   */
+/*     $OpenBSD: machdep.c,v 1.666 2023/08/09 00:01:44 jsg Exp $       */
 /*     $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $    */
 
 /*-
@@ -1859,6 +1859,21 @@ identifycpu(struct cpu_info *ci)
                printf(", %02x-%02x-%02x", ci->ci_family, ci->ci_model,
                    step);
 
+       if ((cpu_ecxfeature & CPUIDECX_HV) == 0) {
+               uint64_t level = 0;
+               uint32_t dummy;
+
+               if (strcmp(cpu_vendor, "AuthenticAMD") == 0) {
+                       level = rdmsr(MSR_PATCH_LEVEL);
+               } else if (strcmp(cpu_vendor, "GenuineIntel") == 0) {
+                       wrmsr(MSR_BIOS_SIGN, 0);
+                       CPUID(1, dummy, dummy, dummy, dummy);
+                       level = rdmsr(MSR_BIOS_SIGN) >> 32;
+               }
+               if (level != 0)
+                       printf(", patch %08llx", level);
+       }
+
        printf("\n");
 
        if (ci->ci_feature_flags) {