From: dv Date: Tue, 10 Jan 2023 01:09:14 +0000 (+0000) Subject: Hide WAITPKG cpu feature from vmm(4) guests. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=c2cbc5b2d858c1549980a6bf2d5f58efa041f1e2;p=openbsd Hide WAITPKG cpu feature from vmm(4) guests. Alder Lake and similar-era Intel platforms introduced new userland wait instructions. Since vmm was passing this cpuid bit into guests, some would attempt TPAUSE instructions and trigger invalid instruction exceptions because VMX requires additional configuration to support emulation. This also adds WAITPKG to i386 and amd64 cpu feature identification. Input from anton@, cheloha@, and guenther@. Tested by jmatthew@. OK deraadt. --- diff --git a/sys/arch/amd64/amd64/identcpu.c b/sys/arch/amd64/amd64/identcpu.c index 001a437045b..3d650a0fc76 100644 --- a/sys/arch/amd64/amd64/identcpu.c +++ b/sys/arch/amd64/amd64/identcpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: identcpu.c,v 1.129 2022/09/22 04:36:38 robert Exp $ */ +/* $OpenBSD: identcpu.c,v 1.130 2023/01/10 01:09:14 dv Exp $ */ /* $NetBSD: identcpu.c,v 1.1 2003/04/26 18:39:28 fvdl Exp $ */ /* @@ -208,6 +208,7 @@ const struct { { SEFF0ECX_AVX512VBMI, "AVX512VBMI" }, { SEFF0ECX_UMIP, "UMIP" }, { SEFF0ECX_PKU, "PKU" }, + { SEFF0ECX_WAITPKG, "WAITPKG" }, }, cpu_seff0_edxfeatures[] = { { SEFF0EDX_AVX512_4FNNIW, "AVX512FNNIW" }, { SEFF0EDX_AVX512_4FMAPS, "AVX512FMAPS" }, diff --git a/sys/arch/amd64/include/specialreg.h b/sys/arch/amd64/include/specialreg.h index cbde6cf9b02..14010a5f2ff 100644 --- a/sys/arch/amd64/include/specialreg.h +++ b/sys/arch/amd64/include/specialreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: specialreg.h,v 1.95 2022/10/24 00:56:33 cheloha Exp $ */ +/* $OpenBSD: specialreg.h,v 1.96 2023/01/10 01:09:14 dv Exp $ */ /* $NetBSD: specialreg.h,v 1.1 2003/04/26 18:39:48 fvdl Exp $ */ /* $NetBSD: x86/specialreg.h,v 1.2 2003/04/25 21:54:30 fvdl Exp $ */ @@ -201,6 +201,7 @@ #define SEFF0ECX_AVX512VBMI 0x00000002 /* AVX-512 vector bit inst */ #define SEFF0ECX_UMIP 0x00000004 /* UMIP support */ #define SEFF0ECX_PKU 0x00000008 /* Page prot keys for user mode */ +#define SEFF0ECX_WAITPKG 0x00000010 /* UMONITOR/UMWAIT/TPAUSE insns */ /* SEFF EDX bits */ #define SEFF0EDX_AVX512_4FNNIW 0x00000004 /* AVX-512 neural network insns */ #define SEFF0EDX_AVX512_4FMAPS 0x00000008 /* AVX-512 mult accum single prec */ diff --git a/sys/arch/amd64/include/vmmvar.h b/sys/arch/amd64/include/vmmvar.h index 6b4802abf4b..7897c777fc5 100644 --- a/sys/arch/amd64/include/vmmvar.h +++ b/sys/arch/amd64/include/vmmvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vmmvar.h,v 1.85 2022/12/26 23:50:20 dv Exp $ */ +/* $OpenBSD: vmmvar.h,v 1.86 2023/01/10 01:09:14 dv Exp $ */ /* * Copyright (c) 2014 Mike Larkin * @@ -672,7 +672,9 @@ struct vm_mprotect_ept_params { SEFF0EBX_AVX512IFMA | SEFF0EBX_AVX512PF | \ SEFF0EBX_AVX512ER | SEFF0EBX_AVX512CD | \ SEFF0EBX_AVX512BW | SEFF0EBX_AVX512VL) -#define VMM_SEFF0ECX_MASK ~(SEFF0ECX_AVX512VBMI) + +/* ECX mask contains the bits to include */ +#define VMM_SEFF0ECX_MASK (SEFF0ECX_PREFETCHWT1 | SEFF0ECX_UMIP | SEFF0ECX_PKU) /* EDX mask contains the bits to include */ #define VMM_SEFF0EDX_MASK (SEFF0EDX_MD_CLEAR) diff --git a/sys/arch/i386/i386/machdep.c b/sys/arch/i386/i386/machdep.c index 708893b00fc..43ab1828d48 100644 --- a/sys/arch/i386/i386/machdep.c +++ b/sys/arch/i386/i386/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.660 2023/01/10 01:01:18 cheloha Exp $ */ +/* $OpenBSD: machdep.c,v 1.661 2023/01/10 01:09:14 dv Exp $ */ /* $NetBSD: machdep.c,v 1.214 1996/11/10 03:16:17 thorpej Exp $ */ /*- @@ -1038,6 +1038,7 @@ const struct cpu_cpuid_feature cpu_seff0_ecxfeatures[] = { { SEFF0ECX_UMIP, "UMIP" }, { SEFF0ECX_AVX512VBMI, "AVX512VBMI" }, { SEFF0ECX_PKU, "PKU" }, + { SEFF0ECX_WAITPKG, "WAITPKG" }, }; const struct cpu_cpuid_feature cpu_seff0_edxfeatures[] = { diff --git a/sys/arch/i386/include/specialreg.h b/sys/arch/i386/include/specialreg.h index 392b4ff412e..22ee7abbae7 100644 --- a/sys/arch/i386/include/specialreg.h +++ b/sys/arch/i386/include/specialreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: specialreg.h,v 1.80 2022/08/20 23:33:53 daniel Exp $ */ +/* $OpenBSD: specialreg.h,v 1.81 2023/01/10 01:09:14 dv Exp $ */ /* $NetBSD: specialreg.h,v 1.7 1994/10/27 04:16:26 cgd Exp $ */ /*- @@ -190,6 +190,7 @@ #define SEFF0ECX_AVX512VBMI 0x00000002 /* AVX-512 vector bit inst */ #define SEFF0ECX_UMIP 0x00000004 /* UMIP support */ #define SEFF0ECX_PKU 0x00000008 /* Page prot keys for user mode */ +#define SEFF0ECX_WAITPKG 0x00000010 /* UMONITOR/UMWAIT/TPAUSE insns */ /* SEFF EDX bits */ #define SEFF0EDX_AVX512_4FNNIW 0x00000004 /* AVX-512 neural network insns */ #define SEFF0EDX_AVX512_4FMAPS 0x00000008 /* AVX-512 mult accum single prec */