mm/page_isolation: fix potential warning from user
Subsystems (2)
PATCH v3 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 crash the system by a non-root user if warn_on_panic is set.
While at it, simplify the code a bit by removing an unnecessary jump label.
---
v3: Drop the page_isolation.c cleanup change.
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 | 18 +++++++++++------- 2 files changed, 15 insertions(+), 14 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 +11 -7
@@ -54,14 +54,18 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ out:spin_unlock_irqrestore (&zone->lock, flags); -if (!ret) +if (!ret) {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" ); + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && unmovable) +/* +* printk() with zone->lock held will likely trigger a +* lockdep splat, so defer it here. +*/ +dump_page (unmovable,"unmovable page" ); + }return ret; }
Signature · 1 line
2.21.0 (Apple Git-122.2)
Quoted 86 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 crash the system by a non-root user ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label.
Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>---
v3: Drop the
page_isolation.ccleanup change.
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.mm/page_alloc.c | 11 ++++------- mm/page_isolation.c | 18 +++++++++++------- 2 files changed, 15 insertions(+), 14 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 +4
-7@@ -54,14 +54,18 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ out:spin_unlock_irqrestore (&zone->lock, flags); -if (!ret) +if (!ret) {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" ); + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); +
mm/page_isolation.c static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ · line 71
Quoted 10 lines
mm/page_isolation.c +7
-0+if ((isol_flags &REPORT_FAILURE ) && unmovable) +/* +* printk() with zone->lock held will likely trigger a +* lockdep splat, so defer it here. +*/ +dump_page (unmovable,"unmovable page" ); + }return ret; }
Thanks!
Signature · 3 lines
Thanks, David / dhildenb
Quoted 10 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 crash the system by a non-root user ifwarn_on_panicis set.While at it, simplify the code a bit by removing an unnecessary jump label.
Suggested-by Michal Hocko <[email protected]>Signed-off-by Qian Cai <[email protected]>
Thanks!
Quoted 87 lines
---
v3: Drop the
page_isolation.ccleanup change.
v2: Improve the commit log.
Warn for allstart_isolate_page_range()users not just offlining.mm/page_alloc.c | 11 ++++------- mm/page_isolation.c | 18 +++++++++++------- 2 files changed, 15 insertions(+), 14 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 +11
-7@@ -54,14 +54,18 @@ static int set_migratetype_isolate(struct page *page, int migratetype, int isol_ out:spin_unlock_irqrestore (&zone->lock, flags); -if (!ret) +if (!ret) {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" ); + }else { +WARN_ON_ONCE (zone_idx (zone) ==ZONE_MOVABLE ); + +if ((isol_flags &REPORT_FAILURE ) && unmovable) +/* +* printk() with zone->lock held will likely trigger a +* lockdep splat, so defer it here. +*/ +dump_page (unmovable,"unmovable page" ); + }return ret; }Signature · 1 line
2.21.0 (Apple Git-122.2)
Signature · 2 lines
Michal Hocko SUSE Labs