From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48CEAC83013 for ; Wed, 2 Jul 2025 11:40:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB901900003; Wed, 2 Jul 2025 07:40:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D688C900002; Wed, 2 Jul 2025 07:40:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C57BC900003; Wed, 2 Jul 2025 07:40:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id AFF1A900002 for ; Wed, 2 Jul 2025 07:40:43 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2F8401401B9 for ; Wed, 2 Jul 2025 11:40:43 +0000 (UTC) X-FDA: 83619132366.05.564D7C3 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by imf11.hostedemail.com (Postfix) with ESMTP id 49C9740013 for ; Wed, 2 Jul 2025 11:40:41 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MBK1oGwT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.50 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751456441; a=rsa-sha256; cv=none; b=u/l5khRUsTWUOKY8QArRsZqNwqxQ8Jho+KiBaJjv87WN0gbRCq9HKSk/kOGDpHGCc85jUB fSPbYp1LUSmXaSfZ5WBNVOLekcH10hkd1se5le3SV4E+6a0iAAZvdQ1xTocCTLb+pTECpR 5LTqLqq1KeQoOWxwMvmt0Q6oTFi0TxE= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=MBK1oGwT; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.50 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751456441; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/Jy2XDv76GfEXHS2fhU8oEAWy8scUGa8s5bkchLIRx4=; b=fMQtPZ72VG9CoPrhvhMFOFm8vgdwN1rdHvUQNu0jWfSC6uHNbXyQvercgRByAnCtsU3zJC 1ygyOAf33Gp2IGDv8OYE/omhdEb7JE03st23vuZopE2Foa8dy681WE1ZbWm0pQZIpTxXhn AdixkKUuT6flVWIb8hUovBFAT34E5D0= Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-54b10594812so5054607e87.1 for ; Wed, 02 Jul 2025 04:40:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751456439; x=1752061239; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=/Jy2XDv76GfEXHS2fhU8oEAWy8scUGa8s5bkchLIRx4=; b=MBK1oGwTALg1WorPB34QBdi6KTiNWQjAUEvdQTITjDe/CCC7j6qoxd359wCvVudAiQ Y1QyXHbi3KOGu9Y/8FeUgYm0VQQuIWPoOOogFiA6rxW/vZB4pHB/eJ0boSGNTsKqGYX+ iLTHg6nL1i71isvbSDli0Gd1HqLB+aLtAIyhMh13TWEzmFaf8XW/O2wwqhOKJGMaG0mq ZQNkqa6x7dq0DqJrIxtboSPRwAxFbnkeoU8hh50nOnQ9t0TV2EG4WhQep9mkznZ/PZRP gCObfFipWB0g/EWIaVdfni+uWJSvcJIWCQXtJHCV8UaxuHQD1r/Uy0h0mzEBJDpX8Zu8 lSIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751456439; x=1752061239; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=/Jy2XDv76GfEXHS2fhU8oEAWy8scUGa8s5bkchLIRx4=; b=wFW3aQQAK7xyNhM/RzD7EAHWrG4tdO1spcvPdD33XJubfWUer7r2tH/ZtyfAjo0zQ/ bN0B9yzGDr3JFBRmXSAYGje3UFCmrIQqKuZGdMYbugVsfa9ga2LYAbaoO0Umwc/gEE/5 TcVkHIhyqLf3L4lahngW0Kxz2Ya/ccGYL8YZCooZqu3kgeHiv1LvDqZx3lAqv0Pw/5TL tw7cUtpq4EJAHwdUQMr9w/kAPZ5LO5I39KdkMezJ0Pr3qGBS8AxwdjjmLq3T1v+Thiz7 8pxSBQLyoShAWqj9wmh0tu6QZAfS/GakVvS/9AzSthApJs0Rr6xZ/hpfXvtbFgaEg7OA s+bw== X-Forwarded-Encrypted: i=1; AJvYcCWixAN5q89DopujS5hUosS+E/1Y6nr9tbHNQPGQcnSb0LQxdRDuXPOhshIuGXB+0eTka2BZKj7y0g==@kvack.org X-Gm-Message-State: AOJu0Yz+/0LzRZwHLu8935sLCsayj4Zgvwf1UO8IquPj5lMxt33UUjUb wCk7s/IEKYOit5GwCLYaUWWZAtB6I2ZRp+l4Gsh6TucpeDzlLbSoyr8T X-Gm-Gg: ASbGncujGCwu+2byLpCRpUNEcrsMz7LuvjFlfHbgOl8jBtA/EE8hMr0/jdCKG3da1dj BETnmRQtA/b1oSNaPF6PciNDpPjOisNQnwPoke74QQkGM+UfKUs1LPqNXllCNFIor/BwDsnzqar am2ZNu0HAtq7pA73+MoW2aDC7r6pOaIIdAMCYIp7C4f1iL/0hIiuS4W8FDNhYDl9lHapmoxyZlZ ZhoqnNR1IXwOblAxrTpnqK9gvV4Nc8TxNFTWeyT14wD58tky9CCJz3mvLcJhM2GBGLa2fzPEJyQ Oa86ZpnHpgGmo4gdkKOIq64n+LLWHSNjKRiJDgoVbV/4HBd4DDfPhGVsYddgl8ID0R4Bb7wZQ/D aPW25HF0CAqg= X-Google-Smtp-Source: AGHT+IGB8LMgoDGUxGACb96551FPJlIGGiA3rNJPCqbdbSbM0625POuaXaLxR/vzwTHli9sg34Kwiw== X-Received: by 2002:a05:6512:b0b:b0:553:350a:32d9 with SMTP id 2adb3069b0e04-55628304703mr844130e87.23.1751456438912; Wed, 02 Jul 2025 04:40:38 -0700 (PDT) Received: from pc636 (host-95-203-1-180.mobileonline.telia.com. [95.203.1.180]) by smtp.gmail.com with ESMTPSA id 38308e7fff4ca-32cd2e0d0cesm18127441fa.37.2025.07.02.04.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Jul 2025 04:40:38 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Wed, 2 Jul 2025 13:40:35 +0200 To: Jeongjun Park Cc: Uladzislau Rezki , akpm@linux-foundation.org, edumazet@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6] mm/vmalloc: fix data race in show_numa_info() Message-ID: References: <20250508165620.15321-1-aha310510@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Stat-Signature: c8m5h6jchqo3x9anugfcbswu3xs5xefz X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 49C9740013 X-Rspam-User: X-HE-Tag: 1751456441-277690 X-HE-Meta: U2FsdGVkX19cpdpJ2hBLQs+0DWT+z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vrq X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Jul 02, 2025 at 01:01:13AM +0900, Jeongjun Park wrote: > Uladzislau Rezki wrote: > > > > On Thu, May 08, 2025 at 07:48:55PM +0200, Uladzislau Rezki wrote: > > > On Fri, May 09, 2025 at 01:56:20AM +0900, Jeongjun Park wrote: > > > > The following data-race was found in show_numa_info(): > > > > > > > > ================================================================== > > > > BUG: KCSAN: data-race in vmalloc_info_show / vmalloc_info_show > > > > > > > > read to 0xffff88800971fe30 of 4 bytes by task 8289 on cpu 0: > > > > show_numa_info mm/vmalloc.c:4936 [inline] > > > > vmalloc_info_show+0x5a8/0x7e0 mm/vmalloc.c:5016 > > > > seq_read_iter+0x373/0xb40 fs/seq_file.c:230 > > > > proc_reg_read_iter+0x11e/0x170 fs/proc/inode.c:299 > > > > .... > > > > > > > > write to 0xffff88800971fe30 of 4 bytes by task 8287 on cpu 1: > > > > show_numa_info mm/vmalloc.c:4934 [inline] > > > > vmalloc_info_show+0x38f/0x7e0 mm/vmalloc.c:5016 > > > > seq_read_iter+0x373/0xb40 fs/seq_file.c:230 > > > > proc_reg_read_iter+0x11e/0x170 fs/proc/inode.c:299 > > > > .... > > > > > > > > value changed: 0x0000008f -> 0x00000000 > > > > ================================================================== > > > > > > > > According to this report,there is a read/write data-race because m->private > > > > is accessible to multiple CPUs. To fix this, instead of allocating the heap > > > > in proc_vmalloc_init() and passing the heap address to m->private, > > > > vmalloc_info_show() should allocate the heap. > > > > > > > > Fixes: a47a126ad5ea ("vmallocinfo: add NUMA information") > > > > Suggested-by: Eric Dumazet > > > > Suggested-by: Uladzislau Rezki (Sony) > > > > Suggested-by: Andrew Morton > > > > Signed-off-by: Jeongjun Park > > > > --- > > > > v6: Change CONFIG_NUMA to must be check before doing any work related to the counters array. > > > > - Link to v5: https://lore.kernel.org/all/20250508160800.12540-1-aha310510@gmail.com/ > > > > v5: Change heap to be allocated only when CONFIG_NUMA is enabled > > > > - Link to v4: https://lore.kernel.org/all/20250508065558.149091-1-aha310510@gmail.com/ > > > > v4: Change the way counters array heap is allocated, per Andrew Morton's suggestion. > > > > And fix it to call smp_rmb() in the correct location. > > > > - Link to v3: https://lore.kernel.org/all/20250507142552.9446-1-aha310510@gmail.com/ > > > > v3: Following Uladzislau Rezki's suggestion, we check v->flags beforehand > > > > to avoid printing uninitialized members of vm_struct. > > > > - Link to v2: https://lore.kernel.org/all/20250506082520.84153-1-aha310510@gmail.com/ > > > > v2: Refactoring some functions and fix patch as per Eric Dumazet suggestion > > > > - Link to v1: https://lore.kernel.org/all/20250505171948.24410-1-aha310510@gmail.com/ > > > > --- > > > > mm/vmalloc.c | 63 +++++++++++++++++++++++++++++----------------------- > > > > 1 file changed, 35 insertions(+), 28 deletions(-) > > > > > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > > index 3ed720a787ec..c1ea9713a1c0 100644 > > > > --- a/mm/vmalloc.c > > > > +++ b/mm/vmalloc.c > > > > @@ -3100,7 +3100,7 @@ static void clear_vm_uninitialized_flag(struct vm_struct *vm) > > > > /* > > > > * Before removing VM_UNINITIALIZED, > > > > * we should make sure that vm has proper values. > > > > - * Pair with smp_rmb() in show_numa_info(). > > > > + * Pair with smp_rmb() in vread_iter() and vmalloc_info_show(). > > > > */ > > > > smp_wmb(); > > > > vm->flags &= ~VM_UNINITIALIZED; > > > > @@ -4914,28 +4914,29 @@ bool vmalloc_dump_obj(void *object) > > > > #endif > > > > > > > > #ifdef CONFIG_PROC_FS > > > > -static void show_numa_info(struct seq_file *m, struct vm_struct *v) > > > > -{ > > > > - if (IS_ENABLED(CONFIG_NUMA)) { > > > > - unsigned int nr, *counters = m->private; > > > > - unsigned int step = 1U << vm_area_page_order(v); > > > > > > > > - if (!counters) > > > > - return; > > > > +/* > > > > + * Print number of pages allocated on each memory node. > > > > + * > > > > + * This function can only be called if CONFIG_NUMA is enabled > > > > + * and VM_UNINITIALIZED bit in v->flags is disabled. > > > > + */ > > > > +static void show_numa_info(struct seq_file *m, struct vm_struct *v, > > > > + unsigned int *counters) > > > > +{ > > > > + unsigned int nr; > > > > + unsigned int step = 1U << vm_area_page_order(v); > > > > > > > > - if (v->flags & VM_UNINITIALIZED) > > > > - return; > > > > - /* Pair with smp_wmb() in clear_vm_uninitialized_flag() */ > > > > - smp_rmb(); > > > > + if (!counters) > > > > + return; > > > > > > > > - memset(counters, 0, nr_node_ids * sizeof(unsigned int)); > > > > + memset(counters, 0, nr_node_ids * sizeof(unsigned int)); > > > > > > > > - for (nr = 0; nr < v->nr_pages; nr += step) > > > > - counters[page_to_nid(v->pages[nr])] += step; > > > > - for_each_node_state(nr, N_HIGH_MEMORY) > > > > - if (counters[nr]) > > > > - seq_printf(m, " N%u=%u", nr, counters[nr]); > > > > - } > > > > + for (nr = 0; nr < v->nr_pages; nr += step) > > > > + counters[page_to_nid(v->pages[nr])] += step; > > > > + for_each_node_state(nr, N_HIGH_MEMORY) > > > > + if (counters[nr]) > > > > + seq_printf(m, " N%u=%u", nr, counters[nr]); > > > > } > > > > > > > > static void show_purge_info(struct seq_file *m) > > > > @@ -4962,8 +4963,12 @@ static int vmalloc_info_show(struct seq_file *m, void *p) > > > > struct vmap_node *vn; > > > > struct vmap_area *va; > > > > struct vm_struct *v; > > > > + unsigned int *counters; > > > > int i; > > > > > > > > + if (IS_ENABLED(CONFIG_NUMA)) > > > > + counters = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL); > > > > + > > > > for (i = 0; i < nr_vmap_nodes; i++) { > > > > vn = &vmap_nodes[i]; > > > > > > > > @@ -4979,6 +4984,11 @@ static int vmalloc_info_show(struct seq_file *m, void *p) > > > > } > > > > > > > > v = va->vm; > > > > + if (v->flags & VM_UNINITIALIZED) > > > > + continue; > > > > + > > > > + /* Pair with smp_wmb() in clear_vm_uninitialized_flag() */ > > > > + smp_rmb(); > > > > > > > > seq_printf(m, "0x%pK-0x%pK %7ld", > > > > v->addr, v->addr + v->size, v->size); > > > > @@ -5013,7 +5023,9 @@ static int vmalloc_info_show(struct seq_file *m, void *p) > > > > if (is_vmalloc_addr(v->pages)) > > > > seq_puts(m, " vpages"); > > > > > > > > - show_numa_info(m, v); > > > > + if (IS_ENABLED(CONFIG_NUMA)) > > > > + show_numa_info(m, v, counters); > > > > + > > > > seq_putc(m, '\n'); > > > > } > > > > spin_unlock(&vn->busy.lock); > > > > @@ -5023,19 +5035,14 @@ static int vmalloc_info_show(struct seq_file *m, void *p) > > > > * As a final step, dump "unpurged" areas. > > > > */ > > > > show_purge_info(m); > > > > + if (IS_ENABLED(CONFIG_NUMA)) > > > > + kfree(counters); > > > > return 0; > > > > } > > > > > > > > static int __init proc_vmalloc_init(void) > > > > { > > > > - void *priv_data = NULL; > > > > - > > > > - if (IS_ENABLED(CONFIG_NUMA)) > > > > - priv_data = kmalloc(nr_node_ids * sizeof(unsigned int), GFP_KERNEL); > > > > - > > > > - proc_create_single_data("vmallocinfo", > > > > - 0400, NULL, vmalloc_info_show, priv_data); > > > > - > > > > + proc_create_single("vmallocinfo", 0400, NULL, vmalloc_info_show); > > > > return 0; > > > > } > > > > module_init(proc_vmalloc_init); > > > > -- > > > LGTM: > > > > > > Reviewed-by: "Uladzislau Rezki (Sony)" > > > > > > Thank you! > > > > > Also one thing i have just noticed. The "Fixes tag" should be updated to > > this: Fixes: 8e1d743f2c26 ("mm: vmalloc: support multiple nodes in vmallocinfo") > > > > the below one should not be blamed: > > > > Fixes: a47a126ad5ea ("vmallocinfo: add NUMA information") > > > > Thanks! > > > > -- > > Uladzislau Rezki > > I've been looking through the stable tree and it seems like this issue > still exists in the stable tree, so I think this patch needs to be > backported. > > What do you think? > If the stable does not have it, we should backport it. But it has to be done only for those where a vmap-node logic is in place. It was delivered starting from the v6.9 kernel version. -- Uladzislau Rezki