Commit graph

10340 commits

Author SHA1 Message Date
bunnie
4a2234f539 XIP works with some processes, but not others
it works with e.g. shellchat, but not vault.

still scratching my head on what's gone wrong -- it's
crashing in the pre-boot, which means something is not
mapped right for some case that wasn't caught in the
earlier testing.
2023-02-11 01:42:04 +08:00
bunnie
68c9865072 fix the assumption about all alignments being identical
figured out a way to modify the trait so that alignments
are 0 by default, and only set/reported for IniF,
on a per-process basis so if for some reason the alignments
change we should be OK.
2023-02-08 04:57:52 +08:00
bunnie
29f050a8ad fix alignment for IniF region so page mappings are 1:1
Turns out, the pointing end of the stick for ELF sections don't start
at a page boundary. For example:

5    IniF: entrypoint @ 0001e42e, loaded from 000440f4.  Sections:
    Loaded from 000440f4 - Section .rodata        16924 bytes loading into 000100f4..00014310 flags: NONE
    Loaded from 00048310 - Section .eh_frame_hdr   1772 bytes loading into 00014310..000149fc flags: NONE
    Loaded from 000489fc - Section .eh_frame       6004 bytes loading into 000149fc..00016170 flags: NONE
    Loaded from 0004a170 - Section .text          59876 bytes loading into 00017170..00025b54 flags: EXECUTE
    Loaded from 00058b54 - Section .sdata            48 bytes loading into 00026b54..00026b84 flags: WRITE
    Loaded from 00058b84 - Section .sbss             48 bytes loading into 00026b84..00026bb4 flags: WRITE | NOCOPY
    Loaded from 00058bb4 - Section .bss             516 bytes loading into 00026bb8..00026dbc flags: WRITE | NOCOPY

Here you can see, the data is "loading into" 0x100f4, not
0x10000. The original PR would align things to a page, which means
you'd still have an offset mismatch if you tried to map these directly
over.

This patch causes IniF to insert extra padding to target
the offset necessary for the MiniElf to map 1:1.

An important assumption is the offset is constant across all
programs being linked. This seems to be the case, but, if this
assumption breaks, then the padding will also break.
2023-02-08 04:47:29 +08:00
bunnie
4fa4becc58 fix #310 + revert other "fixes"
Turns out the testbench failures are due to the testbench
being out of date. OpenSK is correct, the tests are wrong.

See discussions here:

https://github.com/google/OpenSK/issues/586
https://github.com/google/OpenSK/issues/584
https://github.com/google/OpenSK/issues/582

We'll await updates to the test tool and fold those into CI,
and leave the current failures standing.
2023-02-07 23:03:29 +08:00
bunnie
9889856ede page-align processes within the kernel image 2023-02-07 21:10:23 +08:00
bunnie
279b2f71a4 chore: prep release notes for next release 2023-02-07 20:57:56 +08:00
bunnie
fbae0f31f4 fix backup checking without passwords 2023-02-06 16:56:18 +08:00
bunnie
41a34ffda0 bump release URL list in restore script 2023-02-06 16:00:18 +08:00
bunnie
ad5296e3b6 bump verifiers 2023-02-03 00:13:34 +08:00
bunnie
053bc8a06f bump kernel rev 2023-02-03 00:12:57 +08:00
bunnie
0b8d6d2e4a
Merge pull request #317 from betrusted-io/fix-atomics
kernel: fix atomic operations
2023-02-02 23:32:16 +08:00
Sean Cross
dc097e32d8 kernel: fix atomic operations
Atomic operations were previously broken. RISC-V breaks atomic
operations into multiple instructions, and there is some state kept
between those instructions. This state is not visible, and is internal
to the processor.

We were ignoring this state, which resulted in inconsistencies
throughout the system. The following sequence was possible:

1. A thread loads a value, and obtains the `reservation set`
2. A context switch happens on the following instruction
3. A different thread loads the value, modifies it, and continues
4. A third thread (or a different process) loads a value and obtains the
   `reservation set`
5. The original thread runs, sees the `reservation set` is held, and
   updates the value, clobbering what the second thread did in #3

