-/* $OpenBSD: cpu.c,v 1.159 2022/09/15 19:30:51 cheloha Exp $ */
+/* $OpenBSD: cpu.c,v 1.160 2022/09/20 14:28:27 robert Exp $ */
/* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */
/*-
#endif
cpu_tsx_disable(ci);
identifycpu(ci);
+ cpu_fix_msrs(ci);
#ifdef MTRR
mem_range_attach();
#endif /* MTRR */
CPUF_PRESENT | CPUF_BSP | CPUF_PRIMARY);
cpu_intr_init(ci);
identifycpu(ci);
+ cpu_fix_msrs(ci);
#ifdef MTRR
mem_range_attach();
#endif /* MTRR */
atomic_setbits_int(&ci->ci_flags, CPUF_IDENTIFIED);
}
+ /* These have to run after identifycpu() */
+ cpu_fix_msrs(ci);
+
/*
* Test if our TSC is synchronized for the first time.
* Note that interrupts are off at this point.
void
cpu_init_msrs(struct cpu_info *ci)
{
- uint64_t msr;
- int family;
-
wrmsr(MSR_STAR,
((uint64_t)GSEL(GCODE_SEL, SEL_KPL) << 32) |
((uint64_t)GSEL(GUCODE32_SEL, SEL_UPL) << 48));
wrmsr(MSR_FSBASE, 0);
wrmsr(MSR_GSBASE, (u_int64_t)ci);
wrmsr(MSR_KERNELGSBASE, 0);
+ patinit(ci);
+}
- family = ci->ci_family;
- if (strcmp(cpu_vendor, "GenuineIntel") == 0 &&
- (family > 6 || (family == 6 && ci->ci_model >= 0xd)) &&
- rdmsr_safe(MSR_MISC_ENABLE, &msr) == 0 &&
- (msr & MISC_ENABLE_FAST_STRINGS) == 0) {
- msr |= MISC_ENABLE_FAST_STRINGS;
- wrmsr(MSR_MISC_ENABLE, msr);
- DPRINTF("%s: enabled fast strings\n", ci->ci_dev->dv_xname);
+void
+cpu_fix_msrs(struct cpu_info *ci)
+{
+ int family = ci->ci_family;
+ uint64_t msr;
+
+ if (!strcmp(cpu_vendor, "GenuineIntel")) {
+ if ((family > 6 || (family == 6 && ci->ci_model >= 0xd)) &&
+ rdmsr_safe(MSR_MISC_ENABLE, &msr) == 0 &&
+ (msr & MISC_ENABLE_FAST_STRINGS) == 0) {
+ msr |= MISC_ENABLE_FAST_STRINGS;
+ wrmsr(MSR_MISC_ENABLE, msr);
+ DPRINTF("%s: enabled fast strings\n", ci->ci_dev->dv_xname);
+
+ /*
+ * Attempt to disable Silicon Debug and lock the configuration
+ * if it's enabled and unlocked.
+ */
+ if (cpu_ecxfeature & CPUIDECX_SDBG) {
+ msr = rdmsr(IA32_DEBUG_INTERFACE);
+ if ((msr & IA32_DEBUG_INTERFACE_ENABLE) &&
+ (msr & IA32_DEBUG_INTERFACE_LOCK) == 0) {
+ msr &= IA32_DEBUG_INTERFACE_MASK;
+ msr |= IA32_DEBUG_INTERFACE_LOCK;
+ wrmsr(IA32_DEBUG_INTERFACE, msr);
+ } else if (msr & IA32_DEBUG_INTERFACE_ENABLE)
+ printf("%s: cannot disable silicon debug\n",
+ ci->ci_dev->dv_xname);
+ }
+ }
}
- patinit(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")) {
+ if (family >= 0x10 && family != 0x11) {
+ msr = rdmsr(MSR_DE_CFG);
+ if ((msr & DE_CFG_SERIALIZE_LFENCE) == 0) {
+ msr |= DE_CFG_SERIALIZE_LFENCE;
+ wrmsr(MSR_DE_CFG, msr);
+ }
+ }
+ }
}
void
-/* $OpenBSD: identcpu.c,v 1.127 2022/08/30 17:09:21 dv Exp $ */
+/* $OpenBSD: identcpu.c,v 1.128 2022/09/20 14:28:27 robert Exp $ */
/* $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */
/*
replacemeltdown();
x86_print_cacheinfo(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")) {
- if (ci->ci_family >= 0x10 && ci->ci_family != 0x11) {
- uint64_t msr;
-
- msr = rdmsr(MSR_DE_CFG);
- if ((msr & DE_CFG_SERIALIZE_LFENCE) == 0) {
- msr |= DE_CFG_SERIALIZE_LFENCE;
- wrmsr(MSR_DE_CFG, msr);
- }
- }
- }
-
- /*
- * Attempt to disable Silicon Debug and lock the configuration
- * if it's enabled and unlocked.
- */
- if (!strcmp(cpu_vendor, "GenuineIntel") &&
- (cpu_ecxfeature & CPUIDECX_SDBG)) {
- uint64_t msr;
-
- msr = rdmsr(IA32_DEBUG_INTERFACE);
- if ((msr & IA32_DEBUG_INTERFACE_ENABLE) &&
- (msr & IA32_DEBUG_INTERFACE_LOCK) == 0) {
- msr &= IA32_DEBUG_INTERFACE_MASK;
- msr |= IA32_DEBUG_INTERFACE_LOCK;
- wrmsr(IA32_DEBUG_INTERFACE, msr);
- } else if (msr & IA32_DEBUG_INTERFACE_ENABLE)
- printf("%s: cannot disable silicon debug\n",
- ci->ci_dev->dv_xname);
- }
-
if (CPU_IS_PRIMARY(ci)) {
#ifndef SMALL_KERNEL
if (!strcmp(cpu_vendor, "AuthenticAMD") &&