Article View: muc.lists.freebsd.bugs
Article #779[Bug 301179] arm64 kexec: kexec_load_md() builds a malformed and incomplete identity map; the kexec jump faults in kexec_reboot_...
From: bugzilla-noreply
Date: Fri, 27 Nov 2026 08:48
Date: Fri, 27 Nov 2026 08:48
201 lines
8772 bytes
8772 bytes
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=301179
Bug ID: 301179
Summary: arm64 kexec: kexec_load_md() builds a malformed and
incomplete identity map; the kexec jump faults in
kexec_reboot_bottom()
Product: Base System
Version: 16.0-CURRENT
Hardware: arm64
OS: Any
Status: New
Severity: Affects Only Me
Priority: ---
Component: kern
Assignee: bugs@FreeBSD.org
Reporter: dmilith@me.com
Affects: sys/arm64/arm64/kexec_support.c (unchanged in main up to f129398f6454,
2026-11-26)
Seen on: FreeBSD 16.0-CURRENT main-n291235-611046b15dbb (arm64 GENERIC,
snapshot 20261117),
in a VM on Apple silicon (Hypervisor.framework, QEMU "virt"-like machine,
GICv3, U-Boot ->
loader.efi, 2 vCPUs, 2 GiB).
Any image reproduces it: the fault happens before the staged image is entered.
1. kexec_load(2) any image (one segment holding "b ." is enough).
2. reboot(RB_AUTOBOOT | RB_KEXEC)
The whole shutdown runs, "Starting kexec reboot" is printed, then the CPU takes
an instruction
abort at the physical address of kexec_reboot_bottom() and the machine hangs.
Cause
-----
kexec_reboot_md() switches TTBR0 to locore's bootstrap tables
(pagetable_l0_ttbr0_bootstrap,
one L1 entry, one L2 table) and enters kexec_reboot_bottom() at its physical
address.
kexec_reboot_bottom() runs from that identity map with the MMU on until it
writes SCTLR_EL1.
kexec_load_md() adds three L2 block entries for it:
tmp = pmap_kextract((vm_offset_t)kexec_reboot_bottom);
pte[pmap_l2_index(tmp)] = (tmp | L2_BLOCK | ATTR_AF | ATTR_S1_UXN);
These entries have two problems, and the identity map is also incomplete.
1. The output address is the symbol's exact physical address, not its 2 MiB
block
(tmp & ~L2_OFFSET). The symbol's offset within the block therefore lands in
descriptor
bits [20:2]:
- bits [20:12]: RES0, nT, and OA[51:48] with FEAT_LPA;
- bits [11:2]: nG, AF, SH, AP, NS and AttrIndx.
With the kernel at PA 0xb5600000, kexec_reboot_bottom is at PA 0xb5f49390
and gets
0x00400000b5f49791
That is AttrIndx 4 (VM_MEMATTR_DEVICE_nGnRE), AP 0b10 (read-only), SH 3 and
nG 0, with
0x149 in bits [20:12]. locore's entry for that block would be
0x00440000b5e00f09
(ATTR_S1_nG | ATTR_S1_IDX(VM_MEMATTR_WRITE_BACK) | pmap_sh_attr |
pmap_gp_attr | AF | UXN).
2. No memory attribute index, no nG and no shareability are set, unlike the
entries
build_l2_block_pagetable writes into the same table.
3. Three blocks are not enough. Before the MMU goes off, kexec_reboot_bottom()
calls
pmap_kextract() and, through VM_RADIX_FORALL, pctrie_iter_lookup() and
pctrie_iter_next().
These are PC-relative "bl" calls, so they run from the identity map too. In
the snapshot
kernel:
kexec_reboot_bottom KERNBASE + 0x949390
pmap_kextract KERNBASE + 0x951320 (same 2 MiB block)
pctrie_iter_lookup KERNBASE + 0x59bc6c (a block none of the three
entries maps)
pctrie_iter_next KERNBASE + 0x59c33c
Its stack (initstack_end) and the globals it reads with adrp (vm_page_array,
and what the
callees read, e.g. dmap_phys_base) must be identity-mapped as well.
Fix
---
Everything kexec_reboot_bottom() touches with the MMU on lies in the kernel
image. Give every
2 MiB block of [_start, _end) the entry locore builds for _start's block. The
bootstrap L1 table
has one entry, so the image must lie in _start's 1 GiB. Patch attached
(1-kexec_support.c.diff). It is not compile-tested. A tested equivalent runs
from userland:
after kexec_load(2) we write exactly these entries through /dev/kmem, using
kldsym(2) for
_start, _end, pagetable_l0_ttbr0_bootstrap, pmap_sh_attr and pmap_gp_attr. With
that, kexec
reboots complete on the same VM: ZFS root, both CPUs, multi-user, and a second
kexec from the
kexec'd system.
Patch:
--- a/sys/arm64/arm64/kexec_support.c
+++ b/sys/arm64/arm64/kexec_support.c
@@ -56,6 +56,8 @@
extern pt_entry_t pagetable_l0_ttbr0_bootstrap[];
extern unsigned long initstack_end[];
+extern pt_entry_t pmap_gp_attr;
+extern char _start[], _end[];
void switch_stack(void *, void (*)(void *, void *, struct kexec_image *), void
*);
#define SCTLR_EL1_NO_MMU (SCTLR_RES1 | SCTLR_LSMAOE |
SCTLR_nTLSMD | \
@@ -160,8 +162,8 @@
int
kexec_load_md(struct kexec_image *image)
{
- vm_paddr_t tmp;
- pt_entry_t *pte;
+ vm_paddr_t pa, last;
+ pt_entry_t *pte, attr;
/* Create L2 page blocks for the trampoline. L0/L1 are from the
startup. */
@@ -173,16 +175,23 @@
pte -= (Ln_ENTRIES * 2); /* move to start of L2 pages */
/*
- * Populate the identity map with symbols we know we'll need before we
- * turn off the MMU.
+ * kexec_reboot_bottom() runs from the identity map with the MMU on
until
+ * it disables it: its code, its stack (initstack), the functions it
calls
+ * (pmap_kextract(), pctrie_iter_lookup(), pctrie_iter_next()) and the
+ * globals it reads (vm_page_array) must all be mapped. They all lie
in
+ * the kernel image, so identity-map all of it, with the entries
locore's
+ * build_l2_block_pagetable writes for _start's block. The bootstrap
L1
+ * table has a single entry: the image must lie in _start's 1 GiB.
*/
- tmp = pmap_kextract((vm_offset_t)kexec_reboot_bottom);
- pte[pmap_l2_index(tmp)] = (tmp | L2_BLOCK | ATTR_AF | ATTR_S1_UXN);
- tmp = pmap_kextract((vm_offset_t)initstack_end);
- pte[pmap_l2_index(tmp)] = (tmp | L2_BLOCK | ATTR_AF | ATTR_S1_UXN);
- /* We'll need vm_page_array for doing offset calculations. */
- tmp = pmap_kextract((vm_offset_t)&vm_page_array);
- pte[pmap_l2_index(tmp)] = (tmp | L2_BLOCK | ATTR_AF | ATTR_S1_UXN);
+ attr = L2_BLOCK | ATTR_AF | ATTR_S1_UXN | ATTR_S1_nG |
+ ATTR_S1_IDX(VM_MEMATTR_WRITE_BACK) | pmap_sh_attr | pmap_gp_attr;
+ pa = pmap_kextract((vm_offset_t)_start) & ~L2_OFFSET;
+ last = pmap_kextract((vm_offset_t)_end - 1) & ~L2_OFFSET;
+ if ((pa >> L1_SHIFT) != (last >> L1_SHIFT))
+ return (EINVAL);
+ for (; pa <= last; pa += L2_SIZE)
+ pte[pmap_l2_index(pa)] = PHYS_TO_PTE(pa) | attr;
+ dsb(ishst);
return (0);
}
--
You are receiving this mail because:
You are the assignee for the bug.
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Technical Details
Message-ID:
<bug-301179-227@https.bugs.freebsd.org/bugzilla/>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mailShow Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news2.arglkargh.de!news.karotte.org!news.muc.de!.POSTED.news.muc.de!not-for-mail From: bugzilla-noreply@freebsd.org Newsgroups: muc.lists.freebsd.bugs Subject: [Bug 301179] arm64 kexec: kexec_load_md() builds a malformed and incomplete identity map; the kexec jump faults in kexec_reboot_bottom() Date: Fri, 27 Nov 2026 08:48:16 +0000 Organization: Newsgate at muc.de e.V. Approved: news-admin@muc.de Distribution: world Message-ID: <bug-301179-227@https.bugs.freebsd.org/bugzilla/> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: news.muc.de; posting-host="news.muc.de:193.149.48.2"; logging-data="76832"; mail-complaints-to="news-admin@muc.de" X-Original-To: bugs@mlmmj.nyi.freebsd.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1795769297; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=op/2xmPA4IHp93zRmhm7oblq8bZNKCJuide6LeiBDjI=; b=bUpEAR4xa0QQ/nUs5uF0/ZX3x6zyI94SWqf0qteH7qUKhkt82yXd98Nl6Ht/sthJ0XcnuV SghrirK+5bR5PDTcNJ9SfP05uy3OkMZXsuBSqRWNkp43OP5qnB68uTG8K7e2VU+KnPZRBQ JPDcmYLlGw/tf8ZyToBgYFjzJDHyk8gKmMt/3kOZcWoY9MKnymwAZkMfBsP0HJE2fs1atc ZIPpRFbKBXORo0pCzOjJkvK3eRVqYdqwUdRSzSeWvMDcLdJvIm8EqO7oz6jGs/HBN9+QZI /bvTtHjB2Y/8UNdExKdmjjvmnuSa64877W/FdAQ8TdHWMTBoCBpEAeHJKf6Hbw== X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f Auto-Submitted: auto-generated Precedence: list X-Newsgate-Id: f02c70b8849f+ X-No-Archive: Yes