Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions openhcl/underhill_core/src/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2300,6 +2300,11 @@ async fn new_underhill_vm(
);
}

// Set the callback in GET to trigger the debug interrupt.
let p = partition.clone();
let debug_interrupt_callback = move |vtl: u8| p.assert_debug_interrupt(vtl);
get_client.set_debug_interrupt_callback(Box::new(debug_interrupt_callback));

let mut input_distributor = InputDistributor::new(remote_console_cfg.input);
resolver.add_async_resolver::<KeyboardInputHandleKind, _, MultiplexedInputHandle, _>(
input_distributor.client().clone(),
Expand Down
19 changes: 18 additions & 1 deletion openhcl/virt_mshv_vtl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ use user_driver::DmaClient;
use virt::IsolationType;
use virt::PartitionCapabilities;
use virt::VpIndex;
use virt::X86Partition;
use virt::irqcon::IoApicRouting;
use virt::irqcon::MsiRequest;
use virt::x86::apic_software_device::ApicSoftwareDevices;
Expand Down Expand Up @@ -844,7 +845,7 @@ impl virt::Partition for UhPartition {
}
}

impl virt::X86Partition for UhPartition {
impl X86Partition for UhPartition {
fn ioapic_routing(&self) -> Arc<dyn IoApicRouting> {
self.inner.clone()
}
Expand Down Expand Up @@ -1929,6 +1930,22 @@ impl UhPartition {
}
}

/// Trigger the LINT1 interrupt vector on the LAPIC of the BSP.
pub fn assert_debug_interrupt(&self, _vtl: u8) {
#[cfg(guest_arch = "x86_64")]
Copy link
Contributor

@smalis-msft smalis-msft Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should happen here for non-x86? #Resolved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The NMI is triggered by the hypervisor in that case, there is no GET request. We would likely extend this to ARM in the future for ARM CVMs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we trace a warning or something? Or cfg out this whole function, and the block in underhill_core that wires it up?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also not a huge fan of having a variable named with a leading _ that actually does get used. Tracing a warning would fix that.

const LINT_INDEX_1: u8 = 1;
#[cfg(guest_arch = "x86_64")]
match self.inner.isolation {
IsolationType::Snp => {
tracing::error!(?_vtl, "Debug interrupts cannot be injected into SNP VMs",);
}
_ => {
let bsp_index = VpIndex::new(0);
self.pulse_lint(bsp_index, Vtl::try_from(_vtl).unwrap(), LINT_INDEX_1)
}
}
}

/// Enables or disables the PM timer assist.
pub fn set_pm_timer_assist(&self, port: Option<u16>) -> Result<(), HvError> {
self.inner.hcl.set_pm_timer_assist(port)
Expand Down
11 changes: 11 additions & 0 deletions vm/devices/get/get_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ open_enum! {
MODIFY_VTL2_SETTINGS_REV1 = 6,
// --- GE ---
BATTERY_STATUS = 7,
INJECT_DEBUG_INTERRUPT = 8,
}
}

Expand Down Expand Up @@ -1759,6 +1760,16 @@ impl BatteryStatusNotification {
}
}

#[repr(C)]
#[derive(Copy, Clone, Debug, IntoBytes, FromBytes, Immutable, KnownLayout)]
pub struct InjectDebugInterruptNotification {
pub message_header: HeaderGuestNotification,
pub vtl: u8,
pub _pad: u8,
}

const_assert_eq!(6, size_of::<InjectDebugInterruptNotification>());

