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 8A4BCC83F04 for ; Wed, 2 Jul 2025 14:01:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DD896B009B; Wed, 2 Jul 2025 10:01:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 08ED36B00D7; Wed, 2 Jul 2025 10:01:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9F1A6B009B; Wed, 2 Jul 2025 10:01:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D404B6B009B for ; Wed, 2 Jul 2025 10:01:37 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D0F54140535 for ; Wed, 2 Jul 2025 14:01:36 +0000 (UTC) X-FDA: 83619487392.04.0333A1D Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf15.hostedemail.com (Postfix) with ESMTP id CBADFA0030 for ; Wed, 2 Jul 2025 14:01:34 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TeTnJtDW; spf=pass (imf15.hostedemail.com: domain of aha310510@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=aha310510@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751464894; 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=QO1kxLEhQdwObzXYkHGYcAuf/NFzNzXCcRMRjKdSjMQ=; b=tKOi48VAfaS+U/GgsyidKs14VVxAshvcegbbZVagjgi7FffBj2IHJlj4WUz74woX5fTzDZ SNpnY7hHlRNwe+0+B5Vlfz6+NGzmMh0qKTALynvxa/ACR/Sat2Q1OGbjXrrAJJG9LnALSx AXasqVafUV50tRQrDAK8BrOrAYXQd6g= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TeTnJtDW; spf=pass (imf15.hostedemail.com: domain of aha310510@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=aha310510@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751464894; a=rsa-sha256; cv=none; b=gFd3LOMvPqqLdENq3vMJL42/s2LnsiISqkhVXfoeZ2Pe46qUWIEuhuXei3DYZjKDbLsxsb Oni35Wxa+nWD/rrtKkLFa1uXyFCFPv6NO8uWBcAkQavsbYdyyQ6s+YacmYtF3Y3MdNy0Ro zAUZ+EhhqXB+NnWPvjrMwpbLRyI+boY= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-235d6de331fso57181275ad.3 for ; Wed, 02 Jul 2025 07:01:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751464894; x=1752069694; darn=kvack.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=QO1kxLEhQdwObzXYkHGYcAuf/NFzNzXCcRMRjKdSjMQ=; b=TeTnJtDWTF6WRvtoVCjknITPNaVQg2j87/MV0AnQFc77WDV8D9hsZ5WFhqvkcRbyOs 1vNk1Tz3irsN6Hv2KBeBi/rAsBYK1WqoEFFtsUW+v0+gtB7ThQtcEcYjpAV+/fefBxhd yjhwtVG6P7ZktU8JguMgZVwa9sV+3ufsHFDrG2sugn8HP8Ft5cE+U9ilhHMApTC3ey/T T9wbEzb+n+y/ANVmKd7CRjQbGaS00EAF/Z7wFYHdCYZy5WnJ10DdM3Phik4vy6Q24i2V 9cTWP7+JtMzF8prfBv5jvCyX/roZhqyRVbSFQ1Ha2twXrYv0Aze6wFonCW5qQ5LHYW2J 1T6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751464894; x=1752069694; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=QO1kxLEhQdwObzXYkHGYcAuf/NFzNzXCcRMRjKdSjMQ=; b=o+MQKGKGUoGFfxd7NWs5EwUpDl/NLcS/iTHtOckGGVuWYL7WNacLRdTm17W7VP3y0L LOsFqg5peRLlS6N3zx8hZh0kO1FVKMxH9zKBPPu0hml+ia6GeRklJtHu9RPQYwmuqMhk oCy0daLOd1R76KkSepisrenkvYrzD0Rv3gGzJCLkDST2NOs+Avnfcc+jr32YJx/56DhL HHzN6SAr8zCDNVJaQDsuJiCwdo2mGMQ0qq4ptzROehbaSC8og8/HyP9pZg8HLppa3VIa /3UeTTrwvaaEuGUgt/RBN1vZinl6S7M6LJK/tZEziMroSJKdo5bW+pXjcQOxS0Q/2Y1B JQeg== X-Forwarded-Encrypted: i=1; AJvYcCUkpyLdsiGA3zRkL2dEpCHL3XciCT3dLCGatQKevc8ZjA38Agkj5Vi/TE8/vnYsmq/djbgiY7rFHA==@kvack.org X-Gm-Message-State: AOJu0Yz1OEW5G5t8vEPz3iHrX47htfGufKSGe/FnPFMz3ja2xgXvULjq CSP4DrFda87wnG0DLg+LgDXdb8TTRd5qGID79UmY6/2rAFvJeiD4hUPlwoI3WCEA0dvZDBrXQrj 4jjrpHr0z8xlSj2ikjY5S9fljh6F4L8w= X-Gm-Gg: ASbGnctkd+oq73DQEeDw6K15DFT2StJtJeCQQvjiq7T0Mis9iDzAYC7c4svdZ1yq1xO AsdAcNG4KtjlgvRK/e+ejPPwX3r464JTvLFVrMYmXRNhponMcUmm54P3AmYCBcRKO3mgX3Bbl4p EvjugJRue/Nf9q6YSTE48WUB8zT2o4NiQX4cpB856ItaPruQ== X-Google-Smtp-Source: AGHT+IGIG8c+lqWMr2WK3XUTrLfH1GKp+/JJ5CUz0C5+T1dHqbAdNzFKJ/rUgpyFphCq9obTJJfKQ426CCV4bniHh+c= X-Received: by 2002:a17:90b:2703:b0:311:ffe8:20e6 with SMTP id 98e67ed59e1d1-31a90b1a2c3mr4335825a91.3.1751464891509; Wed, 02 Jul 2025 07:01:31 -0700 (PDT) MIME-Version: 1.0 References: <20250508165620.15321-1-aha310510@gmail.com> In-Reply-To: From: Jeongjun Park Date: Wed, 2 Jul 2025 23:01:23 +0900 X-Gm-Features: Ac12FXytpEGD61xI4gVjPopOBnQBPCerPdInR-Lnu5k7RupgGAgjAz_65MrIBXQ Message-ID: Subject: Re: [PATCH v6] mm/vmalloc: fix data race in show_numa_info() To: Uladzislau Rezki Cc: akpm@linux-foundation.org, edumazet@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: CBADFA0030 X-Stat-Signature: zxin788ydmg7u6yc448hrb9mmm7ewbe8 X-HE-Tag: 1751464894-63567 X-HE-Meta: U2FsdGVkX1/PE7JcMBk1oDexMmNM9TvQ4Pg4u+fdlO4EVbci9tpqOky/GKp8W+jNkFJfqY2kqzD87mJtkPsItq0UWnkDhG+u5W6m0IyYD6xBWkuVXWZdvnGhRoliS0xBq++RQ1O9Wv2ZF/2EWCrjcl4ApP0Dc9MLkVjb+fmoYNC/mnenYyo+4L5FxoXOEQQLAwZjDzWNdzoAgFiMFsoFz1Kcey/iiKmRGaYzv+LB2fJQvenn6giIajdcYKvX65qPAiiZ0pIc85+v8yJhxglKr4Q7EvBuIgzw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DBEyvARqtnSLs+gYJACHZjg74WQJLBDx7iMGzxvU++PweH8vOBHfKrNeHJSg/mVX7b/E5fex/sgI9PCrPpqgMA7J2RGVVt5VC5VkCoCK5s54R0L6585x5ZurrgUjEw4fHEA1A043l1MdaFyWgaG+J0fvVx8JD/82Fuz8wOzJyzElw== 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: Uladzislau Rezki wrote: > > 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. > Then I guess I should backport to 6.12, 6.15. Thanks for letting me know! Regards, Jeongjun Park