Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp1864347rwb; Fri, 19 Aug 2022 10:39:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR65vtml44KxD1ez6tK+KHeKZf8tYKw5j+uUyCSU/qKL5qKaCRl6hvYs1ScPdMZ/mU9G14vC X-Received: by 2002:a65:460c:0:b0:429:f162:78e1 with SMTP id v12-20020a65460c000000b00429f16278e1mr7223295pgq.7.1660930761541; Fri, 19 Aug 2022 10:39:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660930761; cv=none; d=google.com; s=arc-20160816; b=ezIPQfopCUyf2v6PkTH3/2ioRxR+2LO9M8YVD86w4oFZV+K9EYzyVZ+2HhCZy7fUie crW6/uRPFk/eCgT5VVT2Cl4ofqaJw7xBhrgdAC6sHPe1X5aHevyArnzloXfR9kJc1Oqj +qjMbpoCf0Kx4MQgC+V6rFWbHEp0I5mEbKAKFUt6RCayy/pMbEqaQUwKpP4p10l6yjeZ 4WQLQOh53fLvpCUN6G47Aitta2gtEAdHcV6q5GW5oiMowkVzpy5fg0VKx8bQUq4yUQAJ pQZrHNlIvivWL2llWx5HilADZjfNoJTmxzk1rOXdejNaMIZTdcdbtGe+MEpI5g6umVVs Nq8w== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=tz8k9ATeAGUH+eRjTrzuSEWhTKj+DEYPMtwb3ZUPA8o=; b=E9QpgHnGmVtigKfblvK1pm2/ECycqMvvT0A8lz30CmM/fy35+fbZ0OyGWewUi7DmtX XJa5c8sNPSS7uR0KCmHc57o/6ho2ECyLd+8C+7c5bqqh/Q5lEiJy1PJnXXNCAGm3arGm puOakWwnEz7QHDCm6qvtyPmBhzAwLSmxDUZUZA8le9jxmH4DBaNRibE/pHijViT9g7Th wBgdcz0wWNwMJz2TGFTkOvv1T9NCbJpAi+pPr3QrXrd0iBvWc1auVXV8rhX6/S99fY/Y QjVqNb1VkPw9NOIUyQ57Sgex6i1onmzk9GrVcEUhoKaBN6HAlU425gQYTqEVW2lZtxFL JJhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UMJVgTPL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t20-20020a17090aba9400b001f0761ae6besi6829096pjr.91.2022.08.19.10.39.10; Fri, 19 Aug 2022 10:39:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-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=@linuxfoundation.org header.s=korg header.b=UMJVgTPL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352950AbiHSQ3a (ORCPT + 99 others); Fri, 19 Aug 2022 12:29:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56766 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353158AbiHSQ0U (ORCPT ); Fri, 19 Aug 2022 12:26:20 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BC0810F698; Fri, 19 Aug 2022 09:03:49 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 8987C617A8; Fri, 19 Aug 2022 16:03:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91C9AC433C1; Fri, 19 Aug 2022 16:03:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660925023; bh=hetWV8UaTx9nf9SJteaS+CRHYoqVCfrTSvqfCWuDS1A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UMJVgTPLhYt8rcj3MYHZPsUu9xEzkT6Hg3etivpvtc7KfcsOgdKRltgjlNckI6KSc EIYddLH7ytGsnoOOXnX+6yRIZIwu8H/N1F8gSr7A9dVkrZJgt2gkTzcEk9xNu7gidu B22SRlILQyqL6qSo9EIHbDdbuWJym99HVtItfAAA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Yi , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 5.10 359/545] jbd2: fix outstanding credits assert in jbd2_journal_commit_transaction() Date: Fri, 19 Aug 2022 17:42:09 +0200 Message-Id: <20220819153845.451878736@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220819153829.135562864@linuxfoundation.org> References: <20220819153829.135562864@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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-kernel@vger.kernel.org From: Zhang Yi [ Upstream commit a89573ce4ad32f19f43ec669771726817e185be0 ] We catch an assert problem in jbd2_journal_commit_transaction() when doing fsstress and request falut injection tests. The problem is happened in a race condition between jbd2_journal_commit_transaction() and ext4_end_io_end(). Firstly, ext4_writepages() writeback dirty pages and start reserved handle, and then the journal was aborted due to some previous metadata IO error, jbd2_journal_abort() start to commit current running transaction, the committing procedure could be raced by ext4_end_io_end() and lead to subtract j_reserved_credits twice from commit_transaction->t_outstanding_credits, finally the t_outstanding_credits is mistakenly smaller than t_nr_buffers and trigger assert. kjournald2 kworker jbd2_journal_commit_transaction() write_unlock(&journal->j_state_lock); atomic_sub(j_reserved_credits, t_outstanding_credits); //sub once jbd2_journal_start_reserved() start_this_handle() //detect aborted journal jbd2_journal_free_reserved() //get running transaction read_lock(&journal->j_state_lock) __jbd2_journal_unreserve_handle() atomic_sub(j_reserved_credits, t_outstanding_credits); //sub again read_unlock(&journal->j_state_lock); journal->j_running_transaction = NULL; J_ASSERT(t_nr_buffers <= t_outstanding_credits) //bomb!!! Fix this issue by using journal->j_state_lock to protect the subtraction in jbd2_journal_commit_transaction(). Fixes: 96f1e0974575 ("jbd2: avoid long hold times of j_state_lock while committing a transaction") Signed-off-by: Zhang Yi Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220611130426.2013258-1-yi.zhang@huawei.com Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/jbd2/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c index 867362f45cf6..98cfa73cb165 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -564,13 +564,13 @@ void jbd2_journal_commit_transaction(journal_t *journal) */ jbd2_journal_switch_revoke_table(journal); + write_lock(&journal->j_state_lock); /* * Reserved credits cannot be claimed anymore, free them */ atomic_sub(atomic_read(&journal->j_reserved_credits), &commit_transaction->t_outstanding_credits); - write_lock(&journal->j_state_lock); trace_jbd2_commit_flushing(journal, commit_transaction); stats.run.rs_flushing = jiffies; stats.run.rs_locked = jbd2_time_diff(stats.run.rs_locked, -- 2.35.1