From patchwork Mon Sep 5 12:24:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Potapenko X-Patchwork-Id: 12966054 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 E4BD9ECAAD3 for ; Mon, 5 Sep 2022 12:26:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 609E58D007E; Mon, 5 Sep 2022 08:26:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5B7CB8D0076; Mon, 5 Sep 2022 08:26:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4325A8D007E; Mon, 5 Sep 2022 08:26:02 -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 351038D0076 for ; Mon, 5 Sep 2022 08:26:02 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 17E021C3F38 for ; Mon, 5 Sep 2022 12:26:02 +0000 (UTC) X-FDA: 79877953764.26.4EA419B Received: from mail-ej1-f73.google.com (mail-ej1-f73.google.com [209.85.218.73]) by imf20.hostedemail.com (Postfix) with ESMTP id BF2AD1C0085 for ; Mon, 5 Sep 2022 12:26:01 +0000 (UTC) Received: by mail-ej1-f73.google.com with SMTP id he38-20020a1709073da600b0073d98728570so2284229ejc.11 for ; Mon, 05 Sep 2022 05:26:01 -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=tTKCC8E0FZGTE1PqKz29JX/2nPiAROSv7nBNIKGtZQqtA/Jc/wKg23z16zcRSICf9V 5+VK18dSOsEVzrLNZfg05+QTe4rJOMf7PLWu12nixFzQPGlMmrK4kNV0MVAmB1xFyDUp fh0O1ZosEFKdO8Yi1waDmf6eNfefrG1y1wRvC1MLpl4b6ewma9AVT6z20HaDp07JZcPW CWv8wkRFGfuGADjLPH0jWxPW3H7vBuGBn9m0/FJ/z7BJvQsM8Oym+Hget4IsHr+AP45B CZ7Yk/Iz2QhGWTNmmH28t0KetSXuqpaeillrdIThwRnrJbAybPbz8cbVsFZy5erwsmUi wLGg== 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=oZ6wrg1H/PNE3OhWKbusMKYofW/aCb0ASXYsIxKdbcoUo0fhFpf/hC3hFKaGXDh8wk nzxBHXYbnEqpw10/joLX8Vkw4tnQ8bWKiDyWn2BjiGrjOhzY7jTOIAkU+SPnXZBSUfZF jHB1F3ykSsAixN9yumPkKELrXeLSzixr95MkN7lcROst88QKYO+JhDuDxJH1sACxR6lI xFKvPAVQ5B33myWtKw0GQ3HuWDuQSvnMCunZeWgQSuyqHeyC2FLrWrvPJxAm2LgvOP5O 3acjCcRuA3/eOGgOyequLVVEs/nfLDrJWQMUavfFDkQE1NIg82Awpsc5XBVVLMPjDHUO 12vg== X-Gm-Message-State: ACgBeo1pGw8og4hTHCUGhHNH8rHeeXf9Rm0G50FEtqc8ag1GYEpiNqr4 BAR8cQ3E5LJdYvL/pyHNilVeTI0wXlA= X-Google-Smtp-Source: AA6agR7FNmpKjolLE1by3INbujX31rVBl6iJG78jz8dfceM2y9tc86KJyobPC7mva0DftsLWsbXlYG7fcOg= X-Received: from glider.muc.corp.google.com ([2a00:79e0:9c:201:b808:8d07:ab4a:554c]) (user=glider job=sendgmr) by 2002:a05:6402:320d:b0:448:7cc8:7901 with SMTP id g13-20020a056402320d00b004487cc87901mr30728374eda.423.1662380760517; Mon, 05 Sep 2022 05:26:00 -0700 (PDT) Date: Mon, 5 Sep 2022 14:24:31 +0200 In-Reply-To: <20220905122452.2258262-1-glider@google.com> Mime-Version: 1.0 References: <20220905122452.2258262-1-glider@google.com> X-Mailer: git-send-email 2.37.2.789.g6183377224-goog Message-ID: <20220905122452.2258262-24-glider@google.com> Subject: [PATCH v6 23/44] 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 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 , 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-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tTKCC8E0; spf=pass (imf20.hostedemail.com: domain of 32OoVYwYKCCUHMJEFSHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=32OoVYwYKCCUHMJEFSHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662380761; a=rsa-sha256; cv=none; b=EGPL9JbI7welvDyc57OmXpgCKBIaRwC5BTxJqGPojODCElL5l5lycEP93sysV5jf1Fhr2q gMWRZHKCVbz4cxjWPwaAjp8O1Q2HhJBlAz0idcqap/GquspfBMRIK7Z3xmtBx5kvIr2nzQ rcO5nFtiCaa2dCr533aOtPoz7OyPymg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662380761; 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=k8NCUajsU1Rjf7B2wvikKppGh1F7SEDWoRS0jPBeb2RlQRG78TNdNGgOIzZi88HLNqDDP9 poNxY8ZwcWCwprylmIae6aPkTa/TSH9nlUYltC9q8rruaOnM0G25oD5rethdBT7m+MAz/O V9bSodbCKQY/+6uuToquthFstekNlGk= Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=tTKCC8E0; spf=pass (imf20.hostedemail.com: domain of 32OoVYwYKCCUHMJEFSHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--glider.bounces.google.com designates 209.85.218.73 as permitted sender) smtp.mailfrom=32OoVYwYKCCUHMJEFSHPPHMF.DPNMJOVY-NNLWBDL.PSH@flex--glider.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com X-Rspamd-Server: rspam06 X-Stat-Signature: e575jjz5y4cin53ubmmo6e6skn37e6r7 X-Rspam-User: X-Rspamd-Queue-Id: BF2AD1C0085 X-HE-Tag: 1662380761-729839 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