Commit Graph

1019 Commits

Author SHA1 Message Date
Jeremy Soller
c19bd573b5 Switch Context::grants to RwLock 2021-02-13 13:06:13 -07:00
Jeremy Soller
2611985a38 Switch Context::actions to RwLock 2021-02-13 13:01:20 -07:00
Jeremy Soller
bfaf8438a1 Switch Context::files to RwLock 2021-02-13 12:57:53 -07:00
Jeremy Soller
55d2467420 Switch Context::cwd to using RwLock 2021-02-13 12:24:19 -07:00
Jeremy Soller
cd6ede84fe Fix warnings from futex changes 2021-02-13 12:16:55 -07: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
Jeremy Soller
76d8c1074c Merge branch 'futex-fix' into 'master'
Use physical addresses internally in futex, and fix a context switching data race

See merge request redox-os/kernel!166
2021-02-13 17:52:09 +00:00
4lDO2
6f3fc3a4f4 Make cpu_id_opt non-mutable. 2021-02-03 18:10:39 +01: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
4lDO2
fec8f4aa0c Use physical addresses internally for futexes.
This solves a bug, that allows processes in different address spaces to
be the target of a futex wakeup call, even though that process is in
another address space!
2021-02-03 18:06:42 +01:00
Jeremy Soller
5e10feeaeb Fix whitespace in linker file 2021-01-12 19:59:05 -07:00
Jeremy Soller
6c4c19a95c Move consts to arch 2021-01-12 19:57:42 -07:00
Jeremy Soller
ed55b49093 Update aarch64 target to new Rust 2021-01-12 19:57:07 -07:00
Jeremy Soller
ea6b1e7f8b Update redox_syscall to 0.2.4 2021-01-11 07:01:05 -07:00
Jeremy Soller
334584b3d5 Use rmm::PhysicalAddress and rmm::VirtualAddress directly 2021-01-09 21:16:11 -07:00
Jeremy Soller
ccddabadf7 Make x86 specific dependencies, x86 specific 2021-01-09 20:12:59 -07:00
Jeremy Soller
e771e6a4d9 Reduce duplication in context::switch 2020-12-27 20:03:13 -07:00
Jeremy Soller
9033902830 Better messaging about which timer is used 2020-12-23 10:33:09 -07:00
Jeremy Soller
04cc8a2d9c Simplify reserved memory hack 2020-12-23 09:55:03 -07:00
Jeremy Soller
7355ae1671 Hack to ensure kernel is mapped even if it uses reserved memory 2020-12-23 09:46:34 -07:00
Jeremy Soller
cff858b455 Merge branch 'rmm' into 'master'
Support for RMM

See merge request redox-os/kernel!155
2020-11-27 16:49:39 +00:00
Jeremy Soller
f5ac405db6 Support for RMM 2020-11-27 16:49:39 +00:00
Jeremy Soller
8b27de416b Update Cargo.lock 2020-08-27 10:26:56 -06:00
Jeremy Soller
afa175f778 Merge branch 'jD91mZM2/kernel-remove-brk' into HEAD 2020-08-27 10:26:29 -06:00
Jeremy Soller
1baeb5a891 Format memory entries using hex 2020-08-27 09:43:39 -06:00
Jeremy Soller
8211e92c02 Merge branch 'master' of https://gitlab.redox-os.org/redox-os/kernel 2020-08-27 09:43:23 -06:00
Jeremy Soller
858dd6ef51 Update syscall 2020-08-27 09:43:15 -06:00
Jeremy Soller
45b48f8078 Merge branch 'fix-deprecate' into 'master'
Fix printing of deprecation warning

See merge request redox-os/kernel!151
2020-08-27 15:33:12 +00:00
Jeremy Soller
853b77e3a4 Unmap owned grants, use owned grants to calculate memory usage 2020-08-25 10:35:55 -06:00
Jeremy Soller
4e3df8b953 Merge branch 'aj-chdir-initfs-message' into 'master'
Add more descriptive error message for when initfs chdir fails

See merge request redox-os/kernel!150
2020-08-17 16:25:46 +00:00
Jeremy Soller
6ba3850042 Merge branch 'aj-logging' into 'master'
Use logging instead of println in src/lib.rs

See merge request redox-os/kernel!149
2020-08-17 16:18:08 +00:00
jD91mZM2
5fc6acacc4 Fix printing of deprecation warning 2020-08-17 15:25:14 +02:00
Aaron Janse
dc6132dc06 elaborate error message for initfs chdir failure 2020-08-17 03:24:56 -07:00
Aaron Janse
dfcf5be778 use logging instead of println 2020-08-17 02:55:40 -07:00
jD91mZM2
922b3d0437 Remove brk 2020-08-15 17:36:50 +02:00
Jeremy Soller
0590a71b87 Merge branch 'mynameissherlockholmes' into 'master'
Investigate why user heap isn't mapped

See merge request redox-os/kernel!147
2020-08-15 15:27:33 +00:00
jD91mZM2
da7b813fa9 Investigate why user heap isn't mapped
Took me way too long to spot this :D
2020-08-15 17:22:34 +02:00
Jeremy Soller
e3814c1ca2 Merge branch 'deprecate-stuff' into 'master'
Deprecate the original fmap/funmap

See merge request redox-os/kernel!146
2020-08-14 15:20:36 +00:00
jD91mZM2
78e5c71103 Deprecate the original fmap/funmap
The cool thing here is that we're temporarily binary compatible with the
old stuff, so if anyone would use an old version of redox_syscall we can
easily find them with these prints.
2020-08-14 15:18:47 +02:00
Jeremy Soller
2057b889ae Merge branch 'log_experiment' into 'master'
Log experiment

See merge request redox-os/kernel!144
2020-08-09 13:01:39 +00:00
Wren Turkal
4c009530a8 Make x86_64 log writer not use println!.
This opens the door to completely elimnating println! usage from the
kernel.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-09 00:00:26 -07:00
Wren Turkal
5301057324 Convert some println -> log::info!.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 21:18:18 -07:00
Wren Turkal
dafd2e9f98 Add a way to customize how logging is done.
Each architecture may have a different method to enable logging. Now
that can be customized with a function passed to the init_logger
function.

Also, provide a minimal x86_64 implementation.

This is the first commit where you can see logging coming from the log
crate.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 21:18:15 -07:00
Wren Turkal
29a9592e7b Re-export log::set_max_level.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 20:50:55 -07:00
Wren Turkal
50675842af Add logger init and initialize on x86_64.
Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 20:50:53 -07:00
Wren Turkal
03e60f7da6 Add log crate and add a generic logger.
This is the first step of integrating the log crate as the main way to
log messages from the kernel.

Also, reexport all log macros. This module should eventually be the
only logging API used in the kernel.

Signed-off-by: Wren Turkal <wt@penguintechs.org>
2020-08-08 20:48:41 -07:00
Jeremy Soller
d8a0a8182d Merge branch 'add_debug_to_structs' into 'master'
Implement Debug for a couple structs.

See merge request redox-os/kernel!142
2020-08-08 12:55:53 +00:00
Jeremy Soller
ad6035c7de Merge branch 'idiomatic-rust' into 'master'
Replace llvm_asm with asm

See merge request redox-os/kernel!141
2020-08-03 15:09:08 +00:00
jD91mZM2
bdc504f862 Update redox_syscall again 2020-08-03 16:08:15 +02:00