A workaround for this is to perform a dummy `sc` as part of the context
switch. This invalidates any atomic operations that may be pending.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-02-02 23:10:12 +08:00
bunnie
935b1a17a4 bump release notes 2023-02-01 23:21:25 +08:00
bunnie
a7dd88dd8c bump verifiers 2023-02-01 22:46:05 +08:00
bunnie
8b7876360f bump kernel package version 2023-02-01 22:45:37 +08:00
bunnie
d14b81d7b7 bump release notes, again 2023-02-01 22:42:38 +08:00
bunnie
870483c555 bump release notes 2023-02-01 22:42:04 +08:00
bunnie
6c20d63822
Merge pull request #313 from gsora/fix/transientdisk-cleanup
`transientdisk` cleanup
2023-02-01 22:25:33 +08:00
bunnie
c1659f2de9
Merge pull request #316 from betrusted-io/messages-late-return-redux
kernel: syscall: fix restoring thread id
2023-02-01 22:24:36 +08:00
Sean Cross
043365ac82 kernel: re-add set_last_thread
git somehow dropped this function during the merge, which would have
made things very sad.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-02-01 20:45:43 +08:00
Sean Cross
c7f5ad25b1 kernel: syscall: fix restoring thread id
The previous patch didn't properly restore thread IDs when switching
contexts -- there were spots where we missed things, and spots where we
were double-borrowing.

Fix these corner cases.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-02-01 20:43:45 +08:00
bunnie
efa4ab1f70 commit bumped susres version 2023-02-01 15:04:49 +08:00
bunnie
9b94033a4a change suspend timeout behavior
When suspend fails to happen within the designated time,
instead of forcing it, return a failure code so we can retry it
again later.

In testing, this seems to be a very reasonable approach, because
sometimes servers are just too busy to do a suspend, and just
waiting a couple seconds until eg some file commits are done
makes everything work much better.
2023-02-01 15:02:40 +08:00
bunnie
9140beef24 clear some warnings in hosted mode 2023-02-01 15:01:19 +08:00
bunnie
5fabcd2ca7 track failed suspend attempts 2023-02-01 15:00:22 +08:00
bunnie
b9ab411e33
Merge pull request #315 from betrusted-io/revert-314-messages-late-return
Revert "Give servers their full quantum"
2023-02-01 14:08:46 +08:00
bunnie
680ddd1c58
Revert "Give servers their full quantum" 2023-02-01 14:08:16 +08:00
bunnie
119296ed5b
Merge pull request #314 from betrusted-io/messages-late-return
Give servers their full quantum
2023-02-01 13:46:01 +08:00
Sean Cross
63e6deae53 kernel: save current thread at context switch
Note the current thread in the original process when its quantum
expires. This will allow us to clean up after ourselves when a context
switch occurs, and will help to prevent thread starvation.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-02-01 10:46:25 +08:00
Sean Cross
4ec43363f5 kernel: don't always context-switch on message return
Currently, returning a Message (e.g. a Scalar1, Scalar2, or
MemoryMessage) always results in a context switch from the server to the
client. This is what makes these syscalls cheaper.

However, this results in process starvation. For example, if three
processes send a message to a server, then the server will only be able
to respond to one of those messages at a time. This works well with a
lightly-loaded system, but quickly falls apart when many threads are
running.

Keep track of which process and thread were originally switched to as
part of the `SwitchTo` call. If the Server is responding to a message
and owns the current quantum, don't immediately switch to the Client
thread.

Signed-off-by: Sean Cross <sean@xobs.io>
2023-02-01 10:19:07 +08:00
Gianguido Sorà
dca88da039
transientdisk: move flash drive implementation in a separate file
Also encapsulate the entire MemoryMessage handling.
2023-01-31 22:55:04 +01:00
Gianguido Sorà
14679efb0b
transientdisk: clean up us fence macros
Just use "mass-storage", and add a log message to inform the user they
compiled a kernel image without `--feature mass-storage`.
2023-01-31 22:37:46 +01:00
bunnie
981abbf503 cleanup some comments, tweak the stress test
the battery switchover behavior is guaranteed by the time management
servers, so we don't redundantly set it in the alarms.
2023-02-01 03:51:09 +08:00
bunnie
a4c97a410c handle time panics more gracefully; work around RTC HW issues
- don't hard panic if the time seems wrong; just clear
the PDDB entries, and move on. This at least allows the
user to intervene to fix the time, intsead of insta-crashing
when anything seems wrong and depriving users an opportunity
to fix anything

