Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1108594imm; Wed, 1 Aug 2018 10:19:01 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcP2BlActZEsFl8OYMLR7R/eV5JpBvILNtGB1PHjfg3pSfHlR0c6saa8wssR1qYANgwe0OD X-Received: by 2002:a62:fc5:: with SMTP id 66-v6mr27857049pfp.237.1533143941603; Wed, 01 Aug 2018 10:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533143941; cv=none; d=google.com; s=arc-20160816; b=F+1XGP8Opdsgiaq8vCdGN/VdELU3ysaDj5Bu5YOeCFiBJcSQXiBNuJI809+wmrjCPx jx6DtiTA6/7BNdflAJKiKf/w2Sy720h5e3DksBrtLVd/vvpPx5rKDUA374ThCQN33di1 jyjjwBAzboOx7atRLfrKfHNIQhCBLNKvx9sU/ZTrzAHKlFTGbwlc2Q28A129axBR3Kc5 pQPdFcBX/GElzruQ5RgtOhkAo7MQKn7vuD7pbi1GJ38Mme/N7Y8rAR/in87wP6nBwhTh fni3E1tl6fpkFpeh82QxI3ANVtsLuCETT/ivXrzOX9Y16HsZYTd9VnNVuRMHwJjNnZIu xn0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=ND8czqSJFWaUUUrx5bd6Z327VbTEQ5f9lkRo4pbnKNE=; b=glN+SKW6J2cKMcXwuii8/U5hyWVrmsvUtQ6iy0T/zbVQDW7fNnfPzPzP1iWb53r9+x xW/2hkne2liPZ3iQh8Bd5zolARkgDCYWRBEcpoASuDwrV70PkZlyq2AWMR2ENV+MKgAD FH7iyYOlQObNj7zoDE8R2F9SffTug8Xy+0xQ5NAUm/QL/mANiYeI9IYvzrl81BinFNv7 y8P2PQ+WB653HSPeEajqKDaezawA49zm9iGta0DkGSWTBCs7QVx105vLyx46dkuTiX7s daSYTFFbrT/PP7xE/46PNAb8jahNBiB9YlN8A+JMQ/M/CedjenPlxXjCG5lvvkuD4hKT ZhCA== 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 r2-v6si16382638pgd.138.2018.08.01.10.18.47; Wed, 01 Aug 2018 10:19:01 -0700 (PDT) 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 S2404662AbeHATEB (ORCPT + 99 others); Wed, 1 Aug 2018 15:04:01 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46312 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403901AbeHATEB (ORCPT ); Wed, 1 Aug 2018 15:04:01 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 3871AC9D; Wed, 1 Aug 2018 17:17:21 +0000 (UTC) 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 4.14 061/246] f2fs: fix race in between GC and atomic open Date: Wed, 1 Aug 2018 18:49:31 +0200 Message-Id: <20180801165014.623520730@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit 27319ba4044c0c67d62ae39e53c0118c89f0a029 ] Thread GC thread - f2fs_ioc_start_atomic_write - get_dirty_pages - filemap_write_and_wait_range - f2fs_gc - do_garbage_collect - gc_data_segment - move_data_page - f2fs_is_atomic_file - set_page_dirty - set_inode_flag(, FI_ATOMIC_FILE) Dirty data page can still be generated by GC in race condition as above call stack. This patch adds fi->dio_rwsem[WRITE] in f2fs_ioc_start_atomic_write to avoid such race. Signed-off-by: Chao Yu Signed-off-by: Jaegeuk Kim Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/f2fs/file.c | 3 +++ 1 file changed, 3 insertions(+) --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1630,6 +1630,8 @@ static int f2fs_ioc_start_atomic_write(s inode_lock(inode); + down_write(&F2FS_I(inode)->dio_rwsem[WRITE]); + if (f2fs_is_atomic_file(inode)) goto out; @@ -1659,6 +1661,7 @@ inc_stat: stat_inc_atomic_write(inode); stat_update_max_atomic_write(inode); out: + up_write(&F2FS_I(inode)->dio_rwsem[WRITE]); inode_unlock(inode); mnt_drop_write_file(filp); return ret;