Skip to contentSkip to conversation

sparc: Fix handling of page table constructor failure

PATCH Applied Matthew Wilcox (Oracle) 4 participants 11 messages Nov 25, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 sparc: Fix handling of page table constructor failure

The page has just been allocated, so its refcount is 1. free_unref_page() is for use on pages which have a zero refcount. Use __free_page() like the other implementations of pte_alloc_one().

Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")
---
 arch/sparc/mm/init_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/mm/init_64.c +1 -1
index 96edf64d4fb3..182bb7bdaa0a 100644
@@ -2894,7 +2894,7 @@ pgtable_t pte_alloc_one(struct mm_struct *mm)
 	if (!page)
 		return NULL;
 	if (!pgtable_pte_page_ctor(page)) {
-		free_unref_page(page);
+		__free_page(page);
 		return NULL;
 	}
 	return (pte_t *) page_address(page);
Signature · 1 line
2.29.2
#1 lore raw

PATCH 2/2 mm: Move free_unref_page to mm/internal.h

Code outside mm/ should not be calling free_unref_page(). Also move free_unref_page_list().

---
 include/linux/gfp.h | 2 --
 mm/internal.h       | 3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/gfp.h +0 -2
index c603237e006c..6e479e9c48ce 100644
@@ -580,8 +580,6 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask);
 
 extern void __free_pages(struct page *page, unsigned int order);
 extern void free_pages(unsigned long addr, unsigned int order);
-extern void free_unref_page(struct page *page);
-extern void free_unref_page_list(struct list_head *list);
 
 struct page_frag_cache;
 extern void __page_frag_cache_drain(struct page *page, unsigned int count);
mm/internal.h +3 -0
index 75ae680d0a2c..5864815947fe 100644
@@ -201,6 +201,9 @@ extern void post_alloc_hook(struct page *page, unsigned int order,
 					gfp_t gfp_flags);
 extern int user_min_free_kbytes;
 
+extern void free_unref_page(struct page *page);
+extern void free_unref_page_list(struct list_head *list);
+
 extern void zone_pcp_update(struct zone *zone);
 extern void zone_pcp_reset(struct zone *zone);
 extern void zone_pcp_disable(struct zone *zone);
Signature · 1 line
2.29.2
Reviewed-by on v1 2/2
#2 lore raw

Re: [PATCH 2/2] mm: Move free_unref_page to mm/internal.h

Quoted 28 lines · Matthew Wilcox (Oracle)

Code outside mm/ should not be calling free_unref_page(). Also move free_unref_page_list().

---
 include/linux/gfp.h | 2 --
 mm/internal.h       | 3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/gfp.h +0 -2
index c603237e006c..6e479e9c48ce 100644
@@ -580,8 +580,6 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask);
 
 extern void __free_pages(struct page *page, unsigned int order);
 extern void free_pages(unsigned long addr, unsigned int order);
-extern void free_unref_page(struct page *page);
-extern void free_unref_page_list(struct list_head *list);
 
 struct page_frag_cache;
 extern void __page_frag_cache_drain(struct page *page, unsigned int count);
mm/internal.h +0 -0
index 75ae680d0a2c..5864815947fe 100644

mm/internal.h extern void post_alloc_hook(struct page *page, unsigned int order, · line 209

Quoted 9 lines
mm/internal.h +3 -0
@@ -201,6 +201,9 @@ extern void post_alloc_hook(struct page *page, unsigned int order,
 					gfp_t gfp_flags);
 extern int user_min_free_kbytes;
 
+extern void free_unref_page(struct page *page);
+extern void free_unref_page_list(struct list_head *list);
+
 extern void zone_pcp_update(struct zone *zone);
 extern void zone_pcp_reset(struct zone *zone);
 extern void zone_pcp_disable(struct zone *zone);
Signature · 3 lines
Thanks,

David / dhildenb
reviewer Reviewed-by on v1 2/2
#3 lore raw

Re: [PATCH 2/2] mm: Move free_unref_page to mm/internal.h

In reply to Matthew Wilcox (Oracle)
Quoted 4 lines · Matthew Wilcox (Oracle)

Code outside mm/ should not be calling free_unref_page(). Also move free_unref_page_list().

Quoted 35 lines
---
 include/linux/gfp.h | 2 --
 mm/internal.h       | 3 +++
 2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/gfp.h +0 -2
index c603237e006c..6e479e9c48ce 100644
@@ -580,8 +580,6 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask);
 
 extern void __free_pages(struct page *page, unsigned int order);
 extern void free_pages(unsigned long addr, unsigned int order);
-extern void free_unref_page(struct page *page);
-extern void free_unref_page_list(struct list_head *list);
 
 struct page_frag_cache;
 extern void __page_frag_cache_drain(struct page *page, unsigned int count);
mm/internal.h +3 -0
index 75ae680d0a2c..5864815947fe 100644
@@ -201,6 +201,9 @@ extern void post_alloc_hook(struct page *page, unsigned int order,
 					gfp_t gfp_flags);
 extern int user_min_free_kbytes;
 
+extern void free_unref_page(struct page *page);
+extern void free_unref_page_list(struct list_head *list);
+
 extern void zone_pcp_update(struct zone *zone);
 extern void zone_pcp_reset(struct zone *zone);
 extern void zone_pcp_disable(struct zone *zone);
Signature · 1 line
2.29.2
Signature · 2 lines
Sincerely yours,
Mike.
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] mm: Move free_unref_page to mm/internal.h

In reply to Matthew Wilcox (Oracle)
Quoted 2 lines · Matthew Wilcox (Oracle)

Code outside mm/ should not be calling free_unref_page(). Also move free_unref_page_list().

Good idea.

Quoted 1 line

There seems to be some effort to remove "extern" from function declarations from headers. Do we want to do that, at once, or piecemeal? If the latter, this is a chance for these functions at least :)

Quoted 33 lines
---
  include/linux/gfp.h | 2 --
  mm/internal.h       | 3 +++
  2 files changed, 3 insertions(+), 2 deletions(-)
include/linux/gfp.h +0 -2
index c603237e006c..6e479e9c48ce 100644
@@ -580,8 +580,6 @@ void * __meminit alloc_pages_exact_nid(int nid, size_t size, gfp_t gfp_mask);
 
  extern void __free_pages(struct page *page, unsigned int order);
  extern void free_pages(unsigned long addr, unsigned int order);
-extern void free_unref_page(struct page *page);
-extern void free_unref_page_list(struct list_head *list);
 
  struct page_frag_cache;
  extern void __page_frag_cache_drain(struct page *page, unsigned int count);
mm/internal.h +3 -0
index 75ae680d0a2c..5864815947fe 100644
@@ -201,6 +201,9 @@ extern void post_alloc_hook(struct page *page, unsigned int order,
  					gfp_t gfp_flags);
  extern int user_min_free_kbytes;
 
+extern void free_unref_page(struct page *page);
+extern void free_unref_page_list(struct list_head *list);
+
  extern void zone_pcp_update(struct zone *zone);
  extern void zone_pcp_reset(struct zone *zone);
  extern void zone_pcp_disable(struct zone *zone);
#5 lore raw

Re: [PATCH 2/2] mm: Move free_unref_page to mm/internal.h

Quoted 6 lines · Vlastimil Babka
Quoted 2 lines · Matthew Wilcox (Oracle)

Code outside mm/ should not be calling free_unref_page(). Also move free_unref_page_list().

Good idea.

Quoted 7 lines
Quoted 1 line

There seems to be some effort to remove "extern" from function declarations from headers. Do we want to do that, at once, or piecemeal? If the latter, this is a chance for these functions at least :)

I'm generally in favour of those efforts, but since I was just moving the function declarations, and all the code near the destination was using 'extern', I decided not to remove it so as to avoid getting caught up in bikeshedding ...

Reviewed-by on v1 1/2
#6 lore raw
In reply to Matthew Wilcox (Oracle)
Quoted 16 lines · Matthew Wilcox (Oracle)

The page has just been allocated, so its refcount is 1. free_unref_page() is for use on pages which have a zero refcount. Use __free_page() like the other implementations of pte_alloc_one().

Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")
---
 arch/sparc/mm/init_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/mm/init_64.c +0 -0
index 96edf64d4fb3..182bb7bdaa0a 100644

arch/sparc/mm/init_64.c pgtable_t pte_alloc_one(struct mm_struct *mm) · line 2900

Quoted 8 lines
arch/sparc/mm/init_64.c +1 -1
@@ -2894,7 +2894,7 @@ pgtable_t pte_alloc_one(struct mm_struct *mm)
 	if (!page)
 		return NULL;
 	if (!pgtable_pte_page_ctor(page)) {
-		free_unref_page(page);
+		__free_page(page);
 		return NULL;
 	}
 	return (pte_t *) page_address(page);

I wonder if reusing __pte_alloc_one() - e.g., internally - would be even cleaner.

Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Matthew Wilcox (Oracle)

The page has just been allocated, so its refcount is 1. free_unref_page() is for use on pages which have a zero refcount. Use __free_page() like the other implementations of pte_alloc_one().

Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")
---
 arch/sparc/mm/init_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/mm/init_64.c +0 -1
