Wed Aug 26 16:29:20 2020 UTC ()
nvmm-x86-svm: don't forget to intercept INVD

INVD executed in the guest can be dangerous for the host, due to CPU
caches being flushed without write-back.


(maxv)
diff -r1.71 -r1.72 src/sys/dev/nvmm/x86/nvmm_x86_svm.c

cvs diff -r1.71 -r1.72 src/sys/dev/nvmm/x86/nvmm_x86_svm.c (expand / switch to unified diff)

--- src/sys/dev/nvmm/x86/nvmm_x86_svm.c 2020/08/22 10:59:05 1.71
+++ src/sys/dev/nvmm/x86/nvmm_x86_svm.c 2020/08/26 16:29:19 1.72
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: nvmm_x86_svm.c,v 1.71 2020/08/22 10:59:05 maxv Exp $ */ 1/* $NetBSD: nvmm_x86_svm.c,v 1.72 2020/08/26 16:29:19 maxv Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2018-2020 The NetBSD Foundation, Inc. 4 * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Maxime Villard. 8 * by Maxime Villard.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -20,27 +20,27 @@ @@ -20,27 +20,27 @@
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.71 2020/08/22 10:59:05 maxv Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: nvmm_x86_svm.c,v 1.72 2020/08/26 16:29:19 maxv Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/kernel.h> 37#include <sys/kernel.h>
38#include <sys/kmem.h> 38#include <sys/kmem.h>
39#include <sys/cpu.h> 39#include <sys/cpu.h>
40#include <sys/xcall.h> 40#include <sys/xcall.h>
41#include <sys/mman.h> 41#include <sys/mman.h>
42 42
43#include <uvm/uvm.h> 43#include <uvm/uvm.h>
44#include <uvm/uvm_page.h> 44#include <uvm/uvm_page.h>
45 45
46#include <x86/cputypes.h> 46#include <x86/cputypes.h>
@@ -2108,40 +2108,40 @@ svm_vcpu_init(struct nvmm_machine *mach, @@ -2108,40 +2108,40 @@ svm_vcpu_init(struct nvmm_machine *mach,
2108 * - RIDTR [reads of IDTR] 2108 * - RIDTR [reads of IDTR]
2109 * - RGDTR [reads of GDTR] 2109 * - RGDTR [reads of GDTR]
2110 * - RLDTR [reads of LDTR] 2110 * - RLDTR [reads of LDTR]
2111 * - RTR [reads of TR] 2111 * - RTR [reads of TR]
2112 * - WIDTR [writes of IDTR] 2112 * - WIDTR [writes of IDTR]
2113 * - WGDTR [writes of GDTR] 2113 * - WGDTR [writes of GDTR]
2114 * - WLDTR [writes of LDTR] 2114 * - WLDTR [writes of LDTR]
2115 * - WTR [writes of TR] 2115 * - WTR [writes of TR]
2116 * - RDTSC [rdtsc instruction] 2116 * - RDTSC [rdtsc instruction]
2117 * - PUSHF [pushf instruction] 2117 * - PUSHF [pushf instruction]
2118 * - POPF [popf instruction] 2118 * - POPF [popf instruction]
2119 * - IRET [iret instruction] 2119 * - IRET [iret instruction]
2120 * - INTN [int $n instructions] 2120 * - INTN [int $n instructions]
2121 * - INVD [invd instruction] 
2122 * - PAUSE [pause instruction] 2121 * - PAUSE [pause instruction]
2123 * - INVLPG [invplg instruction] 2122 * - INVLPG [invplg instruction]
2124 * - TASKSW [task switches] 2123 * - TASKSW [task switches]
2125 * 2124 *
2126 * Intercept the rest below. 2125 * Intercept the rest below.
2127 */ 2126 */
2128 vmcb->ctrl.intercept_misc1 = 2127 vmcb->ctrl.intercept_misc1 =
2129 VMCB_CTRL_INTERCEPT_INTR | 2128 VMCB_CTRL_INTERCEPT_INTR |
2130 VMCB_CTRL_INTERCEPT_NMI | 2129 VMCB_CTRL_INTERCEPT_NMI |
2131 VMCB_CTRL_INTERCEPT_INIT | 2130 VMCB_CTRL_INTERCEPT_INIT |
2132 VMCB_CTRL_INTERCEPT_RDPMC | 2131 VMCB_CTRL_INTERCEPT_RDPMC |
2133 VMCB_CTRL_INTERCEPT_CPUID | 2132 VMCB_CTRL_INTERCEPT_CPUID |
2134 VMCB_CTRL_INTERCEPT_RSM | 2133 VMCB_CTRL_INTERCEPT_RSM |
 2134 VMCB_CTRL_INTERCEPT_INVD |
2135 VMCB_CTRL_INTERCEPT_HLT | 2135 VMCB_CTRL_INTERCEPT_HLT |
2136 VMCB_CTRL_INTERCEPT_INVLPGA | 2136 VMCB_CTRL_INTERCEPT_INVLPGA |
2137 VMCB_CTRL_INTERCEPT_IOIO_PROT | 2137 VMCB_CTRL_INTERCEPT_IOIO_PROT |
2138 VMCB_CTRL_INTERCEPT_MSR_PROT | 2138 VMCB_CTRL_INTERCEPT_MSR_PROT |
2139 VMCB_CTRL_INTERCEPT_FERR_FREEZE | 2139 VMCB_CTRL_INTERCEPT_FERR_FREEZE |
2140 VMCB_CTRL_INTERCEPT_SHUTDOWN; 2140 VMCB_CTRL_INTERCEPT_SHUTDOWN;
2141 2141
2142 /* 2142 /*
2143 * Allow: 2143 * Allow:
2144 * - ICEBP [icebp instruction] 2144 * - ICEBP [icebp instruction]
2145 * - WBINVD [wbinvd instruction] 2145 * - WBINVD [wbinvd instruction]
2146 * - WCR_SPEC(0..15) [writes of CR0-15, received after instruction] 2146 * - WCR_SPEC(0..15) [writes of CR0-15, received after instruction]
2147 * 2147 *