Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/nvmm/x86 nvmm: Filter CR4 bits on x86 SVM (AMD).



details:   https://anonhg.NetBSD.org/src/rev/3d544f0b0ee2
branches:  trunk
changeset: 373649:3d544f0b0ee2
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Feb 23 02:54:02 2023 +0000

description:
nvmm: Filter CR4 bits on x86 SVM (AMD).

In particular, prohibit PKE, Protection Key Enable, which requires
some additional management of CPU state by nvmm.

diffstat:

 sys/dev/nvmm/x86/nvmm_x86_svm.c |  32 ++++++++++++++++++++++++++++++--
 1 files changed, 30 insertions(+), 2 deletions(-)

diffs (60 lines):

diff -r 8b5207b1cc17 -r 3d544f0b0ee2 sys/dev/nvmm/x86/nvmm_x86_svm.c
--- a/sys/dev/nvmm/x86/nvmm_x86_svm.c   Thu Feb 23 02:48:06 2023 +0000
+++ b/sys/dev/nvmm/x86/nvmm_x86_svm.c   Thu Feb 23 02:54:02 2023 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nvmm_x86_svm.c,v 1.84 2022/08/20 23:48:51 riastradh Exp $      */
+/*     $NetBSD: nvmm_x86_svm.c,v 1.85 2023/02/23 02:54:02 riastradh Exp $      */
 
 /*
  * Copyright (c) 2018-2020 Maxime Villard, m00nbsd.net
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.84 2022/08/20 23:48:51 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.85 2023/02/23 02:54:02 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -523,6 +523,33 @@
 #define CR4_TLB_FLUSH \
        (CR4_PSE|CR4_PAE|CR4_PGE|CR4_PCIDE|CR4_SMEP)
 
+#define CR4_VALID \
+       (CR4_VME |                      \
+        CR4_PVI |                      \
+        CR4_TSD |                      \
+        CR4_DE |                       \
+        CR4_PSE |                      \
+        CR4_PAE |                      \
+        CR4_MCE |                      \
+        CR4_PGE |                      \
+        CR4_PCE |                      \
+        CR4_OSFXSR |                   \
+        CR4_OSXMMEXCPT |               \
+        CR4_UMIP |                     \
+        /* CR4_LA57 excluded */        \
+        /* bit 13 reserved on AMD */   \
+        /* bit 14 reserved on AMD */   \
+        /* bit 15 reserved on AMD */   \
+        CR4_FSGSBASE |                 \
+        CR4_PCIDE |                    \
+        CR4_OSXSAVE |                  \
+        /* bit 19 reserved on AMD */   \
+        CR4_SMEP |                     \
+        CR4_SMAP                       \
+        /* CR4_PKE excluded */         \
+        /* CR4_CET excluded */         \
+        /* bits 24:63 reserved on AMD */)
+
 /* -------------------------------------------------------------------------- */
 
 struct svm_machdata {
@@ -1853,6 +1880,7 @@
                vmcb->state.cr2 = state->crs[NVMM_X64_CR_CR2];
                vmcb->state.cr3 = state->crs[NVMM_X64_CR_CR3];
                vmcb->state.cr4 = state->crs[NVMM_X64_CR_CR4];
+               vmcb->state.cr4 &= CR4_VALID;
 
                vmcb->ctrl.v &= ~VMCB_CTRL_V_TPR;
                vmcb->ctrl.v |= __SHIFTIN(state->crs[NVMM_X64_CR_CR8],



Home | Main Index | Thread Index | Old Index