Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Make XEN use the same api as native, for idt vector...



details:   https://anonhg.NetBSD.org/src/rev/9384dc6a1b27
branches:  trunk
changeset: 433589:9384dc6a1b27
user:      cherry <cherry%NetBSD.org@localhost>
date:      Sun Sep 23 00:59:59 2018 +0000

description:
Make XEN use the same api as native, for idt vector allocation
and registration.

lidt() placed in xenfunc() on maxv@ suggestion.

There should be no functional change due to this commit.

Tested on amd64 native and XEN.

diffstat:

 sys/arch/amd64/amd64/db_interface.c |   6 +-
 sys/arch/amd64/amd64/machdep.c      |  79 ++++++++----------------------
 sys/arch/amd64/include/segments.h   |  11 ++-
 sys/arch/i386/i386/machdep.c        |  83 +++++++++++---------------------
 sys/arch/i386/include/segments.h    |  11 +++-
 sys/arch/x86/x86/idt.c              |  93 +++++++++++++++++++++++++++++++-----
 sys/arch/x86/x86/lapic.c            |   6 +-
 sys/arch/xen/x86/xenfunc.c          |  44 ++++++++++++++++-
 8 files changed, 196 insertions(+), 137 deletions(-)

diffs (truncated from 618 to 300 lines):

diff -r bc0970c6efcf -r 9384dc6a1b27 sys/arch/amd64/amd64/db_interface.c
--- a/sys/arch/amd64/amd64/db_interface.c       Sat Sep 22 17:13:30 2018 +0000
+++ b/sys/arch/amd64/amd64/db_interface.c       Sun Sep 23 00:59:59 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: db_interface.c,v 1.33 2018/04/03 07:20:52 christos Exp $       */
+/*     $NetBSD: db_interface.c,v 1.34 2018/09/23 00:59:59 cherry Exp $ */
 
 /*
  * Mach Operating System
@@ -33,7 +33,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.33 2018/04/03 07:20:52 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: db_interface.c,v 1.34 2018/09/23 00:59:59 cherry Exp $");
 
 #include "opt_ddb.h"
 #include "opt_multiprocessor.h"
@@ -113,7 +113,7 @@
                handler = &Xintr_x2apic_ddbipi;
 #endif
        ddb_vec = idt_vec_alloc(0xf0, 0xff);
-       setgate(&idt[ddb_vec], handler, 1, SDT_SYS386IGT, SEL_KPL,
+       set_idtgate(&idt[ddb_vec], handler, 1, SDT_SYS386IGT, SEL_KPL,
            GSEL(GCODE_SEL, SEL_KPL));
 #else
        /* Initialised as part of xen_ipi_init() */
diff -r bc0970c6efcf -r 9384dc6a1b27 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Sat Sep 22 17:13:30 2018 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Sun Sep 23 00:59:59 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.318 2018/08/29 16:26:25 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.319 2018/09/23 00:59:59 cherry Exp $     */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -110,7 +110,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.318 2018/08/29 16:26:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.319 2018/09/23 00:59:59 cherry Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -1397,11 +1397,6 @@
 /*
  * Initialize segments and descriptor tables
  */
-
-#ifdef XEN
-struct trap_info *xen_idt;
-int xen_idt_idx;
-#endif
 char *ldtstore;
 char *gdtstore;
 
@@ -1486,15 +1481,10 @@
 void
 cpu_init_idt(void)
 {
-#ifndef XEN
        struct region_descriptor region;
 
        setregion(&region, idt, NIDT * sizeof(idt[0]) - 1);
        lidt(&region);
-#else
-       if (HYPERVISOR_set_trap_table(xen_idt))
-               panic("HYPERVISOR_set_trap_table() failed");
-#endif
 }
 
 #define        IDTVEC(name)    __CONCAT(X, name)
@@ -1681,7 +1671,6 @@
        extern vaddr_t lwp0uarea;
 #ifndef XEN
        extern paddr_t local_apic_pa;
-       int ist;
 #endif
 
        KASSERT(first_avail % PAGE_SIZE == 0);
@@ -1806,12 +1795,7 @@
 
        pmap_update(pmap_kernel());
 
