gk7205v500: build the CMA allocator into osal - #236
Conversation
mmz_allocator=cma could not work on the gk7205v500 family. The kbuild left mmz/cma_allocator.o out of the osal module. So on a CMA kernel osal.c's call to cma_allocator_setopt() went unresolved, and the module would not load: open_osal: Unknown symbol cma_allocator_setopt (err 0) The file had also never been ported from the HiSilicon kernel's API: - It called get_cma_zone(). The xmedia kernel's drivers/xmedia/cma exports xmedia_get_cma_zone(). - It kept a private copy of struct cma_zone. It now includes <linux/xmedia_cma.h>, so the layout cannot drift from the kernel's. - It defined max_malloc_size, which allocator.c already defines. That was a link error once the file was actually built. It is now built only when the kernel has CONFIG_CMA, so a non-CMA build is unchanged. The printk of the zone casts its gfp_t/phys_addr_t arguments to match the %lx format. Verified on a GK7205V510 (128 MiB DDR) running openipc/linux 4.9.37 with CMA + DMA_CMA, booted with mem=128M mmz_allocator=cma mmz=anonymous,0,0x42000000,96M: cma: Reserved 96 MiB at 0x42000000 Media Memory Zone Manager cmz zone gfp 0x0, phys 0x42000000, nbytes 0x6000000 osal 1.0 init success! All 28 modules load, majestic starts the SDK, and CmaFree falls by the ~15 MB the media stack allocates from the zone. Linux keeps the rest of the DDR: MemTotal is 125840 kB, against 28612 kB with mem=32M and the xmedia carve-out.
PR Summary by QodoEnable CMA allocation in gk7205v500 OSAL
AI Description
Diagram
High-Level Assessment
Files changed (2)
|
Code Review by Qodo
1.
|
Review of the CMA allocator this PR starts building. - Alignment. __mmb_alloc() took the caller's alignment and ignored it. It asked dma_alloc_from_contiguous() for the size's own order only, so an alignment larger than that came back unmet. The fixed-region allocator honours it, and the same callers (the MMZ API, the userdev ioctl) reach both. It now asks for the larger of the two orders. dma_alloc_from_contiguous() silently caps the order at CONFIG_CMA_ALIGNMENT, so an alignment beyond that is refused rather than returned unmet. Every allocation that worked before gets the same block. - No zone. __allocator_init() returned success when no configured zone could be found or registered. osal then loaded and failed every allocation. It now counts the attempts and returns -ENODEV when none registered, which media_mem_init() turns into a failed modprobe -- the rule kernel/osal/linux's CMA allocator already follows. Verified on a GK7205V510 with mmz_allocator=cma mmz=anonymous,0,0x42000000,96M: - "cmz zone gfp 0x0, phys 0x42000000, nbytes 0x6000000"; - "osal 1.0 init success!"; - all 28 modules load; - CmaFree falls by the same ~15 MB as before; - majestic reports "HiSilicon SDK started"; - no allocation is refused for its alignment.
|
Both review findings were real; addressed in 84fd543:
Re-verified on a GK7205V510 with
|
The gk7205v500 family ran with mem=${osmem} (32M) and an xmedia
carve-out for the MMZ, so Linux saw a quarter of a V510's 128 MiB. That
is the wrong configuration for this SoC. On gk7205v200 the MMZ is a CMA
zone inside Linux's memory; this does the same for gk7205v500.
- Kernel: CMA, DMA_CMA, CMA_MEM_SHARED, plus COMPACTION and MIGRATION.
The xmedia kernel reserves the zone named by mmz= on the command line
(drivers/xmedia/cma) and, with CMA_MEM_SHARED, lends it to movable
pages while the media stack does not need it.
- load_goke:
- A command line that names no allocator is rewritten for the next
boot:
mem=${totalmem} ... mmz_allocator=cma mmz=anonymous,0,<osmem>,<rest>
Every other bootargs token is kept (#2281). totalmem is the DDR size
u-boot-xmedia writes into the env.
- xm_osal then loads with mmz_allocator=cma mmz=$MMZ.
- mmz_allocator=xmedia in bootargs keeps the carve-out.
- The "os_mem from mem=" override (for vendor bootloaders passing
mem=70M) now applies to the carve-out only. Under CMA, mem= is the
whole DDR, and the override tripped load_goke's own
"os_mem over total_mem" guard, so no module loaded.
- hisilicon-opensdk is bumped to dfc3a81 (OpenIPC/openhisilicon#236). The
gk7205v500 osal now builds its CMA allocator against the xmedia
kernel's API, honours the caller's alignment, and refuses to load with
no usable zone. Both variants take every xm_*.ko from opensdk, so all
are rebuilt against this kernel.
Verified on a GK7205V510 (128 MiB DDR):
- First boot after the change, still on mem=32M with the carve-out:
29 modules, no oops, and bootargs rewritten.
- Next boot: "cma: Reserved 96 MiB at 0x42000000", "cmz zone phys
0x42000000, nbytes 0x6000000". MemTotal is 125840 kB with ~97 MB
available, against 28612 kB total and ~15 MB available before.
CmaFree falls by the ~15 MB the media stack allocates.
- majestic reports "HiSilicon SDK started".
mmz_allocator=cma could not work on the gk7205v500 family. The kbuild
left mmz/cma_allocator.o out of the osal module. So on a CMA kernel
osal.c's call to cma_allocator_setopt() went unresolved, and the module
would not load:
open_osal: Unknown symbol cma_allocator_setopt (err 0)
The file had also never been ported from the HiSilicon kernel's API:
exports xmedia_get_cma_zone().
<linux/xmedia_cma.h>, so the layout cannot drift from the kernel's.
was a link error once the file was actually built.
It is now built only when the kernel has CONFIG_CMA, so a non-CMA build
is unchanged. The printk of the zone casts its gfp_t/phys_addr_t
arguments to match the %lx format.
Verified on a GK7205V510 (128 MiB DDR) running openipc/linux 4.9.37 with
CMA + DMA_CMA, booted with mem=128M mmz_allocator=cma
mmz=anonymous,0,0x42000000,96M:
cma: Reserved 96 MiB at 0x42000000
Media Memory Zone Manager
cmz zone gfp 0x0, phys 0x42000000, nbytes 0x6000000
osal 1.0 init success!
All 28 modules load, majestic starts the SDK, and CmaFree falls by the
~15 MB the media stack allocates from the zone. Linux keeps the rest of
the DDR: MemTotal is 125840 kB, against 28612 kB with mem=32M and the
xmedia carve-out.
Testing notes
master, whose gk7205v500 kernel has no CMA yet. CI therefore checks that the non-CMA build is unchanged; it doesn't compilecma_allocator.o.ecbc855, which is this repo'smain.hisilicon-opensdkbump replaces that patch.