[2/3] mm/pgalloc, arch/xtensa: Support BUILD_KERNEL on Xtensa - #19796
Draft
casaroli wants to merge 2 commits into
Draft
[2/3] mm/pgalloc, arch/xtensa: Support BUILD_KERNEL on Xtensa#19796casaroli wants to merge 2 commits into
casaroli wants to merge 2 commits into
Conversation
casaroli
marked this pull request as draft
August 11, 2026 14:23
simbit18
requested review from
eren-terzioglu,
fdcavalcanti,
gustavonihei and
tmedicci
August 11, 2026 14:39
casaroli
force-pushed
the
xtensa-split-2-kernel
branch
2 times, most recently
from
August 11, 2026 15:30
4dce990 to
f87469e
Compare
casaroli
marked this pull request as ready for review
August 11, 2026 15:33
Add CONFIG_MM_PGSIZE == 32768 and 65536 to the page-size switch (and the Kconfig help text). The 64 KB size matches the ESP32-S3 cache-MMU page granularity, so an address-environment port there can use one mm_pgalloc() page per cache-MMU page (naturally 64 KB-aligned by the granule allocator) instead of coalescing several smaller pages. Inert for existing configs: MM_PGSIZE is only used when CONFIG_MM_PGALLOC is enabled (BUILD_KERNEL). Assisted-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
Add what a kernel build needs on Xtensa: a crt0 for a user process, the kernel stack allocation that a system call switches to, the syscall entry and return path for an unprivileged caller, and the initial register state that starts a user task at EL0 with its save area on the kernel stack. On the ESP32-S3 the arch code that runs while the flash mapping is in flux moves to IRAM, and the kernel heap is placed above the user .bss so that up_allocate_kheap() and the user address environment do not overlap. Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com> Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
casaroli
force-pushed
the
xtensa-split-2-kernel
branch
from
August 11, 2026 20:06
f87469e to
f67dbec
Compare
casaroli
marked this pull request as draft
August 11, 2026 20:21
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Split from #19772, part 2 of 3, as asked in review.
This is the architecture-independent half:
mm/pgalloclearns larger pages, andarch/xtensa/src/commonlearnsBUILD_KERNEL. No chip code and no board code — those are part 3.This part does not depend on part 1. It adds no
fork()orvfork()code and refers to neither. It applies to master on its own, and the two parts can be merged in any order.mm/pgallocsupported 1 KB, 2 KB and 4 KB pages. The Espressif cache MMU has a fixed 64 KB page for external flash and 32 KB for external RAM, so those two sizes are added. Nothing else changes for existing users, who keep whatever they already selected.On the Xtensa side,
BUILD_KERNELneeds the pieces every kernel build needs and Xtensa did not have: a kernel stack for a user thread, a signal trampoline that returns through a system call, an initial register state that starts a user task on the right stack at the right privilege, and the system call paths to move between the two worlds.Two details are worth a reviewer's attention.
The kernel stack is aligned to 16 bytes because the windowed ABI requires it, and a stack pointer carries a base save area in the 16 bytes below it holding the caller's spilled
a0–a3. Anything that moves or builds a stack pointer has to leave that area alone, which is why the signal trampoline reserves it explicitly rather than assuming the space below the pointer is free.crt0.cusesSTRINGIFYfromnuttx/macro.hrather than defining its own, per review.Impact
Xtensa can be built with
CONFIG_BUILD_KERNELonce a chip provides an address environment. No chip does so in this patch, so nothing changes for any existing configuration.mm/pgallocgains two page sizes and changes no default.MM_PGSIZEis read only whenCONFIG_MM_PGALLOCis set, so existing kernel builds keep the arm they already took.Testing
Host: macOS 15 on Apple Silicon,
xtensa-esp32s3-elf-gcc12.2.0.This branch adds no chip code, so no kernel build is possible yet.
BUILD_KERNELneedsARCH_USE_MMUandARCH_ADDRENV, and the ESP32-S3 selectsARCH_HAVE_MMUandARCH_HAVE_ADDRENVonly in part 3. The check that matters here is that the common code compiles, links and does not disturb a working flat build.esp32s3-devkit:nshbuilds clean on this branch alone, with neitherARCH_HAVE_VFORKnorARCH_HAVE_FORKset.esp32s3-devkit:ostestwas also run on hardware, on this branch alone, to show no regression.esp32s3-devkit:ostestThe 32 MB octal part also needs
ESP32S3_FLASH_MODE_OCTandESP32S3_SPI_FLASH_USE_32BIT_ADDRESS.The kernel build that exercises this code lives in part 3, and its results are reported there.
tools/checkpatch.sh -c -u -m -greports no errors.