Commit graph

7231 commits

Author SHA1 Message Date
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
40a2a2d76d re-use an opcode for internal kernel call 2024-05-24 23:58:41 +08:00
bunnie
d3a0416211 incur tech debt: susres sector hard-codes ram size 2024-05-24 23:58:09 +08:00
bunnie
8d0a1f2ae6 reminder to self about some tech debt 2024-05-24 23:57:47 +08:00
bunnie
0877b9b274 add more testing packages to precursor staging target 2024-05-23 16:51:45 +08:00
bunnie
3fd383a7aa approximate cram target better in precursor staging environment 2024-05-23 16:51:20 +08:00
bunnie
84ef3ed694 add thread reporting to irq entry 2024-05-23 16:49:39 +08:00
bunnie
870326a497 awful intermediate refactor of cramium-console
transitioning this from a mere test stub into something more fully
fledged, but encountered a problem in the kernel along the way.

so, we're committing this pile of poop so we can swap over to
a new branch and put out the kernel fire before resuming with the
refactor.
2024-05-23 14:51:48 +08:00
bunnie
34cfc7db5b temporarily allow more graphics server connections
this is for early testing and debug -- there's a note to
revert this in the console log once we're done with that.
2024-05-23 14:51:11 +08:00
bunnie
ab9b63c7f6 absorb dependencies from adding services to cram target 2024-05-23 14:49:26 +08:00
bunnie
4efd227b70 add an extra reserved page for the swapper
on cramium-soc an extra page of stack ends up being used to
accommodate the page buffer needed for SPIM implementation
2024-05-23 14:48:37 +08:00
bunnie
aa8d84f007 print a message if memory reads timeout 2024-05-23 14:48:11 +08:00
bunnie
6c74948f93 update note about swap 2024-05-23 14:47:37 +08:00
bunnie
3e58bda6ba try putting more services into the cramium target 2024-05-23 14:47:18 +08:00
bunnie
79484224f6 start the keyboard emulator service
the service isn't fully implemented but its existence allows
other processes to make forward progress on boot for testing
2024-05-23 14:46:07 +08:00
bunnie
622652393c refactor TRNG reseed code
refcell leads to some panics in multithreaded code.
Use an atomic usize to track reseed interval, which is a bit
safer.
2024-05-23 14:44:10 +08:00
bunnie
01a5d0aba9 create context list for cramium target 2024-05-23 14:42:16 +08:00
bunnie
1faaf2c092 note timeouts on read in the HAL driver 2024-05-22 18:15:03 +08:00
bunnie
818372a604 report timeouts during the SPIM test in the loader 2024-05-22 18:10:32 +08:00
bunnie
34e7474b80 add work-around for DAR-620
UDMA Rx busy bit seems to get stuck occassionally. This seems
to be aggravated if we insert a dcache_flush in the poll loop.

