Commit Graph

44 Commits

Author SHA1 Message Date
Jeremy Soller 2aa4d8caf5 Merge remote-tracking branch 'origin/aarch64-rebase' into riscv64 2021-05-03 20:52:59 -06:00
Jeremy Soller a9bee0bbdc Require UTF-8 for context name 2021-04-28 20:03:12 -06:00
Jeremy Soller b26c3e0ae9 Make context name a RwLock 2021-04-28 20:03:05 -06:00
4lDO2 47c3b2269f Fix context switching.
Previously there was a triple fault, due to a combination of reasons
(e.g. rsp and rbp being ordered in the struct and in the assembly).

Now, the locks will be held __all the way until the new context__ has
been switched to, which completely eliminates any possibility that the
"pcid fault" originates here.

While I am unsure whether this will work, this could also be an
opportunity to be able to remove CONTEXT_SWITCH_LOCK fully.
2021-02-13 21:55:40 +01:00
4lDO2 ef4270e473 WIP: Attempt to rewrite switch_to in assembly.
This is due to a warning in more recent compilers, which forbid anything
but a single inline assembly block, in naked functions. It does
unfortunately triple fault right now, but I hope I may be able to fix it
soon.
2021-02-13 21:55:36 +01:00
Jeremy Soller 238702f7d1 Require UTF-8 for context name 2021-02-13 12:16:47 -07:00
Jeremy Soller b9f4a915ea Make context name a RwLock 2021-02-13 11:10:21 -07:00
4lDO2 44527a8340 Fix a very annoying multi_core data race*.
So, when I first introduced io_uring, it was not compiled with the
`multi_core` kernel feature, mainly to make development easier (I
thought). However, since io_uring allows multiple simultaneous system
calls, we cannot longer make the in-kernel contexts block, for example
when receiving a message from a pipe, if there can be multiple such
requests simultaneously.

This has required me to change WaitCondition into allowing multiple
simultaneous tasks; although, it introduces a potential race condition:
since a future can only return Pending and not block directly before
releasing the lock (condvar logic), we need some way to make sure that
nothing happens after the context finds out that it has to wait, and the
actual waiting. If a message is pushed in between, and the waker is
called (Context::unblock), just before it was going to block itself,
then we miss the message, and potentially cause a deadlock.

Fortunately, in order to block and unblock contexts, we need to
exclusively lock the context. So, what we can do to ensure that waking
while running is no longer a no-op, is to introduce a "wake flag", which
is set only if the context is currently running, and Runnable.

But, this still caused all weird kinds of hard-to-debug problems, with
arbitrary CPU exceptions and possibly memory corruption. The reason for
this, is that the context switching logic uses really unsafe operations,
which is why context switching (at the moment) requires an exclusive
lock. Before this commit, it would modify the `running` field after the
lock had been released, which obviously can cause a data race, when the
regular context waker code that is run within a system call, locks the
context but not the global switching lock.

The solution was to make sure that the locks were held, all the way
until the actual switching, which was done in assembly. There can still
be a race condition here, since it modifies memory containing registers
after the lock has been released, even if it may be behind &mut on
another context, which can be UB, but it has not contributed to any
actual bugs... yet.

* I have not yet done that rigorous testing, but it appears to work well
enough, and I have not encountered the bug after like 10 tries.
2021-02-03 18:06:42 +01:00
Robin Randhawa 67ec6c23e7 aarch64: Move tpidr_el0 setup from spawn to switch 2021-01-17 10:09:03 +00:00
Robin Randhawa 02c37d3fae WIP: aarch64 rebase 2021-01-15 05:54:42 -07:00
Jeremy Soller e771e6a4d9 Reduce duplication in context::switch 2020-12-27 20:03:13 -07:00
jD91mZM2 cdcb34486b Keep singlestep across signals 2020-07-07 13:32:10 +02:00
Jeremy Soller 582e3fd8eb Unlock CONTEXT_SWITCH_LOCK after loading registers but before switch 2020-04-21 21:03:17 -06:00
Jeremy Soller c79f308f07 Unlock CONTEXT_SWITCH_LOCK after switch happens 2020-04-21 20:45:15 -06:00
Jeremy Soller b616fdb067 Keep track of ticks each context uses 2020-02-18 21:16:53 -07:00
Jeremy Soller 63e2a835e0 Fix clippy.sh script and fix a number of clippy warnings 2019-10-06 11:04:06 -06:00
jD91mZM2 6a3825d408 WIP(ptrace): Only use non-signal stack when using a default handler
This is a curious problem and it's really hard to solve it in a way
that doesn't feel hacky. On one hand, of course you want to be able to
modify and intercept what happens when you use a signal, right? On the
other hand, changes made to the context (especially singlestepping)
while a signal is handled (such as `SIGSTOP`) are not preserved since
the stack is restored after the signal handler was invoked.

