Source-Changes-HG archive

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

[src/trunk]: src/sys x86: Split most of pmap.h into pmap_private.h or vmparam.h.



details:   https://anonhg.NetBSD.org/src/rev/79518809b26d
branches:  trunk
changeset: 369533:79518809b26d
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Sat Aug 20 23:48:50 2022 +0000

description:
x86: Split most of pmap.h into pmap_private.h or vmparam.h.

This way pmap.h only contains the MD definition of the MI pmap(9)
API, which loads of things in the kernel rely on, so changing x86
pmap internals no longer requires recompiling the entire kernel every
time.

Callers needing these internals must now use machine/pmap_private.h.
Note: This is not x86/pmap_private.h because it contains three parts:

1. CPU-specific (different for i386/amd64) definitions used by...

2. common definitions, including Xenisms like xpmap_ptetomach,
   further used by...

3. more CPU-specific inlines for pmap_pte_* operations

So {amd64,i386}/pmap_private.h defines 1, includes x86/pmap_private.h
for 2, and then defines 3.  Maybe we should split that out into a new
pmap_pte.h to reduce this trouble.

No functional change intended, other than that some .c files must
include machine/pmap_private.h when previously uvm/uvm_pmap.h
polluted the namespace with pmap internals.

Note: This migrates part of i386/pmap.h into i386/vmparam.h --
specifically the parts that are needed for several constants defined
in vmparam.h:

VM_MAXUSER_ADDRESS
VM_MAX_ADDRESS
VM_MAX_KERNEL_ADDRESS
VM_MIN_KERNEL_ADDRESS

Since i386 needs PDP_SIZE in vmparam.h, I added it there on amd64
too, just to keep things parallel.

diffstat:

 sys/arch/amd64/amd64/gdt.c            |    5 +-
 sys/arch/amd64/amd64/genassym.cf      |    3 +-
 sys/arch/amd64/amd64/machdep.c        |    6 +-
 sys/arch/amd64/include/pmap.h         |  314 +--------------------------
 sys/arch/amd64/include/pmap_private.h |  316 ++++++++++++++++++++++++++
 sys/arch/amd64/include/vmparam.h      |    4 +-
 sys/arch/i386/i386/dumpsys.c          |    5 +-
 sys/arch/i386/i386/gdt.c              |    5 +-
 sys/arch/i386/i386/genassym.cf        |    3 +-
 sys/arch/i386/i386/machdep.c          |    5 +-
 sys/arch/i386/i386/trap.c             |    5 +-
 sys/arch/i386/include/pmap.h          |  401 +---------------------------------
 sys/arch/i386/include/pmap_private.h  |  370 +++++++++++++++++++++++++++++++
 sys/arch/i386/include/vmparam.h       |   44 +++-
 sys/arch/x86/acpi/acpi_machdep.c      |    5 +-
 sys/arch/x86/include/pmap.h           |  233 +-------------------
 sys/arch/x86/include/pmap_private.h   |  316 ++++++++++++++++++++++++++
 sys/arch/x86/x86/bus_dma.c            |    5 +-
 sys/arch/x86/x86/cpu.c                |    5 +-
 sys/arch/x86/x86/db_memrw.c           |    5 +-
 sys/arch/x86/x86/idt.c                |    5 +-
 sys/arch/x86/x86/lapic.c              |    5 +-
 sys/arch/x86/x86/patch.c              |    5 +-
 sys/arch/x86/x86/pmap.c               |    5 +-
 sys/arch/x86/x86/svs.c                |    6 +-
 sys/arch/x86/x86/x86_machdep.c        |    5 +-
 sys/arch/x86/x86/x86_tlb.c            |    6 +-
 sys/arch/xen/x86/cpu.c                |    5 +-
 sys/arch/xen/x86/hypervisor_machdep.c |    5 +-
 sys/arch/xen/x86/x86_xpmap.c          |    5 +-
 sys/arch/xen/x86/xen_bus_dma.c        |    7 +-
 sys/arch/xen/x86/xen_pmap.c           |    5 +-
 sys/arch/xen/x86/xenfunc.c            |    5 +-
 sys/arch/xen/xen/xen_machdep.c        |    6 +-
 sys/dev/nvmm/x86/nvmm_x86_svm.c       |    5 +-
 sys/dev/nvmm/x86/nvmm_x86_vmx.c       |    5 +-
 36 files changed, 1138 insertions(+), 1002 deletions(-)

