Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Add KASAN-DMA support on aarch64, same as amd64. Di...



details:   https://anonhg.NetBSD.org/src/rev/bc502ccc7b5b
branches:  trunk
changeset: 1009107:bc502ccc7b5b
user:      maxv <maxv%NetBSD.org@localhost>
date:      Mon Apr 13 07:09:50 2020 +0000

description:
Add KASAN-DMA support on aarch64, same as amd64. Discussed with skrll@.

diffstat:

 sys/arch/aarch64/conf/files.aarch64 |    3 +-
 sys/arch/amd64/include/types.h      |    3 +-
 sys/arch/arm/arm/bus_stubs.c        |  104 ++++++++++++++++++++++++++++++++++++
 sys/arch/arm/conf/files.arm         |    4 +-
 sys/arch/arm/include/bus_defs.h     |    8 ++-
 sys/arch/arm/include/bus_funcs.h    |   36 ++++--------
 sys/kern/subr_asan.c                |    8 +--
 7 files changed, 131 insertions(+), 35 deletions(-)

diffs (275 lines):

diff -r 2b75b4fb82a2 -r bc502ccc7b5b sys/arch/aarch64/conf/files.aarch64
--- a/sys/arch/aarch64/conf/files.aarch64       Mon Apr 13 06:24:52 2020 +0000
+++ b/sys/arch/aarch64/conf/files.aarch64       Mon Apr 13 07:09:50 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.aarch64,v 1.20 2020/02/15 08:16:10 skrll Exp $
+#      $NetBSD: files.aarch64,v 1.21 2020/04/13 07:09:50 maxv Exp $
 
 defflag opt_cpuoptions.h       AARCH64_ALIGNMENT_CHECK
 defflag opt_cpuoptions.h       AARCH64_EL0_STACK_ALIGNMENT_CHECK
@@ -86,6 +86,7 @@
 file   arch/arm/arm/arm_cpu_topology.c
 file   arch/arm/arm/arm_generic_dma.c
 file   arch/arm/arm/bootconfig.c
+file   arch/arm/arm/bus_stubs.c
 file   arch/arm/arm/cpu_subr.c
 file   arch/arm/arm32/bus_dma.c
 file   arch/aarch64/aarch64/aarch64_machdep.c
diff -r 2b75b4fb82a2 -r bc502ccc7b5b sys/arch/amd64/include/types.h
--- a/sys/arch/amd64/include/types.h    Mon Apr 13 06:24:52 2020 +0000
+++ b/sys/arch/amd64/include/types.h    Mon Apr 13 07:09:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: types.h,v 1.65 2020/03/17 17:18:49 maxv Exp $  */
+/*     $NetBSD: types.h,v 1.66 2020/04/13 07:09:50 maxv Exp $  */
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -109,7 +109,6 @@
 #include "opt_kmsan.h"
 #ifdef KASAN
 #define __HAVE_KASAN_INSTR_BUS
-#define __HAVE_KASAN_INSTR_DMA
 #endif
 #if defined(__x86_64__) && !defined(XENPV)
 #if !defined(KASAN) && !defined(KMSAN)
diff -r 2b75b4fb82a2 -r bc502ccc7b5b sys/arch/arm/arm/bus_stubs.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/arm/arm/bus_stubs.c      Mon Apr 13 07:09:50 2020 +0000
@@ -0,0 +1,104 @@
+/*     $NetBSD: bus_stubs.c,v 1.1 2020/04/13 07:09:51 maxv Exp $       */
+
+/*
+ * Copyright (c) 2020 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Maxime Villard.
+ *
+ * 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/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: bus_stubs.c,v 1.1 2020/04/13 07:09:51 maxv Exp $");
+
+#include <sys/systm.h>
+#include <sys/asan.h>
+
+#include <machine/bus_defs.h>
+#include <machine/bus_funcs.h>
+
+int
+bus_dmamap_create(bus_dma_tag_t t, bus_size_t size, int nsegments,
+    bus_size_t maxsegsz, bus_size_t boundary, int flags, bus_dmamap_t *dmamp)
+{
+       return (*t->_dmamap_create)(t, size, nsegments, maxsegsz, boundary,
+           flags, dmamp);
+}
+
+void
+bus_dmamap_destroy(bus_dma_tag_t t, bus_dmamap_t dmam)
+{
+       (*t->_dmamap_destroy)(t, dmam);
+}
+
+int
+bus_dmamap_load(bus_dma_tag_t t, bus_dmamap_t dmam, void *buf,
+    bus_size_t buflen, struct proc *p, int flags)
+{
+       kasan_dma_load(dmam, buf, buflen, KASAN_DMA_LINEAR);
+       return (*t->_dmamap_load)(t, dmam, buf, buflen, p, flags);
+}
+
+int
+bus_dmamap_load_mbuf(bus_dma_tag_t t, bus_dmamap_t dmam, struct mbuf *chain,
+    int flags)
+{
+       kasan_dma_load(dmam, chain, 0, KASAN_DMA_MBUF);
+       return (*t->_dmamap_load_mbuf)(t, dmam, chain, flags);
+}
+
+int
+bus_dmamap_load_uio(bus_dma_tag_t t, bus_dmamap_t dmam, struct uio *uio,
+    int flags)
+{
+       kasan_dma_load(dmam, uio, 0, KASAN_DMA_UIO);
+       return (*t->_dmamap_load_uio)(t, dmam, uio, flags);
+}
+
+int
+bus_dmamap_load_raw(bus_dma_tag_t t, bus_dmamap_t dmam, bus_dma_segment_t *segs,
+    int nsegs, bus_size_t size, int flags)
+{
+       return (*t->_dmamap_load_raw)(t, dmam, segs, nsegs, size, flags);
+}
+
+void
+bus_dmamap_unload(bus_dma_tag_t t, bus_dmamap_t dmam)
+{
+       (*t->_dmamap_unload)(t, dmam);
+}
+
+void
+bus_dmamap_sync(bus_dma_tag_t t, bus_dmamap_t p, bus_addr_t o, bus_size_t l,
+    int ops)
+{
+       kasan_dma_sync(p, o, l, ops);
+
+       if ((ops & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0 &&
+           t->_dmamap_sync_pre != NULL)
+               (*t->_dmamap_sync_pre)(t, p, o, l, ops);
+       else if ((ops & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0 &&
+           t->_dmamap_sync_post != NULL)
+               (*t->_dmamap_sync_post)(t, p, o, l, ops);
+}
diff -r 2b75b4fb82a2 -r bc502ccc7b5b sys/arch/arm/conf/files.arm
--- a/sys/arch/arm/conf/files.arm       Mon Apr 13 06:24:52 2020 +0000
+++ b/sys/arch/arm/conf/files.arm       Mon Apr 13 07:09:50 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.arm,v 1.155 2020/04/13 05:40:25 maxv Exp $
+#      $NetBSD: files.arm,v 1.156 2020/04/13 07:09:51 maxv Exp $
 
 # temporary define to allow easy moving to ../arch/arm/arm32
 defflag                                ARM32
@@ -158,6 +158,8 @@
 file   arch/arm/arm/bus_space_asm_generic.S    bus_space_generic
 file   arch/arm/arm/bus_space_notimpl.S        arm32
 
+file   arch/arm/arm/bus_stubs.c
+
 file   arch/arm/arm/arm_cpu_topology.c
 file   arch/arm/arm/arm_machdep.c
 file   arch/arm/arm/ast.c
diff -r 2b75b4fb82a2 -r bc502ccc7b5b sys/arch/arm/include/bus_defs.h
--- a/sys/arch/arm/include/bus_defs.h   Mon Apr 13 06:24:52 2020 +0000
+++ b/sys/arch/arm/include/bus_defs.h   Mon Apr 13 07:09:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_defs.h,v 1.14 2019/12/28 17:19:43 jmcneill Exp $   */
+/*     $NetBSD: bus_defs.h,v 1.15 2020/04/13 07:09:51 maxv Exp $       */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -66,6 +66,7 @@
 
 #if defined(_KERNEL_OPT)
 #include "opt_arm_bus_space.h"
+#include "opt_kasan.h"
 #endif
 
 /*
@@ -484,6 +485,11 @@
        /*
         * PUBLIC MEMBERS: these are used by machine-independent code.
         */
+#if defined(KASAN)
+       void            *dm_buf;
+       bus_size_t      dm_buflen;
+       int             dm_buftype;
+#endif
        bus_size_t      dm_maxsegsz;    /* largest possible segment */
        bus_size_t      dm_mapsize;     /* size of the mapping */
        int             dm_nsegs;       /* # valid segments in mapping */
