From f592305397586212dd60eedbf3a9a9493d548ada Mon Sep 17 00:00:00 2001 From: jsg Date: Wed, 9 Aug 2023 00:01:44 +0000 Subject: [PATCH] show x86 cpu patch level in dmesg ok guenther@ deraadt@ --- sys/arch/amd64/amd64/identcpu.c | 17 ++++++++++++++++- sys/arch/i386/i386/machdep.c | 17 ++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/sys/arch/amd64/amd64/identcpu.c b/sys/arch/amd64/amd64/identcpu.c index ed8701172d2..557e40586a0 100644 --- a/sys/arch/amd64/amd64/identcpu.c +++ b/sys/arch/amd64/amd64/identcpu.c @@ -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++) diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index bea9622e905..8f943685c82 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -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) { -- 2.20.1