From patchwork Thu Oct 10 02:58:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liubaolin X-Patchwork-Id: 1995211 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=KeOhi5Z/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=150.107.74.76; helo=mail.ozlabs.org; envelope-from=srs0=g4lz=rg=vger.kernel.org=linux-ext4+bounces-4538-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XPDyK27s0z1xsc for ; Thu, 10 Oct 2024 14:00:08 +1100 (AEDT) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XPDyD6LMdz4x4c for ; Thu, 10 Oct 2024 14:00:04 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4XPDyD6HVWz4wnw; Thu, 10 Oct 2024 14:00:04 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip=147.75.199.223 arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1728529204; cv=pass; b=bbLO64NN0kR4aGrp9zuPw9fVA7WaE6NEbgVmUSMUhbStfZqTu9scwFK1KkzBkGkPLCA26iWxZ8z4F6AWyJDZOwPoGVFUL1mdK09ExC7txNna1xyWD7/bfDEhhZet38njsVQ8fk9Vi0ZyrZS3LlpL3JHKaBrHJ7BNb4TH7iFQbpTzev89AxgT9Bw3hFCt1dUOCtfWSXQ5Nak8JppvMwuss4M2jBmEDRtJnJw7Jo5FWQw/bs9/0bc/tnuw92VrhmV84j+tftsykz/g8pjIF1OLa2CL58p70jYVqy/4mF8n4bUFZTsPNU+Gy5o7UCXAHWUbbWQSiLuegJn/H1wL5qC9Ww== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1728529204; c=relaxed/relaxed; bh=SDA7ZYp2Z4hIwN64hp5hPfoNZvkXl2fYdBoL9D4Lwy8=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=oTVJhFXEWK97IIzc9lsn1CIW5EUdTdNaBJ7Zcc0dhj+BT3iq7ozb0bAMDzOvkpeEwpTloD1oBfUaslt11jDCsIcdRWSRv6QCkhPU2IVrq0YQv67yLzTXWyrkIEfoTH5wJQzvWxrcxWAWtbvA+VA4bEnBvYFsKolOufgq4vQUXTi+43h+ElWdsvqPbzEtc7h54qQ6YtuOZfRO5hfnLtpRRaeNtTymFz79KpVcR03vTZ8RH/uGpTBn16qBNsXWuYN5jKW2UtHsBPWTjeTOLyXtl6tYQsgyiF4FcLBZzru2NkycMQGZVPWdCRKkbr7B+L25hTg7kwsDtX/HnFDFg+iJ8A== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=163.com; dkim=pass (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=KeOhi5Z/; dkim-atps=neutral; spf=pass (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4538-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: gandalf.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=163.com header.i=@163.com header.a=rsa-sha256 header.s=s110527 header.b=KeOhi5Z/; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=147.75.199.223; helo=ny.mirrors.kernel.org; envelope-from=linux-ext4+bounces-4538-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [147.75.199.223]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XPDyC07rBz4x4c for ; Thu, 10 Oct 2024 14:00:03 +1100 (AEDT) Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 131921C23A50 for ; Thu, 10 Oct 2024 03:00:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D23C18CBE5; Thu, 10 Oct 2024 02:59:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b="KeOhi5Z/" X-Original-To: linux-ext4@vger.kernel.org Received: from m16.mail.163.com (m16.mail.163.com [220.197.31.5]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0888E188704; Thu, 10 Oct 2024 02:59:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728529152; cv=none; b=fYvM2XvDZzScsDT0+qAM2mNtF3y3N38LZUpC7xaTn1P7vZLk7Bs6id5dqluKHBgc+YnwQUWDDfWdwzHawjkD5N9MrwmPA60L+ng9BJswG+Ibh+VsYPtr2MZC5xbUgmYe5aqZDv4v+a1JLRkJ2BBnQeLPvVvg1Me0Z23gej1byUs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728529152; c=relaxed/simple; bh=6KcPaF+1W6KzpMYD4h2jaZLaTzqARo1nCL7ouwgqo0Q=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=iX37dWvY3Kt9VIvK9OrzuFm9wDOpNh/8KJFmE09YTwHhfrO8aS68bJiSJ/zSDML304Jzb/7+f9StRLWsOK3tUEILKdvef9c44hh4WF2rZaiA2mp3WCptqFDu8RwS2KabrwgitUa2OLwb2BJ9Oef2+WKUTq8hGliZVAygAoo2Dsc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com; spf=pass smtp.mailfrom=163.com; dkim=pass (1024-bit key) header.d=163.com header.i=@163.com header.b=KeOhi5Z/; arc=none smtp.client-ip=220.197.31.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=163.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=163.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=SDA7Z Yp2Z4hIwN64hp5hPfoNZvkXl2fYdBoL9D4Lwy8=; b=KeOhi5Z/9w9u9wV+j494u Cb/EKv0t5a2vzErAYjcADhCSpwRzRT162RQxbzSYEGycLGlGV7Msz2sIcp2QmMcR +FzkiVTCniaN5U3bcwY7emAEi3yTRE7E6WEiGMEI3EA+EPlO39plvC5fWr1BG9aO gmiKHUTqQUsMC41kXm87c4= Received: from liubaolin-VMware-Virtual-Platform.localdomain (unknown [223.70.253.255]) by gzga-smtp-mtada-g1-2 (Coremail) with SMTP id _____wD3_y3wQgdnZpfDAA--.21796S2; Thu, 10 Oct 2024 10:58:58 +0800 (CST) From: Baolin Liu To: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz Cc: zhangshida@kylinos.cn, longzhi@sangfor.com.cn, linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, Baolin Liu Subject: [PATCH v1] ext4: fix a assertion failure due to ungranted bh dirting Date: Thu, 10 Oct 2024 10:58:55 +0800 Message-Id: <20241010025855.2632516-1-liubaolin12138@163.com> X-Mailer: git-send-email 2.39.2 Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CM-TRANSID: _____wD3_y3wQgdnZpfDAA--.21796S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxuF45Jr48uF1fKryrWw13twb_yoW5Gr48pr 9xKr93KrWjqry2gFZ3KF47ZF1UWa48GrW7GFWfGry5Za45GFnFgFyjqr1DJF1qkrWxAw1r XFW8Aryak3WjyrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07joAp5UUUUU= X-CM-SenderInfo: xolxutxrol0iasrtmqqrwthudrp/1tbiMRB0ymcHPNfEFQAAsF From: Baolin Liu Since the merge of commit 3910b513fcdf ("ext4: persist the new uptodate buffers in ext4_journalled_zero_new_buffers"), a new assertion failure occurred under a old kernel(ext3, data=journal, pagesize=64k) with corresponding ported patches: ================================================================ Call trace: __ext4_handle_dirty_metadata+0x320/0x7e8 write_end_fn+0x78/0x178 ext4_journalled_zero_new_buffers+0xd0/0x2c8 ext4_block_write_begin+0x850/0xc00 ext4_write_begin+0x334/0xc68 generic_perform_write+0x1a4/0x380 ext4_buffered_write_iter+0x180/0x370 ext4_file_write_iter+0x194/0xfc0 new_sync_write+0x338/0x4b8 __vfs_write+0xc4/0xe8 vfs_write+0x12c/0x3d0 ksys_write+0xf4/0x230 sys_write+0x34/0x48 el0_svc_naked+0x44/0x48 ================================================================ which was caused by bh dirting without calling do_journal_get_write_access(). In the loop for all bhs of a page in ext4_block_write_begin(), when a err occurred, it will jump out of loop. But that will leaves some bhs being processed and some not, which will lead to the asserion failure in calling write_end_fn(). To fixed that, get write access for the rest unprocessed bhs, just as what write_end_fn do. Fixes: 3910b513fcdf ("ext4: persist the new uptodate buffers in ext4_journalled_zero_new_buffers") Reported-and-tested-by: Zhi Long Suggested-by: Shida Zhang Signed-off-by: Baolin Liu Signed-off-by: Baolin Liu --- fs/ext4/inode.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 54bdd4884fe6..a72f951288e4 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1102,9 +1102,24 @@ int ext4_block_write_begin(handle_t *handle, struct folio *folio, err = -EIO; } if (unlikely(err)) { - if (should_journal_data) + if (should_journal_data) { + if (bh != head || !block_start) { + do { + block_end = block_start + bh->b_size; + + if (buffer_new(bh)) + if (block_end > from && block_start < to) + do_journal_get_write_access(handle, + inode, bh); + + block_start = block_end; + bh = bh->b_this_page; + } while (bh != head); + } + ext4_journalled_zero_new_buffers(handle, inode, folio, from, to); + } else folio_zero_new_buffers(folio, from, to); } else if (fscrypt_inode_uses_fs_layer_crypto(inode)) {