From: robert Date: Thu, 22 Sep 2022 04:36:37 +0000 (+0000) Subject: Call amd64_errata() from cpu_fix_msrs() instead of identifycpu() so that X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=46a03a1ef9f5cfd6cf3f55a92b8b55ec30bfcd07;p=openbsd Call amd64_errata() from cpu_fix_msrs() instead of identifycpu() so that on resume, the errata is re-applied. In addition make amd64_errata() print the information about the applied errata only once for the first CPU. input from jsg@ and deraadt@, ok deraadt@ --- diff --git a/sys/arch/amd64/amd64/amd64errata.c b/sys/arch/amd64/amd64/amd64errata.c index 1f891511093..5483eb3c47f 100644 --- a/sys/arch/amd64/amd64/amd64errata.c +++ b/sys/arch/amd64/amd64/amd64errata.c @@ -1,4 +1,4 @@ -/* $OpenBSD: amd64errata.c,v 1.10 2022/09/20 07:54:27 jsg Exp $ */ +/* $OpenBSD: amd64errata.c,v 1.11 2022/09/22 04:36:37 robert Exp $ */ /* $NetBSD: errata.c,v 1.6 2007/02/05 21:05:45 ad Exp $ */ /*- @@ -49,7 +49,6 @@ #include #include - typedef struct errata { u_short e_num; u_short e_reported; @@ -294,6 +293,7 @@ amd64_errata(struct cpu_info *ci) int rc; int found = 0; int corrected = 0; + static int printed = 0; CPUID(0x80000001, code, dummy, dummy, dummy); @@ -362,17 +362,22 @@ amd64_errata(struct cpu_info *ci) int first = 1; /* Print out found and corrected */ - printf("%s: AMD %s", ci->ci_dev->dv_xname, - (corrected == 1) ? "erratum" : "errata"); + if (!printed) { + printf("%s: AMD %s", ci->ci_dev->dv_xname, + (corrected == 1) ? "erratum" : "errata"); + } for (e = errata; e < ex; e++) { if (e->e_reported == 2) { - if (! first) - printf(","); - printf(" %d", e->e_num); + if (!printed) { + if (! first) + printf(","); + printf(" %d", e->e_num); + } first = 0; } } - printf(" detected and fixed\n"); + if (!printed) + printf(" detected and fixed\n"); } #endif @@ -380,16 +385,24 @@ amd64_errata(struct cpu_info *ci) int first = 1; /* Print out found but not corrected */ - printf("%s: AMD %s", ci->ci_dev->dv_xname, - (found == 1) ? "erratum" : "errata"); + if (!printed) { + printf("%s: AMD %s", ci->ci_dev->dv_xname, + (found == 1) ? "erratum" : "errata"); + } for (e = errata; e < ex; e++) { if (e->e_reported == 1) { - if (! first) - printf(","); - printf(" %d", e->e_num); + if (!printed) { + if (! first) + printf(","); + printf(" %d", e->e_num); + } first = 0; } } - printf(" present, BIOS upgrade may be required\n"); + if (!printed) + printf(" present, BIOS upgrade may be required\n"); } + + /* Print only one time for the first CPU */ + printed = 1; } diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index 68c83d902a6..22736b3fc3e 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.160 2022/09/20 14:28:27 robert Exp $ */ +/* $OpenBSD: cpu.c,v 1.161 2022/09/22 04:36:37 robert Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -1146,17 +1146,20 @@ cpu_fix_msrs(struct cpu_info *ci) } } - /* - * "Mitigation G-2" per AMD's Whitepaper "Software Techniques - * for Managing Speculation on AMD Processors" - * - * By setting MSR C001_1029[1]=1, LFENCE becomes a dispatch - * serializing instruction. - * - * This MSR is available on all AMD families >= 10h, except 11h - * where LFENCE is always serializing. - */ if (!strcmp(cpu_vendor, "AuthenticAMD")) { + /* Apply AMD errata */ + amd64_errata(ci); + + /* + * "Mitigation G-2" per AMD's Whitepaper "Software Techniques + * for Managing Speculation on AMD Processors" + * + * By setting MSR C001_1029[1]=1, LFENCE becomes a dispatch + * serializing instruction. + * + * This MSR is available on all AMD families >= 10h, except 11h + * where LFENCE is always serializing. + */ if (family >= 0x10 && family != 0x11) { msr = rdmsr(MSR_DE_CFG); if ((msr & DE_CFG_SERIALIZE_LFENCE) == 0) { diff --git a/sys/arch/amd64/amd64/identcpu.c b/sys/arch/amd64/amd64/identcpu.c index 09c7ce842fa..001a437045b 100644 --- a/sys/arch/amd64/amd64/identcpu.c +++ b/sys/arch/amd64/amd64/identcpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: identcpu.c,v 1.128 2022/09/20 14:28:27 robert Exp $ */ +/* $OpenBSD: identcpu.c,v 1.129 2022/09/22 04:36:38 robert Exp $ */ /* $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */ /* @@ -753,9 +753,6 @@ identifycpu(struct cpu_info *ci) } #endif - if (!strcmp(cpu_vendor, "AuthenticAMD")) - amd64_errata(ci); - if (CPU_IS_PRIMARY(ci) && !strcmp(cpu_vendor, "CentaurHauls")) { ci->cpu_setup = via_nano_setup; #ifndef SMALL_KERNEL