Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp729488imm; Thu, 13 Sep 2018 06:57:03 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYUT7OpBoHQCgXACUp9TWJrirNiMRBngoUDxdYrzCOeKn+jgTABWg6KlUXvtHj86niwkHxz X-Received: by 2002:a17:902:4201:: with SMTP id g1-v6mr7511305pld.203.1536847023842; Thu, 13 Sep 2018 06:57:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847023; cv=none; d=google.com; s=arc-20160816; b=vECbrlOrK586XQTxh8RzN57zQgeFwMJhoDY4tzSitvvaNMXxOK6pKqUOpvcexJCXG0 5e9kizrMyOMn66MR81fwZt3wClSB1fa6s7UZFG5VhH7Yx/4OmyNxlkeIxivOZ38sqzWI RExatLlUii97jSTNLWuy7/Ngggc60LKA9NrA6O7i7zUJuhI6dOoJrcDDDojUPB+OyVGo B7AOyI7ttZg+UD751Z5wIuFukd/bsYuEHzgCDVA6dw34X7wrst2prmcH0SHtJs9ZR3am TUgYg0g1SXwjtAlAcnZwdI8k62nieyI1898ecqFcH4RtKk7FPKFFRd2TFzMvVfRVRdej WnFw== 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; bh=3Aq8nSQt/UzLzCDFc+PCGpxHoaMxjLZRmkQoj/33EWc=; b=JfqhYIXvAuQuhJegdVrlXodMpWgGB0LAF7Bh1+94bo3fj6odLoRLqQZYePhDOnSMiL N1x2x7cRhMN/e66vTB6/dn+rzF0dcye3kAlDemy57PvnD2gUU9o1BjpbLCNRc7u+40ih YR4Y2q3xfgy6pBetLUjahWdM9+Q8DbJIHDapuoJgQVN4jB/YUaWwdHtAWwzvditovkYx wfq4MHl5zq8z/q6NmWOhithQnkxPbyATuEb0K/aoVgixyVG3oke54DUZQd0V5WoqtKHS tV1Hmi6joU8xiWEl7DGH6lXH5X6D/jcGrVg4xPTLV0iuc445jWRln7rWcwXE7qVb1YTh rGDA== 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 p61-v6si4152301plb.55.2018.09.13.06.56.49; Thu, 13 Sep 2018 06:57:03 -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 S1731140AbeIMTGH (ORCPT + 99 others); Thu, 13 Sep 2018 15:06:07 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:34168 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728699AbeIMTGG (ORCPT ); Thu, 13 Sep 2018 15:06:06 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C8B28D10; Thu, 13 Sep 2018 13:56:29 +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.18 088/197] f2fs: avoid race between zero_range and background GC Date: Thu, 13 Sep 2018 15:30:37 +0200 Message-Id: <20180913131845.051902992@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Chao Yu [ Upstream commit c7079853c859c910b9d047a37891b4aafb8f8dd7 ] Thread A Background GC - f2fs_zero_range - truncate_pagecache_range - gc_data_segment - get_read_data_page - move_data_page - set_page_dirty - set_cold_data - f2fs_do_zero_range - dn->data_blkaddr = NEW_ADDR; - f2fs_set_data_blkaddr Actually, we don't need to set dirty & checked flag on the page, since all valid data in the page should be zeroed by zero_range(). Use i_gc_rwsem[WRITE] to avoid such race condition. 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 | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -1295,8 +1295,6 @@ static int f2fs_zero_range(struct inode if (ret) goto out_sem; - truncate_pagecache_range(inode, offset, offset + len - 1); - pg_start = ((unsigned long long) offset) >> PAGE_SHIFT; pg_end = ((unsigned long long) offset + len) >> PAGE_SHIFT; @@ -1326,12 +1324,19 @@ static int f2fs_zero_range(struct inode unsigned int end_offset; pgoff_t end; + down_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); + + truncate_pagecache_range(inode, + (loff_t)index << PAGE_SHIFT, + ((loff_t)pg_end << PAGE_SHIFT) - 1); + f2fs_lock_op(sbi); set_new_dnode(&dn, inode, NULL, NULL, 0); ret = f2fs_get_dnode_of_data(&dn, index, ALLOC_NODE); if (ret) { f2fs_unlock_op(sbi); + up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); goto out; } @@ -1340,7 +1345,9 @@ static int f2fs_zero_range(struct inode ret = f2fs_do_zero_range(&dn, index, end); f2fs_put_dnode(&dn); + f2fs_unlock_op(sbi); + up_write(&F2FS_I(inode)->i_gc_rwsem[WRITE]); f2fs_balance_fs(sbi, dn.node_changed);