diffs (truncated from 2856 to 300 lines):

diff -r d33c31d09247 -r 79518809b26d sys/arch/amd64/amd64/gdt.c
--- a/sys/arch/amd64/amd64/gdt.c        Sat Aug 20 23:37:12 2022 +0000
+++ b/sys/arch/amd64/amd64/gdt.c        Sat Aug 20 23:48:50 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gdt.c,v 1.47 2019/03/09 08:42:25 maxv Exp $    */
+/*     $NetBSD: gdt.c,v 1.48 2022/08/20 23:48:50 riastradh Exp $       */
 
 /*
  * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc.
@@ -37,7 +37,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.47 2019/03/09 08:42:25 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.48 2022/08/20 23:48:50 riastradh Exp $");
 
 #include "opt_multiprocessor.h"
 #include "opt_xen.h"
@@ -52,6 +52,7 @@
 #include <uvm/uvm.h>
 
 #include <machine/gdt.h>
+#include <machine/pmap_private.h>
 
 #ifdef XENPV
 #include <xen/hypervisor.h>
diff -r d33c31d09247 -r 79518809b26d sys/arch/amd64/amd64/genassym.cf
--- a/sys/arch/amd64/amd64/genassym.cf  Sat Aug 20 23:37:12 2022 +0000
+++ b/sys/arch/amd64/amd64/genassym.cf  Sat Aug 20 23:48:50 2022 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: genassym.cf,v 1.87 2022/06/12 11:36:42 bouyer Exp $
+#      $NetBSD: genassym.cf,v 1.88 2022/08/20 23:48:50 riastradh Exp $
 
 #
 # Copyright (c) 1998, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -93,6 +93,7 @@
 
 include <machine/trap.h>
 include <machine/pmap.h>
+include <machine/pmap_private.h>
 include <machine/vmparam.h>
 include <machine/intr.h>
 include <machine/types.h>
diff -r d33c31d09247 -r 79518809b26d sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Sat Aug 20 23:37:12 2022 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Sat Aug 20 23:48:50 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.362 2022/08/20 23:15:36 riastradh Exp $  */
+/*     $NetBSD: machdep.c,v 1.363 2022/08/20 23:48:50 riastradh 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.362 2022/08/20 23:15:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.363 2022/08/20 23:48:50 riastradh Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -182,12 +182,12 @@
 #include <x86/dbregs.h>
 #include <machine/mtrr.h>
 #include <machine/mpbiosvar.h>
+#include <machine/pmap_private.h>
 
 #include <x86/bootspace.h>
 #include <x86/cputypes.h>
 #include <x86/cpuvar.h>
 #include <x86/machdep.h>
-
 #include <x86/x86/tsc.h>
 
 #include <dev/isa/isareg.h>
diff -r d33c31d09247 -r 79518809b26d sys/arch/amd64/include/pmap.h
--- a/sys/arch/amd64/include/pmap.h     Sat Aug 20 23:37:12 2022 +0000
+++ b/sys/arch/amd64/include/pmap.h     Sat Aug 20 23:48:50 2022 +0000
@@ -1,316 +1,4 @@
-/*     $NetBSD: pmap.h,v 1.67 2022/08/20 23:18:20 riastradh Exp $      */
-
-/*
- * Copyright (c) 1997 Charles D. Cranor and Washington University.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/*
- * Copyright (c) 2001 Wasabi Systems, Inc.
- * All rights reserved.
- *
- * Written by Frank van der Linden for Wasabi Systems, Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *      This product includes software developed for the NetBSD Project by
- *      Wasabi Systems, Inc.
- * 4. The name of Wasabi Systems, Inc. may not be used to endorse
- *    or promote products derived from this software without specific prior
- *    written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
- * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
- * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- * POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef        _AMD64_PMAP_H_
-#define        _AMD64_PMAP_H_
-
-#ifdef __x86_64__
-
-#if defined(_KERNEL_OPT)
-#include "opt_xen.h"
-#include "opt_kasan.h"
-#include "opt_kmsan.h"
-#include "opt_kubsan.h"
-#endif
-
-#include <sys/atomic.h>
-
-#include <machine/pte.h>
-#include <machine/segments.h>
-#ifdef _KERNEL
-#include <machine/cpufunc.h>
-#endif
-
-#include <uvm/uvm_object.h>
-#ifdef XENPV
-#include <xen/xenfunc.h>
-#include <xen/xenpmap.h>
-#endif
-
-/*
- * Mask to get rid of the sign-extended part of addresses.
- */
-#define VA_SIGN_MASK           0xffff000000000000
-#define VA_SIGN_NEG(va)                ((va) | VA_SIGN_MASK)
-/* XXXfvdl this one's not right. */
-#define VA_SIGN_POS(va)                ((va) & ~VA_SIGN_MASK)
-
-#ifdef KASAN
-#define L4_SLOT_KASAN          256
-#define NL4_SLOT_KASAN         32
-#endif
-
-#ifdef KMSAN
-#define L4_SLOT_KMSAN          256
-#define NL4_SLOT_KMSAN         4
-#endif
-
-#define NL4_SLOT_DIRECT                32
-
-#ifndef XENPV
-#define L4_SLOT_PTE            slotspace.area[SLAREA_PTE].sslot
-#else
-#define L4_SLOT_PTE            509
-#endif
-#define L4_SLOT_KERN           slotspace.area[SLAREA_MAIN].sslot
-#define L4_SLOT_KERNBASE       511 /* pl4_i(KERNBASE) */
-
-#define PDIR_SLOT_USERLIM      255
-#define PDIR_SLOT_KERN L4_SLOT_KERN
-#define PDIR_SLOT_PTE  L4_SLOT_PTE
-
-/*
- * The following defines give the virtual addresses of various MMU
- * data structures:
- * PTE_BASE: the base VA of the linear PTE mappings
- * PDP_BASE: the base VA of the recursive mapping of the PTD
- */
-
-#ifndef XENPV
-extern pt_entry_t *pte_base;
-#define PTE_BASE       pte_base
-#else
-#define PTE_BASE       ((pt_entry_t *)VA_SIGN_NEG((L4_SLOT_PTE * NBPD_L4)))
-#endif
-
-#define L1_BASE        PTE_BASE
-#define L2_BASE        ((pd_entry_t *)((char *)L1_BASE + L4_SLOT_PTE * NBPD_L3))
-#define L3_BASE        ((pd_entry_t *)((char *)L2_BASE + L4_SLOT_PTE * NBPD_L2))
-#define L4_BASE        ((pd_entry_t *)((char *)L3_BASE + L4_SLOT_PTE * NBPD_L1))
-
-#define PDP_BASE       L4_BASE
-
-#if defined(KMSAN)
-#define NKL4_MAX_ENTRIES       (unsigned long)1        /* 512GB only */
-#else
-#define NKL4_MAX_ENTRIES       (unsigned long)64
-#endif
-#define NKL3_MAX_ENTRIES       (unsigned long)(NKL4_MAX_ENTRIES * 512)
-#define NKL2_MAX_ENTRIES       (unsigned long)(NKL3_MAX_ENTRIES * 512)
-#define NKL1_MAX_ENTRIES       (unsigned long)(NKL2_MAX_ENTRIES * 512)
-
-#define NKL4_KIMG_ENTRIES      1
-#define NKL3_KIMG_ENTRIES      1
-#if defined(KUBSAN) || defined(KMSAN)
-#define NKL2_KIMG_ENTRIES      64      /* really big kernel */
-#else
-#define NKL2_KIMG_ENTRIES      48
-#endif
-
-/*
- * Since kva space is below the kernel in its entirety, we start off
- * with zero entries on each level.
- */
-#define NKL4_START_ENTRIES     0
-#define NKL3_START_ENTRIES     0
-#define NKL2_START_ENTRIES     0
-#define NKL1_START_ENTRIES     0
-
-#define PTP_MASK_INITIALIZER   { L1_MASK, L2_MASK, L3_MASK, L4_MASK }
-#define PTP_FRAME_INITIALIZER  { L1_FRAME, L2_FRAME, L3_FRAME, L4_FRAME }
-#define PTP_SHIFT_INITIALIZER  { L1_SHIFT, L2_SHIFT, L3_SHIFT, L4_SHIFT }
-#define NKPTP_INITIALIZER      { NKL1_START_ENTRIES, NKL2_START_ENTRIES, \
-                                 NKL3_START_ENTRIES, NKL4_START_ENTRIES }
-#define NKPTPMAX_INITIALIZER   { NKL1_MAX_ENTRIES, NKL2_MAX_ENTRIES, \
-                                 NKL3_MAX_ENTRIES, NKL4_MAX_ENTRIES }
-#define NBPD_INITIALIZER       { NBPD_L1, NBPD_L2, NBPD_L3, NBPD_L4 }
-#define PDES_INITIALIZER       { L2_BASE, L3_BASE, L4_BASE }
+/*     $NetBSD: pmap.h,v 1.68 2022/08/20 23:48:50 riastradh Exp $      */
 
 #define PTP_LEVELS     4
-
-/*
- * PTE_AVL usage: we make use of the ignored bits of the PTE
- */
-#define PTE_WIRED      PTE_AVL1        /* Wired Mapping */
-#define PTE_PVLIST     PTE_AVL2        /* Mapping has entry on pvlist */
-#define PTE_X          0               /* Dummy */
-
-/* XXX To be deleted. */
-#define PG_W           PTE_WIRED
-#define PG_PVLIST      PTE_PVLIST
-#define PG_X           PTE_X
-
-void svs_pmap_sync(struct pmap *, int);
-void svs_ldt_sync(struct pmap *);
-void svs_lwp_switch(struct lwp *, struct lwp *);
-void svs_pdir_switch(struct pmap *);
-void svs_init(void);
-extern bool svs_enabled;
-extern bool svs_pcid;
-
 #include <x86/pmap.h>
-
-#ifndef XENPV
-#define pmap_pa2pte(a)                 (a)
-#define pmap_pte2pa(a)                 ((a) & PTE_FRAME)
-#define pmap_pte_set(p, n)             do { *(p) = (n); } while (0)
-#define pmap_pte_cas(p, o, n)          atomic_cas_64((p), (o), (n))
-#define pmap_pte_testset(p, n)         \
-    atomic_swap_ulong((volatile unsigned long *)p, n)
-#define pmap_pte_setbits(p, b)         \
-    atomic_or_ulong((volatile unsigned long *)p, b)
-#define pmap_pte_clearbits(p, b)       \
-    atomic_and_ulong((volatile unsigned long *)p, ~(b))
-#define pmap_pte_flush()               /* nothing */
-#else
-extern kmutex_t pte_lock;
-
-static __inline pt_entry_t
-pmap_pa2pte(paddr_t pa)
-{
-       return (pt_entry_t)xpmap_ptom_masked(pa);



Home | Main Index | Thread Index | Old Index