Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp4836282ybi; Mon, 3 Jun 2019 18:48:09 -0700 (PDT) X-Google-Smtp-Source: APXvYqwPSoTRPm5y+e5T1G4OO8FAmNYRCMA2s8KyKOj5d2UsWep8hN/XHe6h5a9XMlT0qp2zZ/lh X-Received: by 2002:a63:f10e:: with SMTP id f14mr32056464pgi.226.1559612888915; Mon, 03 Jun 2019 18:48:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559612888; cv=none; d=google.com; s=arc-20160816; b=yzHrzjrG93sb9DH2xIcORXn03tR0vvmfKoocm7R5n5z8oWLpKiaYXu5qt0omAGM4Bx LKmkIYDit/+GcVrJg//vw5LCkjTQUzivcbKPUeRsaexWYwRayFr75i494zmla90dqGR4 4AMQAvQ4k5yNmzrpai7GZN6NYmN8k0fbGSLWdq0M0/XtCA6UQf1DH3toZLzVECXvAJmd HHGxiZiyoBAWx9/LsnZvMM+4n62YdyzXZJ9n9V47Z4WJvaqHj0LwJ41YrhP9Y7pCSglW 6CJJ+x8AZ25nu1DsxZrFW8Y5+MWjYAKRmFoAMyf8jRhjnayboHwrDvtprSsIkll8QcSv 56Wg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=njQambdgqMUgo9RPlRofwu+llXN0JyVJ2jEL5EUQFko=; b=sFNnKM4QURb5/pkjIDfQwpX9HP9SHiF2E0rypCf28bI5WqEAEku038O30hT7aBiyYa dln2A97zR66esVN7zDYrI0sJV71+AG7PIJNL3VbM1EBO3c4NXV05Z6wF5GnSvuMvFjJV 6mfY1XzVl0At1ZK95pcgJPCgi4iG5RScLYSAcyoeRbUzRRhkKwe3V17srE3i1+WI7Hm9 sIqLHg5vuzTPRUbjpvhQVXwUE7k6xHpY81R6+RuZhEhd5GpRFC+sUQ1Fgb6gK9wEOTsk cur3UCsf5v/8q41vrDJqGDKZeB/KlrrRjFKVEDr/3IMD5Y02A4UPDAdclEBYQCCFMM3k PNtQ== 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 g90si22291016plb.282.2019.06.03.18.47.52; Mon, 03 Jun 2019 18:48:08 -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 S1726294AbfFDBqu (ORCPT + 99 others); Mon, 3 Jun 2019 21:46:50 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:38100 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725876AbfFDBqt (ORCPT ); Mon, 3 Jun 2019 21:46:49 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 7BA1C55AF8D62E01697B; Tue, 4 Jun 2019 09:46:47 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.210) with Microsoft SMTP Server (TLS) id 14.3.439.0; Tue, 4 Jun 2019 09:46:44 +0800 Subject: Re: [PATCH v3 3/4] f2fs: Fix accounting for unusable blocks To: Jaegeuk Kim CC: Daniel Rosenberg , Jonathan Corbet , , , , , References: <20190530004906.261170-1-drosen@google.com> <20190530004906.261170-4-drosen@google.com> <20190603202630.GB34729@jaegeuk-macbookpro.roam.corp.google.com> From: Chao Yu Message-ID: <2fbeda5b-50d6-a8c2-06a9-dddf5d466de8@huawei.com> Date: Tue, 4 Jun 2019 09:46:43 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190603202630.GB34729@jaegeuk-macbookpro.roam.corp.google.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019/6/4 4:26, Jaegeuk Kim wrote: > On 06/03, Chao Yu wrote: >> On 2019/5/30 8:49, Daniel Rosenberg wrote: >>> Fixes possible underflows when dealing with unusable blocks. >>> >>> Signed-off-by: Daniel Rosenberg >>> --- >>> fs/f2fs/f2fs.h | 15 ++++++++++----- >>> 1 file changed, 10 insertions(+), 5 deletions(-) >>> >>> diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h >>> index 9b3d9977cd1ef..a39cc4ffeb4b1 100644 >>> --- a/fs/f2fs/f2fs.h >>> +++ b/fs/f2fs/f2fs.h >>> @@ -1769,8 +1769,12 @@ static inline int inc_valid_block_count(struct f2fs_sb_info *sbi, >>> >>> if (!__allow_reserved_blocks(sbi, inode, true)) >>> avail_user_block_count -= F2FS_OPTION(sbi).root_reserved_blocks; >>> - if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) >>> - avail_user_block_count -= sbi->unusable_block_count; >>> + if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) { >>> + if (avail_user_block_count > sbi->unusable_block_count) >>> + avail_user_block_count = 0; >> >> avail_user_block_count -= sbi->unusable_block_count; >> >>> + else >>> + avail_user_block_count -= sbi->unusable_block_count; >> >> avail_user_block_count = 0; >> > > I fixed this. Okay, if there is no v4, please add Reviewed-by: Chao Yu Thanks, > > Thanks, > >> Thanks, >> >>> + } >>> if (unlikely(sbi->total_valid_block_count > avail_user_block_count)) { >>> diff = sbi->total_valid_block_count - avail_user_block_count; >>> if (diff > *count) >>> @@ -1970,7 +1974,7 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, >>> struct inode *inode, bool is_inode) >>> { >>> block_t valid_block_count; >>> - unsigned int valid_node_count; >>> + unsigned int valid_node_count, user_block_count; >>> int err; >>> >>> if (is_inode) { >>> @@ -1997,10 +2001,11 @@ static inline int inc_valid_node_count(struct f2fs_sb_info *sbi, >>> >>> if (!__allow_reserved_blocks(sbi, inode, false)) >>> valid_block_count += F2FS_OPTION(sbi).root_reserved_blocks; >>> + user_block_count = sbi->user_block_count; >>> if (unlikely(is_sbi_flag_set(sbi, SBI_CP_DISABLED))) >>> - valid_block_count += sbi->unusable_block_count; >>> + user_block_count -= sbi->unusable_block_count; >>> >>> - if (unlikely(valid_block_count > sbi->user_block_count)) { >>> + if (unlikely(valid_block_count > user_block_count)) { >>> spin_unlock(&sbi->stat_lock); >>> goto enospc; >>> } >>> > . >