Bug 292156 - [patch] Fix conditional jump to incorrect label in 'build_l3_page_pagetable' for 0 entries
Summary: [patch] Fix conditional jump to incorrect label in 'build_l3_page_pagetable' ...
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: arm (show other bugs)
Version: 16.0-CURRENT
Hardware: arm64 Any
: --- Affects Only Me
Assignee: Andrew Turner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2026-01-03 16:41 UTC by Marian Cingel
Modified: 2026-07-18 19:12 UTC (History)
2 users (show)

See Also:
linimon: mfc-stable14?


Attachments
fix jump to correct label (996 bytes, patch)
2026-01-03 16:41 UTC, Marian Cingel
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Marian Cingel 2026-01-03 16:41:21 UTC
Created attachment 266785 [details]
fix jump to correct label

Hello,

I'm using qemu-system-aarch64 with kernel build from current 'main', based on VIRT kernconf - and it does not boot. The fix is in attachment.

The kernel code has size 8M (etext), ergo perfectly aligned to 2M leaves.
The 'build_l3_page_pagetable' function - which populates 4K leaves - is called with argument entries = 0 in register x10.

The first instruction (cbz x10, 2f) compares x10 against 0 and in case of match it jumps to '2f' - which is a *first forward* label named '2' - which stores the entry (not-yet-configured x13) into the page table (str x13, [x6, x11, lsl #3]).

In the function, there is a second '2' label, right before 'ret' instruction, which is where the conditional 'cbz x10, 2f' should aim.
Comment 1 Andrew Turner freebsd_committer freebsd_triage 2026-01-03 18:18:28 UTC
As this is a patch can you post it either via https://reviews.freebsd.org/ or as a GitHub pull request.
Comment 2 Marian Cingel 2026-01-03 18:21:18 UTC
(In reply to Andrew Turner from comment #1)
Ok, I will use pull request, thanks.
Comment 3 commit-hook freebsd_committer freebsd_triage 2026-01-06 11:05:21 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a9f2f92322f211921b955b13b088624efe7f901a

commit a9f2f92322f211921b955b13b088624efe7f901a
Author:     Marian Cingel <cingel.marian@gmail.com>
AuthorDate: 2026-01-03 14:45:27 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2026-01-06 10:36:37 +0000

    arm64: Fix jump to wrong label in case of 0 entries

    Broke qemu-system-aarch6 boot with VIRT kernconf

    PR:             292156
    Fixes:          ea8dc498aa8e ("arm64: Create an L3 table to limit permissions")
    Signed-off-by:  Marian Cingel <cingel.marian@gmail.com>
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1943

 sys/arm64/arm64/locore.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 4 Zhenlei Huang freebsd_committer freebsd_triage 2026-01-15 10:13:57 UTC
I'm not an expert on compiler. From my perspective, having the same labels within same ASM code block is bad smell. Can the compiler emit warnings about such kind of style ?
Comment 5 Marian Cingel 2026-01-15 11:21:41 UTC
(In reply to Zhenlei Huang from comment #4)
Hi,

I'm not compiler expert, this is just my opinion: It is a "local label" and it is common practice f.i to implement loops this way, so you don't have to make a and maintain unique labels across the file. Assembler (GNU gas) is only aware of scope per file/translation_unit  - it does not recognize blocks.
Comment 6 commit-hook freebsd_committer freebsd_triage 2026-02-09 16:29:06 UTC
A commit in branch stable/15 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=5ca05e51c861387003f0ef0ee6862bc39583dab0

commit 5ca05e51c861387003f0ef0ee6862bc39583dab0
Author:     Marian Cingel <cingel.marian@gmail.com>
AuthorDate: 2026-01-03 14:45:27 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2026-02-09 14:47:51 +0000

    arm64: Fix jump to wrong label in case of 0 entries

    Broke qemu-system-aarch6 boot with VIRT kernconf

    PR:             292156
    Fixes:          ea8dc498aa8e ("arm64: Create an L3 table to limit permissions")
    Signed-off-by:  Marian Cingel <cingel.marian@gmail.com>
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1943

    (cherry picked from commit a9f2f92322f211921b955b13b088624efe7f901a)

 sys/arm64/arm64/locore.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)