Skip to content
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

virt_mshv_vtl: Add vtl1_active:bool to CvmVpState and check it for vtl call/return #926

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions openhcl/virt_mshv_vtl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ pub struct UhCvmVpState {
hv: VtlArray<ProcessorVtlHv, 2>,
/// LAPIC state.
lapics: VtlArray<LapicState, 2>,
/// Whether VTL 1 has been started on this VP.
vtl1_active: bool,
}

#[cfg(guest_arch = "x86_64")]
Expand Down Expand Up @@ -390,6 +392,7 @@ impl UhCvmVpState {
exit_vtl: GuestVtl::Vtl0,
hv,
lapics,
vtl1_active: false,
})
}
}
Expand Down
8 changes: 5 additions & 3 deletions openhcl/virt_mshv_vtl/src/processor/hardware_cvm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -840,9 +840,9 @@ impl<T, B: HardwareIsolatedBacking> hv1_hypercall::VtlCall for UhHypercallHandle
self.intercepted_vtl
);
false
} else if !*self.vp.cvm_vp_inner().vtl1_enabled.lock() {
// VTL 1 must be enabled on the vp
tracelimit::warn_ratelimited!("vtl call not allowed because vtl 1 is not enabled");
} else if !self.vp.backing.cvm_state().vtl1_active {
// VTL 1 must be active on the vp
tracelimit::warn_ratelimited!("vtl call not allowed because vtl 1 is not active");
false
} else {
true
Expand Down Expand Up @@ -1532,10 +1532,12 @@ impl<B: HardwareIsolatedBacking> UhProcessor<'_, B> {
// not be desirable.

self.backing.cvm_state_mut().exit_vtl = GuestVtl::Vtl1;
self.backing.cvm_state_mut().vtl1_active = true;
}
}
GuestVtl::Vtl1 => {
self.backing.cvm_state_mut().exit_vtl = GuestVtl::Vtl1;
self.backing.cvm_state_mut().vtl1_active = true;
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions openhcl/virt_mshv_vtl/src/processor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,8 @@ pub trait HardwareIsolatedBacking: Backing {
/// for each CPU.
fn shared_pages_required_per_cpu() -> u64;
/// Gets CVM specific VP state.
fn cvm_state(&self) -> &crate::UhCvmVpState;
/// Gets CVM specific VP state.
fn cvm_state_mut(&mut self) -> &mut crate::UhCvmVpState;
/// Gets CVM specific partition state.
fn cvm_partition_state(shared: &Self::Shared) -> &crate::UhCvmPartitionState;
Expand Down
4 changes: 4 additions & 0 deletions openhcl/virt_mshv_vtl/src/processor/snp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ impl HardwareIsolatedBacking for SnpBacked {
UhDirectOverlay::Count as u64
}

fn cvm_state(&self) -> &UhCvmVpState {
&self.cvm
}

fn cvm_state_mut(&mut self) -> &mut UhCvmVpState {
&mut self.cvm
}
Expand Down
4 changes: 4 additions & 0 deletions openhcl/virt_mshv_vtl/src/processor/tdx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ impl HardwareIsolatedBacking for TdxBacked {
UhDirectOverlay::Count as u64
}

fn cvm_state(&self) -> &UhCvmVpState {
&self.cvm
}

fn cvm_state_mut(&mut self) -> &mut UhCvmVpState {
&mut self.cvm
}
Expand Down