Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp463107pxf; Thu, 8 Apr 2021 06:46:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLtNx6/emj8vEAyhaBI1Mq0bMi3xtJPrcfhJmR4kPTi/hU3BMyBty70oQka2N+cOsflMz7 X-Received: by 2002:a17:906:eb87:: with SMTP id mh7mr10830697ejb.143.1617889594376; Thu, 08 Apr 2021 06:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617889594; cv=none; d=google.com; s=arc-20160816; b=fMC3bHYsy+oPjPdy1PYQ/WgNmdX1IC/i5WYQx5IFYfieSF4XvggkNbsVIkc+uTL+e+ OTnLOWX2wlojzbid808t8fMMeGTXF8uG7CTn6pwrghiS2dMppjtBmGY7+X2KZlRVveGc RbNfT2dAt2iP7hVYcVgrtaDYgZm0zPPem47Qru4SkImgZhjZ18TKEjNLCHOIgLnt27nE hDHWldfj3KDoJVWhXtatg1QjAnIMPdC50viglmbxP3NmobT5dgT/PgudCuCe4Wp/pTO+ YPTxTwzm7k4fQk33G0/oMI/6xXM5ODZ6UkDUIapin4NgLh8GfiropsMMogILCbcrksoX BcuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=9WIjAIHdQsIg46BFx+Svz+uwUD8bJTCx25Z4WIbR0oI=; b=E6YL4l8YogKadIpJk6dz+KIrnDf7vlrck+/weLaS5mmmbxIBDyDa0455ocM6G/QjyS PhdsiWJbhGK0QiuBV3RxDbh8A6jYO4CAALLaZMUScO7/wXHQrIcaHxI+7lbTnCakx9bN YL6T7CFHH8q1cM7e8D3CXFrq9WLmoeRE8hlI0qACZocpikU/xdG2R3wggQyPI1TowHY8 Id+rfkAWwyqJtmFFtz5idBqy9mJ9A+vR8vYZuhxhmIyzGlG05F379AjE/9E36ZcPLU3r edAygHJ0hLL814vMVmnbwo5kwfjOsl+MSYqwuhcnwV+1J+bNKu9CwqjLhSOYglsgWvK0 hSSg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lu3si8862894ejb.560.2021.04.08.06.46.03; Thu, 08 Apr 2021 06:46:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230467AbhDHNqE (ORCPT + 99 others); Thu, 8 Apr 2021 09:46:04 -0400 Received: from mx2.suse.de ([195.135.220.15]:41286 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231621AbhDHNqE (ORCPT ); Thu, 8 Apr 2021 09:46:04 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 13704B032; Thu, 8 Apr 2021 13:45:52 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id BBECB1F2B77; Thu, 8 Apr 2021 15:45:51 +0200 (CEST) Date: Thu, 8 Apr 2021 15:45:51 +0200 From: Jan Kara To: Zhang Yi Cc: linux-ext4@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yukuai3@huawei.com Subject: Re: [PATCH 1/3] jbd2: protect buffers release with j_checkpoint_mutex Message-ID: <20210408134551.GC3271@quack2.suse.cz> References: <20210408113618.1033785-1-yi.zhang@huawei.com> <20210408113618.1033785-2-yi.zhang@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210408113618.1033785-2-yi.zhang@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org On Thu 08-04-21 19:36:16, Zhang Yi wrote: > There is a race between jbd2_journal_try_to_free_buffers() and > jbd2_journal_destroy(), so the jbd2_log_do_checkpoint() may still > missing to detect the buffer write io error flag and lead to filesystem > inconsistency. > > jbd2_journal_try_to_free_buffers() ext4_put_super() > jbd2_journal_destroy() > __jbd2_journal_remove_checkpoint() > detect buffer write error jbd2_log_do_checkpoint() > jbd2_cleanup_journal_tail() > <--- lead to inconsistency > jbd2_journal_abort() > > Fix this issue by add j_checkpoint_mutex to protect journal buffer > release on jbd2_journal_try_to_free_buffers(). > > Signed-off-by: Zhang Yi Thanks for the patch Zhang. I agree with your problem analysis but I don't think the solution is correct: > J_ASSERT(PageLocked(page)); > > + mutex_lock(&journal->j_checkpoint_mutex); We cannot grab j_checkpoint_mutex inside jbd2_journal_try_to_free_buffers() (or even ext4_releasepage()) because that function is called withe a page lock which ranks below the checkpoint mutex - generally page locks are acquired within a transaction and thus all locks required to start a transaction (and j_checkpoint_mutex is one of them) rank above the page lock. Also even if the lock ordering was OK, grabbing j_checkpoint_mutex for every page from memory reclaim just to close this rare race seems like a performance overkill. What we seem to need is a quick way of marking the journal as "IO error occured" in __journal_try_to_free_buffer() before actually removing the buffer from the checkpoint list. Perhaps this marking could even happen already in __jbd2_journal_remove_checkpoint() and we can reuse it in jbd2_log_do_checkpoint() for IO error handling as well... And then once we are in a safer context, we can do: if (!is_journal_aborted(journal) && journal_io_error_happened(journal)) jbd2_journal_abort(...) Honza > head = page_buffers(page); > bh = head; > do { > @@ -2163,6 +2164,7 @@ int jbd2_journal_try_to_free_buffers(journal_t *journal, struct page *page) > if (has_write_io_error) > jbd2_journal_abort(journal, -EIO); > > + mutex_unlock(&journal->j_checkpoint_mutex); > return ret; > } > > -- > 2.25.4 > -- Jan Kara SUSE Labs, CR