Commit graph

834 commits

Author SHA1 Message Date
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
82da94b3da add code to try to handle the case of swap in IRQ
the cases are delineated but still getting a fault on return
from the handler.

also optimize out a memory space swap that was incurred due to
inappropriate abstraction boundaries.
2024-05-15 04:26:08 +08:00
bunnie
5f127b4548 create swap resume functions; differentiate irq context calls
- invoking the swapper context is different in an IRQ because
we don't want to modify the runnability states of the original
process

- didn't want to make a custom version of swap resume but
with the IRQ issue it made sense. In the process of doing this,
we can also optimize out a memory space transition, so it's
probably worth it even if we're not entirely going down the
right path to fix the bug of interest.
2024-05-15 04:24:19 +08:00
bunnie
900d829bf4 a lot of bug fixes in the core kernel swapper
probably should have done this in smaller commit chunks but it
was hard to say if this was going in the right direction until now.

at the moment, system can boot and evict quite a bit of memory before
hitting a panic. The current state is that we panic on returning
from an interrupt handler that hit a swapped page.

This is a pretty decent point to check point everything. hopefully
this next arc will be a bit cleaner.
2024-05-15 02:44:11 +08:00
bunnie
0fbedcebbf add the skeleton for the kernel OOM handler 2024-05-15 02:43:06 +08:00
bunnie
2b05626b69 add context switching debug option 2024-05-15 02:42:29 +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
27d7fb414c add debug on evictpage 2024-05-15 02:39:58 +08:00
bunnie
ad9ef3dedc cleanup comments and fix ordering of events 2024-05-13 21:05:46 +08:00
bunnie
8824372101 make debug a little more compact for the renode swap target 2024-05-13 21:02:32 +08:00
bunnie
327205edb5 release page relies on a physical address, not a virtual address. 2024-05-13 21:00:17 +08:00
bunnie
235806025c clarify api names; add evict target pages; more error checking on eviction 2024-05-13 19:20:59 +08:00
bunnie
0847f99433 swapper abi fixes
- evict error checking - reject requests to swap kernel or swapper
- add target amount of pages to evict on oom handler
2024-05-13 19:19:50 +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
74f75e1ef5 re-org swap code for readability, add oom_doom routine
some thought needs to go into when and how we call oom_doom
but let's test more core functionality of the swapper before we
worry about that. I can think of several places where we could
use that call, the main tricky bit is that oom_doom diverges
and so wherever we patch it has to be able to resume. If we put
it into e.g. somewhere in the main memory alloc loop, the trouble
is we would have to track all of the multiple places that we
could have arrived there...ideally we can find a single spot
to patch this, with a clean entry and exit path.
2024-05-13 17:24:35 +08:00
bunnie
a07ab0e121 update comments and add license headers 2024-05-13 14:21:53 +08:00
bunnie
dcef549099 move SwapAlloc to the swap module 2024-05-13 14:15:38 +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
1112ef5df6 remove unused function (forgot this arg was already available) 2024-05-08 07:22:21 +08:00
bunnie
a58a8dc438 cleanup some debug 2024-05-08 07:21:06 +08:00
bunnie
ee0b1a042c optimize kernel-side alloc advisories; cleanup some APIs 2024-05-08 07:20:33 +08:00
bunnie
4f471544bd add nesting depth = 2 for swapper ops
I think that structurally we might never exceed a nesting depth
of 2, but there are some specific cases where an alloc can call
an alloc in the kernel (e.g., having to create a new superpage
in the midst of a routine alloc), therefore, we have to handle
some nesting.

There's also chance that maybe nesting could be due to race
conditions or self-circular behavior in the swapper, but ideally
we avoid that entirely because we can't handle non-structural,
unbounded nesting of re-entry to the swapper routine.
2024-05-08 00:57:10 +08:00
bunnie
43c452bf97 add a call to get the free memory status from the kernel
this will be helpful for debugging our page tracker
2024-05-07 04:12:46 +08:00
bunnie
9e66c1bee2 commit the version bump 2024-05-07 01:03:05 +08:00
bunnie
b1cc676345 absorb ABI changes 2024-05-07 00:56:35 +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
09b2b29074 remember tid for swap-read; do PID dance for resume abstraction
We want to use the finish_callback_and_resume() function because
it's well-tested and sets up everything just right, but it expects
that we're coming from another process. Unfortunately, in the
middle of all of this, we need to map a page back into the
destination process' memory space, so we end up starting from
the swapper's memory space, changing into the destination process'
memory space, then mapping the page, then changing back into
the swapper's memory space, then using the finish_callback_and_resume()
call.

I think the impact might not be *that* bad, mainly it's a TLB
miss and the PTW isn't super bad, and this comes after a disastrously
expensive decrypt-from-RAM operation -- so probably not worth it
to angonize over optimizing this bit at this point, and stick
with well-tested primitives.
2024-05-04 01:54:23 +08:00
bunnie
dc0244ca35 cleanup init stuff now that args are mapped into memory 2024-05-02 22:08:48 +08:00
bunnie
61128cb25f remove swap init call, as it is no longer needed 2024-05-02 22:08:08 +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
a732eed679 make kernel aware of the IniS type
this should now introduce a crash in the kernel when an IniS
process is in the image set; previously we didn't try to
schedule and run them.
2024-04-06 07:47:18 -07:00
bunnie
cc75520bc2 fix missing commands in non-swap path 2024-04-01 18:11:35 +08:00
bunnie
d9a27ea3d7 remove unnecessary print 2024-04-01 18:11:22 +08:00
bunnie
7d38d1761e add missing config flags 2024-04-01 15:58:16 +08:00
bunnie
b3f695dbc2 fix missing config flag 2024-04-01 15:57:50 +08:00
bunnie
d6b33159a5 stage version pin bump 2024-04-01 15:46:26 +08:00
bunnie
95a10e93ca cleanup warning when swap is not used / hosted mode 2024-04-01 15:38:51 +08:00
bunnie
a37b2c06e1
Merge pull request #512 from betrusted-io/swap
WIP: Encrypted Swap
2024-04-01 00:23:43 -07:00