From patchwork Thu Sep 15 15:03:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12977540 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 2CCD8ECAAA1 for ; Thu, 15 Sep 2022 15:05:41 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B581B80016; Thu, 15 Sep 2022 11:05:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADF9980007; Thu, 15 Sep 2022 11:05:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9A83680016; Thu, 15 Sep 2022 11:05:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 8B29480007 for ; Thu, 15 Sep 2022 11:05:40 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 54D731C506C for ; Thu, 15 Sep 2022 15:05:40 +0000 (UTC) X-FDA: 79914644040.29.4F3F4B2 Received: from mail-ed1-f74.google.com (mail-ed1-f74.google.com [209.85.208.74]) by imf17.hostedemail.com (Postfix) with ESMTP id DF21F400AC for ; Thu, 15 Sep 2022 15:05:39 +0000 (UTC) Received: by mail-ed1-f74.google.com with SMTP id v11-20020a056402348b00b004516e0b7eedso10465267edc.8 for ; Thu, 15 Sep 2022 08:05:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date; bh=lOWe2UvDp+lzLw75WkGUXRoANIiWBb139LkOr44Ytus=; b=r8zwtK7nR6FXPBS442hkgib03/UyNe7gNUiweombLjUeUOwj8SF20sAORY+JgIxfJC xdQzkfFn7/UIZp6qs2BkVURbVTIpmVyq4CogUpIZzqnkOvB4czCVAsUxHuaXyYzg7wYj iSHZbV2gUMNZdtwTkVyP2zImSyDUIobXdqb3vW/gaStenqfHXMWXmhtPDGK7i0t2+x+V LX9ocp5gmEP0hXd6aLkG4expCb4w3nGprape1+X4fjnbTnlSElSS0OcneVvlkPCu1k1v zulBsEXPwjPW//HgEDA7XFR0M2WbDQmJA13wrulrEaaWrxCq8Z7S8FbCgch7VF6L5ax7 LfJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date; bh=lOWe2UvDp+lzLw75WkGUXRoANIiWBb139LkOr44Ytus=; b=YZ4/WfBFS6iEcG6Inm7XL8dNi/h6Sc9x9iugZwkR7OH2J9AdvgfTbV9XOSEPJDcYwZ VUneVb/PZhjB4dY/NfPlbxSCFgfgGkij6PqbpHRQy5j+o8s8KXKRCom7LwRtTyphPSBI +Qlplla8AYnScgr89ZgYH+yT4OICqDU5hdo7ZX0dIHQzMTIEfCbJtNz58vYoEvHJXRqr phRe2dpiBayuV0NU5xmxx5qfPvmtk7JBtNa3A1y5PKK3VQ9gmHS5QnwF4IgpBGw6bhMv 2eKJGTpu4EVnoZEfnt5LQgNzPrnCN1hDJUZSXQcDcihabQvetnUJgymmj1X1PRfKyq3e a+sA== X-Gm-Message-State: ACrzQf37nsHOndDMX1WY2Tgy+w8SaqNvR/BB85qOrNA6YedpLschP5Oe zH8YmjfJ96636XWiA4hH0V7f6au63s4= X-Google-Smtp-Source: AMsMyM6XUfiL29ncKe/ZK/EpTsQsoLddOpxaN22/2HU0VmNdXXQuif+Od6cd/SXFxh2r6j465cljcQVOjxc= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:686d:27b5:495:85b7]) (user=glider job=sendgmr) by 2002:a17:906:58c8:b0:6fe:91d5:18d2 with SMTP id e8-20020a17090658c800b006fe91d518d2mr326676ejs.190.1663254338524; Thu, 15 Sep 2022 08:05:38 -0700 (PDT) Date: Thu, 15 Sep 2022 17:03:56 +0200 In-Reply-To: <20220915150417.722975-1-glider@google.com> Mime-Version: 1.0 References: <20220915150417.722975-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220915150417.722975-23-glider@google.com> Subject: [PATCH v7 22/43] virtio: kmsan: check/unpoison scatterlist in vring_map_one_sg() From: Alexander Potapenko To: glider@google.com Cc: Alexander Viro , Alexei Starovoitov , Andrew Morton , Andrey Konovalov , Andy Lutomirski , Arnd Bergmann , Borislav Petkov , Christoph Hellwig , Christoph Lameter , David Rientjes , Dmitry Vyukov , Eric Biggers , Eric Dumazet , Greg Kroah-Hartman , Herbert Xu , Ilya Leoshkevich , Ingo Molnar , Jens Axboe , Joonsoo Kim , Kees Cook , Marco Elver , Mark Rutland , Matthew Wilcox , "Michael S. Tsirkin" , Pekka Enberg , Peter Zijlstra , Petr Mladek , Stephen Rothwell , Steven Rostedt , Thomas Gleixner , Vasily Gorbik , Vegard Nossum , Vlastimil Babka , kasan-dev@googlegroups.com, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663254339; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lOWe2UvDp+lzLw75WkGUXRoANIiWBb139LkOr44Ytus=; b=RE+IHAiWO8kFG4C6mFZvAQQ5c2d2tHmhDD5kvC29KnLrJ/i7ItfxemOGegiECl8aAnDCaH J/tvE2Qtcr4b2IIuD8p0WEtxEDuWMJf4EVsbXjc3T/30vkJW/7pQuNhN8ffuyjv/ZTlIgr 8166ddcIr/4t6bGD0RVSFNidhxJwWnI= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=r8zwtK7n; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3Qj8jYwYKCG0RWTOPcRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3Qj8jYwYKCG0RWTOPcRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--glider.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663254339; a=rsa-sha256; cv=none; b=M0i5f8mP52pAkS6fzsrzkj2Z1EwEVKv7GrL5Z3vDQV0+h12SH9ado2UYrQFjJkcX0Vt+m5 tq5W2C+TGLZ5Ldomkd6ANRMYLXtFwJoVnKduleKs7mRjdEfup/GTF2gzpMUPaKcDK7A7W+ GxQSCoWQPM1tm1Q0UEPRa1v28tMuPGA= X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: DF21F400AC X-Rspam-User: X-Stat-Signature: w6gk9azqz3bwk4r97nptwpp5jaq9yiqp Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=r8zwtK7n; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf17.hostedemail.com: domain of 3Qj8jYwYKCG0RWTOPcRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--glider.bounces.google.com designates 209.85.208.74 as permitted sender) smtp.mailfrom=3Qj8jYwYKCG0RWTOPcRZZRWP.NZXWTYfi-XXVgLNV.ZcR@flex--glider.bounces.google.com X-HE-Tag: 1663254339-854588 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 --- v4: -- swap virtio: and kmsan: in the subject v6: -- use instead of 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 4620e9d79dde8..8974c34b40fda 100644 --- a/drivers/virtio/virtio_ring.c +++ b/drivers/virtio/virtio_ring.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -352,8 +353,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