From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 92F343EAC71 for ; Tue, 25 Aug 2026 09:35:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787650560; cv=none; b=Y6ezO/Xm4TF04P2w2OfYCBAZk4LJlLLEfN0odxDJgHEuWAXOdpG5nKPggAW+kXOrEzDlrfpIQdGlDziz/kWo9IzWo2hsxUlCyNTJRpK0IQffVeEDBfde8HyuRGpeThYl4lqo503994H3vQ6pukhbj+8a2AaGI0Mx6UD4i5kmcfo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787650560; c=relaxed/simple; bh=bF7+xmYUxjTiUWk5K63jTeMIjjrTEbgWRnT0nW+jFXA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zhv2RYOBd/OlHDkvT6Hz45NeDbLLYC1+gIwvx/0B9TTEjZu8SC6Uxp6uaKrKMuMGAv+MNHCVJRIhltw5uAyHxUlQNZPnXsn6T6AXt++N8//TMtebnXGVCOjdEC/qJ/dRNEU6j0rpF/FyvyXajPpUjr0x8QB/5fiXK0qPIx0Iunc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=CIjPpooc; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="CIjPpooc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 024351F000E9; Tue, 25 Aug 2026 09:35:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1787650559; bh=4jNx1gJfEgzXmkghh2FSeff6tzhWpWsHsfiEs8SThuY=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=CIjPpooc2Xah/nDriAfbFpP3Q84yeu3cwQdifVSKgCJWQfQPOz1TPxEX/KsFtTSo8 NUJk3GV5+czQRWM/srwmKU3KOqZj6mvuAqP9UFu3bycSQgLrlkhKRuV/oB9LFHjTfe /WFja8R751+b4m8S3aPE7UzrxbqvxogZr7QNMHtkd2KMny3h0p6kOwsUA/dI95stF8 RQ+rP/MlSzQ+IH+35c8l5lhJ6B4VW+TL3Hbgqq0mguQy6ldnwRr8qXa8UHY2ZBFSlh 3oVokJLPQ2TbJJsR9Fh35bVkzO+nIz0Ed9ldrda7GOYPRBF2CgDYx9VHs/aVhQeQzg MpUjUM1GbLmIw== Date: Tue, 25 Aug 2026 12:35:53 +0300 From: Mike Rapoport To: Meijing Zhao Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Wandun Chen , Meijing Zhao Subject: Re: [PATCH v2 RESEND 3/3] mm: memblock: synchronize debugfs reads with memory hotplug Message-ID: References: <20260821020910.3428585-1-zhaomeijing100@gmail.com> <20260821020910.3428585-4-zhaomeijing100@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260821020910.3428585-4-zhaomeijing100@gmail.com> Hi, On Fri, Aug 21, 2026 at 10:09:10AM +0800, Meijing Zhao wrote: > From: Meijing Zhao > > memblock_debug_show() walks a memblock region array without > synchronization. With CONFIG_ARCH_KEEP_MEMBLOCK, memory hotplug can > concurrently add a region. If the array has to grow, > memblock_double_array() replaces type->regions and frees the old > allocation while the debugfs reader may still be using it. > > Hold mem_hotplug_lock in read mode while producing the debugfs output. > Memory hotplug updates already hold the write side of this lock, so the > region array remains stable throughout the walk. The helpers are no-ops > when CONFIG_MEMORY_HOTPLUG is disabled. Hmm, I'm not sure it's the right lock to take here. With MEMORY_HOTPLUG and ARCH_KEEP_MEMBLOCK there potentially other races in memblock and we'd better to design proper locking for them. > Fixes: f9126ab9241f ("memory-hotplug: fix wrong edge when hot add a new node") > Signed-off-by: Meijing Zhao > --- > mm/memblock.c | 3 +++ > 1 file changed, 3 insertions(+) > > diff --git a/mm/memblock.c b/mm/memblock.c > index 36a8d2a9378d..f1ddbcce47ac 100644 > --- a/mm/memblock.c > +++ b/mm/memblock.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -2899,6 +2900,7 @@ static int memblock_debug_show(struct seq_file *m, void *private) > phys_addr_t end; > bool first; > > + get_online_mems(); > for (i = 0; i < type->cnt; i++) { > reg = &type->regions[i]; > end = reg->base + reg->size - 1; > @@ -2927,6 +2929,7 @@ static int memblock_debug_show(struct seq_file *m, void *private) > seq_puts(m, "NONE\n"); > } > } > + put_online_mems(); > return 0; > } > DEFINE_SHOW_ATTRIBUTE(memblock_debug); > -- > 2.25.1 > -- Sincerely yours, Mike.