-#ifndef XEN
-       idt = (struct gate_descriptor *)idt_vaddr;
-#else
-       xen_idt = (struct trap_info *)idt_vaddr;
-       xen_idt_idx = 0;
-#endif
+       idt = (idt_descriptor_t *)idt_vaddr;
        gdtstore = (char *)gdt_vaddr;
        ldtstore = (char *)ldt_vaddr;
 
@@ -1870,8 +1854,14 @@
 
        /* CPU-specific IDT exceptions. */
        for (x = 0; x < NCPUIDT; x++) {
-#ifndef XEN
+               int sel, ist;
+
+               /* Reset to default. Special cases below */
+               sel = SEL_KPL;
+               ist = 0;
+
                idt_vec_reserve(x);
+
                switch (x) {
                case 1: /* DB */
                        ist = 4;
@@ -1879,56 +1869,31 @@
                case 2: /* NMI */
                        ist = 3;
                        break;
+               case 3:
+               case 4:                 
+                       sel = SEL_UPL;
+                       break;
                case 8: /* double fault */
                        ist = 2;
                        break;
-               default:
-                       ist = 0;
+#ifdef XEN                     
+               case 18: /* MCA */
+                       sel |= 0x4; /* Auto EOI/mask */
                        break;
-               }
-               setgate(&idt[x], x86_exceptions[x], ist, SDT_SYS386IGT,
-                   (x == 3 || x == 4) ? SEL_UPL : SEL_KPL,
-                   GSEL(GCODE_SEL, SEL_KPL));
-#else /* XEN */
-               pmap_changeprot_local(idt_vaddr, VM_PROT_READ|VM_PROT_WRITE);
-               idt_vec_reserve(x);
-               xen_idt[xen_idt_idx].vector = x;
-
-               switch (x) {
-               case 2:  /* NMI */
-               case 18: /* MCA */
-                       TI_SET_IF(&(xen_idt[xen_idt_idx]), 2);
-                       break;
-               case 3:
-               case 4:
-                       xen_idt[xen_idt_idx].flags = SEL_UPL;
-                       break;
+#endif /* XEN */                       
                default:
-                       xen_idt[xen_idt_idx].flags = SEL_KPL;
                        break;
                }
 
-               xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);
-               xen_idt[xen_idt_idx].address =
-                   (unsigned long)x86_exceptions[x];
-               xen_idt_idx++;
-#endif /* XEN */
+               set_idtgate(&idt[x], x86_exceptions[x], ist, SDT_SYS386IGT,
+                   sel, GSEL(GCODE_SEL, SEL_KPL));
        }
 
        /* new-style interrupt gate for syscalls */
-#ifndef XEN
        idt_vec_reserve(128);
