-
Notifications
You must be signed in to change notification settings - Fork 154
NMI for CVM in OpenHCL #2049
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
base: main
Are you sure you want to change the base?
NMI for CVM in OpenHCL #2049
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
use crate::UhProcessor; | ||
use crate::processor::HardwareIsolatedBacking; | ||
use crate::processor::NMI_SUPPRESS_LINT1_REQUESTED; | ||
use cvm_tracing::CVM_ALLOWED; | ||
use hcl::GuestVtl; | ||
use virt::Processor; | ||
|
@@ -28,6 +29,8 @@ pub(crate) trait ApicBacking<'b, B: HardwareIsolatedBacking> { | |
fn handle_extint(&mut self, vtl: GuestVtl) { | ||
tracelimit::warn_ratelimited!(CVM_ALLOWED, ?vtl, "extint not supported"); | ||
} | ||
|
||
fn supports_nmi_masking(&mut self) -> bool; | ||
} | ||
|
||
pub(crate) fn poll_apic_core<'b, B: HardwareIsolatedBacking, T: ApicBacking<'b, B>>( | ||
|
@@ -53,6 +56,7 @@ pub(crate) fn poll_apic_core<'b, B: HardwareIsolatedBacking, T: ApicBacking<'b, | |
extint, | ||
sipi, | ||
nmi, | ||
lint1, | ||
interrupt, | ||
} = vp.backing.cvm_state_mut().lapics[vtl] | ||
.lapic | ||
|
@@ -93,10 +97,21 @@ pub(crate) fn poll_apic_core<'b, B: HardwareIsolatedBacking, T: ApicBacking<'b, | |
} | ||
|
||
// Interrupts are ignored while waiting for SIPI. | ||
let supports_nmi_masking = apic_backing.supports_nmi_masking(); | ||
let lapic = &mut apic_backing.vp().backing.cvm_state_mut().lapics[vtl]; | ||
if lapic.activity != MpState::WaitForSipi { | ||
if nmi || lapic.nmi_pending { | ||
if lint1 { | ||
if supports_nmi_masking || !lapic.cross_vtl_nmi_requested { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you elaborate on this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VTL0-generated NMIs may occur during normal execution e.g. due to KD interaction, and so we don't want these to block crash dumps. But if VTL1 injected an NMI that only occurs due to bug check so don't allow other NMI sources |
||
lapic.nmi_suppression |= NMI_SUPPRESS_LINT1_REQUESTED; | ||
lapic.nmi_pending = true; | ||
} | ||
} | ||
|
||
if nmi { | ||
lapic.nmi_pending = true; | ||
} | ||
|
||
if lapic.nmi_pending { | ||
apic_backing.handle_nmi(vtl); | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,12 +154,21 @@ impl VtlsTlbLocked { | |
} | ||
} | ||
|
||
// NMI suppression state to prevent duplicate NMI | ||
#[cfg(guest_arch = "x86_64")] | ||
const NMI_SUPPRESS_LINT1_DELIVERED: u32 = 1; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These and nmi_suppression should be combined into a bitfield type |
||
#[cfg(guest_arch = "x86_64")] | ||
const NMI_SUPPRESS_LINT1_REQUESTED: u32 = 1 << 1; | ||
|
||
#[cfg(guest_arch = "x86_64")] | ||
#[derive(Inspect)] | ||
pub(crate) struct LapicState { | ||
lapic: LocalApic, | ||
activity: MpState, | ||
nmi_pending: bool, | ||
lint1_pending: bool, | ||
nmi_suppression: u32, | ||
cross_vtl_nmi_requested: bool, | ||
} | ||
|
||
#[cfg(guest_arch = "x86_64")] | ||
|
@@ -169,6 +178,9 @@ impl LapicState { | |
lapic, | ||
activity, | ||
nmi_pending: false, | ||
lint1_pending: false, | ||
nmi_suppression: 0, | ||
cross_vtl_nmi_requested: false, | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,8 @@ use crate::UhCvmVpState; | |
use crate::UhPartitionInner; | ||
use crate::UhPartitionNewParams; | ||
use crate::WakeReason; | ||
use crate::processor::NMI_SUPPRESS_LINT1_DELIVERED; | ||
use crate::processor::NMI_SUPPRESS_LINT1_REQUESTED; | ||
use crate::processor::UhHypercallHandler; | ||
use crate::processor::UhProcessor; | ||
use crate::processor::hardware_cvm::apic::ApicBacking; | ||
|
@@ -884,6 +886,20 @@ impl<'b> ApicBacking<'b, SnpBacked> for UhProcessor<'b, SnpBacked> { | |
// TODO SNP: support virtual NMI injection | ||
// For now, just inject an NMI and hope for the best. | ||
// Don't forget to update handle_cross_vtl_interrupts if this code changes. | ||
|
||
if (self.backing.cvm.lapics[vtl].nmi_suppression & NMI_SUPPRESS_LINT1_DELIVERED) != 0 { | ||
// Cancel this NMI request since it cannot be delivered. | ||
self.backing.cvm.lapics[vtl].nmi_pending = false; | ||
return; | ||
} | ||
|
||
if (self.backing.cvm.lapics[vtl].nmi_suppression & NMI_SUPPRESS_LINT1_REQUESTED) != 0 { | ||
// If a LINT1 NMI has been requested, then it is being delivered now, | ||
// so no further NMIs can be delivered. | ||
self.backing.cvm.lapics[vtl].nmi_suppression &= !NMI_SUPPRESS_LINT1_REQUESTED; | ||
self.backing.cvm.lapics[vtl].nmi_suppression |= NMI_SUPPRESS_LINT1_DELIVERED; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I missed it, but where do we clear DELIVERED? #Resolved There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. DELIVERED isn't cleared. Once LINT1 debug interrupt has been delivered you can't deliver another LINT1 or NMI. The HCL doesn't know when the NMI is complete so its not safe to signal twice. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we trace a warning or something then if we get one of these and delivered is already set? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the guest is already crashing and hopefully writing a crash dump so no need to add another write at that time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about tracing being low cost |
||
} | ||
|
||
let mut vmsa = self.runner.vmsa_mut(vtl); | ||
|
||
// TODO GUEST VSM: Don't inject the NMI if there's already an event | ||
|
@@ -905,6 +921,10 @@ impl<'b> ApicBacking<'b, SnpBacked> for UhProcessor<'b, SnpBacked> { | |
vmsa.set_rip(0); | ||
self.backing.cvm.lapics[vtl].activity = MpState::Running; | ||
} | ||
|
||
fn supports_nmi_masking(&mut self) -> bool { | ||
false | ||
} | ||
} | ||
|
||
impl UhProcessor<'_, SnpBacked> { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The vtl param should probably be a GuestVtl, and the conversion should happen at a higher level. I guess in the callback.