The current time-out code seems to mitigate the problem, but
I have low confidencne that this is a 100% solution. I have a feeling
we'll be revisiting this again soon.
2024-05-22 18:08:50 +08:00
bunnie
b3aed9f0c6 absorb new dependencies from new features 2024-05-22 02:34:00 +08:00
bunnie
fa707646dc incorporate the new APIs at the top level
also clean up crate names to conform with names used in other crates
2024-05-22 02:32:06 +08:00
bunnie
0fbf1ecf22 add TRNG user API
this is a shim on top of the kernel-owned TRNG port, which uses the
SID generator function to seed a ChaCha8 CSPRNG.  The CSPRNG is seeded
with 64 bits of randomness, and every 32 accesses to the CSPRNG it
gets re-seeded with 32 bits more randomness from the TRNG for better
forward secrecy.
2024-05-22 02:29:38 +08:00
bunnie
4c4e1c99c3 add keyboard API itself 2024-05-22 02:29:27 +08:00
bunnie
9767b29380 add hw drivers to HAL & keyboard driver
this is currently just a stand-in to provide API compat with
with precursor keyboards. eventually we'll need to patch the console
UART (which is output to the log crate) into the keyboard as
an injector source.
2024-05-22 02:27:34 +08:00
bunnie
7d6bd3f086 add api module for more HAL services & keyboard API
this is meant to emulate the Precursor API on cram targets
2024-05-22 02:26:24 +08:00
bunnie
1fa0a3de20 fix quantum timer to 10ms; adjust api names 2024-05-22 02:25:03 +08:00
bunnie
b1e3e81a6f add patches to GAM for cramium-soc compatibility 2024-05-22 02:24:10 +08:00
bunnie
bfef60a0b1 add a configuration that works
for some reason a debug-print is essential for the system to run
stably. It smells like we're violating some minimum time between
accesses of SPIM interface, or else we're encoutnering some weird
optimization bug.
2024-05-21 18:38:37 +08:00
bunnie
362bb4ff7e for some reason, these debug flags must be on for the target to run. 2024-05-21 18:07:35 +08:00
bunnie
c310f4831a a configuration that boots. 2024-05-21 18:07:23 +08:00
bunnie
e705dba13f quite down swap debug in loader 2024-05-21 17:57:41 +08:00
bunnie
32a9413f34 cleanup warnings when debug-print is off 2024-05-21 17:57:24 +08:00
bunnie
bae408b466 fix app_uart default memory mapping
was pointing to the wrong uart initially >_<
2024-05-21 16:33:11 +08:00
bunnie
71d7a2a3ae update api in test routine 2024-05-21 16:33:03 +08:00
bunnie
2e1ad6e1a4 remove T:Copy bounds on bzero
not quite sure why it is even there, might just be a thing from
really old code we never removed. Removing this allows us to
specify pointer types to non-copy elements, making Rust do
the hard work of figuring out how big of a block we need to zero.
2024-05-21 16:02:59 +08:00
bunnie
0153b3b96e allow guard memory to be differentiated across platforms 2024-05-21 16:00:56 +08:00
bunnie
9c90994bd5 reduce size of XIP region
in practice, we're not putting a 128M part out there, but merely
saving space for that amount of memory chews up 32k of page tracking
for something we will never use.

Tune that down to 64M, reducing the overhead to 16k. This also
matches the largest available HyperRam / FLASH part that we might
put into the XIP memory range.
2024-05-21 15:59:17 +08:00
bunnie
8b487361b2 clean up bzero
some errors were made in clearing memory because we weren't
using the Rust type system to our advantage. This cleans up
the phase 1 loader to use the native types of the block plus
the slice length we intend to create to block-zero the correct
region size.

also simplify mem::size_of to size_of
2024-05-21 15:58:10 +08:00
bunnie
f9867bdca5
Merge pull request #543 from betrusted-io/debug-build
bump xous-semver rev
2024-05-21 01:50:30 +05:30
bunnie
85a6f02c3f bump xous-semver rev
git tags now returns a 9-digit commit rev instead of 8 in some
versions of linux. This causes `u32` parsing of the rev to fail.
handle this.
2024-05-21 04:18:03 +08:00
bunnie
b02c159460
Merge pull request #542 from betrusted-io/debug-build
don't map errors so we can see what the underlying problem is
2024-05-21 01:35:27 +05:30
bunnie
80dbf071be don't map errors so we can see what the underlying problem is 2024-05-21 04:03:45 +08:00
bunnie
d22c1f51a6
Merge pull request #536 from betrusted-io/swap-opt
WIP: More swap
2024-05-21 01:21:34 +05:30
bunnie
e5452d3692 tune swapper; add candidate filtering
- make a hard OOM more agressive about clearing memory
- add a filter on OOM Doom to de-proritize code and message
segments, meaning unused heap/stack will tend to be swapped
before code gets evicted.

This can, of course, be tuned down the road!
2024-05-21 03:48:28 +08:00
bunnie
f0584e7f1d and test tuning notes 2024-05-21 03:48:05 +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