Commit graph

741 commits

Author SHA1 Message Date
bunnie
6961bb3e54 fix a bug in debug-print when swap is not specified
a field doesn't exist that is accesed by a debug-print resource
in the case of swap being inactivated
2024-11-30 02:21:20 +08:00
bunnie
820acfa2e6 make sure that swapper pages are marked as wired once allocated
also improve debug output, it was a little nonsensical previously
(some bit rot on meaning of fields)
2024-11-07 16:10:27 +08:00
bunnie
a854ad53ea fix broken code in deep debug option 2024-11-07 16:10:07 +08:00
bunnie
b3de92aabc add option to dump kernel pages in panic dumps 2024-11-07 16:09:49 +08:00
bunnie
735c4bfedd add debug options for sussing out IRQ problems in the kernel 2024-11-07 16:05:47 +08:00
bunnie
bb7209508b update formatting on the published crates
not doing a reformat of the entire project to match
nightly formatting changes, but capturing the published
crates so we can maybe save a version bump later on to get
the project clean.
2024-09-23 01:43:02 +08:00
bunnie
89f92c28a2
Merge branch 'main' into nto-work 2024-08-19 02:30:35 +08:00
bunnie
6eab1c48bb patches to clean up warnings in rust-1.80 2024-08-19 02:24:24 +08:00
bunnie
6ddc8bc79a
Merge branch 'main' into nto-work 2024-06-27 00:41:07 +08:00
bunnie
a9b0ba2666 improve documentation on how the CSPRNG is reseeded from the TRNG. 2024-06-22 21:18:24 +08:00
bunnie
3ae4fde572 fix comment 2024-06-21 18:20:10 +08:00
bunnie
3e8cfab6b0 fix hosted mode 2024-06-20 01:56:36 +08:00
bunnie
32893b9b4c fix build option 2024-06-19 22:04:42 +08:00
bunnie
474343c24e deprecate SID assignment
We no longer send messages to the swapper via the server interface.

All calls go through the blocking handler; in general, there are
no scenarios where it makes sense to have a swapper operation
pre-emptable. We always want our swapper ops to complete quickly,
deterministically, and atomically.
2024-06-19 21:39:54 +08:00
bunnie
96630a11ee handle the case of a failed PTE allocation gracefully
instead of hard crashing, we return an appropriate error.

Also add some debug instrumentation.
2024-06-19 21:39:17 +08:00
bunnie
c5aee47861 update comment to reflect current policy on OOM
I think it's more Xous-y to punt to userland in the case that
no consecutive memory is found, rather than trying to implement
an evictor in the kernel itself.

For now, the blunt hammer we use is to simply request some
blocks be freed and we retry; this works well enough to find
blocks of a few pages in sequence. If we needed larger blocks,
we may want to consider modifying the swapper userland algorithm
to have some API for finding consecutive runs of non-wired
memory to swap out.
2024-06-19 21:37:00 +08:00
bunnie
6ba57774cf add "device RAM" allocation mode to kernel
"Device RAM" is a block of RAM whose physical address is not
important, but the block must be consecutively allocated in
physical address space.

This is used to allocate blocks of memory that are intended
for hardware DMA targets and other peripheral shared-memory
applications.

Note that this also marks the allocated block as "wired", so
it can't be swapped out.
2024-06-19 21:34:42 +08:00
bunnie
7a821a836f cleanup comments 2024-06-18 00:07:43 +08:00
bunnie
ec41c73aa9 harden kernel TRNG
apply the same techniques in the loader key generator to
the kernel TRNG. Every pull of data from the kernel reseeds
the TRNG state as well. This makes server ID creation somewhat
more expensive, but should greatly improve the security of
the system in the case of a TRNG with occassional drop-outs.
2024-06-15 00:40:04 +08:00
bunnie
53f8a9f1d6 apply entropy hardening on boot to kernel as well
Shoot for 256 bits minimum entropy in the seed pool, gives us
some safety margin over our required 128.

note that the pool only gets more entropy over time, as every
call to the pool folds more entropy in (roughly 2 bits per call).
2024-06-14 16:12:17 +08:00
bunnie
223e1995ef fix the fix :P 2024-06-13 15:56:37 +08:00
bunnie
242c682a74 cleanup warning that snuck in 2024-06-13 15:54:32 +08:00
bunnie
40651a37ea add RawTrng syscall implementation 2024-06-13 15:42:18 +08:00
bunnie
a5322eaa7a add sampling countermeasures to the kernel
this evolves the TRNG state further after reporting any raw samples
for QC to make it harder to reason about the TRNG state after QC.
2024-06-13 15:41:30 +08:00
bunnie
ff3138b72b bump stack limit
we did encounter a panic in testing
2024-05-31 20:39:18 +08:00
bunnie
1761b38b23 prevent formatting of assembly 2024-05-31 03:34:21 +08:00
bunnie
d92a8dd00d tweak backup stack space allocation in kernel now that we've tested on hw 2024-05-29 14:05:16 +08:00
bunnie
755265d290 quiet down debug on syscalls 2024-05-28 20:28:55 +08:00
bunnie
c569fa528c handle corner case of OOM during move or lend
In this situation, we enter the OOM with the hardware address
space vs the process space inconsistent (the hardware address
space was transitioned in anticipation of mapping a block into it).

