From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B4CDCA0EDC for ; Thu, 14 Aug 2025 03:48:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ySXGLynnR++p6RuXca+nTN6nGsk03DV3QSK1ER01nvY=; b=Adlq3mBMYyVmt8uxC60PFb1+WL icRz3VOXDMR+CAbmzTyKneYr90zrp7WJGFfaxNXzQH8y0IVK9ovN3tycWi77GiXUfIrTvlZGy9Poe RvNOsQkxJ5Um3L9QkRsRClA40Izqd4BsYpz/rSb3F6WgsbraLSVtzrFivHVyMajsyxBjQSWRaTxcZ GdtAFlu5H0VKPRKkpz8LFcpCBwe44F6M7Qjm6HA9l1ntbKKXqK0lUSuu18it0PfOW3sPrxVFs4we0 gLekuF8shy7Bc0xtsSv1sdreXlVrclfTUApEOPZZevyXmX5jlXRbczYRtZs/uiTHzOPBwQToApWT6 WYdin63Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1umOxC-0000000Fgr4-3hlm; Thu, 14 Aug 2025 03:48:38 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1umD4W-0000000E8Dl-03ku for linux-nvme@lists.infradead.org; Wed, 13 Aug 2025 15:07:24 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 2F0C06112D; Wed, 13 Aug 2025 15:07:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1B711C4CEF1; Wed, 13 Aug 2025 15:07:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1755097642; bh=AgCFVr8B6NzxkSuzvPEJMB9AhjM0iYqJptnGya/8rdo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=YENt6LTmzTF5MtD2CCE/V13VNj4PuphZirCcbsVboFbdWpo5pbDoM+O1RwGND9hHA WetmjCRKzL7pVzJCuB6ANhgpmI5NnCbOUKiA98JWJtIXOH8N50EVLmuQyuay6zm6ky Onvhe46hQosw9HCamdkdEFdjBFc8sAKkHOvcvhEwHpJ12ST8cc+74GQ77yCDPQN8yP 6Wv7nBFsNIocmJw6FI3A2Sw+oIhMT6YNdwdLIq5MhleD6VLBx07CKPNCPkvEmssek+ ZjeG2ZowZ0nIKyT2jMky93WoiZsWFLORbU579a0ityJsLq0oaeKqLOOi+Bq4oEc02a vNc66YhlSs8qQ== Date: Wed, 13 Aug 2025 18:07:18 +0300 From: Leon Romanovsky To: Jason Gunthorpe Cc: Marek Szyprowski , Abdiel Janulgue , Alexander Potapenko , Alex Gaynor , Andrew Morton , Christoph Hellwig , Danilo Krummrich , iommu@lists.linux.dev, Jason Wang , Jens Axboe , Joerg Roedel , Jonathan Corbet , Juergen Gross , kasan-dev@googlegroups.com, Keith Busch , linux-block@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-nvme@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-trace-kernel@vger.kernel.org, Madhavan Srinivasan , Masami Hiramatsu , Michael Ellerman , "Michael S. Tsirkin" , Miguel Ojeda , Robin Murphy , rust-for-linux@vger.kernel.org, Sagi Grimberg , Stefano Stabellini , Steven Rostedt , virtualization@lists.linux.dev, Will Deacon , xen-devel@lists.xenproject.org Subject: Re: [PATCH v1 08/16] kmsan: convert kmsan_handle_dma to use physical addresses Message-ID: <20250813150718.GB310013@unreal> References: <5b40377b621e49ff4107fa10646c828ccc94e53e.1754292567.git.leon@kernel.org> <20250807122115.GH184255@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250807122115.GH184255@nvidia.com> X-Mailman-Approved-At: Wed, 13 Aug 2025 20:48:37 -0700 X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org On Thu, Aug 07, 2025 at 09:21:15AM -0300, Jason Gunthorpe wrote: > On Mon, Aug 04, 2025 at 03:42:42PM +0300, Leon Romanovsky wrote: > > From: Leon Romanovsky > > > > Convert the KMSAN DMA handling function from page-based to physical > > address-based interface. > > > > The refactoring renames kmsan_handle_dma() parameters from accepting > > (struct page *page, size_t offset, size_t size) to (phys_addr_t phys, > > size_t size). A PFN_VALID check is added to prevent KMSAN operations > > on non-page memory, preventing from non struct page backed address, > > > > As part of this change, support for highmem addresses is implemented > > using kmap_local_page() to handle both lowmem and highmem regions > > properly. All callers throughout the codebase are updated to use the > > new phys_addr_t based interface. > > Use the function Matthew pointed at kmap_local_pfn() > > Maybe introduce the kmap_local_phys() he suggested too. At this point it gives nothing. > > > /* Helper function to handle DMA data transfers. */ > > -void kmsan_handle_dma(struct page *page, size_t offset, size_t size, > > +void kmsan_handle_dma(phys_addr_t phys, size_t size, > > enum dma_data_direction dir) > > { > > u64 page_offset, to_go, addr; > > + struct page *page; > > + void *kaddr; > > > > - if (PageHighMem(page)) > > + if (!pfn_valid(PHYS_PFN(phys))) > > return; > > Not needed, the caller must pass in a phys that is kmap > compatible. Maybe just leave a comment. FWIW today this is also not > checking for P2P or DEVICE non-kmap struct pages either, so it should > be fine without checks. It is not true as we will call to kmsan_handle_dma() unconditionally in dma_map_phys(). The reason to it is that kmsan_handle_dma() is guarded with debug kconfig options and cost of pfn_valid() can be accommodated in that case. It gives more clean DMA code. 155 dma_addr_t dma_map_phys(struct device *dev, phys_addr_t phys, size_t size, 156 enum dma_data_direction dir, unsigned long attrs) 157 { <...> 187 188 kmsan_handle_dma(phys, size, dir); 189 trace_dma_map_phys(dev, phys, addr, size, dir, attrs); 190 debug_dma_map_phys(dev, phys, size, dir, addr, attrs); 191 192 return addr; 193 } 194 EXPORT_SYMBOL_GPL(dma_map_phys); So let's keep this patch as is. Thanks