From 8d0e9f7b2f4ccacce392e9c2ada9fb87c63f1ccb Mon Sep 17 00:00:00 2001 From: deraadt Date: Tue, 25 Jul 2023 04:42:00 +0000 Subject: [PATCH] Some hypervisors (such as Hertzner) allow msr read of DE_CFG (which does not indicate bit 9 set, but they could have a firmware fix) but then block a msr write to bit 9 (which disables enough AVX optimizations to prevent the exfiltration of data), with a fault. So let's also check the HV bit before we decide to modify the bit. hypervisors are expected to set that bit. tested by lucas at sexy dot is. with jsg, ok mlarkin --- sys/arch/amd64/amd64/cpu.c | 5 +++-- sys/arch/i386/i386/machdep.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/sys/arch/amd64/amd64/cpu.c b/sys/arch/amd64/amd64/cpu.c index 4d766727076..67298c22f48 100644 --- a/sys/arch/amd64/amd64/cpu.c +++ b/sys/arch/amd64/amd64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.172 2023/07/24 14:53:58 deraadt Exp $ */ +/* $OpenBSD: cpu.c,v 1.173 2023/07/25 04:42:00 deraadt Exp $ */ /* $NetBSD: cpu.c,v 1.1 2003/04/26 18:39:26 fvdl Exp $ */ /*- @@ -1216,7 +1216,8 @@ cpu_fix_msrs(struct cpu_info *ci) if (msr != nmsr) wrmsr(MSR_DE_CFG, nmsr); } - if (family == 0x17 && ci->ci_model >= 0x31) { + if (family == 0x17 && ci->ci_model >= 0x31 && + (cpu_ecxfeature & CPUIDECX_HV) == 0) { nmsr = msr = rdmsr(MSR_DE_CFG); nmsr |= DE_CFG_SERIALIZE_9; if (msr != nmsr) diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 6ef885c0b2c..bea9622e905 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.664 2023/07/24 14:54:00 deraadt Exp $ */ +/* $OpenBSD: machdep.c,v 1.665 2023/07/25 04:42:02 deraadt Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -1993,7 +1993,8 @@ identifycpu(struct cpu_info *ci) if (msr != nmsr) wrmsr(MSR_DE_CFG, nmsr); } - if (family == 0x17 && ci->ci_model >= 0x31) { + if (family == 0x17 && ci->ci_model >= 0x31 && + (cpu_ecxfeature & CPUIDECX_HV) == 0) { nmsr = msr = rdmsr(MSR_DE_CFG); nmsr |= DE_CFG_SERIALIZE_9; if (msr != nmsr) -- 2.20.1