Skip to content

Adds initializers and documentation about them.#60

Closed
remexre wants to merge 51 commits intotrunkfrom
remexre/initializers
Closed

Adds initializers and documentation about them.#60
remexre wants to merge 51 commits intotrunkfrom
remexre/initializers

Conversation

@remexre
Copy link
Member

@remexre remexre commented Oct 7, 2025

On top of #50; merge that one first, then rebase this.


Initializers are a way for drivers to get code to run without needing to jam more code into main.


This is not yet finished; it needs an example of use, and is probably blocked on #50's overhaul of the Devicetree parser. I'm making a draft PR to get feedback, though.

@remexre remexre marked this pull request as draft October 7, 2025 09:13
@remexre
Copy link
Member Author

remexre commented Oct 12, 2025

...whoops, turns out init.h snuck into trunk via #21 ( ab4bf40#diff-b9407181d3f79476016f05a3d1f404b8b30b2f22ec4b028e9c3ce7f255a582ec ) already...

@remexre
Copy link
Member Author

remexre commented Oct 12, 2025

Will probably cherry-pick 3f6b836 into this patchset as the example user; gonna finish #50 first though, I promise...

Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Right now, just the cycle time and timestamp for boot. These are
pretty attacker-guessable, but better than nothing.

This will be used to generate XOR cookies to initialize the heap with.

We usually get better entropy from U-Boot once we process the
Devicetree, so the RNG will reseed at that point.

Signed-off-by: Nathan Ringo <me@remexre.com>
This heap-allocates the Devicetree, so we don't need to keep the FDT
structure reserved.

It also includes the memory reservations block in the Devicetree proper,
under the /reserved-memory node.

This still needs to be fully integrated; e.g. by:

- Adding RAM to the allocators.
- Adding /chosen/rng-seed to the entropy pool.
- Creating devices from nodes.

This has been tested and works on the Milk-V Duo S.

Signed-off-by: Nathan Ringo <me@remexre.com>
It gets removed from the Devicetree to reduce the chances that an
attacker could discover it later. This is maybe kinda moot though,
because of how resistant the entropy pool is to attacks based on that.

Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Tested in QEMU and the Milk-V Duo S.

Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
These are for use in a treap implementation; arguably there should be a
"fast but lower-quality" RNG for this kind of usecase, but we really
don't want people e.g. using it when it would introduce a DoS attack.

Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
The page fault handler, among other things, will need it.

Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
This currently only supports 4KiB pages with Sv39.

Signed-off-by: Nathan Ringo <me@remexre.com>
This results in more readable output from the `info mem` command in
QEMU, since allocations are more often contiguous.

Signed-off-by: Nathan Ringo <me@remexre.com>
This is like Linux's, but uses static_assert to give a better compile
error when the given field is not an array.

Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
At this point, allocation works but freeing is a no-op.

Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
@remexre remexre force-pushed the remexre/initializers branch from bdab406 to 26f1d83 Compare October 25, 2025 22:07
@remexre
Copy link
Member Author

remexre commented Oct 25, 2025

Okay, did that cherry-pick. I think this is mergable behind #50.

This is essentially half of #4 (the half that doesn't need #13).

@remexre remexre marked this pull request as ready for review October 25, 2025 22:16
@remexre remexre force-pushed the remexre/initializers branch from 3e71307 to f3dd58d Compare October 25, 2025 22:17
- page_collect shouldn't assume that the page has an empty free list,
  but neither should it do O(n) work when it does not.
- After page_free, alloc_generic should not refer to the page anymore.

Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
Signed-off-by: Nathan Ringo <me@remexre.com>
@remexre
Copy link
Member Author

remexre commented Nov 8, 2025

Actually, closing this; the device model PR should supersede it. The notion of device classes in this PR is not the right thing for now.

@remexre remexre closed this Nov 8, 2025
@remexre remexre deleted the remexre/initializers branch January 12, 2026 15:39
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.

1 participant