From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 136393FB05A for ; Thu, 30 Apr 2026 07:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777535996; cv=none; b=CrOv7z7NUYXHZIlFunDOdHCpjHObnVqu1rbykbCU6kNxqu7V2S93qT02leMAJ8zKGNQh8MUzH3bDuiOkaVdDr82rRwEPCuHfzGZ9StITSgb4LwRdKu7CxUBzMbeoYSlaKmQhHEQizUdSftyh4iqYHV8i6SRP/OU2psByOpnQiHE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777535996; c=relaxed/simple; bh=RlgmLDmovw9KydWIeUdHmFKeIsmjH23V0zBe8kpL4Cs=; h=MIME-Version:Date:From:To:Cc:Message-Id:In-Reply-To:References: Subject:Content-Type; b=WF9qW4a7CKgjY5bSdrSRWJVXIbqL+SCleyInyz0sStMmamHVYevqu+vsbJzi017qzfTFia1Xi1BccLxE5EjDWFt7DMuBBvdm4On8TGp7hbts6kPPZpLbf/oCwd7+Vi6Smxu4K+DO1WiUI8pkZaKHNmUDCRBKIOv95qLVvVejNW8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aAqyg273; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aAqyg273" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75635C2BCC7; Thu, 30 Apr 2026 07:59:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777535995; bh=RlgmLDmovw9KydWIeUdHmFKeIsmjH23V0zBe8kpL4Cs=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From; b=aAqyg273PDpc50LZvPBeOR6rSZUHFFZbAbyQJ2Pc6RXtFo2c1GeMvBU3jLUw4TYVK uoJkGWEgBgAEgv8q3hHisg5NCoPHTs68u4w5SA831Utd46l0tm51f2dq8gpJyCocUo 0vyWDpVrzfhc0dNtP4GcWzOoOszX+mS/Ed2oCjvVgpxSus6gFof2LjkShhGFq+I15n OCyz9EDzu4ve0KwvxWcJ5fEHNMUskZhlSTKYyCSUonlFVrWPlSA0tIFgrC72u+i3tj chCIxFGXk5SeqBr/IXZaE9nQ7DlK6LSGTY1+8A45Abqg/Fr3H/RJ7cS17HdMtpYb8B hEremIhSdxOqw== Received: from phl-compute-01.internal (phl-compute-01.internal [10.202.2.41]) by mailfauth.phl.internal (Postfix) with ESMTP id 877ADF40075; Thu, 30 Apr 2026 03:59:54 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-01.internal (MEProxy); Thu, 30 Apr 2026 03:59:54 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdekieejkecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvvefkjghfufgtgfesthhqredtredtjeenucfhrhhomhepfdetrhguuceu ihgvshhhvghuvhgvlhdfuceorghruggssehkvghrnhgvlhdrohhrgheqnecuggftrfgrth htvghrnhepueetieduieegkeejvdehudeiheettefgtdeugffhjefghfeftdelhedvheff hfdvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hrugdomhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqudeijedthedttdejledq feefvdduieegudehqdgrrhgusgeppehkvghrnhgvlhdrohhrghesfihorhhkohhfrghrug drtghomhdpnhgspghrtghpthhtohepjedpmhhouggvpehsmhhtphhouhhtpdhrtghpthht oheptggrthgrlhhinhdrmhgrrhhinhgrshesrghrmhdrtghomhdprhgtphhtthhopehhuh grnhhgiihhrghohigrnhhgsehgmhgrihhlrdgtohhmpdhrtghpthhtohepfihilhhlsehk vghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdgrrhhmqdhkvghrnhgvlheslh hishhtshdrihhnfhhrrgguvggrugdrohhrghdprhgtphhtthhopehsthgvvhgvrdhkrghn ghesuhhnihhsohgtrdgtohhmpdhrtghpthhtohepiihhrghohigrnhhgrdhhuhgrnhhgse hunhhishhotgdrtghomhdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghr rdhkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: ice86485a:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 698FF700065; Thu, 30 Apr 2026 03:59:54 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 30 Apr 2026 09:59:28 +0200 From: "Ard Biesheuvel" To: "Zhaoyang Huang" Cc: "zhaoyang.huang" , "Catalin Marinas" , "Will Deacon" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, steve.kang@unisoc.com Message-Id: In-Reply-To: References: <20260429061752.2880923-1-zhaoyang.huang@unisoc.com> <8fcde357-aaa1-4bd2-a8b3-d660b94a38c6@app.fastmail.com> Subject: Re: [PATCH] arch: arm64: fix KERNEL_SEGMENT_COUNT error Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Thu, 30 Apr 2026, at 03:56, Zhaoyang Huang wrote: > On Thu, Apr 30, 2026 at 9:29=E2=80=AFAM Zhaoyang Huang wrote: >> >> On Wed, Apr 29, 2026 at 5:28=E2=80=AFPM Ard Biesheuvel wrote: >> > >> > Hello Zhaoyang, >> > >> > On Wed, 29 Apr 2026, at 08:17, zhaoyang.huang wrote: >> > > From: Zhaoyang Huang >> > > >> > > During debug of a kernel panic, we find that the pte_t of the fin= al >> > > part of [data, end] segment got overflow to the next page of >> > > init_pg_end[1] which is the gap page before early_init_stack[2]. >> > > This should be introduced by the KERNEL_SEGMENT_COUNT's value is 5 >> > > which should be 6 as map_segment are called 6 times for the segme= nts >> > > of (text, stext, rodata, inittext, initdata, data+bss) >> > > >> > > [1] >> > > crash_arm64_v9.0.1> vtop ffffffed00601000 >> > > VIRTUAL PHYSICAL >> > > ffffffed00601000 83401000 >> > > >> > > PAGE DIRECTORY: ffffffecffd62000 >> > > PGD: ffffffecffd62da0 =3D> 10000000833fb003 >> > > PMD: ffffff80033fb018 =3D> 10000000833fe003 >> > > PTE: ffffff80033fe008 =3D> 68000083401f03 >> > > PAGE: 83401000 >> > > >> > > PTE PHYSICAL FLAGS >> > > 68000083401f03 83401000 (VALID|SHARED|AF|NG|PXN|UXN) >> > > >> > > PAGE PHYSICAL MAPPING INDEX CNT FLAGS >> > > fffffffec00d0040 83401000 0 0 1 4000 reser= ved >> > > >> > > [2] >> > > ffffffed002c8000 (r) __pi__data >> > > ffffffed0054e000 (d) __pi___bss_start >> > > ffffffed005f5000 (b) __pi_init_pg_dir >> > > ffffffed005fe000 (b) __pi_init_pg_end >> > > ffffffed005ff000 (B) early_init_stack >> > > ffffffed00608000 (b) __pi__end >> > > >> > > Signed-off-by: Zhaoyang Huang >> > > --- >> > > arch/arm64/include/asm/kernel-pgtable.h | 4 ++-- >> > > 1 file changed, 2 insertions(+), 2 deletions(-) >> > > >> > > diff --git a/arch/arm64/include/asm/kernel-pgtable.h >> > > b/arch/arm64/include/asm/kernel-pgtable.h >> > > index 74a4f738c5f5..14dd1c52552a 100644 >> > > --- a/arch/arm64/include/asm/kernel-pgtable.h >> > > +++ b/arch/arm64/include/asm/kernel-pgtable.h >> > > @@ -64,8 +64,8 @@ >> > > #define INIT_IDMAP_FDT_PAGES (EARLY_PAGES(INIT_IDMAP_PGTABLE_LEV= ELS, >> > > 0UL, UL(MAX_FDT_SIZE), 1) - 1) >> > > #define INIT_IDMAP_FDT_SIZE ((INIT_IDMAP_FDT_PAGES + >> > > EARLY_IDMAP_EXTRA_FDT_PAGES) * PAGE_SIZE) >> > > >> > > -/* The number of segments in the kernel image (text, rodata, ini= ttext, >> > > initdata, data+bss) */ >> > > -#define KERNEL_SEGMENT_COUNT 5 >> > > +/* The number of segments in the kernel image (text, stext, roda= ta, >> > > inittext, initdata, data+bss) */ >> > > +#define KERNEL_SEGMENT_COUNT 6 >> > > >> > > #if SWAPPER_BLOCK_SIZE > SEGMENT_ALIGN >> > > #define EARLY_SEGMENT_EXTRA_PAGES (KERNEL_SEGMENT_COUNT + 1) >> > >> > I think the better fix would be >> > >> > --- a/arch/arm64/include/asm/kernel-pgtable.h >> > +++ b/arch/arm64/include/asm/kernel-pgtable.h >> > @@ -68,7 +68,7 @@ >> > #define KERNEL_SEGMENT_COUNT 5 >> > >> > #if SWAPPER_BLOCK_SIZE > SEGMENT_ALIGN >> > -#define EARLY_SEGMENT_EXTRA_PAGES (KERNEL_SEGMENT_COUNT + 1) >> > +#define EARLY_SEGMENT_EXTRA_PAGES (KERNEL_SEGMENT_COUNT + 2) >> Thanks for the comment. This makes sense since KERNEL_SEGMENT_COUNT is >> also used for defining vmlinux_seg[] in declare_kernel_vmas. > Is the following fix more reasonable, since it makes both map_segment > and declare_kernel_vmas compatible with the value 6? > No, please fix this as I suggested.