Received: by 2002:a17:90a:9103:0:0:0:0 with SMTP id k3csp11787769pjo; Thu, 2 Jan 2020 14:17:06 -0800 (PST) X-Google-Smtp-Source: APXvYqz7XfqBg3R9jWh55/es0Stz2qSvVYN7j2y+VJw4Yv5ZISDeXDg0N2O6j1xyKKbAgPoxUH/B X-Received: by 2002:a05:6830:124b:: with SMTP id s11mr93079288otp.333.1578003425868; Thu, 02 Jan 2020 14:17:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578003425; cv=none; d=google.com; s=arc-20160816; b=gr158vWhhy9cHsPxyAv9Z9MRNuhtnckVPA/iRUur1fM9Axc7rBbItfb4oH2QKTkVXJ 3mif0k3uVWZrdjrHvFzs+cn8qTLef18u060kaOk1kjajAgs7vlRsLEYhYB0b2yLKMOuV m6HoFE0AsfJrHKTjUSqUgWjvu7Um9rhh59d1s76vJklRaIh8GmRn+nVas3G3WBaiSpqu flHCFo/CrGt7Cf50mbgEEgjZA6P1Bz+rrhfxo5mGWVCIDbmRGJI4h0+mOtUJ/AuMmRav 1NVEROcyvb7nlQCI1djp098MelRsIsjsLKusTO/baTJzika2SNByMWH+79eLtsLakJKa 1bQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nc2f80FutPFlOPz4z+SmZqp1AXAobwZV1VSXi0u8zlY=; b=qfFQFmt6AgSbhQKqL73EmLVpuYzPxJ9miTxHz+5xjWpHyZusdjt1HL9lnblvUkHDRm N1WxrtMmGula7OW0jEyQ7pTcpuBcWijX8wZROtK56xAcej/byKKolCh291jvHMAt/Qhz p4abpUy2+LsVha5lyj+U1x3rTEr0SDzccq58gERJg6aL/H4LiPRuMfEnEKsePYLZF9kX HGDyEVQDKoiLO2RbRdrZZUWkjurzKxxiu4ARO83zK07hCg+2mvTxrPVpiDekbHNyKuAT xrbtHJSykXTMqcjZQbZBEds9NFHsuUvUHDGBrmUsKj9w6J58b2by19X9wqzmOJfNPMDL +64Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SNvFI7rf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t15si24603450oij.189.2020.01.02.14.16.54; Thu, 02 Jan 2020 14:17:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SNvFI7rf; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727954AbgABWOo (ORCPT + 99 others); Thu, 2 Jan 2020 17:14:44 -0500 Received: from mail.kernel.org ([198.145.29.99]:55022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727146AbgABWOl (ORCPT ); Thu, 2 Jan 2020 17:14:41 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D1D6822314; Thu, 2 Jan 2020 22:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1578003280; bh=OKseluqIOLKPXGDIT2P+FxfP6IiKBsOcbvgBxl8Gx8c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SNvFI7rf62rlz2v546VCo1u+4W2f9qGekUuBio0zkZ7WhEzmA60BLPS/lrTr4BvK5 6vpNjEsSeEo3/NyAvRb/HPOaDLNNw2PgSo3Bua8p/fAVTed88PVA8DIHyCZc4KTSBY z8+LOiOvKnGOwBB/WwjEin3Al+QRv4tnU04fDR3s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Sahitya Tummala , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.4 095/191] f2fs: Fix deadlock in f2fs_gc() context during atomic files handling Date: Thu, 2 Jan 2020 23:06:17 +0100 Message-Id: <20200102215840.097249623@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200102215829.911231638@linuxfoundation.org> References: <20200102215829.911231638@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sahitya Tummala [ Upstream commit 677017d196ba2a4cfff13626b951cc9a206b8c7c ] The FS got stuck in the below stack when the storage is almost full/dirty condition (when FG_GC is being done). schedule_timeout io_schedule_timeout congestion_wait f2fs_drop_inmem_pages_all f2fs_gc f2fs_balance_fs __write_node_page f2fs_fsync_node_pages f2fs_do_sync_file f2fs_ioctl The root cause for this issue is there is a potential infinite loop in f2fs_drop_inmem_pages_all() for the case where gc_failure is true and when there an inode whose i_gc_failures[GC_FAILURE_ATOMIC] is not set. Fix this by keeping track of the total atomic files currently opened and using that to exit from this condition. Fix-suggested-by: Chao Yu Signed-off-by: Chao Yu Signed-off-by: Sahitya Tummala Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/f2fs.h | 1 + fs/f2fs/file.c | 1 + fs/f2fs/segment.c | 21 +++++++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index f078cd20dab8..9046432b87c2 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -1289,6 +1289,7 @@ struct f2fs_sb_info { unsigned int gc_mode; /* current GC state */ unsigned int next_victim_seg[2]; /* next segment in victim section */ /* for skip statistic */ + unsigned int atomic_files; /* # of opened atomic file */ unsigned long long skipped_atomic_files[2]; /* FG_GC and BG_GC */ unsigned long long skipped_gc_rwsem; /* FG_GC only */ diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 29bc0a542759..8ed8e4328bd1 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1890,6 +1890,7 @@ static int f2fs_ioc_start_atomic_write(struct file *filp) spin_lock(&sbi->inode_lock[ATOMIC_FILE]); if (list_empty(&fi->inmem_ilist)) list_add_tail(&fi->inmem_ilist, &sbi->inode_list[ATOMIC_FILE]); + sbi->atomic_files++; spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); /* add inode in inmem_list first and set atomic_file */ diff --git a/fs/f2fs/segment.c b/fs/f2fs/segment.c index 808709581481..7d8578401267 100644 --- a/fs/f2fs/segment.c +++ b/fs/f2fs/segment.c @@ -288,6 +288,8 @@ void f2fs_drop_inmem_pages_all(struct f2fs_sb_info *sbi, bool gc_failure) struct list_head *head = &sbi->inode_list[ATOMIC_FILE]; struct inode *inode; struct f2fs_inode_info *fi; + unsigned int count = sbi->atomic_files; + unsigned int looped = 0; next: spin_lock(&sbi->inode_lock[ATOMIC_FILE]); if (list_empty(head)) { @@ -296,22 +298,26 @@ next: } fi = list_first_entry(head, struct f2fs_inode_info, inmem_ilist); inode = igrab(&fi->vfs_inode); + if (inode) + list_move_tail(&fi->inmem_ilist, head); spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); if (inode) { if (gc_failure) { - if (fi->i_gc_failures[GC_FAILURE_ATOMIC]) - goto drop; - goto skip; + if (!fi->i_gc_failures[GC_FAILURE_ATOMIC]) + goto skip; } -drop: set_inode_flag(inode, FI_ATOMIC_REVOKE_REQUEST); f2fs_drop_inmem_pages(inode); +skip: iput(inode); } -skip: congestion_wait(BLK_RW_ASYNC, HZ/50); cond_resched(); + if (gc_failure) { + if (++looped >= count) + return; + } goto next; } @@ -327,13 +333,16 @@ void f2fs_drop_inmem_pages(struct inode *inode) mutex_unlock(&fi->inmem_lock); } - clear_inode_flag(inode, FI_ATOMIC_FILE); fi->i_gc_failures[GC_FAILURE_ATOMIC] = 0; stat_dec_atomic_write(inode); spin_lock(&sbi->inode_lock[ATOMIC_FILE]); if (!list_empty(&fi->inmem_ilist)) list_del_init(&fi->inmem_ilist); + if (f2fs_is_atomic_file(inode)) { + clear_inode_flag(inode, FI_ATOMIC_FILE); + sbi->atomic_files--; + } spin_unlock(&sbi->inode_lock[ATOMIC_FILE]); } -- 2.20.1