Source-Changes-HG archive

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

[src/trunk]: src/sys/arch Allocate the TSS area dynamically. This way cpu_inf...



details:   https://anonhg.NetBSD.org/src/rev/c8140f524477
branches:  trunk
changeset: 358506:c8140f524477
user:      maxv <maxv%NetBSD.org@localhost>
date:      Thu Jan 04 13:36:30 2018 +0000

description:
Allocate the TSS area dynamically. This way cpu_info and cpu_tss can be
put in separate pages.

diffstat:

 sys/arch/amd64/amd64/genassym.cf |   6 ++++--
 sys/arch/amd64/amd64/locore.S    |   5 +++--
 sys/arch/amd64/amd64/machdep.c   |  20 ++++++++++++--------
 sys/arch/i386/i386/genassym.cf   |  13 +++++++------
 sys/arch/i386/i386/locore.S      |  17 ++++++++++-------
 sys/arch/i386/i386/machdep.c     |  29 +++++++++++++++++------------
 sys/arch/x86/include/cpu.h       |   4 ++--
 sys/arch/x86/x86/intr.c          |   6 +++---
 sys/arch/x86/x86/pmap.c          |   8 ++++----
 sys/arch/x86/x86/sys_machdep.c   |  10 +++++-----
 10 files changed, 67 insertions(+), 51 deletions(-)

diffs (truncated from 359 to 300 lines):

diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/amd64/amd64/genassym.cf
--- a/sys/arch/amd64/amd64/genassym.cf  Thu Jan 04 12:34:15 2018 +0000
+++ b/sys/arch/amd64/amd64/genassym.cf  Thu Jan 04 13:36:30 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.63 2018/01/04 12:34:15 maxv Exp $
+#      $NetBSD: genassym.cf,v 1.64 2018/01/04 13:36:30 maxv Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -223,6 +223,8 @@
 # Total size includes registers pushed by hardware
 define FRAMESIZE               sizeof(struct trapframe)
 
+define TSS_RSP0                offsetof(struct cpu_tss, tss.tss_rsp0)
+
 define CPU_INFO_SCRATCH        offsetof(struct cpu_info, ci_scratch)
 define CPU_INFO_SELF           offsetof(struct cpu_info, ci_self)
 define CPU_INFO_RESCHED        offsetof(struct cpu_info, ci_want_resched)
@@ -233,7 +235,7 @@
 define CPU_INFO_CURLDT         offsetof(struct cpu_info, ci_curldt)
 define CPU_INFO_IDLELWP        offsetof(struct cpu_info, ci_data.cpu_idlelwp)
 define CPU_INFO_PMAP           offsetof(struct cpu_info, ci_pmap)
-define CPU_INFO_RSP0           offsetof(struct cpu_info, ci_tss.tss.tss_rsp0)
+define CPU_INFO_TSS            offsetof(struct cpu_info, ci_tss)
 define CPU_INFO_NSYSCALL       offsetof(struct cpu_info, ci_data.cpu_nsyscall)
 define CPU_INFO_NTRAP          offsetof(struct cpu_info, ci_data.cpu_ntrap)
 define CPU_INFO_NINTR          offsetof(struct cpu_info, ci_data.cpu_nintr)
diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Thu Jan 04 12:34:15 2018 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Thu Jan 04 13:36:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.143 2017/11/26 15:00:16 maxv Exp $        */
+/*     $NetBSD: locore.S,v 1.144 2018/01/04 13:36:30 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -1107,7 +1107,8 @@
        /* Switch ring0 stack */
 #ifndef XEN
        movq    PCB_RSP0(%r14),%rax
-       movq    %rax,CPUVAR(RSP0)
+       movq    CPUVAR(TSS),%rdi
+       movq    %rax,TSS_RSP0(%rdi)
 #else
        movq    %r14,%rdi
        callq   _C_LABEL(x86_64_switch_context);
diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Thu Jan 04 12:34:15 2018 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Thu Jan 04 13:36:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.282 2018/01/04 12:34:15 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.283 2018/01/04 13:36:30 maxv 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.282 2018/01/04 12:34:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.283 2018/01/04 13:36:30 maxv Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -502,21 +502,25 @@
 void
 cpu_init_tss(struct cpu_info *ci)
 {
-       struct x86_64_tss *tss = &ci->ci_tss.tss;
+       struct cpu_tss *cputss;
        uintptr_t p;
 
-       tss->tss_iobase = IOMAP_INVALOFF << 16;
-       /* tss->tss_ist[0] is filled by cpu_intr_init */
+       cputss = (struct cpu_tss *)uvm_km_alloc(kernel_map,
+           sizeof(struct cpu_tss), 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
+
+       cputss->tss.tss_iobase = IOMAP_INVALOFF << 16;
+       /* cputss->tss.tss_ist[0] is filled by cpu_intr_init */
 
        /* double fault */
        p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
-       tss->tss_ist[1] = p + PAGE_SIZE - 16;
+       cputss->tss.tss_ist[1] = p + PAGE_SIZE - 16;
 
        /* NMI */
        p = uvm_km_alloc(kernel_map, PAGE_SIZE, 0, UVM_KMF_WIRED);
-       tss->tss_ist[2] = p + PAGE_SIZE - 16;
+       cputss->tss.tss_ist[2] = p + PAGE_SIZE - 16;
 
-       ci->ci_tss_sel = tss_alloc(tss);
+       ci->ci_tss = cputss;
+       ci->ci_tss_sel = tss_alloc(&cputss->tss);
 }
 
 void
diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/i386/i386/genassym.cf
--- a/sys/arch/i386/i386/genassym.cf    Thu Jan 04 12:34:15 2018 +0000
+++ b/sys/arch/i386/i386/genassym.cf    Thu Jan 04 13:36:30 2018 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.105 2018/01/04 12:34:15 maxv Exp $
+#      $NetBSD: genassym.cf,v 1.106 2018/01/04 13:36:30 maxv Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -239,6 +239,11 @@
 define IH_LEVEL                offsetof(struct intrhand, ih_level)
 define IH_NEXT                 offsetof(struct intrhand, ih_next)
 
+define TSS_TSS                 offsetof(struct cpu_tss, tss)
+define TSS_ESP0                offsetof(struct cpu_tss, tss.tss_esp0)
+define TSS_IOBASE              offsetof(struct cpu_tss, tss.tss_iobase)
+define TSS_IOMAP               offsetof(struct cpu_tss, iomap)
+
 define CPU_INFO_SELF           offsetof(struct cpu_info, ci_self)
 define CPU_INFO_RESCHED        offsetof(struct cpu_info, ci_want_resched)
 define CPU_INFO_WANT_PMAPLOAD  offsetof(struct cpu_info, ci_want_pmapload)
@@ -249,11 +254,7 @@
 define CPU_INFO_CURLDT         offsetof(struct cpu_info, ci_curldt)
 define CPU_INFO_IDLELWP        offsetof(struct cpu_info, ci_data.cpu_idlelwp)
 define CPU_INFO_PMAP           offsetof(struct cpu_info, ci_pmap)
-define CPU_INFO_TSS            offsetof(struct cpu_info, ci_tss.tss)
-define CPU_INFO_TSS_SEL        offsetof(struct cpu_info, ci_tss_sel)
-define CPU_INFO_ESP0           offsetof(struct cpu_info, ci_tss.tss.tss_esp0)
-define CPU_INFO_IOBASE         offsetof(struct cpu_info, ci_tss.tss.tss_iobase)
-define CPU_INFO_IOMAP          offsetof(struct cpu_info, ci_tss.iomap)
+define CPU_INFO_TSS            offsetof(struct cpu_info, ci_tss)
 define IOMAP_INVALOFF          IOMAP_INVALOFF
 define CPU_INFO_NSYSCALL       offsetof(struct cpu_info, ci_data.cpu_nsyscall)
 define CPU_INFO_NTRAP          offsetof(struct cpu_info, ci_data.cpu_ntrap)
diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Thu Jan 04 12:34:15 2018 +0000
+++ b/sys/arch/i386/i386/locore.S       Thu Jan 04 13:36:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.154 2017/10/02 17:48:01 bouyer Exp $      */
+/*     $NetBSD: locore.S,v 1.155 2018/01/04 13:36:30 maxv Exp $        */
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.154 2017/10/02 17:48:01 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.155 2018/01/04 13:36:30 maxv Exp $");
 
 #include "opt_copy_symtab.h"
 #include "opt_ddb.h"
@@ -1112,7 +1112,8 @@
        addl    $4,%esp
 #else
        movl    PCB_ESP0(%ebx),%eax
-       movl    %eax,CPUVAR(ESP0)
+       movl    CPUVAR(TSS),%ecx
+       movl    %eax,TSS_ESP0(%ecx)
 #endif
 
        /* Don't bother with the rest if switching to a system process. */
@@ -1136,7 +1137,8 @@
        movl    PCB_IOMAP(%ebx),%eax
        orl     %eax,%eax
        jnz     .Lcopy_iobitmap
-       movl    $(IOMAP_INVALOFF << 16),CPUVAR(IOBASE)
+       movl    CPUVAR(TSS),%eax
+       movl    $(IOMAP_INVALOFF << 16),TSS_IOBASE(%eax)
 .Liobitmap_done:
 
        /* Is this process using RAS (restartable atomic sequences)? */
@@ -1200,13 +1202,14 @@
        pushl   %esi
        pushl   %edi
        movl    %eax,%esi               /* pcb_iomap */
-       movl    CPUVAR(SELF),%edi
-       leal    CPU_INFO_IOMAP(%edi),%edi
+       movl    CPUVAR(TSS),%edi
+       leal    TSS_IOMAP(%edi),%edi
        rep
        movsl
        popl    %edi
        popl    %esi
-       movl    $((CPU_INFO_IOMAP - CPU_INFO_TSS) << 16),CPUVAR(IOBASE)
+       movl    CPUVAR(TSS),%eax
+       movl    $((TSS_IOMAP - TSS_TSS) << 16),TSS_IOBASE(%eax)
        jmp     .Liobitmap_done
 END(cpu_switchto)
 
diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Thu Jan 04 12:34:15 2018 +0000
+++ b/sys/arch/i386/i386/machdep.c      Thu Jan 04 13:36:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.801 2018/01/04 12:34:15 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.802 2018/01/04 13:36:30 maxv 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.801 2018/01/04 12:34:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.802 2018/01/04 13:36:30 maxv Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_freebsd.h"
@@ -581,9 +581,9 @@
 
        doubleflt_stack = (void *)uvm_km_alloc(kernel_map, USPACE, 0,
            UVM_KMF_WIRED);
-       tss_init(&ci->ci_tss.dblflt_tss, doubleflt_stack, IDTVEC(tss_trap08));
+       tss_init(&ci->ci_tss->dblflt_tss, doubleflt_stack, IDTVEC(tss_trap08));
 
-       setsegment(&sd, &ci->ci_tss.dblflt_tss, sizeof(struct i386tss) - 1,
+       setsegment(&sd, &ci->ci_tss->dblflt_tss, sizeof(struct i386tss) - 1,
            SDT_SYS386TSS, SEL_KPL, 0, 0);
        ci->ci_gdt[GTRAPTSS_SEL].sd = sd;
 
@@ -602,10 +602,10 @@
 
        ddbipi_stack = (void *)uvm_km_alloc(kernel_map, USPACE, 0,
            UVM_KMF_WIRED);
-       tss_init(&ci->ci_tss.ddbipi_tss, ddbipi_stack,
+       tss_init(&ci->ci_tss->ddbipi_tss, ddbipi_stack,
            x2apic_mode ? Xx2apic_intrddbipi : Xintrddbipi);
 
-       setsegment(&sd, &ci->ci_tss.ddbipi_tss, sizeof(struct i386tss) - 1,
+       setsegment(&sd, &ci->ci_tss->ddbipi_tss, sizeof(struct i386tss) - 1,
            SDT_SYS386TSS, SEL_KPL, 0, 0);
        ci->ci_gdt[GIPITSS_SEL].sd = sd;
 
@@ -620,13 +620,18 @@
 void
 cpu_init_tss(struct cpu_info *ci)
 {
-       struct i386tss *tss = &ci->ci_tss.tss;
+       struct cpu_tss *cputss;
+
+       cputss = (struct cpu_tss *)uvm_km_alloc(kernel_map,
+           sizeof(struct cpu_tss), 0, UVM_KMF_WIRED|UVM_KMF_ZERO);
 
-       tss->tss_iobase = IOMAP_INVALOFF << 16;
-       tss->tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
-       tss->tss_ldt = GSEL(GLDT_SEL, SEL_KPL);
-       tss->tss_cr3 = rcr3();
-       ci->ci_tss_sel = tss_alloc(tss);
+       cputss->tss.tss_iobase = IOMAP_INVALOFF << 16;
+       cputss->tss.tss_ss0 = GSEL(GDATA_SEL, SEL_KPL);
+       cputss->tss.tss_ldt = GSEL(GLDT_SEL, SEL_KPL);
+       cputss->tss.tss_cr3 = rcr3();
+
+       ci->ci_tss = cputss;
+       ci->ci_tss_sel = tss_alloc(&cputss->tss);
 }
 #endif /* XEN */
 
diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/x86/include/cpu.h
--- a/sys/arch/x86/include/cpu.h        Thu Jan 04 12:34:15 2018 +0000
+++ b/sys/arch/x86/include/cpu.h        Thu Jan 04 13:36:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.85 2018/01/04 12:34:15 maxv Exp $    */
+/*     $NetBSD: cpu.h,v 1.86 2018/01/04 13:36:30 maxv Exp $    */
 
 /*
  * Copyright (c) 1990 The Regents of the University of California.
@@ -219,7 +219,7 @@
         * Segmentation-related data.
         */
        union descriptor *ci_gdt;
-       struct cpu_tss  ci_tss;         /* Per-cpu TSSes; shared among LWPs */
+       struct cpu_tss  *ci_tss;        /* Per-cpu TSSes; shared among LWPs */
        int ci_tss_sel;                 /* TSS selector of this cpu */
 
        /*
diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/x86/x86/intr.c
--- a/sys/arch/x86/x86/intr.c   Thu Jan 04 12:34:15 2018 +0000
+++ b/sys/arch/x86/x86/intr.c   Thu Jan 04 13:36:30 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.115 2018/01/04 12:34:15 maxv Exp $  */
+/*     $NetBSD: intr.c,v 1.116 2018/01/04 13:36:30 maxv Exp $  */
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.115 2018/01/04 12:34:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.116 2018/01/04 13:36:30 maxv Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -1529,7 +1529,7 @@
        ci->ci_intrstack = (char *)istack + redzone_const_or_zero(PAGE_SIZE) +
            INTRSTACKSIZE - 33 * sizeof(register_t);
 #if defined(__x86_64__)
-       ci->ci_tss.tss.tss_ist[0] = (uintptr_t)ci->ci_intrstack & ~0xf;
+       ci->ci_tss->tss.tss_ist[0] = (uintptr_t)ci->ci_intrstack & ~0xf;
 #endif /* defined(__x86_64__) */
 #endif /* defined(INTRSTACKSIZE) */
        ci->ci_idepth = -1;
diff -r 1ad15a3cd924 -r c8140f524477 sys/arch/x86/x86/pmap.c



Home | Main Index | Thread Index | Old Index