Skip to content

Commit 214ef24

Browse files
authored
Add a second global synic for VTL 1 (#64)
Pretty simple, just adding yet another VtlArray.
1 parent a699176 commit 214ef24

File tree

7 files changed

+18
-35
lines changed

7 files changed

+18
-35
lines changed

openhcl/virt_mshv_vtl/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,7 @@ impl vmcore::synic::GuestEventPort for UhEventPort {
869869
};
870870
tracing::trace!(vp = vp.index(), sint, flag, "signal_event");
871871
if let Some(hv) = partition.hv.as_ref() {
872-
match hv.synic.signal_event(
872+
match hv.synic[vtl].signal_event(
873873
&partition.gm[vtl],
874874
vp,
875875
sint,

openhcl/virt_mshv_vtl/src/processor/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ impl<'a, T: Backing> UhProcessor<'a, T> {
742742
let untrusted_synic = partition
743743
.untrusted_synic
744744
.as_ref()
745-
.map(|synic| synic.add_vp(vp_info.base.vp_index, Vtl::Vtl0));
745+
.map(|synic| synic.add_vp(vp_info.base.vp_index));
746746

747747
let mut vp = Self {
748748
partition,

vm/hv1/hv1_emulator/src/hv.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ pub struct GlobalHv {
3030
partition_state: Arc<GlobalHvState>,
3131
/// Mutable state, per VTL
3232
vtl_mutable_state: VtlArray<Arc<Mutex<MutableHvState>>, 2>,
33-
/// The partition-wide synic state.
34-
pub synic: GlobalSynic,
33+
/// The per-vtl synic state.
34+
pub synic: VtlArray<GlobalSynic, 2>,
3535
}
3636

3737
#[derive(Inspect)]
@@ -89,7 +89,7 @@ impl GlobalHv {
8989
vtl_mutable_state: VtlArray::from_fn(|_| {
9090
Arc::new(Mutex::new(MutableHvState::AT_RESET))
9191
}),
92-
synic: GlobalSynic::new(params.max_vp_count),
92+
synic: VtlArray::from_fn(|_| GlobalSynic::new(params.max_vp_count)),
9393
}
9494
}
9595

@@ -104,7 +104,7 @@ impl GlobalHv {
104104
vp_index,
105105
partition_state: self.partition_state.clone(),
106106
vtl_state: self.vtl_mutable_state[vtl].clone(),
107-
synic: self.synic.add_vp(vp_index, vtl),
107+
synic: self.synic[vtl].add_vp(vp_index),
108108
vp_assist_page: 0.into(),
109109
guest_memory,
110110
}

vm/hv1/hv1_emulator/src/synic.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use hvdef::HvMessageType;
1111
use hvdef::HvSynicSimpSiefp;
1212
use hvdef::HvSynicStimerConfig;
1313
use hvdef::TimerMessagePayload;
14-
use hvdef::Vtl;
1514
use hvdef::HV_MESSAGE_SIZE;
1615
use hvdef::HV_PAGE_SIZE;
1716
use hvdef::HV_PAGE_SIZE_USIZE;
@@ -247,30 +246,15 @@ impl GlobalSynic {
247246
}
248247

249248
/// Adds a virtual processor to the synthetic interrupt controller state.
250-
pub fn add_vp(&self, vp_index: VpIndex, vtl: Vtl) -> ProcessorSynic {
251-
match vtl {
252-
Vtl::Vtl0 => {
253-
let shared = self.vps[vp_index.index() as usize].clone();
254-
let old_shared =
255-
std::mem::replace(&mut *shared.write(), SharedProcessorState::AT_RESET);
256-
assert!(!old_shared.online);
257-
258-
ProcessorSynic {
259-
sints: SintState::AT_RESET,
260-
timers: array::from_fn(|_| Timer::default()),
261-
shared,
262-
}
263-
}
264-
Vtl::Vtl1 => {
265-
// TODO CVM GUEST VSM, these values are just placeholders to prevent
266-
// messing with VTL 0's state
267-
ProcessorSynic {
268-
sints: SintState::AT_RESET,
269-
timers: array::from_fn(|_| Timer::default()),
270-
shared: Arc::new(RwLock::new(SharedProcessorState::AT_RESET)),
271-
}
272-
}
273-
Vtl::Vtl2 => unreachable!(),
249+
pub fn add_vp(&self, vp_index: VpIndex) -> ProcessorSynic {
250+
let shared = self.vps[vp_index.index() as usize].clone();
251+
let old_shared = std::mem::replace(&mut *shared.write(), SharedProcessorState::AT_RESET);
252+
assert!(!old_shared.online);
253+
254+
ProcessorSynic {
255+
sints: SintState::AT_RESET,
256+
timers: array::from_fn(|_| Timer::default()),
257+
shared,
274258
}
275259
}
276260
}

vmm_core/virt_hvf/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl virt::ProtoPartition for HvfProtoPartition<'_> {
113113
.config
114114
.processor_topology
115115
.vps()
116-
.map(|vp_info| hv1.synic.add_vp(vp_info.vp_index, Vtl::Vtl0))
116+
.map(|vp_info| hv1.synic.add_vp(vp_info.vp_index))
117117
.collect::<Vec<_>>();
118118

119119
let mut gicd = gic::Distributor::new(256);

vmm_core/virt_whp/src/hypercalls.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ impl<T: CpuIo> hv1_hypercall::SignalEventDirect for WhpHypercallExit<'_, '_, T>
183183

184184
return Err(HvError::InvalidSynicState);
185185
}
186-
Hv1State::Emulated(hv) => hv
187-
.synic
186+
Hv1State::Emulated(hv) => hv.synic[vtl]
188187
.signal_event(
189188
&self.vp.vp.partition.gm,
190189
vp,

vmm_core/virt_whp/src/synic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ impl GuestEventPort for EmulatedGuestEventPort {
331331
let Hv1State::Emulated(hv) = &partition.vtlp(vtl).hvstate else {
332332
unreachable!()
333333
};
334-
let _ = hv.synic.signal_event(
334+
let _ = hv.synic[vtl].signal_event(
335335
&partition.gm,
336336
vp,
337337
sint,

0 commit comments

Comments
 (0)