Skip to content

virt_mshv_vtl: Separate out CVM and non-CVM deliver_synic_messages #1381

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

Merged
merged 3 commits into from
May 20, 2025
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
35 changes: 34 additions & 1 deletion openhcl/virt_mshv_vtl/src/processor/hardware_cvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2334,7 +2334,6 @@ impl<B: HardwareIsolatedBacking> UhProcessor<'_, B> {

for vtl in [GuestVtl::Vtl1, GuestVtl::Vtl0] {
// Process interrupts.

self.update_synic(vtl, false);

B::poll_apic(self, vtl, scan_irr[vtl] || *first_scan_irr)
Expand Down Expand Up @@ -2384,6 +2383,40 @@ impl<B: HardwareIsolatedBacking> UhProcessor<'_, B> {
// Loop around to process the synic again.
}
}

pub(crate) fn deliver_synic_messages(&mut self, vtl: GuestVtl, sints: u16) {
let proxied_sints = self.backing.cvm_state().hv[vtl].synic.proxied_sints();
let pending_sints =
self.inner.message_queues[vtl].post_pending_messages(sints, |sint, message| {
if proxied_sints & (1 << sint) != 0 {
if let Some(synic) = self.backing.untrusted_synic_mut() {
synic.post_message(
sint,
message,
&mut self
.partition
.synic_interrupt(self.inner.vp_info.base.vp_index, vtl),
)
} else {
self.partition.hcl.post_message_direct(
self.inner.vp_info.base.vp_index.index(),
sint,
message,
)
}
} else {
self.backing.cvm_state_mut().hv[vtl].synic.post_message(
sint,
message,
&mut self
.partition
.synic_interrupt(self.inner.vp_info.base.vp_index, vtl),
)
}
});

self.request_sint_notifications(vtl, pending_sints);
}
}

