Re: [PATCH 1/4] mm: Check for node_online in node_present_pages
* Srikar Dronamraju [2020-03-17 18:47:50]: > > Reported-by: Sachin Sant > Tested-by: Sachin Sant > Signed-off-by: Srikar Dronamraju > --- > include/linux/mmzone.h | 6 -- > 1 file changed, 4 insertions(+), 2 deletions(-) > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index f3f264826423..88078a3b95e5 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -756,8 +756,10 @@ typedef struct pglist_data { > atomic_long_t vm_stat[NR_VM_NODE_STAT_ITEMS]; > } pg_data_t; > > -#define node_present_pages(nid) (NODE_DATA(nid)->node_present_pages) > -#define node_spanned_pages(nid) (NODE_DATA(nid)->node_spanned_pages) > +#define node_present_pages(nid) \ > + (node_online(nid) ? NODE_DATA(nid)->node_present_pages : 0) > +#define node_spanned_pages(nid) \ > + (node_online(nid) ? NODE_DATA(nid)->node_spanned_pages : 0) > #ifdef CONFIG_FLAT_NODE_MEM_MAP > #define pgdat_page_nr(pgdat, pagenr) ((pgdat)->node_mem_map + (pagenr)) > #else If we indeed start having pgdat/NODE_DATA for even offline nodes as Michal Hocko, then we may not this particular patch. -- Thanks and Regards Srikar Dronamraju
[PATCH 1/4] mm: Check for node_online in node_present_pages
Calling a kmalloc_node on a possible node which is not yet onlined can lead to panic. Currently node_present_pages() doesn't verify the node is online before accessing the pgdat for the node. However pgdat struct may not be available resulting in a crash. NIP [c03d55f4] ___slab_alloc+0x1f4/0x760 LR [c03d5b94] __slab_alloc+0x34/0x60 Call Trace: [c008b3783960] [c03d5734] ___slab_alloc+0x334/0x760 (unreliable) [c008b3783a40] [c03d5b94] __slab_alloc+0x34/0x60 [c008b3783a70] [c03d6fa0] __kmalloc_node+0x110/0x490 [c008b3783af0] [c03443d8] kvmalloc_node+0x58/0x110 [c008b3783b30] [c03fee38] mem_cgroup_css_online+0x108/0x270 [c008b3783b90] [c0235aa8] online_css+0x48/0xd0 [c008b3783bc0] [c023eaec] cgroup_apply_control_enable+0x2ec/0x4d0 [c008b3783ca0] [c0242318] cgroup_mkdir+0x228/0x5f0 [c008b3783d10] [c051e170] kernfs_iop_mkdir+0x90/0xf0 [c008b3783d50] [c043dc00] vfs_mkdir+0x110/0x230 [c008b3783da0] [c0441c90] do_mkdirat+0xb0/0x1a0 [c008b3783e20] [c000b278] system_call+0x5c/0x68 Fix this by verifying the node is online before accessing the pgdat structure. Fix the same for node_spanned_pages() too. Cc: Andrew Morton Cc: linux...@kvack.org Cc: Mel Gorman Cc: Michael Ellerman Cc: Sachin Sant Cc: Michal Hocko Cc: Christopher Lameter Cc: linuxppc-dev@lists.ozlabs.org Cc: Joonsoo Kim Cc: Kirill Tkhai Cc: Vlastimil Babka Cc: Srikar Dronamraju Cc: Bharata B Rao Reported-by: Sachin Sant Tested-by: Sachin Sant Signed-off-by: Srikar Dronamraju --- include/linux/mmzone.h | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index f3f264826423..88078a3b95e5 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -756,8 +756,10 @@ typedef struct pglist_data { atomic_long_t vm_stat[NR_VM_NODE_STAT_ITEMS]; } pg_data_t; -#define node_present_pages(nid)(NODE_DATA(nid)->node_present_pages) -#define node_spanned_pages(nid)(NODE_DATA(nid)->node_spanned_pages) +#define node_present_pages(nid)\ + (node_online(nid) ? NODE_DATA(nid)->node_present_pages : 0) +#define node_spanned_pages(nid)\ + (node_online(nid) ? NODE_DATA(nid)->node_spanned_pages : 0) #ifdef CONFIG_FLAT_NODE_MEM_MAP #define pgdat_page_nr(pgdat, pagenr) ((pgdat)->node_mem_map + (pagenr)) #else -- 2.18.1