From e9e3331fb26c498979859bb92fdd085366ebe4a9 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Tue, 12 Oct 2021 14:09:26 +0200 Subject: [PATCH] fix: coding style for sev and kvm backend Signed-off-by: Harald Hoyer --- src/backend/kvm/builder.rs | 10 ++++++---- src/backend/kvm/data.rs | 1 + src/backend/kvm/mod.rs | 11 +++++++---- src/backend/kvm/thread.rs | 2 +- src/backend/sev/builder.rs | 9 +++++---- src/backend/sev/cpuid_page.rs | 5 +++-- src/backend/sev/data.rs | 5 +++-- src/backend/sev/mod.rs | 8 +++++--- 8 files changed, 31 insertions(+), 20 deletions(-) diff --git a/src/backend/kvm/builder.rs b/src/backend/kvm/builder.rs index 75ddcedf1..274b68235 100644 --- a/src/backend/kvm/builder.rs +++ b/src/backend/kvm/builder.rs @@ -1,7 +1,12 @@ // SPDX-License-Identifier: Apache-2.0 use super::mem::Region; -use crate::backend::kvm::KvmKeepPersonality; +use super::KvmKeepPersonality; + +use std::convert::TryFrom; +use std::mem::size_of; +use std::sync::{Arc, RwLock}; + use anyhow::{Error, Result}; use kvm_bindings::bindings::kvm_userspace_memory_region; use kvm_bindings::fam_wrappers::KVM_MAX_CPUID_ENTRIES; @@ -9,9 +14,6 @@ use kvm_ioctls::{Kvm, VcpuFd, VmFd}; use mmarinus::{perms, Map}; use sallyport::elf::pf::kvm::SALLYPORT; use sallyport::Block; -use std::convert::TryFrom; -use std::mem::size_of; -use std::sync::{Arc, RwLock}; use x86_64::VirtAddr; pub struct Builder { diff --git a/src/backend/kvm/data.rs b/src/backend/kvm/data.rs index c56ad97c1..7beae6e9a 100644 --- a/src/backend/kvm/data.rs +++ b/src/backend/kvm/data.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::backend::Datum; + use kvm_ioctls::Kvm; pub fn dev_kvm() -> Datum { diff --git a/src/backend/kvm/mod.rs b/src/backend/kvm/mod.rs index 3643a17bb..2e7d1fd0a 100644 --- a/src/backend/kvm/mod.rs +++ b/src/backend/kvm/mod.rs @@ -1,15 +1,18 @@ // SPDX-License-Identifier: Apache-2.0 +pub use kvm_bindings::kvm_userspace_memory_region as KvmUserspaceMemoryRegion; + use super::Loader; -use crate::backend::kvm::data::{dev_kvm, kvm_version}; -use crate::backend::kvm::mem::Region; +use data::{dev_kvm, kvm_version}; +use mem::Region; + +use std::sync::Arc; + use anyhow::Result; use kvm_bindings::bindings::kvm_userspace_memory_region; -pub use kvm_bindings::kvm_userspace_memory_region as KvmUserspaceMemoryRegion; use kvm_ioctls::Kvm; use kvm_ioctls::{VcpuFd, VmFd}; use mmarinus::{perms, Map}; -use std::sync::Arc; use x86_64::VirtAddr; pub mod builder; diff --git a/src/backend/kvm/thread.rs b/src/backend/kvm/thread.rs index fccef8273..18b6bc07e 100644 --- a/src/backend/kvm/thread.rs +++ b/src/backend/kvm/thread.rs @@ -1,10 +1,10 @@ // SPDX-License-Identifier: Apache-2.0 use super::super::Command; +use super::KeepPersonality; use std::sync::{Arc, RwLock}; -use crate::backend::kvm::KeepPersonality; use anyhow::{anyhow, Result}; use kvm_ioctls::{VcpuExit, VcpuFd}; use mmarinus::{perms, Kind, Map}; diff --git a/src/backend/sev/builder.rs b/src/backend/sev/builder.rs index 07382eb28..4d795f161 100644 --- a/src/backend/sev/builder.rs +++ b/src/backend/sev/builder.rs @@ -1,12 +1,13 @@ // SPDX-License-Identifier: Apache-2.0 +use super::cpuid_page::CpuidPage; +use super::SnpKeepPersonality; +use crate::backend::kvm::builder::kvm_try_from_builder; +use crate::backend::kvm::mem::Region; + use std::convert::TryFrom; use std::sync::{Arc, RwLock}; -use super::cpuid_page::CpuidPage; -use super::mem::Region; -use crate::backend::kvm::builder::kvm_try_from_builder; -use crate::backend::sev::SnpKeepPersonality; use anyhow::Context; use anyhow::{Error, Result}; use kvm_ioctls::{Kvm, VmFd}; diff --git a/src/backend/sev/cpuid_page.rs b/src/backend/sev/cpuid_page.rs index 974c536b9..8cd5497b8 100644 --- a/src/backend/sev/cpuid_page.rs +++ b/src/backend/sev/cpuid_page.rs @@ -3,13 +3,14 @@ //! FIXME use const_default::ConstDefault; -use core::mem::size_of; use core::fmt::{Debug, Formatter}; +use core::mem::size_of; +use std::fmt::Display; + use kvm_bindings::bindings::KVM_CPUID_FLAG_SIGNIFCANT_INDEX; use kvm_bindings::fam_wrappers::KVM_MAX_CPUID_ENTRIES; use kvm_ioctls::Kvm; -use std::fmt::Display; const COUNT_MAX: usize = 64; diff --git a/src/backend/sev/data.rs b/src/backend/sev/data.rs index ceba77cbe..1355adf57 100644 --- a/src/backend/sev/data.rs +++ b/src/backend/sev/data.rs @@ -1,14 +1,15 @@ // SPDX-License-Identifier: Apache-2.0 +pub use crate::backend::kvm::data::{dev_kvm, kvm_version}; + use crate::backend::probe::x86_64::{CpuId, Vendor}; use crate::backend::Datum; + use std::arch::x86_64::__cpuid_count; use std::fs::OpenOptions; use std::mem::{transmute, MaybeUninit}; use std::str::from_utf8; -pub use super::super::kvm::data::{dev_kvm, kvm_version}; - pub fn has_reasonable_memlock_rlimit() -> Datum { let mut rlimits = MaybeUninit::uninit(); let res = unsafe { libc::getrlimit(libc::RLIMIT_MEMLOCK, rlimits.as_mut_ptr()) }; diff --git a/src/backend/sev/mod.rs b/src/backend/sev/mod.rs index d4154ddc6..a2e744cac 100644 --- a/src/backend/sev/mod.rs +++ b/src/backend/sev/mod.rs @@ -1,8 +1,11 @@ // SPDX-License-Identifier: Apache-2.0 -use super::kvm::{mem, Keep, KeepPersonality}; -use super::sev::mem::Region; +use super::kvm::mem::Region; +use super::kvm::{Keep, KeepPersonality}; use super::Loader; + +use std::sync::Arc; + use anyhow::Result; use data::{ dev_kvm, dev_sev, dev_sev_readable, dev_sev_writable, has_reasonable_memlock_rlimit, @@ -11,7 +14,6 @@ use data::{ use kvm_ioctls::VmFd; use sev::firmware::Firmware; use sev::launch::linux::ioctl::KvmEncRegion; -use std::sync::Arc; mod builder; mod cpuid_page;