From 01ce8a61ccc32d6db3b93599dfba2810fc95ca58 Mon Sep 17 00:00:00 2001 From: Liam Girdwood Date: Tue, 1 Dec 2026 11:40:26 +0000 Subject: [PATCH] zephyr: lib: vpage: skip L2 clamp for relocatable LLEXTs With CONFIG_LLEXT_TYPE_ELF_RELOCATABLE and a virtual heap region on MTL, clamping end to l2_end reduced the vpage pool to 69 pages even though virtual heap and library regions are backed on demand. Skip the l2_end clamp when LLEXT_TYPE_ELF_RELOCATABLE is enabled so the pool uses the full virtual address space up to CONFIG_LIBRARY_BASE_ADDRESS (325 pages on MTL), capped below by available physical L2. Signed-off-by: Liam Girdwood --- zephyr/lib/vpage.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/zephyr/lib/vpage.c b/zephyr/lib/vpage.c index afc93035f3e1..a4d05dee0237 100644 --- a/zephyr/lib/vpage.c +++ b/zephyr/lib/vpage.c @@ -572,16 +572,18 @@ __cold static int vpage_init(void) k_mutex_init(&vpage_ctx.lock); - if (start + library_l2_size + CONFIG_MM_DRV_PAGE_SIZE <= l2_end) { + if (!IS_ENABLED(CONFIG_LLEXT_TYPE_ELF_RELOCATABLE) && + start + library_l2_size + CONFIG_MM_DRV_PAGE_SIZE <= l2_end) { /* virtual heap and library regions fit in L2, vpages get the rest */ end = l2_end - library_l2_size; } else { /* - * Small L2 (e.g. NVL-S): the virtual heap and library regions are only - * virtual address space backed on demand, so they need not fit in L2 - * together with the vpages. Use the virtual space up to the library - * region (or the end of virtual memory) and cap it below by the - * physical L2 left after the image, as vpages can never use more. + * Relocatable LLEXTs or small L2 (e.g. NVL-S / MTL with virtual heap): + * the virtual heap and library regions are only virtual address space + * backed on demand, so they need not fit in L2 together with the + * vpages. Use the virtual space up to the library region (or the end + * of virtual memory) and cap it below by the physical L2 left after + * the image, as vpages can never use more. * Using pages beyond physical L2 needs the Zephyr TLB driver to map * the uncached alias too, see * https://github.com/zephyrproject-rtos/zephyr/pull/122801