From patchwork Thu Oct 19 15:25:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 13429368 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7E17CDB483 for ; Thu, 19 Oct 2023 15:26:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 820FE80096; Thu, 19 Oct 2023 11:26:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D0EF8000B; Thu, 19 Oct 2023 11:26:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6BFDB80096; Thu, 19 Oct 2023 11:26:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 59F398000B for ; Thu, 19 Oct 2023 11:26:04 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 21095160137 for ; Thu, 19 Oct 2023 15:26:04 +0000 (UTC) X-FDA: 81362586648.24.6360F68 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf01.hostedemail.com (Postfix) with ESMTP id 32EF84001D for ; Thu, 19 Oct 2023 15:26:01 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ocXti95o; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of cel@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697729162; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xDR7dn0oKDWDBNbcVNI65T4LvKi1Dhba+HObmm5aiNA=; b=6zWY4c1u1JUa8wnaMhwS23bws0rrDm3wYOGsfvFRmE4MxJ5UBi7kOB3YeBVKQLtv6n1dyX dW/BsODKz2prcxe9ool0AitA0vRoXcbYvwC5/+nB/ZxSEMGpDBQz2C4Nm/ORHYkanSwNQZ h0t6qONoqljaDTepv+Lv0rx1zcKySMM= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=ocXti95o; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf01.hostedemail.com: domain of cel@kernel.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=cel@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697729162; a=rsa-sha256; cv=none; b=6GsQgK638+2ahkZTr3rHJt8+aAutNUfMqSagrKGWqqV+RO/pX6O0kQOouyYaDg9qxSoLQr 0j5XIyyNwPX5FnkU7LwUU9HzoDnVEmPdsLoT7x2C0rtfBfet0aSTJCk7YB+3pANgv3WmSS /pQyLGDBBQCEo/TO3w1GtXstNOi8gq8= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by ams.source.kernel.org (Postfix) with ESMTP id DE096B828A4; Thu, 19 Oct 2023 15:26:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BF50DC433C9; Thu, 19 Oct 2023 15:25:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1697729160; bh=P4b6wsJEKT/3IXcqFp8KjGqq8Imdm8sdVfTi6RWsVXU=; h=Subject:From:Cc:Date:In-Reply-To:References:From; b=ocXti95o34TJcUGQJjL1VTemEZSTo7XFgSL9x327zb9g4/KyKjKuQOJJN4iN+Vlw2 +93yWadJ4LZ+Ew2TmR5EjM5PLLWjPsBAzXuxNTn+B0xKRkNPM2f4VYMFAqy/IW9Vq7 0UkS+Et/KQ1C76yEgXV3hkMgM6Ko3kSzw5uyNfwt4AUGf+A6rRF2UOQFfl05a2d1It IbHjj7se3QfzvuzXk5QhkSbwRSRL6M38+qrn63gt4BT71WUDx+RofV2BD/iXCCPX+5 itWEmX8gSsYXDHnHzARYHMGi6XuQOFTP4yixh5fOkdtYTZ9vd9N+yk2aXXmxrZSGqa sgDSxnS0Lev2Q== Subject: [PATCH RFC 4/9] mm: kmsan: Add support for DMA mapping bio_vec arrays From: Chuck Lever Cc: Alexander Potapenko , kasan-dev@googlegroups.com, linux-mm@kvack.org, iommu@lists.linux.dev, linux-rdma@vger.kernel.org, Chuck Lever Date: Thu, 19 Oct 2023 11:25:58 -0400 Message-ID: <169772915869.5232.9306605321315591579.stgit@klimt.1015granger.net> In-Reply-To: <169772852492.5232.17148564580779995849.stgit@klimt.1015granger.net> References: <169772852492.5232.17148564580779995849.stgit@klimt.1015granger.net> User-Agent: StGit/1.5 MIME-Version: 1.0 X-Rspamd-Queue-Id: 32EF84001D X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: jqmmtcq4dzqnkxba415xfo3qu6jb59ou X-HE-Tag: 1697729161-471086 X-HE-Meta: U2FsdGVkX18SwSouo/xbuAj1pJuyy+p6E2QqlP77m8CJWSYi5vFLqsJUElMBCktYUIuLUEkIAyFq1PWVEycGr736M9xRzWoW17QY6KGSb3VVI7m9gUYbeVebOqAcuYLfDrpRxSfBAj5u7HS/Sw+t62sqKq6LKpbwo7tLMcRhWnQ7mNq3foBqeNx01xt0jmQDjNS6oYfowIGvUmlDfWErMSR7yttyT+Z6ZR05mfxqFlBFJnPpHyMw2tWEvF1+GoMfLS6y9i7cAfXWPJiiAVJaZKannV3c6Sb8j5jsxOj8pDbKjOn9ZBnrFdp3P4iBle8oDO1n8e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GjiXoUWjO2D3RLYG0rolkHPmUxslvYsRySgrBUYHf1HIz8shLkpes/HEiw== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Chuck Lever Cc: Alexander Potapenko Cc: kasan-dev@googlegroups.com Cc: linux-mm@kvack.org Cc: iommu@lists.linux.dev Cc: linux-rdma@vger.kernel.org Signed-off-by: Chuck Lever --- include/linux/kmsan.h | 20 ++++++++++++++++++++ mm/kmsan/hooks.c | 13 +++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/linux/kmsan.h b/include/linux/kmsan.h index e0c23a32cdf0..36c581a18b30 100644 --- a/include/linux/kmsan.h +++ b/include/linux/kmsan.h @@ -18,6 +18,7 @@ struct page; struct kmem_cache; struct task_struct; struct scatterlist; +struct bio_vec; struct urb; #ifdef CONFIG_KMSAN @@ -209,6 +210,20 @@ void kmsan_handle_dma(struct page *page, size_t offset, size_t size, void kmsan_handle_dma_sg(struct scatterlist *sg, int nents, enum dma_data_direction dir); +/** + * kmsan_handle_dma_bvecs() - Handle a DMA transfer using bio_vec array. + * @bvecs: bio_vec array holding DMA buffers. + * @nents: number of scatterlist entries. + * @dir: one of possible dma_data_direction values. + * + * Depending on @direction, KMSAN: + * * checks the buffers in the bio_vec array, if they are copied to device; + * * initializes the buffers, if they are copied from device; + * * does both, if this is a DMA_BIDIRECTIONAL transfer. + */ +void kmsan_handle_dma_bvecs(struct bio_vec *bv, int nents, + enum dma_data_direction dir); + /** * kmsan_handle_urb() - Handle a USB data transfer. * @urb: struct urb pointer. @@ -321,6 +336,11 @@ static inline void kmsan_handle_dma_sg(struct scatterlist *sg, int nents, { } +static inline void kmsan_handle_dma_bvecs(struct bio_vec *bv, int nents, + enum dma_data_direction dir) +{ +} + static inline void kmsan_handle_urb(const struct urb *urb, bool is_out) { } diff --git a/mm/kmsan/hooks.c b/mm/kmsan/hooks.c index 5d6e2dee5692..87846011c9bd 100644 --- a/mm/kmsan/hooks.c +++ b/mm/kmsan/hooks.c @@ -358,6 +358,19 @@ void kmsan_handle_dma_sg(struct scatterlist *sg, int nents, dir); } +void kmsan_handle_dma_bvecs(struct bio_vec *bvecs, int nents, + enum dma_data_direction dir) +{ + struct bio_vec *item; + int i; + + for (i = 0; i < nents; i++) { + item = &bvecs[i]; + kmsan_handle_dma(bv_page(item), item->bv_offset, item->bv_len, + dir); + } +} + /* Functions from kmsan-checks.h follow. */ void kmsan_poison_memory(const void *address, size_t size, gfp_t flags) {