Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5410156rwl; Tue, 11 Apr 2023 05:12:40 -0700 (PDT) X-Google-Smtp-Source: AKy350avjLXZNp/v//hWLZC1JuIZ6lTt5jv5eqffx892l+LE09kD5xT9QegpdSsbZW+1spwJMQ4s X-Received: by 2002:a05:6402:12c9:b0:4fb:eda4:c093 with SMTP id k9-20020a05640212c900b004fbeda4c093mr13912926edx.13.1681215160161; Tue, 11 Apr 2023 05:12:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681215160; cv=none; d=google.com; s=arc-20160816; b=ddpQsY2nvrK9k720Tl1q0z5dhc+IwTfCyLs/tcoU4UEdj8cfHuWG6rCw8ulPhS65UV z6UqWyR6G8tHO7mhktQLk/13NZT5ASi68h1VPRd5JQ3lilvdgXVX01kMYTyQjDxyW+q4 H+zdKPWav5LBUDlLuPEnTBr02+Hsf/WN68okDHaNAxaIBKGSlD0JIfjfYFFkuvIigodi kWTircji1PQZDV0BF3eoMDr7ZSnvHSvP8N8+JwwKpwFBTmHyFmvJ2CxvKF9kfFfE2/s8 SBT6r3YWsFqFyvDMQEQ3wjWkgB+lOAQ0PWmdpP11h5S4Sa3AQEZl6k6gn8Qgfq4v8UeF 6LHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature:dkim-signature; bh=bv8x8jQlW6Pb0Rh2Oe1ctp/9xyNXEJx4R234z3ZM3W4=; b=eK3Rwnnb71tBspT1rNdi3aqYkX7UewnlODZ16qi9Mr9YxmmEChGj4FYF6njr3bFLYU X8yhx7ez1JgZgEITPIPonqB5dSTDYGMFrk+kHI25kpDmzLWoyNLmagZ2b6XfpridbIgy fN85/DXZ/cfIOJ3/FvVPj8i2/7bIt3zwocRKJiOxEZKFlYPJ7iN4aQxcSamuW86w7Ect vuMPyWMSieUVG6zIVg/kC+Qven22dYrUp9h5Ea8ttgWiwToO0md9h9SBHAjc7rxnoU2v h18V11uMz1+scZH7bJbykB+SCfdC5BmCbemB8jpjoIOWWhaAJvVOUD5AsB0bEIggcAG8 JVPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=tzoEcsb5; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=MifkFwh8; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y12-20020a50e60c000000b005025289a5dfsi12625339edm.128.2023.04.11.05.12.10; Tue, 11 Apr 2023 05:12:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=tzoEcsb5; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=MifkFwh8; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229451AbjDKMK1 (ORCPT + 99 others); Tue, 11 Apr 2023 08:10:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58546 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229562AbjDKMK0 (ORCPT ); Tue, 11 Apr 2023 08:10:26 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 452F8E7B for ; Tue, 11 Apr 2023 05:10:25 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E3A2E219DA; Tue, 11 Apr 2023 12:10:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1681215023; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bv8x8jQlW6Pb0Rh2Oe1ctp/9xyNXEJx4R234z3ZM3W4=; b=tzoEcsb5yESgle3g3nI8HT3OMn+fRzlmwMC1TJ1e11GtxvOmheUzeQuXm3qjPm0JHKf/c3 YKTvla+exI5nNFkaj74PwxsRjmkwtvYEHgF1h89f1iUz/L7qSri8sC2ujoRsJZZMGIJ5Lm tozIo7eBVHc5yNPUHiCsi1OVOmcHDXY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1681215023; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=bv8x8jQlW6Pb0Rh2Oe1ctp/9xyNXEJx4R234z3ZM3W4=; b=MifkFwh8CAX/q//2mIN0rzeeaCMA45jveTpUYKDtQHJ5ENmsjjlYddbNJgmRqSJswo3R6m s24Wi7JsCsrNTZBg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D32A413638; Tue, 11 Apr 2023 12:10:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id jHa4My9ONWRYCAAAMHmgww (envelope-from ); Tue, 11 Apr 2023 12:10:23 +0000 Received: by quack3.suse.cz (Postfix, from userid 1000) id 4E4B2A0732; Tue, 11 Apr 2023 14:10:23 +0200 (CEST) From: Jan Kara To: Ted Tso Cc: , Christian Brauner , Jan Kara , syzbot+aacb82fca60873422114@syzkaller.appspotmail.com Subject: [PATCH] ext4: Fix lockdep warning when enabling MMP Date: Tue, 11 Apr 2023 14:10:19 +0200 Message-Id: <20230411121019.21940-1-jack@suse.cz> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2523; i=jack@suse.cz; h=from:subject; bh=dD3uoQhrxJx8Hg+MhgRvQlTGtN7kO+Seo/HbO/qLn4Q=; b=owEBbQGS/pANAwAIAZydqgc/ZEDZAcsmYgBkNU4q0LYqi+HejodJpDdqQ8p+aqthCR8psLgTBWy4 kG2d0PuJATMEAAEIAB0WIQSrWdEr1p4yirVVKBycnaoHP2RA2QUCZDVOKgAKCRCcnaoHP2RA2f4fCA C2Cm8Li25hR8w/aalU0GwnEl8+r33qUqzAUwjxjl9DzfFCWgmwmQ4qpoJ9n1a2BIpwMAZlYesEnMsM 33NdX3cSjplrl732msBedTXP/Zt8ZKgCW5MEH8GdxYgx9jAE7/NSVM+GzZ30TKznp74jXrFbu5EwGK J8ffeNrJkJ5yD+zi6GuTfWBU2KUYcEVKGGDe/4MTPVqYwUVRDlRaP7BkKffyTglaJh2derALEGBWdi ruBMAh/Gxz7t8kxmteX8w70L8pk9DwlgHd3rhFquxR6zot+zk5/8iffba5XjZ5ZOGuUHi3wzNsCbPf Phx1PpUgb322jtIouZhTQamZQ7aJLX X-Developer-Key: i=jack@suse.cz; a=openpgp; fpr=93C6099A142276A28BBE35D815BC833443038D8C Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_SOFTFAIL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org When we enable MMP in ext4_multi_mount_protect() during mount or remount, we end up calling sb_start_write() from write_mmp_block(). This triggers lockdep warning because freeze protection ranks above s_umount semaphore we are holding during mount / remount. The problem is harmless because we are guaranteed the filesystem is not frozen during mount / remount but still let's fix the warning by not grabbing freeze protection from ext4_multi_mount_protect(). Reported-by: syzbot+aacb82fca60873422114@syzkaller.appspotmail.com Signed-off-by: Jan Kara --- fs/ext4/mmp.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c index 4681fff6665f..46735ce315b5 100644 --- a/fs/ext4/mmp.c +++ b/fs/ext4/mmp.c @@ -39,28 +39,36 @@ static void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp) * Write the MMP block using REQ_SYNC to try to get the block on-disk * faster. */ -static int write_mmp_block(struct super_block *sb, struct buffer_head *bh) +static int write_mmp_block_thawed(struct super_block *sb, + struct buffer_head *bh) { struct mmp_struct *mmp = (struct mmp_struct *)(bh->b_data); - /* - * We protect against freezing so that we don't create dirty buffers - * on frozen filesystem. - */ - sb_start_write(sb); ext4_mmp_csum_set(sb, mmp); lock_buffer(bh); bh->b_end_io = end_buffer_write_sync; get_bh(bh); submit_bh(REQ_OP_WRITE | REQ_SYNC | REQ_META | REQ_PRIO, bh); wait_on_buffer(bh); - sb_end_write(sb); if (unlikely(!buffer_uptodate(bh))) return -EIO; - return 0; } +static int write_mmp_block(struct super_block *sb, struct buffer_head *bh) +{ + int err; + + /* + * We protect against freezing so that we don't create dirty buffers + * on frozen filesystem. + */ + sb_start_write(sb); + err = write_mmp_block_thawed(sb, bh); + sb_end_write(sb); + return err; +} + /* * Read the MMP block. It _must_ be read from disk and hence we clear the * uptodate flag on the buffer. @@ -340,7 +348,11 @@ int ext4_multi_mount_protect(struct super_block *sb, seq = mmp_new_seq(); mmp->mmp_seq = cpu_to_le32(seq); - retval = write_mmp_block(sb, bh); + /* + * On mount / remount we are protected against fs freezing (by s_umount + * semaphore) and grabbing freeze protection upsets lockdep + */ + retval = write_mmp_block_thawed(sb, bh); if (retval) goto failed; -- 2.35.3