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

mshv-ioctls: Add support for aarch64 #135

Merged
merged 2 commits into from
Mar 28, 2024
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
32 changes: 22 additions & 10 deletions mshv-ioctls/src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl AsRawFd for VcpuFd {

impl VcpuFd {
/// Get the register values by providing an array of register names
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn get_reg(&self, reg_names: &mut [hv_register_assoc]) -> Result<()> {
//TODO: Error if input register len is zero
let mut mshv_vp_register_args = mshv_vp_registers {
Expand All @@ -86,7 +86,7 @@ impl VcpuFd {
///
/// * `reg_name` - general purpose register name.
/// * `reg_value` - register value.
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn set_reg(&self, regs: &[hv_register_assoc]) -> Result<()> {
let hv_vp_register_args = mshv_vp_registers {
count: regs.len() as i32,
Expand All @@ -100,7 +100,7 @@ impl VcpuFd {
Ok(())
}
/// Sets the vCPU general purpose registers
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn set_regs(&self, regs: &StandardRegisters) -> Result<()> {
let reg_assocs = [
hv_register_assoc {
Expand Down Expand Up @@ -199,7 +199,7 @@ impl VcpuFd {
}

/// Returns the vCPU general purpose registers.
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn get_regs(&self) -> Result<StandardRegisters> {
let reg_names = [
hv_register_name_HV_X64_REGISTER_RAX,
Expand Down Expand Up @@ -255,7 +255,7 @@ impl VcpuFd {
Ok(ret_regs)
}
/// Returns the vCPU special registers.
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn get_sregs(&self) -> Result<SpecialRegisters> {
let reg_names: [::std::os::raw::c_uint; 18] = [
hv_register_name_HV_X64_REGISTER_CS,
Expand Down Expand Up @@ -326,7 +326,7 @@ impl VcpuFd {
Ok(ret_regs)
}
/// Sets the vCPU special registers
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn set_sregs(&self, sregs: &SpecialRegisters) -> Result<()> {
let reg_names: [hv_register_name; 17] = [
hv_register_name_HV_X64_REGISTER_CS,
Expand Down Expand Up @@ -410,7 +410,7 @@ impl VcpuFd {
Ok(())
}

#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
fn fpu_registers() -> [hv_register_name; 26] {
[
hv_register_name_HV_X64_REGISTER_XMM0,
Expand Down Expand Up @@ -443,7 +443,7 @@ impl VcpuFd {
}

/// Sets the vCPU floating point registers
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn set_fpu(&self, fpu: &FloatingPointUnit) -> Result<()> {
let reg_names = Self::fpu_registers();
let mut reg_values: [hv_register_value; 26] = [hv_register_value { reg64: 0 }; 26];
Expand Down Expand Up @@ -510,7 +510,7 @@ impl VcpuFd {
Ok(())
}
/// Returns the floating point state (FPU) from the vCPU.
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn get_fpu(&self) -> Result<FloatingPointUnit> {
let reg_names = Self::fpu_registers();
let mut reg_assocs: Vec<hv_register_assoc> = reg_names
Expand Down Expand Up @@ -563,6 +563,7 @@ impl VcpuFd {
Ok(ret_regs)
}
/// X86 specific call that returns the vcpu's current "debug registers".
#[cfg(not(target_arch = "aarch64"))]
pub fn get_debug_regs(&self) -> Result<DebugRegisters> {
let reg_names: [hv_register_name; 6] = [
hv_register_name_HV_X64_REGISTER_DR0,
Expand Down Expand Up @@ -597,6 +598,7 @@ impl VcpuFd {
Ok(ret_regs)
}
/// X86 specific call that sets the vcpu's current "debug registers".
#[cfg(not(target_arch = "aarch64"))]
pub fn set_debug_regs(&self, d_regs: &DebugRegisters) -> Result<()> {
let reg_names = [
hv_register_name_HV_X64_REGISTER_DR0,
Expand Down Expand Up @@ -629,6 +631,7 @@ impl VcpuFd {
Ok(())
}
/// Returns the machine-specific registers (MSR) for this vCPU.
#[cfg(not(target_arch = "aarch64"))]
pub fn get_msrs(&self, msrs: &mut Msrs) -> Result<usize> {
let nmsrs = msrs.as_fam_struct_ref().nmsrs as usize;
let mut reg_assocs: Vec<hv_register_assoc> = Vec::with_capacity(nmsrs);
Expand Down Expand Up @@ -658,6 +661,7 @@ impl VcpuFd {
}
/// Setup the model-specific registers (MSR) for this vCPU.
/// Returns the number of MSR entries actually written.
#[cfg(not(target_arch = "aarch64"))]
pub fn set_msrs(&self, msrs: &Msrs) -> Result<usize> {
let nmsrs = msrs.as_fam_struct_ref().nmsrs as usize;
let mut reg_assocs: Vec<hv_register_assoc> = Vec::with_capacity(nmsrs);
Expand Down Expand Up @@ -690,6 +694,7 @@ impl VcpuFd {
}
/// Returns currently pending exceptions, interrupts, and NMIs as well as related
/// states of the vcpu.
#[cfg(not(target_arch = "aarch64"))]
pub fn get_vcpu_events(&self) -> Result<VcpuEvents> {
let reg_names: [hv_register_name; 5] = [
hv_register_name_HV_REGISTER_PENDING_INTERRUPTION,
Expand Down Expand Up @@ -720,6 +725,7 @@ impl VcpuFd {
Ok(ret_regs)
}
/// Sets pending exceptions, interrupts, and NMIs as well as related states of the vcpu.
#[cfg(not(target_arch = "aarch64"))]
pub fn set_vcpu_events(&self, events: &VcpuEvents) -> Result<()> {
let reg_names: [hv_register_name; 5] = [
hv_register_name_HV_REGISTER_PENDING_INTERRUPTION,
Expand Down Expand Up @@ -763,6 +769,7 @@ impl VcpuFd {
Ok(())
}
/// X86 specific call that returns the vcpu's current "xcrs".
#[cfg(not(target_arch = "aarch64"))]
pub fn get_xcrs(&self) -> Result<Xcrs> {
let mut reg_assocs: [hv_register_assoc; 1] = [hv_register_assoc {
name: hv_register_name_HV_X64_REGISTER_XFEM,
Expand All @@ -780,6 +787,7 @@ impl VcpuFd {
Ok(ret_regs)
}
/// X86 specific call to set XCRs
#[cfg(not(target_arch = "aarch64"))]
pub fn set_xcrs(&self, xcrs: &Xcrs) -> Result<()> {
self.set_reg(&[hv_register_assoc {
name: hv_register_name_HV_X64_REGISTER_XFEM,
Expand All @@ -788,6 +796,7 @@ impl VcpuFd {
}])
}
/// X86 specific call that returns the vcpu's current "misc registers".
#[cfg(not(target_arch = "aarch64"))]
pub fn get_misc_regs(&self) -> Result<MiscRegs> {
let mut reg_assocs: [hv_register_assoc; 1] = [hv_register_assoc {
name: hv_register_name_HV_X64_REGISTER_HYPERCALL,
Expand All @@ -805,6 +814,7 @@ impl VcpuFd {
Ok(ret_regs)
}
/// X86 specific call that sets the vcpu's current "misc registers".
#[cfg(not(target_arch = "aarch64"))]
pub fn set_misc_regs(&self, misc: &MiscRegs) -> Result<()> {
self.set_reg(&[hv_register_assoc {
name: hv_register_name_HV_X64_REGISTER_HYPERCALL,
Expand Down Expand Up @@ -899,6 +909,7 @@ impl VcpuFd {
Ok((gpa, result))
}
/// X86 specific call that returns the vcpu's current "suspend registers".
#[cfg(not(target_arch = "aarch64"))]
pub fn get_suspend_regs(&self) -> Result<SuspendRegisters> {
let reg_names: [hv_register_name; 2] = [
hv_register_name_HV_REGISTER_EXPLICIT_SUSPEND,
Expand Down Expand Up @@ -1016,7 +1027,7 @@ impl VcpuFd {
}
/// X86 specific call that retrieves the values of the specified CPUID
/// leaf as observed on the virtual processor.
#[cfg(not(any(target_arch = "arm", target_arch = "aarch64")))]
#[cfg(not(target_arch = "aarch64"))]
pub fn get_cpuid_values(&self, eax: u32, ecx: u32, xfem: u64, xss: u64) -> Result<[u32; 4]> {
let mut parms = mshv_get_vp_cpuid_values {
function: eax,
Expand Down Expand Up @@ -1054,6 +1065,7 @@ impl VcpuFd {
Ok(*input)
}
/// Sets the sev control register
#[cfg(not(target_arch = "aarch64"))]
pub fn set_sev_control_register(&self, reg: u64) -> Result<()> {
let reg_assocs = [hv_register_assoc {
name: hv_register_name_HV_X64_REGISTER_SEV_CONTROL,
Expand Down
1 change: 0 additions & 1 deletion mshv-ioctls/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
//
#![cfg(target_arch = "x86_64")]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
Expand Down
Loading