#[bitfield(u64)]
#[derive(IntoBytes, FromBytes, Immutable, KnownLayout)]
pub struct CreateRamGpaRangeFlags {
Expand Down
6 changes: 6 additions & 0 deletions vm/devices/get/guest_emulation_transport/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ impl GuestEmulationTransportClient {
.notify(msg::Msg::SetGpaAllocator(gpa_allocator));
}

/// Set the the callback to trigger the debug interrupt.
pub fn set_debug_interrupt_callback(&mut self, callback: Box<dyn Fn(u8) + Send + Sync>) {
self.control
.notify(msg::Msg::SetDebugInterruptCallback(callback));
}

/// Send the attestation request to the IGVM agent on the host.
pub async fn igvm_attest(
&self,
Expand Down
39 changes: 37 additions & 2 deletions vm/devices/get/guest_emulation_transport/src/process_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ pub(crate) mod msg {
Inspect(inspect::Deferred),
/// Store the gpa allocator to be used for attestation.
SetGpaAllocator(Arc<dyn DmaClient>),
/// Store the callback to trigger the debug interrupt.
SetDebugInterruptCallback(Box<dyn Fn(u8) + Send + Sync>),

// Late bound receivers for Guest Notifications
/// Take the late-bound GuestRequest receiver for Generation Id updates.
Expand Down Expand Up @@ -493,6 +495,8 @@ pub(crate) struct ProcessLoop<T: RingMem> {
#[inspect(skip)]
secondary_host_requests_read_send: mesh::Sender<Vec<u8>>,
gpa_allocator: Option<Arc<dyn DmaClient>>,
#[inspect(skip)]
set_debug_interrupt: Option<Box<dyn Fn(u8) + Send + Sync>>,
stats: Stats,

guest_notification_listeners: GuestNotificationListeners,
Expand Down Expand Up @@ -700,6 +704,7 @@ impl<T: RingMem> ProcessLoop<T> {
battery_status: GuestNotificationSender::new(),
},
gpa_allocator: None,
set_debug_interrupt: None,
}
}

Expand Down Expand Up @@ -1029,6 +1034,9 @@ impl<T: RingMem> ProcessLoop<T> {
Msg::SetGpaAllocator(gpa_allocator) => {
self.gpa_allocator = Some(gpa_allocator);
}
Msg::SetDebugInterruptCallback(callback) => {
self.set_debug_interrupt = Some(callback);
}

// Late bound receivers for Guest Notifications
Msg::TakeVtl2SettingsReceiver(req) => req.handle_sync(|()| {
Expand Down Expand Up @@ -1244,8 +1252,8 @@ impl<T: RingMem> ProcessLoop<T> {
) -> Result<(), FatalError> {
use get_protocol::GuestNotifications;

// Version must be latest. Give up if not.
if header.message_version != get_protocol::MessageVersions::HEADER_VERSION_1 {
// Version must be at least version 1.
if header.message_version < get_protocol::MessageVersions::HEADER_VERSION_1 {
tracing::error!(
msg = ?buf,
version = ?header.message_version,
Expand Down Expand Up @@ -1287,6 +1295,9 @@ impl<T: RingMem> ProcessLoop<T> {
GuestNotifications::BATTERY_STATUS => {
self.handle_battery_status_notification(read_guest_notification(id, buf)?)?;
}
GuestNotifications::INJECT_DEBUG_INTERRUPT => {
self.handle_debug_interrupt_notification(read_guest_notification(id, buf)?)?;
}
invalid_notification => {
tracing::error!(
?invalid_notification,
Expand Down Expand Up @@ -1489,6 +1500,30 @@ impl<T: RingMem> ProcessLoop<T> {
})
}

fn handle_debug_interrupt_notification(
&mut self,
notification: get_protocol::InjectDebugInterruptNotification,
) -> Result<(), FatalError> {
tracing::debug!(
"Received inject debug interrupt notification, vtl = {}",
notification.vtl,
);

if notification.vtl != 0 {
tracing::error!(
?notification.vtl,
"Debug interrupts can only be injected into VTL 0",
);
} else {
// Trigger the LINT1 interrupt vector on the LAPIC of the BSP.
if let Some(callback) = self.set_debug_interrupt.as_ref() {
callback(notification.vtl)
}
}

Ok(())
}

fn complete_modify_vtl2_settings(
&mut self,
result: Result<(), RpcError<Vec<Vtl2SettingsErrorInfo>>>,
Expand Down