Module Name: src
Committed By: maxv
Date: Fri Nov 25 14:12:56 UTC 2016
Modified Files:
src/sys/arch/amd64/amd64: locore.S vector.S
src/sys/arch/amd64/include: i82093reg.h
src/sys/arch/i386/i386: locore.S vector.S
src/sys/arch/i386/include: i82093reg.h
src/sys/arch/x86/include: i82489var.h
src/sys/arch/x86/x86: lapic.c pmap.c
Log Message:
Move the virtual address of the LAPIC page out of the data segment on amd64
and i386. The old design was error-prone, and it didn't allow us to map the
data segment with large pages.
Now, the VA is allocated dynamically in the pmap bootstrap code, and entered
manually later. We go from using &local_apic to using *local_apic_va, and we
therefore need one more level of indirection in the asm code.
Discussed on tech-kern.
To generate a diff of this commit:
cvs rdiff -u -r1.113 -r1.114 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.47 -r1.48 src/sys/arch/amd64/amd64/vector.S
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/amd64/include/i82093reg.h
cvs rdiff -u -r1.140 -r1.141 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.67 -r1.68 src/sys/arch/i386/i386/vector.S
cvs rdiff -u -r1.8 -r1.9 src/sys/arch/i386/include/i82093reg.h
cvs rdiff -u -r1.15 -r1.16 src/sys/arch/x86/include/i82489var.h
cvs rdiff -u -r1.53 -r1.54 src/sys/arch/x86/x86/lapic.c
cvs rdiff -u -r1.227 -r1.228 src/sys/arch/x86/x86/pmap.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/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.113 src/sys/arch/amd64/amd64/locore.S:1.114
--- src/sys/arch/amd64/amd64/locore.S:1.113 Fri Nov 11 11:34:51 2016
+++ src/sys/arch/amd64/amd64/locore.S Fri Nov 25 14:12:55 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.113 2016/11/11 11:34:51 maxv Exp $ */
+/* $NetBSD: locore.S,v 1.114 2016/11/25 14:12:55 maxv Exp $ */
/*
* Copyright-o-rama!
@@ -313,16 +313,6 @@
*/
.data
-#if NLAPIC > 0
- .align PAGE_SIZE
- .globl _C_LABEL(local_apic)
-
- .type _C_LABEL(local_apic), @object
-LABEL(local_apic)
- .space PAGE_SIZE
-END(local_apic)
-#endif
-
.globl _C_LABEL(tablesize)
.globl _C_LABEL(nox_flag)
.globl _C_LABEL(cputype)
Index: src/sys/arch/amd64/amd64/vector.S
diff -u src/sys/arch/amd64/amd64/vector.S:1.47 src/sys/arch/amd64/amd64/vector.S:1.48
--- src/sys/arch/amd64/amd64/vector.S:1.47 Fri Aug 19 19:04:57 2016
+++ src/sys/arch/amd64/amd64/vector.S Fri Nov 25 14:12:55 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: vector.S,v 1.47 2016/08/19 19:04:57 maxv Exp $ */
+/* $NetBSD: vector.S,v 1.48 2016/11/25 14:12:55 maxv Exp $ */
/*-
* Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc.
@@ -123,7 +123,8 @@ IDTVEC(intr_lapic_ipi)
pushq $0
pushq $T_ASTFLT
INTRENTRY
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movq _C_LABEL(local_apic_va),%rbx
+ movl $0,LAPIC_EOI(%rbx)
movl CPUVAR(ILEVEL),%ebx
cmpl $IPL_HIGH,%ebx
jae 2f
@@ -149,7 +150,8 @@ IDTVEC(intrddb)
INTRENTRY
movl $0xf,%eax
movq %rax,%cr8
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movq _C_LABEL(local_apic_va),%rbx
+ movl $0,LAPIC_EOI(%rbx)
sti
call _C_LABEL(ddb_ipi)
xorl %eax,%eax
@@ -174,7 +176,8 @@ IDTVEC(intr_lapic_ltimer)
pushq $0
pushq $T_ASTFLT
INTRENTRY
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movq _C_LABEL(local_apic_va),%rbx
+ movl $0,LAPIC_EOI(%rbx)
movl CPUVAR(ILEVEL),%ebx
cmpl $IPL_CLOCK,%ebx
jae 2f
@@ -203,7 +206,8 @@ IDTVEC(intr_lapic_tlb)
pushq $0
pushq $T_ASTFLT
INTRENTRY
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movq _C_LABEL(local_apic_va),%rax
+ movl $0,LAPIC_EOI(%rax)
callq _C_LABEL(pmap_tlb_intr)
INTRFASTEXIT
IDTVEC_END(intr_lapic_tlb)
Index: src/sys/arch/amd64/include/i82093reg.h
diff -u src/sys/arch/amd64/include/i82093reg.h:1.6 src/sys/arch/amd64/include/i82093reg.h:1.7
--- src/sys/arch/amd64/include/i82093reg.h:1.6 Thu Aug 11 15:45:39 2016
+++ src/sys/arch/amd64/include/i82093reg.h Fri Nov 25 14:12:55 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: i82093reg.h,v 1.6 2016/08/11 15:45:39 maxv Exp $ */
+/* $NetBSD: i82093reg.h,v 1.7 2016/11/25 14:12:55 maxv Exp $ */
#include <x86/i82093reg.h>
@@ -9,7 +9,8 @@
#endif
#define ioapic_asm_ack(num) \
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movq _C_LABEL(local_apic_va),%rax ; \
+ movl $0,LAPIC_EOI(%rax)
#ifdef MULTIPROCESSOR
Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.140 src/sys/arch/i386/i386/locore.S:1.141
--- src/sys/arch/i386/i386/locore.S:1.140 Fri Nov 11 11:34:51 2016
+++ src/sys/arch/i386/i386/locore.S Fri Nov 25 14:12:55 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: locore.S,v 1.140 2016/11/11 11:34:51 maxv Exp $ */
+/* $NetBSD: locore.S,v 1.141 2016/11/25 14:12:55 maxv Exp $ */
/*
* Copyright-o-rama!
@@ -128,7 +128,7 @@
*/
#include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.140 2016/11/11 11:34:51 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.141 2016/11/25 14:12:55 maxv Exp $");
#include "opt_compat_oldboot.h"
#include "opt_copy_symtab.h"
@@ -270,16 +270,6 @@ __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1
*/
.data
-#if NLAPIC > 0
- .align PAGE_SIZE
- .globl _C_LABEL(local_apic)
-
- .type _C_LABEL(local_apic), @object
-LABEL(local_apic)
- .space PAGE_SIZE
-END(local_apic)
-#endif
-
.globl _C_LABEL(tablesize)
.globl _C_LABEL(nox_flag)
.globl _C_LABEL(cputype)
Index: src/sys/arch/i386/i386/vector.S
diff -u src/sys/arch/i386/i386/vector.S:1.67 src/sys/arch/i386/i386/vector.S:1.68
--- src/sys/arch/i386/i386/vector.S:1.67 Sun Nov 13 12:38:14 2016
+++ src/sys/arch/i386/i386/vector.S Fri Nov 25 14:12:55 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: vector.S,v 1.67 2016/11/13 12:38:14 maxv Exp $ */
+/* $NetBSD: vector.S,v 1.68 2016/11/25 14:12:55 maxv Exp $ */
/*
* Copyright 2002 (c) Wasabi Systems, Inc.
@@ -65,7 +65,7 @@
*/
#include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.67 2016/11/13 12:38:14 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vector.S,v 1.68 2016/11/25 14:12:55 maxv Exp $");
#include "opt_ddb.h"
#include "opt_multiprocessor.h"
@@ -162,7 +162,8 @@ IDTVEC(intr_lapic_ipi)
pushl $0
pushl $T_ASTFLT
INTRENTRY
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movl _C_LABEL(local_apic_va),%ebx
+ movl $0,LAPIC_EOI(%ebx)
movl CPUVAR(ILEVEL),%ebx
cmpl $IPL_HIGH,%ebx
jae 2f
@@ -188,7 +189,8 @@ IDTVEC(intr_lapic_tlb)
pushl $0
pushl $T_ASTFLT
INTRENTRY
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movl _C_LABEL(local_apic_va),%eax
+ movl $0,LAPIC_EOI(%eax)
call _C_LABEL(pmap_tlb_intr)
INTRFASTEXIT
IDTVEC_END(intr_lapic_tlb)
@@ -205,12 +207,15 @@ IDTVEC(intrddbipi)
movzwl (%eax),%eax
GET_TSS
pushl %eax
- movl $0xff,_C_LABEL(local_apic)+LAPIC_TPRI
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movl _C_LABEL(local_apic_va),%ebx
+ movl $0xff,LAPIC_TPRI(%ebx)
+ movl _C_LABEL(local_apic_va),%ebx
+ movl $0,LAPIC_EOI(%ebx)
sti
call _C_LABEL(ddb_ipi_tss)
addl $4,%esp
- movl $0,_C_LABEL(local_apic)+LAPIC_TPRI
+ movl _C_LABEL(local_apic_va),%ebx
+ movl $0,LAPIC_TPRI(%ebx)
iret
jmp 1b
IDTVEC_END(intrddbipi)
@@ -233,7 +238,8 @@ IDTVEC(intr_lapic_ltimer)
pushl $0
pushl $T_ASTFLT
INTRENTRY
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movl _C_LABEL(local_apic_va),%ebx
+ movl $0,LAPIC_EOI(%ebx)
movl CPUVAR(ILEVEL),%ebx
cmpl $IPL_CLOCK,%ebx
jae 2f
Index: src/sys/arch/i386/include/i82093reg.h
diff -u src/sys/arch/i386/include/i82093reg.h:1.8 src/sys/arch/i386/include/i82093reg.h:1.9
--- src/sys/arch/i386/include/i82093reg.h:1.8 Thu Jul 3 14:02:25 2008
+++ src/sys/arch/i386/include/i82093reg.h Fri Nov 25 14:12:55 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: i82093reg.h,v 1.8 2008/07/03 14:02:25 drochner Exp $ */
+/* $NetBSD: i82093reg.h,v 1.9 2016/11/25 14:12:55 maxv Exp $ */
#include <x86/i82093reg.h>
@@ -9,7 +9,8 @@
#endif
#define ioapic_asm_ack(num) \
- movl $0,_C_LABEL(local_apic)+LAPIC_EOI
+ movl _C_LABEL(local_apic_va),%eax ; \
+ movl $0,LAPIC_EOI(%eax)
#ifdef MULTIPROCESSOR
Index: src/sys/arch/x86/include/i82489var.h
diff -u src/sys/arch/x86/include/i82489var.h:1.15 src/sys/arch/x86/include/i82489var.h:1.16
--- src/sys/arch/x86/include/i82489var.h:1.15 Sun Oct 16 10:51:31 2016
+++ src/sys/arch/x86/include/i82489var.h Fri Nov 25 14:12:56 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: i82489var.h,v 1.15 2016/10/16 10:51:31 maxv Exp $ */
+/* $NetBSD: i82489var.h,v 1.16 2016/11/25 14:12:56 maxv Exp $ */
/*-
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -40,20 +40,19 @@ static __inline uint32_t i82489_readreg(
static __inline void i82489_writereg(int, uint32_t);
#ifdef _KERNEL
-extern volatile uint32_t local_apic[];
+extern volatile vaddr_t local_apic_va;
#endif
static __inline uint32_t
i82489_readreg(int reg)
{
- return *((volatile uint32_t *)(((volatile uint8_t *)local_apic)
- + reg));
+ return *((volatile uint32_t *)(local_apic_va + reg));
}
static __inline void
i82489_writereg(int reg, uint32_t val)
{
- *((volatile uint32_t *)(((volatile uint8_t *)local_apic) + reg)) = val;
+ *((volatile uint32_t *)(local_apic_va + reg)) = val;
}
#define lapic_cpu_number() (i82489_readreg(LAPIC_ID) >> LAPIC_ID_SHIFT)
Index: src/sys/arch/x86/x86/lapic.c
diff -u src/sys/arch/x86/x86/lapic.c:1.53 src/sys/arch/x86/x86/lapic.c:1.54
--- src/sys/arch/x86/x86/lapic.c:1.53 Sat Oct 15 09:50:27 2016
+++ src/sys/arch/x86/x86/lapic.c Fri Nov 25 14:12:56 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: lapic.c,v 1.53 2016/10/15 09:50:27 maxv Exp $ */
+/* $NetBSD: lapic.c,v 1.54 2016/11/25 14:12:56 maxv Exp $ */
/*-
* Copyright (c) 2000, 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.53 2016/10/15 09:50:27 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lapic.c,v 1.54 2016/11/25 14:12:56 maxv Exp $");
#include "opt_ddb.h"
#include "opt_mpbios.h" /* for MPDEBUG */
@@ -93,7 +93,7 @@ static void
lapic_map(paddr_t lapic_base)
{
pt_entry_t *pte;
- vaddr_t va = (vaddr_t)&local_apic;
+ vaddr_t va = local_apic_va;
/*
* If the CPU has an APIC MSR, use it and ignore the supplied value:
Index: src/sys/arch/x86/x86/pmap.c
diff -u src/sys/arch/x86/x86/pmap.c:1.227 src/sys/arch/x86/x86/pmap.c:1.228
--- src/sys/arch/x86/x86/pmap.c:1.227 Thu Nov 17 16:32:06 2016
+++ src/sys/arch/x86/x86/pmap.c Fri Nov 25 14:12:56 2016
@@ -1,4 +1,4 @@
-/* $NetBSD: pmap.c,v 1.227 2016/11/17 16:32:06 maxv Exp $ */
+/* $NetBSD: pmap.c,v 1.228 2016/11/25 14:12:56 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.227 2016/11/17 16:32:06 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmap.c,v 1.228 2016/11/25 14:12:56 maxv Exp $");
#include "opt_user_ldt.h"
#include "opt_lockdebug.h"
@@ -483,6 +483,11 @@ static vaddr_t virtual_avail __read_most
static vaddr_t virtual_end __read_mostly; /* VA of last free KVA */
/*
+ * LAPIC virtual address.
+ */
+volatile vaddr_t local_apic_va;
+
+/*
* pool that pmap structures are allocated from
*/
static struct pool_cache pmap_cache;
@@ -554,6 +559,7 @@ extern vaddr_t pentium_idt_vaddr;
* Local prototypes
*/
+static void pmap_init_lapic(void);
#ifdef __HAVE_DIRECT_MAP
static void pmap_init_directmap(struct pmap *);
#endif
@@ -1324,6 +1330,8 @@ pmap_bootstrap(vaddr_t kva_start)
}
#endif /* !XEN */
+ pmap_init_lapic();
+
#ifdef __HAVE_DIRECT_MAP
pmap_init_directmap(kpm);
#else
@@ -1456,6 +1464,12 @@ pmap_bootstrap(vaddr_t kva_start)
pmap_maxkvaddr = kva;
}
+static void
+pmap_init_lapic(void)
+{
+ local_apic_va = pmap_bootstrap_valloc(1);
+}
+
#ifdef __HAVE_DIRECT_MAP
/*
* Create the amd64 direct map. Called only once at boot time.