]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
mm/migration: fix potential invalid node access for reclaim-based migration
authorMiaohe Lin <linmiaohe@huawei.com>
Fri, 29 Apr 2022 06:16:08 +0000 (23:16 -0700)
committerakpm <akpm@linux-foundation.org>
Fri, 29 Apr 2022 06:16:08 +0000 (23:16 -0700)
If we failed to setup hotplug state callbacks for mm/demotion:online in
some corner cases, node_demotion will be left uninitialized.  Invalid node
might be returned from the next_demotion_node() when doing reclaim-based
migration.  Use kcalloc to allocate node_demotion to fix the issue.

Link: https://lkml.kernel.org/r/20220318111709.60311-11-linmiaohe@huawei.com
Fixes: ac16ec835314 ("mm: migrate: support multiple target nodes demotion")
Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
Reviewed-by: "Huang, Ying" <ying.huang@intel.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Muchun Song <songmuchun@bytedance.com>
Cc: Zi Yan <ziy@nvidia.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/migrate.c

index 173ba05070497112be623a80de786ea7c82e185c..cb3fa7c24081388e3ab777e5ad7651fd8159a9c6 100644 (file)
@@ -2479,9 +2479,9 @@ static int __meminit migrate_on_reclaim_callback(struct notifier_block *self,
 
 void __init migrate_on_reclaim_init(void)
 {
-       node_demotion = kmalloc_array(nr_node_ids,
-                                     sizeof(struct demotion_nodes),
-                                     GFP_KERNEL);
+       node_demotion = kcalloc(nr_node_ids,
+                               sizeof(struct demotion_nodes),
+                               GFP_KERNEL);
        WARN_ON(!node_demotion);
 
        hotplug_memory_notifier(migrate_on_reclaim_callback, 100);