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 9C34D606A322 for ; Fri, 4 Dec 2026 06:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=faPm1RA0; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qOyhv6Qs; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=faPm1RA0; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=qOyhv6Qs Received: by kanga.kvack.org (Postfix) id BA80C6B05BF; Fri, 4 Dec 2026 01:36:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B57EB6B05C0; Fri, 4 Dec 2026 01:36:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A1FC46B05C1; Fri, 4 Dec 2026 01:36:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 7690E6B05BF for ; Fri, 4 Dec 2026 01:36:16 -0500 (EST) Received: from smtpin11.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 88275140266 for ; Fri, 4 Dec 2026 06:36:12 +0000 (UTC) X-FDA: 85505340984.11.9634DCD Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf25.hostedemail.com (Postfix) with ESMTP id 4B65DA0002 for ; Fri, 4 Dec 2026 06:36:10 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=faPm1RA0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qOyhv6Qs; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=faPm1RA0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qOyhv6Qs; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf25.hostedemail.com: domain of bdas@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=bdas@suse.de ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796366170; b=by02rH46iP8cVNwgFxXlbZqPCIR5Im+0mbtgvnzJyCMM45vdb8mFDJJInlCCsh5HL8Kkps jsj5iUD2tCqN/vK/lJGg93GAuNkP1mNd9er79zKd7CYtM9HKEeO2TBpO9arc/Yp+Ebx+Tn 8/L2qpyp7x6yVMyGeHGPPNJfI62r0OU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796366170; 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=E6x2CtHuAfQSvkZbE+HaWQ95y+k1NHgVx5J3jIrt5C4=; b=oxvE1zu65V/54ZVCt6lvqnHa2KXycl0JNwSRuVXUjnzHYId48+/P2UNXNJG2W+n530RgaB s+YacJ//DxmfFiVb1Tpbjper6nmkn8rz5YjcaO7tRsE6ALvyg5937xvBxGEv6RXq9i5Qua 2noYSlcFcG5Jmz0ug2Np9yqIeGX781A= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=faPm1RA0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qOyhv6Qs; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=faPm1RA0; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=qOyhv6Qs; dmarc=pass (policy=none) header.from=suse.de; spf=pass (imf25.hostedemail.com: domain of bdas@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=bdas@suse.de Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 9E8B437330; Fri, 4 Dec 2026 06:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796366168; h=from:from:reply-to: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; bh=E6x2CtHuAfQSvkZbE+HaWQ95y+k1NHgVx5J3jIrt5C4=; b=faPm1RA09qTevKGP1ERqZGRcMt+Lbt5WfP3N7nYnkGdHwCeuY6SU/sDSCEv2eu2knUIQTr ImT5RvMtUkZTqPuVcsOF6pqe8pdI0xCRhZ5ovi6piJRYAv9O+lVMl6BSf0bKnuGJpax9u+ gQlWLBijKFyOsgGnsXFUWY9s+35OC/Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796366168; h=from:from:reply-to: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; bh=E6x2CtHuAfQSvkZbE+HaWQ95y+k1NHgVx5J3jIrt5C4=; b=qOyhv6QsnnPTBTr5lJdIxGQg1aM96m8SYjmR/LSJZTtCMiHZIFHVn6vj3Z8wBEcN6Ovuwl g3bqPspcw4cu1uAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796366168; h=from:from:reply-to: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; bh=E6x2CtHuAfQSvkZbE+HaWQ95y+k1NHgVx5J3jIrt5C4=; b=faPm1RA09qTevKGP1ERqZGRcMt+Lbt5WfP3N7nYnkGdHwCeuY6SU/sDSCEv2eu2knUIQTr ImT5RvMtUkZTqPuVcsOF6pqe8pdI0xCRhZ5ovi6piJRYAv9O+lVMl6BSf0bKnuGJpax9u+ gQlWLBijKFyOsgGnsXFUWY9s+35OC/Y= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796366168; h=from:from:reply-to: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; bh=E6x2CtHuAfQSvkZbE+HaWQ95y+k1NHgVx5J3jIrt5C4=; b=qOyhv6QsnnPTBTr5lJdIxGQg1aM96m8SYjmR/LSJZTtCMiHZIFHVn6vj3Z8wBEcN6Ovuwl g3bqPspcw4cu1uAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id ED4ED1342D; Fri, 4 Dec 2026 06:36:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id DDfmJFdfEmsbZAAAD6G6ig (envelope-from ); Fri, 04 Dec 2026 06:36:07 +0000 Date: Fri, 4 Dec 2026 12:06:05 +0530 From: Brahmajit Das To: Qu Wenruo Cc: David Sterba , linux-btrfs@vger.kernel.org, Chris Mason , David Hildenbrand , Jason Gunthorpe , John Hubbard , Peter Xu , linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com Subject: Re: [PATCH v3 3/3] btrfs: re-attach folio private when a released folio gets dirtied Message-ID: References: <6ab2d179.e8212013.2d060.0001.GAE@google.com> <20261203133059.2193197-1-listout@listout.xyz> <20261203133059.2193197-4-listout@listout.xyz> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Score: -11.80 X-Spam-Level: X-Stat-Signature: 9gg95xpmqi68zcpn5i4hb7r785b3mosx X-Spam-Status: No, score=-16.0 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 autolearn=ham autolearn_force=no version=4.0.1 X-Rspam-User: X-Rspamd-Queue-Id: 4B65DA0002 X-Rspamd-Server: rspam07 X-HE-Tag: 1796366170-91794 X-HE-Meta: U2FsdGVkX1/vK6cXC8ekKolO40uZOJ7rXak/woMA+XLEfZQ2fhUObJnBEZUIhybQq3shYN8tesIUV5JBJqrW7IzkTLn1HYjCJ1oyuFrHbjnrMAPXfO98DX3SJrGvEEKzRAzoRSzb684ycvyOS6m25Gqr/nibg1m0X+VleIxGws6sE57L2KU/CWAr7av7mUyyYI9oRzf5GHtBtQlssyT9/ufHt3Q6Hwf06QJEgCoJhNSMP0laec7mdvOKaa1ly7lv/0DlEx4v8o6Ik8Thfg+/lK4qXzTfj1ibLEGWePk7ADQKIPaS36c5+cjaA80wVmN4rUaGoPRDCYrUkUkZyEcbUrdQkdVeazNmpxRs7NEtn0Py/rc1NO5G5xUWLzxsLJ7L+7LfDgW8lXyyjQiFnarQCksY8ZInF2b0d3e8AJ2ZJFDbY3XRlAbf7xegDHyA/c/eCUWNj5vRQ+byz6t6lw1rkEBKxsPKLLJ29A+1lFj174vE45pHzxOxZCx+quxNE1YCtq/oVLosP6ZYtB3mOde+nbomeZr008cKBAPJnZr8MrTOukJJ2Knlz2aQT8QaojLTh2BQC8DgtWIda9bI/+lW8yv+StTo8kHB1xASxp56NCE7/SZU4W77HgUqKwdqtJ21x8m9MH6bqHFZ+3z5xsJQEUnbJ+xjodatcLEDizoJSiklM+EgPyUtsICwfjQCuhj8MZaEVX6aZjM4+cOoRVE5p6atV//kwpJvs0wiPpUXkivzdVmTVMNgFdimwfVGzoNmyLEVEh8fEaSiTpURGYCty8DSttGT98KKvshXi8Lf6YVvGAi6dbqIFQgAsKsBDmeoyAJDOSYLjRjbrVEEG8TrF2kSmEInlzmb1GG7ziWPk8iIImN6EzHT/obDDTKW895WyFa0KKr95Kl6sHeoXcb/X8b1IKIjDYpC9pHQRRrtInA9vxn4AD87gFDSojENx8iesh/GbHtIRLBC/SJN7+u lG9hDqMK 47liFhnr5AghJZwBUQZzR49yvFviF68/5Ctwy3LAjC3XJbK9Eeylo0tNQEf2xXoB+t0eHg7YPshiqj4Vov2tXP4weSW7onvjy+pAIvEwvDBHPCzJpg5OCe2Fu7jVzZez6ZI8xXAaHiEuBqYD0HSeaVIr6PS1sQzoIp3PYRgQjavpiyyfkMAzZgz/4bC4xQPeh+++TZbcHIUqEc+lim48p0z8d77aPnVx5odTMpSVn+YPVxxXBr6vyDhBoz6v/6R8fxDj7BkL4uU9jeQZhCVxFIZqzO/wR/2ykeHdti4ubcxz7pSI7p/JWajuYMjZ5o8V9o9LbHTBeY/JrAkfwbkQUGe9sdsIYeTHtUaYlDs6+ufT44QLZILi46rOAniPgo6eN7HRZQKQhrSlqo+V2QYa2PVRzInW2HIj+l46MqbpIFPo+f0wMwmsxGwroN3J4xK/93v2ZhDY27bN2ltxbSdLnuMcyJwktOqhbiFWNQAlUPueEaNfAM3onE0GqYBxLMY7RAbMBscb5ILSIJlI76ncjFu03Z1tE/5JKPtqhGtbjLHqE+ciNyy81NvGT2CIQUkJ2bmfVqMKRujOr0E884Lt3HHGBTbkQIU2eChmcLo2wnUsAJzxbZkWsOvY+hNZbQlXRIpmNZCwzZRw56SdlCEGq2hmx+vjue+7VDnLHR0LFMRxYYa1sf7nmiZAQIn8k34Qshr3uRG6fTpW4QGX2ZpEE+GTOaUSoOufnPDIka9V99ImtULHWq1aG8fDH97zExPOUtGJI5iZPje8sqw/SUm9gxJCbSP6ThYUvbLl69G0wFIkG8fnpCBRxBKtl3nuErE2/Yk22NY14A6jkiBfUG6lQo2YCGWvhprYnMfctIjxTo8GUZMLgHkWk0C+k3kWPwqaCV9+FldbWT7jvusW1P9AsyZaZAs9VCPEoadCv4JFIKrTF4wA= Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Fri, Dec 04, 2026 at 07:06:55 +1030, Qu Wenruo wrote: > > > 在 2026/12/4 00:00, Brahmajit Das 写道: > > From: Brahmajit Das > > > > syzbot reported an assertion failure in wait_subpage_spinlock(): > > > > assertion failed: folio_test_private(folio) && folio_get_private(folio), > > in fs/btrfs/inode.c:7616 > > kernel BUG at fs/btrfs/inode.c:7616! > > Call Trace: > > btrfs_invalidate_folio+0x26e/0xc50 > > extent_writepage fs/btrfs/extent_io.c:2058 [inline] > > extent_write_cache_pages fs/btrfs/extent_io.c:2843 [inline] > > btrfs_writepages+0x129f/0x28c0 > > do_writepages+0x338/0x560 > > filemap_fdatawrite_range+0x1ef/0x2f0 > > btrfs_start_ordered_extent_nowriteback+0x305/0x6e0 > > btrfs_page_mkwrite+0x856/0x1a40 > > ... > > __gup_longterm_locked+0x1032/0x15c0 > > ... > > blkdev_direct_IO+0x121d/0x17b0 > > aio_read+0x33a/0x4d0 > > > > The program does an O_DIRECT read into a MAP_SHARED mapping of a btrfs > > file, while the same file is being truncated. > > > > A dirty folio of a btrfs data inode is expected to have folio::private, > > but a folio can lose it while it stays in the page cache and is pinned > > by an in-flight O_DIRECT read, e.g.: > > > > truncate_inode_partial_folio() > > folio_invalidate(folio, offset, length) > > btrfs_invalidate_folio() > > btrfs_release_folio() /* folio is clean */ > > __btrfs_release_folio() > > clear_folio_extent_mapped() > > folio_split_or_unmap() > > folio_split() /* fails, the folio is pinned */ > > > > or from any failed large folio split, as __folio_freeze_split_file() > > calls filemap_release_folio() before folio_ref_freeze(). > > > > When the read completes, the folio is re-dirtied without notifying the > > fs: > > > > bio_release_pages() > > folio_mark_dirty() > > btrfs_data_dirty_folio() > > filemap_dirty_folio() > > > > If the folio is beyond EOF by then, btrfs_data_dirty_folio() does not > > touch any btrfs state, and the next writeback calls folio_invalidate() > > on a folio without private, triggering the above ASSERT() in the > > bs < folio size case. If the folio straddles EOF, > > btrfs_folio_set_fixup_dirty() dereferences the NULL folio private > > instead. > > > > Fix it by re-attaching the folio private in btrfs_data_dirty_folio() > > if it is missing. ->dirty_folio() may not block, so use GFP_NOWAIT. > > The folio was only released, not invalidated, so it may still be > > uptodate; btrfs_attach_folio_state() now syncs the uptodate bitmap with > > the folio flag for that. > > > > If the allocation fails, skip marking the blocks for fixup rather than > > dereferencing a NULL private. For a folio beyond EOF, attach the > > private in the beyond-EOF branch of extent_writepage(), which can > > sleep, before calling folio_invalidate(). A folio inside EOF is then > > rejected by writeback with -EUCLEAN, which no longer crashes after the > > previous patch. > > > > Note: syzbot has no reproducer for this issue. The fix was only build > > tested, the race has not been reproduced locally. > > > > This patch was written with the help of an AI coding assistant (Claude), > > from the syzbot report, console log and review feedback. > > > > Reported-by: syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com > > Closes: https://syzkaller.appspot.com/bug?extid=d6f123d4060990f0f3ff > > Fixes: 0680cbbf39ca ("btrfs: trigger cow fixup via dirty_folio()") > > Signed-off-by: Brahmajit Das > > --- > > > > Notes: > > v3: > > - Split into a series: fix the NULL dereference on the -EUCLEAN path > > of extent_writepage() (patch 1), sync the uptodate bitmap in > > btrfs_attach_folio_state() for all callers (patch 2) (Sashiko AI review) > > - Drop the explicit uptodate bitmap sync from btrfs_data_dirty_folio(), > > now done by patch 2 > > - v2: https://lore.kernel.org/linux-btrfs/20261202041853.4184717-1-listout@listout.xyz/ > > v2: > > - Re-attach the folio private in btrfs_data_dirty_folio() instead of > > skipping folio_invalidate() for folios without private (Qu) > > - Attach private only inside the beyond-EOF branch of extent_writepage(), > > leaving the unexpected dirty folio check alone (Qu) > > - Sync the uptodate bitmap of the new folio state with the folio flag > > - Explain where the folio private is dropped in the changelog > > - Cc GUP maintainers for the GUP part of the reasoning (Qu) > > - v1: https://lore.kernel.org/linux-btrfs/20261130182637.468143-1-listout@listout.xyz/ > > > > fs/btrfs/extent_io.c | 24 +++++++++++++++++++++--- > > fs/btrfs/extent_io.h | 1 + > > fs/btrfs/inode.c | 16 +++++++++++++++- > > fs/btrfs/subpage.c | 5 +++-- > > fs/btrfs/subpage.h | 3 ++- > > 5 files changed, 42 insertions(+), 7 deletions(-) > > > > diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c > > index 9dded5c670de..e2a6a4bf7f4b 100644 > > --- a/fs/btrfs/extent_io.c > > +++ b/fs/btrfs/extent_io.c > > @@ -923,11 +923,12 @@ static int attach_extent_buffer_folio(struct extent_buffer *eb, > > folio_attach_private(folio, prealloc); > > else > > /* Do new allocation to attach subpage */ > > - ret = btrfs_attach_folio_state(fs_info, folio, BTRFS_SUBPAGE_METADATA); > > + ret = btrfs_attach_folio_state(fs_info, folio, BTRFS_SUBPAGE_METADATA, > > + GFP_NOFS); > > return ret; > > } > > -int set_folio_extent_mapped(struct folio *folio) > > +int set_folio_extent_mapped_gfp(struct folio *folio, gfp_t gfp) > > { > > struct btrfs_fs_info *fs_info; > > @@ -939,12 +940,18 @@ int set_folio_extent_mapped(struct folio *folio) > > fs_info = folio_to_fs_info(folio); > > if (btrfs_is_subpage(fs_info, folio)) > > - return btrfs_attach_folio_state(fs_info, folio, BTRFS_SUBPAGE_DATA); > > + return btrfs_attach_folio_state(fs_info, folio, > > + BTRFS_SUBPAGE_DATA, gfp); > > folio_attach_private(folio, (void *)EXTENT_FOLIO_PRIVATE); > > return 0; > > } > > +int set_folio_extent_mapped(struct folio *folio) > > +{ > > + return set_folio_extent_mapped_gfp(folio, GFP_NOFS); > > +} > > + > > void clear_folio_extent_mapped(struct folio *folio) > > { > > struct btrfs_fs_info *fs_info; > > @@ -2046,6 +2053,17 @@ static int extent_writepage(struct folio *folio, struct btrfs_bio_ctrl *bio_ctrl > > pg_offset = offset_in_folio(folio, i_size); > > if (folio->index > end_index || > > (folio->index == end_index && !pg_offset)) { > > + /* > > + * btrfs_invalidate_folio() requires folio::private for the > > + * bs < folio size case. A folio can still get here without > > + * it, if btrfs_data_dirty_folio() failed its GFP_NOWAIT > > + * allocation. We can sleep here, so attach it now. > > + */ > > + ret = set_folio_extent_mapped(folio); > > + if (unlikely(ret < 0)) { > > + folio_unlock(folio); > > + return ret; > > + } > > folio_invalidate(folio, 0, folio_size(folio)); > > folio_unlock(folio); > > return 0; > > diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h > > index c55b37cb24b7..1da7606efaad 100644 > > --- a/fs/btrfs/extent_io.h > > +++ b/fs/btrfs/extent_io.h > > @@ -285,6 +285,7 @@ int btrfs_writepages(struct address_space *mapping, struct writeback_control *wb > > int btree_writepages(struct address_space *mapping, struct writeback_control *wbc); > > void btrfs_btree_wait_writeback_range(struct btrfs_fs_info *fs_info, u64 start, u64 end); > > void btrfs_readahead(struct readahead_control *rac); > > +int set_folio_extent_mapped_gfp(struct folio *folio, gfp_t gfp); > > int set_folio_extent_mapped(struct folio *folio); > > void clear_folio_extent_mapped(struct folio *folio); > > diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c > > index 95c9530554d0..a8fdd1b834f2 100644 > > --- a/fs/btrfs/inode.c > > +++ b/fs/btrfs/inode.c > > @@ -10739,7 +10739,21 @@ static bool btrfs_data_dirty_folio(struct address_space *mapping, > > round_up(i_size_read(&inode->vfs_inode), > > fs_info->sectorsize)); > > - if (range_end > page_start) > > + /* > > + * The folio may have lost its private while it stayed in the page > > + * cache, e.g. btrfs_release_folio() from a partial invalidation or > > + * from a failed large folio split, while it was pinned by GUP. When > > + * the pin is released, the folio is dirtied through here, so > > + * re-attach the private, as every dirty folio is expected to have it. > > + * > > + * We may not block here, thus GFP_NOWAIT. If that fails, the blocks > > + * can't be marked for fixup. Writeback attaches the private later > > + * for folios beyond EOF, and rejects folios inside EOF with -EUCLEAN. > > + */ > > + if (unlikely(!folio_test_private(folio))) > > + set_folio_extent_mapped_gfp(folio, GFP_NOWAIT | __GFP_NOWARN); > > Can you explain why iomap can go NOFAIL but why we can not here? > > I don't think this is any different from your previous atttempt, which can > still fail. > > And I think the iomap solution is more reliable than this one. > I used GFP_NOWAIT because I assumed ->dirty_folio() can run in atomic context. The atomic callers do exist (folio_mark_dirty() under the PTE lock in zap/unmap), but they only get there for a folio with a dirty PTE. A folio can only lose its private while it's clean, and a clean folio has no writable PTEs, so those callers always see a folio that already has private. The bio path dirties pages from process context, since bio_check_pages_dirty() defers to a workqueue. v4 uses GFP_NOFS | __GFP_NOFAIL like iomap_dirty_folio(), and the NOWAIT failure handling and the extent_writepage() fallback are gone. The uptodate sync now lives only in btrfs_data_dirty_folio(), as you asked on patch 2. -- Brahmajit Das SUSE L3