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 CE117606A332 for ; Fri, 4 Dec 2026 12:48:35 +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=q5uA0qY4; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=d1bGc/lm; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=q5uA0qY4; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=d1bGc/lm Received: by kanga.kvack.org (Postfix) id F179C6B05B4; Fri, 4 Dec 2026 07:48:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC8356B05B5; Fri, 4 Dec 2026 07:48:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D6BF26B05B8; Fri, 4 Dec 2026 07:48:34 -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 D27F16B05B4 for ; Fri, 4 Dec 2026 07:48:33 -0500 (EST) Received: from smtpin10.hostedemail.com (lb01a-stub [10.200.18.249]) by unirelay09.hostedemail.com (Postfix) with ESMTP id F0B23803B2 for ; Fri, 4 Dec 2026 12:48:32 +0000 (UTC) X-FDA: 85506279264.10.0E7AC46 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by imf07.hostedemail.com (Postfix) with ESMTP id DC4C840010 for ; Fri, 4 Dec 2026 12:48:30 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=q5uA0qY4; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="d1bGc/lm"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=q5uA0qY4; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="d1bGc/lm"; spf=pass (imf07.hostedemail.com: domain of bdas@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=bdas@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; a=rsa-sha256; d=hostedemail.com; s=arc-20220608; cv=none; t=1796388511; b=aoFZEW7aZVRZVTyXDUgHrUZ4tSp6sYnYdJtadJxQlFs9xQns9OjYhTfDHPWl/0K0pgtCvB FjYdl7KorXICjc5jjUTY8ZVAXc/iFHWMYEnQB/ZT1g3JDcNbKULBHCnf0R2XFFjw9zKMTK a48kAv+TsjVOuCi03zcFUgszaGXxwTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1796388511; 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=1TlkxjjilTllF9+J/LrHIdu/RfI2TK7+Q+H5iF5ZCoQ=; b=y1vWjxuS/hwdIexX04qJjU5FZbYmiU+76ZD2cZVq4Zehitb4SRJWcgXY2af8WJ3IHF/2YT 1L9F0rHCX0EMRGthF+C4SCijO2gb9Si3tbkSFU7iHj35G91zjvS6g3SL06G8CWkQP8rmjI +QB4FWO7+URTWzB586/G/eJI5TBB+WI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=q5uA0qY4; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="d1bGc/lm"; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=q5uA0qY4; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b="d1bGc/lm"; spf=pass (imf07.hostedemail.com: domain of bdas@suse.de designates 195.135.223.131 as permitted sender) smtp.mailfrom=bdas@suse.de; dmarc=pass (policy=none) header.from=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-out2.suse.de (Postfix) with ESMTPS id 6CF395BDC5; Fri, 4 Dec 2026 12:48:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796388509; 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=1TlkxjjilTllF9+J/LrHIdu/RfI2TK7+Q+H5iF5ZCoQ=; b=q5uA0qY4YD6Spy737v0zFKVPwOg6bRGOnD3+IS8AT6RahPUeYXMT1QkdlEv1fO6clUNlLr cuAwNtD5IQTVDwODVOd81J2TmjpJ6UMLeqpLTprVKRsio2ajTkl/z6PZv1w52JsaiZedgk uCLE5qzdVdO/E8aVNHFKqqb8sJPnJn0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796388509; 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=1TlkxjjilTllF9+J/LrHIdu/RfI2TK7+Q+H5iF5ZCoQ=; b=d1bGc/lm+1bkbdtB6KR6Myc2lcmFoHRZGwF+q88N9vJYZdaPCsvTxsg2TBoiKn7PLiEq4K h3sp1p5nU3xhVwDg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796388509; 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=1TlkxjjilTllF9+J/LrHIdu/RfI2TK7+Q+H5iF5ZCoQ=; b=q5uA0qY4YD6Spy737v0zFKVPwOg6bRGOnD3+IS8AT6RahPUeYXMT1QkdlEv1fO6clUNlLr cuAwNtD5IQTVDwODVOd81J2TmjpJ6UMLeqpLTprVKRsio2ajTkl/z6PZv1w52JsaiZedgk uCLE5qzdVdO/E8aVNHFKqqb8sJPnJn0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796388509; 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=1TlkxjjilTllF9+J/LrHIdu/RfI2TK7+Q+H5iF5ZCoQ=; b=d1bGc/lm+1bkbdtB6KR6Myc2lcmFoHRZGwF+q88N9vJYZdaPCsvTxsg2TBoiKn7PLiEq4K h3sp1p5nU3xhVwDg== 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 E0BAF1342D; Fri, 4 Dec 2026 12:48:28 +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 i7gjI5y2Emu3XwAAD6G6ig (envelope-from ); Fri, 04 Dec 2026 12:48:28 +0000 Date: Fri, 4 Dec 2026 18:18:18 +0530 From: Brahmajit Das To: Pedro Falcato Cc: Qu Wenruo , dsterba@suse.com, linux-btrfs@vger.kernel.org, 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, syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com, willy@infradead.org, jack@suse.cz, hch@lst.de 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-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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DC4C840010 X-Rspam-User: X-Stat-Signature: wjt7ziahayp9whyzpapn469zhzk4tn9w X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-HE-Tag: 1796388510-820632 X-HE-Meta: U2FsdGVkX19IiNQPtUYqwttJl44k3Eu4/+FXcnJJvHFEAMsd2XUT8638aLmSsBBF/9gb0zR/b6kBL9lA4NH96TMvAbzRLN+UeQ7I0FTDk7YkxyQw3hhwdrUP0g9Tb7eIbPUBe4zmWFlmUYql6mEWaCeI1+q5UNfXmujYUv9Rp4fuFeMg1qiO3lItnDBEu5iEYNnQq8v4NBNf8VRFsWyNGd5iSNd/1/0i5ui+VCQN7BiPj1USXU2gg9iNruvBfINuZRNgCT8Zpyo86fqe+ITuJo2D+S0iXltD+lFFW1JuG0U8VgiNBaTEGSWsVNZeYgZTBvAHNf1ylHFKTllfkXw2DLw3Okt0x6N+Lu+XBa499fJR5mdmfoj9rCx7XBdWv8GK+1Tj8Tj5FW5GLXpEpTglIgDHcf8uNmi+OOd2Zi3btXjosc3S1dSSPdGSXW/603L9VdJ5u7YP8HL5dCQ8Og1ssIEXxj/Bl6Vl88HlDuDr+lSRxSHh6wEqY2Pf7akp0RPmzIZu6DLe4j/DiNofdkOWHo6rmJwXI7M07I+P14nq/l/xPg3Iy/qzzQGk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nwxeLFOQ35xPn3DK4qeeOywwqvuJHnS5rk2uEBEynkNcMXUGhJ8KiCwp7oYuEzwnPZbaQs+SND94ssTECHumZRdLLeDsK3J+SsES8EgOtoKTdU2b4HoyK4jeOaEtIcnnpGr1TKn8xFrSgeL9Wbjn9fdwmFsycIJQ6Q= 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 10:05:49 +0000, Pedro Falcato wrote: > +CC willy, jack, hch > > On Fri, Dec 04, 2026 at 07:13:08AM +1030, Qu Wenruo wrote: > > > > > > 在 2026/12/3 23:58, Pedro Falcato 写道: > > [...] > > > > 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) > > > > One assumption doesn't meet the current code. > > > > > - ->dirty_folio() relies on buffers/IFS/etc being attached to the > > > folios. It _cannot_ attach them itself, as dirty_folio() cannot > > > block. > > > > Iomap is already attaching it: > > > > iomap_dirty_folio() > > ifs_alloc(inode, folio, 0); > > gfp = GFP_NOFS | __GFP_NOFAIL; > > ifs = kzalloc_flex(..., gfp); > > > > Either it's already a bug, or we won't hit such folio without private for > > the non-sleeping routes. > > This is, strictly speaking, a bug. Per Documentation/filesystems/locking.rst: > > locking rules: > All except dirty_folio and free_folio may block > > I think currently, de facto, it's not very likely to be hit[1]. Mostly because, > for writenotify filesystems/VMAs, you'll always trip over ->page_mkwrite() > (marking the folio dirty), and cleaning will always write-protect it before > clearing the dirty flag off the folio. > > [1] I _think_ there are ways to hit it, if you go down funky folio_cancel_dirty() > paths. > > > > > > > > > > > > > > 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()? > > > > If a folio is beyond EOF, we have no need to write it, thus can go > > invalidating it directly. > > Why would you not rely on truncation itself to invalidate it? > > > > > Or is there any better solution from the perspective of MM? > > My understanding is that the truncation logic should correctly handle > the semantics you want. > > As for the GUP problem, yes, this is yet another issue. It is known. > ->dirty_folio() implementations cannot assume the memory allocation will > succeed. And there's no possible fallback to "failure to dirty a folio". > > The real solution (in my series) is to simply not discard this at-will. > invalidate_folio() seems to be yet another variant of this issue. > > For what it's worth, I observed a similar issue in mm/truncate code. I don't > know what the correct approach would be. Keep the private around for GUP pins? > Reject the truncate altogether? > > (I don't think it's possible to do this last option; keeping the private is > also weird, and I don't see how you can possibly ditch it after the folio is > orphaned) > > -- > Pedro Just to note by mistake I created v2 a separate thread. v4 is at: https://lore.kernel.org/all/20261204063235.1033893-1-listout@listout.xyz/ -- Brahmajit Das SUSE L3