Module Name:    src
Committed By:   maxv
Date:           Thu Jan  4 13:36:30 UTC 2018

Modified Files:
        src/sys/arch/amd64/amd64: genassym.cf locore.S machdep.c
        src/sys/arch/i386/i386: genassym.cf locore.S machdep.c
        src/sys/arch/x86/include: cpu.h
        src/sys/arch/x86/x86: intr.c pmap.c sys_machdep.c

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


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/sys/arch/amd64/amd64/genassym.cf
cvs rdiff -u -r1.143 -r1.144 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.282 -r1.283 src/sys/arch/amd64/amd64/machdep.c
cvs rdiff -u -r1.105 -r1.106 src/sys/arch/i386/i386/genassym.cf
cvs rdiff -u -r1.154 -r1.155 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.801 -r1.802 src/sys/arch/i386/i386/machdep.c
cvs rdiff -u -r1.85 -r1.86 src/sys/arch/x86/include/cpu.h
cvs rdiff -u -r1.115 -r1.116 src/sys/arch/x86/x86/intr.c
cvs rdiff -u -r1.274 -r1.275 src/sys/arch/x86/x86/pmap.c
cvs rdiff -u -r1.44 -r1.45 src/sys/arch/x86/x86/sys_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/genassym.cf
diff -u src/sys/arch/amd64/amd64/genassym.cf:1.63 src/sys/arch/amd64/amd64/genassym.cf:1.64
--- src/sys/arch/amd64/amd64/genassym.cf:1.63	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/amd64/amd64/genassym.cf	Thu Jan  4 13:36:30 2018
@@ -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 @@ define	TF_REGSIZE		offsetof(struct trapf
 # 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_CURLWP		offsetof(struct 
 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)

Index: src/sys/arch/amd64/amd64/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.143 src/sys/arch/amd64/amd64/locore.S:1.144
--- src/sys/arch/amd64/amd64/locore.S:1.143	Sun Nov 26 15:00:16 2017
+++ src/sys/arch/amd64/amd64/locore.S	Thu Jan  4 13:36:30 2018
@@ -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 @@ ENTRY(cpu_switchto)
 	/* 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);

Index: src/sys/arch/amd64/amd64/machdep.c
diff -u src/sys/arch/amd64/amd64/machdep.c:1.282 src/sys/arch/amd64/amd64/machdep.c:1.283
--- src/sys/arch/amd64/amd64/machdep.c:1.282	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/amd64/amd64/machdep.c	Thu Jan  4 13:36:30 2018
@@ -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 @@ x86_64_proc0_pcb_ldt_init(void)
 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

Index: src/sys/arch/i386/i386/genassym.cf
diff -u src/sys/arch/i386/i386/genassym.cf:1.105 src/sys/arch/i386/i386/genassym.cf:1.106
--- src/sys/arch/i386/i386/genassym.cf:1.105	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/i386/i386/genassym.cf	Thu Jan  4 13:36:30 2018
@@ -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_ARG			offsetof(struct intrhand
 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_FPCURLWP	offsetof(struct
 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)

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.154 src/sys/arch/i386/i386/locore.S:1.155
--- src/sys/arch/i386/i386/locore.S:1.154	Mon Oct  2 17:48:01 2017
+++ src/sys/arch/i386/i386/locore.S	Thu Jan  4 13:36:30 2018
@@ -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 @@ skip_save:
 	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 @@ skip_save:
 	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 @@ switch_return:
 	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)
 

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.801 src/sys/arch/i386/i386/machdep.c:1.802
--- src/sys/arch/i386/i386/machdep.c:1.801	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/i386/i386/machdep.c	Thu Jan  4 13:36:30 2018
@@ -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 @@ cpu_set_tss_gates(struct cpu_info *ci)
 
 	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 @@ cpu_set_tss_gates(struct cpu_info *ci)
 
 	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 @@ cpu_set_tss_gates(struct cpu_info *ci)
 void
 cpu_init_tss(struct cpu_info *ci)
 {
-	struct i386tss *tss = &ci->ci_tss.tss;
+	struct cpu_tss *cputss;
 
-	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 = (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_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 */
 

