Source-Changes-HG archive

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

[src/trunk]: src/sys Make the direct-map API always available, but fail if KA...



details:   https://anonhg.NetBSD.org/src/rev/3cb442eb93c6
branches:  trunk
changeset: 994603:3cb442eb93c6
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Thu Nov 15 04:59:02 2018 +0000

description:
Make the direct-map API always available, but fail if KASAN or rump.

(Only for architectures that support it at all; on others,
__HAVE_MM_MD_DIRECT_MAPPED_PHYS/IO are still undefined and the
functions unimplemented.)

This gives modules like zfs an opportunity to use it.

While here, fix the one caller of mm_md_direct_mapped_phys that
ignored the return value (and make sure to call pmap_kremove/update
before uvm_km_free).

diffstat:

 sys/arch/amd64/amd64/machdep.c                                  |  15 ++-
 sys/arch/amd64/include/types.h                                  |   6 +-
 sys/arch/x86/x86/efi.c                                          |  31 ++++--
 sys/rump/librump/rumpkern/arch/generic/Makefile.inc             |   3 +-
 sys/rump/librump/rumpkern/arch/generic/rump_generic_directmap.c |  47 ++++++++++
 sys/rump/librump/rumpkern/arch/x86_64/Makefile.inc              |   5 +-
 6 files changed, 88 insertions(+), 19 deletions(-)

diffs (246 lines):

diff -r 42979f03f155 -r 3cb442eb93c6 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Thu Nov 15 04:57:00 2018 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Thu Nov 15 04:59:02 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.321 2018/11/11 10:58:40 maxv Exp $       */
+/*     $NetBSD: machdep.c,v 1.322 2018/11/15 04:59:02 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.321 2018/11/11 10:58:40 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.322 2018/11/15 04:59:02 riastradh Exp $");
 
 #include "opt_modular.h"
 #include "opt_user_ldt.h"
@@ -2285,23 +2285,30 @@
        kpreempt_enable();
 }
 
-#ifdef __HAVE_DIRECT_MAP
 bool
 mm_md_direct_mapped_io(void *addr, paddr_t *paddr)
 {
        vaddr_t va = (vaddr_t)addr;
 
+#ifdef __HAVE_DIRECT_MAP
        if (va >= PMAP_DIRECT_BASE && va < PMAP_DIRECT_END) {
                *paddr = PMAP_DIRECT_UNMAP(va);
                return true;
        }
+#else
+       __USE(va);
+#endif
+
        return false;
 }
 
 bool
 mm_md_direct_mapped_phys(paddr_t paddr, vaddr_t *vaddr)
 {
+#ifdef __HAVE_DIRECT_MAP
        *vaddr = PMAP_DIRECT_MAP(paddr);
        return true;
+#else
+       return false;
+#endif
 }
-#endif
diff -r 42979f03f155 -r 3cb442eb93c6 sys/arch/amd64/include/types.h
--- a/sys/arch/amd64/include/types.h    Thu Nov 15 04:57:00 2018 +0000
+++ b/sys/arch/amd64/include/types.h    Thu Nov 15 04:59:02 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: types.h,v 1.57 2018/08/20 15:04:51 maxv Exp $  */
+/*     $NetBSD: types.h,v 1.58 2018/11/15 04:59:02 riastradh Exp $     */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -94,6 +94,8 @@
 #define        __HAVE_INTR_CONTROL
 #define        __HAVE_CPU_RNG
 #define        __HAVE_COMPAT_NETBSD32
+#define        __HAVE_MM_MD_DIRECT_MAPPED_IO
+#define        __HAVE_MM_MD_DIRECT_MAPPED_PHYS
 
 #ifdef _KERNEL_OPT
 #define        __HAVE_RAS
@@ -104,8 +106,6 @@
 #if !defined(KASAN)
 #define        __HAVE_PCPU_AREA 1
 #define        __HAVE_DIRECT_MAP 1
-#define        __HAVE_MM_MD_DIRECT_MAPPED_IO
-#define        __HAVE_MM_MD_DIRECT_MAPPED_PHYS
 #endif
 #if !defined(NO_PCI_MSI_MSIX)
 #define        __HAVE_PCI_MSI_MSIX
diff -r 42979f03f155 -r 3cb442eb93c6 sys/arch/x86/x86/efi.c
--- a/sys/arch/x86/x86/efi.c    Thu Nov 15 04:57:00 2018 +0000
+++ b/sys/arch/x86/x86/efi.c    Thu Nov 15 04:59:02 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: efi.c,v 1.15 2018/05/19 17:18:57 jakllsch Exp $        */
+/*     $NetBSD: efi.c,v 1.16 2018/11/15 04:59:02 riastradh Exp $       */
 
 /*-
  * Copyright (c) 2016 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.15 2018/05/19 17:18:57 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: efi.c,v 1.16 2018/11/15 04:59:02 riastradh Exp $");
 
 #include <sys/kmem.h>
 #include <sys/param.h>
@@ -55,6 +55,7 @@
 bool           efi_uuideq(const struct uuid *, const struct uuid *);
 
 static bool efi_is32x64 = false;
+static paddr_t efi_systbl_pa = NULL;
 static struct efi_systbl *efi_systbl_va = NULL;
 static struct efi_cfgtbl *efi_cfgtblhead_va = NULL;
 static struct efi_e820memmap {
@@ -72,8 +73,10 @@
        vaddr_t va;
 
 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
-       mm_md_direct_mapped_phys(pa, &va);
-#else
+       if (mm_md_direct_mapped_phys(pa, &va))
+               return va;
+#endif
+
        /* XXX This code path is not tested. */
        va = uvm_km_alloc(kernel_map, PAGE_SIZE, 0,
            UVM_KMF_VAONLY | UVM_KMF_WAITVA);
