Skip to content

Commit

Permalink
Update the global synic to have per-vtl state
Browse files Browse the repository at this point in the history
  • Loading branch information
smalis-msft committed Oct 4, 2024
1 parent 803eae9 commit 3c6bbf8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
2 changes: 2 additions & 0 deletions underhill/virt_underhill/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,7 @@ impl vmcore::synic::GuestEventPort for UhEventPort {
match hv.synic.signal_event(
&partition.gm[vtl],
vp,
vtl,
sint,
flag,
&mut partition.synic_interrupt(vp, vtl),
Expand All @@ -894,6 +895,7 @@ impl vmcore::synic::GuestEventPort for UhEventPort {
.signal_event(
&partition.gm[vtl],
vp,
vtl,
sint,
flag,
&mut partition.synic_interrupt(vp, vtl),
Expand Down
41 changes: 15 additions & 26 deletions vm/hv1/hv1_emulator/src/synic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use std::array;
use std::sync::Arc;
use virt::x86::MsrError;
use vm_topology::processor::VpIndex;
use vtl_array::VtlArray;
use zerocopy::AsBytes;

/// The virtual processor synthetic interrupt controller state.
Expand Down Expand Up @@ -92,7 +93,7 @@ impl SharedProcessorState {
#[derive(Inspect)]
pub struct GlobalSynic {
#[inspect(iter_by_index)]
vps: Vec<Arc<RwLock<SharedProcessorState>>>,
vps: Vec<VtlArray<Arc<RwLock<SharedProcessorState>>, 2>>,
}

fn sint_interrupt(request: &mut dyn RequestInterrupt, sint: hvdef::HvSynicSint) {
Expand Down Expand Up @@ -185,7 +186,9 @@ impl GlobalSynic {
/// Returns a new instance of the synthetic interrupt controller.
pub fn new(max_vp_count: u32) -> Self {
Self {
vps: (0..max_vp_count).map(|_| Default::default()).collect(),
vps: (0..max_vp_count)
.map(|_| VtlArray::from_fn(|_| Default::default()))
.collect(),
}
}

Expand All @@ -199,14 +202,15 @@ impl GlobalSynic {
&self,
guest_memory: &GuestMemory,
vp: VpIndex,
vtl: Vtl,
sint_index: u8,
flag: u16,
interrupt: &mut dyn RequestInterrupt,
) -> Result<bool, SintProxied> {
let Some(vp) = self.vps.get(vp.index() as usize) else {
return Ok(false);
};
let vp = vp.read();
let vp = vp[vtl].read();
let sint_index = sint_index as usize;
let sint = vp.sint[sint_index];
let flag = flag as usize;
Expand Down Expand Up @@ -248,29 +252,14 @@ impl GlobalSynic {

/// Adds a virtual processor to the synthetic interrupt controller state.
pub fn add_vp(&self, vp_index: VpIndex, vtl: Vtl) -> ProcessorSynic {
match vtl {
Vtl::Vtl0 => {
let shared = self.vps[vp_index.index() as usize].clone();
let old_shared =
std::mem::replace(&mut *shared.write(), SharedProcessorState::AT_RESET);
assert!(!old_shared.online);

ProcessorSynic {
sints: SintState::AT_RESET,
timers: array::from_fn(|_| Timer::default()),
shared,
}
}
Vtl::Vtl1 => {
// TODO CVM GUEST VSM, these values are just placeholders to prevent
// messing with VTL 0's state
ProcessorSynic {
sints: SintState::AT_RESET,
timers: array::from_fn(|_| Timer::default()),
shared: Arc::new(RwLock::new(SharedProcessorState::AT_RESET)),
}
}
Vtl::Vtl2 => unreachable!(),
let shared = self.vps[vp_index.index() as usize][vtl].clone();
let old_shared = std::mem::replace(&mut *shared.write(), SharedProcessorState::AT_RESET);
assert!(!old_shared.online);

ProcessorSynic {
sints: SintState::AT_RESET,
timers: array::from_fn(|_| Timer::default()),
shared,
}
}
}
Expand Down

0 comments on commit 3c6bbf8

Please sign in to comment.