From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 17BC338B146 for ; Wed, 1 Apr 2026 07:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028523; cv=none; b=nBDWCuucuFQoKxHJgtbl8L+yMjB+Tjd+bsw3RUOm3s4ZkFLCKOomFkueQhAFR9VeVDg4nQKqmZihVGJwTDz/WGZdRm95NZ32OiU+GyfthtgWGU1pNO9kiDTLUdScFNQ8yxcrQ59Jr/jj5pg0abhA1Vh2ryZ3VWfIVROLJqtTdfc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775028523; c=relaxed/simple; bh=6cNlxYVyE+wqNsWCro1ARl2SpdIG8URpFkryj4IVUEg=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=X0+1UIkNK463amdrsyZZQuBGqH6YX3bKWKUBUFGncU0FdsOqFVcPlZnzFASuafc7HYMkLLFkKDksFjHm0dnazoPz+6bG+12fJBq+hkts0N+pKkxHFLZs/Pwsjp9CFWlE2WEWQoMYro9+zM9ShOeEarzYBrVXHZfhgXVmGQ4KW7U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=ekLZuRfv; arc=none smtp.client-ip=91.218.175.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="ekLZuRfv" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1775028520; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=E65Yz/rtARK/BoOkD3xuTZ60cfg1ITmPfEUtw4OR+xc=; b=ekLZuRfvTNCtpFghyWNvQkF0dw/QlHQ/4NJCHKaG2saoB/wne2gQkqdXXi4U8SbNw3lEk7 VcVen11Op8JslhT3MdPKrTobHFwtQRIQwyvscqZVHbDyPF22VMO0ZCk+7ITCoYkfaR8J3r OovXcG1rn4TEzAYcC0TMMGwRm8ak4CY= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.400.21\)) Subject: Re: [PATCH] mm/sparse: fix preinited section_mem_map clobbering on failure path X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: Date: Wed, 1 Apr 2026 15:28:02 +0800 Cc: Muchun Song , Andrew Morton , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Frank van der Linden , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <462D1EBC-22B7-4527-B725-6DED308D428E@linux.dev> References: <20260331113724.2080833-1-songmuchun@bytedance.com> <17246161-f314-45da-933a-770231ef2a49@kernel.org> <2183487D-0CED-4BEF-84D7-4439F3386584@linux.dev> To: "David Hildenbrand (Arm)" X-Migadu-Flow: FLOW_OUT > On Apr 1, 2026, at 15:25, David Hildenbrand (Arm) = wrote: >=20 > On 4/1/26 04:41, Muchun Song wrote: >>=20 >>=20 >>> On Apr 1, 2026, at 04:42, David Hildenbrand (Arm) = wrote: >>>=20 >>> On 3/31/26 13:37, Muchun Song wrote: >>>> sparse_init_nid() is careful to leave alone every section whose = vmemmap >>>> has already been set up by sparse_vmemmap_init_nid_early(); it only >>>> clears section_mem_map for the rest: >>>>=20 >>>> if (!preinited_vmemmap_section(ms)) >>>> ms->section_mem_map =3D 0; >>>>=20 >>>> A leftover line after that conditional block >>>>=20 >>>> ms->section_mem_map =3D 0; >>>>=20 >>>> was supposed to be deleted but was missed in the failure path, = causing the >>>> field to be overwritten for all sections when memory allocation = fails, >>>> effectively destroying the pre-initialization check. >>>>=20 >>>> Drop the stray assignment so that preinited sections retain their >>>> already valid state. >>>>=20 >>>> Fixes: d65917c42373 ("mm/sparse: allow for alternate vmemmap = section init at boot") >>>> Signed-off-by: Muchun Song >>>> --- >>>> mm/sparse.c | 1 - >>>> 1 file changed, 1 deletion(-) >>>>=20 >>>> diff --git a/mm/sparse.c b/mm/sparse.c >>>> index c2eb36bfb86d..3a14b733bf71 100644 >>>> --- a/mm/sparse.c >>>> +++ b/mm/sparse.c >>>> @@ -584,7 +584,6 @@ static void __init sparse_init_nid(int nid, = unsigned long pnum_begin, >>>> ms =3D __nr_to_section(pnum); >>>> if (!preinited_vmemmap_section(ms)) >>>> ms->section_mem_map =3D 0; >>>> - ms->section_mem_map =3D 0; >>>=20 >>>=20 >>> Acked-by: David Hildenbrand (Arm) >>=20 >> Thanks. >>=20 >>>=20 >>> I have some cleanup patches lying around that cleanup that code = heavily. >>> I think I get rid of this questionable "failed to allocate" case = entirely. >>=20 >> It's truly a coincidence =E2=80=94 I also have a piece of code = locally >> that does something similar. Since allocation failure would also >> affect subsequent startup processes, I simply made it panic when >> allocation fails. >=20 > Don't use BUG_ON, use actual panic(). :) Got it. >=20 > And yes, we should rip out that handling. Agree. >=20 > --=20 > Cheers, >=20 > David