This patch reverts our address space to the original space then
runs the OOM routine, and then puts us back where we were.
2024-05-28 20:27:38 +08:00
bunnie
ec9a2be9cc reduce warnings when debug is turned off 2024-05-28 20:27:13 +08:00
bunnie
3cf79dbbd4 fix typos, adjust debug 2024-05-28 20:26:57 +08:00
bunnie
bed9252614 suppress warning when debug is turned off 2024-05-28 16:54:18 +08:00
bunnie
ed73dfb401 make retrievepage a re-entrant syscall: syscall abi 2024-05-28 02:49:00 +08:00
bunnie
747e07c90f remove code bits now that all syscalls are re-entrant
previously we could re-enter into a process through a divergent
call into the swapper. Now, we only ever re-enter as a syscall
through the syscall interface.

in order to make this happen we had to store all the thread and
stack state for the handler so we can do a re-entrant syscall, but
I think this is worth it. makes the code so much better.
2024-05-28 02:47:19 +08:00
bunnie
8ce2ac566a make swapper syscall API re-entrant (map/retrieve page)
we no longer diverge at the swapper call, so execution flows
intuitively here. this feels so much nicer.
2024-05-28 02:45:27 +08:00
bunnie
62eb233db1 make swapper api generic for re-entrant kernel calls (alloc element) 2024-05-28 02:44:36 +08:00
bunnie
0e135b0e4c refactor retrieve_page to use re-entrant syscall
- makes retrieve_page in-lineable into existing kernel routines
without a divergence issue on the call return
- reduces code duplication
- fixes a hairy bug on interrupt restore timing. With the previous
method, the interrupts would have to un-gate just before the
syscall executes its return to normalcy; this can cause a race
condition between a hardware interrupt and that return context
switch which can lead to the return context being corrupted.

By making this re-entrant, we can make the IRQ pause/restore
point happen outside of any fancy system context footwork, which
makes the interrupt via hardware source work again.
2024-05-28 02:41:08 +08:00
bunnie
fa777b6198 cleanup the original alloc_page now that all are oomable 2024-05-26 23:00:20 +08:00
bunnie
a799e4b09d make all other allocs possibly oomable 2024-05-26 22:57:53 +08:00
bunnie
fb502a8073 debug cleanup 2024-05-26 12:12:58 +08:00
bunnie
f1d5a015cc remove oom-doom path handler
in practice the hard-OOM only seems to happen, and oom-doom
takes up precious memory that could be used for preventing
OOMs. Just leave one path in, but make it a bit smarter.

The smarts are still in userland, so the kernel is minimal
dependencies.
2024-05-25 02:10:55 +08:00
bunnie
bd696e5a62 make the backing stack extent easier to configure 2024-05-25 01:34:11 +08:00
bunnie
9387a701c2 cull now-unused path-dependent kernel OOM implementation 2024-05-25 00:53:25 +08:00
bunnie
bfb25af370 make hard OOM a re-entrant syscall
Re-entrant syscall is tricky because we end up smashing
the return thread context and stack of the current syscall.

We stash the thread context and stack in order to make this
happen, but we have to make some assumption about the potential
stack size. There's a assert to save us if this is wrong, but
generally the kernel is extremely well behaved on stack consumption
so we shouldn't be bumping into it.

This version of the OOM handler allows us to bury the OOM
handler "anywhere", which means we can handle the hard OOM
in multiple allocation methods without having to track the entry
and exit point of every single possible one.

This means we can chop a lot of fragile code out of the kernel.
We'll do that after this commit, and some testing, to make sure
this is the right path, but it feels "much nicer".

We'll probably also cut the oom-doomer, because I think in
practice it won't be effective and it consumes a non-trivial amount
of RAM, which would otherwise make OOMs more infrequent -- probably
an amount that would be greater than the benefit that any soft-OOM
handler can get us.
2024-05-25 00:06:38 +08:00
bunnie
514afc2385 refine swapper OOM handler security checks
The Hard OOM re-entrant syscall can actually originate in
any process space, but only from inside the kernel. Modify the
checks so that the PID==2 check is applied only to all the other
calls; and that a supervisor mode check is applied to the hard OOM
call.
2024-05-25 00:04:59 +08:00
bunnie
081f2009e8 make alloc_page_oomable re-entrant
This version of the OOM handler uses a syscall in a syscall
(previously forbidden) to make the OOM case deep in an alloc
situation oomable, but also have multiple exit paths.

this saves us from having to recode oodles of exit paths which
is complicated and error-prone.

I also think we should trim back some of the OOM handling paths
because it is bloating the swapper, but let's commit the current
working state before we trim stuff.
2024-05-25 00:01:22 +08:00
bunnie
010bdd0180 more debug tweaking in irq reporting 2024-05-24 23:59:41 +08:00
bunnie
84ef3ed694 add thread reporting to irq entry 2024-05-23 16:49:39 +08:00
bunnie
641b6dbeb3 remove unused configurable OOM thresholds in the kernel
turns out that

- hard OOM has a clearly defined threshold: 0. we shouldn't
make it higher, because then it forces us to count free memory
on every allocation.

- it's better to have the tuning in userspace (I think) for
OOM, because that's where all the algorithms are
2024-05-21 03:46:54 +08:00
bunnie
cf6c084696 quite down debug in kernel 2024-05-21 02:56:08 +08:00