Commit graph

54 commits

Author SHA1 Message Date
bunnie
3f869ca389 bump utralib version for publication 2026-01-29 19:12:00 +08:00
bunnie
fba011db3a commit version bump so that we may publish our packages 2026-01-08 03:04:19 +08:00
bunnie
e27b30d818 fix edge case in swapper
A particular edge case was finally reproduced & fixed. The edge
case occurs when a swap is triggered while handling an interrupt,
and an OOM happens during the context switch to/from the interrupt.

The background on this is that the hardware drivers for the swapper,
as well as much of the logical heavy lifting on e.g. what pages to
swap out, live in a userspace process known as xous-swapper.

The userspace process has to run free of interrupts - when you're
OOM'd or trying to swap, interrupts should not happen. The way to
do this in Xous is to run that code inside an interurpt context,
as interrupts are not interruptable.

Thus, the xous swapper userspace consists of two halves: a regular
userspace stub that provides some amount of control/debug over
the swapper, and a handler that gets run in a "pseudo-interrupt"
context.

Like all other interrupts, the handler "borrows" the stack of the currently
running thread - interrupt contexts don't have an explicit stack, they
just grow on top of the current stack of the current thread in the
current process at the time of the interrupt.

This is broken because when you have a swap event inside an interrupt
context, there are conditions where you might not have a stack. What
was in fact happening is that the stack pointer was being orphaned
as being the "exception stack" - which is a temporary location,
only accessible by the kernel, used for storing all the registers
going into and out of exceptions. Since no stack pointer is set up,
the moment the userspace starts to run and spill its registers to
stack, the system trips a "nested swap" event, which leads to a panic
because this is not allowed.

The fix to this is to devote two hard-wired pages, mapped in the
loader, to be the swapper's private stack area. Instead of behaving
like an interrupt and borrowing the caller's stack, the swapper instead
goes back to its hard-wired stack to do all the processing.

This should also improve the performance of swap handling in some
cases because we can now guarantee the stack is always in-memory
and doesn't need to be swapped in during swap processing.

One complication is that the "reserved memory" that the swapper
puts aside in case it *does* need to allocate extra pages during
handling can't be freed at the top of the OOM routine. Thus if
the swapper ends up using new pages, we should expect yet another
crash.

However, in practice, this doesn't seem to happen, because the
cases in which we hit needing a new page are typically related
to cases early on in boot where superpages/new page table entries
are being allocated, or if we're growing the heap that passes
data back and forth between swap and userspace. Because this call
triggers in such a specific condition, I hypothesize that actually
in practice it should generally be able to run without allocations.

One case where maybe it could hit an allocation is if the swapper
hit, for the first time, in an interrupt handler that was swapped
out, and never hit before, and the interrupt handler needed a
superpage to be allocated, thus triggering an allocation request
for a new PTE or two. I think this is probably pretty unlikely, but
if we do hit it, the fix would be to, for the purposes of targets
with "swap" enabled, to mark unmap_memory and map_memory to be
legal syscalls in interrupt contexts. These are normally illegal
because interrupts should always return - and these calls could
potentially fail or block. However, I think in this case it's
a trade-off between "we should be failing if we run out of memory"
and that failure being a potentially incorrect behavior that is guarded
against by a runtime check to discourage such calls.
2026-01-08 02:08:03 +08:00
bunnie
d874c3e5c2 commit for version bump 2025-12-16 02:02:37 +08:00
bunnie
fcc6fc5538 add chaffing feature to the swapper
the main imagined attack vector on the swapper is recovery
of the AES key through side channel analysis.
2025-12-02 01:06:36 +08:00
bunnie
dbb0a75118 bump versions
have to absorb a version change due to xous-semver change

might as well also update the utra/svd generator dependencies
since that's been held off for a long time now.
2025-10-06 13:23:18 +08:00
bunnie
1255bf12d9 FLAG DAY: fix all names to harmonize around 'bao1x'
The code base had evolved through several code names, interim
names, company names and chip names that alternatively did or did
not exist.

Baochip is the definitive name of the company, and the Baochip1x
(full part number BAO1X2S4F-WA) is the definitivey part number of
the SoC. For convenience, the part number is shortened to 'bao1x'
in most feature flags and variable references.

This commit fixes all of the odd names and removes some unmaintained
early targets.
2025-09-18 21:25:51 +08:00
bunnie
75a9373fea fix AES dependencies so that the correct acceleration is enabled
This relies on a trick I was not aware of previously, which is
that transitive dependencies absorb the additive set of features
enabled within a crate.

see

https://doc.rust-lang.org/cargo/reference/features.html#feature-unification

for the full description. but basically by referring to the feature
required in "aes" despite not being used in the crate but pulled
in by aes-gcm-siv, i can ensure that the transitive dependency
is in fact used.

I think this was always there but previously I just didn't understand
it correctly or didn't use it right when I tried to deploy it, but
this time I think I got it right.
2025-09-07 11:50:12 +08:00
bunnie
1810825744 add block erase routine 2025-05-21 10:20:23 +08:00
bunnie
5d288ec9a8 cleanup dependencies to allow for hosted builds 2025-05-18 09:25:33 +08:00
bunnie
9b13f46741 cleanup notes in toml file so i don't forget to toggle a loader flag 2025-05-18 04:41:21 +08:00
bunnie
de06522499 cleanup debug statement 2025-05-18 04:40:38 +08:00
bunnie
5db2b3449e remove unused "spinor" implementation now that access is delegated to swapper
the explicity "spinor" interface is no longer needed (or even
compatible!) because we now have the swap-mapped spinor layer

