Source-Changes-HG archive

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

[src/netbsd-1-5]: src/sys/arch/i386 Update from trunk:



details:   https://anonhg.NetBSD.org/src/rev/1205ce679549
branches:  netbsd-1-5
changeset: 489129:1205ce679549
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Aug 16 23:18:20 2000 +0000

description:
Update from trunk:
Move the TSS selector out of the PCB and put it into mdproc.  We
need to access this when we have the proclist locked for reading,
and thus cannot store it in the PCB (which may be swapped out).

As part of this, call pmap_activate() from cpu_switch() to switch
to the new address space, and refresh the PCB's copy of the LDT
selector from the pmap structure (see above paragraph).  We need
to do this for MP support anyhow.

Fixes a "panic: spinlock_switchcheck: CPU 0 has 1 spin locks" via
gdt_compact() reported by Nathan Williams.

diffstat:

 sys/arch/i386/i386/gdt.c        |  33 +++++++++++++--------------------
 sys/arch/i386/i386/genassym.cf  |   5 ++---
 sys/arch/i386/i386/locore.s     |  20 +++++++++++++-------
 sys/arch/i386/i386/machdep.c    |   8 ++++----
 sys/arch/i386/i386/pmap.c       |   6 +++---
 sys/arch/i386/i386/vm_machdep.c |  16 ++++++----------
 sys/arch/i386/include/gdt.h     |   7 ++++---
 sys/arch/i386/include/pcb.h     |   3 +--
 sys/arch/i386/include/proc.h    |   3 ++-
 9 files changed, 48 insertions(+), 53 deletions(-)

diffs (truncated from 302 to 300 lines):

diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/i386/gdt.c
--- a/sys/arch/i386/i386/gdt.c  Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/i386/gdt.c  Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gdt.c,v 1.20 1999/07/25 18:05:31 thorpej Exp $ */
+/*     $NetBSD: gdt.c,v 1.20.14.1 2000/08/16 23:18:20 thorpej Exp $    */
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -107,15 +107,13 @@
 gdt_compact()
 {
        struct proc *p;
-       struct pcb *pcb;
        pmap_t pmap;
        int slot = NGDT, oslot;
 
        proclist_lock_read();
        for (p = allproc.lh_first; p != 0; p = p->p_list.le_next) {
-               pcb = &p->p_addr->u_pcb;
                pmap = p->p_vmspace->vm_map.pmap;
-               oslot = IDXSEL(pcb->pcb_tss_sel);
+               oslot = IDXSEL(p->p_md.md_tss_sel);
                if (oslot >= gdt_count) {
                        while (gdt[slot].sd.sd_type != SDT_SYSNULL) {
                                if (++slot >= gdt_count)
@@ -123,7 +121,7 @@
                        }
                        gdt[slot] = gdt[oslot];
                        gdt[oslot].gd.gd_type = SDT_SYSNULL;
-                       pcb->pcb_tss_sel = GSEL(slot, SEL_KPL);
+                       p->p_md.md_tss_sel = GSEL(slot, SEL_KPL);
                }
                simple_lock(&pmap->pm_lock);
                oslot = IDXSEL(pmap->pm_ldt_sel);
@@ -135,16 +133,10 @@
                        gdt[slot] = gdt[oslot];
                        gdt[oslot].gd.gd_type = SDT_SYSNULL;
                        pmap->pm_ldt_sel = GSEL(slot, SEL_KPL);
-
-                       /* Refresh the PCB. */
-                       pcb->pcb_pmap = pmap;
-                       pcb->pcb_ldt_sel = pmap->pm_ldt_sel;
-
                        /*
-                        * XXX We don't need to re-load the LDT on this
-                        * XXX processor, but if this pmap/pcb is in use
-                        * XXX on _another_ processor, we need to notify
-                        * XXX it!
+                        * XXXSMP: if the pmap is in use on other
+                        * processors, they need to reload thier
+                        * LDT!
                         */
                }
                simple_unlock(&pmap->pm_lock);
@@ -283,23 +275,24 @@
 }
 
 void
-tss_alloc(pcb)
-       struct pcb *pcb;
+tss_alloc(p)
+       struct proc *p;
 {
+       struct pcb *pcb = &p->p_addr->u_pcb;
        int slot;
 
        slot = gdt_get_slot();
        setsegment(&gdt[slot].sd, &pcb->pcb_tss, sizeof(struct pcb) - 1,
            SDT_SYS386TSS, SEL_KPL, 0, 0);
-       pcb->pcb_tss_sel = GSEL(slot, SEL_KPL);
+       p->p_md.md_tss_sel = GSEL(slot, SEL_KPL);
 }
 
 void
