KernelPatch 0.13.8 fundamental incompatibility with MTK 4.14 (begonia/Redmi Note 8 Pro)
维护者通常 4 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- c, linux
调研方向
首先阅读 start.c 和 map.c 中的早期映射代码,尤其是 map_phys_alloc() 和 mem_proc(),并检查在 MTK 4.14 上如何解析 memblock 符号。使用报告中的启动镜像和 expdb 崩溃通道重现 begonia 故障。完成标准是安全处理 5 参数回退,并在不使用 hooks 的情况下验证兼容 4.x 的映射路径。
由索引模型根据 Issue 内容生成。
描述
Upstream Report: KernelPatch Incompatibility with MTK 4.14 (begonia/Redmi Note 8 Pro)
Device Information
- Codename: begonia
- Device: Redmi Note 8 Pro (Xiaomi)
- Platform: MT6785 (MTK)
- Kernel: 4.14.356-openela-rc1-Suzakukernel-V2
- Compiler: Clang version 11.0.1 (Android build)
- KP version: 0.13.8 (d08)
Executive Summary
KernelPatch's early-boot virtual-memory rework (_paging_init + memblock reserve/alloc/image relocation) is fundamentally incompatible with this MTK 4.14 kernel across ALL KP versions (0.13.0 through 0.13.8), even with zero hooks installed. The fault is in KP's core boot-time mapping machinery, not the hook subsystem or feature toggles.
Cross-Version Behavioral Matrix (all fresh-repatched from boot_work.img)
| kpimg | map/start path | failure mode | time->recovery | boots? |
|---|---|---|---|---|
| stock (no KP) | n/a | none | n/a | YES |
| 0.13.8 d08 | new _paging_init | quick crash → recovery | ~1 min | NO |
0.13.8 no-hooks (patch()=0) |
none | quick crash → recovery | ~1 min | NO |
| 0.13.0 d00 | old/simple paging | LONG hang → recovery | ~7 min | NO |
| 0.13.7 d07 | intermediate | LONG hang → recovery | ~7 min | NO |
Key observation: 0.13.0/0.13.7 with the old simpler paging path ALSO fail. This is NOT a 0.13.8 regression — the entire KP early mapping path is incompatible with this device.
Root-Cause Localization
1. Memblock 5-arg argument fragility (CONFIRMED)
On begonia, memblock_phys_alloc_try_nid (3-arg) is absent from the kernel. The patcher falls back to the 5-arg memblock_alloc_try_nid(size, align, min_addr, max_addr, nid).
The bug: KP's map_phys_alloc() calls through a 3-arg typedef memblock_phys_alloc_try_nid_f(size, align, int nid) even when the resolved function is the 5-arg memblock_alloc_try_nid. Only x0=size, x1=align, x2=third_arg(=0) are set; x3 (max_addr) and x4 (nid) hold garbage from registers at the call site.
Consequence: In memblock_alloc_try_nid, if the garbage max_addr lands below min_addr=0, the range is empty, allocation fails, start_pa returns 0, and the paging hook relocates the kernel into physical address 0 → init SIGSEGV at ~2.4s.
Evidence:
- Patch log line 53-56:
[?] no symbol: memblock_phys_alloc_try_nid/[+] use memblock_alloc_try_nid as map phys alloc - Upstream 0.13.8 map.c lines 54-64 already has the
third_argdistiction but it's insufficient when the 5-arg path is taken with garbage max_addr
Fix: When memblock_phys_alloc_type == MAP_SYM_MEMBLOCK_ALLOC_TRY_NID, call the 5-arg function with all 5 arguments properly: (size, align, 0, ~0ULL, 0) — i.e., min_addr=0, max_addr=anywhere, nid=0.
2. mem_proc linear_voffset probe (same class of bug)
The linear map offset detection at map.c lines 140-149 calls memblock_phys_alloc_try_nid(0, 0x10, NUMA_NO_NODE) through the 3-arg typedef against the 5-arg function, producing garbage detect_phys → linear_voffset is wrong → kernel image relocation is wrong → later crash.
Fix: Same pattern — detect the memblock_phys_alloc_type and call the 5-arg memblock_alloc_try_nid with all 5 args when needed.
3. Fundamental KP/core incompatibility (CONFIRMED by cross-version)
- 0.13.8 (new
_paging_initscratch path, gated to 6.x vianew_era = kmajor > 5) → crashes on 4.14 taking legacy path - 0.13.0 (old simple paging, no scratch) → crashes with long hang
- 0.13.7 (intermediate) → crashes
- Zero-hooks build (patch() returns 0 immediately, no panic/rest_init/kernel_init hooks installed) → still crashes
- Conclusion: The bug is in KP's early
start.c/map.cmapping code, not the hook subsystem or feature toggles. The entire_paging_init/_paging_initrework approach is incompatible with this MTK 4.14 kernel.
Diagnostic Channels
/sys/fs/pstore/console-ramoops — USELESS
- Returns the same 27711-byte dump (md5
912f79c4358489313533346be5c068d8) every crash - Even after
rm -fand a fresh crash - MTK crashes go through
mrdump/aeepath which does NOT refresh console-ramoops
/dev/block/by-name/expdb — RELIABLE CRASH CHANNEL
- Captures fresh mrdump crash logs via MTK's
mrdump/aeemechanism - Contains full backtrace:
dump_backtrace → mrdump_common_die → make_task_dead → panic → ipanic - KP bootlog lines NOT observed in the kernel log immediately before panic — meaning KP's
printkeither doesn't reach the log buffer before crash, or the mrdump RAM console capture starts after KP's phase - 20MB partition, always openable without a mounted filesystem
File-dump to /cache/``/data//sdcard` — FAILS
- Partitions are not mounted at 2.4s crash time during normal boot
filp_open/kernel_writesilently fail (orbefore_panicnever runs)
Evidence Summary
| Evidence Type | Result |
|---|---|
| Cross-version matrix (0.13.0/0.13.7/0.13.8) | ALL crash → fundamental incompatibility |
| Zero-hooks build | Still crashes → fault in core mapping, not hooks |
| Memblock 5-arg fragility | Confirmed bug; fixable but not sole root cause |
| pstore console-ramoops | STALE — unusable |
| File-dump to /cache /data /sdcard | Fails (partitions not mounted at crash) |
| Expdb mrdump channel | Fresh crash logs captureable; KP lines not visible |
| Custom tail-return in start.c | Present in upstream 0.13.8; may contribute but not sole cause |
Requested Actions for Upstream
-
Add a 4.x-safe mapping path or config option in KP to bypass the
_paging_initrework on kernels where it's known incompatible (similar to thenew_era = kmajor > 5gate, but for specific known-incompatible devices/SoCs). -
Fix the memblock 5-arg calling convention in
map_phys_alloc()andmem_proc()to pass all 5 arguments when the resolved function is the 5-argmemblock_alloc_try_nid(rather than the 3-arg typedef call that leaves max_addr/nid as garbage). -
Consider a device-specific quirk for MTK 4.14 kernels (begonia, sagit, etc.) that notes the absent
memblock_phys_alloc_try_nidsymbol and the fallback path fragility. -
Enable the expdb diagnostic channel in future KP releases so developers can capture fresh crash logs via
mrdump→ expdb for post-crash analysis.
Maintainer Notes
- This is NOT a 0.13.8 regression — the issue exists in 0.13.0 and 0.13.7 as well, confirming it's a fundamental KP/core incompatibility with this device's MTK 4.14 kernel.
- The
new_era = kmajor > 5gate in map.c correctly routes 4.14 to the legacy path, but the legacy path itself has device-specific breakage (the 5-arg memblock calling convention). - The two anonymous panic frames (offset 0x17f8ff3d8 / 0x17f901204) are KP core code in the vmalloc region it allocates during early mapping — not user-space or init code.
- pstore console-ramoops is NOT usable for observing fresh crashes on MTK devices; use the expdb mrdump channel instead.
Report generated from extensive behavioral bisection on real device (begonia, adb serial 8t9dl7ukaulvh6h6). All test images flashed via TWRP dd if=/sdcard/*.img of=/dev/block/by-name/boot bs=4k. Device restored to working stock V2 after testing.
- 主要语言
- C
- 星标
- 1.6k
- 派生
- 395
- 平均合并
- 3 天 15 小时
- 30 天内合并 PR
- 9
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bmax121/KernelPatch 的其他 Issue
-
official LineageOS on nicepool: APpatch patching fails but only if done via recovery sideload可能已有人在做 @bmax121 于 15 天前认领。 未关闭
bmax121/KernelPatch#332 · 已指派 1 人 ·
维护者通常 4 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
bmax121/KernelPatch#329 · 1 条评论 ·
维护者通常 4 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
bmax121/KernelPatch#323 ·
维护者通常 4 天内回复
-
难度 4/5 3-5 天 新手友好度 35/100
bmax121/KernelPatch#319 · 9 条评论 ·
维护者通常 4 天内回复
-
SUPERCALL_KSTORAGE_LIST_IDS writes to an unvalidated userspace pointer with a raw memcpy → kernel KE未关闭
难度 3/5 1-2 天 新手友好度 72/100
bmax121/KernelPatch#308 ·
维护者通常 4 天内回复
查看 bmax121/KernelPatch 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
zephyrproject-rtos/zephyr#123881 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 77/100
eclipse-zenoh/zenoh-pico#1354 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 65/100
ly05010419/MacNativeGames#1252 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 2 天内回复