linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ubifs: Get/put page when changing PG_private
@ 2018-12-15 15:01 Richard Weinberger
  2018-12-15 20:38 ` zhangjun
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Richard Weinberger @ 2018-12-15 15:01 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, linux-fsdevel, hsiangkao, kirill.shutemov,
	Richard Weinberger, stable, zhangjun

The page migration code assumes that a page with PG_private
set has its page count elevated by 1.
UBIFS never did this and therefore the migration code was unable
to migrate some pages owned by UBIFS.
The lead to situations where the CMA memory allocator failed to
allocate memory.

Fix this by using get/put_page when changing PG_private.

Cc: <stable@vger.kernel.org>
Cc: zhangjun <openzhangj@gmail.com>
Fixes: 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")
Reported-by: zhangjun <openzhangj@gmail.com>
Signed-off-by: Richard Weinberger <richard@nod.at>
---
zhangjun,

Please give this patch a try!

Thanks,
//richard
---
 fs/ubifs/file.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
index 1b78f2e09218..abe940d0767c 100644
--- a/fs/ubifs/file.c
+++ b/fs/ubifs/file.c
@@ -582,6 +582,7 @@ static int ubifs_write_end(struct file *file, struct address_space *mapping,
 	}
 
 	if (!PagePrivate(page)) {
+		get_page(page);
 		SetPagePrivate(page);
 		atomic_long_inc(&c->dirty_pg_cnt);
 		__set_page_dirty_nobuffers(page);
@@ -959,6 +960,7 @@ static int do_writepage(struct page *page, int len)
 	atomic_long_dec(&c->dirty_pg_cnt);
 	ClearPagePrivate(page);
 	ClearPageChecked(page);
+	put_page(page);
 
 	kunmap(page);
 	unlock_page(page);
@@ -1318,6 +1320,7 @@ static void ubifs_invalidatepage(struct page *page, unsigned int offset,
 	atomic_long_dec(&c->dirty_pg_cnt);
 	ClearPagePrivate(page);
 	ClearPageChecked(page);
+	put_page(page);
 }
 
 int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
@@ -1487,6 +1490,8 @@ static int ubifs_migrate_page(struct address_space *mapping,
 
 	if (PagePrivate(page)) {
 		ClearPagePrivate(page);
+		put_page(page);
+		get_page(newpage);
 		SetPagePrivate(newpage);
 	}
 
@@ -1513,6 +1518,7 @@ static int ubifs_releasepage(struct page *page, gfp_t unused_gfp_flags)
 	ubifs_assert(c, 0);
 	ClearPagePrivate(page);
 	ClearPageChecked(page);
+	put_page(page);
 	return 1;
 }
 
@@ -1582,6 +1588,7 @@ static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf)
 	else {
 		if (!PageChecked(page))
 			ubifs_convert_page_budget(c);
+		get_page(page);
 		SetPagePrivate(page);
 		atomic_long_inc(&c->dirty_pg_cnt);
 		__set_page_dirty_nobuffers(page);
-- 
2.20.0


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

* Re: [PATCH] ubifs: Get/put page when changing PG_private
  2018-12-15 15:01 [PATCH] ubifs: Get/put page when changing PG_private Richard Weinberger
@ 2018-12-15 20:38 ` zhangjun
  2018-12-17 10:59 ` Kirill A. Shutemov
  2018-12-21  8:56 ` Richard Weinberger
  2 siblings, 0 replies; 8+ messages in thread
From: zhangjun @ 2018-12-15 20:38 UTC (permalink / raw)
  To: Richard Weinberger, linux-mtd
  Cc: linux-kernel, linux-fsdevel, hsiangkao, kirill.shutemov, stable