Index: src/sys/arch/x86/include/cpu.h
diff -u src/sys/arch/x86/include/cpu.h:1.85 src/sys/arch/x86/include/cpu.h:1.86
--- src/sys/arch/x86/include/cpu.h:1.85	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/x86/include/cpu.h	Thu Jan  4 13:36:30 2018
@@ -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 @@ struct cpu_info {
 	 * 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 */
 
 	/*

Index: src/sys/arch/x86/x86/intr.c
diff -u src/sys/arch/x86/x86/intr.c:1.115 src/sys/arch/x86/x86/intr.c:1.116
--- src/sys/arch/x86/x86/intr.c:1.115	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/x86/x86/intr.c	Thu Jan  4 13:36:30 2018
@@ -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 @@ cpu_intr_init(struct cpu_info *ci)
 	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;

Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.274 src/sys/arch/x86/x86/pmap.c:1.275
--- src/sys/arch/x86/x86/pmap.c:1.274	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/x86/x86/pmap.c	Thu Jan  4 13:36:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmap.c,v 1.274 2018/01/04 12:34:15 maxv Exp $	*/
+/*	$NetBSD: pmap.c,v 1.275 2018/01/04 13:36:30 maxv Exp $	*/
 
 /*
  * Copyright (c) 2008, 2010, 2016, 2017 The NetBSD Foundation, Inc.
@@ -170,7 +170,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.274 2018/01/04 12:34:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.275 2018/01/04 13:36:30 maxv Exp $");
 
 #include "opt_user_ldt.h"
 #include "opt_lockdebug.h"
@@ -2897,8 +2897,8 @@ pmap_load(void)
 
 #ifdef i386
 #ifndef XEN
-	ci->ci_tss.tss.tss_ldt = pmap->pm_ldt_sel;
-	ci->ci_tss.tss.tss_cr3 = pcb->pcb_cr3;
+	ci->ci_tss->tss.tss_ldt = pmap->pm_ldt_sel;
+	ci->ci_tss->tss.tss_cr3 = pcb->pcb_cr3;
 #endif /* !XEN */
 #endif /* i386 */
 

Index: src/sys/arch/x86/x86/sys_machdep.c
diff -u src/sys/arch/x86/x86/sys_machdep.c:1.44 src/sys/arch/x86/x86/sys_machdep.c:1.45
--- src/sys/arch/x86/x86/sys_machdep.c:1.44	Thu Jan  4 12:34:15 2018
+++ src/sys/arch/x86/x86/sys_machdep.c	Thu Jan  4 13:36:30 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: sys_machdep.c,v 1.44 2018/01/04 12:34:15 maxv Exp $	*/
+/*	$NetBSD: sys_machdep.c,v 1.45 2018/01/04 13:36:30 maxv Exp $	*/
 
 /*
  * Copyright (c) 1998, 2007, 2009, 2017 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.44 2018/01/04 12:34:15 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.45 2018/01/04 13:36:30 maxv Exp $");
 
 #include "opt_mtrr.h"
 #include "opt_pmc.h"
@@ -482,9 +482,9 @@ x86_set_ioperm(struct lwp *l, void *args
 
 	kpreempt_disable();
 	ci = curcpu();
-	memcpy(ci->ci_tss.iomap, pcb->pcb_iomap, sizeof(ci->ci_tss.iomap));
-	ci->ci_tss.tss.tss_iobase =
-	    ((uintptr_t)&ci->ci_tss.iomap - (uintptr_t)&ci->ci_tss.tss) << 16;
+	memcpy(ci->ci_tss->iomap, pcb->pcb_iomap, IOMAPSIZE);
+	ci->ci_tss->tss.tss_iobase =
+	    ((uintptr_t)&ci->ci_tss->iomap - (uintptr_t)&ci->ci_tss->tss) << 16;
 	kpreempt_enable();
 
 	return error;

Reply via email to