Skip to content

core: mm: don't walk translation tables for every mapped page - #7947

Merged
jenswikl merged 1 commit into
OP-TEE:masterfrom
Edward-HP:core-mmu-map-pages-tbl-cache
Aug 28, 2026
Merged

core: mm: don't walk translation tables for every mapped page#7947
jenswikl merged 1 commit into
OP-TEE:masterfrom
Edward-HP:core-mmu-map-pages-tbl-cache

Conversation

@Edward-HP

Copy link
Copy Markdown
Contributor

core_mmu_map_pages(), core_mmu_map_contiguous_pages() and core_mmu_unmap_pages() called core_mmu_find_table() once per small page, even though the leaf translation table only changes every CORE_MMU_PGDIR_SIZE. For a 2MB pgdir that means 511 out of 512 walks returned the same table, each one masking exceptions, reading mpidr_el1 and doing a phys_to_virt() per level descended, all with mmu_spinlock held. The user mapping path in set_um_region() and set_pg_region() already switches leaf table only once per CORE_MMU_PGDIR_SIZE.

Add tbl_info_covers_va() and only walk the tables when the virtual address has left the table found for the previous page. Registering an 8MB non-secure shared buffer now walks 4 times instead of 2048 (8 the first time, when each pgdir entry still has to be split), and the same again on unmap. No functional change.

Link: #7946

@Edward-HP
Edward-HP force-pushed the core-mmu-map-pages-tbl-cache branch from ee993eb to 2644c43 Compare August 26, 2026 09:03
@jenswikl

Copy link
Copy Markdown
Contributor

Reviewed-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>

core_mmu_map_pages(), core_mmu_map_contiguous_pages() and
core_mmu_unmap_pages() called core_mmu_find_table() once per small page,
even though the leaf translation table only changes every
CORE_MMU_PGDIR_SIZE. For a 2MB pgdir that means 511 out of 512 walks
returned the same table, each one masking exceptions, reading mpidr_el1
and doing a phys_to_virt() per level descended, all with mmu_spinlock
held. The user mapping path in set_um_region() and set_pg_region()
already switches leaf table only once per CORE_MMU_PGDIR_SIZE.

Add tbl_info_covers_va() and only walk the tables when the virtual
address has left the table found for the previous page. Registering an
8MB non-secure shared buffer now walks 4 times instead of 2048 (8 the
first time, when each pgdir entry still has to be split), and the same
again on unmap. No functional change.

Link: OP-TEE#7946
Signed-off-by: edward-hp.wu <edward-hp.wu@mediatek.com>
Reviewed-by: Jens Wiklander <jens.wiklander@oss.qualcomm.com>
@Edward-HP
Edward-HP force-pushed the core-mmu-map-pages-tbl-cache branch from 2644c43 to ccc9af2 Compare August 28, 2026 06:13
@jenswikl

Copy link
Copy Markdown
Contributor

I'll merge this when the CI tests have passed.

@jenswikl
jenswikl merged commit b9436f3 into OP-TEE:master Aug 28, 2026
58 checks passed
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.

2 participants