Module Name: src Committed By: maxv Date: Mon Apr 13 07:09:51 UTC 2020
Modified Files: src/sys/arch/aarch64/conf: files.aarch64 src/sys/arch/amd64/include: types.h src/sys/arch/arm/conf: files.arm src/sys/arch/arm/include: bus_defs.h bus_funcs.h src/sys/kern: subr_asan.c Added Files: src/sys/arch/arm/arm: bus_stubs.c Log Message: Add KASAN-DMA support on aarch64, same as amd64. Discussed with skrll@. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 src/sys/arch/aarch64/conf/files.aarch64 cvs rdiff -u -r1.65 -r1.66 src/sys/arch/amd64/include/types.h cvs rdiff -u -r0 -r1.1 src/sys/arch/arm/arm/bus_stubs.c cvs rdiff -u -r1.155 -r1.156 src/sys/arch/arm/conf/files.arm cvs rdiff -u -r1.14 -r1.15 src/sys/arch/arm/include/bus_defs.h cvs rdiff -u -r1.8 -r1.9 src/sys/arch/arm/include/bus_funcs.h cvs rdiff -u -r1.20 -r1.21 src/sys/kern/subr_asan.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/aarch64/conf/files.aarch64 diff -u src/sys/arch/aarch64/conf/files.aarch64:1.20 src/sys/arch/aarch64/conf/files.aarch64:1.21 --- src/sys/arch/aarch64/conf/files.aarch64:1.20 Sat Feb 15 08:16:10 2020 +++ src/sys/arch/aarch64/conf/files.aarch64 Mon Apr 13 07:09:50 2020 @@ -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/aarch64/aarch64/bus_space_noti 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 Index: src/sys/arch/amd64/include/types.h diff -u src/sys/arch/amd64/include/types.h:1.65 src/sys/arch/amd64/include/types.h:1.66 --- src/sys/arch/amd64/include/types.h:1.65 Tue Mar 17 17:18:49 2020 +++ src/sys/arch/amd64/include/types.h Mon Apr 13 07:09:50 2020 @@ -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 @@ typedef unsigned char __cpu_simple_lock #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) Index: src/sys/arch/arm/conf/files.arm diff -u src/sys/arch/arm/conf/files.arm:1.155 src/sys/arch/arm/conf/files.arm:1.156 --- src/sys/arch/arm/conf/files.arm:1.155 Mon Apr 13 05:40:25 2020 +++ src/sys/arch/arm/conf/files.arm Mon Apr 13 07:09:51 2020 @@ -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 @@ define bus_space_generic 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 Index: src/sys/arch/arm/include/bus_defs.h diff -u src/sys/arch/arm/include/bus_defs.h:1.14 src/sys/arch/arm/include/bus_defs.h:1.15 --- src/sys/arch/arm/include/bus_defs.h:1.14 Sat Dec 28 17:19:43 2019 +++ src/sys/arch/arm/include/bus_defs.h Mon Apr 13 07:09:51 2020 @@ -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 @@ struct arm32_bus_dmamap { /* * 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 */ Index: src/sys/arch/arm/include/bus_funcs.h diff -u src/sys/arch/arm/include/bus_funcs.h:1.8 src/sys/arch/arm/include/bus_funcs.h:1.9 --- src/sys/arch/arm/include/bus_funcs.h:1.8 Tue Jul 16 11:32:07 2019 +++ src/sys/arch/arm/include/bus_funcs.h Mon Apr 13 07:09:51 2020 @@ -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 @@ bs_po_8_proto(f); 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)) Index: src/sys/kern/subr_asan.c diff -u src/sys/kern/subr_asan.c:1.20 src/sys/kern/subr_asan.c:1.21 --- src/sys/kern/subr_asan.c:1.20 Fri Apr 3 18:44:50 2020 +++ src/sys/kern/subr_asan.c Mon Apr 13 07:09:51 2020 @@ -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 @@ ASAN_BUS_WRITE_FUNC(8, 64) /* -------------------------------------------------------------------------- */ -#ifdef __HAVE_KASAN_INSTR_DMA - #include <sys/mbuf.h> static void @@ -1162,8 +1160,6 @@ kasan_dma_load(bus_dmamap_t map, void *b map->dm_buftype = type; } -#endif /* __HAVE_KASAN_INSTR_DMA */ - /* -------------------------------------------------------------------------- */ void __asan_register_globals(struct __asan_global *, size_t); Added files: Index: src/sys/arch/arm/arm/bus_stubs.c diff -u /dev/null src/sys/arch/arm/arm/bus_stubs.c:1.1 --- /dev/null Mon Apr 13 07:09:51 2020 +++ src/sys/arch/arm/arm/bus_stubs.c Mon Apr 13 07:09:51 2020 @@ -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); +}