Skip to content

Make the loader runs on 16k page size kernel with SCons (2)#16

Open
illwieckz wants to merge 2 commits into
masterfrom
illwieckz/16k-scons
Open

Make the loader runs on 16k page size kernel with SCons (2)#16
illwieckz wants to merge 2 commits into
masterfrom
illwieckz/16k-scons

Conversation

@illwieckz

Copy link
Copy Markdown
Member

Build arm sel_ldr and nacl_helper_bootstrap with 64K page size alignment.
Makes it compatible with 16k page size kernels.
SCons plumbing.
@illwieckz illwieckz added the enhancement New feature or request label Jun 21, 2026
@illwieckz illwieckz changed the title Make the loader runs on 16k page size kernel (SCons only) (2) Make the loader runs on 16k page size kernel with SCons only (2) Jun 22, 2026
@illwieckz illwieckz changed the title Make the loader runs on 16k page size kernel with SCons only (2) Make the loader runs on 16k page size kernel with SCons (2) Jun 22, 2026
@illwieckz illwieckz mentioned this pull request Jun 22, 2026
@slipher

slipher commented Jun 25, 2026

Copy link
Copy Markdown
Member

I think it is breaking the bootstrap loader memory mapping somehow based on nacl_bootstrap_prereservation_test. I'm testing just on a 4k page system. The test also doesn't work on master because mmap is buggy and refuses to allocate the page starting right at vm.mmap_min_addr but the test can be made to work by modifying IsPageMappable to accept EINVAL with any address. So with that change, the mappings from master are like

00002000-00010000 ---p 00000000 00:00 0 
00010000-00012000 r-xp 00000000 b3:02 137384     /home/me/elsewhere/scons-out/opt-linux-arm/staging/nacl_helper_bootstrap
00012000-00014000 rw-p 00000000 00:00 0 
00014000-40002000 ---p 00000000 b3:02 137384     /home/me/elsewhere/scons-out/opt-linux-arm/staging/nacl_helper_bootstrap
40002000-40003000 rw-p 00002000 b3:02 137384     /home/me/elsewhere/scons-out/opt-linux-arm/staging/nacl_helper_bootstrap
4112a000-4114b000 rw-p 00000000 00:00 0          [heap]

The test, which checks that the first 1 GiB is reserved, passes. With this branch, the patched test fails and shows there was no additional memory reserved:

00002000-00010000 ---p 00000000 00:00 0 
00010000-00012000 r-xp 00000000 b3:02 146288     /home/me/elsewhere/scons-out/opt-linux-arm/staging/nacl_helper_bootstrap
00020000-00022000 rw-p 00000000 00:00 0 

The patch to the test:

diff --git a/src/trusted/service_runtime/linux/nacl_bootstrap_prereservation_test.c b/src/trusted/service_runtime/linux/nacl_bootstrap_prereservation_test.c
index 9f0a888e2..10812bcfa 100644
--- a/src/trusted/service_runtime/linux/nacl_bootstrap_prereservation_test.c
+++ b/src/trusted/service_runtime/linux/nacl_bootstrap_prereservation_test.c
@@ -28,7 +28,7 @@ int ParseMapsLine(FILE *fp, uintptr_t *start, uintptr_t *end) {
   if (!fgets(buf, sizeof(buf), fp)) {
     return 0;
   }
-
+ printf("%s", buf);
   if (sscanf(buf, "%"SCNxPTR"-%"SCNxPTR" %*4[-rwxp] %*8x %*2x:%*2x %*16x",
              start, end) != 2) {
     return 0;
@@ -62,9 +62,10 @@ int IsPageMappable(uintptr_t addr) {
                       MAP_ANONYMOUS | MAP_NORESERVE,
                       -1, 0);
   if (retval != (void *) addr)   {
+printf("addr=%p retval=%p errno=%d\n", (void*)addr, retval, errno);
     CHECK(MAP_FAILED == retval &&
           (EPERM == errno || EACCES == errno ||
-           (EINVAL == errno && 0 == addr)));
+           (EINVAL == errno /*&& 0 == addr*/)));
     return 0;
   }
   return 1;

@illwieckz illwieckz force-pushed the illwieckz/16k-scons branch from 580ab6a to 1ce4e9f Compare June 25, 2026 21:17
@illwieckz illwieckz force-pushed the illwieckz/16k-scons branch from 1ce4e9f to 3583583 Compare July 3, 2026 00:20
@slipher

slipher commented Jul 5, 2026

Copy link
Copy Markdown
Member

#36 has a proper fix for the aforementioned test.

I haven't investigated deeply yet why it fails with this PR, but probably we need to change the code to look up the page size at runtime for the mapping to work correctly.

Is there a strong reason to increase the supported page size to 64k rather than just 16k? That may require additional changes due to the ARM kernel's rule that the first two pages can't be mapped. We would also have to increase the loader's base address to at least 128k for it to be loadable. Though we were thinking of increasing it anyway due to the Slackware vm.min_mmap_addr issue.

@illwieckz

Copy link
Copy Markdown
Member Author

Is there a strong reason to increase the supported page size to 64k rather than just 16k?

No more reason other than “the more can do the less”. I discovered that all other binaries were aligned on 64K, and since 64k can run on 16K that can run on 4k, I just thought it would be good practice to standardize the alignment.

Now if 64K is harder to achieve than 16k, we can do 16k.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants