stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited
@ 2019-12-04 13:11 yu kuai
  2019-12-04 17:31 ` Greg KH
  2019-12-04 17:33 ` Greg KH
  0 siblings, 2 replies; 6+ messages in thread
From: yu kuai @ 2019-12-04 13:11 UTC (permalink / raw)
  To: stable, gregkh, hughd, viro; +Cc: yi.zhang, zhengbin13, yukuai3, houtao1

tmpfs support 'size', 'nr_blocks' and 'nr_inodes' mount options. mount or
remount them to zero means unlimited. 'size' and 'br_blocks' can remount
from limited to unlimited, while 'nr_inodes' can't.

The problem is fixed since upstream commit 0b5071dd323d ("
shmem_parse_options(): use a separate structure to keep the results"). But
in order to backport it, the amount of related patches need to backport is
huge. 

So, I made some local changes to fix the problem.

Signed-off-by: yu kuai <yukuai3@huawei.com>
---
 mm/shmem.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mm/shmem.c b/mm/shmem.c
index 3c8742655756..966fc69ee8fb 100644
--- a/mm/shmem.c
+++ b/mm/shmem.c
@@ -3444,7 +3444,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
 	inodes = sbinfo->max_inodes - sbinfo->free_inodes;
 	if (percpu_counter_compare(&sbinfo->used_blocks, config.max_blocks) > 0)
 		goto out;
-	if (config.max_inodes < inodes)
+	if (config.max_inodes && config.max_inodes < inodes)
 		goto out;
 	/*
 	 * Those tests disallow limited->unlimited while any are in use;
@@ -3460,7 +3460,10 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
 	sbinfo->huge = config.huge;
 	sbinfo->max_blocks  = config.max_blocks;
 	sbinfo->max_inodes  = config.max_inodes;
-	sbinfo->free_inodes = config.max_inodes - inodes;
+	if (!config.max_inodes)
+		sbinfo->free_inodes = 0;
+	else
+		sbinfo->free_inodes = config.max_inodes - inodes;
 
 	/*
 	 * Preserve previous mempolicy unless mpol remount option was specified.
-- 
2.17.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited
  2019-12-04 13:11 [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited yu kuai
@ 2019-12-04 17:31 ` Greg KH
  2019-12-04 17:33 ` Greg KH
  1 sibling, 0 replies; 6+ messages in thread
From: Greg KH @ 2019-12-04 17:31 UTC (permalink / raw)
  To: yu kuai; +Cc: stable, hughd, viro, yi.zhang, zhengbin13, houtao1

On Wed, Dec 04, 2019 at 09:11:37PM +0800, yu kuai wrote:
> tmpfs support 'size', 'nr_blocks' and 'nr_inodes' mount options. mount or
> remount them to zero means unlimited. 'size' and 'br_blocks' can remount
> from limited to unlimited, while 'nr_inodes' can't.
> 
> The problem is fixed since upstream commit 0b5071dd323d ("
> shmem_parse_options(): use a separate structure to keep the results"). But
> in order to backport it, the amount of related patches need to backport is
> huge. 
> 
> So, I made some local changes to fix the problem.
> 
> Signed-off-by: yu kuai <yukuai3@huawei.com>
> ---
>  mm/shmem.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)


<formletter>

This is not the correct way to submit patches for inclusion in the
stable kernel tree.  Please read:
    https://www.kernel.org/doc/html/latest/process/stable-kernel-rules.html
for how to do this properly.

</formletter>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited
  2019-12-04 13:11 [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited yu kuai
  2019-12-04 17:31 ` Greg KH
@ 2019-12-04 17:33 ` Greg KH
  2019-12-04 20:13   ` Hugh Dickins
  2019-12-05  1:22   ` yukuai (C)
  1 sibling, 2 replies; 6+ messages in thread
From: Greg KH @ 2019-12-04 17:33 UTC (permalink / raw)
  To: yu kuai; +Cc: stable, hughd, viro, yi.zhang, zhengbin13, houtao1

On Wed, Dec 04, 2019 at 09:11:37PM +0800, yu kuai wrote:
> tmpfs support 'size', 'nr_blocks' and 'nr_inodes' mount options. mount or
> remount them to zero means unlimited. 'size' and 'br_blocks' can remount
> from limited to unlimited, while 'nr_inodes' can't.
> 
> The problem is fixed since upstream commit 0b5071dd323d ("
> shmem_parse_options(): use a separate structure to keep the results"). But
> in order to backport it, the amount of related patches need to backport is
> huge. 
> 
> So, I made some local changes to fix the problem.
> 
> Signed-off-by: yu kuai <yukuai3@huawei.com>
> ---
>  mm/shmem.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/mm/shmem.c b/mm/shmem.c
> index 3c8742655756..966fc69ee8fb 100644
> --- a/mm/shmem.c
> +++ b/mm/shmem.c
> @@ -3444,7 +3444,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
>  	inodes = sbinfo->max_inodes - sbinfo->free_inodes;
>  	if (percpu_counter_compare(&sbinfo->used_blocks, config.max_blocks) > 0)
>  		goto out;
> -	if (config.max_inodes < inodes)
> +	if (config.max_inodes && config.max_inodes < inodes)
>  		goto out;
>  	/*
>  	 * Those tests disallow limited->unlimited while any are in use;
> @@ -3460,7 +3460,10 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
>  	sbinfo->huge = config.huge;
>  	sbinfo->max_blocks  = config.max_blocks;
>  	sbinfo->max_inodes  = config.max_inodes;
> -	sbinfo->free_inodes = config.max_inodes - inodes;
> +	if (!config.max_inodes)
> +		sbinfo->free_inodes = 0;
> +	else
> +		sbinfo->free_inodes = config.max_inodes - inodes;
>  
>  	/*
>  	 * Preserve previous mempolicy unless mpol remount option was specified.
> -- 
> 2.17.2
> 

Hm, sorry about my bot, this looked like an odd one-off patch.

What about 5.3.y, should this patch also go there as well?

But is it really an issue as this is a new "feature" that 5.4 now has,
can't you just use 5.4.y if you need this type of thing?  It's never
worked in the past, right?

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited
  2019-12-04 17:33 ` Greg KH
@ 2019-12-04 20:13   ` Hugh Dickins
  2019-12-05  1:41     ` yukuai (C)
  2019-12-05  1:22   ` yukuai (C)
  1 sibling, 1 reply; 6+ messages in thread
From: Hugh Dickins @ 2019-12-04 20:13 UTC (permalink / raw)
  To: Greg KH; +Cc: yu kuai, stable, hughd, viro, yi.zhang, zhengbin13, houtao1

On Wed, 4 Dec 2019, Greg KH wrote:
> On Wed, Dec 04, 2019 at 09:11:37PM +0800, yu kuai wrote:
> > tmpfs support 'size', 'nr_blocks' and 'nr_inodes' mount options. mount or
> > remount them to zero means unlimited. 'size' and 'br_blocks' can remount
> > from limited to unlimited, while 'nr_inodes' can't.
> > 
> > The problem is fixed since upstream commit 0b5071dd323d ("
> > shmem_parse_options(): use a separate structure to keep the results"). But
> > in order to backport it, the amount of related patches need to backport is
> > huge. 
> > 
> > So, I made some local changes to fix the problem.
> > 
> > Signed-off-by: yu kuai <yukuai3@huawei.com>
> > ---
> >  mm/shmem.c | 7 +++++--
> >  1 file changed, 5 insertions(+), 2 deletions(-)
> > 
> > diff --git a/mm/shmem.c b/mm/shmem.c
> > index 3c8742655756..966fc69ee8fb 100644
> > --- a/mm/shmem.c
> > +++ b/mm/shmem.c
> > @@ -3444,7 +3444,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
> >  	inodes = sbinfo->max_inodes - sbinfo->free_inodes;
> >  	if (percpu_counter_compare(&sbinfo->used_blocks, config.max_blocks) > 0)
> >  		goto out;
> > -	if (config.max_inodes < inodes)
> > +	if (config.max_inodes && config.max_inodes < inodes)
> >  		goto out;
> >  	/*
> >  	 * Those tests disallow limited->unlimited while any are in use;
> > @@ -3460,7 +3460,10 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
> >  	sbinfo->huge = config.huge;
> >  	sbinfo->max_blocks  = config.max_blocks;
> >  	sbinfo->max_inodes  = config.max_inodes;
> > -	sbinfo->free_inodes = config.max_inodes - inodes;
> > +	if (!config.max_inodes)
> > +		sbinfo->free_inodes = 0;
> > +	else
> > +		sbinfo->free_inodes = config.max_inodes - inodes;
> >  
> >  	/*
> >  	 * Preserve previous mempolicy unless mpol remount option was specified.
> > -- 
> > 2.17.2
> > 
> 
> Hm, sorry about my bot, this looked like an odd one-off patch.
> 
> What about 5.3.y, should this patch also go there as well?
> 
> But is it really an issue as this is a new "feature" that 5.4 now has,
> can't you just use 5.4.y if you need this type of thing?  It's never
> worked in the past, right?

Yes, please ignore this for stable, Greg: it appears to be a new feature
in 5.4: one that I should have noticed when testing, but failed to do so
(and it may even be something that I foisted unthinkingly on Al when
suggesting mods to his and David's originals).

Yu Kuai: many thanks for noticing and reporting this, I was unconscious
of changing behavior here.  Notice how the 5.4 shmem_reconfigure() still
has a comment above it saying "we disallow change from limited->unlimited
blocks/inodes while any are in use" - and root inode is always in use.
Notice how your 4.19 patch does nothing for max_blocks, so remounting
with nr_blocks=0 will still fail, once a non-empty file has been created.

I agree that it's not obvious why limited->unlimited needs to fail,
and perhaps a nice (worthwhile?) little enhancement to allow that;
but it was unintentional, and now (but not today) I have to go back
to remind myself why 2.6.13 implemented it with that restriction,
and whether there are any fixes needed to the new behavior in 5.4
(at the least, we ought to fix that comment in 5.5).

Hugh

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited
  2019-12-04 17:33 ` Greg KH
  2019-12-04 20:13   ` Hugh Dickins
@ 2019-12-05  1:22   ` yukuai (C)
  1 sibling, 0 replies; 6+ messages in thread
From: yukuai (C) @ 2019-12-05  1:22 UTC (permalink / raw)
  To: Greg KH; +Cc: stable, hughd, viro, yi.zhang, zhengbin13, houtao1



On 2019/12/5 1:33, Greg KH wrote:
> On Wed, Dec 04, 2019 at 09:11:37PM +0800, yu kuai wrote:
>> tmpfs support 'size', 'nr_blocks' and 'nr_inodes' mount options. mount or
>> remount them to zero means unlimited. 'size' and 'br_blocks' can remount
>> from limited to unlimited, while 'nr_inodes' can't.
>>
>> The problem is fixed since upstream commit 0b5071dd323d ("
>> shmem_parse_options(): use a separate structure to keep the results"). But
>> in order to backport it, the amount of related patches need to backport is
>> huge.
>>
>> So, I made some local changes to fix the problem.
>>
>> Signed-off-by: yu kuai <yukuai3@huawei.com>
>> ---
>>   mm/shmem.c | 7 +++++--
>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>
>> diff --git a/mm/shmem.c b/mm/shmem.c
>> index 3c8742655756..966fc69ee8fb 100644
>> --- a/mm/shmem.c
>> +++ b/mm/shmem.c
>> @@ -3444,7 +3444,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
>>   	inodes = sbinfo->max_inodes - sbinfo->free_inodes;
>>   	if (percpu_counter_compare(&sbinfo->used_blocks, config.max_blocks) > 0)
>>   		goto out;
>> -	if (config.max_inodes < inodes)
>> +	if (config.max_inodes && config.max_inodes < inodes)
>>   		goto out;
>>   	/*
>>   	 * Those tests disallow limited->unlimited while any are in use;
>> @@ -3460,7 +3460,10 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
>>   	sbinfo->huge = config.huge;
>>   	sbinfo->max_blocks  = config.max_blocks;
>>   	sbinfo->max_inodes  = config.max_inodes;
>> -	sbinfo->free_inodes = config.max_inodes - inodes;
>> +	if (!config.max_inodes)
>> +		sbinfo->free_inodes = 0;
>> +	else
>> +		sbinfo->free_inodes = config.max_inodes - inodes;
>>   
>>   	/*
>>   	 * Preserve previous mempolicy unless mpol remount option was specified.
>> -- 
>> 2.17.2
>>
> 
> Hm, sorry about my bot, this looked like an odd one-off patch.
> 
> What about 5.3.y, should this patch also go there as well?
Yes, 4.4y and 5.3y have the same problem.
> 
> But is it really an issue as this is a new "feature" that 5.4 now has,
> can't you just use 5.4.y if you need this type of thing?  It's never
> worked in the past, right?
> 
It's true that it never worked in the past. I thoult it might be a bug 
because the behavior is not like what the document said.

Thanks for your response.
Yu Kuai


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited
  2019-12-04 20:13   ` Hugh Dickins
@ 2019-12-05  1:41     ` yukuai (C)
  0 siblings, 0 replies; 6+ messages in thread
From: yukuai (C) @ 2019-12-05  1:41 UTC (permalink / raw)
  To: Hugh Dickins, Greg KH; +Cc: stable, viro, yi.zhang, zhengbin13, houtao1



On 2019/12/5 4:13, Hugh Dickins wrote:
> On Wed, 4 Dec 2019, Greg KH wrote:
>> On Wed, Dec 04, 2019 at 09:11:37PM +0800, yu kuai wrote:
>>> tmpfs support 'size', 'nr_blocks' and 'nr_inodes' mount options. mount or
>>> remount them to zero means unlimited. 'size' and 'br_blocks' can remount
>>> from limited to unlimited, while 'nr_inodes' can't.
>>>
>>> The problem is fixed since upstream commit 0b5071dd323d ("
>>> shmem_parse_options(): use a separate structure to keep the results"). But
>>> in order to backport it, the amount of related patches need to backport is
>>> huge.
>>>
>>> So, I made some local changes to fix the problem.
>>>
>>> Signed-off-by: yu kuai <yukuai3@huawei.com>
>>> ---
>>>   mm/shmem.c | 7 +++++--
>>>   1 file changed, 5 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/mm/shmem.c b/mm/shmem.c
>>> index 3c8742655756..966fc69ee8fb 100644
>>> --- a/mm/shmem.c
>>> +++ b/mm/shmem.c
>>> @@ -3444,7 +3444,7 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
>>>   	inodes = sbinfo->max_inodes - sbinfo->free_inodes;
>>>   	if (percpu_counter_compare(&sbinfo->used_blocks, config.max_blocks) > 0)
>>>   		goto out;
>>> -	if (config.max_inodes < inodes)
>>> +	if (config.max_inodes && config.max_inodes < inodes)
>>>   		goto out;
>>>   	/*
>>>   	 * Those tests disallow limited->unlimited while any are in use;
>>> @@ -3460,7 +3460,10 @@ static int shmem_remount_fs(struct super_block *sb, int *flags, char *data)
>>>   	sbinfo->huge = config.huge;
>>>   	sbinfo->max_blocks  = config.max_blocks;
>>>   	sbinfo->max_inodes  = config.max_inodes;
>>> -	sbinfo->free_inodes = config.max_inodes - inodes;
>>> +	if (!config.max_inodes)
>>> +		sbinfo->free_inodes = 0;
>>> +	else
>>> +		sbinfo->free_inodes = config.max_inodes - inodes;
>>>   
>>>   	/*
>>>   	 * Preserve previous mempolicy unless mpol remount option was specified.
>>> -- 
>>> 2.17.2
>>>
>>
>> Hm, sorry about my bot, this looked like an odd one-off patch.
>>
>> What about 5.3.y, should this patch also go there as well?
>>
>> But is it really an issue as this is a new "feature" that 5.4 now has,
>> can't you just use 5.4.y if you need this type of thing?  It's never
>> worked in the past, right?
> 
> Yes, please ignore this for stable, Greg: it appears to be a new feature
> in 5.4: one that I should have noticed when testing, but failed to do so
> (and it may even be something that I foisted unthinkingly on Al when
> suggesting mods to his and David's originals).
> 
> Yu Kuai: many thanks for noticing and reporting this, I was unconscious
> of changing behavior here.  Notice how the 5.4 shmem_reconfigure() still
> has a comment above it saying "we disallow change from limited->unlimited
> blocks/inodes while any are in use" - and root inode is always in use.
> Notice how your 4.19 patch does nothing for max_blocks, so remounting
> with nr_blocks=0 will still fail, once a non-empty file has been created.
Thank you for your response, I missed that in my test.
> 
> I agree that it's not obvious why limited->unlimited needs to fail,
> and perhaps a nice (worthwhile?) little enhancement to allow that;
> but it was unintentional, and now (but not today) I have to go back
> to remind myself why 2.6.13 implemented it with that restriction,
> and whether there are any fixes needed to the new behavior in 5.4
> (at the least, we ought to fix that comment in 5.5).

I was confused about the comment in 5.5: "we disallow change from 
limited->unlimited blocks/inodes while any are in use", it seems change 
from limited to unlimited will always succed. Maybe this is
more appropriate: "Note that we allow change from limited to unlimited 
blocks/inodes. But we disallow change from unlimited->limited, because 
in that case we have no record of how much is already in use. And we 
disallow change blocks/inodes to less than the amount that is aready in use"

Thanks
Yu Kuai


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2019-12-05  1:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-04 13:11 [4.19.y PATCH] tmpfs: fix unable to remount nr_inodes from limited to unlimited yu kuai
2019-12-04 17:31 ` Greg KH
2019-12-04 17:33 ` Greg KH
2019-12-04 20:13   ` Hugh Dickins
2019-12-05  1:41     ` yukuai (C)
2019-12-05  1:22   ` yukuai (C)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).