From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796304516; b=YcHqajUFpx5IBX1bPSBqNEx4ZTw/YE1NJTUkZHwiesM5HqBqorpFsX7Ov7Ck8gJQY935 79/2UkhEVSfqhcV47AI9O6CxPIW6jJjdfMxBrkejAI5L7fhCamHSB6HYZnXStShvLm05N Wbno2KXTVVj/ikoLivVkLcD3JHB+6WTmKRDF7F0eI4GDy4Lv/TGVwbMJpQwhGta6Nr9DI riRNDWZ20h7DhEFrVHbTgt/X26GSHj85hCAf7yLih5hUyoLid8HAheJrZiLOIUzX+BUda 36ft/1YSxKzpFY4BJXjXiWzkWhD8olLiPLf97hhj714aNcpPomnxq4My/oUxKGRbVEw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796304516; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:DKIM-Signature: DKIM-Signature:Received:Received:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To: X-Spam-Flag:X-Spam-Level:X-Spamd-Result:X-Spam-Score; bh=5yCurnU9pZyPN21ZG1YWNPyUoLBIY6wSxo1FwhaIoLw=; b=GixTchxndVWIITo+L1PL3EcF+QHL/5EewdQMwUpkNE+0w6x+U/NMHIKi+VPe8W2x5T7i KPHQ7lghtjkmbm15L0m0WSyBBeETfHLxBU0I237lLrbAq66pu/dnaOVx6ciA+zaVsjuvh GKhMR2lh4vilOBkcE9RYHmnyqCP/NtE3GTMaA+MrFhud9vzBGlDNKFiqbOJjPC5Zy7zcg 8cRca3B2Rtqmr+sVumxU5YNKBwb9yPQ9htTKBoGKGQcGmPuc6T4ktk7Qkj2tihnZXokQE QklOnb6n8YRnNPjWJoy1nwPRc5+NMi3cEVrGgzen+yI3+za0miASR+D0e03JVPaVzfA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.de; spf=pass smtp.mailfrom=suse.de; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=gGY8VHYc; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=nZ0w4Vy8; dkim=pass header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=G0cNaybu; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=KTva1eyT; arc=none smtp.remote-ip=195.135.223.131 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C6EE4606A322; Thu, 3 Dec 2026 13:28:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C6EE4606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.de 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=gGY8VHYc; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=nZ0w4Vy8; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=G0cNaybu; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=KTva1eyT 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-out2.suse.de (Postfix) with ESMTPS id CF6145CDCF; Thu, 3 Dec 2026 13:28:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796304513; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5yCurnU9pZyPN21ZG1YWNPyUoLBIY6wSxo1FwhaIoLw=; b=gGY8VHYca9B7IqEmvySNybT57n40CDAw+pyluWqdus82PvdakwCPD+uzkpvbHYfjtPMMXe PSeGkEIEQGMj504MZ8M7juvcBXqWNzqgUH2xkY2KUNolfim04jqxvXgKbII23mwBoQlFpQ 5Vm5S/bk7iyzXvaC+5Lwl8VFCEv13Xs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796304513; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5yCurnU9pZyPN21ZG1YWNPyUoLBIY6wSxo1FwhaIoLw=; b=nZ0w4Vy8fWbGXFjTgOTy05Z0jAsAYoWhKyb6VWsT9xTOEQ1JzsoLXTWUhxhCdyZyU/BSK3 Z0/AWvRxoUoCYtAA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796304510; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5yCurnU9pZyPN21ZG1YWNPyUoLBIY6wSxo1FwhaIoLw=; b=G0cNaybuJC8YqgJop3WGW0kT9x8L1cNEFr2+g8O8FJJGx28YMhHMr5cjRriGh9n5UiSZ6A yzZnNZUUrkRPu6wZ4vUntpGXkmPsvLfWenWJWSNVBoFVbitQsx/EjfSAM+lFEDqibFRYpp EFfUmaNPogQuTNKNYwBS0KTOOj3Gyqw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796304510; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=5yCurnU9pZyPN21ZG1YWNPyUoLBIY6wSxo1FwhaIoLw=; b=KTva1eyTnlW4nwCKTA13+7U9nX5v9x189mxf79zITgu0Ii+2UBX8suiMDqCcAXUbo0Kld8 FqZ02QccWmQsiGBg== 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 B4FD3134F6; Thu, 3 Dec 2026 13:28:29 +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 zKroGH1uEWsBXQAAD6G6ig (envelope-from ); Thu, 03 Dec 2026 13:28:29 +0000 Date: Thu, 3 Dec 2026 13:28:27 +0000 From: Pedro Falcato To: Brahmajit Das Cc: dsterba@suse.com, linux-btrfs@vger.kernel.org, quwenruo.btrfs@gmx.com, clm@fb.com, mason@kernel.org, david@kernel.org, jgg@ziepe.ca, jhubbard@nvidia.com, peterx@redhat.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, Brahmajit Das , syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com Subject: Re: [PATCH v2] btrfs: re-attach folio private when a released folio gets dirtied Message-ID: References: <20261202041853.4184717-1-listout@listout.xyz> 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 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261202041853.4184717-1-listout@listout.xyz> X-Spam-Flag: NO X-Spam-Level: X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; SUSPICIOUS_RECIPS(1.50)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MISSING_XM_UA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWELVE(0.00)[15]; ARC_NA(0.00)[]; TAGGED_RCPT(0.00)[d6f123d4060990f0f3ff]; FREEMAIL_ENVRCPT(0.00)[gmx.com]; TO_DN_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[suse.com,vger.kernel.org,gmx.com,fb.com,kernel.org,ziepe.ca,nvidia.com,redhat.com,kvack.org,googlegroups.com,suse.de,syzkaller.appspotmail.com]; RCVD_TLS_ALL(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email] X-Spam-Score: -11.80 On Wed, Dec 02, 2026 at 09:48:53AM +0530, Brahmajit Das wrote: > 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() FWIW, this sounds like a variant of https://lore.kernel.org/linux-mm/20261119-gup-dirty-what-v1-0-236d69f25c24@suse.de/. (which I will respin soon) > > 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 ? why is writeback calling folio_invalidate()? > 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. NAK to this approach. I need to think about folio_invalidate() and its interaction with GUP a little harder. -- Pedro