Commit graph

325 commits

Author SHA1 Message Date
bunnie
4fb3a3da43 add vexii-test shims for irq subsystem in kernel 2025-07-20 19:03:29 +08:00
bunnie
04c7933c87 handle case of write pages being swapped out upon write release 2025-05-21 18:02:21 +08:00
bunnie
3f0b833b90 add swapped flag to flag translation 2025-05-15 11:51:53 +08:00
bunnie
7af009be78 migrations for moving constants out of xous-rs/kernel and into board/platform
this is a fairly major re-org of where key constants go that
define platform features. things that were in xous-rs that were
platform specific (namely precursor) were moved into a boards file,
and things that are generic to the system (like PAGE_SIZE) are moved
to a public location in xous-rs::arch.
2025-05-11 12:50:02 +08:00
bunnie
4f14a67504 formatting changes due to changes in nightly rust
needed to get a clean check on gh
2025-02-01 22:26:40 +08:00
bunnie
95611d9598 This begins a series of commits to cleanup a static_mut warning
So in Rust 1.83, we now get a strongly worded warning telling
us to really, really don't use static muts. They aren't wrong,
except that in some places like the kernel we have few options:
we are conjuring pointers out of thin air, creating memory mappings,
and then doing things with them that are hard for the compiler
to reason about.

I think the newly minted warning was made because the intention
is that we could use the new fancy `const` semantics to take
the place of static mut usage by wrapping things in UnsafeCell,
and I think maaaaybe in some
cases this could apply here, but as a simple example a dive
into the kernel debug UART indicates that to initialize the
shared variable we have to allocate pages in the page table,
which involves calling the memory manager and doing some
decidedly non-const type of things. So one option is we could
just push the debug UART initialization into the loader and
paper over the whole thing by pretending it's static.

Instead of that, we adopt a pattern of casting all our static
muts to a raw pointer, and then back into what we want. The
cast to raw pointer is like an "uber unsafe" marker that says
"no we really mean that this pointer is where it is and we
conjured it out of thin air and we promise that the behavior
is defined and values are representable, etc.".

In general we're fairly judicious about the use of static
mut in the kernel, and when in the kernel there's no thread
pre-emption (although we could take an interrupt or page
fault) so generally we are single-threaded. The trickiest
spots are when we have to take a page fault while handling
a page fault (for example, allocating a new L1 page table
entry would require something like this) but this code path
is fairly carefully vetted.

So instead of just doing a global lint silence, we use an
`&raw` idiom to call out the fact that we're doing something
naughty wherever we do it, which makes the compiler "happy"
(for now) while still making the code ugly enough that it
looks sufficiently scary and you have to apply some
cognitive burden to even reason about what's going on,
which I *think* is the intention of Rust in this case.

Basically you get a get out of jail free card but you can't
simply wear it on a lanyard and pass through the gate -- every
time we need to use it, we have to do a little dance and
wash ourselves in the waters of unsafety and recite the
mantras about defined behavior, representable numbers, thread
safety, etc.
2024-12-02 18:55:18 +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
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
3cf79dbbd4 fix typos, adjust debug 2024-05-28 20:26:57 +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
a799e4b09d make all other allocs possibly oomable 2024-05-26 22:57:53 +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
a677824160 improve debug output on entry/exit from irqs 2024-05-21 01:11:58 +08:00
bunnie
b684420d28 pass the masked address to alloc_page
was accidentally passing the whole address before, which was
causing the LSB's that are assumed to be empty to muck up
some page table computations.

Also make sure old PTE entries are properly masked when recycling
flags.
2024-05-21 01:10:23 +08:00
bunnie
d7a8671e7e allow a process to identify itself
this makes debugging code a lot more ergonomic. I don't think
this impacts security...
2024-05-21 01:07:59 +08:00
bunnie
c412f44b51 quiet down debug in the irq routine 2024-05-18 00:24:25 +08:00
bunnie
c06612e43e lock down some key pages
- no swapping of kernel pages
- mark L1 PT's properly in the memory allocation table
  (was accidentally marking them with the VA of the first address
   allocated)
