From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379286; b=rQ0dL5zjZl2lN7GrgLwO5MuSy0UHWZz+ceSzPOvN+EaNlRhXTJuOy15G6v6k6UDfQrHn w/BrD1R7hdoNcJSEQfT8tgzJIiZ95aAOAqf6VgUekLYA8GFr89SB57Ukf/saKsdNru+Og mfA2nDSqEfUnIGCjrw4hE1LDEY5BxIv2VX6wg3dUojjXay4W5jjgUQ+5w29OymqsWXnvn pIeqnOZPD39LhowW6ox4VnJB//o241cYn9QWVGUCM/iNLlJtYSbDicAcZqfjlgUKC/LRO yJK+A17VQZ4YWrfONz9dpwBl5MVovdRXaMeKZtWC55gswqbyMctqMOnYSNvbSv29Qtg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379286; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=8/BqSnJRQ+n4PguSmXTWDL56QerbD4WpXCjIqOKfTFs=; b=TAysulZuV/Mmfr9ZJqJDXsky+eDrnjatYQ5JpG+WPYRWh2I5z3Gsm4GaVJ48WesrdeEd 73JCGEpjvkZ8iXEjIH5pVJlkfUryrtWIy7FDYm+TML0D4sWWmhVVsZeI7LOzGevCH6kr5 gGan1JCTeSMKoPnKzSQ+fXUmM3LoB1JAjjMBakW04i10sQd2QxfLuv3EAkMdgzYZKTrdN gmpzi4G9UgCBSFAdnpG1GaywQpPZL8Ds3IOpocdk3iPkCYjWZNx4zfKG+8GrFX/84/eBN q1IisX2DZKo08K19uMFJCnuf4OLa0BgdE642i8FUGoCKkamN7xP5v1m4V/5p4NlhdVw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kKHQOyqj; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C08A0606A32C; Fri, 4 Dec 2026 10:14:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=kKHQOyqj Received: by smtp.kernel.org (Postfix) with ESMTPSA id F1AE91F000C2; Fri, 4 Dec 2026 10:14:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379286; bh=8/BqSnJRQ+n4PguSmXTWDL56QerbD4WpXCjIqOKfTFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kKHQOyqjPigSkUAHz7SVx7VlsVfsuqnFlp/jy6J1xp+lmLlxtLtPRaOnt0cfyEmj+ fxYGu2aKpm6XFwnUYOhfnyW4uN55xdODXZzzx/ss0Ye8j0RskZxsTPHEVqDzY2xNfj OH9r9RHwHq+9B4082GZ2xnUX5jf9UeDqRdkPBV2U= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jan Kara , "Christian Brauner (Amutable)" , Sasha Levin Subject: [PATCH 7.3 019/742] fs: set I_METADATA_WRITEBACK in mmb_mark_buffer_dirty() Date: Fri, 4 Dec 2026 18:58:03 +0900 Message-ID: <20261204100635.551546432@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Christian Brauner [ Upstream commit d4fdde3257a577f184b4498d040f6fe20be72326 ] ext2, ext4 without a journal, fat, udf and minix track the metadata buffers of an inode in a mapping_metadata_bhs list and sync them from ->sync_inode_metadata() and ->evict_inode(). The inode block itself is only tracked by I_METADATA_WRITEBACK which ->write_inode() sets after copying the inode into its buffer. Set the bit in mmb_mark_buffer_dirty() as well so that it covers all the metadata an inode may still have to write out. Set it after the buffer is on the list. An fsync() that sees the bit then also finds the buffer when it walks the list, and one that cleared the bit before we set it leaves it set for the next one. The inode itself may never have been dirtied. fat for example tracks the FAT buffers on a private inode that nothing marks dirty. So attach the inode to a wb before setting the bit, the way ext4_mark_iloc_dirty() does, or writeback_single_inode() has no wb to lock once evict() syncs it. That lets evict() write out everything the bit tracks in one place instead of every ->evict_inode() calling mmb_sync() itself. Suggested-by: Jan Kara Cc: stable@vger.kernel.org # v7.3 Link: https://patch.msgid.link/20261109-work-inode-metadata_writeback-v3-8-91ac6c024018@kernel.org Reviewed-by: Jan Kara Signed-off-by: Christian Brauner (Amutable) Signed-off-by: Sasha Levin --- fs/buffer.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/buffer.c b/fs/buffer.c index 30e7f2cc2386f..3f430fb824500 100644 --- a/fs/buffer.c +++ b/fs/buffer.c @@ -623,12 +623,15 @@ void write_boundary_block(struct block_device *bdev, * @bh: The buffer to mark dirty. * @mmb: The list of buffers to add the buffer to. * - * Mark the buffer dirty and add it to the list if it is not already on - * a list. + * Mark the buffer dirty, add it to the list if it is not already on a list + * and set I_METADATA_WRITEBACK on the inode so that fsync() and eviction + * write it out. */ void mmb_mark_buffer_dirty(struct buffer_head *bh, struct mapping_metadata_bhs *mmb) { + struct inode *inode = mmb->mapping->host; + mark_buffer_dirty(bh); if (!bh->b_mmb) { spin_lock(&mmb->lock); @@ -643,6 +646,15 @@ void mmb_mark_buffer_dirty(struct buffer_head *bh, list_move_tail(&bh->b_assoc_buffers, &mmb->list); spin_unlock(&mmb->lock); } + /* + * The inode itself may never have been dirtied, so attach it to a wb + * before setting the bit or writeback_single_inode() has nothing to + * lock when evict() syncs it. + */ + spin_lock(&inode->i_lock); + inode_attach_wb(inode, NULL); + inode_state_set(inode, I_METADATA_WRITEBACK); + spin_unlock(&inode->i_lock); } EXPORT_SYMBOL(mmb_mark_buffer_dirty); -- 2.53.0