diff options
author | David Hildenbrand <[email protected]> | 2020-10-15 20:07:50 -0700 |
---|---|---|
committer | Linus Torvalds <[email protected]> | 2020-10-16 11:11:17 -0700 |
commit | 4986fac160b3eb1432ca9970d51c55f4f93b1a2e (patch) | |
tree | edc817dfa2e5e1a80a01da67dd1e2c8a08989e06 | |
parent | 73a11c9658577d876d4c70730719feab3fa328b0 (diff) |
mm/memory_hotplug: enforce section granularity when onlining/offlining
Already two people (including me) tried to offline subsections, because
the function looks like it can deal with it. But we really can only
online/offline full sections that are properly aligned (e.g., we can only
mark full sections online/offline via SECTION_IS_ONLINE).
Add a simple safety net to document the restriction now. Current users
(core and powernv/memtrace) respect these restrictions.
Signed-off-by: David Hildenbrand <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Reviewed-by: Oscar Salvador <[email protected]>
Acked-by: Michal Hocko <[email protected]>
Cc: Wei Yang <[email protected]>
Cc: Baoquan He <[email protected]>
Cc: Pankaj Gupta <[email protected]>
Cc: Charan Teja Reddy <[email protected]>
Cc: Dan Williams <[email protected]>
Cc: Fenghua Yu <[email protected]>
Cc: Logan Gunthorpe <[email protected]>
Cc: "Matthew Wilcox (Oracle)" <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Mel Gorman <[email protected]>
Cc: Michel Lespinasse <[email protected]>
Cc: Mike Rapoport <[email protected]>
Cc: Tony Luck <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
Signed-off-by: Linus Torvalds <[email protected]>
-rw-r--r-- | mm/memory_hotplug.c | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index ba201ab4c0e4..03a8825c5620 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -809,6 +809,11 @@ int __ref online_pages(unsigned long pfn, unsigned long nr_pages, int ret; struct memory_notify arg; + /* We can only online full sections (e.g., SECTION_IS_ONLINE) */ + if (WARN_ON_ONCE(!nr_pages || + !IS_ALIGNED(pfn | nr_pages, PAGES_PER_SECTION))) + return -EINVAL; + mem_hotplug_begin(); /* associate pfn range with the zone */ @@ -1494,6 +1499,11 @@ int __ref offline_pages(unsigned long start_pfn, unsigned long nr_pages) struct memory_notify arg; char *reason; + /* We can only offline full sections (e.g., SECTION_IS_ONLINE) */ + if (WARN_ON_ONCE(!nr_pages || + !IS_ALIGNED(start_pfn | nr_pages, PAGES_PER_SECTION))) + return -EINVAL; + mem_hotplug_begin(); /* |