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-{bindings, ioctls}: add line breaks #151

Merged
merged 1 commit into from
May 3, 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
1 change: 1 addition & 0 deletions mshv-bindings/src/hvcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct RepInput<T> {
size: usize,
rep_count: usize,
}

impl<T: Default> RepInput<T> {
/// Create a RepInput<T> for a rep hypercall
///
Expand Down
4 changes: 4 additions & 0 deletions mshv-bindings/src/x86_64/regs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,7 @@ pub struct VcpuEvents {
pub pending_event0: [u8; 16usize],
pub pending_event1: [u8; 16usize],
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes, FromZeroes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
Expand All @@ -408,6 +409,7 @@ pub struct hv_cpuid_entry {
pub edx: __u32,
pub padding: [__u32; 3usize],
}

#[repr(C)]
#[derive(Debug, Default)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
Expand Down Expand Up @@ -496,6 +498,7 @@ impl Drop for Buffer {
pub struct LapicState {
pub regs: [::std::os::raw::c_char; 1024usize],
}

impl Default for LapicState {
fn default() -> Self {
unsafe { ::std::mem::zeroed() }
Expand Down Expand Up @@ -674,6 +677,7 @@ pub struct SuspendRegisters {
pub explicit_register: u64,
pub intercept_register: u64,
}

#[repr(C)]
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, AsBytes, FromBytes, FromZeroes)]
#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))]
Expand Down
1 change: 1 addition & 0 deletions mshv-bindings/src/x86_64/serializers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ mod tests {
.zip(d_state.regs.iter())
.all(|(a, b)| a == b));
}

#[test]
fn test_xsave_serialization_deserialization() {
let mut xsave = XSave {
Expand Down
12 changes: 12 additions & 0 deletions mshv-bindings/src/x86_64/unmarshal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_memory_info(&self) -> Result<hv_x64_memory_intercept_message> {
if self.header.message_type != hv_message_type_HVMSG_GPA_INTERCEPT
Expand All @@ -35,6 +36,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_gpa_attribute_info(&self) -> Result<hv_x64_gpa_attribute_intercept_message> {
if self.header.message_type != hv_message_type_HVMSG_GPA_ATTRIBUTE_INTERCEPT {
Expand All @@ -47,6 +49,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_ioport_info(&self) -> Result<hv_x64_io_port_intercept_message> {
if self.header.message_type != hv_message_type_HVMSG_X64_IO_PORT_INTERCEPT {
Expand All @@ -59,6 +62,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_msr_info(&self) -> Result<hv_x64_msr_intercept_message> {
if self.header.message_type != hv_message_type_HVMSG_X64_MSR_INTERCEPT {
Expand All @@ -71,6 +75,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_exception_info(&self) -> Result<hv_x64_exception_intercept_message> {
if self.header.message_type != hv_message_type_HVMSG_X64_EXCEPTION_INTERCEPT {
Expand All @@ -83,6 +88,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_invalid_vp_register_info(&self) -> Result<hv_x64_invalid_vp_register_message> {
if self.header.message_type != hv_message_type_HVMSG_INVALID_VP_REGISTER_VALUE {
Expand All @@ -95,6 +101,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_unrecoverable_exception_info(
&self,
Expand All @@ -109,6 +116,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_interruption_deliverable_info(
&self,
Expand All @@ -123,6 +131,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_apic_eoi_info(&self) -> Result<hv_x64_apic_eoi_message> {
if self.header.message_type != hv_message_type_HVMSG_X64_APIC_EOI {
Expand All @@ -135,6 +144,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_hypercall_intercept_info(&self) -> Result<hv_x64_hypercall_intercept_message> {
if self.header.message_type != hv_message_type_HVMSG_HYPERCALL_INTERCEPT {
Expand All @@ -147,6 +157,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_sint_deliverable_info(&self) -> Result<hv_x64_sint_deliverable_message> {
if self.header.message_type != hv_message_type_HVMSG_SYNIC_SINT_DELIVERABLE {
Expand All @@ -159,6 +170,7 @@ impl hv_message {
unsafe { std::ptr::read_unaligned(std::ptr::addr_of!(self.u.payload) as *const _) };
Ok(ret)
}

#[inline]
pub fn to_vmg_intercept_info(&self) -> Result<hv_x64_vmgexit_intercept_message> {
if self.header.message_type != hv_message_type_HVMSG_X64_SEV_VMGEXIT_INTERCEPT {
Expand Down
2 changes: 2 additions & 0 deletions mshv-ioctls/src/ioctls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl MshvError {
}
error.into()
}

/// Convert to error code. Analogous to errno::Error::errno()
pub fn errno(self) -> i32 {
errno::Error::from(self).errno()
Expand Down Expand Up @@ -130,6 +131,7 @@ mod tests {
assert!(mshv_err == mshv_err_check);
}
}

#[test]
fn test_errno_from_mshv_root_hvcall() {
let args = mshv_root_hvcall {
Expand Down
7 changes: 6 additions & 1 deletion mshv-ioctls/src/ioctls/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ pub struct MshvPartitionBuilder {
mshv_partition: mshv_create_partition,
}

/// Synthetic processor features
#[derive(Debug)]
///
pub enum SyntheticProcessorFeature {
/// Report a hypervisor is present.
HypervisorPresent,
Expand Down Expand Up @@ -226,6 +226,7 @@ impl MshvPartitionBuilder {
}
self
}

/// Builds the partition
pub fn build(&self) -> mshv_create_partition {
self.mshv_partition
Expand All @@ -242,6 +243,7 @@ impl Mshv {
let ret = unsafe { Self::new_with_fd_number(fd) };
Ok(ret)
}

/// Creates a new Mshv object assuming `fd` represents an existing open file descriptor
/// associated with `/dev/mshv`.
///
Expand Down Expand Up @@ -408,6 +410,7 @@ impl Mshv {
.unwrap())
}
}

#[allow(dead_code)]
#[cfg(test)]
mod tests {
Expand All @@ -421,6 +424,7 @@ mod tests {
let vm = hv.create_vm();
assert!(vm.is_ok());
}

#[test]
#[ignore]
fn test_create_vm_with_default_config() {
Expand All @@ -429,6 +433,7 @@ mod tests {
let vm = hv.create_vm_with_config(&pr);
assert!(vm.is_ok());
}

#[test]
fn test_get_msr_index_list() {
let hv = Mshv::new().unwrap();
Expand Down
13 changes: 13 additions & 0 deletions mshv-ioctls/src/ioctls/vcpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1331,6 +1331,7 @@ mod tests {
assert!(g_sregs.apic_base == s_sregs.apic_base);
assert!(g_sregs.efer == s_sregs.efer);
}

#[test]
fn test_set_get_standardregisters() {
let hv = Mshv::new().unwrap();
Expand All @@ -1345,6 +1346,7 @@ mod tests {
assert!(g_regs.rcx == s_regs.rcx);
assert!(g_regs.rdx == s_regs.rdx);
}

#[test]
fn test_set_get_debug_gisters() {
let hv = Mshv::new().unwrap();
Expand All @@ -1361,6 +1363,7 @@ mod tests {
assert!(g_regs.dr6 == s_regs.dr6);
assert!(g_regs.dr7 == s_regs.dr7);
}

#[cfg(target_arch = "x86_64")]
#[test]
fn test_set_get_fpu() {
Expand Down Expand Up @@ -1389,6 +1392,7 @@ mod tests {
assert!(g_regs.last_dp == s_regs.last_dp);
assert!(g_regs.mxcsr == s_regs.mxcsr);
}

#[cfg(target_arch = "x86_64")]
#[test]
fn test_run_code() {
Expand Down Expand Up @@ -1537,6 +1541,7 @@ mod tests {
vm.unmap_user_memory(mem_region).unwrap();
unsafe { libc::munmap(load_addr as *mut c_void, mem_size) };
}

#[test]
fn test_set_get_msrs() {
let hv = Mshv::new().unwrap();
Expand Down Expand Up @@ -1573,6 +1578,7 @@ mod tests {
assert!(g_regs.as_slice()[0].data == s_regs.as_slice()[0].data);
assert!(g_regs.as_slice()[1].data == s_regs.as_slice()[1].data);
}

#[test]
fn test_set_get_vcpu_events() {
let hv = Mshv::new().unwrap();
Expand All @@ -1590,6 +1596,7 @@ mod tests {
assert!(g_regs.pending_event1[i] == s_regs.pending_event1[i]);
}
}

#[test]
fn test_set_get_xcrs() {
let hv = Mshv::new().unwrap();
Expand All @@ -1601,6 +1608,7 @@ mod tests {
let g_regs = vcpu.get_xcrs().unwrap();
assert!(g_regs.xcr0 == s_regs.xcr0);
}

#[test]
fn test_set_get_lapic() {
let hv = Mshv::new().unwrap();
Expand All @@ -1614,6 +1622,7 @@ mod tests {
assert!(state.regs[i] == g_state.regs[i]);
}
}

#[test]
fn test_set_registers_64() {
let hv = Mshv::new().unwrap();
Expand Down Expand Up @@ -1643,6 +1652,7 @@ mod tests {
assert!(get_regs[1].value.reg64 == 0x2);
}
}

#[test]
fn test_get_set_xsave() {
let hv = Mshv::new().unwrap();
Expand All @@ -1653,6 +1663,7 @@ mod tests {

vcpu.set_xsave(&state).unwrap();
}

#[test]
fn test_get_suspend_regs() {
let hv = Mshv::new().unwrap();
Expand All @@ -1664,6 +1675,7 @@ mod tests {
assert!(regs.explicit_register == 0x1);
assert!(regs.intercept_register == 0x0);
}

#[test]
fn test_set_get_misc_regs() {
let hv = Mshv::new().unwrap();
Expand All @@ -1675,6 +1687,7 @@ mod tests {
let g_regs = vcpu.get_misc_regs().unwrap();
assert!(g_regs.hypercall == s_regs.hypercall);
}

#[test]
fn test_get_cpuid_values() {
let hv = Mshv::new().unwrap();
Expand Down
Loading