Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3022092rwb; Mon, 15 Aug 2022 16:19:33 -0700 (PDT) X-Google-Smtp-Source: AA6agR62uY9mraG6qYyBFDdEj2+gotgSVMabgp8yummEcYXPr8eXMTqXW3ZCmpvV8BJtL27kWwGR X-Received: by 2002:a17:907:a218:b0:731:2b2b:f34 with SMTP id qp24-20020a170907a21800b007312b2b0f34mr11846044ejc.404.1660605474563; Mon, 15 Aug 2022 16:17:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660605474; cv=none; d=google.com; s=arc-20160816; b=sh8COfzSq8SnNP6SrXfYXWlAyO/Nr4pji0V/mpXE3EsyEG9TcDdgZJ0Rgb9CtuO7UU jIIdXvCybg9hzJAyfsYQKBgsWDtwoXSwSUNc9YmqMVEOOsRnpBHPHxViQl6UPaffCq18 mYkrXbHSc0TEVv2XgV3EqiC/zNTAGT6gqnn677e3DtVjshzg9yGZkoke6pqx9/Qt+kpH eHUdp5Ween3iTXDGXPEcRqHKzfvkQvJUJZ+d69ZybxhJlW9dF4vZW2Src/Lx6YniR9m/ jdQoapmX4KN5K8MoxJC5etThrvWhro7S81fOYrBR2BfPWMPGjbm0AhoSzghvoJwRNxhu wToA== 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=n6LP91g3RuG1bUynJEBMjU2xWzTJMTx6zRCEiYO1vxI=; b=XZpxgKHPPcQ24BDXZ9LlMucvTZROApk/xvJ1vT5Gnceb2VHpE4KcNDIiOYtjk/poWf oGi1sWwk2C+0/g+F3FVm3v1gJrgL3+b6KsIOnJOUJCJgvrpi5LCnfAjbzN8foJ0PdJ3f UD23fapq/4u2Cx0W0bwV+xXR6nN9EFTqwnKqwd8dDH3HYZGXs5yhTEARVNu8PEjeS8d+ uqfdDLPPOUtkx4XEXo0F7ohRAWK4PhPo2Sk8PD6zc7kTYMRgk/5PdKqT04GaYciEeqg5 5CXFAEyKNyc3tOgcP/w1RuOVqpdlbPuVJrw4+MwjGCqMiZxp9D25kq81aS6CNBmmpx7K pGWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hTYU8sN0; 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 cs10-20020a170906dc8a00b006fea2a02361si8613244ejc.371.2022.08.15.16.17.28; Mon, 15 Aug 2022 16:17:54 -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=hTYU8sN0; 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 S1348252AbiHOW3y (ORCPT + 99 others); Mon, 15 Aug 2022 18:29:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348628AbiHOWYS (ORCPT ); Mon, 15 Aug 2022 18:24:18 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FF12125D5C; Mon, 15 Aug 2022 12:44:16 -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 B105F61206; Mon, 15 Aug 2022 19:44:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A02E8C433C1; Mon, 15 Aug 2022 19:44:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660592655; bh=MoeozJqCnJo6pSScNpsVtHy3goijawpt8UNpV7zwa4Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hTYU8sN0Em4FVdy/XYiwUpY1pAhyw+m2pqPJCu87kfpwjyQMwNdOK5bK0reTrREyi rQUMag3SKbpatkkt1YM3B/Abf3JtdBM1sYnVWEAkxZjI2KnYE7dp4OJHrYurIL0E0d wk227qmWhIe474KRTryK9PmmdeYrJgoPq4ZuuBhQ= 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.18 0822/1095] jbd2: fix outstanding credits assert in jbd2_journal_commit_transaction() Date: Mon, 15 Aug 2022 20:03:41 +0200 Message-Id: <20220815180503.305558324@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@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 ac7f067b7bdd..f306b52b8e0b 100644 --- a/fs/jbd2/commit.c +++ b/fs/jbd2/commit.c @@ -551,13 +551,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