Commit graph

7256 commits

Author SHA1 Message Date
bunnie
3cf79dbbd4 fix typos, adjust debug 2024-05-28 20:26:57 +08:00
bunnie
e5ac160c7c demote panic to warning on edge case of re-assigned swap page
Found a case where this is actually "legal" - when you have
a piece of memory that is allocated without going to swap,
then lent, then swapped, then released before being read back
into memory. In this case, the release will clear the page without
notifying the swapper of such an event.

This case is mostly harmless -- the biggest problem is that we
leak swap due to pages that are released while swapped. This
tends to happen mostly with memory messages, and there is a high
re-use of addresses in this situation so I think the leakage
is not bad.

However, we continue to print the warning. If it turns out
that the leakage is cumulative, we'll have to come up with a
way to report this situation back to the swapper -- but it's
fairly disruptive, because it also forces us to do a full PT
walk and check on release plus send a message to the swap context
which is another chunk of code and syscall.

My working theory is this will be a "couple of pages" that circulate
around in a messaging pool inside swap memory, which is fine because
it doesn't impact main memory usage and swap memory is fairly
ample.
2024-05-28 16:54:45 +08:00
bunnie
bed9252614 suppress warning when debug is turned off 2024-05-28 16:54:18 +08:00
bunnie
21fab71558 snapshot current testing config in xtask 2024-05-28 02:49:50 +08:00
bunnie
4005b0f1ca update abi mappings and clear out a comment that i think is old 2024-05-28 02:49:23 +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
66fe45edf9 make emulation more deterministic; add autologging of UARTs 2024-05-27 23:07:03 +08:00
bunnie
42d30dc799 remove com bus handler in case it is making things not deterministic 2024-05-27 23:06:42 +08:00
bunnie
5813cee4f7 fix debug va 2024-05-26 23:14:41 +08:00
bunnie
c9ac6142b5 make oom doom a feature
even though we can do it, I am not sure we should.
2024-05-26 23:01:21 +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
de7d876820 more missing prereqs for gam op 2024-05-26 12:13:13 +08:00
bunnie
fb502a8073 debug cleanup 2024-05-26 12:12:58 +08:00
bunnie
2a1552b628 bring renode emulator params closer to in line with cram target 2024-05-25 14:35:17 +08:00
bunnie
3146e7c379 cleanup documentation in the swapper
also re-organize code so there is less duplication.
2024-05-25 14:34:43 +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
160acec326 checkpoint cram-console re-org before doing kernel re-org 2024-05-25 00:20:17 +08:00
bunnie
01e04280b9 cleanup test/debug a little bit 2024-05-25 00:20:04 +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
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