From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 156FE606A31C for ; Mon, 30 Nov 2026 04:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=oSbcLtwc Received: by kanga.kvack.org (Postfix) id 3B5A06B05B2; Sun, 29 Nov 2026 23:44:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 367066B05B3; Sun, 29 Nov 2026 23:44:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2560E6B05B4; Sun, 29 Nov 2026 23:44:15 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id E35186B05B2 for ; Sun, 29 Nov 2026 23:44:14 -0500 (EST) Received: from smtpin06.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2E355A02C0 for ; Mon, 30 Nov 2026 04:44:14 +0000 (UTC) X-FDA: 85490543628.06.0BC7081 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by imf08.hostedemail.com (Postfix) with ESMTP id 4E10516000E for ; Mon, 30 Nov 2026 04:44:12 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=oSbcLtwc; spf=pass (imf08.hostedemail.com: domain of namjain@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=namjain@linux.microsoft.com; dmarc=pass (policy=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796013852; b=g4suZeUmHx3pG9eJ7wVHoWFSoVW/Q4CDONP3fKE1lcfIAgc5juKZ8PtezdJbScu0RWshij FH4kNy3mcWA3r433wejaTfDJd7WC/Jde+hXCSBkMlIVZhPtEgkNFCyjo2mUCKpUt4LEhiT cLxhTfR+8zUrPt1y/qhQDgw9IlD32xw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796013852; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ISRoO5ENrhr7vo+Vf3L107XjJlsgbN2smFiGHEo4dZ8=; b=R5CzAHnFZWnk/Zskm31ENHw44nhzLr/ytjnx3/gA+GMgFwHVZzjq3lGTHbPBFYUAufTAca DDaAU663xUdXnd7h/9qAkRKWKsbezFdKMRgQC0Cr3OxnP/mk4NiozZlnRcNvbQCZasIMwY XeEMh4ciqeiBhRdhJdK/M9I6T6ZSjWM= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=linux.microsoft.com header.s=default header.b=oSbcLtwc; spf=pass (imf08.hostedemail.com: domain of namjain@linux.microsoft.com designates 13.77.154.182 as permitted sender) smtp.mailfrom=namjain@linux.microsoft.com; dmarc=pass (policy=none) header.from=linux.microsoft.com Received: from [10.95.64.116] (unknown [52.172.102.219]) by linux.microsoft.com (Postfix) with ESMTPSA id D1DAF20B7166; Sun, 29 Nov 2026 20:43:59 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D1DAF20B7166 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1796013843; bh=ISRoO5ENrhr7vo+Vf3L107XjJlsgbN2smFiGHEo4dZ8=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=oSbcLtwcG7Fksz1vR1hSFk/+oKi67d5fzsAHDAuW8mees2kqEYmkLBzAzv0AQ0WwQ 1ccqVzjVTPcmRm46s/O33CUKsj/q5jmRl4FOz9S/1owdx9uwuqmyn/beVHxG3Pn3VB snPiPx/OT+/1s06ROHeUlDmQXF/FZJiMLJO6beCk= Message-ID: <20488a10-37a1-44a6-986d-e92dca87dd01@linux.microsoft.com> Date: Mon, 30 Nov 2026 10:14:03 +0530 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iov_iter: Fix direct I/O across compatible device pgmaps To: "David Hildenbrand (Arm)" , 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> <06ea7db8-51d1-49e0-8592-300d084ea5fd@kernel.org> Content-Language: en-US From: Naman Jain In-Reply-To: <06ea7db8-51d1-49e0-8592-300d084ea5fd@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Rspam-User: X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 4E10516000E X-Stat-Signature: wi5g1gd671kfhfu955chqibj57kjg1cs X-Spam-Status: No, score=-17.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=4.0.1 X-HE-Tag: 1796013852-99533 X-HE-Meta: U2FsdGVkX18fE+5wgpliVA1wWxU749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gODDtiaJDATDKKKBOXzIo9EWEjhWZ0Xv0Q7hSyIKJ6hhmS/tnFM9QqsUP5npZHWtk9I0xm7fxoBCyMgz2exbpzHFvc3MOm/bjYs+ggAU8ph7m3hWWyfxq6XpE37F4g0K2UoDQYcDySv9qdS/rlXOE99KlGVUbQWa5rhx34aWlz5vK0pCfR11ezHLwY2EwO9IVWsDFsuW6SX6Il7OVV/L0UmADuhK/405nPpKN0+c6MdeBScepnYDphjtXRLkgsTsQ3B6SFbW7ohsZBT/8nGWV6GBzef3FG7Q0IoIql9iAXgqDwFU6liK6z7/DS+j1YYOOP5Jh8kY09oGI9nSK+TB8zEdlg4mrGxayoupclzWzEsT3mRr9VpibQ60OLRMPshbQWuVhdLG1UZvrrMJoYRLfe2GyrEeLzcTdtHfp3RtQW3q5FPr04a2LKtPlH4QMnO5ThbEpMBlSv9Pu3Aw== Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: On 11/29/2026 4:02 PM, David Hildenbrand (Arm) wrote: > 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. > zone_device_pages_bio_compatible() is an alternative. Please let me know if this looks good. Regards, Naman