Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1584025ybv; Thu, 20 Feb 2020 23:44:53 -0800 (PST) X-Google-Smtp-Source: APXvYqzAdKGKcn8DXJnAwufu892XLPoSmZoFxyEBzL7CE/LgZukAqiI1Wh10QVSx+Zo0Oq1YD1Kn X-Received: by 2002:a05:6830:10da:: with SMTP id z26mr12705717oto.27.1582271092925; Thu, 20 Feb 2020 23:44:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582271092; cv=none; d=google.com; s=arc-20160816; b=rj29opPxHorHyYXWO2sUoEfgbGAmt2MQUNwfJpre7qfYxIQHeu/nDZUmbNuWrnBKT7 zUWB8bb9HlyKrIYcJp3WqXVKVflFv/l/UuL9ElgBaEnh8HRUq7S8RRQtO/y6LDaDMQdw pFJ5exbLxYGDcSJfORI3J3vwM+ZpSqh8KrcPTii52gzLiIjxCsZAG8g83FrA08EvylNt hYJkScimwoYYgN7KdEL26tB7ic+fDx0trB18BI6zWPVlEBxmURdUQVSirsY+I97D9XuW 23nis7vz1lLYFAzHtb/5kMM/b55KuF4ndjp9t7EVkvYH4WSCHnyI1JuP1hTLqff8x2bo tGzg== 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=TkT+TrwbAZ6yQEwErQq05eeW9IaT5fu48gFePJy1zMw=; b=dOgGXoQa/v2NQFCHqnlFjtL38jmRdirxTO2eSHMj6QJn9omNtGQ/XQo2nPHS93noOU QH0+hHKqqwIe9Dt2xe9RDj0CbxLsJiPVGzU6oTFT2H9b2wDUuj1UI0Wt6kTaLZ/VYyOs laSccyuXJ1InfhqZinUvObqDIl3u53BrivVOHYGacFJ7A6jV2SpELIzpxgg4le5Zk4yE diE02Zgdt3jFIwTzThalVQggTnd6lqeDCv6z6iq3R8sJ9VIpVOeDo+TUpBNIgchDRV/e YrInxZA+8hBBU/SI5o1ObPK+T2NGPyoW8MqbFf+skF0PskqCfq+2jPhEhpscC0z6x7xB RV1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=e0quyPB8; 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 v18si1074518otq.209.2020.02.20.23.44.41; Thu, 20 Feb 2020 23:44:52 -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=e0quyPB8; 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 S1727833AbgBUHoN (ORCPT + 99 others); Fri, 21 Feb 2020 02:44:13 -0500 Received: from mail.kernel.org ([198.145.29.99]:38818 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727797AbgBUHoL (ORCPT ); Fri, 21 Feb 2020 02:44:11 -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 A7425208C4; Fri, 21 Feb 2020 07:44:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582271050; bh=iZIRaUEUsPfVHTOn9MDUDIfCsp4dj78qw/0Z1aF2xFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e0quyPB8ynfEEQND5ZeI+tlpnRhiDWqw9U1H2Q3FkseRNB9vtqzvNeTCl1y8ZpbK7 2ndB0/n3ELau5y7lgOTdMhjzJoi93+SlIMPQNCOcs+mVeBwgAfRx+NJFW8Vd90YJz3 DVYy0ZkxEYGep3kzt/E0uZAQUChukxgVjiX6l7l0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Chao Yu , Jaegeuk Kim , Sasha Levin Subject: [PATCH 5.5 020/399] f2fs: call f2fs_balance_fs outside of locked page Date: Fri, 21 Feb 2020 08:35:45 +0100 Message-Id: <20200221072404.289499313@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072402.315346745@linuxfoundation.org> References: <20200221072402.315346745@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: Jaegeuk Kim [ Upstream commit bdf03299248916640a835a05d32841bb3d31912d ] Otherwise, we can hit deadlock by waiting for the locked page in move_data_block in GC. Thread A Thread B - do_page_mkwrite - f2fs_vm_page_mkwrite - lock_page - f2fs_balance_fs - mutex_lock(gc_mutex) - f2fs_gc - do_garbage_collect - ra_data_block - grab_cache_page - f2fs_balance_fs - mutex_lock(gc_mutex) Fixes: 39a8695824510 ("f2fs: refactor ->page_mkwrite() flow") Reviewed-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin --- fs/f2fs/file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index 33c412d178f0f..6c4436a5ce797 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -50,7 +50,7 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) struct page *page = vmf->page; struct inode *inode = file_inode(vmf->vma->vm_file); struct f2fs_sb_info *sbi = F2FS_I_SB(inode); - struct dnode_of_data dn = { .node_changed = false }; + struct dnode_of_data dn; int err; if (unlikely(f2fs_cp_error(sbi))) { @@ -63,6 +63,9 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) goto err; } + /* should do out of any locked page */ + f2fs_balance_fs(sbi, true); + sb_start_pagefault(inode->i_sb); f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); @@ -120,8 +123,6 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) out_sem: up_read(&F2FS_I(inode)->i_mmap_sem); - f2fs_balance_fs(sbi, dn.node_changed); - sb_end_pagefault(inode->i_sb); err: return block_page_mkwrite_return(err); -- 2.20.1