Sun Jan 22 19:42:48 2017 UTC ()
Import xpmap_pg_nx, and put it in the per-cpu recursive slot on amd64.


(maxv)
diff -r1.105 -r1.106 src/sys/arch/xen/x86/cpu.c

cvs diff -r1.105 -r1.106 src/sys/arch/xen/x86/cpu.c (expand / switch to unified diff)

--- src/sys/arch/xen/x86/cpu.c 2016/11/25 12:20:03 1.105
+++ src/sys/arch/xen/x86/cpu.c 2017/01/22 19:42:48 1.106
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: cpu.c,v 1.105 2016/11/25 12:20:03 maxv Exp $ */ 1/* $NetBSD: cpu.c,v 1.106 2017/01/22 19:42:48 maxv Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi, 5 * Copyright (c) 2002, 2006, 2007 YAMAMOTO Takashi,
6 * All rights reserved. 6 * All rights reserved.
7 * 7 *
8 * This code is derived from software contributed to The NetBSD Foundation 8 * This code is derived from software contributed to The NetBSD Foundation
9 * by RedBack Networks Inc. 9 * by RedBack Networks Inc.
10 * 10 *
11 * Author: Bill Sommerfeld 11 * Author: Bill Sommerfeld
12 * 12 *
13 * Redistribution and use in source and binary forms, with or without 13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions 14 * modification, are permitted provided that the following conditions
@@ -55,27 +55,27 @@ @@ -55,27 +55,27 @@
55 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE 57 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE. 64 * SUCH DAMAGE.
65 */ 65 */
66 66
67#include <sys/cdefs.h> 67#include <sys/cdefs.h>
68__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.105 2016/11/25 12:20:03 maxv Exp $"); 68__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.106 2017/01/22 19:42:48 maxv Exp $");
69 69
70#include "opt_ddb.h" 70#include "opt_ddb.h"
71#include "opt_multiprocessor.h" 71#include "opt_multiprocessor.h"
72#include "opt_mpbios.h" /* for MPDEBUG */ 72#include "opt_mpbios.h" /* for MPDEBUG */
73#include "opt_mtrr.h" 73#include "opt_mtrr.h"
74#include "opt_xen.h" 74#include "opt_xen.h"
75 75
76#include "lapic.h" 76#include "lapic.h"
77#include "ioapic.h" 77#include "ioapic.h"
78 78
79#include <sys/param.h> 79#include <sys/param.h>
80#include <sys/proc.h> 80#include <sys/proc.h>
81#include <sys/systm.h> 81#include <sys/systm.h>
@@ -1208,40 +1208,39 @@ pmap_cpu_init_late(struct cpu_info *ci) @@ -1208,40 +1208,39 @@ pmap_cpu_init_late(struct cpu_info *ci)
1208#endif /* PAE */ 1208#endif /* PAE */
1209 1209
1210 ci->ci_kpm_pdir = (pd_entry_t *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0, 1210 ci->ci_kpm_pdir = (pd_entry_t *)uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
1211 UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_NOWAIT); 1211 UVM_KMF_WIRED | UVM_KMF_ZERO | UVM_KMF_NOWAIT);
1212 1212
1213 if (ci->ci_kpm_pdir == NULL) { 1213 if (ci->ci_kpm_pdir == NULL) {
1214 panic("%s: failed to allocate L4 per-cpu PD for CPU %d\n", 1214 panic("%s: failed to allocate L4 per-cpu PD for CPU %d\n",
1215 __func__, cpu_index(ci)); 1215 __func__, cpu_index(ci));
1216 } 1216 }
1217 ci->ci_kpm_pdirpa = vtophys((vaddr_t)ci->ci_kpm_pdir); 1217 ci->ci_kpm_pdirpa = vtophys((vaddr_t)ci->ci_kpm_pdir);
1218 KASSERT(ci->ci_kpm_pdirpa != 0); 1218 KASSERT(ci->ci_kpm_pdirpa != 0);
1219 1219
1220#if defined(__x86_64__) 1220#if defined(__x86_64__)
1221 /* 1221 extern pt_entry_t xpmap_pg_nx;
1222 * Copy over the pmap_kernel() shadow L4 entries  
1223 */ 
1224 1222
 1223 /* Copy over the pmap_kernel() shadow L4 entries */
1225 memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir, PAGE_SIZE); 1224 memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir, PAGE_SIZE);
1226 1225
1227 /* Recursive kernel mapping */ 1226 /* Recursive kernel mapping */
1228 ci->ci_kpm_pdir[PDIR_SLOT_PTE] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) 1227 ci->ci_kpm_pdir[PDIR_SLOT_PTE] = xpmap_ptom_masked(ci->ci_kpm_pdirpa)
1229 | PG_k | PG_V; 1228 | PG_k | PG_V | xpmap_pg_nx;
1230#elif defined(PAE) 1229#elif defined(PAE)
1231 /* Copy over the pmap_kernel() shadow L2 entries that map the kernel */ 1230 /* Copy over the pmap_kernel() shadow L2 entries */
1232 memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir + PDIR_SLOT_KERN, 1231 memcpy(ci->ci_kpm_pdir, pmap_kernel()->pm_pdir + PDIR_SLOT_KERN,
1233 nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t)); 1232 nkptp[PTP_LEVELS - 1] * sizeof(pd_entry_t));
1234#endif /* __x86_64__ else PAE */ 1233#endif
1235 1234
1236 /* Xen wants a RO pdir. */ 1235 /* Xen wants a RO pdir. */
1237 pmap_protect(pmap_kernel(), (vaddr_t)ci->ci_kpm_pdir, 1236 pmap_protect(pmap_kernel(), (vaddr_t)ci->ci_kpm_pdir,
1238 (vaddr_t)ci->ci_kpm_pdir + PAGE_SIZE, VM_PROT_READ); 1237 (vaddr_t)ci->ci_kpm_pdir + PAGE_SIZE, VM_PROT_READ);
1239 pmap_update(pmap_kernel()); 1238 pmap_update(pmap_kernel());
1240#if defined(PAE) 1239#if defined(PAE)
1241 /* 1240 /*
1242 * Initialize L3 entry 3. This mapping is shared across all pmaps and is 1241 * Initialize L3 entry 3. This mapping is shared across all pmaps and is
1243 * static, ie: loading a new pmap will not update this entry. 1242 * static, ie: loading a new pmap will not update this entry.
1244 */ 1243 */
1245 ci->ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) | PG_k | PG_V; 1244 ci->ci_pae_l3_pdir[3] = xpmap_ptom_masked(ci->ci_kpm_pdirpa) | PG_k | PG_V;
1246 1245
1247 /* Xen wants a RO L3. */ 1246 /* Xen wants a RO L3. */