-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
kernel: run with interrupts enabled when possible #485
Conversation
The changes break test-in-svsm in my setup, I need to investigate before merging. |
Yeah, also on my env:
Maybe with commit 78b0a92 we need to adjust tests in |
I've modified the tests to understand the interrupt configuration, so hopefully everything will work now. |
Some other tests failing in
But applying the same changes you did also there, everything is fine: diff --git a/kernel/src/locking/rwlock.rs b/kernel/src/locking/rwlock.rs
index 9d81b7d..f48fa55 100644
--- a/kernel/src/locking/rwlock.rs
+++ b/kernel/src/locking/rwlock.rs
@@ -330,11 +330,12 @@ mod tests {
#[cfg_attr(not(test_in_svsm), ignore = "Can only be run inside guest")]
fn rw_lock_irq_unsafe() {
use crate::cpu::irq_state::{raw_irqs_disable, raw_irqs_enable};
- use crate::cpu::{irqs_disabled, irqs_enabled};
+ use crate::cpu::{irqs_enabled};
use crate::locking::*;
- assert!(irqs_disabled());
unsafe {
+ let was_enabled = irqs_enabled();
+
raw_irqs_enable();
let lock = RWLock::new(0);
@@ -355,6 +356,10 @@ mod tests {
// IRQs must still be enabled
assert!(irqs_enabled());
raw_irqs_disable();
+
+ if !was_enabled {
+ raw_irqs_disable();
+ }
}
}
@@ -365,8 +370,9 @@ mod tests {
use crate::cpu::{irqs_disabled, irqs_enabled};
use crate::locking::*;
- assert!(irqs_disabled());
unsafe {
+ let was_enabled = irqs_enabled();
+
raw_irqs_enable();
let lock = RWLockIrqSafe::new(0);
@@ -389,6 +395,10 @@ mod tests {
// IRQs must still be enabled
assert!(irqs_enabled());
raw_irqs_disable();
+
+ if !was_enabled {
+ raw_irqs_disable();
+ }
}
}
} BTW, in order not to break the bisection, I think it's better to change the tests before commit 78b0a92 or along with it. |
e0d5c44
to
db2d8cf
Compare
Thanks for identifying the problem!
Fixed. |
Another issue :-( I guess because we merged new stuff in main:
There are some tests in nit: maybe better to update the title of commit 05082b0 since we are fixing tests not only in |
49b5530
to
652eb2f
Compare
Thanks for checking! Hopefully I've got them all now.
There's no obviously good name because there isn't a clear path here, so hopefully the new title of the commit is good enough. |
Yeah, no failures running
Yep, I think it's fine ;-) Thanks! |
Various interrupt-related tests previously assumed that the test environment would always execute with interrupts disabled. They must actually tolerate any interrupt configuration within the kernel environment. Signed-off-by: Jon Lange <[email protected]>
Enable the use of interrupts whenever the kernel is executing outside of an IRQ guard. This is not safe on SNP systems that do not use Restricted Injection but is safe in all other configurations. Signed-off-by: Jon Lange <[email protected]>
Some platforms permit the injection of arbitrary interrupt vectors. System calls from user mode are implemented as software interrupts, and handling an injected interrupt as a system call would be a security issue. The system call handler must determine whether it was invoked in an unsafe way. Signed-off-by: Jon Lange <[email protected]>
Issuing a GHCB call via VMGEXIT requires setting and potentially reading the GHCB MSR. Since GHCB calls can be issued by interrupt routines, interrupts must be disabled during each set-exit-read sequence to prevent possible tearing due to preemption during such a sequence. Signed-off-by: Jon Lange <[email protected]>
On platforms that support SVSM interrupt delivery correctly (all platforms except SNP without Restricted Injection), the kernel should generally run with interrupts enabled so that interrupts directed at the SVSM can be handled as quickly as possible.