pub(crate) struct XsetbvExitInput {
Expand Down
49 changes: 3 additions & 46 deletions openhcl/virt_mshv_vtl/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ cfg_if::cfg_if! {
use crate::VtlCrash;
use bitvec::prelude::BitArray;
use bitvec::prelude::Lsb0;
use hv1_emulator::synic::ProcessorSynic;
use hvdef::HvX64RegisterName;
use virt::vp::MpState;
use virt::x86::MsrError;
Expand Down Expand Up @@ -186,7 +187,6 @@ mod private {
use crate::GuestVtl;
use crate::processor::UhProcessor;
use hv1_emulator::hv::ProcessorVtlHv;
use hv1_emulator::synic::ProcessorSynic;
use hv1_structs::VtlArray;
use inspect::InspectMut;
use std::future::Future;
Expand Down Expand Up @@ -260,8 +260,6 @@ mod private {
fn hv(&self, vtl: GuestVtl) -> Option<&ProcessorVtlHv>;
fn hv_mut(&mut self, vtl: GuestVtl) -> Option<&mut ProcessorVtlHv>;

fn untrusted_synic_mut(&mut self) -> Option<&mut ProcessorSynic>;

fn vtl1_inspectable(this: &UhProcessor<'_, Self>) -> bool;
}
}
Expand Down Expand Up @@ -477,6 +475,8 @@ trait HardwareIsolatedBacking: Backing {
this: &mut UhProcessor<'_, Self>,
intercept_control: HvRegisterCrInterceptControl,
);

fn untrusted_synic_mut(&mut self) -> Option<&mut ProcessorSynic>;
}

#[cfg_attr(guest_arch = "aarch64", expect(dead_code))]
Expand Down Expand Up @@ -1126,49 +1126,6 @@ impl<'a, T: Backing> UhProcessor<'a, T> {
.await
}

fn deliver_synic_messages(&mut self, vtl: GuestVtl, sints: u16) {
let proxied_sints = self
.backing
.hv(vtl)
.as_ref()
.map_or(!0, |hv| hv.synic.proxied_sints());
let pending_sints =
self.inner.message_queues[vtl].post_pending_messages(sints, |sint, message| {
if proxied_sints & (1 << sint) != 0 {
if let Some(synic) = self.backing.untrusted_synic_mut().as_mut() {
synic.post_message(
sint,
message,
&mut self
.partition
.synic_interrupt(self.inner.vp_info.base.vp_index, vtl),
)
} else {
self.partition.hcl.post_message_direct(
self.inner.vp_info.base.vp_index.index(),
sint,
message,
)
}
} else {
self.backing
.hv_mut(vtl)
.as_mut()
.unwrap()
.synic
.post_message(
sint,
message,
&mut self
.partition
.synic_interrupt(self.inner.vp_info.base.vp_index, vtl),
)
}
});

self.request_sint_notifications(vtl, pending_sints);
}

#[cfg(guest_arch = "x86_64")]
fn update_proxy_irr_filter(&mut self, vtl: GuestVtl) {
assert_eq!(vtl, GuestVtl::Vtl0);
Expand Down
5 changes: 0 additions & 5 deletions openhcl/virt_mshv_vtl/src/processor/mshv/arm64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use hcl::UnsupportedGuestVtl;
use hcl::ioctl;
use hcl::ioctl::aarch64::MshvArm64;
use hv1_emulator::hv::ProcessorVtlHv;
use hv1_emulator::synic::ProcessorSynic;
use hvdef::HvAarch64PendingEvent;
use hvdef::HvArm64RegisterName;
use hvdef::HvArm64ResetType;
Expand Down Expand Up @@ -239,10 +238,6 @@ impl BackingPrivate for HypervisorBackedArm64 {
None
}

fn untrusted_synic_mut(&mut self) -> Option<&mut ProcessorSynic> {
None
}

fn handle_vp_start_enable_vtl_wake(
_this: &mut UhProcessor<'_, Self>,
_vtl: GuestVtl,
Expand Down
19 changes: 19 additions & 0 deletions openhcl/virt_mshv_vtl/src/processor/mshv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

//! Processor support for Microsoft hypervisor-backed partitions.

use crate::HypervisorBacked;
use crate::UhProcessor;
use hcl::GuestVtl;

pub mod arm64;
mod tlb_lock;
pub mod x64;
Expand All @@ -13,3 +17,18 @@ pub(crate) struct VbsIsolatedVtl1State {
default_vtl_protections: Option<hvdef::HvMapGpaFlags>,
enable_vtl_protection: bool,
}

impl UhProcessor<'_, HypervisorBacked> {
fn deliver_synic_messages(&mut self, vtl: GuestVtl, sints: u16) {
let pending_sints =
self.inner.message_queues[vtl].post_pending_messages(sints, |sint, message| {
self.partition.hcl.post_message_direct(
self.inner.vp_info.base.vp_index.index(),
sint,
message,
)
});

self.request_sint_notifications(vtl, pending_sints);
}
}
5 changes: 0 additions & 5 deletions openhcl/virt_mshv_vtl/src/processor/mshv/x64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use hcl::ioctl::ApplyVtlProtectionsError;
use hcl::ioctl::x64::MshvX64;
use hcl::protocol;
use hv1_emulator::hv::ProcessorVtlHv;
use hv1_emulator::synic::ProcessorSynic;
use hv1_hypercall::HvRepResult;
use hv1_structs::VtlSet;
use hvdef::HV_PAGE_SIZE;
Expand Down Expand Up @@ -353,10 +352,6 @@ impl BackingPrivate for HypervisorBackedX86 {
None
}

fn untrusted_synic_mut(&mut self) -> Option<&mut ProcessorSynic> {
None
}

fn handle_vp_start_enable_vtl_wake(
_this: &mut UhProcessor<'_, Self>,
_vtl: GuestVtl,
Expand Down
8 changes: 4 additions & 4 deletions openhcl/virt_mshv_vtl/src/processor/snp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ impl HardwareIsolatedBacking for SnpBacked {
true
})
}

fn untrusted_synic_mut(&mut self) -> Option<&mut ProcessorSynic> {
None
}
}

/// Partition-wide shared data for SNP VPs.
Expand Down Expand Up @@ -577,10 +581,6 @@ impl BackingPrivate for SnpBacked {
Some(&mut self.cvm.hv[vtl])
}

fn untrusted_synic_mut(&mut self) -> Option<&mut ProcessorSynic> {
None
}

fn handle_vp_start_enable_vtl_wake(
this: &mut UhProcessor<'_, Self>,
vtl: GuestVtl,
Expand Down
8 changes: 4 additions & 4 deletions openhcl/virt_mshv_vtl/src/processor/tdx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,10 @@ impl HardwareIsolatedBacking for TdxBacked {
true
})
}

fn untrusted_synic_mut(&mut self) -> Option<&mut ProcessorSynic> {
self.untrusted_synic.as_mut()
}
}

/// Partition-wide shared data for TDX VPs.
Expand Down Expand Up @@ -1103,10 +1107,6 @@ impl BackingPrivate for TdxBacked {
Some(&mut self.cvm.hv[vtl])
}

fn untrusted_synic_mut(&mut self) -> Option<&mut ProcessorSynic> {
self.untrusted_synic.as_mut()
}

fn handle_vp_start_enable_vtl_wake(
this: &mut UhProcessor<'_, Self>,
vtl: GuestVtl,
Expand Down