I think what we have in this change makes sense anyway, as we don't
really want users modifying registers and other data in the default
signal behavior that occurs **in kernel mode**. Also trying to use
`PTRACE_SINGLESTEP` will set the singlestep flag only if in a
user-mode signal handler, else it will set it on the instruction after
the signal handling, which I guess makes sense since it can't affect
the kernel-mode code that runs the default handler.

I don't know. Help. Pls.
2019-07-20 22:45:33 +02:00
Jeremy Soller 788526a3b3 Bare-bones ptracing functionality
Since even a very basic ptrace can be nice to have, I thought I would split
the, perhaps rather big, ptrace project up in multiple PRs to make as few
changes as necessary in each. This PR contains the initial registry modifying
bits and only a very basic security measure. Letting this out to the community
should be good for spotting bugs and maybe getting some hype ;)
2019-07-02 07:38:26 -06:00
Jeremy Soller 45ea634798 Revert "Merge branch 'ptrace' into 'master'"
This reverts merge request !103
2019-07-02 11:56:11 +00:00
jD91mZM2 effe02bd45 Remove change I am faaairly certain I did NOT add :O
I'm guessing it's some issue after a rebase or something...
2019-07-01 22:50:19 +00:00
jD91mZM2 fe705d9b63 Switch to 2018 edition
Most of this was generated by the absolutely extraordinary `cargo fix`
subcommand. There were still 2 errors and a few warnings to patch up,
but compared to the normal 600+ errors, I'd say the fixer did a damn
good job! I'm also amazed that I could still start the VM after this,
I half expected some kinds of runtime failure...
2019-06-21 12:12:01 +02:00
Jeremy Soller 434e799f2a Place TCB at thread-specific location to avoid overlapping TCBs 2019-04-14 19:05:25 -06:00
Jeremy Soller 133c433f60 Fix warning in context::switch 2018-03-11 11:35:41 -06:00
Jeremy Soller c020ce7d8a Fix delivery of signals when a signal uses the default handler, make context status update on every switch 2018-02-24 17:47:46 -07:00
Jeremy Soller 5b389c7ffa Update PTI patch to inline PTI functions 2018-01-10 17:25:31 -07:00
Jeremy Soller d82ffd16cb WIP: Add per-cpu interrupt stack used before mapping kernel heap 2018-01-09 22:16:14 -07:00
Jeremy Soller 49d5c33928 Add support for WCONTINUED and WUNTRACED
Fix issues with SIGCONT
2018-01-03 22:34:50 -07:00
Jeremy Soller b6878760c7 Use seperate stopped status 2018-01-03 21:33:56 -07:00
Jeremy Soller 7906f6891e Add support for stop/cont signals 2018-01-02 22:05:29 -07:00
Jeremy Soller c2644adf3d Improve multi_core support 2017-12-05 21:26:45 -07:00
Jeremy Soller dd7c61b830 Allow other processors to pick up work 2017-12-05 20:24:03 -07:00
Jeremy Soller ed05564011 Remove SwitchResult, use out of band data to detect interruption
Update debugging code
2017-11-14 21:16:35 -07:00
Jeremy Soller 51339cb8c9 Cleanup warnings
Implement interrupt on signal in pipe:
2017-10-21 20:30:20 -06:00
Jeremy Soller ef8c120533 Prevent nested signals, fix check for PID > 0 2017-07-23 16:02:48 -06:00
Jeremy Soller a03457a9eb Simpler debug message 2017-07-10 20:33:29 -06:00
Jeremy Soller a3493d16fd Allow simple signal delivery to PID 1 (the kernel idle process) 2017-07-10 20:28:10 -06:00
Jeremy Soller ab738cede5 Restore kernel parameters on sigreturn 2017-07-10 20:08:57 -06:00
Jeremy Soller b5ff0aabd5 WIP: Signal handling 2017-07-09 21:34:38 -06:00
Jeremy Soller 0e8e1b5c4e WIP: Signal handling 2017-07-05 21:45:53 -06:00
bjorn3 248cfa51ae Remove PIT_TICKS assert 2017-04-29 10:46:07 +02:00
Andrew Plaza 2fc4454f5e set PIT_TICKS to 0 in context::switch() 2017-04-25 16:59:14 -04:00
Jeremy Soller 2087544ea7 Move all files to src 2017-04-03 21:47:01 -06:00
Jeremy Soller 906ef94ffd Fix bug with sleep - wake is not cleared after it occurs
Do not initialize waitcondition with capacity
2017-03-21 20:30:46 -06:00
Jeremy Soller 0c8ba636f4 Cleanup Redox repo, update Rust, remove old target 2017-01-03 15:55:00 -07:00