Commit fb4cfc6e0a465ccdeddd47567c42fbb197253aca

Authored by Xishi Qiu
Committed by Greg Kroah-Hartman
1 parent 3495017eaa

mm: fix invalid node in alloc_migrate_target()

commit 6f25a14a7053b69917e2ebea0d31dd444cd31fd5 upstream.

It is incorrect to use next_node to find a target node, it will return
MAX_NUMNODES or invalid node.  This will lead to crash in buddy system
allocation.

Fixes: c8721bbbdd36 ("mm: memory-hotplug: enable memory hotplug to handle hugepage")
Signed-off-by: Xishi Qiu <qiuxishi@huawei.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Acked-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com>
Cc: Joonsoo Kim <js1304@gmail.com>
Cc: David Rientjes <rientjes@google.com>
Cc: "Laura Abbott" <lauraa@codeaurora.org>
Cc: Hui Zhu <zhuhui@xiaomi.com>
Cc: Wang Xiaoqiang <wangxq10@lzu.edu.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 4 additions and 4 deletions Side-by-side Diff

... ... @@ -283,11 +283,11 @@
283 283 * now as a simple work-around, we use the next node for destination.
284 284 */
285 285 if (PageHuge(page)) {
286   - nodemask_t src = nodemask_of_node(page_to_nid(page));
287   - nodemask_t dst;
288   - nodes_complement(dst, src);
  286 + int node = next_online_node(page_to_nid(page));
  287 + if (node == MAX_NUMNODES)
  288 + node = first_online_node;
289 289 return alloc_huge_page_node(page_hstate(compound_head(page)),
290   - next_node(page_to_nid(page), dst));
  290 + node);
291 291 }
292 292  
293 293 if (PageHighMem(page))