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=1796388516; b=r9xATSnBBWLSgCGeUlOQxulhDL23IGwkjJFS46Wn/bnZGbMLr7BDc3LN3bcyexzwas+0 qISdvZsOhR9v91JtSv2cDRC8KpC5zhDP0KPfWxMzs/RYI+hnEqOgSOnGY2iJbla2ywW76 hKNCJ5hbGdBROpY1DBZh61NACim8cXktk8BgB/Q/yPYafOtXSmeAIeR8orugK4+JMPZYI 0rLehSwjcihzW/wNzmqHvNpxsoQs9WZQgasVg2JLKoHZid1+jV+jeqdiJVecAdzHRcmHg 4VjIkntvdV6Fcumip79Cd1grf62oDABqdo2HQPR4ertUZ8jNBq8CLItvVsZJ0Qt0aSw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388516; 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: Content-Transfer-Encoding:In-Reply-To:X-Spamd-Result:X-Spam-Score: X-Spam-Level:X-Spam-Flag; bh=1TlkxjjilTllF9+J/LrHIdu/RfI2TK7+Q+H5iF5ZCoQ=; b=O3myKStWxzkax+AsYKiLi1Y4z9DAxSgpngllQmixMXILGefObMide20Z81am/gkcgaAJ PVY1VhLoYXZ1FRpeIT9XzOBqvqa9z8CEEqCL9Q1u1ecWhRT5zq/ZxoRf4cqbW13Z+QZll JkkDOJcTUZtONXd8U3auSa8To37yUB7NT50YY6RCNabdFtv8fPpDoqKHu2pc4h8ehwLeU +MsVihQA3JhWKxHy1Mlz7hMhRGCVRWVV+caeIiKIVY4+iHnCHQE7ztNFrzDgeCXLgUQZz RFgIcgoz+M2j9IUsJlx45TiuhJC1oT9u1YnzNGY3ZNVUarKaxXxhe/btcUehy72J9/w== 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=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 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"; 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 56ECB606A33F; Fri, 4 Dec 2026 12:48:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 56ECB606A33F 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=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: 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== Authentication-Results: smtp-out2.suse.de; none 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-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=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: 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]; ARC_NA(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCPT_COUNT_TWELVE(0.00)[17]; RCVD_TLS_ALL(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TAGGED_RCPT(0.00)[d6f123d4060990f0f3ff]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -11.80 X-Spam-Level: X-Spam-Flag: NO 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