-tss_free(pcb)
-       struct pcb *pcb;
+tss_free(p)
+       struct proc *p;
 {
 
-       gdt_put_slot(IDXSEL(pcb->pcb_tss_sel));
+       gdt_put_slot(IDXSEL(p->p_md.md_tss_sel));
 }
 
 void
diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/i386/genassym.cf
--- a/sys/arch/i386/i386/genassym.cf    Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/i386/genassym.cf    Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.19 2000/05/26 00:36:45 thorpej Exp $
+#      $NetBSD: genassym.cf,v 1.19.4.1 2000/08/16 23:18:21 thorpej Exp $
 
 #
 # Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -137,8 +137,8 @@
 define P_PRIORITY              offsetof(struct proc, p_priority)
 define P_STAT                  offsetof(struct proc, p_stat)
 define P_WCHAN                 offsetof(struct proc, p_wchan)
-define P_VMSPACE               offsetof(struct proc, p_vmspace)
 define P_FLAG                  offsetof(struct proc, p_flag)
+define P_MD_TSS_SEL            offsetof(struct proc, p_md.md_tss_sel)
 
 define P_SYSTEM                P_SYSTEM
 
@@ -156,7 +156,6 @@
 define PCB_GS                  offsetof(struct pcb, pcb_gs)
 define PCB_CR0                 offsetof(struct pcb, pcb_cr0)
 define PCB_LDT_SEL             offsetof(struct pcb, pcb_ldt_sel)
-define PCB_TSS_SEL             offsetof(struct pcb, pcb_tss_sel)
 define PCB_ONFAULT             offsetof(struct pcb, pcb_onfault)
 
 define TF_CS                   offsetof(struct trapframe, tf_cs)
diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/i386/locore.s
--- a/sys/arch/i386/i386/locore.s       Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/i386/locore.s       Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.s,v 1.222 2000/05/31 05:09:16 thorpej Exp $     */
+/*     $NetBSD: locore.s,v 1.222.2.1 2000/08/16 23:18:21 thorpej Exp $ */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -2009,13 +2009,19 @@
        jnz     switch_restored
 #endif
 
+       /*
+        * Activate the address space.  We're curproc, so %cr3 will
+        * be reloaded, but we're not yet curpcb, so the LDT won't
+        * be reloaded, although the PCB copy of the selector will
+        * be refreshed from the pmap.
+        */
+       pushl   %edi
+       call    _C_LABEL(pmap_activate)
+       addl    $4,%esp
+
        /* Load TSS info. */
        movl    _C_LABEL(gdt),%eax
-       movl    PCB_TSS_SEL(%esi),%edx
-
-       /* Switch address space. */
-       movl    PCB_CR3(%esi),%ecx
-       movl    %ecx,%cr3
+       movl    P_MD_TSS_SEL(%edi),%edx
 
        /* Switch TSS. Reset "task busy" flag before */
        andl    $~0x0200,4(%eax,%edx, 1)
@@ -2087,7 +2093,7 @@
 
        /* Load TSS info. */
        movl    _C_LABEL(gdt),%eax
-       movl    PCB_TSS_SEL(%esi),%edx
+       movl    P_MD_TSS_SEL(%ebx),%edx
 
        /* Switch address space. */
        movl    PCB_CR3(%esi),%ecx
diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/i386/machdep.c      Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.389 2000/06/05 23:44:58 jhawk Exp $      */
+/*     $NetBSD: machdep.c,v 1.389.2.1 2000/08/16 23:18:22 thorpej Exp $        */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -392,13 +392,13 @@
        for (x = 0; x < sizeof(pcb->pcb_iomap) / 4; x++)
                pcb->pcb_iomap[x] = 0xffffffff;
 
-       pcb->pcb_ldt_sel = GSEL(GLDT_SEL, SEL_KPL);
+       pcb->pcb_ldt_sel = pmap_kernel()->pm_ldt_sel = GSEL(GLDT_SEL, SEL_KPL);
        pcb->pcb_cr0 = rcr0();
        pcb->pcb_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
        pcb->pcb_tss.tss_esp0 = (int)proc0.p_addr + USPACE - 16;
-       tss_alloc(pcb);
+       tss_alloc(&proc0);
 
-       ltr(pcb->pcb_tss_sel);
+       ltr(proc0.p_md.md_tss_sel);
        lldt(pcb->pcb_ldt_sel);
 
        proc0.p_md.md_regs = (struct trapframe *)pcb->pcb_tss.tss_esp0 - 1;
diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/i386/pmap.c
--- a/sys/arch/i386/i386/pmap.c Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/i386/pmap.c Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pmap.c,v 1.94 2000/06/15 13:35:27 mycroft Exp $        */
+/*     $NetBSD: pmap.c,v 1.94.2.1 2000/08/16 23:18:23 thorpej Exp $    */
 
 /*
  *
@@ -1952,9 +1952,9 @@
 #endif /* USER_LDT */
 
 /*
- * pmap_activate: activate a process' pmap (fill in %cr3 info)
+ * pmap_activate: activate a process' pmap (fill in %cr3 and LDT info)
  *
- * => called from cpu_fork()
+ * => called from cpu_switch()
  * => if proc is the curproc, then load it into the MMU
  */
 
diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/i386/vm_machdep.c
--- a/sys/arch/i386/i386/vm_machdep.c   Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/i386/vm_machdep.c   Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vm_machdep.c,v 1.89 2000/05/28 05:49:01 thorpej Exp $  */
+/*     $NetBSD: vm_machdep.c,v 1.89.2.1 2000/08/16 23:18:24 thorpej Exp $      */
 
 /*-
  * Copyright (c) 1995 Charles M. Hannum.  All rights reserved.
@@ -135,19 +135,15 @@
         * Preset these so that gdt_compact() doesn't get confused if called
         * during the allocations below.
         *
-        * Note: pcb_ldt_sel is handled in the pmap_activate() call below.
+        * Note: pcb_ldt_sel is handled in the pmap_activate() call when
+        * we run the new process.
         */
-       pcb->pcb_tss_sel = GSEL(GNULL_SEL, SEL_KPL);
-
-       /*
-        * Activate the addres space.  Note this will refresh pcb_ldt_sel.
-        */
-       pmap_activate(p2);
+       p2->p_md.md_tss_sel = GSEL(GNULL_SEL, SEL_KPL);
 
        /* Fix up the TSS. */
        pcb->pcb_tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
        pcb->pcb_tss.tss_esp0 = (int)p2->p_addr + USPACE - 16;
-       tss_alloc(pcb);
+       tss_alloc(p2);
 
        /*
         * Copy the trapframe.
@@ -222,7 +218,7 @@
 {
 
        /* Nuke the TSS. */
-       tss_free(&p->p_addr->u_pcb);
+       tss_free(p);
 }
 
 /*
diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/include/gdt.h
--- a/sys/arch/i386/include/gdt.h       Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/include/gdt.h       Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gdt.h,v 1.7 1999/05/12 19:28:30 thorpej Exp $  */
+/*     $NetBSD: gdt.h,v 1.7.14.1 2000/08/16 23:18:27 thorpej Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
@@ -36,10 +36,11 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+struct proc;
 struct pmap;
 
 void gdt_init __P((void));
-void tss_alloc __P((struct pcb *));
-void tss_free __P((struct pcb *));
+void tss_alloc __P((struct proc *));
+void tss_free __P((struct proc *));
 void ldt_alloc __P((struct pmap *, union descriptor *, size_t));
 void ldt_free __P((struct pmap *));
diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/include/pcb.h
--- a/sys/arch/i386/include/pcb.h       Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/include/pcb.h       Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pcb.h,v 1.26 1999/09/12 01:17:07 chs Exp $     */
+/*     $NetBSD: pcb.h,v 1.26.14.1 2000/08/16 23:18:28 thorpej Exp $    */
 
 /*-
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -98,7 +98,6 @@
 #define        pcb_fs  pcb_tss.tss_fs
 #define        pcb_gs  pcb_tss.tss_gs
 #define        pcb_ldt_sel     pcb_tss.tss_ldt
-       int     pcb_tss_sel;
        int     pcb_cr0;                /* saved image of CR0 */
        struct  save87 pcb_savefpu;     /* floating point state for 287/387 */
        struct  emcsts pcb_saveemc;     /* Cyrix EMC state */
diff -r c7f1843d3ab3 -r 1205ce679549 sys/arch/i386/include/proc.h
--- a/sys/arch/i386/include/proc.h      Wed Aug 16 22:55:47 2000 +0000
+++ b/sys/arch/i386/include/proc.h      Wed Aug 16 23:18:20 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: proc.h,v 1.10 1995/08/06 05:33:23 mycroft Exp $        */
+/*     $NetBSD: proc.h,v 1.10.44.1 2000/08/16 23:18:28 thorpej Exp $   */
 
 /*
  * Copyright (c) 1991 Regents of the University of California.
@@ -41,6 +41,7 @@
 struct mdproc {
        struct  trapframe *md_regs;     /* registers on current frame */
        int     md_flags;               /* machine-dependent flags */
+       int     md_tss_sel;             /* TSS selector */
 };



Home | Main Index | Thread Index | Old Index