From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (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 11BBB37472A for ; Thu, 2 Apr 2026 07:37:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775115477; cv=none; b=tsQUd70HJS3nXs/iaiVThviIn+4GCQed7ENkzPqwP25joFRj900bsGndGwXUbWjxv5CEx2rMP7IlQplFivla2DGEiwLyeTxxOfvzcyI2tfr3OnOG++TpQZiDkvUbkmq19zvxPxehpel5FcnScJTntmTN9GFkxhCx2ZIIvcCyvFk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775115477; c=relaxed/simple; bh=y1xpi9A5CGY7LojjPktQD4JbsPsNwBQZ+MS/XO3FHsQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=VM01JzQaq5YCMKCCw7hHjGCIg3hL7MC/ufyYK/ZR9bTSzPfC9bc86QBHkgajoGkVo62wc0hAUMLsIy35M3TnBYY3epHJDcps5vHm8UQQthKqRAykr8OWHzovb7RgFEYtRm/Z8nazllAoehZAr8blDo41deJQmVJE3nMEGJrLvy8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=U9da5meo; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="U9da5meo" Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6320NBqH314183; Thu, 2 Apr 2026 07:37:35 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=phJ01w 2m6VFY3xoBmiLavGXCKH3byF8C6J8VTpkH1eI=; b=U9da5meobGMO2MgtRrZ+fr yOExv4ksO+a2ib8xR1tp7Uqbtb99JTItCCS0ISQOxDT/3Ixx7z9c3U9mbJmvSsbi y1OhxXtUjjCic6vFNweP7dWkzE83Yu4OG6ipmjmzoLzmT+dPmLShefleRXwOvTYA TZ0DgP4QuPxQcfAWm9aEL3PEh29AOHChtPjK6PZezDDQyndqRIj1NOR3gZN8eAPB 17Pu5SHQJUBzOTSdQbaw4+KXdHVbm1CUCbhuTJMaY7Fw3K/VYDCRka1rPEMgqbDq V3H1saB/ULTFmtDOOxw3ws3dZnSEsUiVlla9WOUvX/dhm6yNLuvMR0t/4Vark58g == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4d64dgu3be-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Apr 2026 07:37:35 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 6321iuXG008698; Thu, 2 Apr 2026 07:37:34 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4d6v11rwn6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 02 Apr 2026 07:37:34 +0000 Received: from smtpav01.dal12v.mail.ibm.com (smtpav01.dal12v.mail.ibm.com [10.241.53.100]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6327bXAT6226632 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 2 Apr 2026 07:37:34 GMT Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E181D58058; Thu, 2 Apr 2026 07:37:33 +0000 (GMT) Received: from smtpav01.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5029958057; Thu, 2 Apr 2026 07:37:29 +0000 (GMT) Received: from [9.39.16.6] (unknown [9.39.16.6]) by smtpav01.dal12v.mail.ibm.com (Postfix) with ESMTP; Thu, 2 Apr 2026 07:37:29 +0000 (GMT) Message-ID: <3ab0e5dd-cd3d-4f78-a7ee-01051f200b36@linux.ibm.com> Date: Thu, 2 Apr 2026 13:07:27 +0530 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/sparse: fix preinited section_mem_map clobbering on failure path To: "David Hildenbrand (Arm)" , Muchun Song 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 References: <20260331113724.2080833-1-songmuchun@bytedance.com> <17246161-f314-45da-933a-770231ef2a49@kernel.org> <2183487D-0CED-4BEF-84D7-4439F3386584@linux.dev> Content-Language: en-US From: Donet Tom In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwNDAyMDA2MyBTYWx0ZWRfXyNHigohVT/NE jvydsk/Q2BNTNFCoiMJdue/G6An4WhO/mRYZVMdEtXHnrIILchW0gh5L8QbZwEeI63RACYM6vS8 B4OyKwEB7IqmTqaW5XBvcB1OKDubtJLsCVRORESdlJZIVX1LvJUF3IuhwAkON3GUv/HTHMNey+H 6ofyBr7SysXPQ2uTuJStZsHIe5AsQSL5LbXD8uKyy7l1zoVYhrtmev0JVXfEX506KxCy8/zhA3U 6jsmClxzdlGP0lZDk5geCKLmxs3JVsa3u7Hs4XOYXNHKTzC6zYtntLjXFNcjU3IRXiHexf6BNYn qpVDziy/plfyIoy3aJ9ILIhw1rcUVwpzOBqC69z0uxS/v6VSFiNsUTlvXVRrCFqImz1rEz8zoPF 71lorC25ZXmSSjOveujox1Rq94YE90vn15Sx5yri+hWRRS5QwGxsKXetflzYqBY22SZq5A+6KfP 8m6tGAAy9Z3G3AxI/cA== X-Authority-Analysis: v=2.4 cv=QKZlhwLL c=1 sm=1 tr=0 ts=69ce1cbf cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=Y2IxJ9c9Rs8Kov3niI8_:22 a=VwQbUJbxAAAA:8 a=968KyxNXAAAA:8 a=LABA4A6g8ucfnDsEYEMA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 X-Proofpoint-GUID: m9KsDZjHJTwdLY4j3iWQAvKm7OWMyiRv X-Proofpoint-ORIG-GUID: m5QEaLQA9cH8fdoYAzD5PlSY6_fDZ894 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1143,Hydra:6.1.51,FMLib:17.12.100.49 definitions=2026-04-02_01,2026-04-02_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 adultscore=0 impostorscore=0 clxscore=1015 spamscore=0 bulkscore=0 priorityscore=1501 suspectscore=0 malwarescore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2603050001 definitions=main-2604020063 On 4/1/26 12:55 PM, David Hildenbrand (Arm) wrote: > On 4/1/26 04:41, Muchun Song wrote: >> >>> On Apr 1, 2026, at 04:42, David Hildenbrand (Arm) wrote: >>> >>> 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: >>>> >>>> if (!preinited_vmemmap_section(ms)) >>>> ms->section_mem_map = 0; >>>> >>>> A leftover line after that conditional block >>>> >>>> ms->section_mem_map = 0; >>>> >>>> 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. >>>> >>>> Drop the stray assignment so that preinited sections retain their >>>> already valid state. >>>> >>>> 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(-) >>>> >>>> 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 = __nr_to_section(pnum); >>>> if (!preinited_vmemmap_section(ms)) >>>> ms->section_mem_map = 0; >>>> - ms->section_mem_map = 0; >>> >>> Acked-by: David Hildenbrand (Arm) >> Thanks. >> >>> 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. >> It's truly a coincidence — 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. > Don't use BUG_ON, use actual panic(). :) Apologies if I’m missing something, but would it make sense to check the section validity in memmap_init() instead of panicking? Is there a reason this is avoided? -Donet > > And yes, we should rip out that handling. >