Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4458695ioa; Wed, 27 Apr 2022 04:27:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwBIvkFbRYz68V69MZl/uoU40y8K3KU88JKsgwjWghtMgJsed9MPP8XoML2hYFO8nAlxacw X-Received: by 2002:a17:90b:3a86:b0:1d9:8716:90a0 with SMTP id om6-20020a17090b3a8600b001d9871690a0mr14639107pjb.113.1651058853867; Wed, 27 Apr 2022 04:27:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651058853; cv=none; d=google.com; s=arc-20160816; b=ZYolk5P8TsgBLLp3ztHIzKcFw0IeA0QS4BsjDh9Pnv8UzEWq0aMbiRSosPApGt46wZ io/ZLcqQ4tiQzwsM8ocQjhWLzdzP71a4LOTgvmj9kXLqGbrlct40ZD9zfQ/19cLNY/Y+ 4UMla467qu0xPSyXqxA8OYGqE2qSdafWrZO+cAFkVn5b/tMfvQIt08gHHJbBN5RBTHgY Y2ZTBuAfn0l19CFtQLYrQTIWUB1p6BhtoF0e9mq3fm3903B6l7uiEl9RxUnrmLC5BXZ0 F0qrZEUA4s58Zk9aPap40WA//4jWfssuY9k7cabLf5S21vCryJ99SzcMNF5ldbxpHuuP Iz3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=n12oscJoQy25ZeJEgKUppRaHioaFclURl8PsqxmYCmo=; b=fWXHWEKx9rY7wj4Cmg3dYTd/xc11LRKnCS8uLHzXm95Hp+rChfTkuUaH2Qw4kzzeek KR20maYbAMJr6S3B/AfkiNZsZ2eCIruSylbjAiZl3kj8mgSkvoQgO6ANopkT5cV9VoQh PB+Mzw0Gyzmjs/K8sCuDltcYKqGZAtPMejkvqrVFniKI4ISECONIlo9kWuOlwpdNS7r4 XLDdKrzjzt/cDfDe5xXiXdkcJ6txPZQhPFqjHFGn9TeH2jvOfAU21SY+z0yCoA/8Agah OetuepK76dPJChVl4QIT6JjsEKUGZYesR9i6NEnkdD2c1uIhnjl/P76sqlRNgT+BX6/M VJvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PIyBhpOC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id t70-20020a638149000000b0039da72fcd63si1191165pgd.472.2022.04.27.04.27.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 04:27:33 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=PIyBhpOC; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 80D1228B763; Wed, 27 Apr 2022 03:25:26 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353274AbiDZQvB (ORCPT + 99 others); Tue, 26 Apr 2022 12:51:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43278 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353303AbiDZQtL (ORCPT ); Tue, 26 Apr 2022 12:49:11 -0400 Received: from mail-ej1-x649.google.com (mail-ej1-x649.google.com [IPv6:2a00:1450:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB663D4AC for ; Tue, 26 Apr 2022 09:45:27 -0700 (PDT) Received: by mail-ej1-x649.google.com with SMTP id dp12-20020a170906c14c00b006e7e8234ae2so9350439ejc.2 for ; Tue, 26 Apr 2022 09:45:27 -0700 (PDT) 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=n12oscJoQy25ZeJEgKUppRaHioaFclURl8PsqxmYCmo=; b=PIyBhpOCM8Ov1/+Aan+YSMRBfpf54pHX8ytL+CV9/1wxPrduFClfDo2MC25BFRGqUr LC5Hr2Ef8nJt4G1Cr30fbnTHYjTJ5Gax8GaKjFXG0iL+r/c29mApiZT+RSwu1Gv2kkOz 34uVLpDsIsKTbG2q42gMn4a9Vr9GOVlaxiLfXa8b/4pWebY6TjT2x9JFCSEXRuOPPg3n b/OGc6pwoUP/SU7+PJ629KnVXCQHZctVc5m6qyPQPfIcXk7XKqS9AYp6qyxiblVFksU/ vePEsS5V3b8GJxiZEtgsjh4z7hZSSCwDY93JM9PnMnCLZhZrlsTx6bFvrt7KV12fLlqe re3Q== 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=n12oscJoQy25ZeJEgKUppRaHioaFclURl8PsqxmYCmo=; b=eDfHR9etxf7+bT1TNJL/Wk64k90nQKooUpqUmkxiaBJsKFqV7y3J077oZHDAKAZ/ok DAEGgB4eAveYLNC+DqT4fjz13O5cbfEUg+UDWRusF63BkiHQxO2OfhF/YkJDtgmPjQGY 80ILieXfEAldpzrrYmUl5LSAMuVmNkXkp0HmUMVM66kP9yeGngZ+HSVaciAhqmGakNSm s7xTQ87/Kg+SJTm2jCQc1ii6aAvaHxix+chtHPKI6Xpt6Dg0ho5dVoP2Rts82PuhZKxP uAYLlVfSOhOSvl2v96FxXSwHQY9tmEb4gOa4q9o/I1NDd9Y2dzYaWNNS0YsCIZKXOjGf WuAA== X-Gm-Message-State: AOAM5316n9sW0EtgukyUSrKbWUmFrUagP2J8JPfH7EHGjfOcpT9QrymI oXPFx68L+tefmQfsUNMMNbO46V1arHg= X-Received: from glider.muc.corp.google.com ([2a00:79e0:15:13:d580:abeb:bf6d:5726]) (user=glider job=sendgmr) by 2002:a05:6402:5210:b0:423:de77:2a4d with SMTP id s16-20020a056402521000b00423de772a4dmr25186177edd.295.1650991525861; Tue, 26 Apr 2022 09:45:25 -0700 (PDT) Date: Tue, 26 Apr 2022 18:42:54 +0200 In-Reply-To: <20220426164315.625149-1-glider@google.com> Message-Id: <20220426164315.625149-26-glider@google.com> Mime-Version: 1.0 References: <20220426164315.625149-1-glider@google.com> X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 25/46] 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 , 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 Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 cfb028ca238eb..faecd9e3d6560 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 -- 2.36.0.rc2.479.g8af0fa9b8e-goog