From patchwork Tue Dec 14 16:20:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12676391 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 480BBC433F5 for ; Tue, 14 Dec 2021 16:37:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 041036B009E; Tue, 14 Dec 2021 11:23:23 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id F31BB6B00A0; Tue, 14 Dec 2021 11:23:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D853D6B00A1; Tue, 14 Dec 2021 11:23:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0221.hostedemail.com [216.40.44.221]) by kanga.kvack.org (Postfix) with ESMTP id C9AEB6B009E for ; Tue, 14 Dec 2021 11:23:22 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 9251C87714 for ; Tue, 14 Dec 2021 16:23:12 +0000 (UTC) X-FDA: 78916919424.10.BDBE4DF Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf31.hostedemail.com (Postfix) with ESMTP id CD9392000F for ; Tue, 14 Dec 2021 16:23:06 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id u4-20020a5d4684000000b0017c8c1de97dso4854174wrq.16 for ; Tue, 14 Dec 2021 08:23:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=x5YBqNptwlSdtxXj6Mpbhns9uYlzM7sKdh+OiWmHV8E=; b=Eq16fqo7/umIC+mRw+0mkHSO2SVMHikYc1m6jSZV8W6hhVaM9NMvFdQfrWKGA3yg/i 7vUEVTKL+jqzhdEkXU9xVd75uPZ4Rmx4C1qHm0ZEuH7q6SV7Qvuyq3wzniVYxjvJom4F 4OBdWZpawHisawFRRG9ZiNgKyC5uZphoOmN+OvbQMyHKkPhl4uA1SbeivqjtkKXkYXvj ayyTsXbSYK8GBBsDpjliMHxRjjyXaQDfpdlmy8yxUniRXrvUu+NwM9AzRrogCDV9SX9P LlNfxBQ96uMgIvTX+ftvkx34ETbts7JwLHCgfgsywDgA/Qo2UWkAtoDM5JW5QNO9UuHJ Hb+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=x5YBqNptwlSdtxXj6Mpbhns9uYlzM7sKdh+OiWmHV8E=; b=5u5x4dT5hZPxJwdK3s02BNAvcBYkrOG4mvjuyQGG7xmUMJK4eFxs8ZG4RLHft575AY PsLF18y/MaI3uz+4qqWzHSwUbybNXAEiXi0jqh4FIXy4dlT87QcWTyMD+R4leG77dnEm ccM5Xk3gZ13b7Dq5e3NiXjnvRQwS6UZV+0orznfYIZXKFT45SFep8k+MpJwD9y0QKXnq eX+RL+/0YvrE2VTPHMjvNyBXIkrNGutfrbRsacQm/koslTzEpzfLNMfTxPG5L6t7iTdq OPaNZ+ILdCCb3GJKSSxn6Wlt+YEubbS0B43e1ENS6Jf9KAaQ+i2jAalkH+06RJJAb3Jl OnKg== X-Gm-Message-State: AOAM532IJ+im9NjhctUVNQZfgGfS8/UmF+m9ew9vOVwnAYVYBFcSwoFr c/YtU3u92+gRth9cybuHDB1xKjDFo9s= X-Google-Smtp-Source: ABdhPJz2ZQuIEn5ZmHrH4VnKPAPp72t+EVJM3lTIPSyuDMPR4kQmFKNO01R60JjhCJQ/Lb82u7miTPMRVUQ= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:357e:2b9d:5b13:a652]) (user=glider job=sendgmr) by 2002:adf:ed52:: with SMTP id u18mr6938942wro.609.1639498989844; Tue, 14 Dec 2021 08:23:09 -0800 (PST) Date: Tue, 14 Dec 2021 17:20:35 +0100 In-Reply-To: <20211214162050.660953-1-glider@google.com> Message-Id: <20211214162050.660953-29-glider@google.com> Mime-Version: 1.0 References: <20211214162050.660953-1-glider@google.com> X-Mailer: git-send-email 2.34.1.173.g76aa8bc2d0-goog Subject: [PATCH 28/43] kmsan: dma: unpoison DMA mappings From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Ard Biesheuvel , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: CD9392000F X-Stat-Signature: j4e133c8x8dakthswb875ogkjosfiagk Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=Eq16fqo7; spf=pass (imf31.hostedemail.com: domain of 37cS4YQYKCG4SXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=37cS4YQYKCG4SXUPQdSaaSXQ.OaYXUZgj-YYWhMOW.adS@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1639498986-997677 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: KMSAN doesn't know about DMA memory writes performed by devices. We unpoison such memory when it's mapped to avoid false positive reports. Signed-off-by: Alexander Potapenko --- Link: https://linux-review.googlesource.com/id/Ia162dc4c5a92e74d4686c1be32a4dfeffc5c32cd --- kernel/dma/mapping.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/dma/mapping.c b/kernel/dma/mapping.c index 9478eccd1c8e6..0560080813761 100644 --- a/kernel/dma/mapping.c +++ b/kernel/dma/mapping.c @@ -156,6 +156,7 @@ dma_addr_t dma_map_page_attrs(struct device *dev, struct page *page, addr = dma_direct_map_page(dev, page, offset, size, dir, attrs); else addr = ops->map_page(dev, page, offset, size, dir, attrs); + kmsan_handle_dma(page, offset, size, dir); debug_dma_map_page(dev, page, offset, size, dir, addr, attrs); return addr; @@ -194,11 +195,13 @@ static int __dma_map_sg_attrs(struct device *dev, struct scatterlist *sg, else ents = ops->map_sg(dev, sg, nents, dir, attrs); - if (ents > 0) + if (ents > 0) { + kmsan_handle_dma_sg(sg, nents, dir); debug_dma_map_sg(dev, sg, nents, ents, dir, attrs); - else if (WARN_ON_ONCE(ents != -EINVAL && ents != -ENOMEM && - ents != -EIO)) + } else if (WARN_ON_ONCE(ents != -EINVAL && ents != -ENOMEM && + ents != -EIO)) { return -EIO; + } return ents; }