load_hisilicon: derive os_mem_size from kernel cmdline mem=#2039
Merged
Conversation
load_hisilicon was deciding where to put the MMZ region by reading osmem from the U-Boot environment. But the kernel's actual memory size is set by the mem= argument on the kernel command line -- osmem is just a hint U-Boot uses when it builds that command line at boot. When those two drift apart (observed on a hi3516av200 with the kernel booted with mem=256M while osmem in the env still said 128M), the script trusted osmem, computed mmz_start = 0x80000000 + 128M = 0x88000000, and asked the MMZ allocator for a 384MB region starting there. The kernel had already claimed everything up to 0x8FFFFFFF, so the request overlapped kernel memory by 128MB and got rejected -- silent on older opensdk builds, hard insmod failure on opensdk e866011 and later (openhisilicon PR OpenIPC/openhisilicon#73). Read mem= directly from /proc/cmdline -- that's what the running kernel actually claimed, it can't lie -- and use it as os_mem_size. Fall back to the env value when the kernel was booted without an explicit mem=, so boot paths that never set it keep working. Same patch applied to all eight load_hisilicon scripts since they share the formula. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Picks up OpenIPC/openhisilicon#73: mmz: fail allocator init when every configured zone is rejected. Pairs with the previous commit -- without the bump, a corrected osmem from /proc/cmdline still leaves users on older opensdk builds silently passing a bad mmz= range without noticing; with the bump, that case becomes a loud insmod failure. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
3 tasks
widgetii
pushed a commit
that referenced
this pull request
May 6, 2026
Two-part regression test paired with the fix in the previous commit, so
any future regression to load_hisilicon's mem= parsing breaks CI before
release rather than after a user reports their camera is bricked:
Part 1 — logic test. Synthetic harness reproducing the post-fix
parse_os_mem block, exercised against six cmdline / totalmem /
osmem combinations (the V4+CMA bug case from #2059, the
legacy split #2039 wanted to honor, missing-cmdline fallback,
default-32, mem>totalmem misconfig, edge case mem=N-1).
Part 2 — drift test. greps every general/package/hisilicon-osdrv-*
load_hisilicon for the totalmem-validation block. If anyone
reverts the fix in any family, or adds a new
hisilicon-osdrv-* package without the validation, Part 2
fails immediately.
Verified the test would have caught #2059. Running it against the
unfixed scripts on master:
=== Part 2: validation block present in every load_hisilicon ===
scanning 8 load_hisilicon copies
FAIL hi3516av100: validation block MISSING — fix from #2060 was reverted or not applied
FAIL hi3516cv100: validation block MISSING — fix from #2060 was reverted or not applied
... (all 8 fail) ...
8 check(s) failed. See #2059
exit=1
After the fix all 14 checks pass (6 logic + 8 drift). The shell-tests
workflow runs on every PR to master so this stays the pre-release gate.
Refs: #2039, #2059, OpenIPC/openhisilicon#86 (post-release defence-in-depth)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
load_hisiliconwas deciding where to put the MMZ region by readingosmemfrom the U-Boot environment. But the kernel's actual memory size is set by themem=argument on the kernel command line —osmemis just a hint U-Boot uses when it builds that command line at boot.On a
hi3516av200camera those two had drifted apart: the kernel was booted withmem=256M, whileosmemin the env still said128M. The script trustedosmem, computedmmz_start = 0x80000000 + 128M = 0x88000000, and asked the MMZ allocator for a 384MB region starting there. The kernel had already claimed everything up to0x8FFFFFFF, so the request overlapped kernel memory by 128MB and got rejected.What this PR does
Reads
mem=directly from/proc/cmdlineand uses that value asos_mem_size:/proc/cmdlineis what the running kernel actually claimed — it can't lie. So now the script's "where does kernel memory end / where does MMZ start" matches reality, regardless of whatosmemsays. On the affected camera that producedmmz_start=0x90000000, mmz_size=256M, which fits cleanly above the kernel's 256MB and below the end of the 512MB DDR.Why a fallback to
osmemIf a kernel is booted without an explicit
mem=(uncommon on these SoCs, but possible — thebootargsubi/bootargsnfstemplates show thatmem=${osmem}is normal but not enforced),/proc/cmdlinewon't have it. Falling back to the env keeps that boot path working instead of forcing every user to add a kernel arg. The final:=32keeps the original behaviour as a last resort.Why this layering instead of "just fix the env"
The env can be wrong in either direction (
osmemlarger or smaller thanmem=), and on a remote camera you can't always rewrite U-Boot env safely. The cmdline-first approach makes the script self-correcting: whatever the kernel actually got, MMZ will agree with it. The env stays meaningful only as the boot-time hint it always was.Pairs with opensdk bump (commit 2)
Also bumps
HISILICON_OPENSDK_VERSIONtoe866011, which picks up openipc/openhisilicon#73 —mmz: fail allocator init when every configured zone is rejected.Without the bump, a corrected
osmemstill leaves users on older opensdk builds silently passing a badmmz=range without noticing; with the bump, that case becomes a loud insmod failure with the conflict line indmesgright above it.The two changes are complementary: this PR fixes the misconfig that produced the conflict, the opensdk bump ensures any future misconfig fails fast and visibly instead of presenting as zombie modules with empty MMZ.
Test plan
hi3516av200(V3 family / kernel 3.18.20):mmz_start: 0x88000000, mmz_size: 384M→ MMZ rejected → on opensdk e866011insmod hi_osal.kofails withMMZ: all 1 configured zone(s) failed to registerand exit 19.mmz_start: 0x90000000, mmz_size: 256M→ MMZ registered successfully → allhi3519v101_*modules load →/proc/media-memshowsZONE: PHYS(0x90000000, 0x9FFFFFFF), nBYTES=262144KB, NAME="anonymous"→ majestic starts and reaches sensor init.🤖 Generated with Claude Code