Skip to content

xm530: CONFIG_CMA without an area, coherent memory from the page allocator - #160

Merged
openipc-ai merged 1 commit into
xiongmai-xm530from
xm530-cma-no-area
Oct 28, 2026
Merged

openipc-ai merged 1 commit into
xiongmai-xm530from
xm530-cma-no-area

Conversation

@openipc-ai

Copy link
Copy Markdown

A follow-up to #157, found while testing a full firmware image with CONFIG_CMA on.

With CONFIG_CMA, 3.10's ARM dma-mapping.c takes the atomic pool and every non-atomic dma_alloc_coherent() from CMA without checking that an area exists. With no cma= and CONFIG_CMA_SIZE_MBYTES=0, which is firmware's default layout, there is none, so every coherent allocation fails. On an XM550 booted mem=80M, pl330 couldn't create its channels, and the Ethernet driver oopsed on a NULL descriptor ring when udhcpc started, at every boot.

This takes CMA only when the device has an area (dev_get_cma_area()) and falls back to the page allocator otherwise, as later kernels do. The area is reserved at boot, so an allocation and its free always take the same path. Without CONFIG_CMA, dev_has_cma() is false and the code is unchanged.

Tested on the XM550, flashed:

  • mem=80M, no cma=: pl330 and Ethernet come up, with no oops, and majestic runs on the fixed zone (open_mmz default).
  • mem=127M cma=31M: 32 MiB is reserved, and open_mmz allocator=cma serves majestic from it (22 MB).

Firmware doesn't enable CONFIG_CMA yet. OpenIPC/firmware#2711 will, after this.

…cator

With CONFIG_CMA, 3.10's ARM dma-mapping takes every non-atomic coherent
allocation, and the atomic pool, from CMA without checking that there is
an area. A kernel booted without cma= (CONFIG_CMA_SIZE_MBYTES=0) has none,
so every dma_alloc_coherent() failed: on an XM550 booted mem=80M, pl330
could not create its channels and the Ethernet driver oopsed on a NULL
descriptor ring as udhcpc started, at every boot.

Take CMA only when the device has an area, and the page allocator
otherwise, as later kernels do. The area is reserved at boot, so an
allocation and its free take the same path.

Tested on the XM550: booted mem=80M it comes up with pl330 and Ethernet,
and majestic runs on the fixed zone; booted mem=127M cma=31M the area is
reserved and open_mmz allocator=cma serves majestic from it.
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Fall back to page allocation when no CMA area exists

🐞 Bug fix 🕐 10-20 Minutes

Grey Divider

AI Description

• Prevent coherent DMA allocation failures when CONFIG_CMA is enabled without a reserved area.
• Use CMA only for devices with an area, including when initializing the atomic pool.
• Match each allocation with the corresponding free path; XM550 boot tests covered both memory
 layouts.
Diagram

graph TD
  A["Coherent allocation"] --> B{"CMA area?"} -->|Yes| C["CMA allocator"] --> E["CMA release"]
  B -->|No| D["Page allocator"] --> F["Page release"]
Loading
High-Level Assessment

Checking area availability at the existing branch points is appropriate: it preserves CMA allocations where configured and restores the existing page-allocation path elsewhere. Requiring a CMA reservation would not support the firmware's default no-area layout.

Files changed (1) +14 / -3

Bug fix (1) +14 / -3
dma-mapping.cSelect coherent DMA allocation and free paths by CMA area availability +14/-3

Select coherent DMA allocation and free paths by CMA area availability

• Adds a CONFIG_CMA-aware area check and uses it for atomic-pool initialization, non-atomic coherent allocation, and the matching free path. Kernels without a CMA area now use the page allocator instead of attempting CMA allocations; builds without CONFIG_CMA retain their previous behavior.

arch/arm/mm/dma-mapping.c

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can turn on the rule miner and Qodo learns your standards from review history

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@openipc-ai
openipc-ai merged commit d9376d8 into xiongmai-xm530 Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant