Page MenuHomeFreeBSD

stand: Add mod_align_size variable
Needs ReviewPublic

Authored by imp on May 28 2025, 9:49 PM.
Tags
None
Referenced Files
F123243719: D50590.diff
Sat, Jul 12, 3:28 PM
Unknown Object (File)
Sun, Jul 6, 10:50 PM
Unknown Object (File)
Sun, Jul 6, 12:32 PM
Unknown Object (File)
Sun, Jul 6, 4:40 AM
Unknown Object (File)
Fri, Jul 4, 3:25 AM
Unknown Object (File)
Wed, Jul 2, 11:38 AM
Unknown Object (File)
Mon, Jun 30, 11:28 AM
Unknown Object (File)
Sun, Jun 29, 7:58 PM
Subscribers

Details

Summary

Add mod_align_size to specify the size of alignment. This controls how
md_align aligns things, thus controlling the alignment of
modules. Normally, you'd leave this unset. But if you have a 16k
PAGE_SIZE kernel on an architecture that defaults to 4k page size for
userland, then you'd set mod_align_size=16384 in your loader.conf. This
must be greater than or equal to the page size, less than 32,768 times
the page size (4k -> 128K on x86) and a power of two.

While it doesn't hurt to set this too big, it does waste memory. Setting
too small can lead to writeable text segments in the kernel... One
usually never sets it, though, since non-default pagesize kernels are a
specialty item still.

Future work would include having the page_size exported from the kernel
and some automation to find it when we first load the ELF kernel (which
typically is loaded with a 2MB alignmet), but not today.

Sponsored by: Netflix

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 64539
Build 61423: arc lint + arc unit

Event Timeline

imp requested review of this revision.May 28 2025, 9:49 PM
stand/common/modinfo.c
212

probably want to use EFI_PAGE_SIZE in case of UEFI?

stand/common/modinfo.c
212

Yea, we don't know here if we're EFI or not.

stand/common/modinfo.c
212

I think you meant to limit this to 32 times the default PAGE_SIZE, not 32768 times? 128k / 4k = 32, not 32k.

stand/common/modinfo.c
212

We do have -DEFI on cc command line... ;)

stand/common/modinfo.c
212

I really did mean 32k not 32. But maybe 32 is a better limit.

EFI_PAGE_SIZE is too small on some platforms when it's smaller than PAGE_SIZE. PAGE_SIZE is the smallest alignment in the kernel possible, and in userland we seem to be drifting towards it being the smallest alignment we can run on (since we might have some power-of-2 page size larger). So I think this is correct from that perspective.

stand/common/modinfo.c
208

That should be 128MB, not 32MB, I think.

241

Should this be EV_VOLATILE? EV_DYNAMIC keeps value, which is local here.

267

Wouldn't this result in a divide by zero if mod_align_size is 0, and the mod_align_size environment variable isn't pre-set? env_setenv() appears to only call the set-hook if it's replacing an environment variable, not if it's creating a new one.

stand/common/modinfo.c
208

oh, that's right.

241

No, it should be EV_DYNAMIC because asprintf allocates a string pointed to by value.

267

It's working for me, but now I don't see how :(. But it's worse than that... if this is actually set in the env, we won't have the set function set... I'm totally confused how my tests worked... I'm going to revert this chunk until I understand it.

stand/common/modinfo.c
267

oh, I hand't pushed, so I'll not push this until I can resolve it.

stand/common/modinfo.c
241

Oops, I was thinking of alloca() when I wrote that.