sparc: Fix handling of page table constructor failure
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().
--- arch/sparc/mm/init_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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);
Signature · 1 line
2.29.2
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
@@ -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
@@ -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
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 callingfree_unref_page(). Also movefree_unref_page_list().Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- include/linux/gfp.h | 2 -- mm/internal.h | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-)include/linux/gfp.h +0
-2@@ -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
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
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 callingfree_unref_page(). Also movefree_unref_page_list().Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
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@@ -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@@ -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.
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 callingfree_unref_page(). Also movefree_unref_page_list().
Good idea.
Quoted 1 line
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
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@@ -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@@ -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);
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 callingfree_unref_page(). Also movefree_unref_page_list().Good idea.
Quoted 7 lines
Quoted 1 line
Signed-off-by Matthew Wilcox (Oracle) <[email protected]>Acked-by Vlastimil Babka <[email protected]>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 ...
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 ofpte_alloc_one().Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- arch/sparc/mm/init_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/sparc/mm/init_64.c +0
-0
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
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 ofpte_alloc_one().Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- arch/sparc/mm/init_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/sparc/mm/init_64.c +0
-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);
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.
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 ofpte_alloc_one().Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")Signed-off-by Matthew Wilcox (Oracle) <[email protected]>--- arch/sparc/mm/init_64.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/sparc/mm/init_64.c +0
-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);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_tis 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
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 ofpte_alloc_one().Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
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@@ -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.
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 ofpte_alloc_one().Fixes 1ae9ae5f7df7 ("sparc: handle pgtable_page_ctor() fail")Signed-off-by Matthew Wilcox (Oracle) <[email protected]>
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@@ -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);