@@ -83,7 +86,7 @@
        }
        pmap_kenter_pa(va, pa, VM_PROT_READ, 0);
        pmap_update(pmap_kernel());
-#endif
+
        return va;
 }
 
@@ -91,14 +94,21 @@
  * Free a virtual address (VA) allocated using efi_getva().
  */
 static void
-efi_relva(vaddr_t va)
+efi_relva(paddr_t pa, vaddr_t va)
 {
+
 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
-       /* XXX Should we free the va? */
-#else
+       vaddr_t va0 __diagused;
+       if (mm_md_direct_mapped_phys(pa, &va0)) {
+               KASSERT(va0 == va);
+               return;
+       }
+#endif
+
        /* XXX This code path is not tested. */
+       pmap_kremove(va, PAGE_SIZE);
+       pmap_update(pmap_kernel());
        uvm_km_free(kernel_map, va, PAGE_SIZE, UVM_KMF_VAONLY);
-#endif
 }
 
 /*
@@ -326,6 +336,7 @@
                return NULL;
 
        aprint_normal("efi: systbl at pa %" PRIxPADDR "\n", pa);
+       efi_systbl_pa = pa;
        va = efi_getva(pa);
        aprint_debug("efi: systbl mapped at va %" PRIxVADDR "\n", va);
 
@@ -403,7 +414,7 @@
        }
        if (efi_getcfgtblhead() == NULL) {
                aprint_debug("efi: missing or invalid cfgtbl\n");
-               efi_relva((vaddr_t) efi_systbl_va);
+               efi_relva(efi_systbl_pa, (vaddr_t) efi_systbl_va);
                bootmethod_efi = false;
                return;
        }
diff -r 42979f03f155 -r 3cb442eb93c6 sys/rump/librump/rumpkern/arch/generic/Makefile.inc
--- a/sys/rump/librump/rumpkern/arch/generic/Makefile.inc       Thu Nov 15 04:57:00 2018 +0000
+++ b/sys/rump/librump/rumpkern/arch/generic/Makefile.inc       Thu Nov 15 04:59:02 2018 +0000
@@ -1,5 +1,6 @@
-#      $NetBSD: Makefile.inc,v 1.2 2015/04/22 18:12:39 pooka Exp $
+#      $NetBSD: Makefile.inc,v 1.3 2018/11/15 04:59:02 riastradh Exp $
 #
 
 SRCS+= rump_generic_cpu.c rump_generic_kobj.c rump_generic_pmap.c
 SRCS+= rump_generic_abi.c
+SRCS+= rump_generic_directmap.c
diff -r 42979f03f155 -r 3cb442eb93c6 sys/rump/librump/rumpkern/arch/generic/rump_generic_directmap.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/rump/librump/rumpkern/arch/generic/rump_generic_directmap.c   Thu Nov 15 04:59:02 2018 +0000
@@ -0,0 +1,47 @@
+/*     $NetBSD: rump_generic_directmap.c,v 1.1 2018/11/15 04:59:02 riastradh Exp $     */
+
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * 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 NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``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 FOUNDATION OR CONTRIBUTORS
+ * 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.
+ */
+
+#include <sys/types.h>
+
+#include <dev/mm.h>
+
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_IO
+bool
+mm_md_direct_mapped_io(void *ptr, paddr_t *pap)
+{
+       return false;
+}
+#endif
+
+#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
+bool
+mm_md_direct_mapped_phys(paddr_t pa, vaddr_t *vap)
+{
+       return false;
+}
+#endif
diff -r 42979f03f155 -r 3cb442eb93c6 sys/rump/librump/rumpkern/arch/x86_64/Makefile.inc
--- a/sys/rump/librump/rumpkern/arch/x86_64/Makefile.inc        Thu Nov 15 04:57:00 2018 +0000
+++ b/sys/rump/librump/rumpkern/arch/x86_64/Makefile.inc        Thu Nov 15 04:59:02 2018 +0000
@@ -1,7 +1,10 @@
-#      $NetBSD: Makefile.inc,v 1.8 2014/02/12 22:28:44 pooka Exp $
+#      $NetBSD: Makefile.inc,v 1.9 2018/11/15 04:59:02 riastradh Exp $
 #
 
 .include "${RUMPTOP}/librump/rumpkern/arch/x86/Makefile.inc"
 
 .PATH: ${RUMPTOP}/../arch/amd64/amd64
 SRCS+= kobj_machdep.c
+
+.PATH: ${RUMPTOP}/librump/rumpkern/arch/generic
+SRCS+= rump_generic_directmap.c



Home | Main Index | Thread Index | Old Index