Skip to content

Commit

Permalink
ioctls: Introduce feature 'use-generic-hvcall'
Browse files Browse the repository at this point in the history
Conditionally use hvcall_* versions of ioctls based on whether the
feature is enabled.

Signed-off-by: Nuno Das Neves <[email protected]>
  • Loading branch information
NunoDasNeves committed Apr 9, 2024
1 parent 81a9ebe commit ab6101b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mshv-ioctls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ authors = ["Microsoft Authors"]
edition = "2018"
license = "Apache-2.0 OR BSD-3-Clause"

[features]
use-generic-hvcall = []

[dependencies]
libc = ">=0.2.39"
mshv-bindings = {path = "../mshv-bindings", features = ["fam-wrappers"]}
Expand Down
6 changes: 6 additions & 0 deletions mshv-ioctls/src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ impl VcpuFd {
/// Get the register values by providing an array of register names
#[cfg(not(target_arch = "aarch64"))]
pub fn get_reg(&self, reg_names: &mut [hv_register_assoc]) -> Result<()> {
if cfg!(feature = "use-generic-hvcall") {
return self.hvcall_get_reg(reg_names);
}
//TODO: Error if input register len is zero
let mut mshv_vp_register_args = mshv_vp_registers {
count: reg_names.len() as i32,
Expand Down Expand Up @@ -122,6 +125,9 @@ impl VcpuFd {
/// Set vcpu register values by providing an array of register assocs
#[cfg(not(target_arch = "aarch64"))]
pub fn set_reg(&self, regs: &[hv_register_assoc]) -> Result<()> {
if cfg!(feature = "use-generic-hvcall") {
return self.hvcall_set_reg(regs);
}
let hv_vp_register_args = mshv_vp_registers {
count: regs.len() as i32,
regs: regs.as_ptr() as *mut hv_register_assoc,
Expand Down
3 changes: 3 additions & 0 deletions mshv-ioctls/src/ioctls/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ impl AsRawFd for VmFd {
impl VmFd {
/// Install intercept to enable some VM exits like MSR, CPUId etc
pub fn install_intercept(&self, install_intercept_args: mshv_install_intercept) -> Result<()> {
if cfg!(feature = "use-generic-hvcall") {
return self.hvcall_install_intercept(install_intercept_args);
}
// SAFETY: IOCTL with correct types
let ret =
unsafe { ioctl_with_ref(self, MSHV_INSTALL_INTERCEPT(), &install_intercept_args) };
Expand Down

0 comments on commit ab6101b

Please sign in to comment.