| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: gdt.c,v 1.64 2017/07/02 11:21:13 maxv Exp $ */ | | 1 | /* $NetBSD: gdt.c,v 1.65 2017/07/06 20:23:57 bouyer Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 1996, 1997, 2009 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 John T. Kohl, by Charles M. Hannum, and by Andrew Doran. | | 8 | * by John T. Kohl, by Charles M. Hannum, and by Andrew Doran. |
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: gdt.c,v 1.64 2017/07/02 11:21:13 maxv Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.65 2017/07/06 20:23:57 bouyer Exp $"); |
34 | | | 34 | |
35 | #include "opt_multiprocessor.h" | | 35 | #include "opt_multiprocessor.h" |
36 | #include "opt_xen.h" | | 36 | #include "opt_xen.h" |
37 | | | 37 | |
38 | #include <sys/param.h> | | 38 | #include <sys/param.h> |
39 | #include <sys/systm.h> | | 39 | #include <sys/systm.h> |
40 | #include <sys/proc.h> | | 40 | #include <sys/proc.h> |
41 | #include <sys/mutex.h> | | 41 | #include <sys/mutex.h> |
42 | #include <sys/cpu.h> | | 42 | #include <sys/cpu.h> |
43 | | | 43 | |
44 | #include <uvm/uvm.h> | | 44 | #include <uvm/uvm.h> |
45 | | | 45 | |
46 | #include <machine/gdt.h> | | 46 | #include <machine/gdt.h> |
| @@ -192,51 +192,52 @@ gdt_alloc_cpu(struct cpu_info *ci) | | | @@ -192,51 +192,52 @@ gdt_alloc_cpu(struct cpu_info *ci) |
192 | * be ci. | | 192 | * be ci. |
193 | */ | | 193 | */ |
194 | void | | 194 | void |
195 | gdt_init_cpu(struct cpu_info *ci) | | 195 | gdt_init_cpu(struct cpu_info *ci) |
196 | { | | 196 | { |
197 | #ifndef XEN | | 197 | #ifndef XEN |
198 | struct region_descriptor region; | | 198 | struct region_descriptor region; |
199 | size_t max_len; | | 199 | size_t max_len; |
200 | | | 200 | |
201 | max_len = MAXGDTSIZ; | | 201 | max_len = MAXGDTSIZ; |
202 | setregion(®ion, ci->ci_gdt, max_len - 1); | | 202 | setregion(®ion, ci->ci_gdt, max_len - 1); |
203 | lgdt(®ion); | | 203 | lgdt(®ion); |
204 | #else | | 204 | #else |
205 | size_t len = gdt_size; | | 205 | size_t len = roundup(gdt_size, PAGE_SIZE); |
206 | unsigned long frames[len >> PAGE_SHIFT]; | | 206 | unsigned long frames[len >> PAGE_SHIFT]; |
207 | vaddr_t va; | | 207 | vaddr_t va; |
208 | pt_entry_t *ptp; | | 208 | pt_entry_t *ptp; |
209 | size_t f; | | 209 | size_t f; |
210 | | | 210 | |
211 | for (va = (vaddr_t)ci->ci_gdt, f = 0; va < (vaddr_t)ci->ci_gdt + len; | | 211 | for (va = (vaddr_t)ci->ci_gdt, f = 0; |
| | | 212 | va < (vaddr_t)ci->ci_gdt + gdt_size; |
212 | va += PAGE_SIZE, f++) { | | 213 | va += PAGE_SIZE, f++) { |
213 | KASSERT(va >= VM_MIN_KERNEL_ADDRESS); | | 214 | KASSERT(va >= VM_MIN_KERNEL_ADDRESS); |
214 | ptp = kvtopte(va); | | 215 | ptp = kvtopte(va); |
215 | frames[f] = *ptp >> PAGE_SHIFT; | | 216 | frames[f] = *ptp >> PAGE_SHIFT; |
216 | | | 217 | |
217 | /* | | 218 | /* |
218 | * Our own | | 219 | * Our own |
219 | * pmap_pte_clearbits(ptp, PG_RW) | | 220 | * pmap_pte_clearbits(ptp, PG_RW) |
220 | * but without spl(), since %fs is not set up properly yet; ie | | 221 | * but without spl(), since %fs is not set up properly yet; ie |
221 | * curcpu() won't work at this point and spl() will break. | | 222 | * curcpu() won't work at this point and spl() will break. |
222 | */ | | 223 | */ |
223 | if (HYPERVISOR_update_va_mapping((vaddr_t)va, | | 224 | if (HYPERVISOR_update_va_mapping((vaddr_t)va, |
224 | *ptp & ~PG_RW, UVMF_INVLPG) < 0) { | | 225 | *ptp & ~PG_RW, UVMF_INVLPG) < 0) { |
225 | panic("%s page RO update failed.\n", __func__); | | 226 | panic("%s page RO update failed.\n", __func__); |
226 | } | | 227 | } |
227 | } | | 228 | } |
228 | | | 229 | |
229 | if (HYPERVISOR_set_gdt(frames, gdt_size)) | | 230 | if (HYPERVISOR_set_gdt(frames, gdt_size / sizeof(gdtstore[0]))) |
230 | panic("HYPERVISOR_set_gdt failed!\n"); | | 231 | panic("HYPERVISOR_set_gdt failed!\n"); |
231 | lgdt_finish(); | | 232 | lgdt_finish(); |
232 | #endif | | 233 | #endif |
233 | } | | 234 | } |
234 | | | 235 | |
235 | #ifndef XEN | | 236 | #ifndef XEN |
236 | /* | | 237 | /* |
237 | * Grow the GDT. The GDT is present on each CPU, so we need to iterate over all | | 238 | * Grow the GDT. The GDT is present on each CPU, so we need to iterate over all |
238 | * of them. We already have the virtual memory, we only need to grow the | | 239 | * of them. We already have the virtual memory, we only need to grow the |
239 | * physical memory. | | 240 | * physical memory. |
240 | */ | | 241 | */ |
241 | static void | | 242 | static void |
242 | gdt_grow(void) | | 243 | gdt_grow(void) |