Skip to content

Commit

Permalink
mm/memory_hotplug: enforce section granularity when onlining/offlining
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
davidhildenbrand authored and torvalds committed Oct 16, 2020
1 parent 73a11c9 commit 4986fac
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions mm/memory_hotplug.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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();

/*
Expand Down

0 comments on commit 4986fac

Please sign in to comment.