From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795948350; b=O1PYUGdl17FKhmHvW9tFLMypgKt4PjoHJmzFSVlxIOn01ip9537SVPz4QjALPJlXfWfq zihXz+MXdXIhiAUPibyacbJqOWHwI1Cw9hLK3kRY5bx5NRdYF3HAa+YGIZyotkDO4FBPk SY3lsy/O6e5YVt93Nj0KR+N9xPzJYJEJYKmBgDdFbUSmyA9jZj92OGmZhrzdSyfr9elaD ge1AIdejzAjHbPSoi5aYvWY8hOVxHQFWxCEi9se84fQHTp15OUkVDYhVjcwCK7l/8CkxK 950e2ZSEMz7XUUMYGAvE+zzKaZaAMqMBseGKoN1iUZZzsg6sWaiaZutklI8XJroGU+w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795948350; h=Received:DKIM-Signature:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:Content-Language:Autocrypt:In-Reply-To: Content-Type:Content-Transfer-Encoding; bh=fpQN0fVt6qUqgvG962YtFlNmhmKnIGjYY/K6Y2l+MWg=; b=YvOzUKqlhSeJqeVB0LarqanWT2Om7rEP+wK+db28qLiVlY0/6gYGeVzQQEvtGkxNLOEF +JWrOXKWhvAaMxP8a/i/N02i3dSJbZv6Ydc2EIPgWD4ZzGd7qw2qC2T361z5FLukewqUU RjQAuqKEPS/4KPA63MFFui3sWy9mEhxq0Ep6KLqMC6mhgwIbLvNmIUMMhc1PqhcqteqWc hwpCimY+sbGWyftE0QcSAPaTrPWelA1KcNbl8v366+x2oHelIEx0jZv3q22zGnarHT8dy X4nVyoMcvSoSIsY3/IrjG6ju+7LHEJS/1XcaFlpHVnODaVRl8lTWjJnnOf+jxAQSbow== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=azErJuvO; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37724606A31C; Sun, 29 Nov 2026 10:32:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=azErJuvO Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1955F1F00896; Sun, 29 Nov 2026 10:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795948349; bh=fpQN0fVt6qUqgvG962YtFlNmhmKnIGjYY/K6Y2l+MWg=; h=Date:Subject:To:Cc:References:From:In-Reply-To; b=azErJuvOZUdqG2Z791EZHO5nDvTgOXqCxnMw+WfLz4jwsLa1qfMWdLEx4CsWUuaO5 XwFpMuRuk3TcsfTlaSuLw1bn9MFbHR2gbBQoP0cmLuzZ3cTarwovSsL4yyjOuW5YnL 1/R5Yola3Edfw4+ioohBaeRbzhY9IxQz6U9P1mOE9ZSQf5n4A8Rs1txJBb4Nr3CMub F5ETgCdczW+epmokMG9GERAWQwj2Yuhl191nmIJQLylxioUZ+cWNinrONwZlDe45zT yGJ2d8EKk9NaTIS82XTIrKXjNyWZyeCJg7imkmJNdstXk5E43nVJumdtOB9nrc/F+j TK4xyhToNK20A== Message-ID: <06ea7db8-51d1-49e0-8592-300d084ea5fd@kernel.org> Date: Sun, 29 Nov 2026 11:32:20 +0100 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iov_iter: Fix direct I/O across compatible device pgmaps To: Naman Jain , Christoph Hellwig , Jens Axboe , Andrew Morton , Alexander Viro Cc: Oscar Salvador , Logan Gunthorpe , Leon Romanovsky , Keith Busch , linux-block@vger.kernel.org, linux-mm@kvack.org, linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, stable@vger.kernel.org References: <20261126053433.88531-1-namjain@linux.microsoft.com> <5cc60faa-002c-4c96-97e3-46d3002718c9@kernel.org> <74edd490-26bd-41a4-81ee-cd18b9f28154@linux.microsoft.com> From: "David Hildenbrand (Arm)" Content-Language: en-US Autocrypt: addr=david@kernel.org; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3Gp XNeiN4QroO+5qaSr0ID2sz5jtBLRb15RMre27E1ImpaIv2Jw8NJgW0k/D1RyKCwaTsgRdwuK Kx/Y91XuSBdz0uOyU/S8kM1+ag0wvsGlpBVxRR/xw/E8M7TEwuCZQArqqTCmkG6HGcXFT0V9 PXFNNgV5jXMQRwU0O/ztJIQqsE5LsUomE//bLwzj9IVsaQpKDqW6TAPjcdBDPLHvriq7kGjt WhVhdl0qEYB8lkBEU7V2Yb+SYhmhpDrti9Fq1EsmhiHSkxJcGREoMK/63r9WLZYI3+4W2rAc UucZa4OT27U5ZISjNg3Ev0rxU5UH2/pT4wJCfxwocmqaRr6UYmrtZmND89X0KigoFD/XSeVv jwBRNjPAubK9/k5NoRrYqztM9W6sJqrH8+UWZ1Idd/DdmogJh0gNC0+N42Za9yBRURfIdKSb B3JfpUqcWwE7vUaYrHG1nw54pLUoPG6sAA7Mehl3nd4pZUALHwARAQABzS5EYXZpZ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VNr7yBic4yfzVWGCGNE4DnOW0vcIeoyhy9vnIa3w1uZ 3iyY2Nsd7JxfKu1PRhCGwXzRw5TlfEsoRI7V9A8isUCoqE2Dzh3FvYHVeX4Us+bRL/oqareJ CIFqgYMyvHj7Q06kTKmauOe4Nf0l0qEkIuIzfoLJ3qr5UyXc2hLtWyT9Ir+lYlX9efqh7mOY qIws/H2t In-Reply-To: <74edd490-26bd-41a4-81ee-cd18b9f28154@linux.microsoft.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit On 11/27/26 05:05, Naman Jain wrote: > > > On 11/26/2026 6:42 PM, David Hildenbrand (Arm) wrote: >> On 11/26/26 06:34, Naman Jain wrote: >>> Commit 38446014648c ("block: don't merge different kinds of P2P transfers >>> in a single bio") made bio_add_page() reject pages from different >>> dev_pagemaps. This was needed for PCI P2PDMA, but also rejected pages >>> with compatible DMA mapping requirements. >>> >>> Commit 41c665aae2b5 ("block: relax pgmap check in bio_add_page for >>> compatible zone device pages") allows these pages in separate bvecs. >>> Commit 13920e4b7b784 ("block: add pgmap check to biovec_phys_mergeable") >>> prevents physically contiguous bvecs from different pgmaps from being >>> merged into one segment. >>> >>> But direct I/O now fills a bio using iov_iter_extract_bvecs(), which >>> retained the original restriction and bypasses bio_add_page(). >>> For a non-atomic request handled by a single bio, only the data before >>> the pgmap boundary is submitted. The rest is not transferred, and the >>> request completes with fewer bytes than requested. >>> >>> Fix this by moving zone_device_pages_compatible() from blk.h to >>> memremap.h and using it in iov_iter_extract_bvecs(). This allows >>> compatible pages to be added as separate bvecs without relaxing the >>> same-pgmap requirement for PCI P2PDMA. >>> >>> Fixes: 38446014648c ("block: don't merge different kinds of P2P transfers in a single bio") >>> Cc: stable@vger.kernel.org >>> Signed-off-by: Naman Jain >>> --- >>> block/blk.h | 19 ------------------- >>> include/linux/memremap.h | 19 +++++++++++++++++++ >>> lib/iov_iter.c | 3 ++- >>> 3 files changed, 21 insertions(+), 20 deletions(-) >>> >>> diff --git a/block/blk.h b/block/blk.h >>> index 50abfd9328861..460c064f1d1b0 100644 >>> --- a/block/blk.h >>> +++ b/block/blk.h >>> @@ -142,25 +142,6 @@ static inline bool biovec_phys_mergeable(struct request_queue *q, >>> return true; >>> } >>> >>> -/* >>> - * Check if two pages from potentially different zone device pgmaps can >>> - * coexist as separate bvec entries in the same bio. >>> - * >>> - * The block DMA iterator (blk_dma_map_iter_start) caches the P2PDMA mapping >>> - * state from the first segment and applies it to all subsequent segments, so >>> - * P2PDMA pages from different pgmaps must not be mixed in the same bio. >>> - * >>> - * Other zone device types (FS_DAX, GENERIC) use the same dma_map_phys() path >>> - * as normal RAM. PRIVATE and COHERENT pages never appear in bios. >>> - */ >>> -static inline bool zone_device_pages_compatible(const struct page *a, >>> - const struct page *b) >>> -{ >>> - if (is_pci_p2pdma_page(a) || is_pci_p2pdma_page(b)) >>> - return zone_device_pages_have_same_pgmap(a, b); >>> - return true; >>> -} >>> - >>> static inline bool __bvec_gap_to_prev(const struct queue_limits *lim, >>> struct bio_vec *bprv, unsigned int offset) >>> { >>> diff --git a/include/linux/memremap.h b/include/linux/memremap.h >>> index c8a4979d4c780..a1d447a847990 100644 >>> --- a/include/linux/memremap.h >>> +++ b/include/linux/memremap.h >>> @@ -202,6 +202,25 @@ static inline bool is_pci_p2pdma_page(const struct page *page) >>> folio_is_pci_p2pdma(page_folio(page)); >>> } >>> >>> +/* >>> + * Check if two pages from potentially different zone device pgmaps can >>> + * coexist as separate bvec entries in the same bio. >>> + * >>> + * The block DMA iterator (blk_dma_map_iter_start) caches the P2PDMA mapping >>> + * state from the first segment and applies it to all subsequent segments, so >>> + * P2PDMA pages from different pgmaps must not be mixed in the same bio. >>> + * >>> + * Other zone device types (FS_DAX, GENERIC) use the same dma_map_phys() path >>> + * as normal RAM. PRIVATE and COHERENT pages never appear in bios. >>> + */ >>> >> >> Can you convert this to proper kernel doc while at it? >> >> Also this should all be working on folios instead of pages. But that will need a >> zone_device_folios_have_same_pgmap() so we can defer it, not suitable for this fix. >> > > IIUC, you want me to change this comment to kernel doc, something like this. > > /** > * zone_device_pages_compatible() - Check if pages can share a bio > * @a: First page > * @b: Second page > * > * Check if two pages from potentially different zone device pgmaps can > * coexist as separate bvec entries in the same bio. > * > * The block DMA iterator (blk_dma_map_iter_start()) caches the P2PDMA > * mapping state from the first segment and applies it to all subsequent > * segments, so P2PDMA pages from different pgmaps must not be mixed in > * the same bio. > * > * Other zone device types (FS_DAX, GENERIC) use the same dma_map_phys() > * path as normal RAM. PRIVATE and COHERENT pages never appear in bios. > * > * Return: %true if the pages can coexist as separate bvec entries in the > * same bio, otherwise %false. > */ > > I can do that in next version. Thanks. Yeah, can we rename the function while moving it? in bio.h the "bio" context was quite clear. In memremap.h it's a bit weird. If this is all about bios, I'd squeeze that into the filename and make it clearer for *what* they are compatible. -- Cheers, David