Re: [PATCH 1/2] f2fs: fix to avoid potential negative .f_bfree

From: Chao Yu
Date: Mon Apr 29 2019 - 23:15:20 EST


On 2019/4/30 10:54, Jaegeuk Kim wrote:
> On 04/29, Chao Yu wrote:
>> 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?
>
> What I've concerend is whether or not this fixes all the inconsistent values.
> The original intention was providing stats in best effort, so we wouldn't use
> any lock.

Hmm.. I've made a patch to protect .unusable_block_count update/access as below,
how about merging this two patch, in addition, in this patch, let's add
stat_lock around accessing .f_bfree/.unusable_block_count.