Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3708496yba; Mon, 29 Apr 2019 07:16:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzUKf7xF9dSIz87mRvSE1fTulivpj7nwQy3pcVH9RrFxs+vzAm4RtDD4VUo/rLPiw5Z5euW X-Received: by 2002:aa7:81d0:: with SMTP id c16mr61965961pfn.132.1556547391251; Mon, 29 Apr 2019 07:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556547391; cv=none; d=google.com; s=arc-20160816; b=kDZWYPlAwne7p6tOVMi2PcAnvarN4WQjBZ4TVq35Iq/t94XS0pIkd5/+m5zcpAjHry ikih9I0aYBy0hiU0UN9GiPSiwi2/ZLf3IM8XPeRoz4ub/inGFyISnDC1PIFQE8nE9gZS V0TfyE8j3rf/o4niCBPsjvUt7bcEoe2wNKr1lnsEDVLw7Pk0hoibaOvKx6ZoEZ1DiKZp JzQrFr4CN4zBOy4slpO+AE1Chlyzx62jFGA8XSBddcNinj7zXs+uQiWsiymb7cs0CRV7 PfBzp0GFBdF7L/Kvh7TBXsnKlnHorGPBJEI25uH9HckOCz32/b0/3AKDq6IqQhPzlSze euXA== 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:dkim-signature; bh=ihRHnsCtYX0Mly5gWTWcExD+WyVUsWlANB40Pz4ho7Y=; b=itiZo0ur7uJWBjB1uJ1t9BFVMj+LXk3bPDrJJXCwFVMSzAeY8+1GJ6o2G/odeCOaGh X1ooognl7ysPOSHCMjtWg8RX4SbTVUv4cm9cQS1hW2k1okp/PHf5koYOvJ+kLpItE/Z3 0oXH1fRyFYxC1BT8bMeyW3f/Kp+MBwRf1yW2j0QDzkZNwO/D+dJHPoT2k4y/30eixVjv jgiTYY86PKtVUk0JOhYMekP2+JRh6KqYcT1UywGQQycOw0tatn5/hrXLq7K66tM52Y3r vJaJZMxu8c0K1TiwEfXuu83OLF2uKJiUNODjvW/0pWP67CWUDisEs+Dzm9J8uIbljuxX QJ8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dso4WA3f; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k33si34042051pld.27.2019.04.29.07.16.15; Mon, 29 Apr 2019 07:16:31 -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; dkim=pass header.i=@kernel.org header.s=default header.b=dso4WA3f; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728287AbfD2OOC (ORCPT + 99 others); Mon, 29 Apr 2019 10:14:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:33018 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728196AbfD2OOC (ORCPT ); Mon, 29 Apr 2019 10:14:02 -0400 Received: from [192.168.0.101] (unknown [58.212.133.185]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 75D6320652; Mon, 29 Apr 2019 14:14:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1556547241; bh=xf6NipygRwz8sNGT+uqf5PgnOsEKfKT1vm3IZ3bunjM=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=dso4WA3f9LnwH+OyLKzx9gjPszb+OcJsevJ1VxlQW5cC4aDph7RORwuDlkB86eNA8 q/XDB8hJuEdwfD5rG8Fs5+ks4fTIp4o4MBiK1yNfIwPHETyf9GmAKyiUVj84nByrBk 2x5gEM1+/soBwQiUPiA+Nykh6NB86t3bieQfx24c= Subject: Re: [PATCH 1/2] f2fs: fix to avoid potential negative .f_bfree To: Jaegeuk Kim , Chao Yu Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, drosen@google.com References: <20190426095754.85784-1-yuchao0@huawei.com> <20190428134722.GC37346@jaegeuk-macbookpro.roam.corp.google.com> From: Chao Yu Message-ID: Date: Mon, 29 Apr 2019 22:13:55 +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: <20190428134722.GC37346@jaegeuk-macbookpro.roam.corp.google.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2019-4-28 21:47, Jaegeuk Kim wrote: > On 04/26, Chao Yu wrote: >> When calculating .f_bfree value in f2fs_statfs(), sbi->unusable_block_count >> can be increased after the judgment condition, result in overflow of >> .f_bfree in later calculation. This patch fixes to use a temporary signed >> variable to save the calculation result of .f_bfree. >> >> if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) >> buf->f_bfree = 0; >> else >> buf->f_bfree -= sbi->unusable_block_count; > > Do we just need stat_lock for this? Like we access other stat value in statfs(), we just need the instantaneous value of .unusable_block_count, so we don't need additional stat_lock, right? Thanks, > >> >> Signed-off-by: Chao Yu >> --- >> fs/f2fs/super.c | 7 +++++-- >> 1 file changed, 5 insertions(+), 2 deletions(-) >> >> diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c >> index 2376bb01b5c4..fcc9793dbc2c 100644 >> --- a/fs/f2fs/super.c >> +++ b/fs/f2fs/super.c >> @@ -1216,6 +1216,7 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) >> u64 id = huge_encode_dev(sb->s_bdev->bd_dev); >> block_t total_count, user_block_count, start_count; >> u64 avail_node_count; >> + long long bfree; >> >> total_count = le64_to_cpu(sbi->raw_super->block_count); >> user_block_count = sbi->user_block_count; >> @@ -1226,10 +1227,12 @@ static int f2fs_statfs(struct dentry *dentry, struct kstatfs *buf) >> buf->f_blocks = total_count - start_count; >> buf->f_bfree = user_block_count - valid_user_blocks(sbi) - >> sbi->current_reserved_blocks; >> - if (unlikely(buf->f_bfree <= sbi->unusable_block_count)) >> + >> + bfree = buf->f_bfree - sbi->unusable_block_count; >> + if (unlikely(bfree < 0)) >> buf->f_bfree = 0; >> else >> - buf->f_bfree -= sbi->unusable_block_count; >> + buf->f_bfree = bfree; >> >> if (buf->f_bfree > F2FS_OPTION(sbi).root_reserved_blocks) >> buf->f_bavail = buf->f_bfree - >> -- >> 2.18.0.rc1