Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Map the boot IDT, GDT and LDT in three different pa...



details:   https://anonhg.NetBSD.org/src/rev/6adc99cbc593
branches:  trunk
changeset: 817627:6adc99cbc593
user:      maxv <maxv%NetBSD.org@localhost>
date:      Sat Aug 27 16:07:26 2016 +0000

description:
Map the boot IDT, GDT and LDT in three different pages on x86. It is much
better this way, and it reduces the diff between x86 and Xen. Also, zero
them properly, otherwise we might end up with garbage in several slots.

diffstat:

 sys/arch/amd64/amd64/machdep.c |  29 ++++++++++++++---------------
 sys/arch/i386/i386/machdep.c   |  20 ++++++++++++++------
 sys/arch/x86/x86/pmap.c        |  34 +++++++++++++++++-----------------
 3 files changed, 45 insertions(+), 38 deletions(-)

diffs (205 lines):

diff -r be2f29761db1 -r 6adc99cbc593 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Sat Aug 27 14:36:22 2016 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Sat Aug 27 16:07:26 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.228 2016/08/27 14:19:47 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.229 2016/08/27 16:07:26 maxv Exp $       */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.228 2016/08/27 14:19:47 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.229 2016/08/27 16:07:26 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -262,6 +262,10 @@
 
 vaddr_t idt_vaddr;
 paddr_t idt_paddr;
+vaddr_t gdt_vaddr;
+paddr_t gdt_paddr;
+vaddr_t ldt_vaddr;
+paddr_t ldt_paddr;
 
 vaddr_t module_start, module_end;
 static struct vm_map module_map_store;