- fix HW derpiness by introducing some dummy reads during
the resetting of the hardware process.

One thing I wanted to do was to have the RTC always powered
off of the battery. This is not a default mode but it's an
option. In theory, this is a more efficient because anyways,
VDD comes from VBAT, right? However, the RTC hardware gets
a little side-eye when VBAT is higher than VDD most of the
time and reports a strange error code. The power savings
is miniscule -- some tens of nanowatts -- so I'm not going
to fight with the RTC hardware quirks anymore.
2023-02-01 03:19:32 +08:00
bunnie
e4caa84463 work around some more RTC derpiness
This isn't in the spec sheet, and I can't figure out why it
is the case, but emperically it is the case.

The RTC is much more reliable at absorbing values writen
to it if they are immediately read back.

I suspect it may have something to do with their internal
synchronizer that locks out updates to registers while
any of the time registers are being updated. It doesn't say
that a read is required to clear that lock, but empricially
sometimes I find the RTC gets "hung" returning 0xFF all
the time, unless some dummy reads follow up writes.
2023-02-01 03:17:31 +08:00
bunnie
c50c9358c5 add option for disabling repeated start condition
A very tiny bit of fine print in the RTC datasheet
indicates that the RTC hardware unit is derpy and it does
not support repeated starts. In this case, a stop condition
must be issued between a write that sets an address, and
the subsequent read transaction.
2023-02-01 03:15:53 +08:00
bunnie
8c08cf8f91 make susres stress test a bit harder 2023-02-01 03:14:57 +08:00
bunnie
7cf448c0d1 fix more corner cases on suspend/resume vs i2c mutex 2023-01-31 19:11:47 +08:00
bunnie
f860f7bb33 add a mutex guard around I2C transactions
Individual I2C register reads and writes, even if to multiple bytes,
are atomic.

However, some i2c operations require multiple reads and writes
to be strung together without interruption for them to be valid.
A "mutex" is added, which if a program using I2C calls it prior
to their I2C operation, it will block if another program is
already using the I2C block for an uninterruptable series of
operations. The caller will automatically be unblocked once
the untinterruptable transactionts are completed.

Note that this is a collaborative exercise, a caller can still
try to initiate an I2C operation without getting a mutex first,
in which case it could interrupt another block that is doing something
uninterruptable. At the moment this merely generates a warning on
the console, but eventually, this will become a panic.
2023-01-31 18:22:10 +08:00
bunnie
e97c99b435 make the susres test a bit more difficult to pass 2023-01-31 18:21:55 +08:00
bunnie
19667800cb modify sleep stress test timing
now that the initiate suspend call is working right, we need
to give a little bit of time for the i2c command to issue to
setup the wake alarm before issuing a suspend call. otherwise
we end up with a scrambled RTC unit.
2023-01-31 17:10:08 +08:00
bunnie
b75e048702 commit bumped versions 2023-01-31 16:42:46 +08:00
bunnie
7ca1ece03d quiet down debug 2023-01-31 16:42:36 +08:00
bunnie
3ee4bb2252 fix suspend ack behavior, now that blocking scalar messages return quantum
before, blocking scalar messages didn't return their quantum.

so, in order to get a resume message working, some hacks were done.

now that it works, the suspend core routine has been refactored to
properly acknowledge the resume *on resume*.
2023-01-31 16:39:00 +08:00
bunnie
2d74630bdf add some prints to help debug susres issues 2023-01-31 16:20:33 +08:00
bunnie
413dc51a35 bump lockfile 2023-01-31 16:14:39 +08:00
bunnie
ace8dd649a bump verifier versions 2023-01-31 16:14:28 +08:00
bunnie
404301dd0b reflect improvements in cargo 2023-01-31 16:12:45 +08:00
bunnie
bbc9695086 bump susres version 2023-01-31 16:11:44 +08:00
bunnie
cc97f157e4 bump kernel rev for publication 2023-01-31 16:10:53 +08:00