Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp261203ybl; Thu, 5 Dec 2019 19:33:27 -0800 (PST) X-Google-Smtp-Source: APXvYqxaGGRrdevDLd1z9ncOtJ4Zv8TKlxGpK0/wi+MwlRs69Hwc/q2fxlWzIhqPoWKO2TwgFmUd X-Received: by 2002:aca:de03:: with SMTP id v3mr5098616oig.162.1575603207114; Thu, 05 Dec 2019 19:33:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575603207; cv=none; d=google.com; s=arc-20160816; b=qEzy6wyQNOz7qNAOeGFI0/yk7nc0UFYKvD02+gKByMNX3fkjBNEbmBMgkt0+NeNpkk CamOIglzqaMOP5tY/WoA3IcpwFDPaiakpRdzwaEphbJb0Nu4wNM1dJhiTnDl6KjAhRab 4/bYyPexddArjCqlCC3YQMv38Gy7oDFGgSxbf1ArdEefK8CqnCa6AUcTSfs5uU2ylsgm LyrDBoqzlG7JUos8aGv83mDBu0IIbfX8jBkMP7uJ15N1KH5kkHK2ToFT2tUw7dC6C6fq 16Bi5PW3v9CNeILksFIs6mZGM/tcryX50br5hqFCYg1EvlFwIYxNqa8uLOcIRTB+F5K6 hGjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=o/enalIwF8+oFs0VCmBmFYlr6HI56ec+H2svrNPDkTs=; b=01clt8oArQe7ou7l87l6E28R39EFalMtr80fOIbiNADWB0bNeYHaao2Gr+G3FFTMOQ Itx9+TnEoalf1HkahSMBFRXP5Kc7+Zy7ZjCgobiV46ngJp9oWZ0q5WOqmjwzl4HbWDVR l97EDW2ki1NFJZxgzkUeTJz8NFzFxKMnd8KKy6LcAfpOHtoauCf/pdmykkVOgjS8BX3R fGalt03Lp9bF+j3iK5XDEBJPAIDV2uz5ZXuhjTXqHoFdYJX1iwwY+lZw1R4IYapYB+jm GGZTn0FzNxTNZLPmk/Xf/8i7Vu6iLFgBaR0kH2tEgf1QXRQt/3WQlYxLSLNV96LMqsrC OG7A== ARC-Authentication-Results: i=1; mx.google.com; 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 t3si6179387oig.25.2019.12.05.19.33.14; Thu, 05 Dec 2019 19:33:27 -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; 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 S1726366AbfLFDcA (ORCPT + 99 others); Thu, 5 Dec 2019 22:32:00 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:7643 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726076AbfLFDcA (ORCPT ); Thu, 5 Dec 2019 22:32:00 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 67EADA3DF8EF18778786; Fri, 6 Dec 2019 11:31:58 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.439.0; Fri, 6 Dec 2019 11:31:47 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH] f2fs: fix to relocate f2fs_balance_fs() in mkwrite() Date: Fri, 6 Dec 2019 11:31:00 +0800 Message-ID: <20191206033100.36345-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As Dinosaur Huang reported, there is a potential deadlock in between GC and mkwrite(): 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) In order to fix this, we just move f2fs_balance_fs() out of page lock's coverage in f2fs_vm_page_mkwrite(). Reported-by: Dinosaur Huang Signed-off-by: Chao Yu --- fs/f2fs/file.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index c0560d62dbee..ed3290225506 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -67,6 +67,8 @@ static vm_fault_t f2fs_vm_page_mkwrite(struct vm_fault *vmf) f2fs_bug_on(sbi, f2fs_has_inline_data(inode)); + f2fs_balance_fs(sbi, true); + file_update_time(vmf->vma->vm_file); down_read(&F2FS_I(inode)->i_mmap_sem); lock_page(page); @@ -120,8 +122,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.18.0.rc1