Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp644782pxb; Tue, 5 Apr 2022 17:07:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/0K/+7/mL/YXVajznXl77s1zMTp9vSCyoQoH8p+TgWMrMy3DfQ3etll84hJrvRYnMUTyf X-Received: by 2002:a17:90b:3508:b0:1c6:e4f9:538b with SMTP id ls8-20020a17090b350800b001c6e4f9538bmr7048591pjb.158.1649203639247; Tue, 05 Apr 2022 17:07:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649203639; cv=none; d=google.com; s=arc-20160816; b=LGL0zKoiaYD+lvTWhP2JdhHmU2F7XHlBpNxgTPLgCqbDzeg8aqfEGvhNSZYq4ZENkc g1ut2tzngbng7M7W95GqJBNFy0FqJggMLzbbCTHM8eK3ha3BucaYYP6zisKLFy4JfUx6 0VWE1wfMhb6ZnpqhGhdYB9ckUwVEJuVWdv3yJ0rLYa9WoEK5iULpVoIUp/afIZTiBQzN jvcDv7oYanTg/nseZ6Hsl/hHRQLxjajeY2XNUV92c3/zim1MqjZ2inrMdyuXY6SichZS 80krPG05X2rz7RY8t/PsDgMKD0tfyu8yif2a5fFFyrHsOyW0dMBVjf/ySgMr+c8+Dc4Y tmUw== 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=TWD8CvAOHTYuvqUaECrhMiaoS0mmAmqCgeu40Fdy/xg=; b=MTz3APFeahTXWatjX2WRGzWM1HGIQC3OEh1GH4o3dvhiQM4Xd1JcGjRVqChuuMrhgH Rt/jboyIbIYARyePGhCttQeeJMfPIQdtLc+pKZWAmOXN1rH+MUfrsG2QHO6SLdJqRSqW BCGZTYWzjPdYTKV6ZCGFp1uik/18A9ACDXW1GtphP9hlN1jKZQDlR/G8u7w4mY+dDKDW IEbuJzEjzRde02flv4Gs+3GgM4MJwhZ+tZa7xJrxwQEUNRAclE7G/E99maQlAvWNbKhm nRLplMa+Kpm97FQHN4cwgQYGO+hfQt0X1Bh93LUeqNHOG2+2V0pQUxr50EReTGwLDi/l 3XNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VOFDraaL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id q22-20020a631f56000000b003816043ef28si14574649pgm.285.2022.04.05.17.07.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 17:07:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VOFDraaL; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 69A341788E4; Tue, 5 Apr 2022 16:51:58 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378909AbiDELjp (ORCPT + 99 others); Tue, 5 Apr 2022 07:39:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244758AbiDEIwh (ORCPT ); Tue, 5 Apr 2022 04:52:37 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D1831CFFA; Tue, 5 Apr 2022 01:43:22 -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 ams.source.kernel.org (Postfix) with ESMTPS id C3B98B81C19; Tue, 5 Apr 2022 08:43:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32D15C385A0; Tue, 5 Apr 2022 08:43:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649148199; bh=WUARvHMnxR/HMiG3z7KbysMJPPbOUMTkSbauZ+e6w5w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VOFDraaLumiumTUcm+9dSaMY0xz/dwkfoyNeAVgk8focOs+2VGMlf6lHFC7HHwhAR QIA2/AswCjm6vfVhwYt08eFp+ffdwYfsUWC5DeLd/UrY8YKjOud7FcT1rIRT1zH7zQ KrwEk0HVe21F4B2AWQ44VpldpccFxOBOevOCwKX8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhiguo Niu , Jing Xia , Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.16 0271/1017] f2fs: fix to avoid potential deadlock Date: Tue, 5 Apr 2022 09:19:44 +0200 Message-Id: <20220405070402.310055433@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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: Chao Yu [ Upstream commit 344150999b7fc88502a65bbb147a47503eca2033 ] Quoted from Jing Xia's report, there is a potential deadlock may happen between kworker and checkpoint as below: [T:writeback] [T:checkpoint] - wb_writeback - blk_start_plug bio contains NodeA was plugged in writeback threads - do_writepages -- sync write inodeB, inc wb_sync_req[DATA] - f2fs_write_data_pages - f2fs_write_single_data_page -- write last dirty page - f2fs_do_write_data_page - set_page_writeback -- clear page dirty flag and PAGECACHE_TAG_DIRTY tag in radix tree - f2fs_outplace_write_data - f2fs_update_data_blkaddr - f2fs_wait_on_page_writeback -- wait NodeA to writeback here - inode_dec_dirty_pages - writeback_sb_inodes - writeback_single_inode - do_writepages - f2fs_write_data_pages -- skip writepages due to wb_sync_req[DATA] - wbc->pages_skipped += get_dirty_pages() -- PAGECACHE_TAG_DIRTY is not set but get_dirty_pages() returns one - requeue_inode -- requeue inode to wb->b_dirty queue due to non-zero.pages_skipped - blk_finish_plug Let's try to avoid deadlock condition by forcing unplugging previous bio via blk_finish_plug(current->plug) once we'v skipped writeback in writepages() due to valid sbi->wb_sync_req[DATA/NODE]. Fixes: 687de7f1010c ("f2fs: avoid IO split due to mixed WB_SYNC_ALL and WB_SYNC_NONE") Signed-off-by: Zhiguo Niu Signed-off-by: Jing Xia Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/data.c | 6 +++++- fs/f2fs/node.c | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index 3ba75587a2cd..04e82dedb4df 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3267,8 +3267,12 @@ static int __f2fs_write_data_pages(struct address_space *mapping, /* to avoid spliting IOs due to mixed WB_SYNC_ALL and WB_SYNC_NONE */ if (wbc->sync_mode == WB_SYNC_ALL) atomic_inc(&sbi->wb_sync_req[DATA]); - else if (atomic_read(&sbi->wb_sync_req[DATA])) + else if (atomic_read(&sbi->wb_sync_req[DATA])) { + /* to avoid potential deadlock */ + if (current->plug) + blk_finish_plug(current->plug); goto skip_write; + } if (__should_serialize_io(inode, wbc)) { mutex_lock(&sbi->writepages); diff --git a/fs/f2fs/node.c b/fs/f2fs/node.c index 556fcd8457f3..69c6bcaf5aae 100644 --- a/fs/f2fs/node.c +++ b/fs/f2fs/node.c @@ -2106,8 +2106,12 @@ static int f2fs_write_node_pages(struct address_space *mapping, if (wbc->sync_mode == WB_SYNC_ALL) atomic_inc(&sbi->wb_sync_req[NODE]); - else if (atomic_read(&sbi->wb_sync_req[NODE])) + else if (atomic_read(&sbi->wb_sync_req[NODE])) { + /* to avoid potential deadlock */ + if (current->plug) + blk_finish_plug(current->plug); goto skip_write; + } trace_f2fs_writepages(mapping->host, wbc, NODE); -- 2.34.1