the main concern I have at this point is there is a potential race
condition between marking a page as dirty and when the data is actually
updated on the page. Some locking might be necessary to fix this,
but possibly it might be sufficient just to mark a page as dirty
immediately before it's written?

another option might be to handle the writes in an interrupt context
so that the write data + dirty mark are atomic. Need to think about
this a bit.
2025-05-16 19:16:20 +08:00
bunnie
22a72125bd add precursor-hal to dependencies for xous-swapper 2025-05-16 19:05:52 +08:00
bunnie
e2379821e6 republish xous-rs to fix cargo test 2025-05-11 15:36:17 +08:00
bunnie
8a4959056b bump version for xous crate update - commit so we can publish crates 2025-05-11 14:45:24 +08:00
bunnie
48c6ce7232 cleanup non-spinor config for xous-swapper
this allows us to build configs that aren't in the dev path
without errors
2025-05-04 17:00:08 +08:00
bunnie
b2098916c7 start to add a spinor driver into xous-swapper
the hardware interface for SPIM is shared between both
RAM and FLASH, therefore, the drivers need to be co-located
in the same crate.
2025-05-04 03:31:15 +08:00
bunnie
2e060e7bc3 bring xous-swapper up to api spec 2025-02-20 15:07:11 +08:00
bunnie
fa067f1137 retrofit swapper so that its print function can be selected out
so that we can share app uart with other processes that need it for debug
2024-12-22 00:32:40 +08:00
bunnie
45a8eb2227 stage tomls for version bump: try_send added to xous-ipc 2024-12-16 18:50:11 +08:00
bunnie
e90bd02cae note that debug-print needs to be mutually exclusive
...with other crates that might want to use the application
console, e.g., the USB crate.
2024-12-16 18:03:11 +08:00
bunnie
93b9ec00bf bump version numbers on all the packages so we can absorb num-derive changes 2024-12-02 19:14:11 +08:00
bunnie
83e26ff4c7 update num-derive dependency
this became mandatory in 1.83 to remove warnings. I think it
should have no impact on functionality.
2024-12-02 18:52:59 +08:00
bunnie
d78899ca74 implement retry on SPIM failure
somehow, the retry still *fails* - to be looked into in the future
2024-11-19 22:17:19 +08:00
bunnie
84f88e9e65 configure xous-swapper to point to board files 2024-10-02 01:45:47 +08:00
bunnie
f494da21cc absorb new xous-ipc version 2024-09-23 22:05:50 +08:00
bunnie
75954de8d6 commit the version bump 2024-09-23 01:46:25 +08:00
bunnie
4c7c9312c1 change xous-ipc api to 0.10.0 2024-09-23 00:24:48 +08:00
bunnie
311154e231 absorb version bump 2024-06-27 00:26:12 +08:00
bunnie
0fd6ad7c0e
Merge branch 'main' into new-rust-warnings 2024-06-14 19:14:02 +08:00
bunnie
0036c46ea1 clean up warnings in the latest rust 2024-06-14 19:10:18 +08:00
bunnie
a360f3ee52 bump xous pins for RawTrng API 2024-06-13 15:49:35 +08:00
bunnie
f313b8a866 cleanup test procedure and dependencies 2024-06-06 22:38:22 +08:00
bunnie
35e7cf3a5b bump xous dep revs 2024-05-29 02:07:06 +08:00
bunnie
6303b9a075 turnoff debug spew on swapper userspace
haha like this is going to be default for any period of time...
2024-05-28 20:31:42 +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
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
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
751042e202 quite down debug in swapper 2024-05-21 02:56:27 +08:00
bunnie
2ea6c83bf0 implement the userspace side of hard-oom and oom-doom handlers
see the comments added in the main.rs file for a discussion of all
the things.
2024-05-21 01:42:19 +08:00
bunnie
e3b3960a40 add a "debug-verbose" option on the swapper
we'll surely need this again someday...
2024-05-16 03:58:03 +08:00
bunnie
1bd07d7657 remove dependencies that we decided not to use 2024-05-13 14:04:54 +08:00
bunnie
a031eeba4e add the skeleton of LRU tracking data
1. add a method to aggregate and export advisories into userspace
2. add an LRU cache to absorb the advisories

LRU cache still needs init'ing

aggregation method for advisories could be mirrored into the
kernel (sans heapless dependency) for even better efficiency...
2024-05-08 02:06:27 +08:00
bunnie
9e66c1bee2 commit the version bump 2024-05-07 01:03:05 +08:00
bunnie
61b781892e fixes for cramium target 2024-05-04 21:41:01 +08:00
bunnie
ce20fdff8b refactor the swapper to absorb the HALs developed for the loader
Remove the stand-in swapper functions we put in...oh god, so many
weeks, months ago...and replace it with actual battle-tested APIs
from the loader.
2024-05-03 16:05:58 +08:00
bunnie
8ef3692bf5 make the loader a depedency of the swapper 2024-05-02 22:19:09 +08:00
bunnie
d6b33159a5 stage version pin bump 2024-04-01 15:46:26 +08:00