@@ -1624,32 +1628,27 @@
        kpreempt_disable();
 
        pmap_kenter_pa(idt_vaddr, idt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
+       pmap_kenter_pa(gdt_vaddr, gdt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
+       pmap_kenter_pa(ldt_vaddr, ldt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
        pmap_update(pmap_kernel());
        memset((void *)idt_vaddr, 0, PAGE_SIZE);
+       memset((void *)gdt_vaddr, 0, PAGE_SIZE);
+       memset((void *)ldt_vaddr, 0, PAGE_SIZE);
 
 #ifndef XEN
        pmap_changeprot_local(idt_vaddr, VM_PROT_READ);
 #endif
-       pmap_kenter_pa(idt_vaddr + PAGE_SIZE, idt_paddr + PAGE_SIZE,
-           VM_PROT_READ|VM_PROT_WRITE, 0);
-#ifdef XEN
-       /* Steal one more page for LDT */
-       pmap_kenter_pa(idt_vaddr + 2 * PAGE_SIZE, idt_paddr + 2 * PAGE_SIZE,
-           VM_PROT_READ|VM_PROT_WRITE, 0);
-#endif
+
        pmap_update(pmap_kernel());
 
 #ifndef XEN
        idt = (struct gate_descriptor *)idt_vaddr;
-       gdtstore = (char *)(idt + NIDT);
-       ldtstore = gdtstore + DYNSEL_START;
 #else
        xen_idt = (struct trap_info *)idt_vaddr;
        xen_idt_idx = 0;
-       /* Xen wants page aligned GDT/LDT in separated pages */
-       ldtstore = (char *) roundup((vaddr_t) (xen_idt + NIDT), PAGE_SIZE);
-       gdtstore = (char *) (ldtstore + PAGE_SIZE);
-#endif /* XEN */
+#endif
+       gdtstore = (char *)gdt_vaddr;
+       ldtstore = (char *)ldt_vaddr;
 
        /*
         * Make GDT gates and memory segments.
diff -r be2f29761db1 -r 6adc99cbc593 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Sat Aug 27 14:36:22 2016 +0000
+++ b/sys/arch/i386/i386/machdep.c      Sat Aug 27 16:07:26 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.760 2016/08/27 14:19:47 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.761 2016/08/27 16:07:26 maxv Exp $       */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.760 2016/08/27 14:19:47 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.761 2016/08/27 16:07:26 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -243,6 +243,11 @@
 
 vaddr_t idt_vaddr;
 paddr_t idt_paddr;
+vaddr_t gdt_vaddr;
+paddr_t gdt_paddr;
+vaddr_t ldt_vaddr;
+paddr_t ldt_paddr;
+
 vaddr_t pentium_idt_vaddr;
 
 struct vm_map *phys_map = NULL;
@@ -1300,19 +1305,22 @@
 #endif /* !XEN */
 
        pmap_kenter_pa(idt_vaddr, idt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
+       pmap_kenter_pa(gdt_vaddr, gdt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
+       pmap_kenter_pa(ldt_vaddr, ldt_paddr, VM_PROT_READ|VM_PROT_WRITE, 0);
        pmap_update(pmap_kernel());
        memset((void *)idt_vaddr, 0, PAGE_SIZE);
+       memset((void *)gdt_vaddr, 0, PAGE_SIZE);
+       memset((void *)ldt_vaddr, 0, PAGE_SIZE);
 
 #ifndef XEN
-       idt = (struct gate_descriptor *)idt_vaddr;
        pmap_kenter_pa(pentium_idt_vaddr, idt_paddr, VM_PROT_READ, 0);
        pmap_update(pmap_kernel());
        pentium_idt = (union descriptor *)pentium_idt_vaddr;
 
        tgdt = gdt;
-       gdt = (union descriptor *)
-                   ((char *)idt + NIDT * sizeof(struct gate_descriptor));
-       ldt = gdt + NGDT;
+       idt = (struct gate_descriptor *)idt_vaddr;
+       gdt = (union descriptor *)gdt_vaddr;
+       ldt = (union descriptor *)ldt_vaddr;
 
        memcpy(gdt, tgdt, NGDT * sizeof(*gdt));
 
diff -r be2f29761db1 -r 6adc99cbc593 sys/arch/x86/x86/pmap.c
--- a/sys/arch/x86/x86/pmap.c   Sat Aug 27 14:36:22 2016 +0000
+++ b/sys/arch/x86/x86/pmap.c   Sat Aug 27 16:07:26 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.220 2016/08/19 18:24:57 maxv Exp $  */
+/*     $NetBSD: pmap.c,v 1.221 2016/08/27 16:07:26 maxv Exp $  */
 
 /*-
  * Copyright (c) 2008, 2010, 2016 The NetBSD Foundation, Inc.
@@ -171,7 +171,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.220 2016/08/19 18:24:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.221 2016/08/27 16:07:26 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -538,6 +538,10 @@
 
 extern vaddr_t idt_vaddr;
 extern paddr_t idt_paddr;
+extern vaddr_t gdt_vaddr;
+extern paddr_t gdt_paddr;
+extern vaddr_t ldt_vaddr;
+extern paddr_t ldt_paddr;
 
 extern int end;
 
@@ -1389,8 +1393,7 @@
        }
 #endif
 
-#ifdef XEN
-#ifdef __x86_64__
+#if defined(XEN) && defined(__x86_64__)
        /*
         * We want a dummy page directory for Xen: when deactivating a pmap, Xen
         * will still consider it active. So we set user PGD to this one to lift
@@ -1405,28 +1408,25 @@
            pmap_pa2pte(xen_dummy_user_pgd) | PG_u | PG_V, UVMF_INVLPG);
        /* Pin as L4 */
        xpq_queue_pin_l4_table(xpmap_ptom_masked(xen_dummy_user_pgd));
-#endif /* __x86_64__ */
+#endif
+
        /*
-        * Xen requires one more page as we can't store GDT and LDT on the same
-        * page.
+        * Allocate space for the IDT, GDT and LDT.
         */
-       idt_vaddr = pmap_bootstrap_valloc(3);
-       idt_paddr = pmap_bootstrap_palloc(3);
-#else /* XEN */
-
-#if defined(__x86_64__)
-       idt_vaddr = pmap_bootstrap_valloc(2);
-       idt_paddr = pmap_bootstrap_palloc(2);
-#else
        idt_vaddr = pmap_bootstrap_valloc(1);
        idt_paddr = pmap_bootstrap_palloc(1);
 
+       gdt_vaddr = pmap_bootstrap_valloc(1);
+       gdt_paddr = pmap_bootstrap_palloc(1);
+
+       ldt_vaddr = pmap_bootstrap_valloc(1);
+       ldt_paddr = pmap_bootstrap_palloc(1);
+
+#if !defined(__x86_64__) && !defined(XEN)
        /* pentium f00f bug stuff */
        pentium_idt_vaddr = pmap_bootstrap_valloc(1);
 #endif
 
-#endif /* XEN */
-
        /*
         * Now we reserve some VM for mapping pages when doing a crash dump.
         */



Home | Main Index | Thread Index | Old Index