mm/page_isolation: fix potential warning from user
Subsystems (2)
PATCH v2 1/1 mm/page_isolation: fix potential warning from user
It makes sense to call the WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE) from start_isolate_page_range(), but should avoid triggering it from userspace, i.e, from is_mem_section_removable() because it could be a DoS if warn_on_panic is set.
While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so set_migratetype_isolate() could really return a bool.
---
v2: Improve the commit log.
Warn for all start_isolate_page_range() users not just offlining.
mm/page_alloc.c | 11 ++++------- mm/page_isolation.c | 30 +++++++++++++++++------------- 2 files changed, 21 insertions(+), 20 deletions(-)
mm/page_alloc.c +4 -7
@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {
@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved
@@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;
@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC
mm/page_isolation.c +17 -13
@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags) { -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);
@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; } out:spin_unlock_irqrestore (&zone->lock, flags); -if (!ret) + +if (!unmovable) {drain_all_pages (zone); -else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a -* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/* +* printk() with zone->lock held will likely trigger a +* lockdep splat, so defer it here. +*/ +dump_page (unmovable,"unmovable page" ); + } + +return !!unmovable; }static void unset_migratetype_isolate (struct page *page,unsigned migratetype)
Signature · 1 line
2.21.0 (Apple Git-122.2)
Quoted 70 lines · Qian Cai
It makes sense to call the
WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)fromstart_isolate_page_range(), but should avoid triggering it from userspace, i.e, fromis_mem_section_removable()because it could be a DoS ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so
set_migratetype_isolate()could really return a bool.Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>---
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.mm/page_alloc.c | 11 ++++------- mm/page_isolation.c | 30 +++++++++++++++++------------- 2 files changed, 21 insertions(+), 20 deletions(-)mm/page_alloc.c +4
-7@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC mm/page_isolation.c +0
-0
mm/page_isolation.c line 19
Quoted 6 lines
mm/page_isolation.c +2
-1@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags)
Why this change?
mm/page_isolation.c line 21
Quoted 3 lines
mm/page_isolation.c +1
-1{ -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );
Also, why this change?
Quoted 22 lines
mm/page_isolation.c +2
-6struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; } out:spin_unlock_irqrestore (&zone->lock, flags); -if (!ret) + +if (!unmovable) {drain_all_pages (zone); -else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a
mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 63
Quoted 10 lines
mm/page_isolation.c +5
-5-* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/*
Why this change? (!IS_ERR)
Some things here look unrelated - or I am missing something :)
Signature · 3 lines
Thanks, David / dhildenb
Quoted 126 lines · David Hildenbrand
Quoted 70 lines · Qian Cai
It makes sense to call the
WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)fromstart_isolate_page_range(), but should avoid triggering it from userspace, i.e, fromis_mem_section_removable()because it could be a DoS ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so
set_migratetype_isolate()could really return a bool.Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>---
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.
mm/page_alloc.c| 11 ++++-------mm/page_isolation.c| 30 +++++++++++++++++-------------2 files changed, 21 insertions(+), 20 deletions(-)mm/page_alloc.c +4
-7@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC mm/page_isolation.c +0
-0mm/page_isolation.c line 19
Quoted 6 lines
mm/page_isolation.c +2
-1@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags)Why this change?
mm/page_isolation.c line 21
Quoted 3 lines
mm/page_isolation.c +1
-1{ -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );Also, why this change?
Quoted 22 lines
mm/page_isolation.c +0
-2struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; }out:
spin_unlock_irqrestore(&zone->lock, flags);mm/page_isolation.c +2
-1-if (!ret) + +if (!unmovable) {drain_all_pages(zone);mm/page_isolation.c +0
-3-else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 63
Quoted 10 lines
mm/page_isolation.c +5
-5-* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/* Why this change? (!IS_ERR)
Quoted 1 line
Some things here look unrelated - or I am missing something :)
The original “ret” variable looks ugly to me, so I just removed that and consolidated with the “unmovable” pointer to always be able to report an error. Since this cleanup is really small, I did not bother send a separate patch for it.
Quoted 122 lines · David Hildenbrand
Quoted 70 lines · Qian Cai
It makes sense to call the
WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)fromstart_isolate_page_range(), but should avoid triggering it from userspace, i.e, fromis_mem_section_removable()because it could be a DoS ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so
set_migratetype_isolate()could really return a bool.Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>---
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.mm/page_alloc.c | 11 ++++------- mm/page_isolation.c | 30 +++++++++++++++++------------- 2 files changed, 21 insertions(+), 20 deletions(-)mm/page_alloc.c +4
-7@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC mm/page_isolation.c +0
-0mm/page_isolation.c line 19
Quoted 6 lines
mm/page_isolation.c +2
-1@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags)Why this change?
mm/page_isolation.c line 21
Quoted 3 lines
mm/page_isolation.c +1
-1{ -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );Also, why this change?
Quoted 22 lines
mm/page_isolation.c +2
-6struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; } out:spin_unlock_irqrestore (&zone->lock, flags); -if (!ret) + +if (!unmovable) {drain_all_pages (zone); -else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 63
Quoted 10 lines
mm/page_isolation.c +5
-5-* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/* Why this change? (!IS_ERR)
Quoted 2 lines
Some things here look unrelated - or I am missing something :)
FWIW, I'd prefer this change without any such cleanups (e.g., I don't like returning a bool from this function and the IS_ERR handling, makes the function harder to read than before)
Signature · 3 lines
Thanks, David / dhildenb
Quoted 127 lines · David Hildenbrand
Quoted 122 lines · David Hildenbrand
Quoted 70 lines · Qian Cai
It makes sense to call the
WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)fromstart_isolate_page_range(), but should avoid triggering it from userspace, i.e, fromis_mem_section_removable()because it could be a DoS ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so
set_migratetype_isolate()could really return a bool.Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>---
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.
mm/page_alloc.c| 11 ++++-------mm/page_isolation.c| 30 +++++++++++++++++-------------2 files changed, 21 insertions(+), 20 deletions(-)mm/page_alloc.c +4
-7@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC mm/page_isolation.c +0
-0mm/page_isolation.c line 19
Quoted 6 lines
mm/page_isolation.c +2
-1@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags)Why this change?
mm/page_isolation.c line 21
Quoted 3 lines
mm/page_isolation.c +1
-1{ -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );Also, why this change?
Quoted 22 lines
mm/page_isolation.c +0
-2struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; }out:
spin_unlock_irqrestore(&zone->lock, flags);mm/page_isolation.c +2
-1-if (!ret) + +if (!unmovable) {drain_all_pages(zone);mm/page_isolation.c +0
-3-else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 63
Quoted 10 lines
mm/page_isolation.c +5
-5-* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/* Why this change? (!IS_ERR)
Quoted 6 lines
Quoted 2 lines
Some things here look unrelated - or I am missing something :)
FWIW, I'd prefer this change without any such cleanups (e.g., I don't like returning a bool from this function and the
IS_ERRhandling, makes the function harder to read than before)
What is Michal or Andrew’s opinion? BTW, a bonus point to return a bool is that it helps the code robustness in general, as UBSAN will be able to catch any abuse.
Quoted 130 lines · Qian Cai
Quoted 130 lines · David Hildenbrand
Quoted 124 lines · David Hildenbrand
Quoted 70 lines · Qian Cai
It makes sense to call the
WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)fromstart_isolate_page_range(), but should avoid triggering it from userspace, i.e, fromis_mem_section_removable()because it could be a DoS ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so
set_migratetype_isolate()could really return a bool.Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>---
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.
mm/page_alloc.c| 11 ++++-------mm/page_isolation.c| 30 +++++++++++++++++-------------2 files changed, 21 insertions(+), 20 deletions(-)mm/page_alloc.c +4
-7@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC mm/page_isolation.c +0
-0mm/page_isolation.c line 19
Quoted 6 lines
mm/page_isolation.c +2
-1@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags)Why this change?
mm/page_isolation.c line 21
Quoted 3 lines
mm/page_isolation.c +1
-1{ -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );Also, why this change?
Quoted 22 lines
mm/page_isolation.c +0
-2struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; }out:
spin_unlock_irqrestore(&zone->lock, flags);mm/page_isolation.c +2
-1-if (!ret) + +if (!unmovable) {drain_all_pages(zone);mm/page_isolation.c +0
-3-else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 63
Quoted 10 lines
mm/page_isolation.c +5
-5-* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/* Why this change? (!IS_ERR)
Some things here look unrelated - or I am missing something :)
Quoted 8 lines
Quoted 3 lines
FWIW, I'd prefer this change without any such cleanups (e.g., I don't like returning a bool from this function and the
IS_ERRhandling, makes the function harder to read than before)What is Michal or Andrew’s opinion? BTW, a bonus point to return a bool is that it helps the code robustness in general, as UBSAN will be able to catch any abuse.
A return type of bool on a function that does not test a property ("has_...", "is"...") is IMHO confusing.
If we have an int, it is clear that "0" means "success". With a bool (true/false), it is not clear.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 139 lines · David Hildenbrand
Quoted 134 lines · Qian Cai
Quoted 133 lines · David Hildenbrand
Quoted 122 lines · David Hildenbrand
Quoted 70 lines · Qian Cai
It makes sense to call the
WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)fromstart_isolate_page_range(), but should avoid triggering it from userspace, i.e, fromis_mem_section_removable()because it could be a DoS ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so
set_migratetype_isolate()could really return a bool.Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>---
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.
mm/page_alloc.c| 11 ++++-------mm/page_isolation.c| 30 +++++++++++++++++-------------2 files changed, 21 insertions(+), 20 deletions(-)mm/page_alloc.c +4
-7@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC mm/page_isolation.c +0
-0mm/page_isolation.c line 19
Quoted 6 lines
mm/page_isolation.c +2
-1@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags)Why this change?
mm/page_isolation.c line 21
Quoted 3 lines
mm/page_isolation.c +1
-1{ -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );Also, why this change?
Quoted 22 lines
mm/page_isolation.c +0
-2struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; }out:
spin_unlock_irqrestore(&zone->lock, flags);mm/page_isolation.c +2
-1-if (!ret) + +if (!unmovable) {drain_all_pages(zone);mm/page_isolation.c +0
-3-else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 63
Quoted 10 lines
mm/page_isolation.c +5
-5-* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/* Why this change? (!IS_ERR)
Quoted 2 lines
Some things here look unrelated - or I am missing something :)
FWIW, I'd prefer this change without any such cleanups (e.g., I don't like returning a bool from this function and the
IS_ERRhandling, makes the function harder to read than before)
Quoted 7 lines
Quoted 4 lines
What is Michal or Andrew’s opinion? BTW, a bonus point to return a bool is that it helps the code robustness in general, as UBSAN will be able to catch any abuse.
A return type of bool on a function that does not test a property ("
has_...", "is"...") is IMHO confusing.
That is fine. It could be renamed to set_migratetype_is_isolate() or is_set_migratetype_isolate() which seems pretty minor because we have no consistency in the naming of this in linux kernel at all, i.e., many existing bool function names without those test of properties.
Quoted 9 lines
If we have an int, it is clear that "0" means "success". With a bool (true/false), it is not clear.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 144 lines · Qian Cai
Quoted 144 lines · David Hildenbrand
Quoted 138 lines · Qian Cai
Quoted 127 lines · David Hildenbrand
Quoted 122 lines · David Hildenbrand
Quoted 70 lines · Qian Cai
It makes sense to call the
WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)fromstart_isolate_page_range(), but should avoid triggering it from userspace, i.e, fromis_mem_section_removable()because it could be a DoS ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so
set_migratetype_isolate()could really return a bool.Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>---
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.
mm/page_alloc.c| 11 ++++-------mm/page_isolation.c| 30 +++++++++++++++++-------------2 files changed, 21 insertions(+), 20 deletions(-)mm/page_alloc.c +4
-7@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC mm/page_isolation.c +0
-0mm/page_isolation.c line 19
Quoted 6 lines
mm/page_isolation.c +2
-1@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags)Why this change?
mm/page_isolation.c line 21
Quoted 3 lines
mm/page_isolation.c +1
-1{ -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );Also, why this change?
Quoted 22 lines
mm/page_isolation.c +0
-2struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; }out:
spin_unlock_irqrestore(&zone->lock, flags);mm/page_isolation.c +2
-1-if (!ret) + +if (!unmovable) {drain_all_pages(zone);mm/page_isolation.c +0
-3-else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 63
Quoted 10 lines
mm/page_isolation.c +5
-5-* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/* Why this change? (!IS_ERR)
Quoted 6 lines
Quoted 2 lines
Some things here look unrelated - or I am missing something :)
FWIW, I'd prefer this change without any such cleanups (e.g., I don't like returning a bool from this function and the
IS_ERRhandling, makes the function harder to read than before)What is Michal or Andrew’s opinion? BTW, a bonus point to return a bool is that it helps the code robustness in general, as UBSAN will be able to catch any abuse.
Quoted 7 lines
Quoted 2 lines
A return type of bool on a function that does not test a property ("
has_...", "is"...") is IMHO confusing.That is fine. It could be renamed to
set_migratetype_is_isolate()oris_set_migratetype_isolate()which seems pretty minor because we have no consistency in the naming of this in linux kernel at all, i.e., many existing bool function names without those test of properties.
It does not query a property, so "is_set_migratetype_isolate()" is plain wrong.
Anyhow, Michal does not seem to care.
Signature · 3 lines
Thanks, David / dhildenb
Quoted 3 lines · David Hildenbrand
Quoted 2 lines · Qian Cai
Quoted 2 lines · David Hildenbrand
On 20.01.20 14:56, Qian Cai wrote:
[...]
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 3 lines
FWIW, I'd prefer this change without any such cleanups (e.g., I don't like returning a bool from this function and the
IS_ERRhandling, makes the function harder to read than before)What is Michal or Andrew’s opinion? BTW, a bonus point to return a bool is that it helps the code robustness in general, as UBSAN will be able to catch any abuse.
Quoted 7 lines
Quoted 2 lines
A return type of bool on a function that does not test a property ("
has_...", "is"...") is IMHO confusing.That is fine. It could be renamed to
set_migratetype_is_isolate()oris_set_migratetype_isolate()which seems pretty minor because we have no consistency in the naming of this in linux kernel at all, i.e., many existing bool function names without those test of properties.
Quoted 4 lines
It does not query a property, so "
is_set_migratetype_isolate()" is plain wrong.Anyhow, Michal does not seem to care.
Well, TBH I have missed this change. My bad. I have mostly checked that the WARN_ONCE is not gated by the check and didn't expect more changes. But I have likely missed that change in the previous version already. You guys are too quick with new version to my standard.
Anyway, I do agree that bool is clumsy here. Returning false on success is just head scratching. Nobody really consumes the errno value but I would just leave it that way or if there is a strong need to change then do it in a separate patch.
Signature · 2 lines
Michal Hocko SUSE Labs
Quoted 4 lines · Qian Cai
It makes sense to call the
WARN_ON_ONCE(zone_idx(zone) == ZONE_MOVABLE)fromstart_isolate_page_range(), but should avoid triggering it from userspace, i.e, fromis_mem_section_removable()because it could be a DoS ifwarn_on_panicis set.
Let's just make it clear that this mostly a pre-cautious because a real DoS should be pretty much impossible. But let's see whether somebody want to make a CVE out of it ;)
Quoted 6 lines
While at it, simplify the code a bit by removing an unnecessary jump label and a local variable, so
set_migratetype_isolate()could really return a bool.Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>
Thanks!
Quoted 112 lines
---
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.mm/page_alloc.c | 11 ++++------- mm/page_isolation.c | 30 +++++++++++++++++------------- 2 files changed, 21 insertions(+), 20 deletions(-)mm/page_alloc.c +4
-7@@ -8231,7 +8231,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,if (is_migrate_cma (migratetype))return NULL ; - goto unmovable; +return page; }for (; iter < pageblock_nr_pages; iter++) {@@ -8241,7 +8241,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, page =pfn_to_page (pfn + iter);if (PageReserved (page)) - goto unmovable; +return page;/* * If the zone is movable and we have ruled out all reserved @@ -8261,7 +8261,7 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,unsigned int skip_pages;if (!hugepage_migration_supported (page_hstate (head))) - goto unmovable; +return page; skip_pages =compound_nr (head) - (page - head); iter += skip_pages -1 ;@@ -8303,12 +8303,9 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page,* is set to both of a memory hole page and a _used_ kernel * page at boot. */ - goto unmovable; +return page; }return NULL ; -unmovable: -WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); -return pfn_to_page (pfn + iter); }#ifdef CONFIG_CONTIG_ALLOC mm/page_isolation.c +17
-13@@ -15,12 +15,12 @@#define CREATE_TRACE_POINTS #include <trace/events/page_isolation.h> -static int set_migratetype_isolate (struct page *page,int migratetype,int isol_flags) +static bool set_migratetype_isolate (struct page *page,int migratetype, +int isol_flags) { -struct page *unmovable =NULL ; +struct page *unmovable =ERR_PTR (-EBUSY );struct zone *zone;unsigned long flags; -int ret = -EBUSY ; zone =page_zone (page);@@ -49,21 +49,25 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ NULL);__mod_zone_freepage_state (zone, -nr_pages, mt); - ret =0 ; } out:spin_unlock_irqrestore (&zone->lock, flags); -if (!ret) + +if (!unmovable) {drain_all_pages (zone); -else if ((isol_flags &REPORT_FAILURE ) && unmovable) -/* -* printk() with zone->lock held will guarantee to trigger a -* lockdep splat, so defer it here. -*/ -dump_page (unmovable,"unmovable page" ); - -return ret; + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && !IS_ERR (unmovable)) +/* +* printk() with zone->lock held will likely trigger a +* lockdep splat, so defer it here. +*/ +dump_page (unmovable,"unmovable page" ); + } + +return !!unmovable; }static void unset_migratetype_isolate (struct page *page,unsigned migratetype)Signature · 1 line
2.21.0 (Apple Git-122.2)
Signature · 2 lines
Michal Hocko SUSE Labs