2024-05-16 03:53:07 +08:00
bunnie
1b0fc181a5 ensure process state is correct on errors; remove excess mmu flushes 2024-05-15 02:41:15 +08:00
bunnie
b86ee4b036 move irq-renable as late as possible; add helper function to access irq state 2024-05-15 02:40:31 +08:00
bunnie
8824372101 make debug a little more compact for the renode swap target 2024-05-13 21:02:32 +08:00
bunnie
0fca04f14e swapper needs write privs to the lent page
encryption is in-place to save on memory
2024-05-13 19:18:49 +08:00
bunnie
9b89bde46a refactor alloc API
instead of sending scalar messages on every page alloc/free, which
is a lot of traffic, introduce an API where the swapper can request
a snapshot of the alloc status by mapping the kernel's alloc
table as a read-only structure into the swapper's memory space,
and then invoking the swapper in its interrupt context to read that out.

The structure is unmapped on return from the context.

additionally, a running tally of free space is now maintained
and this can be queried with a fast syscall.

Thus, the normal workflow is the swapper would have a timer that
periodically queries the kernel's free space level, and when it
falls below a critical amount, it will invoke the expensive snapshot.

this can also be extended so that the kernel can call into
the swapper's interrupt context with a "help, OOM imminent"
message down the road.
2024-05-13 13:59:17 +08:00
bunnie
84d42460eb correspending kernel changes for run time page tracker split
memory alloc table split into RAM region and everything else ("extra")
2024-05-12 20:23:29 +08:00
bunnie
a3e55834e9 checking in the corresponding kernel changes to the RPT type alias 2024-05-12 16:28:14 +08:00
bunnie
1f12a97b64 cleanup debug 2024-05-08 07:22:43 +08:00
bunnie
77cfc34f59 make panic outputs in hex
everything else is in hex, why should these be in decimal...
2024-05-06 18:47:11 +08:00
bunnie
f635917658 fix typo 2024-05-06 02:06:15 +08:00
bunnie
4db82e01d8 retrieve tid as well as pid when invoking swapper 2024-05-04 02:01:56 +08:00
bunnie
feefb57791 cleanup some debug output 2024-05-04 02:01:38 +08:00
bunnie
39a427e1b0 improve debug output 2024-05-01 14:27:31 +08:00
bunnie
5f425ebc56 expand flags scope and fix swap test 2024-05-01 14:27:06 +08:00
bunnie
88a9854e54 add swap flags to debug output 2024-04-30 18:35:54 +08:00
bunnie
863f17652d broaded scope of conditional compilation 2024-04-28 02:57:04 +08:00
bunnie
ecf2396d0c put debug prints behind debug flags 2024-04-28 02:41:29 +08:00
bunnie
73c834d067 start debugging of swap in kernel
switching contexts to bringing up hardware.
2024-04-22 10:58:37 +08:00
bunnie
cc75520bc2 fix missing commands in non-swap path 2024-04-01 18:11:35 +08:00
bunnie
7d38d1761e add missing config flags 2024-04-01 15:58:16 +08:00
bunnie
ec439a38d4 handle both cases in the irq return handler
differentiate between the case that we got here via
a page fault, or a syscall, and handle appropriately
2024-04-01 14:08:15 +08:00
bunnie
2f23225b9d update API for advise alloc 2024-04-01 14:07:43 +08:00
bunnie
0e756003a1 debugging around the swapper protected context calls 2024-03-31 17:25:47 +08:00
bunnie
504253a033 more tid recording 2024-03-31 17:25:05 +08:00
bunnie
28b415cb27 handle swapped pages and allocation advisories 2024-03-23 11:59:31 +08:00
bunnie
14364e09c6 ensure compliance with unsafe conditions on exit_blocking_call() 2024-03-23 11:59:31 +08:00
bunnie
47a16b6ce4 add RETURN_FROM_ISR magic address
this is picked to not conflict with other addresses used by
the ARM implementation. I think it should be OK?
2024-03-23 11:59:31 +08:00
bunnie
26047bf956 add the routine to evict a page 2024-03-23 11:59:31 +08:00
bunnie
6f18a0ed21 add trampoline to return from swapper 2024-03-23 11:59:31 +08:00