diff -r 2b75b4fb82a2 -r bc502ccc7b5b sys/arch/arm/include/bus_funcs.h
--- a/sys/arch/arm/include/bus_funcs.h  Mon Apr 13 06:24:52 2020 +0000
+++ b/sys/arch/arm/include/bus_funcs.h  Mon Apr 13 07:09:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bus_funcs.h,v 1.8 2019/07/16 11:32:07 skrll Exp $      */
+/*     $NetBSD: bus_funcs.h,v 1.9 2020/04/13 07:09:51 maxv Exp $       */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2001 The NetBSD Foundation, Inc.
@@ -638,29 +638,17 @@
 struct mbuf;
 struct uio;
 
-#define        bus_dmamap_create(t, s, n, m, b, f, p)                  \
-       (*(t)->_dmamap_create)((t), (s), (n), (m), (b), (f), (p))
-#define        bus_dmamap_destroy(t, p)                                \
-       (*(t)->_dmamap_destroy)((t), (p))
-#define        bus_dmamap_load(t, m, b, s, p, f)                       \
-       (*(t)->_dmamap_load)((t), (m), (b), (s), (p), (f))
-#define        bus_dmamap_load_mbuf(t, m, b, f)                        \
-       (*(t)->_dmamap_load_mbuf)((t), (m), (b), (f))
-#define        bus_dmamap_load_uio(t, m, u, f)                         \
-       (*(t)->_dmamap_load_uio)((t), (m), (u), (f))
-#define        bus_dmamap_load_raw(t, m, sg, n, s, f)                  \
-       (*(t)->_dmamap_load_raw)((t), (m), (sg), (n), (s), (f))
-#define        bus_dmamap_unload(t, p)                                 \
-       (*(t)->_dmamap_unload)((t), (p))
-#define        bus_dmamap_sync(t, p, o, l, ops)                        \
-do {                                                                   \
-       if (((ops) & (BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE)) != 0   \
-           && (t)->_dmamap_sync_pre != NULL)                           \
-               (*(t)->_dmamap_sync_pre)((t), (p), (o), (l), (ops));    \
-       else if (((ops) & (BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE)) != 0 \
-                && (t)->_dmamap_sync_post != NULL)                          \
-               (*(t)->_dmamap_sync_post)((t), (p), (o), (l), (ops));        \
-} while (/*CONSTCOND*/0)
+int bus_dmamap_create(bus_dma_tag_t, bus_size_t, int, bus_size_t, bus_size_t,
+    int, bus_dmamap_t *);
+void bus_dmamap_destroy(bus_dma_tag_t, bus_dmamap_t);
+int bus_dmamap_load(bus_dma_tag_t, bus_dmamap_t, void *, bus_size_t,
+    struct proc *, int);
+int bus_dmamap_load_mbuf(bus_dma_tag_t, bus_dmamap_t, struct mbuf *, int);
+int bus_dmamap_load_uio(bus_dma_tag_t, bus_dmamap_t, struct uio *, int);
+int bus_dmamap_load_raw(bus_dma_tag_t, bus_dmamap_t, bus_dma_segment_t *,
+    int, bus_size_t, int);
+void bus_dmamap_unload(bus_dma_tag_t, bus_dmamap_t);
+void bus_dmamap_sync(bus_dma_tag_t, bus_dmamap_t, bus_addr_t, bus_size_t, int);
 
 #define        bus_dmamem_alloc(t, s, a, b, sg, n, r, f)               \
        (*(t)->_dmamem_alloc)((t), (s), (a), (b), (sg), (n), (r), (f))
diff -r 2b75b4fb82a2 -r bc502ccc7b5b sys/kern/subr_asan.c
--- a/sys/kern/subr_asan.c      Mon Apr 13 06:24:52 2020 +0000
+++ b/sys/kern/subr_asan.c      Mon Apr 13 07:09:50 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_asan.c,v 1.20 2020/04/03 18:44:50 maxv Exp $      */
+/*     $NetBSD: subr_asan.c,v 1.21 2020/04/13 07:09:51 maxv Exp $      */
 
 /*
  * Copyright (c) 2018-2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.20 2020/04/03 18:44:50 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_asan.c,v 1.21 2020/04/13 07:09:51 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
@@ -1069,8 +1069,6 @@
 
 /* -------------------------------------------------------------------------- */
 
-#ifdef __HAVE_KASAN_INSTR_DMA
-
 #include <sys/mbuf.h>
 
 static void
@@ -1162,8 +1160,6 @@
        map->dm_buftype = type;
 }
 
-#endif /* __HAVE_KASAN_INSTR_DMA */
-
 /* -------------------------------------------------------------------------- */
 
 void __asan_register_globals(struct __asan_global *, size_t);



Home | Main Index | Thread Index | Old Index