-       setgate(&idt[128], &IDTVEC(osyscall), 0, SDT_SYS386IGT, SEL_UPL,
+       set_idtgate(&idt[128], &IDTVEC(osyscall), 0, SDT_SYS386IGT, SEL_UPL,
            GSEL(GCODE_SEL, SEL_KPL));
-#else
-       idt_vec_reserve(128);
-       xen_idt[xen_idt_idx].vector = 128;
-       xen_idt[xen_idt_idx].flags = SEL_KPL;
-       xen_idt[xen_idt_idx].cs = GSEL(GCODE_SEL, SEL_KPL);
-       xen_idt[xen_idt_idx].address =  (unsigned long) &IDTVEC(osyscall);
-       xen_idt_idx++;
-       pmap_changeprot_local(idt_vaddr, VM_PROT_READ);
-#endif /* XEN */
+
        kpreempt_enable();
 
        setregion(&region, gdtstore, DYNSEL_START - 1);
diff -r bc0970c6efcf -r 9384dc6a1b27 sys/arch/amd64/include/segments.h
--- a/sys/arch/amd64/include/segments.h Sat Sep 22 17:13:30 2018 +0000
+++ b/sys/arch/amd64/include/segments.h Sun Sep 23 00:59:59 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: segments.h,v 1.34 2017/12/31 08:29:38 maxv Exp $       */
+/*     $NetBSD: segments.h,v 1.35 2018/09/23 00:59:59 cherry Exp $     */
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -234,15 +234,18 @@
 
 #ifdef _KERNEL
 #ifdef XEN
-extern struct trap_info *idt;
+typedef struct trap_info idt_descriptor_t;
 #else
-extern struct gate_descriptor *idt;
-#endif
+typedef struct gate_descriptor idt_descriptor_t; 
+#endif /* XEN */
+extern idt_descriptor_t *idt;
 extern char *gdtstore;
 extern char *ldtstore;
 
 void setgate(struct gate_descriptor *, void *, int, int, int, int);
 void unsetgate(struct gate_descriptor *);
+void set_idtgate(idt_descriptor_t *, void *, int, int, int, int);
+void unset_idtgate(idt_descriptor_t *);
 void setregion(struct region_descriptor *, void *, uint16_t);
 void set_sys_segment(struct sys_segment_descriptor *, void *, size_t,
     int, int, int);
diff -r bc0970c6efcf -r 9384dc6a1b27 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Sat Sep 22 17:13:30 2018 +0000
+++ b/sys/arch/i386/i386/machdep.c      Sun Sep 23 00:59:59 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.808 2018/07/26 09:29:08 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.809 2018/09/23 00:59:59 cherry Exp $     */
 
 /*
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009, 2017
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.808 2018/07/26 09:29:08 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.809 2018/09/23 00:59:59 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -580,7 +580,7 @@
            SDT_SYS386TSS, SEL_KPL, 0, 0);
        ci->ci_gdt[GTRAPTSS_SEL].sd = sd;
 
-       setgate(&idt[8], NULL, 0, SDT_SYSTASKGT, SEL_KPL,
+       set_idtgate(&idt[8], NULL, 0, SDT_SYSTASKGT, SEL_KPL,
            GSEL(GTRAPTSS_SEL, SEL_KPL));
 
 #if defined(DDB) && defined(MULTIPROCESSOR)
@@ -602,7 +602,7 @@
            SDT_SYS386TSS, SEL_KPL, 0, 0);
        ci->ci_gdt[GIPITSS_SEL].sd = sd;
 
-       setgate(&idt[ddb_vec], NULL, 0, SDT_SYSTASKGT, SEL_KPL,
+       set_idtgate(&idt[ddb_vec], NULL, 0, SDT_SYSTASKGT, SEL_KPL,
            GSEL(GIPITSS_SEL, SEL_KPL));
 #endif
 }
@@ -960,23 +960,15 @@
 extern vector IDTVEC(syscall);
 extern vector *IDTVEC(exceptions)[];
 #ifdef XEN
-#define MAX_XEN_IDT 128
-trap_info_t xen_idt[MAX_XEN_IDT];
-int xen_idt_idx;
 extern union descriptor tmpgdt[];
 #endif
 
 void
 cpu_init_idt(void)
 {
-#ifndef XEN
        struct region_descriptor region;
        setregion(&region, pentium_idt, NIDT * sizeof(idt[0]) - 1);
        lidt(&region);
-#else
-       if (HYPERVISOR_set_trap_table(xen_idt))
-               panic("HYPERVISOR_set_trap_table %p failed\n", xen_idt);
-#endif
 }
 
 void
@@ -1342,62 +1334,47 @@
        ldtstore[LUCODEBIG_SEL] = gdtstore[GUCODEBIG_SEL];
        ldtstore[LUDATA_SEL] = gdtstore[GUDATA_SEL];
 
-#ifndef XEN
        /* exceptions */
        for (x = 0; x < 32; x++) {
+               /* Reset to default. Special cases below */
+               int sel;
+#ifdef XEN             
+               sel = SEL_XEN;
+#else
+               sel = SEL_KPL;
+#endif /* XEN */
+
                idt_vec_reserve(x);
-               setgate(&idt[x], IDTVEC(exceptions)[x], 0, SDT_SYS386IGT,
-                   (x == 3 || x == 4) ? SEL_UPL : SEL_KPL,
-                   GSEL(GCODE_SEL, SEL_KPL));
+
+               switch (x) {
+#ifdef XEN
+               case 2:  /* NMI */
+               case 18: /* MCA */
+                       sel |= 0x4; /* Auto EOI/mask */
+                       break;
+#endif /* XEN */
+               case 3:
+               case 4:



Home | Main Index | Thread Index | Old Index