index 96edf64d4fb3..182bb7bdaa0a 100644
@@ -2894,7 +2894,7 @@ pgtable_t pte_alloc_one(struct mm_struct *mm)
 	if (!page)
 		return NULL;
 	if (!pgtable_pte_page_ctor(page)) {
-		free_unref_page(page);
Quoted 8 lines

arch/sparc/mm/init_64.c pgtable_t pte_alloc_one(struct mm_struct *mm) · line 2900

Quoted 5 lines
arch/sparc/mm/init_64.c +1 -0
+		__free_page(page);
 		return NULL;
 	}
 	return (pte_t *) page_address(page);

I wonder if reusing __pte_alloc_one() - e.g., internally - would be even cleaner.

It's really awkward to do because pgtable_t is defined differently. The clean thing to do would be:

--- arch/sparc/include/asm/page_64.h
-typedef pte_t *pgtable_t;
+typedef struct page *pgtable_t;

and then do all the other changes that would require.

But that feels like a lot more work than appropriate to fix this unlikely bug.

#8 lore raw
Quoted 37 lines · Matthew Wilcox
Quoted 20 lines · David Hildenbrand
Quoted 19 lines · Matthew Wilcox (Oracle)

The page has just been allocated, so its refcount is 1. free_unref_page() is for use on pages which have a zero refcount. Use __free_page() like the other implementations of pte_alloc_one().

Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")
---
 arch/sparc/mm/init_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/mm/init_64.c +0 -1
index 96edf64d4fb3..182bb7bdaa0a 100644
@@ -2894,7 +2894,7 @@ pgtable_t pte_alloc_one(struct mm_struct *mm)
 	if (!page)
 		return NULL;
 	if (!pgtable_pte_page_ctor(page)) {
-		free_unref_page(page);
Quoted 8 lines

arch/sparc/mm/init_64.c pgtable_t pte_alloc_one(struct mm_struct *mm) · line 2900

Quoted 5 lines
arch/sparc/mm/init_64.c +1 -0
+		__free_page(page);
 		return NULL;
 	}
 	return (pte_t *) page_address(page);

I wonder if reusing __pte_alloc_one() - e.g., internally - would be even cleaner.

It's really awkward to do because pgtable_t is defined differently. The clean thing to do would be:

--- arch/sparc/include/asm/page_64.h

(quoted diff) +1 -1
-typedef pte_t *pgtable_t;
+typedef struct page *pgtable_t;
Quoted 4 lines

and then do all the other changes that would require.

But that feels like a lot more work than appropriate to fix this unlikely bug.

Yeah, cleanups would have to come on top of the fix of course. But I can understand that you have plenty of better things to do :) ... maybe sparc people want to work on that at one point.

Signature · 3 lines
Thanks,

David / dhildenb
reviewer Reviewed-by on v1 1/2
#9 lore raw
In reply to Matthew Wilcox (Oracle)
Quoted 6 lines · Matthew Wilcox (Oracle)

The page has just been allocated, so its refcount is 1. free_unref_page() is for use on pages which have a zero refcount. Use __free_page() like the other implementations of pte_alloc_one().

Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")
Quoted 20 lines
---
 arch/sparc/mm/init_64.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/mm/init_64.c +1 -1
index 96edf64d4fb3..182bb7bdaa0a 100644
@@ -2894,7 +2894,7 @@ pgtable_t pte_alloc_one(struct mm_struct *mm)
 	if (!page)
 		return NULL;
 	if (!pgtable_pte_page_ctor(page)) {
-		free_unref_page(page);
+		__free_page(page);
 		return NULL;
 	}
 	return (pte_t *) page_address(page);
Signature · 1 line
2.29.2
Signature · 2 lines
Sincerely yours,
Mike.
Acked-by on v1 1/2
#10 lore raw
In reply to Matthew Wilcox (Oracle)
Quoted 6 lines · Matthew Wilcox (Oracle)

The page has just been allocated, so its refcount is 1. free_unref_page() is for use on pages which have a zero refcount. Use __free_page() like the other implementations of pte_alloc_one().

Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")
Quoted 18 lines
---
  arch/sparc/mm/init_64.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/mm/init_64.c +1 -1
index 96edf64d4fb3..182bb7bdaa0a 100644
@@ -2894,7 +2894,7 @@ pgtable_t pte_alloc_one(struct mm_struct *mm)
  	if (!page)
  		return NULL;
  	if (!pgtable_pte_page_ctor(page)) {
-		free_unref_page(page);
+		__free_page(page);
  		return NULL;
  	}
  	return (pte_t *) page_address(page);