From patchwork Tue Dec 14 16:20:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12676387 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 3EE54C433F5 for ; Tue, 14 Dec 2021 16:36:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8C7F6B009F; Tue, 14 Dec 2021 11:23:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B39B26B009E; Tue, 14 Dec 2021 11:23:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DAE16B009F; Tue, 14 Dec 2021 11:23:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0238.hostedemail.com [216.40.44.238]) by kanga.kvack.org (Postfix) with ESMTP id 7C94D6B009D for ; Tue, 14 Dec 2021 11:23:17 -0500 (EST) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 42EEA8249980 for ; Tue, 14 Dec 2021 16:23:07 +0000 (UTC) X-FDA: 78916919214.27.78C3D49 Received: from mail-wr1-f74.google.com (mail-wr1-f74.google.com [209.85.221.74]) by imf05.hostedemail.com (Postfix) with ESMTP id 3505910001A for ; Tue, 14 Dec 2021 16:23:05 +0000 (UTC) Received: by mail-wr1-f74.google.com with SMTP id b1-20020a5d6341000000b001901ddd352eso4897332wrw.7 for ; Tue, 14 Dec 2021 08:23:05 -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=RCylrb6G91/E/2vtsmKFgkT1r5eRWWtCKOMrnaR3rS0=; b=SC1C+6vpXr8HhRaNadHiQrHplXa2kTitGVDtEEVvo/VrrTc0GKtS90GfxGyyjv/uIU Gl/r4wNi4cjwD4k7LpB8i9yt1uiBCrmAnLNIaiGGNAa5OoTgjezb10lfEPoQ/GaeQqmf 5qUDDqWGueIOP/FgPPX7tknIguxeVvNUN++V/9a+2dDpTxqjWw4PQpyEc8noRfwFoXyv xy6PPtcuiudOOiEZccKacAw0PDC4zXCg+pdnGBrwgtN8FZ+qpJpxq26TBTjQXuIXJ0Mi 1/jfDPSYbAYAUEVRomUDfFdagkdwem60SUAf9u9FUETpXnhkyTL+cqPlolp9b8UvxxVm y5Yw== 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=RCylrb6G91/E/2vtsmKFgkT1r5eRWWtCKOMrnaR3rS0=; b=vcvplbanet/LIIfkCTUVaNCA4PYSVyn/pe2QMELaZXfnpXEZJqIP2Drjn6AcV/Var+ +EgYGDE51LK9aDWPotREBV6P6BPpiiRocGoq6QWbg1Fv8o+z1/lFKsxZEUijGOcN6ciN hSz8ZFFPqf5SHWatlgyKjl4B1DLco9Gph2uBliATgE3y3YcQ7YrXXzC8UflegqQ/j9jx nIP1hIEQrYX2B0v1f4231ISpvIUnIqFIHF0s52NoMnnZC0O1zvC9KVIStYWDWICihT4q q7nPh0mPjlO0ZMqT4O+GPlc8MZDvJuZNsXHfr1W80wGExHujyE+g9sQHXju+9jR2DPUv fgtw== X-Gm-Message-State: AOAM5319jDEOV8YJo5Sq11eXLYFaFs8GlSw6+eC6cjOcqe4HglcuI3D2 EUD3QvJGDgH2bxVP3tX3/7rQovJAvyU= X-Google-Smtp-Source: ABdhPJw9UBXdJlo13EpvnyI9qmtetaMmbSMsl/SrkoqoZXzI79hK6SLrS6tAUR/JTk3AKx81zpcHzTtcriI= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:357e:2b9d:5b13:a652]) (user=glider job=sendgmr) by 2002:adf:f088:: with SMTP id n8mr6603937wro.411.1639498984734; Tue, 14 Dec 2021 08:23:04 -0800 (PST) Date: Tue, 14 Dec 2021 17:20:33 +0100 In-Reply-To: <20211214162050.660953-1-glider@google.com> Message-Id: <20211214162050.660953-27-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 26/43] kmsan: virtio: check/unpoison scatterlist in vring_map_one_sg() 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: 3505910001A X-Stat-Signature: z5pmqheqnu58wt9d8sd1octs8xwxdpyd Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=SC1C+6vp; spf=pass (imf05.hostedemail.com: domain of 36MS4YQYKCGkNSPKLYNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--glider.bounces.google.com designates 209.85.221.74 as permitted sender) smtp.mailfrom=36MS4YQYKCGkNSPKLYNVVNSL.JVTSPUbe-TTRcHJR.VYN@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-HE-Tag: 1639498985-45907 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: If vring doesn't use the DMA API, KMSAN is unable to tell whether the memory is initialized by hardware. Explicitly call kmsan_handle_dma() from vring_map_one_sg() in this case to prevent false positives. Signed-off-by: Alexander Potapenko Acked-by: Michael S. Tsirkin --- Link: https://linux-review.googlesource.com/id/I211533ecb86a66624e151551f83ddd749536b3af --- drivers/virtio/virtio_ring.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c index 6d2614e34470f..bf4d5b331e99d 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -331,8 +332,15 @@ static dma_addr_t vring_map_one_sg(const struct vring_virtqueue *vq, struct scatterlist *sg, enum dma_data_direction direction) { - if (!vq->use_dma_api) + if (!vq->use_dma_api) { + /* + * If DMA is not used, KMSAN doesn't know that the scatterlist + * is initialized by the hardware. Explicitly check/unpoison it + * depending on the direction. + */ + kmsan_handle_dma(sg_page(sg), sg->offset, sg->length, direction); return (dma_addr_t)sg_phys(sg); + } /* * We can't use dma_map_sg, because we don't use scatterlists in