From nobody Tue Jun 16 17:04:34 2026 Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 BDCDD3FF8B3 for ; Thu, 30 Apr 2026 08:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777539572; cv=none; b=VZsWAiOAF7Nl2hYtFHWsym6AMhNbZi0j+HLbhrbDUs20trT2nEahQA/0SxADD0oypzu/TmLHy98X/tjbeo+M/Aa1sGbrcMXhnj1diLVSPwONmD7udU74py1BmpqHXXcJgZL5rqHZRAJhQ7xDx4rXkZkY62EZ57IeNYnhVVdTKPU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777539572; c=relaxed/simple; bh=9DptAU95oAX56MhMb33tz7PvKNSpeVggJKjm4BHJEaU=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type; b=U91YsHVKS3KK2oxHse7GKRcbBfi2cxgz/J13CWZn7TZ72tNs99plg7k6lG6BXGPGjsoQ4pzzMkPZ9FV4YjbCh/UyMnZuTNIV+nqeYe1Je0Zs/TE7Tsq1t/a3wXpLCFtIxMEUFNKh4z7sgVlel30URzP2ln53NszTbI550nVpU6g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b=th3+sdgl; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=unisoc.com header.i=@unisoc.com header.b="th3+sdgl" Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 63U8wKQk074189; Thu, 30 Apr 2026 16:58:20 +0800 (+08) (envelope-from zhaoyang.huang@unisoc.com) Received: from SHDLP.spreadtrum.com (BJMBX01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4g5p0V5Trhz2MHhwM; Thu, 30 Apr 2026 16:55:22 +0800 (CST) Received: from bj03382pcu03.spreadtrum.com (10.0.73.40) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Thu, 30 Apr 2026 16:58:18 +0800 From: "zhaoyang.huang" To: Catalin Marinas , Will Deacon , Ard Biesheuvel , , , Zhaoyang Huang , Subject: [PATCHv3] arch: arm64: fix KERNEL_SEGMENT_COUNT error Date: Thu, 30 Apr 2026 16:58:08 +0800 Message-ID: <20260430085808.2951417-1-zhaoyang.huang@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 63U8wKQk074189 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=unisoc.com; s=default; t=1777539513; bh=yQbiiv0Vf+2505Xy7ivR6FqbF/Y+NWBphkmMi6/ATIs=; h=From:To:Subject:Date; b=th3+sdgl4EPjhpTnWjOdQaPClbAEnADwWLbDiO/4ld9Sqw66BMWkH4HtlcGIVxXI9 /a8jQ+Cmc6wts7kLTr+4AJhK+ZNnjtShlrWOBy0q9wv21oF+R7QzvG37dWa52374yh sRwpwbYkK5fwF31NZ/sZ3iJ4BN05rVj4u7gg59Y3XURE7b9f5fmnx/tXOdHrmIPpt/ GG/sUd6TVXffbfy2igYW7UA2/6SCc3BjvyV2Nuf12+VdOQtc6opmiBXujvvcicIKlE IQDglw3ly2PtKmaUd23GVko40Hrw568LVKgCthWhJqIFNXF2ua8M6U8zRtCPv7dlob YtJiiRjiUmsPA== Content-Type: text/plain; charset="utf-8" From: Zhaoyang Huang During debug of a kernel panic, we find that the pte_t of the final 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 segments 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 reserved [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 Fixes: 5973a62efa34 ("arm64: map [_text, _stext) virtual address range non-= executable+read-only") Assisted-by: TRAE: GLM-5.1 Suggested-by: Ard Biesheuvel Signed-off-by: Zhaoyang Huang --- Patchv2: make the size of vmlinux_reg[] more reasonable Patchv3: use extra value of 2 to meet the final segments count --- --- arch/arm64/include/asm/kernel-pgtable.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kernel-pgtable.h b/arch/arm64/include/a= sm/kernel-pgtable.h index 74a4f738c5f5..f6aed326e1ce 100644 --- a/arch/arm64/include/asm/kernel-pgtable.h +++ b/arch/arm64/include/asm/kernel-pgtable.h @@ -68,7 +68,9 @@ #define KERNEL_SEGMENT_COUNT 5 =20 #if SWAPPER_BLOCK_SIZE > SEGMENT_ALIGN -#define EARLY_SEGMENT_EXTRA_PAGES (KERNEL_SEGMENT_COUNT + 1) + +/* [_text, _stext) is mapped separately which consume 1 extra page */ +#define EARLY_SEGMENT_EXTRA_PAGES (KERNEL_SEGMENT_COUNT + 2) /* * The initial ID map consists of the kernel image, mapped as two separate * segments, and may appear misaligned wrt the swapper block size. This me= ans --=20 2.25.1