On 2018/12/15 下午11:01, Richard Weinberger wrote:
> The page migration code assumes that a page with PG_private
> set has its page count elevated by 1.
> UBIFS never did this and therefore the migration code was unable
> to migrate some pages owned by UBIFS.
> The lead to situations where the CMA memory allocator failed to
> allocate memory.
>
> Fix this by using get/put_page when changing PG_private.
>
> Cc: <stable@vger.kernel.org>
> Cc: zhangjun <openzhangj@gmail.com>
> Fixes: 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")
> Reported-by: zhangjun <openzhangj@gmail.com>
> Signed-off-by: Richard Weinberger <richard@nod.at>
> ---
> zhangjun,
>
> Please give this patch a try!
>
> Thanks,
> //richard
> ---
>   fs/ubifs/file.c | 7 +++++++
>   1 file changed, 7 insertions(+)
>
> diff --git a/fs/ubifs/file.c b/fs/ubifs/file.c
> index 1b78f2e09218..abe940d0767c 100644
> --- a/fs/ubifs/file.c
> +++ b/fs/ubifs/file.c
> @@ -582,6 +582,7 @@ static int ubifs_write_end(struct file *file, struct address_space *mapping,
>   	}
>   
>   	if (!PagePrivate(page)) {
> +		get_page(page);
>   		SetPagePrivate(page);
>   		atomic_long_inc(&c->dirty_pg_cnt);
>   		__set_page_dirty_nobuffers(page);
> @@ -959,6 +960,7 @@ static int do_writepage(struct page *page, int len)
>   	atomic_long_dec(&c->dirty_pg_cnt);
>   	ClearPagePrivate(page);
>   	ClearPageChecked(page);
> +	put_page(page);
>   
>   	kunmap(page);
>   	unlock_page(page);
> @@ -1318,6 +1320,7 @@ static void ubifs_invalidatepage(struct page *page, unsigned int offset,
>   	atomic_long_dec(&c->dirty_pg_cnt);
>   	ClearPagePrivate(page);
>   	ClearPageChecked(page);
> +	put_page(page);
>   }
>   
>   int ubifs_fsync(struct file *file, loff_t start, loff_t end, int datasync)
> @@ -1487,6 +1490,8 @@ static int ubifs_migrate_page(struct address_space *mapping,
>   
>   	if (PagePrivate(page)) {
>   		ClearPagePrivate(page);
> +		put_page(page);
> +		get_page(newpage);
>   		SetPagePrivate(newpage);
>   	}
>   
> @@ -1513,6 +1518,7 @@ static int ubifs_releasepage(struct page *page, gfp_t unused_gfp_flags)
>   	ubifs_assert(c, 0);
>   	ClearPagePrivate(page);
>   	ClearPageChecked(page);
> +	put_page(page);
>   	return 1;
>   }
>   
> @@ -1582,6 +1588,7 @@ static vm_fault_t ubifs_vm_page_mkwrite(struct vm_fault *vmf)
>   	else {
>   		if (!PageChecked(page))
>   			ubifs_convert_page_budget(c);
> +		get_page(page);
>   		SetPagePrivate(page);
>   		atomic_long_inc(&c->dirty_pg_cnt);
>   		__set_page_dirty_nobuffers(page);

Hello Richard

After adding your patch,my test did not go wrong.
I think it is ok now.

thanks
//zhangjun


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

* Re: [PATCH] ubifs: Get/put page when changing PG_private
  2018-12-15 15:01 [PATCH] ubifs: Get/put page when changing PG_private Richard Weinberger
  2018-12-15 20:38 ` zhangjun
@ 2018-12-17 10:59 ` Kirill A. Shutemov
  2018-12-17 11:32   ` Richard Weinberger
  2018-12-21  8:56 ` Richard Weinberger
  2 siblings, 1 reply; 8+ messages in thread
From: Kirill A. Shutemov @ 2018-12-17 10:59 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd, linux-kernel, linux-fsdevel, hsiangkao,
	kirill.shutemov, stable, zhangjun

On Sat, Dec 15, 2018 at 04:01:30PM +0100, Richard Weinberger wrote:
> The page migration code assumes that a page with PG_private
> set has its page count elevated by 1.
> UBIFS never did this and therefore the migration code was unable
> to migrate some pages owned by UBIFS.
> The lead to situations where the CMA memory allocator failed to
> allocate memory.
> 
> Fix this by using get/put_page when changing PG_private.

Looks good to me.

Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>

> Cc: <stable@vger.kernel.org>
> Cc: zhangjun <openzhangj@gmail.com>
> Fixes: 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")

It is fair to reference the commit here. But I believe the bug itself
predates the commit and relevant not only for migration.

We might make it clear in the commit message.

-- 
 Kirill A. Shutemov

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

* Re: [PATCH] ubifs: Get/put page when changing PG_private
  2018-12-17 10:59 ` Kirill A. Shutemov
@ 2018-12-17 11:32   ` Richard Weinberger
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Weinberger @ 2018-12-17 11:32 UTC (permalink / raw)
  To: Kirill A. Shutemov
  Cc: linux-mtd, linux-kernel, linux-fsdevel, hsiangkao,
	kirill.shutemov, stable, zhangjun

Am Montag, 17. Dezember 2018, 11:59:44 CET schrieb Kirill A. Shutemov:
> On Sat, Dec 15, 2018 at 04:01:30PM +0100, Richard Weinberger wrote:
> > The page migration code assumes that a page with PG_private
> > set has its page count elevated by 1.
> > UBIFS never did this and therefore the migration code was unable
> > to migrate some pages owned by UBIFS.
> > The lead to situations where the CMA memory allocator failed to
> > allocate memory.
> > 
> > Fix this by using get/put_page when changing PG_private.
> 
> Looks good to me.
> 
> Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
> 
> > Cc: <stable@vger.kernel.org>
> > Cc: zhangjun <openzhangj@gmail.com>
> > Fixes: 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")
> 
> It is fair to reference the commit here. But I believe the bug itself
> predates the commit and relevant not only for migration.

My intention was not blaming you. :)
IMHO backporting the fix makes only sense up to that commit.
 
> We might make it clear in the commit message.

Fair point, I'll rephrase.

Thanks,
//richard





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

* Re: [PATCH] ubifs: Get/put page when changing PG_private
  2018-12-15 15:01 [PATCH] ubifs: Get/put page when changing PG_private Richard Weinberger
  2018-12-15 20:38 ` zhangjun
  2018-12-17 10:59 ` Kirill A. Shutemov
@ 2018-12-21  8:56 ` Richard Weinberger
  2018-12-21 10:35   ` Kirill A. Shutemov
  2018-12-25  2:42   ` zhangjun
  2 siblings, 2 replies; 8+ messages in thread
From: Richard Weinberger @ 2018-12-21  8:56 UTC (permalink / raw)
  To: linux-mtd
  Cc: linux-kernel, linux-fsdevel, hsiangkao, kirill.shutemov, stable,
	zhangjun

Am Samstag, 15. Dezember 2018, 16:01:30 CET schrieb Richard Weinberger:
> The page migration code assumes that a page with PG_private
> set has its page count elevated by 1.
> UBIFS never did this and therefore the migration code was unable
> to migrate some pages owned by UBIFS.
> The lead to situations where the CMA memory allocator failed to
> allocate memory.
> 
> Fix this by using get/put_page when changing PG_private.
> 
> Cc: <stable@vger.kernel.org>
> Cc: zhangjun <openzhangj@gmail.com>
> Fixes: 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")
> Reported-by: zhangjun <openzhangj@gmail.com>
> Signed-off-by: Richard Weinberger <richard@nod.at>

FYI, on the XFS side a similar change caused a regression.
https://marc.info/?l=linux-fsdevel&m=154530861202448&w=2

Until this regression is not fully understood, including the implications
for UBIFS, I'll not merge this patch.

Thanks,
//richard



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

* Re: [PATCH] ubifs: Get/put page when changing PG_private
  2018-12-21  8:56 ` Richard Weinberger
@ 2018-12-21 10:35   ` Kirill A. Shutemov
  2018-12-25  2:42   ` zhangjun
  1 sibling, 0 replies; 8+ messages in thread
From: Kirill A. Shutemov @ 2018-12-21 10:35 UTC (permalink / raw)
  To: Richard Weinberger
  Cc: linux-mtd, linux-kernel, linux-fsdevel, hsiangkao,
	kirill.shutemov, stable, zhangjun

On Fri, Dec 21, 2018 at 09:56:25AM +0100, Richard Weinberger wrote:
> Am Samstag, 15. Dezember 2018, 16:01:30 CET schrieb Richard Weinberger:
> > The page migration code assumes that a page with PG_private
> > set has its page count elevated by 1.
> > UBIFS never did this and therefore the migration code was unable
> > to migrate some pages owned by UBIFS.
> > The lead to situations where the CMA memory allocator failed to
> > allocate memory.
> > 
> > Fix this by using get/put_page when changing PG_private.
> > 
> > Cc: <stable@vger.kernel.org>
> > Cc: zhangjun <openzhangj@gmail.com>
> > Fixes: 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")
> > Reported-by: zhangjun <openzhangj@gmail.com>
> > Signed-off-by: Richard Weinberger <richard@nod.at>
> 
> FYI, on the XFS side a similar change caused a regression.
> https://marc.info/?l=linux-fsdevel&m=154530861202448&w=2
> 
> Until this regression is not fully understood, including the implications
> for UBIFS, I'll not merge this patch.

This looks like a reasonable resolution to me:

http://lkml.kernel.org/r/20181221093919.GA2337@lst.de

But let's wait the inclusion (or objection).

-- 
 Kirill A. Shutemov

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

* Re: [PATCH] ubifs: Get/put page when changing PG_private
  2018-12-21  8:56 ` Richard Weinberger
  2018-12-21 10:35   ` Kirill A. Shutemov
@ 2018-12-25  2:42   ` zhangjun
  2018-12-25 21:08     ` Richard Weinberger
  1 sibling, 1 reply; 8+ messages in thread
From: zhangjun @ 2018-12-25  2:42 UTC (permalink / raw)
  To: Richard Weinberger, linux-mtd
  Cc: linux-kernel, linux-fsdevel, hsiangkao, kirill.shutemov, stable

On 2018/12/21 下午4:56, Richard Weinberger wrote:
> Am Samstag, 15. Dezember 2018, 16:01:30 CET schrieb Richard Weinberger:
>> The page migration code assumes that a page with PG_private
>> set has its page count elevated by 1.
>> UBIFS never did this and therefore the migration code was unable
>> to migrate some pages owned by UBIFS.
>> The lead to situations where the CMA memory allocator failed to
>> allocate memory.
>>
>> Fix this by using get/put_page when changing PG_private.
>>
>> Cc: <stable@vger.kernel.org>
>> Cc: zhangjun <openzhangj@gmail.com>
>> Fixes: 4ac1c17b2044 ("UBIFS: Implement ->migratepage()")
>> Reported-by: zhangjun <openzhangj@gmail.com>
>> Signed-off-by: Richard Weinberger <richard@nod.at>
> FYI, on the XFS side a similar change caused a regression.
> https://marc.info/?l=linux-fsdevel&m=154530861202448&w=2
>
> Until this regression is not fully understood, including the implications
> for UBIFS, I'll not merge this patch.
>
> Thanks,
> //richard
>
>
Hello,richard


Before fully understanding this regression, in order to fix the bug of 
cma_alloc(),
submit a conservative patch that modifies count in iomap_migrate_page().
Can you consider merging first?

https://marc.info/?l=linux-kernel&m=154473132332661&w=2


Thanks
//zhangjun


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

* Re: [PATCH] ubifs: Get/put page when changing PG_private
  2018-12-25  2:42   ` zhangjun
@ 2018-12-25 21:08     ` Richard Weinberger
  0 siblings, 0 replies; 8+ messages in thread
From: Richard Weinberger @ 2018-12-25 21:08 UTC (permalink / raw)
  To: zhangjun
  Cc: linux-mtd, linux-kernel, linux-fsdevel, hsiangkao,
	kirill.shutemov, stable

Am Dienstag, 25. Dezember 2018, 03:42:37 CET schrieb zhangjun:
> Hello,richard
> 
> 
> Before fully understanding this regression, in order to fix the bug of 
> cma_alloc(),
> submit a conservative patch that modifies count in iomap_migrate_page().
> Can you consider merging first?

No. There is no need to rush.
As it looks like the iomap regression is trivial, Christoph pointed out
that a case was forgotten.
But Dave is currently (like almost all of us) on vacation to confirm.

Thanks,
//richard





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

end of thread, other threads:[~2018-12-25 21:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-15 15:01 [PATCH] ubifs: Get/put page when changing PG_private Richard Weinberger
2018-12-15 20:38 ` zhangjun
2018-12-17 10:59 ` Kirill A. Shutemov
2018-12-17 11:32   ` Richard Weinberger
2018-12-21  8:56 ` Richard Weinberger
2018-12-21 10:35   ` Kirill A. Shutemov
2018-12-25  2:42   ` zhangjun
2018-12-25 21:08     ` Richard Weinberger

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).