diff --git a/Cargo.lock b/Cargo.lock index bd0bda4ed0..fcaf92124b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -426,9 +426,9 @@ dependencies = [ [[package]] name = "cargo_toml" -version = "0.18.0" +version = "0.22.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "802b755090e39835a4b0440fb0bbee0df7495a8b337f63db21e616f7821c7e8c" +checksum = "02260d489095346e5cafd04dea8e8cb54d1d74fcd759022a9b72986ebe9a1257" dependencies = [ "serde", "toml", @@ -6051,9 +6051,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "87607cb1398ed59d48732e575a4c28a7a8ebf2454b964fe3f224f2afc07909e1" dependencies = [ "serde", ] @@ -6735,9 +6735,9 @@ dependencies = [ [[package]] name = "toml" -version = "0.8.8" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a195ec8c9da26928f773888e0742ca3ca1040c6cd859c919c9f59c1954ab35" +checksum = "cd87a5cdd6ffab733b2f74bc4fd7ee5fff6634124999ac278c35fc78c6120148" dependencies = [ "serde", "serde_spanned", @@ -6747,18 +6747,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.21.0" +version = "0.22.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34d383cd00a163b4a5b85053df514d45bc330f6de7737edfe0a93311d1eaa03" +checksum = "17b4795ff5edd201c7cd6dca065ae59972ce77d1b80fa0a84d94950ece7d1474" dependencies = [ "indexmap", "serde", @@ -9291,9 +9291,9 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winnow" -version = "0.5.34" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7cf47b659b318dccbd69cc4797a39ae128f533dce7902a1096044d1967b9c16" +checksum = "0e7f4ea97f6f78012141bcdb6a216b2609f0979ada50b20ca5b52dde2eac2bb1" dependencies = [ "memchr", ] diff --git a/Cargo.toml b/Cargo.toml index b21416c20c..1fda7a1bd3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -50,7 +50,7 @@ exclude = [ [workspace.package] rust-version = "1.85" -edition = "2021" +edition = "2024" [workspace.dependencies] xtask_fuzz = { path = "xtask/xtask_fuzz" } @@ -388,7 +388,7 @@ bitfield-struct = "0.7" bitvec = { version = "1.1", default-features = false } blocking = "1.2" caps = "0.5" -cargo_toml = "0.18" +cargo_toml = "0.22" cc = "1.0" cfg-if = "1" clap = "4.2" @@ -500,7 +500,7 @@ target-lexicon = "0.12.13" tempfile = "3.2" thiserror = { version = "2", default-features = false } time = "0.3" -toml_edit = "0.21" +toml_edit = "0.22" tracing = "0.1" tracing-core = "=0.1.30" # Pin to avoid binary size increase https://github.com/tokio-rs/tracing/issues/3182 tracing-subscriber = "0.3.16" diff --git a/Guide/mdbook-openvmm-shim/Cargo.toml b/Guide/mdbook-openvmm-shim/Cargo.toml index 2c4c88b195..2d647e8612 100644 --- a/Guide/mdbook-openvmm-shim/Cargo.toml +++ b/Guide/mdbook-openvmm-shim/Cargo.toml @@ -3,7 +3,7 @@ [package] name = "mdbook-openvmm-shim" -edition = "2021" +edition = "2024" [package.metadata.xtask.house-rules] # emits a binary, where kebab-case is more natural diff --git a/flowey/flowey_cli/src/cli/debug/dump_stage0_dag.rs b/flowey/flowey_cli/src/cli/debug/dump_stage0_dag.rs index 43c75f4249..5649354dcf 100644 --- a/flowey/flowey_cli/src/cli/debug/dump_stage0_dag.rs +++ b/flowey/flowey_cli/src/cli/debug/dump_stage0_dag.rs @@ -53,7 +53,9 @@ impl DumpStage0Dag { let Some(patchfn) = flowey_core::patch::patchfn_by_modpath().get(patchfn_name.as_str()) else { - anyhow::bail!("could not find patch with name '{patchfn_name}'. Was it registered with `flowey_core::node::register_patch!`?") + anyhow::bail!( + "could not find patch with name '{patchfn_name}'. Was it registered with `flowey_core::node::register_patch!`?" + ) }; patch_aggregator.apply_patchfn(*patchfn); } diff --git a/flowey/flowey_cli/src/cli/debug/interrogate.rs b/flowey/flowey_cli/src/cli/debug/interrogate.rs index ef945c804d..8fee19433a 100644 --- a/flowey/flowey_cli/src/cli/debug/interrogate.rs +++ b/flowey/flowey_cli/src/cli/debug/interrogate.rs @@ -2,15 +2,15 @@ // Licensed under the MIT License. use crate::cli::FlowBackendCli; -use flowey_core::node::steps::rust::RustRuntimeServices; -use flowey_core::node::user_facing::ClaimedGhParam; -use flowey_core::node::user_facing::GhPermission; -use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::node::FlowArch; use flowey_core::node::FlowBackend; use flowey_core::node::FlowPlatform; use flowey_core::node::GhVarState; use flowey_core::node::NodeHandle; +use flowey_core::node::steps::rust::RustRuntimeServices; +use flowey_core::node::user_facing::ClaimedGhParam; +use flowey_core::node::user_facing::GhPermission; +use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::pipeline::HostExt; use flowey_core::pipeline::PipelineBackendHint; use std::collections::BTreeMap; diff --git a/flowey/flowey_cli/src/cli/exec_snippet.rs b/flowey/flowey_cli/src/cli/exec_snippet.rs index 56a6130da0..19634a59ae 100644 --- a/flowey/flowey_cli/src/cli/exec_snippet.rs +++ b/flowey/flowey_cli/src/cli/exec_snippet.rs @@ -3,15 +3,15 @@ use crate::cli::FlowBackendCli; use anyhow::Context; -use flowey_core::node::steps::rust::RustRuntimeServices; -use flowey_core::node::user_facing::ClaimedGhParam; -use flowey_core::node::user_facing::GhPermission; -use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::node::FlowArch; use flowey_core::node::FlowBackend; use flowey_core::node::FlowPlatform; use flowey_core::node::GhVarState; use flowey_core::node::NodeHandle; +use flowey_core::node::steps::rust::RustRuntimeServices; +use flowey_core::node::user_facing::ClaimedGhParam; +use flowey_core::node::user_facing::GhPermission; +use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::pipeline::HostExt; use flowey_core::pipeline::PipelineBackendHint; use serde::Deserialize; diff --git a/flowey/flowey_cli/src/flow_resolver/stage1_dag.rs b/flowey/flowey_cli/src/flow_resolver/stage1_dag.rs index e335758314..dea735d428 100644 --- a/flowey/flowey_cli/src/flow_resolver/stage1_dag.rs +++ b/flowey/flowey_cli/src/flow_resolver/stage1_dag.rs @@ -2,16 +2,16 @@ // Licensed under the MIT License. use anyhow::Context; -use flowey_core::node::read_var_internals; -use flowey_core::node::steps::rust::RustRuntimeServices; -use flowey_core::node::user_facing::ClaimedGhParam; -use flowey_core::node::user_facing::GhPermission; -use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::node::FlowArch; use flowey_core::node::FlowBackend; use flowey_core::node::FlowPlatform; use flowey_core::node::GhVarState; use flowey_core::node::NodeHandle; +use flowey_core::node::read_var_internals; +use flowey_core::node::steps::rust::RustRuntimeServices; +use flowey_core::node::user_facing::ClaimedGhParam; +use flowey_core::node::user_facing::GhPermission; +use flowey_core::node::user_facing::GhPermissionValue; use parking_lot::Mutex; use std::collections::BTreeMap; use std::collections::BTreeSet; @@ -534,7 +534,9 @@ pub(crate) fn stage1_dag( output_graph[idx].1.as_ref().unwrap().step.label() ); } - log::error!("found buggy node that emitted unreachable steps! use `--viz-mode flow-dot` to debug"); + log::error!( + "found buggy node that emitted unreachable steps! use `--viz-mode flow-dot` to debug" + ); Some(FoundUnreachableNodes) } else { None diff --git a/flowey/flowey_cli/src/pipeline_resolver/ado_yaml.rs b/flowey/flowey_cli/src/pipeline_resolver/ado_yaml.rs index 4cf0f19ee6..31b5e116be 100644 --- a/flowey/flowey_cli/src/pipeline_resolver/ado_yaml.rs +++ b/flowey/flowey_cli/src/pipeline_resolver/ado_yaml.rs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use super::common_yaml::FloweySource; use super::common_yaml::check_generated_yaml_and_json; use super::common_yaml::job_flowey_bootstrap_source; use super::common_yaml::write_generated_yaml_and_json; -use super::common_yaml::FloweySource; use super::generic::ResolvedJobArtifact; use super::generic::ResolvedJobUseParameter; use crate::cli::exec_snippet::FloweyPipelineStaticDb; @@ -127,7 +127,9 @@ pub fn ado_yaml( let _ = (artifact, publish); if ado_bootstrap_template.is_empty() { - anyhow::bail!("Did not specify flowey bootstrap template. Please provide one using `Pipeline::ado_set_flowey_bootstrap_template`") + anyhow::bail!( + "Did not specify flowey bootstrap template. Please provide one using `Pipeline::ado_set_flowey_bootstrap_template`" + ) } let ado_bootstrap_template = ado_bootstrap_template diff --git a/flowey/flowey_cli/src/pipeline_resolver/direct_run.rs b/flowey/flowey_cli/src/pipeline_resolver/direct_run.rs index 0d8a082d5f..1a9502b95d 100644 --- a/flowey/flowey_cli/src/pipeline_resolver/direct_run.rs +++ b/flowey/flowey_cli/src/pipeline_resolver/direct_run.rs @@ -8,12 +8,12 @@ use crate::pipeline_resolver::generic::ResolvedJobArtifact; use crate::pipeline_resolver::generic::ResolvedJobUseParameter; use crate::pipeline_resolver::generic::ResolvedPipeline; use crate::pipeline_resolver::generic::ResolvedPipelineJob; -use flowey_core::node::steps::rust::RustRuntimeServices; use flowey_core::node::FlowArch; use flowey_core::node::FlowBackend; use flowey_core::node::FlowPlatform; use flowey_core::node::NodeHandle; use flowey_core::node::RuntimeVarDb; +use flowey_core::node::steps::rust::RustRuntimeServices; use flowey_core::pipeline::internal::Parameter; use petgraph::prelude::NodeIndex; use petgraph::visit::EdgeRef; @@ -198,10 +198,16 @@ fn direct_run_do_work( Step::Anchor { .. } => continue, Step::Rust { label, code, idx } => (label, code, idx), Step::AdoYaml { .. } => { - anyhow::bail!("{} emitted ADO YAML. Fix the node by checking `ctx.backend()` appropriately", node_handle.modpath()) + anyhow::bail!( + "{} emitted ADO YAML. Fix the node by checking `ctx.backend()` appropriately", + node_handle.modpath() + ) } Step::GitHubYaml { .. } => { - anyhow::bail!("{} emitted GitHub YAML. Fix the node by checking `ctx.backend()` appropriately", node_handle.modpath()) + anyhow::bail!( + "{} emitted GitHub YAML. Fix the node by checking `ctx.backend()` appropriately", + node_handle.modpath() + ) } }; steps.push((idx, label, code.lock().take().unwrap())); diff --git a/flowey/flowey_cli/src/pipeline_resolver/generic.rs b/flowey/flowey_cli/src/pipeline_resolver/generic.rs index 30dd70ad32..34cc4eaed1 100644 --- a/flowey/flowey_cli/src/pipeline_resolver/generic.rs +++ b/flowey/flowey_cli/src/pipeline_resolver/generic.rs @@ -2,19 +2,12 @@ // Licensed under the MIT License. use anyhow::Context; -use flowey_core::node::user_facing::GhPermission; -use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::node::FlowArch; use flowey_core::node::FlowPlatform; use flowey_core::node::NodeHandle; +use flowey_core::node::user_facing::GhPermission; +use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::patch::ResolvedPatches; -use flowey_core::pipeline::internal::AdoPool; -use flowey_core::pipeline::internal::ArtifactMeta; -use flowey_core::pipeline::internal::InternalAdoResourcesRepository; -use flowey_core::pipeline::internal::Parameter; -use flowey_core::pipeline::internal::ParameterMeta; -use flowey_core::pipeline::internal::PipelineFinalized; -use flowey_core::pipeline::internal::PipelineJobMetadata; use flowey_core::pipeline::AdoCiTriggers; use flowey_core::pipeline::AdoPrTriggers; use flowey_core::pipeline::AdoScheduleTriggers; @@ -23,6 +16,13 @@ use flowey_core::pipeline::GhPrTriggers; use flowey_core::pipeline::GhRunner; use flowey_core::pipeline::GhScheduleTriggers; use flowey_core::pipeline::Pipeline; +use flowey_core::pipeline::internal::AdoPool; +use flowey_core::pipeline::internal::ArtifactMeta; +use flowey_core::pipeline::internal::InternalAdoResourcesRepository; +use flowey_core::pipeline::internal::Parameter; +use flowey_core::pipeline::internal::ParameterMeta; +use flowey_core::pipeline::internal::PipelineFinalized; +use flowey_core::pipeline::internal::PipelineJobMetadata; use std::collections::BTreeMap; use std::collections::BTreeSet; diff --git a/flowey/flowey_cli/src/pipeline_resolver/github_yaml/github_yaml_defs.rs b/flowey/flowey_cli/src/pipeline_resolver/github_yaml/github_yaml_defs.rs index 889b2fd3e0..640c1c90e3 100644 --- a/flowey/flowey_cli/src/pipeline_resolver/github_yaml/github_yaml_defs.rs +++ b/flowey/flowey_cli/src/pipeline_resolver/github_yaml/github_yaml_defs.rs @@ -6,11 +6,11 @@ #![allow(unused)] use flowey_core::pipeline::GhRunner; -use serde::ser::SerializeMap; -use serde::ser::SerializeSeq; use serde::Deserialize; use serde::Serialize; use serde::Serializer; +use serde::ser::SerializeMap; +use serde::ser::SerializeSeq; use std::collections::BTreeMap; /// Valid names may only contain alphanumeric characters and '_' and may not diff --git a/flowey/flowey_cli/src/pipeline_resolver/github_yaml/mod.rs b/flowey/flowey_cli/src/pipeline_resolver/github_yaml/mod.rs index 33da850233..707bb86f56 100644 --- a/flowey/flowey_cli/src/pipeline_resolver/github_yaml/mod.rs +++ b/flowey/flowey_cli/src/pipeline_resolver/github_yaml/mod.rs @@ -12,18 +12,18 @@ use crate::cli::exec_snippet::VAR_DB_SEEDVAR_FLOWEY_WORKING_DIR; use crate::cli::pipeline::CheckMode; use crate::flow_resolver::stage1_dag::OutputGraphEntry; use crate::flow_resolver::stage1_dag::Step; -use crate::pipeline_resolver::common_yaml::job_flowey_bootstrap_source; use crate::pipeline_resolver::common_yaml::FloweySource; +use crate::pipeline_resolver::common_yaml::job_flowey_bootstrap_source; use crate::pipeline_resolver::generic::ResolvedPipeline; use crate::pipeline_resolver::generic::ResolvedPipelineJob; use anyhow::Context; -use flowey_core::node::user_facing::GhPermission; -use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::node::FlowArch; use flowey_core::node::FlowBackend; use flowey_core::node::FlowPlatform; use flowey_core::node::FlowPlatformKind; use flowey_core::node::NodeHandle; +use flowey_core::node::user_facing::GhPermission; +use flowey_core::node::user_facing::GhPermissionValue; use flowey_core::pipeline::GhRunner; use flowey_core::pipeline::GhRunnerOsLabel; use std::collections::BTreeMap; @@ -127,7 +127,9 @@ pub fn github_yaml( // actual artifact publish happens at the end of the job if let FloweySource::Bootstrap(_artifact, _publish) = &flowey_source { if gh_bootstrap_template.is_empty() { - anyhow::bail!("Did not specify flowey bootstrap template. Please provide one using `Pipeline::gh_set_flowey_bootstrap_template`") + anyhow::bail!( + "Did not specify flowey bootstrap template. Please provide one using `Pipeline::gh_set_flowey_bootstrap_template`" + ) } let gh_bootstrap_template = gh_bootstrap_template diff --git a/flowey/flowey_cli/src/pipeline_resolver/viz.rs b/flowey/flowey_cli/src/pipeline_resolver/viz.rs index 0964161d78..906cdcae25 100644 --- a/flowey/flowey_cli/src/pipeline_resolver/viz.rs +++ b/flowey/flowey_cli/src/pipeline_resolver/viz.rs @@ -347,17 +347,17 @@ pub fn viz_flow_dot( impl std::fmt::Debug for VizNode { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - if self.0 .1.is_none() { - return write!(f, "{:?} - ???", self.0 .0); + if self.0.1.is_none() { + return write!(f, "{:?} - ???", self.0.0); } - let entry = &self.0 .1.as_ref().unwrap(); + let entry = &self.0.1.as_ref().unwrap(); write!( f, "{}:{}\n\n{}", - self.0 .0.step_idx, - self.0 .0.node.modpath(), + self.0.0.step_idx, + self.0.0.node.modpath(), match &entry.step { crate::flow_resolver::stage1_dag::Step::Anchor { label } => { format!("") diff --git a/flowey/flowey_core/src/node.rs b/flowey/flowey_core/src/node.rs index a84eff590e..27f391f0b8 100644 --- a/flowey/flowey_core/src/node.rs +++ b/flowey/flowey_core/src/node.rs @@ -17,9 +17,9 @@ use self::user_facing::GhPermission; use self::user_facing::GhPermissionValue; use crate::node::github_context::GhContextVarReader; use github_context::state::Root; -use serde::de::DeserializeOwned; use serde::Deserialize; use serde::Serialize; +use serde::de::DeserializeOwned; use std::cell::RefCell; use std::collections::BTreeMap; use std::path::PathBuf; @@ -29,14 +29,6 @@ use user_facing::GhParam; /// Node types which are considered "user facing", and re-exported in the /// `flowey` crate. pub mod user_facing { - pub use super::steps::ado::AdoResourcesRepositoryId; - pub use super::steps::ado::AdoRuntimeVar; - pub use super::steps::ado::AdoStepServices; - pub use super::steps::github::ClaimedGhParam; - pub use super::steps::github::GhParam; - pub use super::steps::github::GhPermission; - pub use super::steps::github::GhPermissionValue; - pub use super::steps::rust::RustRuntimeServices; pub use super::ClaimVar; pub use super::ClaimedReadVar; pub use super::ClaimedWriteVar; @@ -57,6 +49,14 @@ pub mod user_facing { pub use super::VarEqBacking; pub use super::VarNotClaimed; pub use super::WriteVar; + pub use super::steps::ado::AdoResourcesRepositoryId; + pub use super::steps::ado::AdoRuntimeVar; + pub use super::steps::ado::AdoStepServices; + pub use super::steps::github::ClaimedGhParam; + pub use super::steps::github::GhParam; + pub use super::steps::github::GhPermission; + pub use super::steps::github::GhPermissionValue; + pub use super::steps::rust::RustRuntimeServices; pub use crate::flowey_request; pub use crate::new_flow_node; pub use crate::new_simple_flow_node; @@ -781,11 +781,7 @@ impl FlowPlatform { /// The suffix to use for executables on this platform. pub fn exe_suffix(&self) -> &'static str { - if self == &Self::Windows { - ".exe" - } else { - "" - } + if self == &Self::Windows { ".exe" } else { "" } } /// The full name for a binary on this platform (i.e. `name + self.exe_suffix()`). @@ -1855,8 +1851,8 @@ pub mod steps { use crate::node::FlowBackend; use crate::node::FlowPlatform; use crate::node::RuntimeVarDb; - use serde::de::DeserializeOwned; use serde::Serialize; + use serde::de::DeserializeOwned; pub fn new_rust_runtime_services( runtime_var_db: &mut dyn RuntimeVarDb, @@ -1989,9 +1985,9 @@ pub trait FlowNodeBase { } pub mod erased { - use crate::node::user_facing::*; use crate::node::FlowNodeBase; use crate::node::NodeCtx; + use crate::node::user_facing::*; pub struct ErasedNode(pub N); @@ -2134,8 +2130,8 @@ mod node_luts { lookup } - pub(super) fn erased_node_by_typeid( - ) -> &'static HashMap Box>>> { + pub(super) fn erased_node_by_typeid() + -> &'static HashMap Box>>> { static LOOKUP: OnceLock< HashMap Box>>>, > = OnceLock::new(); diff --git a/flowey/flowey_core/src/node/github_context.rs b/flowey/flowey_core/src/node/github_context.rs index 3b85277f6b..ce18b93142 100644 --- a/flowey/flowey_core/src/node/github_context.rs +++ b/flowey/flowey_core/src/node/github_context.rs @@ -3,14 +3,14 @@ //! Core types and traits used to read GitHub context variables. -use crate::node::spec::GhContextVarReaderEventPullRequest; use crate::node::ClaimVar; use crate::node::GhUserSecretVar; use crate::node::NodeCtx; use crate::node::ReadVar; use crate::node::StepCtx; -use serde::de::DeserializeOwned; +use crate::node::spec::GhContextVarReaderEventPullRequest; use serde::Serialize; +use serde::de::DeserializeOwned; use std::collections::BTreeMap; pub mod state { diff --git a/flowey/flowey_core/src/pipeline.rs b/flowey/flowey_core/src/pipeline.rs index 16ed8c5e3d..b4feac1578 100644 --- a/flowey/flowey_core/src/pipeline.rs +++ b/flowey/flowey_core/src/pipeline.rs @@ -4,10 +4,6 @@ //! Core types and traits used to create and work with flowey pipelines. use self::internal::*; -use crate::node::steps::ado::AdoResourcesRepositoryId; -use crate::node::user_facing::AdoRuntimeVar; -use crate::node::user_facing::GhPermission; -use crate::node::user_facing::GhPermissionValue; use crate::node::FlowArch; use crate::node::FlowNodeBase; use crate::node::FlowPlatform; @@ -17,10 +13,14 @@ use crate::node::IntoRequest; use crate::node::NodeHandle; use crate::node::ReadVar; use crate::node::WriteVar; +use crate::node::steps::ado::AdoResourcesRepositoryId; +use crate::node::user_facing::AdoRuntimeVar; +use crate::node::user_facing::GhPermission; +use crate::node::user_facing::GhPermissionValue; use crate::patch::PatchResolver; use crate::patch::ResolvedPatches; -use serde::de::DeserializeOwned; use serde::Serialize; +use serde::de::DeserializeOwned; use std::collections::BTreeMap; use std::collections::BTreeSet; use std::path::PathBuf; diff --git a/flowey/flowey_hvlite/src/pipelines/build_igvm.rs b/flowey/flowey_hvlite/src/pipelines/build_igvm.rs index 8f58f37d6c..5553da693e 100644 --- a/flowey/flowey_hvlite/src/pipelines/build_igvm.rs +++ b/flowey/flowey_hvlite/src/pipelines/build_igvm.rs @@ -197,11 +197,17 @@ pub fn bail_if_running_in_ci() -> anyhow::Result<()> { log::warn!("Detected that {ci_env} is set"); log::warn!(""); log::warn!("Do not use `build-igvm` in CI scripts!"); - log::warn!("This is a local-only, inner-dev-loop tool to build IGVM files, with an UNSTABLE CLI."); + log::warn!( + "This is a local-only, inner-dev-loop tool to build IGVM files, with an UNSTABLE CLI." + ); log::warn!(""); - log::warn!("Automated pipelines should use the underlying `flowey` nodes that power build-igvm directly, _without_ relying on its CLI!"); + log::warn!( + "Automated pipelines should use the underlying `flowey` nodes that power build-igvm directly, _without_ relying on its CLI!" + ); log::warn!(""); - log::warn!("If you _really_ know what you're doing, you can set {OVERRIDE_ENV} to disable this error."); + log::warn!( + "If you _really_ know what you're doing, you can set {OVERRIDE_ENV} to disable this error." + ); anyhow::bail!("attempted to run `build-igvm` in CI") } } diff --git a/flowey/flowey_lib_common/src/install_rust.rs b/flowey/flowey_lib_common/src/install_rust.rs index 1ed9265212..bd3c875fec 100644 --- a/flowey/flowey_lib_common/src/install_rust.rs +++ b/flowey/flowey_lib_common/src/install_rust.rs @@ -140,7 +140,9 @@ impl FlowNode for Node { // way to detect this... if stderr.contains("does not support components") { log::warn!("Detected a non-standard `rustup default` toolchain!"); - log::warn!("Will not be able to double-check that all required target-triples are available."); + log::warn!( + "Will not be able to double-check that all required target-triples are available." + ); } else { let mut installed_target_triples = BTreeSet::new(); @@ -151,7 +153,9 @@ impl FlowNode for Node { for expected_target in additional_target_triples { if !installed_target_triples.contains(expected_target.as_str()) { - anyhow::bail!("missing required target-triple: {expected_target}; to intsall: `rustup target add {expected_target}`") + anyhow::bail!( + "missing required target-triple: {expected_target}; to intsall: `rustup target add {expected_target}`" + ) } } } diff --git a/flowey/flowey_lib_common/src/run_cargo_nextest_run.rs b/flowey/flowey_lib_common/src/run_cargo_nextest_run.rs index f47aad102e..79aec60056 100644 --- a/flowey/flowey_lib_common/src/run_cargo_nextest_run.rs +++ b/flowey/flowey_lib_common/src/run_cargo_nextest_run.rs @@ -237,7 +237,7 @@ impl FlowNode for Node { // the profile, and if so, where the output if going to be. let junit_path = { let nextest_toml = fs_err::read_to_string(&config_file)? - .parse::() + .parse::() .context("failed to parse nextest.toml")?; let path = Some(&nextest_toml) diff --git a/flowey/flowey_lib_hvlite/src/build_and_test_vmgs_lib.rs b/flowey/flowey_lib_hvlite/src/build_and_test_vmgs_lib.rs index 1378a6ea3f..b3797ba6fc 100644 --- a/flowey/flowey_lib_hvlite/src/build_and_test_vmgs_lib.rs +++ b/flowey/flowey_lib_hvlite/src/build_and_test_vmgs_lib.rs @@ -5,9 +5,9 @@ //! //! Tests are windows only at the moment. +use crate::run_cargo_build::CargoBuildOutput; use crate::run_cargo_build::common::CommonProfile; use crate::run_cargo_build::common::CommonTriple; -use crate::run_cargo_build::CargoBuildOutput; use flowey::node::prelude::*; use flowey_lib_common::run_cargo_build::CargoCrateType; diff --git a/flowey/flowey_lib_hvlite/src/build_nextest_unit_tests.rs b/flowey/flowey_lib_hvlite/src/build_nextest_unit_tests.rs index 95482056b9..b1518e090a 100644 --- a/flowey/flowey_lib_hvlite/src/build_nextest_unit_tests.rs +++ b/flowey/flowey_lib_hvlite/src/build_nextest_unit_tests.rs @@ -16,10 +16,10 @@ use crate::run_cargo_build::common::CommonTriple; use crate::run_cargo_nextest_run::NextestProfile; use flowey::node::prelude::*; use flowey_lib_common::run_cargo_build::CargoBuildProfile; +use flowey_lib_common::run_cargo_nextest_run::TestResults; use flowey_lib_common::run_cargo_nextest_run::build_params::FeatureSet; use flowey_lib_common::run_cargo_nextest_run::build_params::PanicAbortTests; use flowey_lib_common::run_cargo_nextest_run::build_params::TestPackages; -use flowey_lib_common::run_cargo_nextest_run::TestResults; /// Type-safe wrapper around a built nextest archive containing unit tests #[derive(Serialize, Deserialize)] diff --git a/flowey/flowey_lib_hvlite/src/build_nextest_vmm_tests.rs b/flowey/flowey_lib_hvlite/src/build_nextest_vmm_tests.rs index 26a462db25..f1f274ea12 100644 --- a/flowey/flowey_lib_hvlite/src/build_nextest_vmm_tests.rs +++ b/flowey/flowey_lib_hvlite/src/build_nextest_vmm_tests.rs @@ -7,9 +7,9 @@ use crate::run_cargo_build::common::CommonProfile; use crate::run_cargo_nextest_run::NextestProfile; use flowey::node::prelude::*; use flowey_lib_common::run_cargo_build::CargoBuildProfile; +use flowey_lib_common::run_cargo_nextest_run::TestResults; use flowey_lib_common::run_cargo_nextest_run::build_params::FeatureSet; use flowey_lib_common::run_cargo_nextest_run::build_params::TestPackages; -use flowey_lib_common::run_cargo_nextest_run::TestResults; use std::collections::BTreeMap; /// Type-safe wrapper around a built nextest archive containing VMM tests diff --git a/flowey/flowey_lib_hvlite/src/build_openhcl_boot.rs b/flowey/flowey_lib_hvlite/src/build_openhcl_boot.rs index 80524c3271..e1ac301ad9 100644 --- a/flowey/flowey_lib_hvlite/src/build_openhcl_boot.rs +++ b/flowey/flowey_lib_hvlite/src/build_openhcl_boot.rs @@ -3,8 +3,8 @@ //! Build `openhcl_boot` binaries -use crate::run_cargo_build::common::CommonArch; use crate::run_cargo_build::BuildProfile; +use crate::run_cargo_build::common::CommonArch; use flowey::node::prelude::*; use std::collections::BTreeMap; diff --git a/flowey/flowey_lib_hvlite/src/build_sidecar.rs b/flowey/flowey_lib_hvlite/src/build_sidecar.rs index f3dc8f2a07..21502599fd 100644 --- a/flowey/flowey_lib_hvlite/src/build_sidecar.rs +++ b/flowey/flowey_lib_hvlite/src/build_sidecar.rs @@ -3,8 +3,8 @@ //! Build `sidecar` binaries -use crate::run_cargo_build::common::CommonArch; use crate::run_cargo_build::BuildProfile; +use crate::run_cargo_build::common::CommonArch; use flowey::node::prelude::*; use std::collections::BTreeMap; diff --git a/flowey/flowey_lib_hvlite/src/build_xtask.rs b/flowey/flowey_lib_hvlite/src/build_xtask.rs index 638ac5e960..2737f693bf 100644 --- a/flowey/flowey_lib_hvlite/src/build_xtask.rs +++ b/flowey/flowey_lib_hvlite/src/build_xtask.rs @@ -3,8 +3,8 @@ //! Build `xtask` binary -use crate::run_cargo_build::common::CommonTriple; use crate::run_cargo_build::BuildProfile; +use crate::run_cargo_build::common::CommonTriple; use flowey::node::prelude::*; use flowey_lib_common::run_cargo_build::CargoCrateType; diff --git a/flowey/flowey_lib_hvlite/src/run_split_debug_info.rs b/flowey/flowey_lib_hvlite/src/run_split_debug_info.rs index b24d2e0c2c..b4d4eb770c 100644 --- a/flowey/flowey_lib_hvlite/src/run_split_debug_info.rs +++ b/flowey/flowey_lib_hvlite/src/run_split_debug_info.rs @@ -35,11 +35,13 @@ impl SimpleFlowNode for Node { let installed_objcopy = ctx.reqv( |side_effect| flowey_lib_common::install_dist_pkg::Request::Install { - package_names: vec![match arch { - CommonArch::X86_64 => "binutils-x86-64-linux-gnu", - CommonArch::Aarch64 => "binutils-aarch64-linux-gnu", - } - .into()], + package_names: vec![ + match arch { + CommonArch::X86_64 => "binutils-x86-64-linux-gnu", + CommonArch::Aarch64 => "binutils-aarch64-linux-gnu", + } + .into(), + ], done: side_effect, }, ); diff --git a/guest_test_uefi/src/uefi/mod.rs b/guest_test_uefi/src/uefi/mod.rs index b65908d75f..f0c5ccd151 100644 --- a/guest_test_uefi/src/uefi/mod.rs +++ b/guest_test_uefi/src/uefi/mod.rs @@ -7,10 +7,10 @@ mod tests; use core::num::NonZeroU8; use splash::Splashes; +use uefi::Status; use uefi::entry; use uefi::println; use uefi::system; -use uefi::Status; #[entry] fn uefi_main() -> Status { diff --git a/guest_test_uefi/src/uefi/splash.rs b/guest_test_uefi/src/uefi/splash.rs index 60654dfa56..bf719e9715 100644 --- a/guest_test_uefi/src/uefi/splash.rs +++ b/guest_test_uefi/src/uefi/splash.rs @@ -6,12 +6,12 @@ use alloc::vec::Vec; use core::num::NonZeroU8; +use uefi::Result; use uefi::boot; use uefi::proto::console::gop::BltOp; use uefi::proto::console::gop::BltPixel; use uefi::proto::console::gop::BltRegion; use uefi::proto::console::gop::GraphicsOutput; -use uefi::Result; struct Buffer { width: usize, diff --git a/guest_test_uefi/src/uefi/tests/mod.rs b/guest_test_uefi/src/uefi/tests/mod.rs index d992a2d469..94328f2d64 100644 --- a/guest_test_uefi/src/uefi/tests/mod.rs +++ b/guest_test_uefi/src/uefi/tests/mod.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::uefi::splash; use crate::uefi::Splashes; +use crate::uefi::splash; use core::num::NonZeroU8; use uefi::boot; use uefi::cstr16; diff --git a/hyperv/tools/hypestv/src/windows/mod.rs b/hyperv/tools/hypestv/src/windows/mod.rs index c712773ff6..187d5f4948 100644 --- a/hyperv/tools/hypestv/src/windows/mod.rs +++ b/hyperv/tools/hypestv/src/windows/mod.rs @@ -13,8 +13,8 @@ use clap::CommandFactory; use clap::FromArgMatches; use clap::Parser; use clap::ValueEnum; -use futures::executor::block_on; use futures::StreamExt; +use futures::executor::block_on; use hyperv::run_hvc; use mesh::rpc::RpcSend; use pal_async::DefaultDriver; diff --git a/hyperv/tools/hypestv/src/windows/vm.rs b/hyperv/tools/hypestv/src/windows/vm.rs index f47b4c241d..ff5b42be65 100644 --- a/hyperv/tools/hypestv/src/windows/vm.rs +++ b/hyperv/tools/hypestv/src/windows/vm.rs @@ -3,30 +3,30 @@ //! VM command handling. -use super::hyperv::hvc_output; -use super::hyperv::powershell_script; -use super::hyperv::run_hcsdiag; -use super::hyperv::run_hvc; -use super::rustyline_printer::Printer; use super::InspectArgs; use super::InspectTarget; use super::LogMode; use super::ParavisorCommand; use super::SerialMode; use super::VmCommand; +use super::hyperv::hvc_output; +use super::hyperv::powershell_script; +use super::hyperv::run_hcsdiag; +use super::hyperv::run_hvc; +use super::rustyline_printer::Printer; use anyhow::Context as _; use diag_client::DiagClient; -use futures::io::BufReader; use futures::AsyncBufReadExt; use futures::AsyncWriteExt; use futures::FutureExt; use futures::StreamExt; +use futures::io::BufReader; use futures_concurrency::future::Race; use guid::Guid; +use pal_async::DefaultDriver; use pal_async::pipe::PolledPipe; use pal_async::task::Spawn; use pal_async::task::Task; -use pal_async::DefaultDriver; use std::sync::Arc; use std::time::Duration; diff --git a/openhcl/bootloader_fdt_parser/src/lib.rs b/openhcl/bootloader_fdt_parser/src/lib.rs index 422236b44b..ffa498762e 100644 --- a/openhcl/bootloader_fdt_parser/src/lib.rs +++ b/openhcl/bootloader_fdt_parser/src/lib.rs @@ -7,13 +7,13 @@ #![forbid(unsafe_code)] -use anyhow::bail; use anyhow::Context; +use anyhow::bail; use fdt::parser::Node; use fdt::parser::Parser; use fdt::parser::Property; -use igvm_defs::dt::IGVM_DT_IGVM_TYPE_PROPERTY; use igvm_defs::MemoryMapEntryType; +use igvm_defs::dt::IGVM_DT_IGVM_TYPE_PROPERTY; use inspect::Inspect; use loader_defs::shim::MemoryVtlType; use memory_range::MemoryRange; diff --git a/openhcl/diag_client/src/lib.rs b/openhcl/diag_client/src/lib.rs index 4520211405..b94a11acdf 100644 --- a/openhcl/diag_client/src/lib.rs +++ b/openhcl/diag_client/src/lib.rs @@ -6,11 +6,11 @@ pub mod kmsg_stream; use anyhow::Context; -use diag_proto::network_packet_capture_request::OpData; -use diag_proto::network_packet_capture_request::Operation; use diag_proto::ExecRequest; use diag_proto::WaitRequest; use diag_proto::WaitResponse; +use diag_proto::network_packet_capture_request::OpData; +use diag_proto::network_packet_capture_request::Operation; use futures::AsyncReadExt; use futures::AsyncWrite; use futures::AsyncWriteExt; diff --git a/openhcl/diag_server/src/diag_service.rs b/openhcl/diag_server/src/diag_service.rs index 8ea84987dc..2792ec6582 100644 --- a/openhcl/diag_server/src/diag_service.rs +++ b/openhcl/diag_server/src/diag_service.rs @@ -8,9 +8,9 @@ use crate::new_pty; use anyhow::Context; use azure_profiler_proto::AzureProfiler; use azure_profiler_proto::ProfileRequest; -use diag_proto::network_packet_capture_request::Operation; use diag_proto::ExecRequest; use diag_proto::ExecResponse; +use diag_proto::FILE_LINE_MAX; use diag_proto::FileRequest; use diag_proto::KmsgRequest; use diag_proto::NetworkPacketCaptureRequest; @@ -20,15 +20,15 @@ use diag_proto::StartRequest; use diag_proto::UnderhillDiag; use diag_proto::WaitRequest; use diag_proto::WaitResponse; -use diag_proto::FILE_LINE_MAX; -use futures::future::join_all; -use futures::io::AllowStdIo; +use diag_proto::network_packet_capture_request::Operation; use futures::AsyncRead; use futures::AsyncReadExt; use futures::AsyncWrite; use futures::AsyncWriteExt; use futures::FutureExt; use futures::StreamExt; +use futures::future::join_all; +use futures::io::AllowStdIo; use futures_concurrency::stream::Merge; use inspect::InspectionBuilder; use inspect_proto::InspectRequest; @@ -36,9 +36,9 @@ use inspect_proto::InspectResponse2; use inspect_proto::InspectService; use inspect_proto::UpdateRequest; use inspect_proto::UpdateResponse2; +use mesh::CancelContext; use mesh::rpc::FailableRpc; use mesh::rpc::RpcSend; -use mesh::CancelContext; use mesh_rpc::server::RpcReceiver; use net_packet_capture::OperationData; use net_packet_capture::PacketCaptureOperation; diff --git a/openhcl/hcl/src/ioctl.rs b/openhcl/hcl/src/ioctl.rs index 3ada4eab61..90bd6fb037 100644 --- a/openhcl/hcl/src/ioctl.rs +++ b/openhcl/hcl/src/ioctl.rs @@ -16,30 +16,22 @@ pub mod x64; use self::deferred::DeferredActionSlots; use self::deferred::DeferredActions; use self::ioctls::*; +use crate::GuestVtl; use crate::ioctl::deferred::DeferredAction; use crate::mapped_page::MappedPage; use crate::protocol; -use crate::protocol::hcl_intr_offload_flags; -use crate::protocol::hcl_run; use crate::protocol::EnterModes; use crate::protocol::HCL_REG_PAGE_OFFSET; use crate::protocol::HCL_VMSA_GUEST_VSM_PAGE_OFFSET; use crate::protocol::HCL_VMSA_PAGE_OFFSET; use crate::protocol::MSHV_APIC_PAGE_OFFSET; -use crate::GuestVtl; +use crate::protocol::hcl_intr_offload_flags; +use crate::protocol::hcl_run; use hv1_structs::ProcessorSet; use hv1_structs::VtlArray; -use hvdef::hypercall::AssertVirtualInterrupt; -use hvdef::hypercall::HostVisibilityType; -use hvdef::hypercall::HvGpaRange; -use hvdef::hypercall::HvGpaRangeExtended; -use hvdef::hypercall::HvInputVtl; -use hvdef::hypercall::HvInterceptParameters; -use hvdef::hypercall::HvInterceptType; -use hvdef::hypercall::HvRegisterAssoc; -use hvdef::hypercall::HypercallOutput; -use hvdef::hypercall::InitialVpContextX64; -use hvdef::hypercall::ModifyHostVisibility; +use hvdef::HV_PAGE_SIZE; +use hvdef::HV_PARTITION_ID_SELF; +use hvdef::HV_VP_INDEX_SELF; use hvdef::HvAllArchRegisterName; #[cfg(guest_arch = "aarch64")] use hvdef::HvArm64RegisterName; @@ -54,9 +46,17 @@ use hvdef::HvX64RegisterName; use hvdef::HvX64RegisterPage; use hvdef::HypercallCode; use hvdef::Vtl; -use hvdef::HV_PAGE_SIZE; -use hvdef::HV_PARTITION_ID_SELF; -use hvdef::HV_VP_INDEX_SELF; +use hvdef::hypercall::AssertVirtualInterrupt; +use hvdef::hypercall::HostVisibilityType; +use hvdef::hypercall::HvGpaRange; +use hvdef::hypercall::HvGpaRangeExtended; +use hvdef::hypercall::HvInputVtl; +use hvdef::hypercall::HvInterceptParameters; +use hvdef::hypercall::HvInterceptType; +use hvdef::hypercall::HvRegisterAssoc; +use hvdef::hypercall::HypercallOutput; +use hvdef::hypercall::InitialVpContextX64; +use hvdef::hypercall::ModifyHostVisibility; use memory_range::MemoryRange; use pal::unix::pthread::*; use parking_lot::Mutex; @@ -71,14 +71,14 @@ use std::fmt::Debug; use std::fs::File; use std::io; use std::os::unix::prelude::*; -use std::sync::atomic::AtomicU32; -use std::sync::atomic::AtomicU8; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::Once; +use std::sync::atomic::AtomicU8; +use std::sync::atomic::AtomicU32; +use std::sync::atomic::Ordering; use thiserror::Error; -use user_driver::memory::MemoryBlock; use user_driver::DmaClient; +use user_driver::memory::MemoryBlock; use x86defs::snp::SevVmsa; use x86defs::tdx::TdCallResultCode; use x86defs::vmx::ApicPage; @@ -153,7 +153,9 @@ pub enum Error { Sidecar(#[source] sidecar_client::SidecarError), #[error("failed to open sidecar")] OpenSidecar(#[source] NewSidecarClientError), - #[error("mismatch between requested isolation type {requested:?} and supported isolation type {supported:?}")] + #[error( + "mismatch between requested isolation type {requested:?} and supported isolation type {supported:?}" + )] MismatchedIsolation { supported: IsolationType, requested: IsolationType, @@ -194,7 +196,9 @@ impl HypercallError { #[derive(Error, Debug)] #[expect(missing_docs)] pub enum HvcallError { - #[error("kernel rejected the hypercall, most likely due to the hypercall code not being allowed via set_allowed_hypercalls")] + #[error( + "kernel rejected the hypercall, most likely due to the hypercall code not being allowed via set_allowed_hypercalls" + )] HypercallIoctlFailed(#[source] nix::Error), #[error("input parameters are larger than a page")] InputParametersTooLarge, @@ -229,7 +233,9 @@ pub enum ApplyVtlProtectionsError { permissions: x86defs::snp::SevRmpAdjust, vtl: HvInputVtl, }, - #[error("tdcall failed with {error:?} when protecting pages {range} with permissions {permissions:x?} for vtl {vtl:?}")] + #[error( + "tdcall failed with {error:?} when protecting pages {range} with permissions {permissions:x?} for vtl {vtl:?}" + )] Tdx { error: TdCallResultCode, range: MemoryRange, @@ -1654,7 +1660,7 @@ mod private { pub trait BackingPrivate<'a>: Sized { fn new(vp: &'a HclVp, sidecar: Option<&SidecarVp<'a>>, hcl: &Hcl) - -> Result; + -> Result; fn try_set_reg( runner: &mut ProcessorRunner<'_, Self>, diff --git a/openhcl/hcl/src/ioctl/aarch64.rs b/openhcl/hcl/src/ioctl/aarch64.rs index 1cdf23c8dd..f53ac4cc62 100644 --- a/openhcl/hcl/src/ioctl/aarch64.rs +++ b/openhcl/hcl/src/ioctl/aarch64.rs @@ -7,8 +7,8 @@ use super::Hcl; use super::HclVp; use super::NoRunner; use super::ProcessorRunner; -use crate::protocol::hcl_cpu_context_aarch64; use crate::GuestVtl; +use crate::protocol::hcl_cpu_context_aarch64; use hvdef::HvArm64RegisterName; use hvdef::HvRegisterName; use hvdef::HvRegisterValue; diff --git a/openhcl/hcl/src/ioctl/snp.rs b/openhcl/hcl/src/ioctl/snp.rs index 0fba81e6f1..37c3ff97c6 100644 --- a/openhcl/hcl/src/ioctl/snp.rs +++ b/openhcl/hcl/src/ioctl/snp.rs @@ -3,23 +3,23 @@ //! Backing for SNP partitions. +use super::Hcl; +use super::HclVp; +use super::MshvVtl; +use super::NoRunner; +use super::ProcessorRunner; use super::hcl_pvalidate_pages; use super::hcl_rmpadjust_pages; use super::hcl_rmpquery_pages; use super::mshv_pvalidate; use super::mshv_rmpadjust; use super::mshv_rmpquery; -use super::Hcl; -use super::HclVp; -use super::MshvVtl; -use super::NoRunner; -use super::ProcessorRunner; -use crate::vmsa::VmsaWrapper; use crate::GuestVtl; +use crate::vmsa::VmsaWrapper; use hv1_structs::VtlArray; +use hvdef::HV_PAGE_SIZE; use hvdef::HvRegisterName; use hvdef::HvRegisterValue; -use hvdef::HV_PAGE_SIZE; use memory_range::MemoryRange; use sidecar_client::SidecarVp; use std::cell::UnsafeCell; diff --git a/openhcl/hcl/src/ioctl/tdx.rs b/openhcl/hcl/src/ioctl/tdx.rs index 7240adb7b0..3339e14fdc 100644 --- a/openhcl/hcl/src/ioctl/tdx.rs +++ b/openhcl/hcl/src/ioctl/tdx.rs @@ -3,18 +3,18 @@ //! Backing for TDX partitions. -use super::hcl_tdcall; -use super::mshv_tdcall; use super::Hcl; use super::HclVp; use super::MshvVtl; use super::NoRunner; use super::ProcessorRunner; +use super::hcl_tdcall; +use super::mshv_tdcall; +use crate::GuestVtl; use crate::protocol::tdx_tdg_vp_enter_exit_info; use crate::protocol::tdx_vp_context; use crate::protocol::tdx_vp_state; use crate::protocol::tdx_vp_state_flags; -use crate::GuestVtl; use hv1_structs::VtlArray; use hvdef::HvRegisterName; use hvdef::HvRegisterValue; @@ -22,10 +22,10 @@ use memory_range::MemoryRange; use sidecar_client::SidecarVp; use std::cell::UnsafeCell; use std::os::fd::AsRawFd; +use tdcall::Tdcall; use tdcall::tdcall_vp_invgla; use tdcall::tdcall_vp_rd; use tdcall::tdcall_vp_wr; -use tdcall::Tdcall; use x86defs::tdx::TdCallResult; use x86defs::tdx::TdCallResultCode; use x86defs::tdx::TdGlaVmAndFlags; diff --git a/openhcl/hcl/src/ioctl/x64.rs b/openhcl/hcl/src/ioctl/x64.rs index 46a475fd83..5524b95836 100644 --- a/openhcl/hcl/src/ioctl/x64.rs +++ b/openhcl/hcl/src/ioctl/x64.rs @@ -3,7 +3,6 @@ //! Backing for non-hardware-isolated X64 partitions. -use super::private::BackingPrivate; use super::BackingState; use super::Error; use super::GuestVtl; @@ -13,14 +12,15 @@ use super::NoRunner; use super::ProcessorRunner; use super::TranslateGvaToGpaError; use super::TranslateResult; +use super::private::BackingPrivate; use crate::protocol::hcl_cpu_context_x64; +use hvdef::HV_PARTITION_ID_SELF; +use hvdef::HV_VP_INDEX_SELF; use hvdef::HvRegisterName; use hvdef::HvRegisterValue; use hvdef::HvX64RegisterName; use hvdef::HvX64RegisterPage; use hvdef::HypercallCode; -use hvdef::HV_PARTITION_ID_SELF; -use hvdef::HV_VP_INDEX_SELF; use sidecar_client::SidecarVp; use std::cell::UnsafeCell; use zerocopy::FromZeros; diff --git a/openhcl/hcl/src/lib.rs b/openhcl/hcl/src/lib.rs index bd6c0312c8..3198b673d2 100644 --- a/openhcl/hcl/src/lib.rs +++ b/openhcl/hcl/src/lib.rs @@ -8,8 +8,8 @@ // UNSAFETY: Calling ioctls. #![expect(unsafe_code)] -use hvdef::hypercall::HvInputVtl; use hvdef::Vtl; +use hvdef::hypercall::HvInputVtl; use inspect::Inspect; use thiserror::Error; diff --git a/openhcl/hcl/src/protocol.rs b/openhcl/hcl/src/protocol.rs index 59f97a23c5..af1a907bbb 100644 --- a/openhcl/hcl/src/protocol.rs +++ b/openhcl/hcl/src/protocol.rs @@ -12,8 +12,8 @@ )] use bitfield_struct::bitfield; -use hvdef::hypercall::HvInputVtl; use hvdef::HV_MESSAGE_SIZE; +use hvdef::hypercall::HvInputVtl; use libc::c_void; use zerocopy::FromBytes; use zerocopy::Immutable; diff --git a/openhcl/host_fdt_parser/src/lib.rs b/openhcl/host_fdt_parser/src/lib.rs index 0d9feedbbf..3f2e16183f 100644 --- a/openhcl/host_fdt_parser/src/lib.rs +++ b/openhcl/host_fdt_parser/src/lib.rs @@ -291,14 +291,13 @@ pub struct CpuEntry { } impl< - 'a, - 'b, - const MAX_MEMORY_ENTRIES: usize, - const MAX_CPU_ENTRIES: usize, - const MAX_COMMAND_LINE_SIZE: usize, - const MAX_ENTROPY_SIZE: usize, - > - ParsedDeviceTree + 'a, + 'b, + const MAX_MEMORY_ENTRIES: usize, + const MAX_CPU_ENTRIES: usize, + const MAX_COMMAND_LINE_SIZE: usize, + const MAX_ENTROPY_SIZE: usize, +> ParsedDeviceTree { /// Create an empty parsed device tree structure. This is used to construct /// a valid instance to pass into [`Self::parse`]. @@ -339,7 +338,7 @@ impl< return Err(ErrorKind::Node { parent_name: "", error: e, - }) + }); } }; @@ -355,7 +354,7 @@ impl< return Err(ErrorKind::MemoryRegOverlap { lower: memory[index], upper: entry, - }) + }); } Err(index) => index, }; @@ -954,7 +953,7 @@ fn parse_simple_bus<'a>( return Err(ErrorKind::UnexpectedVmbusVtl { node_name: child.name, vtl, - }) + }); } } } diff --git a/openhcl/lower_vtl_permissions_guard/src/lib.rs b/openhcl/lower_vtl_permissions_guard/src/lib.rs index 16338c9075..9e2b5b2213 100644 --- a/openhcl/lower_vtl_permissions_guard/src/lib.rs +++ b/openhcl/lower_vtl_permissions_guard/src/lib.rs @@ -14,8 +14,8 @@ use anyhow::Context; use anyhow::Result; use inspect::Inspect; use std::sync::Arc; -use user_driver::memory::MemoryBlock; use user_driver::DmaClient; +use user_driver::memory::MemoryBlock; use virt::VtlMemoryProtection; /// A guard that will restore [`hvdef::HV_MAP_GPA_PERMISSIONS_NONE`] permissions diff --git a/openhcl/ohcldiag-dev/src/completions.rs b/openhcl/ohcldiag-dev/src/completions.rs index 68a6b4ba84..27f04a3c95 100644 --- a/openhcl/ohcldiag-dev/src/completions.rs +++ b/openhcl/ohcldiag-dev/src/completions.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::new_client; use crate::VmArg; use crate::VmId; +use crate::new_client; use clap::Parser; use clap_dyn_complete::CustomCompleter; use clap_dyn_complete::CustomCompleterFactory; diff --git a/openhcl/ohcldiag-dev/src/main.rs b/openhcl/ohcldiag-dev/src/main.rs index 9094d27332..cebf2a37ba 100644 --- a/openhcl/ohcldiag-dev/src/main.rs +++ b/openhcl/ohcldiag-dev/src/main.rs @@ -15,14 +15,14 @@ use clap::Parser; use clap::Subcommand; use diag_client::DiagClient; use diag_client::PacketCaptureOperation; -use futures::io::AllowStdIo; use futures::StreamExt; +use futures::io::AllowStdIo; use futures_concurrency::future::Race; +use pal_async::DefaultPool; use pal_async::driver::Driver; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; use pal_async::timer::PolledTimer; -use pal_async::DefaultPool; use std::convert::Infallible; use std::ffi::OsStr; use std::io::ErrorKind; @@ -895,7 +895,7 @@ fn create_or_stderr(path: &Option) -> std::io::Result { async fn capture_packets( client: DiagClient, - streams: Vec>>, + streams: Vec>>, capture_duration: Duration, ) { let mut capture_streams = FuturesUnordered::from_iter(streams); diff --git a/openhcl/openhcl_boot/src/arch/aarch64/memory.rs b/openhcl/openhcl_boot/src/arch/aarch64/memory.rs index b8b2ea3386..733accacaa 100644 --- a/openhcl/openhcl_boot/src/arch/aarch64/memory.rs +++ b/openhcl/openhcl_boot/src/arch/aarch64/memory.rs @@ -3,9 +3,9 @@ //! Setting up memory -use crate::hvcall; use crate::PartitionInfo; use crate::ShimParams; +use crate::hvcall; use aarch64defs::IntermPhysAddrSize; pub fn setup_vtl2_memory(_shim_params: &ShimParams, _partition_info: &PartitionInfo) { diff --git a/openhcl/openhcl_boot/src/arch/aarch64/vp.rs b/openhcl/openhcl_boot/src/arch/aarch64/vp.rs index f266c69b64..c9052518c4 100644 --- a/openhcl/openhcl_boot/src/arch/aarch64/vp.rs +++ b/openhcl/openhcl_boot/src/arch/aarch64/vp.rs @@ -3,8 +3,8 @@ //! Setting up VTL2 VPs -use crate::hypercall::hvcall; use crate::PartitionInfo; +use crate::hypercall::hvcall; pub fn setup_vtl2_vp(partition_info: &PartitionInfo) { // VTL2 kernel boot processor will try to remote read the GICR before AP's are diff --git a/openhcl/openhcl_boot/src/arch/x86_64/address_space.rs b/openhcl/openhcl_boot/src/arch/x86_64/address_space.rs index 2ec7e567da..8b467a1b86 100644 --- a/openhcl/openhcl_boot/src/arch/x86_64/address_space.rs +++ b/openhcl/openhcl_boot/src/arch/x86_64/address_space.rs @@ -14,9 +14,9 @@ use crate::single_threaded::SingleThreaded; use core::arch::asm; use core::cell::Cell; use core::marker::PhantomData; -use core::sync::atomic::compiler_fence; use core::sync::atomic::AtomicU64; use core::sync::atomic::Ordering; +use core::sync::atomic::compiler_fence; use memory_range::MemoryRange; use x86defs::X64_LARGE_PAGE_SIZE; use zerocopy::FromBytes; diff --git a/openhcl/openhcl_boot/src/arch/x86_64/memory.rs b/openhcl/openhcl_boot/src/arch/x86_64/memory.rs index 022fdd2c55..0f15e6daeb 100644 --- a/openhcl/openhcl_boot/src/arch/x86_64/memory.rs +++ b/openhcl/openhcl_boot/src/arch/x86_64/memory.rs @@ -3,17 +3,17 @@ //! Routines to prepare VTL2 memory for launching the kernel. -use super::address_space::init_local_map; use super::address_space::LocalMap; -use crate::host_params::shim_params::IsolationType; +use super::address_space::init_local_map; +use crate::ShimParams; use crate::host_params::PartitionInfo; +use crate::host_params::shim_params::IsolationType; use crate::hypercall::hvcall; -use crate::ShimParams; use memory_range::MemoryRange; use sha2::Digest; use sha2::Sha384; -use x86defs::tdx::TDX_SHARED_GPA_BOUNDARY_ADDRESS_BIT; use x86defs::X64_LARGE_PAGE_SIZE; +use x86defs::tdx::TDX_SHARED_GPA_BOUNDARY_ADDRESS_BIT; /// On isolated systems, transitions all VTL2 RAM to be private and accepted, with the appropriate /// VTL permissions applied. diff --git a/openhcl/openhcl_boot/src/arch/x86_64/snp.rs b/openhcl/openhcl_boot/src/arch/x86_64/snp.rs index 8e1711396c..552edfe5b5 100644 --- a/openhcl/openhcl_boot/src/arch/x86_64/snp.rs +++ b/openhcl/openhcl_boot/src/arch/x86_64/snp.rs @@ -8,8 +8,8 @@ use core::arch::asm; use memory_range::MemoryRange; use minimal_rt::arch::msr::read_msr; use minimal_rt::arch::msr::write_msr; -use x86defs::snp::GhcbInfo; use x86defs::X86X_AMD_MSR_GHCB; +use x86defs::snp::GhcbInfo; pub struct Ghcb; diff --git a/openhcl/openhcl_boot/src/arch/x86_64/tdx.rs b/openhcl/openhcl_boot/src/arch/x86_64/tdx.rs index 47858bd3cd..5ed6e2a7e1 100644 --- a/openhcl/openhcl_boot/src/arch/x86_64/tdx.rs +++ b/openhcl/openhcl_boot/src/arch/x86_64/tdx.rs @@ -7,12 +7,12 @@ use crate::single_threaded::SingleThreaded; use core::arch::asm; use core::cell::Cell; use memory_range::MemoryRange; -use tdcall::tdcall_map_gpa; -use tdcall::tdcall_rdmsr; use tdcall::AcceptPagesError; use tdcall::Tdcall; use tdcall::TdcallInput; use tdcall::TdcallOutput; +use tdcall::tdcall_map_gpa; +use tdcall::tdcall_rdmsr; /// Perform a tdcall instruction with the specified inputs. fn tdcall(input: TdcallInput) -> TdcallOutput { diff --git a/openhcl/openhcl_boot/src/cmdline.rs b/openhcl/openhcl_boot/src/cmdline.rs index be352aa607..b7ab35e9df 100644 --- a/openhcl/openhcl_boot/src/cmdline.rs +++ b/openhcl/openhcl_boot/src/cmdline.rs @@ -60,11 +60,7 @@ pub fn parse_boot_command_line(cmdline: &str) -> BootCommandLineOptions { let num = arg.parse::().unwrap_or(0); // A size of 0 or failure to parse is treated as disabling // the pool. - if num == 0 { - None - } else { - Some(num) - } + if num == 0 { None } else { Some(num) } }); } } diff --git a/openhcl/openhcl_boot/src/dt.rs b/openhcl/openhcl_boot/src/dt.rs index bf25b1fb86..fdc6669f13 100644 --- a/openhcl/openhcl_boot/src/dt.rs +++ b/openhcl/openhcl_boot/src/dt.rs @@ -4,13 +4,13 @@ //! Module used to write the device tree used by the OpenHCL kernel and //! usermode. -use crate::host_params::shim_params::IsolationType; -use crate::host_params::PartitionInfo; +use crate::MAX_RESERVED_MEM_RANGES; +use crate::ReservedMemoryType; use crate::host_params::COMMAND_LINE_SIZE; +use crate::host_params::PartitionInfo; +use crate::host_params::shim_params::IsolationType; use crate::sidecar::SidecarConfig; use crate::single_threaded::off_stack; -use crate::ReservedMemoryType; -use crate::MAX_RESERVED_MEM_RANGES; use arrayvec::ArrayString; use arrayvec::ArrayVec; use core::fmt; @@ -23,9 +23,9 @@ use host_fdt_parser::VmbusInfo; use hvdef::Vtl; use igvm_defs::dt::IGVM_DT_IGVM_TYPE_PROPERTY; use loader_defs::shim::MemoryVtlType; -use memory_range::walk_ranges; use memory_range::MemoryRange; use memory_range::RangeWalkResult; +use memory_range::walk_ranges; /// AArch64 defines mod aarch64 { diff --git a/openhcl/openhcl_boot/src/host_params/dt.rs b/openhcl/openhcl_boot/src/host_params/dt.rs index c1b7d1351c..a1a97ccc1b 100644 --- a/openhcl/openhcl_boot/src/host_params/dt.rs +++ b/openhcl/openhcl_boot/src/host_params/dt.rs @@ -3,9 +3,9 @@ //! Parse partition info using the IGVM device tree parameter. +use super::PartitionInfo; use super::shim_params::IsolationType; use super::shim_params::ShimParams; -use super::PartitionInfo; use crate::boot_logger::log; use crate::host_params::COMMAND_LINE_SIZE; use crate::host_params::MAX_CPU_COUNT; @@ -13,8 +13,8 @@ use crate::host_params::MAX_ENTROPY_SIZE; use crate::host_params::MAX_NUMA_NODES; use crate::host_params::MAX_PARTITION_RAM_RANGES; use crate::host_params::MAX_VTL2_USED_RANGES; -use crate::single_threaded::off_stack; use crate::single_threaded::OffStackRef; +use crate::single_threaded::off_stack; use arrayvec::ArrayVec; use core::cmp::max; use core::fmt::Display; @@ -25,10 +25,10 @@ use host_fdt_parser::ParsedDeviceTree; use hvdef::HV_PAGE_SIZE; use igvm_defs::MemoryMapEntryType; use loader_defs::paravisor::CommandLinePolicy; +use memory_range::MemoryRange; use memory_range::flatten_ranges; use memory_range::subtract_ranges; use memory_range::walk_ranges; -use memory_range::MemoryRange; /// Errors when reading the host device tree. #[derive(Debug)] @@ -248,7 +248,9 @@ fn allocate_vtl2_ram( if required_mem != 0 { // TODO: Handle fallback allocations on other numa nodes when a node // is exhausted. - panic!("failed to allocate {required_mem:#x} for vnode {node:#x}, no memory remaining for vnode"); + panic!( + "failed to allocate {required_mem:#x} for vnode {node:#x}, no memory remaining for vnode" + ); } } diff --git a/openhcl/openhcl_boot/src/host_params/mmio.rs b/openhcl/openhcl_boot/src/host_params/mmio.rs index 6c96955775..a6184ad82f 100644 --- a/openhcl/openhcl_boot/src/host_params/mmio.rs +++ b/openhcl/openhcl_boot/src/host_params/mmio.rs @@ -3,8 +3,8 @@ //! Manages MMIO range partitioning between VTLs. -use super::dt::DtError; use super::PartitionInfo; +use super::dt::DtError; use memory_range::MemoryRange; /// The start address of MMIO high range. diff --git a/openhcl/openhcl_boot/src/host_params/mod.rs b/openhcl/openhcl_boot/src/host_params/mod.rs index 3f5a6e596c..ea9ac0d422 100644 --- a/openhcl/openhcl_boot/src/host_params/mod.rs +++ b/openhcl/openhcl_boot/src/host_params/mod.rs @@ -11,8 +11,8 @@ use host_fdt_parser::GicInfo; use host_fdt_parser::MemoryAllocationMode; use host_fdt_parser::MemoryEntry; use host_fdt_parser::VmbusInfo; -use memory_range::subtract_ranges; use memory_range::MemoryRange; +use memory_range::subtract_ranges; use shim_params::IsolationType; mod dt; diff --git a/openhcl/openhcl_boot/src/hypercall.rs b/openhcl/openhcl_boot/src/hypercall.rs index 93d2f0d7bb..18c744afc6 100644 --- a/openhcl/openhcl_boot/src/hypercall.rs +++ b/openhcl/openhcl_boot/src/hypercall.rs @@ -8,9 +8,9 @@ use arrayvec::ArrayVec; use core::cell::RefCell; use core::cell::UnsafeCell; use core::mem::size_of; -use hvdef::hypercall::HvInputVtl; -use hvdef::Vtl; use hvdef::HV_PAGE_SIZE; +use hvdef::Vtl; +use hvdef::hypercall::HvInputVtl; use memory_range::MemoryRange; use minimal_rt::arch::hypercall::invoke_hypercall; use zerocopy::FromBytes; diff --git a/openhcl/openhcl_boot/src/main.rs b/openhcl/openhcl_boot/src/main.rs index 5e4e9744fd..4e871421b5 100644 --- a/openhcl/openhcl_boot/src/main.rs +++ b/openhcl/openhcl_boot/src/main.rs @@ -32,20 +32,20 @@ use arrayvec::ArrayString; use arrayvec::ArrayVec; use boot_logger::LoggerType; use core::fmt::Write; -use dt::write_dt; use dt::BootTimes; +use dt::write_dt; +use host_params::COMMAND_LINE_SIZE; +use host_params::PartitionInfo; use host_params::shim_params::IsolationType; use host_params::shim_params::ShimParams; -use host_params::PartitionInfo; -use host_params::COMMAND_LINE_SIZE; use hvdef::Vtl; -use loader_defs::linux::setup_data; use loader_defs::linux::SETUP_DTB; +use loader_defs::linux::setup_data; use loader_defs::shim::ShimParamsRaw; -use memory_range::merge_adjacent_ranges; -use memory_range::walk_ranges; use memory_range::MemoryRange; use memory_range::RangeWalkResult; +use memory_range::merge_adjacent_ranges; +use memory_range::walk_ranges; use minimal_rt::enlightened_panic::enable_enlightened_panic; use sidecar::SidecarConfig; use sidecar_defs::SidecarOutput; @@ -374,24 +374,24 @@ fn reserved_memory_regions( #[cfg_attr(not(target_arch = "x86_64"), allow(dead_code))] mod x86_boot { + use crate::PageAlign; + use crate::ReservedMemoryType; use crate::host_params::PartitionInfo; - use crate::single_threaded::off_stack; use crate::single_threaded::OffStackRef; + use crate::single_threaded::off_stack; use crate::zeroed; - use crate::PageAlign; - use crate::ReservedMemoryType; use core::mem::size_of; use core::ops::Range; use core::ptr; - use loader_defs::linux::boot_params; - use loader_defs::linux::e820entry; - use loader_defs::linux::setup_data; use loader_defs::linux::E820_RAM; use loader_defs::linux::E820_RESERVED; use loader_defs::linux::SETUP_E820_EXT; - use memory_range::walk_ranges; + use loader_defs::linux::boot_params; + use loader_defs::linux::e820entry; + use loader_defs::linux::setup_data; use memory_range::MemoryRange; use memory_range::RangeWalkResult; + use memory_range::walk_ranges; use zerocopy::FromZeros; use zerocopy::Immutable; use zerocopy::KnownLayout; @@ -863,14 +863,14 @@ fn main() { #[cfg(test)] mod test { - use super::x86_boot::build_e820_map; use super::x86_boot::E820Ext; + use super::x86_boot::build_e820_map; + use crate::ReservedMemoryType; use crate::dt::write_dt; - use crate::host_params::shim_params::IsolationType; - use crate::host_params::PartitionInfo; use crate::host_params::MAX_CPU_COUNT; + use crate::host_params::PartitionInfo; + use crate::host_params::shim_params::IsolationType; use crate::reserved_memory_regions; - use crate::ReservedMemoryType; use arrayvec::ArrayString; use arrayvec::ArrayVec; use core::ops::Range; @@ -878,13 +878,13 @@ mod test { use host_fdt_parser::MemoryEntry; use host_fdt_parser::VmbusInfo; use igvm_defs::MemoryMapEntryType; - use loader_defs::linux::boot_params; - use loader_defs::linux::e820entry; use loader_defs::linux::E820_RAM; use loader_defs::linux::E820_RESERVED; - use memory_range::walk_ranges; + use loader_defs::linux::boot_params; + use loader_defs::linux::e820entry; use memory_range::MemoryRange; use memory_range::RangeWalkResult; + use memory_range::walk_ranges; use zerocopy::FromZeros; const HIGH_MMIO_GAP_END: u64 = 0x1000000000; // 64 GiB @@ -1125,13 +1125,15 @@ mod test { let partition_info = partition_info_ram_ranges(&[ONE_MB..4 * ONE_MB], parameter_range, None); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_ok()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_ok() + ); check_e820( &boot_params, @@ -1153,13 +1155,15 @@ mod test { Some(3 * ONE_MB..4 * ONE_MB), ); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_ok()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_ok() + ); check_e820( &boot_params, @@ -1183,13 +1187,15 @@ mod test { Some(3 * ONE_MB..4 * ONE_MB), ); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_ok()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_ok() + ); check_e820( &boot_params, @@ -1221,13 +1227,15 @@ mod test { Some(3 * ONE_MB..4 * ONE_MB), ); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_ok()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_ok() + ); check_e820( &boot_params, @@ -1253,13 +1261,15 @@ mod test { let partition_info = partition_info_ram_ranges(&[ONE_MB..4 * ONE_MB], parameter_range, None); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_err()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_err() + ); // parameter range start partial coverage let mut boot_params: boot_params = FromZeros::new_zeroed(); @@ -1268,13 +1278,15 @@ mod test { let partition_info = partition_info_ram_ranges(&[ONE_MB..4 * ONE_MB], parameter_range, None); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_err()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_err() + ); // parameter range end partial coverage let mut boot_params: boot_params = FromZeros::new_zeroed(); @@ -1283,13 +1295,15 @@ mod test { let partition_info = partition_info_ram_ranges(&[4 * ONE_MB..6 * ONE_MB], parameter_range, None); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_err()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_err() + ); // parameter range larger than ram let mut boot_params: boot_params = FromZeros::new_zeroed(); @@ -1298,13 +1312,15 @@ mod test { let partition_info = partition_info_ram_ranges(&[4 * ONE_MB..6 * ONE_MB], parameter_range, None); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_err()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_err() + ); // ram has gap inside param range let mut boot_params: boot_params = FromZeros::new_zeroed(); @@ -1316,13 +1332,15 @@ mod test { None, ); - assert!(build_e820_map( - &mut boot_params, - &mut ext, - &partition_info, - reserved_memory_regions(&partition_info, None).as_ref(), - ) - .is_err()); + assert!( + build_e820_map( + &mut boot_params, + &mut ext, + &partition_info, + reserved_memory_regions(&partition_info, None).as_ref(), + ) + .is_err() + ); } #[test] diff --git a/openhcl/openhcl_boot/src/sidecar.rs b/openhcl/openhcl_boot/src/sidecar.rs index d3d69ba0ff..01de19848a 100644 --- a/openhcl/openhcl_boot/src/sidecar.rs +++ b/openhcl/openhcl_boot/src/sidecar.rs @@ -2,11 +2,11 @@ // Licensed under the MIT License. use crate::boot_logger::log; -use crate::host_params::shim_params::IsolationType; -use crate::host_params::shim_params::ShimParams; -use crate::host_params::PartitionInfo; use crate::host_params::MAX_CPU_COUNT; use crate::host_params::MAX_NUMA_NODES; +use crate::host_params::PartitionInfo; +use crate::host_params::shim_params::IsolationType; +use crate::host_params::shim_params::ShimParams; use crate::single_threaded::off_stack; use arrayvec::ArrayVec; use memory_range::MemoryRange; @@ -162,7 +162,9 @@ pub fn start_sidecar<'a>( log!("sidecar: not enough memory for sidecar"); return None; }; - log!("sidecar: not enough memory for sidecar on node {local_vnode}, falling back to node {remote_vnode}"); + log!( + "sidecar: not enough memory for sidecar on node {local_vnode}, falling back to node {remote_vnode}" + ); vtl2_ram = &mut free_memory[remote_vnode]; } let (rest, mem) = vtl2_ram.split_at_offset(vtl2_ram.len() - required_ram); diff --git a/openhcl/openhcl_dma_manager/src/lib.rs b/openhcl/openhcl_dma_manager/src/lib.rs index aef25bb34c..f5e55cc631 100644 --- a/openhcl/openhcl_dma_manager/src/lib.rs +++ b/openhcl/openhcl_dma_manager/src/lib.rs @@ -17,8 +17,8 @@ use page_pool_alloc::PagePool; use page_pool_alloc::PagePoolAllocator; use page_pool_alloc::PagePoolAllocatorSpawner; use std::sync::Arc; -use user_driver::lockmem::LockedMemorySpawner; use user_driver::DmaClient; +use user_driver::lockmem::LockedMemorySpawner; /// Save restore support for [`OpenhclDmaManager`]. pub mod save_restore { @@ -73,7 +73,7 @@ pub mod save_restore { (Some(_), None) => { return Err(RestoreError::InvalidSavedState(anyhow::anyhow!( "saved state for shared pool but no shared pool" - ))) + ))); } (None, Some(_)) => { // It's possible that previously we did not have a shared @@ -91,7 +91,7 @@ pub mod save_restore { (Some(_), None) => { return Err(RestoreError::InvalidSavedState(anyhow::anyhow!( "saved state for private pool but no private pool" - ))) + ))); } (None, Some(_)) => { // It's possible that previously we did not have a private diff --git a/openhcl/profiler_worker/src/lib.rs b/openhcl/profiler_worker/src/lib.rs index a4ccd8d1fd..44db998e49 100644 --- a/openhcl/profiler_worker/src/lib.rs +++ b/openhcl/profiler_worker/src/lib.rs @@ -8,14 +8,14 @@ use anyhow::Context; use futures::FutureExt; -use mesh::error::RemoteError; use mesh::MeshPayload; +use mesh::error::RemoteError; use mesh_worker::Worker; use mesh_worker::WorkerId; use mesh_worker::WorkerRpc; +use pal_async::DefaultPool; use pal_async::driver::Driver; use pal_async::timer::PolledTimer; -use pal_async::DefaultPool; use socket2::Socket; use std::io::Read; use std::os::fd::AsRawFd; diff --git a/openhcl/sidecar/src/arch/x86_64/init.rs b/openhcl/sidecar/src/arch/x86_64/init.rs index af1ca9b559..51885024c6 100644 --- a/openhcl/sidecar/src/arch/x86_64/init.rs +++ b/openhcl/sidecar/src/arch/x86_64/init.rs @@ -4,14 +4,14 @@ //! Sidecar initialization code. This code runs once, on the BSP, before the //! main kernel boots. -use super::addr_space; -use super::temporary_map; -use super::CommandErrorWriter; -use super::VpGlobals; use super::AFTER_INIT; +use super::CommandErrorWriter; use super::ENABLE_LOG; use super::VSM_CAPABILITIES; use super::VTL_RETURN_OFFSET; +use super::VpGlobals; +use super::addr_space; +use super::temporary_map; use crate::arch::x86_64::get_hv_vp_register; use crate::arch::x86_64::hypercall; use crate::arch::x86_64::log; @@ -26,28 +26,28 @@ use core::sync::atomic::AtomicU32; use core::sync::atomic::Ordering::Acquire; use core::sync::atomic::Ordering::Relaxed; use core::sync::atomic::Ordering::Release; -use hvdef::hypercall::EnableVpVtlX64; -use hvdef::hypercall::HvInputVtl; -use hvdef::hypercall::StartVirtualProcessorX64; use hvdef::HvError; use hvdef::HvRegisterVsmCodePageOffsets; use hvdef::HvX64RegisterName; use hvdef::HvX64SegmentRegister; use hvdef::HypercallCode; +use hvdef::hypercall::EnableVpVtlX64; +use hvdef::hypercall::HvInputVtl; +use hvdef::hypercall::StartVirtualProcessorX64; use memory_range::AlignedSubranges; use memory_range::MemoryRange; use minimal_rt::arch::hypercall::HYPERCALL_PAGE; use minimal_rt::enlightened_panic; -use sidecar_defs::required_memory; use sidecar_defs::ControlPage; use sidecar_defs::CpuStatus; +use sidecar_defs::PAGE_SIZE; +use sidecar_defs::PER_VP_PAGES; +use sidecar_defs::PER_VP_SHMEM_PAGES; use sidecar_defs::SidecarNodeOutput; use sidecar_defs::SidecarNodeParams; use sidecar_defs::SidecarOutput; use sidecar_defs::SidecarParams; -use sidecar_defs::PAGE_SIZE; -use sidecar_defs::PER_VP_PAGES; -use sidecar_defs::PER_VP_SHMEM_PAGES; +use sidecar_defs::required_memory; use x86defs::Exception; use x86defs::GdtEntry; use x86defs::IdtAttributes; diff --git a/openhcl/sidecar/src/arch/x86_64/mod.rs b/openhcl/sidecar/src/arch/x86_64/mod.rs index a731eb35b7..78af42eeb7 100644 --- a/openhcl/sidecar/src/arch/x86_64/mod.rs +++ b/openhcl/sidecar/src/arch/x86_64/mod.rs @@ -16,8 +16,8 @@ use core::sync::atomic::AtomicBool; use core::sync::atomic::Ordering::Acquire; use hvdef::HvError; use hvdef::HypercallCode; -use minimal_rt::arch::msr::write_msr; use minimal_rt::arch::Serial; +use minimal_rt::arch::msr::write_msr; use x86defs::Exception; use zerocopy::FromBytes; use zerocopy::IntoBytes; @@ -169,9 +169,9 @@ macro_rules! log { }; } use core::mem::size_of; -use hvdef::hypercall::HvInputVtl; use hvdef::HvRegisterName; use hvdef::HvRegisterValue; +use hvdef::hypercall::HvInputVtl; pub(crate) use log; use minimal_rt::arch::InstrIoAccess; diff --git a/openhcl/sidecar/src/arch/x86_64/temporary_map.rs b/openhcl/sidecar/src/arch/x86_64/temporary_map.rs index 3aa755cf5f..58cfb6495d 100644 --- a/openhcl/sidecar/src/arch/x86_64/temporary_map.rs +++ b/openhcl/sidecar/src/arch/x86_64/temporary_map.rs @@ -7,8 +7,8 @@ use super::addr_space; use core::ops::Deref; use core::ops::DerefMut; -use core::sync::atomic::compiler_fence; use core::sync::atomic::Ordering::SeqCst; +use core::sync::atomic::compiler_fence; use x86defs::Pte; const PAGE_SIZE: usize = 0x1000; diff --git a/openhcl/sidecar/src/arch/x86_64/vp.rs b/openhcl/sidecar/src/arch/x86_64/vp.rs index a31fad6d30..1bdedcd7c4 100644 --- a/openhcl/sidecar/src/arch/x86_64/vp.rs +++ b/openhcl/sidecar/src/arch/x86_64/vp.rs @@ -4,15 +4,15 @@ //! Sidecar code that runs on the APs, after initialization. This code all runs //! with per-AP page tables, concurrently with the main kernel. +use super::CommandErrorWriter; +use super::VSM_CAPABILITIES; +use super::VTL_RETURN_OFFSET; +use super::VpGlobals; use super::addr_space; use super::get_hv_vp_register; use super::hypercall; use super::log; use super::set_hv_vp_register; -use super::CommandErrorWriter; -use super::VpGlobals; -use super::VSM_CAPABILITIES; -use super::VTL_RETURN_OFFSET; use core::fmt::Write; use core::mem::size_of; use core::ptr::addr_of; @@ -20,16 +20,16 @@ use core::sync::atomic::AtomicU8; use core::sync::atomic::Ordering::Acquire; use core::sync::atomic::Ordering::Relaxed; use core::sync::atomic::Ordering::Release; -use hvdef::hypercall::HvInputVtl; -use hvdef::hypercall::HvRegisterAssoc; -use hvdef::hypercall::TranslateVirtualAddressX64; +use hvdef::HV_PAGE_SHIFT; +use hvdef::HV_PARTITION_ID_SELF; +use hvdef::HV_VP_INDEX_SELF; use hvdef::HvStatus; use hvdef::HvVtlEntryReason; use hvdef::HvX64RegisterName; use hvdef::HypercallCode; -use hvdef::HV_PAGE_SHIFT; -use hvdef::HV_PARTITION_ID_SELF; -use hvdef::HV_VP_INDEX_SELF; +use hvdef::hypercall::HvInputVtl; +use hvdef::hypercall::HvRegisterAssoc; +use hvdef::hypercall::TranslateVirtualAddressX64; use minimal_rt::arch::hypercall::HYPERCALL_PAGE; use minimal_rt::arch::msr::read_msr; use minimal_rt::arch::msr::write_msr; diff --git a/openhcl/sidecar_client/src/lib.rs b/openhcl/sidecar_client/src/lib.rs index 298e80b596..1c381cba69 100644 --- a/openhcl/sidecar_client/src/lib.rs +++ b/openhcl/sidecar_client/src/lib.rs @@ -8,12 +8,12 @@ #![expect(unsafe_code)] use fs_err::os::unix::fs::OpenOptionsExt; -use hvdef::hypercall::HvInputVtl; -use hvdef::hypercall::HvRegisterAssoc; -use hvdef::hypercall::TranslateVirtualAddressExOutputX64; use hvdef::HvError; use hvdef::HvMessage; use hvdef::HvStatus; +use hvdef::hypercall::HvInputVtl; +use hvdef::hypercall::HvRegisterAssoc; +use hvdef::hypercall::TranslateVirtualAddressExOutputX64; use pal_async::driver::PollImpl; use pal_async::driver::SpawnDriver; use pal_async::fd::PollFdReady; @@ -24,11 +24,11 @@ use parking_lot::Mutex; use sidecar_defs::CommandPage; use sidecar_defs::CpuContextX64; use sidecar_defs::GetSetVpRegisterRequest; +use sidecar_defs::PAGE_SIZE; use sidecar_defs::RunVpResponse; use sidecar_defs::SidecarCommand; use sidecar_defs::TranslateGvaRequest; use sidecar_defs::TranslateGvaResponse; -use sidecar_defs::PAGE_SIZE; use std::fs::File; use std::future::poll_fn; use std::io::Read; @@ -36,13 +36,13 @@ use std::mem::MaybeUninit; use std::ops::Range; use std::os::fd::AsRawFd; use std::os::raw::c_void; +use std::ptr::NonNull; use std::ptr::addr_of; use std::ptr::addr_of_mut; -use std::ptr::NonNull; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::Acquire; use std::sync::atomic::Ordering::Release; -use std::sync::Arc; use std::task::Poll; use std::task::Waker; use thiserror::Error; @@ -187,7 +187,7 @@ impl SidecarNode { return Err(NewSidecarClientError::Io { operation: "open", err, - }) + }); } }; diff --git a/openhcl/sidecar_defs/src/lib.rs b/openhcl/sidecar_defs/src/lib.rs index 4605e7078a..112b7de230 100644 --- a/openhcl/sidecar_defs/src/lib.rs +++ b/openhcl/sidecar_defs/src/lib.rs @@ -6,11 +6,11 @@ #![no_std] #![forbid(unsafe_code)] -use core::sync::atomic::AtomicU32; use core::sync::atomic::AtomicU8; -use hvdef::hypercall::HvInputVtl; +use core::sync::atomic::AtomicU32; use hvdef::HvMessage; use hvdef::HvStatus; +use hvdef::hypercall::HvInputVtl; use open_enum::open_enum; use zerocopy::FromBytes; use zerocopy::FromZeros; diff --git a/openhcl/underhill_attestation/src/igvm_attest/ak_cert.rs b/openhcl/underhill_attestation/src/igvm_attest/ak_cert.rs index f1d66054de..6383d5dd80 100644 --- a/openhcl/underhill_attestation/src/igvm_attest/ak_cert.rs +++ b/openhcl/underhill_attestation/src/igvm_attest/ak_cert.rs @@ -4,15 +4,17 @@ //! The module for `AK_CERT_REQUEST` request type that supports parsing the //! response. -use openhcl_attestation_protocol::igvm_attest::get::IgvmAttestAkCertResponseHeader; use openhcl_attestation_protocol::igvm_attest::get::AK_CERT_RESPONSE_HEADER_VERSION; +use openhcl_attestation_protocol::igvm_attest::get::IgvmAttestAkCertResponseHeader; use thiserror::Error; use zerocopy::FromBytes; /// AkCertError is returned by parse_ak_cert_response() in emuplat/tpm.rs #[derive(Debug, Error)] pub enum AkCertError { - #[error("AK cert response is too small to parse. Found {size} bytes but expected at least {minimum_size}")] + #[error( + "AK cert response is too small to parse. Found {size} bytes but expected at least {minimum_size}" + )] SizeTooSmall { size: usize, minimum_size: usize }, #[error( "AK cert response size {specified_size} specified in the header is larger then the actual size {size}" @@ -88,10 +90,12 @@ mod tests { // When we finally have `HEADER_SIZE` bytes, we no longer see the failure as `AkCertError::SizeTooSmall`, // but we still see a different error since the response is not valid. let properly_sized_parse = parse_response(&properly_sized_response); - assert!(!properly_sized_parse - .unwrap_err() - .to_string() - .starts_with("AK cert response is too small to parse"),); + assert!( + !properly_sized_parse + .unwrap_err() + .to_string() + .starts_with("AK cert response is too small to parse"), + ); } #[test] diff --git a/openhcl/underhill_attestation/src/igvm_attest/key_release.rs b/openhcl/underhill_attestation/src/igvm_attest/key_release.rs index 0f571bf0a4..889428fa33 100644 --- a/openhcl/underhill_attestation/src/igvm_attest/key_release.rs +++ b/openhcl/underhill_attestation/src/igvm_attest/key_release.rs @@ -11,8 +11,8 @@ use openssl::hash::MessageDigest; use openssl::pkey::PKey; use openssl::rsa::Padding; use openssl::sign::Verifier; -use openssl::x509::X509VerifyResult; use openssl::x509::X509; +use openssl::x509::X509VerifyResult; use std::fmt::Write; use thiserror::Error; diff --git a/openhcl/underhill_attestation/src/igvm_attest/mod.rs b/openhcl/underhill_attestation/src/igvm_attest/mod.rs index fae391027a..8df8281719 100644 --- a/openhcl/underhill_attestation/src/igvm_attest/mod.rs +++ b/openhcl/underhill_attestation/src/igvm_attest/mod.rs @@ -6,10 +6,10 @@ //! `IGVM_ATTEST` host request. use base64_serde::base64_serde_type; -use openhcl_attestation_protocol::igvm_attest::get::runtime_claims::AttestationVmConfig; use openhcl_attestation_protocol::igvm_attest::get::IgvmAttestHashType; use openhcl_attestation_protocol::igvm_attest::get::IgvmAttestReportType; use openhcl_attestation_protocol::igvm_attest::get::IgvmAttestRequestType; +use openhcl_attestation_protocol::igvm_attest::get::runtime_claims::AttestationVmConfig; use tee_call::TeeType; use thiserror::Error; use zerocopy::FromZeros; diff --git a/openhcl/underhill_attestation/src/key_protector.rs b/openhcl/underhill_attestation/src/key_protector.rs index 2b5084d9c1..a5d003ee81 100644 --- a/openhcl/underhill_attestation/src/key_protector.rs +++ b/openhcl/underhill_attestation/src/key_protector.rs @@ -3,12 +3,12 @@ //! Implementation of the key retrieval logic for the [`KeyProtector`]. -use crate::crypto; use crate::Keys; +use crate::crypto; use cvm_tracing::CVM_ALLOWED; use cvm_tracing::CVM_CONFIDENTIAL; -use openhcl_attestation_protocol::vmgs::KeyProtector; use openhcl_attestation_protocol::vmgs::AES_GCM_KEY_LENGTH; +use openhcl_attestation_protocol::vmgs::KeyProtector; use openssl::pkey::Private; use openssl::rsa::Rsa; use thiserror::Error; @@ -24,7 +24,9 @@ pub(crate) enum GetKeysFromKeyProtectorError { key_size: usize, expected_size: usize, }, - #[error("Wrapped DiskEncryptionSettings key size {key_size} was smaller than expected {expected_size}")] + #[error( + "Wrapped DiskEncryptionSettings key size {key_size} was smaller than expected {expected_size}" + )] InvalidWrappedDesKeySize { key_size: usize, expected_size: usize, diff --git a/openhcl/underhill_attestation/src/lib.rs b/openhcl/underhill_attestation/src/lib.rs index 434440e0d6..7bea5361ae 100644 --- a/openhcl/underhill_attestation/src/lib.rs +++ b/openhcl/underhill_attestation/src/lib.rs @@ -16,17 +16,17 @@ mod key_protector; mod secure_key_release; mod vmgs; -pub use igvm_attest::ak_cert::parse_response as parse_ak_cert_response; pub use igvm_attest::Error as IgvmAttestError; pub use igvm_attest::IgvmAttestRequestHelper; +pub use igvm_attest::ak_cert::parse_response as parse_ak_cert_response; use ::vmgs::EncryptionAlgorithm; use ::vmgs::Vmgs; use cvm_tracing::CVM_ALLOWED; +use guest_emulation_transport::GuestEmulationTransportClient; use guest_emulation_transport::api::GspExtendedStatusFlags; use guest_emulation_transport::api::GuestStateProtection; use guest_emulation_transport::api::GuestStateProtectionById; -use guest_emulation_transport::GuestEmulationTransportClient; use guid::Guid; use hardware_key_sealing::HardwareDerivedKeys; use hardware_key_sealing::HardwareKeyProtectorExt as _; @@ -34,10 +34,10 @@ use key_protector::GetKeysFromKeyProtectorError; use key_protector::KeyProtectorExt as _; use mesh::MeshPayload; use openhcl_attestation_protocol::igvm_attest::get::runtime_claims::AttestationVmConfig; +use openhcl_attestation_protocol::vmgs::AES_GCM_KEY_LENGTH; use openhcl_attestation_protocol::vmgs::HardwareKeyProtector; use openhcl_attestation_protocol::vmgs::KeyProtector; use openhcl_attestation_protocol::vmgs::SecurityProfile; -use openhcl_attestation_protocol::vmgs::AES_GCM_KEY_LENGTH; use openssl::pkey::Private; use openssl::rsa::Rsa; use pal_async::local::LocalDriver; @@ -1064,13 +1064,13 @@ mod tests { use super::*; use disk_backend::Disk; use disklayer_ram::ram_disk; - use get_protocol::GspExtendedStatusFlags; use get_protocol::GSP_CLEARTEXT_MAX; + use get_protocol::GspExtendedStatusFlags; use key_protector::AES_WRAPPED_AES_KEY_LENGTH; - use openhcl_attestation_protocol::vmgs::DekKp; - use openhcl_attestation_protocol::vmgs::GspKp; use openhcl_attestation_protocol::vmgs::DEK_BUFFER_SIZE; + use openhcl_attestation_protocol::vmgs::DekKp; use openhcl_attestation_protocol::vmgs::GSP_BUFFER_SIZE; + use openhcl_attestation_protocol::vmgs::GspKp; use openhcl_attestation_protocol::vmgs::NUMBER_KP; use pal_async::async_test; use vmgs_format::EncryptionAlgorithm; @@ -1719,10 +1719,12 @@ mod tests { .await .unwrap(); - assert!(found_key_protector.dek[active_kp_copy as usize] - .dek_buffer - .iter() - .all(|&b| b == 0),); + assert!( + found_key_protector.dek[active_kp_copy as usize] + .dek_buffer + .iter() + .all(|&b| b == 0), + ); assert_eq!( found_key_protector.gsp[active_kp_copy as usize].gsp_length, 0 diff --git a/openhcl/underhill_attestation/src/secure_key_release.rs b/openhcl/underhill_attestation/src/secure_key_release.rs index 4dde948009..5543c52631 100644 --- a/openhcl/underhill_attestation/src/secure_key_release.rs +++ b/openhcl/underhill_attestation/src/secure_key_release.rs @@ -4,14 +4,14 @@ //! Implementation of secure key release (SKR) scheme for stateful CVM to obtain VMGS //! encryption keys. +use crate::IgvmAttestRequestHelper; use crate::crypto; use crate::igvm_attest; -use crate::IgvmAttestRequestHelper; use cvm_tracing::CVM_ALLOWED; use guest_emulation_transport::GuestEmulationTransportClient; -use openhcl_attestation_protocol::igvm_attest::get::runtime_claims::AttestationVmConfig; use openhcl_attestation_protocol::igvm_attest::get::KEY_RELEASE_RESPONSE_BUFFER_SIZE; use openhcl_attestation_protocol::igvm_attest::get::WRAPPED_KEY_RESPONSE_BUFFER_SIZE; +use openhcl_attestation_protocol::igvm_attest::get::runtime_claims::AttestationVmConfig; use openhcl_attestation_protocol::vmgs::AGENT_DATA_MAX_SIZE; use openssl::pkey::Private; use openssl::rsa::Rsa; @@ -35,7 +35,9 @@ pub(crate) enum RequestVmgsEncryptionKeysError { ParseIgvmAttestWrappedKeyResponse(#[source] igvm_attest::wrapped_key::WrappedKeyError), #[error("wrapped key from WRAPPED_KEY response is empty")] EmptyWrappedKey, - #[error("key reference size {key_reference_size} from WRAPPED_KEY response was larger than expected {expected_size}")] + #[error( + "key reference size {key_reference_size} from WRAPPED_KEY response was larger than expected {expected_size}" + )] InvalidKeyReferenceSize { key_reference_size: usize, expected_size: usize, diff --git a/openhcl/underhill_attestation/src/vmgs.rs b/openhcl/underhill_attestation/src/vmgs.rs index 1df8ef4e13..62ad74408e 100644 --- a/openhcl/underhill_attestation/src/vmgs.rs +++ b/openhcl/underhill_attestation/src/vmgs.rs @@ -4,13 +4,13 @@ //! Implementation of the helper functions for accessing VMGS entries. use guid::Guid; +use openhcl_attestation_protocol::vmgs::AGENT_DATA_MAX_SIZE; +use openhcl_attestation_protocol::vmgs::GUEST_SECRET_KEY_MAX_SIZE; use openhcl_attestation_protocol::vmgs::GuestSecretKey; use openhcl_attestation_protocol::vmgs::HardwareKeyProtector; use openhcl_attestation_protocol::vmgs::KeyProtector; use openhcl_attestation_protocol::vmgs::KeyProtectorById; use openhcl_attestation_protocol::vmgs::SecurityProfile; -use openhcl_attestation_protocol::vmgs::AGENT_DATA_MAX_SIZE; -use openhcl_attestation_protocol::vmgs::GUEST_SECRET_KEY_MAX_SIZE; use thiserror::Error; use vmgs::FileId; use vmgs::Vmgs; @@ -275,18 +275,18 @@ mod tests { use super::*; use disk_backend::Disk; use disklayer_ram::ram_disk; - use openhcl_attestation_protocol::vmgs::DekKp; - use openhcl_attestation_protocol::vmgs::GspKp; - use openhcl_attestation_protocol::vmgs::HardwareKeyProtectorHeader; - use openhcl_attestation_protocol::vmgs::KeyProtector; - use openhcl_attestation_protocol::vmgs::KeyProtectorById; use openhcl_attestation_protocol::vmgs::AES_CBC_IV_LENGTH; use openhcl_attestation_protocol::vmgs::AES_GCM_KEY_LENGTH; use openhcl_attestation_protocol::vmgs::DEK_BUFFER_SIZE; + use openhcl_attestation_protocol::vmgs::DekKp; use openhcl_attestation_protocol::vmgs::GSP_BUFFER_SIZE; + use openhcl_attestation_protocol::vmgs::GspKp; use openhcl_attestation_protocol::vmgs::HMAC_SHA_256_KEY_LENGTH; use openhcl_attestation_protocol::vmgs::HW_KEY_PROTECTOR_SIZE; + use openhcl_attestation_protocol::vmgs::HardwareKeyProtectorHeader; use openhcl_attestation_protocol::vmgs::KEY_PROTECTOR_SIZE; + use openhcl_attestation_protocol::vmgs::KeyProtector; + use openhcl_attestation_protocol::vmgs::KeyProtectorById; use openhcl_attestation_protocol::vmgs::NUMBER_KP; use pal_async::async_test; diff --git a/openhcl/underhill_core/src/diag.rs b/openhcl/underhill_core/src/diag.rs index 07ea53254f..344b024395 100644 --- a/openhcl/underhill_core/src/diag.rs +++ b/openhcl/underhill_core/src/diag.rs @@ -6,8 +6,8 @@ use anyhow::Context; use diag_server::DiagServer; use futures::FutureExt; -use mesh::error::RemoteError; use mesh::MeshPayload; +use mesh::error::RemoteError; use mesh_worker::Worker; use mesh_worker::WorkerId; use mesh_worker::WorkerRpc; diff --git a/openhcl/underhill_core/src/dispatch/mod.rs b/openhcl/underhill_core/src/dispatch/mod.rs index 5d4c3912a4..bf3c460597 100644 --- a/openhcl/underhill_core/src/dispatch/mod.rs +++ b/openhcl/underhill_core/src/dispatch/mod.rs @@ -7,8 +7,9 @@ mod pci_shutdown; pub mod vtl2_settings_worker; use self::vtl2_settings_worker::DeviceInterfaces; -use crate::emuplat::netvsp::RuntimeSavedState; +use crate::ControlRequest; use crate::emuplat::EmuplatServicing; +use crate::emuplat::netvsp::RuntimeSavedState; use crate::nvme_manager::NvmeManager; use crate::options::TestScenarioConfig; use crate::reference_time::ReferenceTime; @@ -18,7 +19,6 @@ use crate::servicing::ServicingState; use crate::vmbus_relay_unit::VmbusRelayHandle; use crate::worker::FirmwareType; use crate::worker::NetworkSettingsError; -use crate::ControlRequest; use anyhow::Context; use async_trait::async_trait; use futures::FutureExt; @@ -33,12 +33,12 @@ use hyperv_ic_resources::shutdown::ShutdownRpc; use hyperv_ic_resources::shutdown::ShutdownType; use igvm_defs::MemoryMapEntryType; use inspect::Inspect; +use mesh::CancelContext; +use mesh::MeshPayload; use mesh::error::RemoteError; use mesh::rpc::FailableRpc; use mesh::rpc::Rpc; use mesh::rpc::RpcSend; -use mesh::CancelContext; -use mesh::MeshPayload; use mesh_worker::WorkerRpc; use net_packet_capture::PacketCaptureParams; use openhcl_dma_manager::DmaClientSpawner; @@ -52,8 +52,8 @@ use state_unit::SpawnedUnit; use state_unit::StateUnits; use std::sync::Arc; use std::time::Duration; -use tracing::instrument; use tracing::Instrument; +use tracing::instrument; use uevent::UeventListener; use underhill_threadpool::AffinitizedThreadpool; use virt::IsolationType; @@ -68,9 +68,9 @@ use vmm_core::partition_unit::PartitionUnit; use vmm_core::vmbus_unit::ChannelUnit; use vmm_core::vmbus_unit::VmbusServerHandle; use vmotherboard::ChipsetDevices; -use vtl2_settings_worker::handle_vtl2_config_rpc; use vtl2_settings_worker::Vtl2ConfigNicRpc; use vtl2_settings_worker::Vtl2SettingsWorker; +use vtl2_settings_worker::handle_vtl2_config_rpc; #[derive(MeshPayload)] pub enum UhVmRpc { diff --git a/openhcl/underhill_core/src/dispatch/vtl2_settings_worker.rs b/openhcl/underhill_core/src/dispatch/vtl2_settings_worker.rs index 77c170316b..bea30e6a10 100644 --- a/openhcl/underhill_core/src/dispatch/vtl2_settings_worker.rs +++ b/openhcl/underhill_core/src/dispatch/vtl2_settings_worker.rs @@ -7,8 +7,8 @@ use super::LoadedVm; use crate::nvme_manager::NvmeDiskConfig; use crate::worker::NicConfig; use anyhow::Context; -use disk_backend::resolve::ResolveDiskParameters; use disk_backend::Disk; +use disk_backend::resolve::ResolveDiskParameters; use disk_backend_resources::AutoFormattedDiskHandle; use disk_blockdevice::OpenBlockDeviceConfig; use futures::StreamExt; @@ -18,10 +18,10 @@ use ide_resources::GuestMedia; use ide_resources::IdeControllerConfig; use ide_resources::IdeDeviceConfig; use ide_resources::IdePath; +use mesh::CancelContext; use mesh::rpc::Rpc; use mesh::rpc::RpcError; use mesh::rpc::RpcSend; -use mesh::CancelContext; use nvme_resources::NamespaceDefinition; use nvme_resources::NvmeControllerHandle; use scsidisk_resources::SimpleScsiDiskHandle; @@ -38,8 +38,8 @@ use storvsp_resources::ScsiControllerHandle; use storvsp_resources::ScsiControllerRequest; use storvsp_resources::ScsiDeviceAndPath; use thiserror::Error; -use tracing::instrument; use tracing::Instrument; +use tracing::instrument; use uevent::UeventListener; use underhill_config::DiskParameters; use underhill_config::NicDevice; @@ -51,13 +51,13 @@ use underhill_config::Vtl2SettingsDynamic; use underhill_config::Vtl2SettingsErrorCode; use underhill_config::Vtl2SettingsErrorInfo; use underhill_threadpool::AffinitizedThreadpool; -use vm_resource::kind::DiskHandleKind; -use vm_resource::kind::PciDeviceHandleKind; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::IntoResource; use vm_resource::ResolveError; use vm_resource::Resource; use vm_resource::ResourceResolver; +use vm_resource::kind::DiskHandleKind; +use vm_resource::kind::PciDeviceHandleKind; +use vm_resource::kind::VmbusDeviceHandleKind; #[derive(Error, Debug)] enum Error<'a> { @@ -122,7 +122,9 @@ enum Error<'a> { }, #[error("failed to parse Device ID: LUN = {lun:?}, device_id = {device_id:?}")] StorageBadDeviceId { lun: u8, device_id: &'a str }, - #[error("failed to parse Product Revision Level: LUN = {lun:?}, product_revision_level = {product_revision_level:?}")] + #[error( + "failed to parse Product Revision Level: LUN = {lun:?}, product_revision_level = {product_revision_level:?}" + )] StorageBadProductRevisionLevel { lun: u8, product_revision_level: &'a str, @@ -429,11 +431,12 @@ impl Vtl2SettingsWorker { })?; if let Some(dvd) = dvd { - assert!(self - .interfaces - .scsi_dvds - .insert(StorageDevicePath::Scsi(scsi_path), dvd) - .is_none()); + assert!( + self.interfaces + .scsi_dvds + .insert(StorageDevicePath::Scsi(scsi_path), dvd) + .is_none() + ); } } Vtl2ConfigCommit::RmDisk(controller_id, scsi_path) => { diff --git a/openhcl/underhill_core/src/emuplat/firmware.rs b/openhcl/underhill_core/src/emuplat/firmware.rs index 4145d16b22..0e9140efcd 100644 --- a/openhcl/underhill_core/src/emuplat/firmware.rs +++ b/openhcl/underhill_core/src/emuplat/firmware.rs @@ -7,8 +7,8 @@ use firmware_pcat::PcatEvent; use firmware_pcat::PcatLogger; use firmware_uefi::platform::logger::UefiEvent; use firmware_uefi::platform::logger::UefiLogger; -use guest_emulation_transport::api::EventLogId; use guest_emulation_transport::GuestEmulationTransportClient; +use guest_emulation_transport::api::EventLogId; use std::sync::Weak; use virt_mshv_vtl::UhPartition; diff --git a/openhcl/underhill_core/src/emuplat/framebuffer.rs b/openhcl/underhill_core/src/emuplat/framebuffer.rs index 98826111b9..0a1f7bccbe 100644 --- a/openhcl/underhill_core/src/emuplat/framebuffer.rs +++ b/openhcl/underhill_core/src/emuplat/framebuffer.rs @@ -6,8 +6,8 @@ use video_core::FramebufferControl; use video_core::FramebufferFormat; use video_core::ResolvedFramebuffer; use video_core::SharedFramebufferHandle; -use vm_resource::kind::FramebufferHandleKind; use vm_resource::ResolveResource; +use vm_resource::kind::FramebufferHandleKind; #[derive(Clone)] pub struct FramebufferRemoteControl { diff --git a/openhcl/underhill_core/src/emuplat/netvsp.rs b/openhcl/underhill_core/src/emuplat/netvsp.rs index 905392c09d..3d015e5b8f 100644 --- a/openhcl/underhill_core/src/emuplat/netvsp.rs +++ b/openhcl/underhill_core/src/emuplat/netvsp.rs @@ -5,9 +5,9 @@ use crate::dispatch::vtl2_settings_worker::wait_for_pci_path; use crate::vpci::HclVpciBusControl; use anyhow::Context; use async_trait::async_trait; +use futures::StreamExt; use futures::lock::Mutex; use futures::stream::iter; -use futures::StreamExt; use futures_concurrency::stream::Merge; use guest_emulation_transport::GuestEmulationTransportClient; use guid::Guid; @@ -27,20 +27,20 @@ use net_packet_capture::PacketCaptureEndpointControl; use net_packet_capture::PacketCaptureParams; use pal_async::task::Spawn; use pal_async::task::Task; -pub use save_restore::state::SavedState; pub use save_restore::RuntimeSavedState; +pub use save_restore::state::SavedState; use socket2::Socket; use std::future::pending; use std::path::Path; use std::sync::Arc; -use std::task::ready; use std::task::Poll; +use std::task::ready; use tracing::Instrument; use uevent::UeventListener; -use user_driver::vfio::vfio_set_device_reset_method; +use user_driver::DmaClient; use user_driver::vfio::PciDeviceResetMethod; use user_driver::vfio::VfioDevice; -use user_driver::DmaClient; +use user_driver::vfio::vfio_set_device_reset_method; use vmcore::vm_task::VmTaskDriverSource; use vpci::bus_control::VpciBusControl; use vpci::bus_control::VpciBusEvent; @@ -986,7 +986,7 @@ impl HclNetworkVFManager { ) -> anyhow::Result> where F: Fn(bool) -> R + Sync + Send + 'static, - R: std::future::Future + Send, + R: Future + Send, { let (tx_update, rx_update) = mesh::channel(); let guest_state = self @@ -1095,7 +1095,7 @@ impl HclNetworkVFManagerInstance { impl netvsp::VirtualFunction for HclNetworkVFManagerInstance where F: Fn(bool) -> R + Sync + Send + 'static, - R: std::future::Future + Send, + R: Future + Send, { async fn id(&self) -> Option { self.guest_state.vtl0_vfid().await diff --git a/openhcl/underhill_core/src/emuplat/tpm.rs b/openhcl/underhill_core/src/emuplat/tpm.rs index be06128ba9..80563bbeb0 100644 --- a/openhcl/underhill_core/src/emuplat/tpm.rs +++ b/openhcl/underhill_core/src/emuplat/tpm.rs @@ -2,8 +2,8 @@ // Licensed under the MIT License. use guest_emulation_transport::GuestEmulationTransportClient; -use openhcl_attestation_protocol::igvm_attest::get::runtime_claims::AttestationVmConfig; use openhcl_attestation_protocol::igvm_attest::get::AK_CERT_RESPONSE_BUFFER_SIZE; +use openhcl_attestation_protocol::igvm_attest::get::runtime_claims::AttestationVmConfig; use std::sync::Arc; use thiserror::Error; use tpm::ak_cert::RequestAkCert; @@ -112,13 +112,13 @@ pub mod resources { use tpm::ak_cert::ResolvedRequestAkCert; use tpm_resources::RequestAkCertKind; use underhill_attestation::AttestationType; - use vm_resource::declare_static_async_resolver; use vm_resource::AsyncResolveResource; use vm_resource::IntoResource; use vm_resource::PlatformResource; use vm_resource::ResolveError; use vm_resource::ResourceId; use vm_resource::ResourceResolver; + use vm_resource::declare_static_async_resolver; #[derive(MeshPayload)] pub struct GetTpmRequestAkCertHelperHandle { diff --git a/openhcl/underhill_core/src/get_tracing.rs b/openhcl/underhill_core/src/get_tracing.rs index 591ed4f796..ef6bd757c4 100644 --- a/openhcl/underhill_core/src/get_tracing.rs +++ b/openhcl/underhill_core/src/get_tracing.rs @@ -29,10 +29,10 @@ use futures::FutureExt; use futures::StreamExt; use futures_concurrency::stream::Merge; use get_helpers::build_tracelogging_notification_buffer; +use get_protocol::GET_LOG_INTERFACE_GUID; use get_protocol::LogFlags; use get_protocol::LogLevel; use get_protocol::LogType; -use get_protocol::GET_LOG_INTERFACE_GUID; use mesh::rpc::Rpc; use mesh_tracing::Level; use mesh_tracing::RemoteTracer; @@ -42,11 +42,11 @@ use mesh_tracing::Type; use pal_async::driver::SpawnDriver; use pal_async::task::Spawn; use tracing_helpers::formatter::FieldFormatter; +use tracing_subscriber::Layer; use tracing_subscriber::fmt::format::FmtSpan; use tracing_subscriber::fmt::format::Format; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; -use tracing_subscriber::Layer; use vmbus_async::async_dgram::AsyncSendExt; fn tracing_log_level(level: Level) -> LogLevel { diff --git a/openhcl/underhill_core/src/get_tracing/json_layer.rs b/openhcl/underhill_core/src/get_tracing/json_layer.rs index 0e4ae98244..a3940766dd 100644 --- a/openhcl/underhill_core/src/get_tracing/json_layer.rs +++ b/openhcl/underhill_core/src/get_tracing/json_layer.rs @@ -8,23 +8,23 @@ use super::json_common::Message; use super::json_common::SpanMessage; use guid::Guid; use mesh_tracing::TraceWriter; -use serde::ser::SerializeMap; -use serde::ser::SerializeSeq; use serde::Serialize; use serde::Serializer; +use serde::ser::SerializeMap; +use serde::ser::SerializeSeq; use std::fmt::Debug; use std::fmt::Display; use std::num::NonZeroU64; use std::str::FromStr; use std::sync::atomic::AtomicU64; use std::time::Duration; +use tracing::Id; +use tracing::Subscriber; use tracing::field::Field; use tracing::field::Visit; use tracing::span::Attributes; -use tracing::Id; -use tracing::Subscriber; -use tracing_subscriber::registry::LookupSpan; use tracing_subscriber::Layer; +use tracing_subscriber::registry::LookupSpan; use zerocopy::FromZeros; use zerocopy::IntoBytes; diff --git a/openhcl/underhill_core/src/get_tracing/kmsg_stream.rs b/openhcl/underhill_core/src/get_tracing/kmsg_stream.rs index 4b6a981734..49c48fcf33 100644 --- a/openhcl/underhill_core/src/get_tracing/kmsg_stream.rs +++ b/openhcl/underhill_core/src/get_tracing/kmsg_stream.rs @@ -19,9 +19,9 @@ use std::io::ErrorKind; use std::io::Write; use std::num::NonZeroU64; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; use tracing::Level; /// A stream of trace logging notifications from `/dev/kmsg`. diff --git a/openhcl/underhill_core/src/inspect_internal.rs b/openhcl/underhill_core/src/inspect_internal.rs index 1e0b5733e5..971fc6d9f2 100644 --- a/openhcl/underhill_core/src/inspect_internal.rs +++ b/openhcl/underhill_core/src/inspect_internal.rs @@ -38,8 +38,8 @@ use inspect::Request; use inspect::Response; use inspect::SensitivityLevel; use mesh::Sender; -use pal_async::task::Spawn; use pal_async::DefaultDriver; +use pal_async::task::Spawn; pub(crate) fn inspect_internal_diagnostics( req: Request<'_>, diff --git a/openhcl/underhill_core/src/lib.rs b/openhcl/underhill_core/src/lib.rs index a11329ea4e..b268fa5f11 100644 --- a/openhcl/underhill_core/src/lib.rs +++ b/openhcl/underhill_core/src/lib.rs @@ -39,35 +39,35 @@ use crate::worker::UnderhillWorkerParameters; use anyhow::Context; use bootloader_fdt_parser::BootTimes; use cvm_tracing::CVM_ALLOWED; -use framebuffer::FramebufferAccess; use framebuffer::FRAMEBUFFER_SIZE; +use framebuffer::FramebufferAccess; use futures::StreamExt; use futures_concurrency::stream::Merge; use get_tracing::init_tracing; use get_tracing::init_tracing_backend; use inspect::Inspect; use inspect::SensitivityLevel; -use mesh::error::RemoteError; -use mesh::rpc::Rpc; -use mesh::rpc::RpcSend; use mesh::CancelContext; use mesh::CancelReason; use mesh::MeshPayload; -use mesh_process::try_run_mesh_host; +use mesh::error::RemoteError; +use mesh::rpc::Rpc; +use mesh::rpc::RpcSend; use mesh_process::Mesh; use mesh_process::ProcessConfig; +use mesh_process::try_run_mesh_host; use mesh_tracing::RemoteTracer; use mesh_tracing::TracingBackend; -use mesh_worker::launch_local_worker; -use mesh_worker::register_workers; use mesh_worker::RegisteredWorkers; use mesh_worker::WorkerEvent; use mesh_worker::WorkerHandle; use mesh_worker::WorkerHost; use mesh_worker::WorkerHostRunner; -use pal_async::task::Spawn; +use mesh_worker::launch_local_worker; +use mesh_worker::register_workers; use pal_async::DefaultDriver; use pal_async::DefaultPool; +use pal_async::task::Spawn; #[cfg(feature = "profiler")] use profiler_worker::ProfilerWorker; #[cfg(feature = "profiler")] diff --git a/openhcl/underhill_core/src/loader/mod.rs b/openhcl/underhill_core/src/loader/mod.rs index 01c7f9a6c6..aa22c04d04 100644 --- a/openhcl/underhill_core/src/loader/mod.rs +++ b/openhcl/underhill_core/src/loader/mod.rs @@ -12,8 +12,8 @@ use guestmem::GuestMemory; use hvdef::HV_PAGE_SIZE; use igvm_defs::MemoryMapEntryType; use loader::importer::Register; -use loader::uefi::config; use loader::uefi::IMAGE_SIZE; +use loader::uefi::config; use loader_defs::paravisor::PageRegionDescriptor; use memory_range::MemoryRange; #[cfg(guest_arch = "x86_64")] diff --git a/openhcl/underhill_core/src/loader/vtl0_config.rs b/openhcl/underhill_core/src/loader/vtl0_config.rs index 2de5f434dd..fff60acb39 100644 --- a/openhcl/underhill_core/src/loader/vtl0_config.rs +++ b/openhcl/underhill_core/src/loader/vtl0_config.rs @@ -5,12 +5,12 @@ //! configuration information that is deposited into the guest address space that //! is measured as part of the partition's launch. -use super::memory_range_from_page_region; use super::LoadKind; -use super::VpContext; use super::PV_CONFIG_BASE_PAGE; -use guestmem::ranges::PagedRange; +use super::VpContext; +use super::memory_range_from_page_region; use guestmem::GuestMemory; +use guestmem::ranges::PagedRange; use hvdef::HV_PAGE_SIZE; use igvm::registers::UnsupportedRegister; use loader_defs::paravisor::ParavisorMeasuredVtl0Config; diff --git a/openhcl/underhill_core/src/loader/vtl2_config/mod.rs b/openhcl/underhill_core/src/loader/vtl2_config/mod.rs index 9fd90cfeb8..f491f2c144 100644 --- a/openhcl/underhill_core/src/loader/vtl2_config/mod.rs +++ b/openhcl/underhill_core/src/loader/vtl2_config/mod.rs @@ -13,7 +13,6 @@ use bootloader_fdt_parser::IsolationType; use bootloader_fdt_parser::ParsedBootDtInfo; use hvdef::HV_PAGE_SIZE; use inspect::Inspect; -use loader_defs::paravisor::ParavisorMeasuredVtl2Config; use loader_defs::paravisor::PARAVISOR_CONFIG_PPTT_PAGE_INDEX; use loader_defs::paravisor::PARAVISOR_CONFIG_SLIT_PAGE_INDEX; use loader_defs::paravisor::PARAVISOR_MEASURED_VTL2_CONFIG_PAGE_INDEX; @@ -21,6 +20,7 @@ use loader_defs::paravisor::PARAVISOR_RESERVED_VTL2_SNP_CPUID_PAGE_INDEX; use loader_defs::paravisor::PARAVISOR_RESERVED_VTL2_SNP_CPUID_SIZE_PAGES; use loader_defs::paravisor::PARAVISOR_RESERVED_VTL2_SNP_SECRETS_PAGE_INDEX; use loader_defs::paravisor::PARAVISOR_RESERVED_VTL2_SNP_SECRETS_SIZE_PAGES; +use loader_defs::paravisor::ParavisorMeasuredVtl2Config; use memory_range::MemoryRange; use sparse_mmap::SparseMapping; use vm_topology::memory::MemoryRangeWithNode; diff --git a/openhcl/underhill_core/src/nvme_manager.rs b/openhcl/underhill_core/src/nvme_manager.rs index 9c56fab4ce..2580996140 100644 --- a/openhcl/underhill_core/src/nvme_manager.rs +++ b/openhcl/underhill_core/src/nvme_manager.rs @@ -11,28 +11,28 @@ use anyhow::Context; use async_trait::async_trait; use disk_backend::resolve::ResolveDiskParameters; use disk_backend::resolve::ResolvedDisk; -use futures::future::join_all; use futures::StreamExt; use futures::TryFutureExt; +use futures::future::join_all; use inspect::Inspect; +use mesh::MeshPayload; use mesh::rpc::Rpc; use mesh::rpc::RpcSend; -use mesh::MeshPayload; use openhcl_dma_manager::AllocationVisibility; use openhcl_dma_manager::DmaClientParameters; use openhcl_dma_manager::DmaClientSpawner; use openhcl_dma_manager::LowerVtlPermissionPolicy; use pal_async::task::Spawn; use pal_async::task::Task; -use std::collections::hash_map; use std::collections::HashMap; +use std::collections::hash_map; use thiserror::Error; use tracing::Instrument; use user_driver::vfio::VfioDevice; -use vm_resource::kind::DiskHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResourceId; use vm_resource::ResourceResolver; +use vm_resource::kind::DiskHandleKind; use vmcore::vm_task::VmTaskDriverSource; #[derive(Debug, Error)] diff --git a/openhcl/underhill_core/src/options.rs b/openhcl/underhill_core/src/options.rs index f5aac7c09b..fcdde25f9d 100644 --- a/openhcl/underhill_core/src/options.rs +++ b/openhcl/underhill_core/src/options.rs @@ -5,8 +5,8 @@ #![warn(missing_docs)] -use anyhow::bail; use anyhow::Context; +use anyhow::bail; use mesh::MeshPayload; use std::collections::BTreeMap; use std::ffi::OsStr; diff --git a/openhcl/underhill_core/src/vmbus_relay_unit.rs b/openhcl/underhill_core/src/vmbus_relay_unit.rs index dbf49aea4f..ffa85f0160 100644 --- a/openhcl/underhill_core/src/vmbus_relay_unit.rs +++ b/openhcl/underhill_core/src/vmbus_relay_unit.rs @@ -3,11 +3,11 @@ use inspect::Inspect; use pal_async::task::Spawn; -use state_unit::run_async_unit; use state_unit::NameInUse; use state_unit::SpawnedUnit; use state_unit::StateUnit; use state_unit::UnitBuilder; +use state_unit::run_async_unit; use vmbus_relay::HostVmbusTransport; use vmcore::save_restore::RestoreError; use vmcore::save_restore::SaveError; diff --git a/openhcl/underhill_core/src/worker.rs b/openhcl/underhill_core/src/worker.rs index 86470bccc0..8d8186d47c 100644 --- a/openhcl/underhill_core/src/worker.rs +++ b/openhcl/underhill_core/src/worker.rs @@ -16,11 +16,13 @@ cfg_if::cfg_if! { } } -use crate::dispatch::vtl2_settings_worker::disk_from_disk_type; -use crate::dispatch::vtl2_settings_worker::wait_for_mana; -use crate::dispatch::vtl2_settings_worker::InitialControllers; +use crate::ControlRequest; use crate::dispatch::LoadedVm; use crate::dispatch::LoadedVmNetworkSettings; +use crate::dispatch::vtl2_settings_worker::InitialControllers; +use crate::dispatch::vtl2_settings_worker::disk_from_disk_type; +use crate::dispatch::vtl2_settings_worker::wait_for_mana; +use crate::emuplat::EmuplatServicing; use crate::emuplat::firmware::UnderhillLogger; use crate::emuplat::firmware::UnderhillVsmConfig; use crate::emuplat::framebuffer::FramebufferRemoteControl; @@ -35,22 +37,20 @@ use crate::emuplat::netvsp::RuntimeSavedState; use crate::emuplat::non_volatile_store::VmbsBrokerNonVolatileStore; use crate::emuplat::tpm::resources::GetTpmRequestAkCertHelperHandle; use crate::emuplat::vga_proxy::UhRegisterHostIoFastPath; -use crate::emuplat::EmuplatServicing; +use crate::loader::LoadKind; use crate::loader::vtl0_config::MeasuredVtl0Info; use crate::loader::vtl2_config::RuntimeParameters; -use crate::loader::LoadKind; use crate::nvme_manager::NvmeDiskConfig; use crate::nvme_manager::NvmeDiskResolver; use crate::nvme_manager::NvmeManager; use crate::options::TestScenarioConfig; use crate::reference_time::ReferenceTime; use crate::servicing; -use crate::servicing::transposed::OptionServicingInitState; use crate::servicing::ServicingState; +use crate::servicing::transposed::OptionServicingInitState; use crate::threadpool_vm_task_backend::ThreadpoolBackend; use crate::vmbus_relay_unit::VmbusRelayHandle; use crate::wrapped_partition::WrappedPartition; -use crate::ControlRequest; use anyhow::Context; use async_trait::async_trait; use chipset_device::ChipsetDevice; @@ -66,15 +66,15 @@ use futures_concurrency::future::Race; use get_protocol::EventLogId; use get_protocol::RegisterState; use get_protocol::TripleFaultType; +use guest_emulation_transport::GuestEmulationTransportClient; use guest_emulation_transport::api::platform_settings::DevicePlatformSettings; use guest_emulation_transport::api::platform_settings::General; -use guest_emulation_transport::GuestEmulationTransportClient; use guestmem::GuestMemory; use guid::Guid; use hcl_compat_uefi_nvram_storage::HclCompatNvramQuirks; -use hvdef::hypercall::HvGuestOsId; use hvdef::HvRegisterValue; use hvdef::Vtl; +use hvdef::hypercall::HvGuestOsId; use hyperv_ic_guest::ShutdownGuestIc; use ide_resources::GuestMedia; use ide_resources::IdePath; @@ -84,9 +84,9 @@ use input_core::MultiplexedInputHandle; use inspect::Inspect; use loader_defs::shim::MemoryVtlType; use memory_range::MemoryRange; -use mesh::rpc::RpcSend; use mesh::CancelContext; use mesh::MeshPayload; +use mesh::rpc::RpcSend; use mesh_worker::Worker; use mesh_worker::WorkerId; use mesh_worker::WorkerRpc; @@ -97,10 +97,10 @@ use openhcl_dma_manager::DmaClientParameters; use openhcl_dma_manager::DmaClientSpawner; use openhcl_dma_manager::LowerVtlPermissionPolicy; use openhcl_dma_manager::OpenhclDmaManager; -use pal_async::local::LocalDriver; -use pal_async::task::Spawn; use pal_async::DefaultDriver; use pal_async::DefaultPool; +use pal_async::local::LocalDriver; +use pal_async::task::Spawn; use parking_lot::Mutex; use scsi_core::ResolveScsiDeviceHandleParams; use scsidisk::atapi_scsi::AtapiScsiDisk; @@ -118,37 +118,37 @@ use thiserror::Error; use tpm_resources::TpmAkCertTypeResource; use tpm_resources::TpmDeviceHandle; use tpm_resources::TpmRegisterLayout; -use tracing::instrument; use tracing::Instrument; +use tracing::instrument; use uevent::UeventListener; use underhill_attestation::AttestationType; use underhill_threadpool::AffinitizedThreadpool; use underhill_threadpool::ThreadpoolBuilder; use user_driver::DmaClient; -use virt::state::HvRegisterState; use virt::Partition; use virt::VpIndex; use virt::X86Partition; +use virt::state::HvRegisterState; use virt_mshv_vtl::UhPartition; use virt_mshv_vtl::UhPartitionNewParams; use virt_mshv_vtl::UhProtoPartition; use vm_loader::initial_regs::initial_regs; -use vm_resource::kind::DiskHandleKind; -use vm_resource::kind::KeyboardInputHandleKind; -use vm_resource::kind::MouseInputHandleKind; use vm_resource::IntoResource; use vm_resource::Resource; use vm_resource::ResourceResolver; +use vm_resource::kind::DiskHandleKind; +use vm_resource::kind::KeyboardInputHandleKind; +use vm_resource::kind::MouseInputHandleKind; use vm_topology::memory::MemoryLayout; use vm_topology::memory::MemoryRangeWithNode; -use vm_topology::processor::aarch64::GicInfo; use vm_topology::processor::ProcessorTopology; use vm_topology::processor::TopologyBuilder; use vm_topology::processor::VpInfo; +use vm_topology::processor::aarch64::GicInfo; use vmbus_relay_intercept_device::SimpleVmbusClientDeviceWrapper; use vmbus_server::VmbusServer; -use vmcore::non_volatile_store::resources::EphemeralNonVolatileStoreHandle; use vmcore::non_volatile_store::EphemeralNonVolatileStore; +use vmcore::non_volatile_store::resources::EphemeralNonVolatileStoreHandle; use vmcore::vm_task::VmTaskDriverSource; use vmcore::vmtime::VmTime; use vmcore::vmtime::VmTimeKeeper; @@ -161,17 +161,17 @@ use vmm_core::partition_unit::Halt; use vmm_core::partition_unit::PartitionUnit; use vmm_core::partition_unit::PartitionUnitParams; use vmm_core::synic::SynicPorts; -use vmm_core::vmbus_unit::offer_channel_unit; -use vmm_core::vmbus_unit::offer_vmbus_device_handle_unit; use vmm_core::vmbus_unit::ChannelUnit; use vmm_core::vmbus_unit::VmbusServerHandle; +use vmm_core::vmbus_unit::offer_channel_unit; +use vmm_core::vmbus_unit::offer_vmbus_device_handle_unit; use vmm_core::vmtime_unit::run_vmtime; use vmm_core_defs::HaltReason; -use vmotherboard::options::BaseChipsetDevices; -use vmotherboard::options::BaseChipsetFoundation; use vmotherboard::BaseChipsetBuilder; use vmotherboard::BaseChipsetBuilderOutput; use vmotherboard::ChipsetDeviceHandle; +use vmotherboard::options::BaseChipsetDevices; +use vmotherboard::options::BaseChipsetFoundation; use zerocopy::FromZeros; pub(crate) const PM_BASE: u16 = 0x400; @@ -188,8 +188,8 @@ struct GuestEmulationTransportInfra { get_client: GuestEmulationTransportClient, } -async fn construct_get( -) -> Result<(GuestEmulationTransportInfra, pal_async::task::Task<()>), anyhow::Error> { +async fn construct_get() +-> Result<(GuestEmulationTransportInfra, pal_async::task::Task<()>), anyhow::Error> { // Create a thread to run GET and VMGS clients on. // // This must be a separate thread from the thread pool because sometimes diff --git a/openhcl/underhill_crash/src/lib.rs b/openhcl/underhill_crash/src/lib.rs index 245d336cf1..a3cfe003e9 100644 --- a/openhcl/underhill_crash/src/lib.rs +++ b/openhcl/underhill_crash/src/lib.rs @@ -23,12 +23,12 @@ use crate::elf::Elf64_Phdr; use crate::elf::PT_NOTE; use crate::proto::check_header; use crate::proto::make_header; -use fs_err::os::unix::fs::OpenOptionsExt; use fs_err::File; -use futures::io::AllowStdIo; +use fs_err::os::unix::fs::OpenOptionsExt; use futures::AsyncRead; use futures::AsyncReadExt; use futures::FutureExt; +use futures::io::AllowStdIo; use get_protocol::crash; use get_protocol::crash::Header; use libc::O_NONBLOCK; diff --git a/openhcl/underhill_init/src/lib.rs b/openhcl/underhill_init/src/lib.rs index b01b066ada..f486c792e9 100644 --- a/openhcl/underhill_init/src/lib.rs +++ b/openhcl/underhill_init/src/lib.rs @@ -16,10 +16,10 @@ mod syslog; pub use options::Options; use anyhow::Context; -use libc::c_void; use libc::STDERR_FILENO; use libc::STDIN_FILENO; use libc::STDOUT_FILENO; +use libc::c_void; use std::collections::HashMap; use std::ffi::CStr; use std::ffi::OsStr; diff --git a/openhcl/underhill_mem/src/init.rs b/openhcl/underhill_mem/src/init.rs index 67eee8c6fc..9eea72d32e 100644 --- a/openhcl/underhill_mem/src/init.rs +++ b/openhcl/underhill_mem/src/init.rs @@ -3,17 +3,17 @@ #![expect(missing_docs)] -use crate::mapping::GuestMemoryMapping; use crate::HardwareIsolatedMemoryProtector; use crate::MemoryAcceptor; +use crate::mapping::GuestMemoryMapping; use anyhow::Context; use futures::future::try_join_all; use guestmem::GuestMemory; use hcl::ioctl::MshvHvcall; use hcl::ioctl::MshvVtlLow; -use hvdef::hypercall::HvInputVtl; use hvdef::HypercallCode; use hvdef::Vtl; +use hvdef::hypercall::HvInputVtl; use inspect::Inspect; use memory_range::AlignedSubranges; use memory_range::MemoryRange; @@ -395,7 +395,9 @@ pub async fn init(params: &Init<'_>) -> anyhow::Result { } else { // On ARM, the alias map is not exposed: see // underhill_core::init::vtl0_alias_map_bit. - tracing::warn!("cannot safely support VTL 1 without using the alias map; Guest VSM not supported"); + tracing::warn!( + "cannot safely support VTL 1 without using the alias map; Guest VSM not supported" + ); None } } else { diff --git a/openhcl/underhill_mem/src/lib.rs b/openhcl/underhill_mem/src/lib.rs index 6cbc4369ca..381449e110 100644 --- a/openhcl/underhill_mem/src/lib.rs +++ b/openhcl/underhill_mem/src/lib.rs @@ -9,29 +9,29 @@ mod init; mod mapping; mod registrar; -pub use init::init; pub use init::Init; pub use init::MemoryMappings; +pub use init::init; -use guestmem::ranges::PagedRange; use guestmem::PAGE_SIZE; -use hcl::ioctl::snp::SnpPageError; +use guestmem::ranges::PagedRange; +use hcl::GuestVtl; use hcl::ioctl::AcceptPagesError; use hcl::ioctl::ApplyVtlProtectionsError; use hcl::ioctl::Mshv; use hcl::ioctl::MshvHvcall; use hcl::ioctl::MshvVtl; -use hcl::GuestVtl; +use hcl::ioctl::snp::SnpPageError; use hv1_structs::VtlArray; -use hvdef::hypercall::AcceptMemoryType; -use hvdef::hypercall::HostVisibilityType; -use hvdef::hypercall::HvInputVtl; +use hvdef::HV_MAP_GPA_PERMISSIONS_ALL; +use hvdef::HV_PAGE_SIZE; use hvdef::HvError; use hvdef::HvMapGpaFlags; use hvdef::HypercallCode; use hvdef::Vtl; -use hvdef::HV_MAP_GPA_PERMISSIONS_ALL; -use hvdef::HV_PAGE_SIZE; +use hvdef::hypercall::AcceptMemoryType; +use hvdef::hypercall::HostVisibilityType; +use hvdef::hypercall::HvInputVtl; use mapping::GuestMemoryMapping; use memory_range::MemoryRange; use parking_lot::Mutex; @@ -544,7 +544,10 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector { }; if let Err(err) = self.acceptor.modify_gpa_visibility(host_visibility, &gpns) { if shared { - panic!("the hypervisor refused to transition pages to shared, we cannot safely roll back: {:?}", err); + panic!( + "the hypervisor refused to transition pages to shared, we cannot safely roll back: {:?}", + err + ); } todo!("roll back bitmap changes and report partial success"); } @@ -755,11 +758,12 @@ impl ProtectIsolatedMemory for HardwareIsolatedMemoryProtector { ) { // Should already have written contents to the page via the guest // memory object, confirming that this is a guest page - assert!(self - .layout - .ram() - .iter() - .any(|r| r.range.contains_addr(gpn * HV_PAGE_SIZE))); + assert!( + self.layout + .ram() + .iter() + .any(|r| r.range.contains_addr(gpn * HV_PAGE_SIZE)) + ); let inner = self.inner.lock(); diff --git a/openhcl/underhill_mem/src/mapping.rs b/openhcl/underhill_mem/src/mapping.rs index 591970c2d0..67fb5c0068 100644 --- a/openhcl/underhill_mem/src/mapping.rs +++ b/openhcl/underhill_mem/src/mapping.rs @@ -4,9 +4,9 @@ // UNSAFETY: Implementing GuestMemoryAccess. #![expect(unsafe_code)] -use crate::registrar::MemoryRegistrar; use crate::MshvVtlWithPolicy; use crate::RegistrationError; +use crate::registrar::MemoryRegistrar; use guestmem::GuestMemoryAccess; use guestmem::GuestMemoryBackingError; use guestmem::PAGE_SIZE; diff --git a/openhcl/underhill_mem/src/registrar.rs b/openhcl/underhill_mem/src/registrar.rs index 2d88bc84cb..c49dc00813 100644 --- a/openhcl/underhill_mem/src/registrar.rs +++ b/openhcl/underhill_mem/src/registrar.rs @@ -20,8 +20,8 @@ //! been registered via a small bitmap. use inspect::Inspect; -use memory_range::overlapping_ranges; use memory_range::MemoryRange; +use memory_range::overlapping_ranges; use parking_lot::Mutex; use std::ops::Range; use std::sync::atomic::AtomicU64; diff --git a/openhcl/underhill_threadpool/src/lib.rs b/openhcl/underhill_threadpool/src/lib.rs index 9938117227..56ea691861 100644 --- a/openhcl/underhill_threadpool/src/lib.rs +++ b/openhcl/underhill_threadpool/src/lib.rs @@ -34,11 +34,11 @@ use std::future::poll_fn; use std::io; use std::marker::PhantomData; use std::os::fd::RawFd; +use std::sync::Arc; +use std::sync::OnceLock; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering::Relaxed; -use std::sync::Arc; -use std::sync::OnceLock; use std::task::Poll; use std::task::Waker; use thiserror::Error; diff --git a/openhcl/virt_mshv_vtl/src/cvm_cpuid/masking.rs b/openhcl/virt_mshv_vtl/src/cvm_cpuid/masking.rs index c149c9e879..946f3888ee 100644 --- a/openhcl/virt_mshv_vtl/src/cvm_cpuid/masking.rs +++ b/openhcl/virt_mshv_vtl/src/cvm_cpuid/masking.rs @@ -3,9 +3,9 @@ //! Definitions and implementation related to masking CPUID results. +use super::CPUID_LEAF_B_MAX_SUBLEAF_INDEX; use super::CpuidArchInitializer; use super::CpuidResults; -use super::CPUID_LEAF_B_MAX_SUBLEAF_INDEX; use super::MAX_EXTENDED_STATE_ENUMERATION_SUBLEAF; use core::arch::x86_64::CpuidResult; use x86defs::cpuid; diff --git a/openhcl/virt_mshv_vtl/src/cvm_cpuid/mod.rs b/openhcl/virt_mshv_vtl/src/cvm_cpuid/mod.rs index 9da1bbdbde..238adef349 100644 --- a/openhcl/virt_mshv_vtl/src/cvm_cpuid/mod.rs +++ b/openhcl/virt_mshv_vtl/src/cvm_cpuid/mod.rs @@ -292,8 +292,15 @@ impl CpuidResults { } if skipped { - tracing::warn!("cpuid result for leaf {} subleaf {} specified multiple times, ignoring duplicate with eax {}, ebx {}, ecx {}, edx {}", - leaf.0, subleaf, result.eax, result.ebx, result.ecx, result.edx); + tracing::warn!( + "cpuid result for leaf {} subleaf {} specified multiple times, ignoring duplicate with eax {}, ebx {}, ecx {}, edx {}", + leaf.0, + subleaf, + result.eax, + result.ebx, + result.ecx, + result.edx + ); } } std::collections::hash_map::Entry::Vacant(entry) => { diff --git a/openhcl/virt_mshv_vtl/src/cvm_cpuid/tdx.rs b/openhcl/virt_mshv_vtl/src/cvm_cpuid/tdx.rs index c95088bb1a..ce07454072 100644 --- a/openhcl/virt_mshv_vtl/src/cvm_cpuid/tdx.rs +++ b/openhcl/virt_mshv_vtl/src/cvm_cpuid/tdx.rs @@ -3,6 +3,7 @@ //! CPUID definitions and implementation specific to Underhill in TDX CVMs. +use super::COMMON_REQUIRED_LEAVES; use super::CpuidArchInitializer; use super::CpuidArchSupport; use super::CpuidResultMask; @@ -11,7 +12,6 @@ use super::CpuidResultsError; use super::CpuidSubtable; use super::ParsedCpuidEntry; use super::TopologyError; -use super::COMMON_REQUIRED_LEAVES; use core::arch::x86_64::CpuidResult; use x86defs::cpuid; use x86defs::cpuid::CpuidFunction; diff --git a/openhcl/virt_mshv_vtl/src/cvm_cpuid/tests/mod.rs b/openhcl/virt_mshv_vtl/src/cvm_cpuid/tests/mod.rs index e7e5d46087..4e9a7be741 100644 --- a/openhcl/virt_mshv_vtl/src/cvm_cpuid/tests/mod.rs +++ b/openhcl/virt_mshv_vtl/src/cvm_cpuid/tests/mod.rs @@ -457,12 +457,14 @@ fn hypervisor_present() { }) .unwrap(); - assert!(cpuid::VersionAndFeaturesEcx::from( - cpuid - .registered_result(CpuidFunction::VersionAndFeatures, 0) - .ecx, - ) - .hypervisor_present()); + assert!( + cpuid::VersionAndFeaturesEcx::from( + cpuid + .registered_result(CpuidFunction::VersionAndFeatures, 0) + .ecx, + ) + .hypervisor_present() + ); } #[test] @@ -678,19 +680,23 @@ fn tsc_aux() { }) .unwrap(); - assert!(!cpuid::ExtendedVersionAndFeaturesEdx::from( - cpuid - .registered_result(CpuidFunction::ExtendedVersionAndFeatures, 0) - .edx - ) - .rdtscp()); + assert!( + !cpuid::ExtendedVersionAndFeaturesEdx::from( + cpuid + .registered_result(CpuidFunction::ExtendedVersionAndFeatures, 0) + .edx + ) + .rdtscp() + ); - assert!(!cpuid::ExtendedFeatureSubleaf0Ecx::from( - cpuid - .registered_result(CpuidFunction::ExtendedFeatures, 0) - .ecx - ) - .rd_pid()); + assert!( + !cpuid::ExtendedFeatureSubleaf0Ecx::from( + cpuid + .registered_result(CpuidFunction::ExtendedFeatures, 0) + .ecx + ) + .rd_pid() + ); } // values obtained by running cpuid.exe -G 0 -P 0 (from bin\idw, copied into diff --git a/openhcl/virt_mshv_vtl/src/cvm_cpuid/tests/xfem.rs b/openhcl/virt_mshv_vtl/src/cvm_cpuid/tests/xfem.rs index c7f2cf1925..fdd3b4e82d 100644 --- a/openhcl/virt_mshv_vtl/src/cvm_cpuid/tests/xfem.rs +++ b/openhcl/virt_mshv_vtl/src/cvm_cpuid/tests/xfem.rs @@ -6,9 +6,9 @@ //! version. use super::super::*; use super::*; +use x86defs::snp::HV_PSP_CPUID_LEAF_COUNT_MAX; use x86defs::snp::HvPspCpuidLeaf; use x86defs::snp::HvPspCpuidPage; -use x86defs::snp::HV_PSP_CPUID_LEAF_COUNT_MAX; use zerocopy::FromZeros; /// Tests that xfem results put into page 0 are ignored diff --git a/openhcl/virt_mshv_vtl/src/lib.rs b/openhcl/virt_mshv_vtl/src/lib.rs index 5b7e95e031..b534269b2b 100644 --- a/openhcl/virt_mshv_vtl/src/lib.rs +++ b/openhcl/virt_mshv_vtl/src/lib.rs @@ -45,24 +45,16 @@ use bitfield_struct::bitfield; use bitvec::boxed::BitBox; use bitvec::vec::BitVec; use guestmem::GuestMemory; +use hcl::GuestVtl; use hcl::ioctl::Hcl; use hcl::ioctl::SetVsmPartitionConfigError; -use hcl::GuestVtl; use hv1_emulator::hv::GlobalHv; use hv1_emulator::message_queues::MessageQueues; use hv1_emulator::synic::GlobalSynic; use hv1_emulator::synic::SintProxied; use hv1_structs::VtlArray; -use hvdef::hypercall::HostVisibilityType; -use hvdef::hypercall::HvGuestOsId; -use hvdef::hypercall::HvInputVtl; -use hvdef::hypercall::HvInterceptParameters; -use hvdef::hypercall::HvInterceptType; -use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_EXECUTE; -use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_NONE; -use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_READ_WRITE; -use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_WRITE; use hvdef::GuestCrashCtl; +use hvdef::HV_PAGE_SIZE; use hvdef::HvAllArchRegisterName; use hvdef::HvError; use hvdef::HvMapGpaFlags; @@ -70,7 +62,15 @@ use hvdef::HvRegisterName; use hvdef::HvRegisterVsmPartitionConfig; use hvdef::HvRegisterVsmPartitionStatus; use hvdef::Vtl; -use hvdef::HV_PAGE_SIZE; +use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_EXECUTE; +use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_NONE; +use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_READ_WRITE; +use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_WRITE; +use hvdef::hypercall::HostVisibilityType; +use hvdef::hypercall::HvGuestOsId; +use hvdef::hypercall::HvInputVtl; +use hvdef::hypercall::HvInterceptParameters; +use hvdef::hypercall::HvInterceptType; use inspect::Inspect; use inspect::InspectMut; use memory_range::MemoryRange; @@ -86,23 +86,23 @@ use processor::SidecarExitReason; use sidecar_client::NewSidecarClientError; use std::ops::RangeInclusive; use std::os::fd::AsRawFd; +use std::sync::Arc; +use std::sync::Weak; use std::sync::atomic::AtomicBool; +use std::sync::atomic::AtomicU8; use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicU64; -use std::sync::atomic::AtomicU8; use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::sync::Weak; use std::task::Waker; use thiserror::Error; use user_driver::DmaClient; -use virt::irqcon::IoApicRouting; -use virt::irqcon::MsiRequest; -use virt::x86::apic_software_device::ApicSoftwareDevices; use virt::CpuidLeafSet; use virt::IsolationType; use virt::PartitionCapabilities; use virt::VpIndex; +use virt::irqcon::IoApicRouting; +use virt::irqcon::MsiRequest; +use virt::x86::apic_software_device::ApicSoftwareDevices; use virt_support_apic::LocalApicSet; use vm_topology::memory::MemoryLayout; use vm_topology::processor::ProcessorTopology; @@ -152,7 +152,9 @@ pub enum Error { BadCpuidTsc, #[error("failed to read tsc frequency")] ReadTscFrequency(#[source] std::io::Error), - #[error("tsc frequency mismatch between hypervisor ({hv}) and hardware {hw}, exceeds allowed error {allowed_error}")] + #[error( + "tsc frequency mismatch between hypervisor ({hv}) and hardware {hw}, exceeds allowed error {allowed_error}" + )] TscFrequencyMismatch { hv: u64, hw: u64, @@ -1636,7 +1638,9 @@ impl<'a> UhProtoPartition<'a> { let vsm_state = if guest_vsm_available { if is_hardware_isolated { - tracing::warn!("Advertising guest vsm as being supported to the guest. This feature is in development, so the guest might crash."); + tracing::warn!( + "Advertising guest vsm as being supported to the guest. This feature is in development, so the guest might crash." + ); } GuestVsmState::NotGuestEnabled } else { diff --git a/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/apic.rs b/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/apic.rs index e5b070ee8d..703073f7a1 100644 --- a/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/apic.rs +++ b/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/apic.rs @@ -4,12 +4,12 @@ #![cfg(guest_arch = "x86_64")] use super::UhRunVpError; -use crate::processor::HardwareIsolatedBacking; use crate::UhProcessor; +use crate::processor::HardwareIsolatedBacking; use hcl::GuestVtl; +use virt::Processor; use virt::vp::MpState; use virt::x86::SegmentRegister; -use virt::Processor; use virt_support_apic::ApicWork; pub(crate) trait ApicBacking<'b, B: HardwareIsolatedBacking> { diff --git a/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/mod.rs b/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/mod.rs index f026cbf548..3ad3fba7d9 100644 --- a/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/mod.rs +++ b/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/mod.rs @@ -9,9 +9,6 @@ pub mod tlb_lock; use super::UhEmulationState; use super::UhProcessor; use super::UhRunVpError; -use crate::processor::HardwareIsolatedBacking; -use crate::processor::UhHypercallHandler; -use crate::validate_vtl_gpa_flags; use crate::GuestVsmState; use crate::GuestVsmVtl1State; use crate::GuestVtl; @@ -19,13 +16,13 @@ use crate::InitialVpContextOperation; use crate::TlbFlushLockAccess; use crate::VpStartEnableVtl; use crate::WakeReason; +use crate::processor::HardwareIsolatedBacking; +use crate::processor::UhHypercallHandler; +use crate::validate_vtl_gpa_flags; use guestmem::GuestMemory; use hv1_emulator::RequestInterrupt; use hv1_hypercall::HvRepResult; use hv1_structs::ProcessorSet; -use hvdef::hypercall::HostVisibilityType; -use hvdef::hypercall::HvFlushFlags; -use hvdef::hypercall::TranslateGvaResultCode; use hvdef::HvCacheType; use hvdef::HvError; use hvdef::HvMapGpaFlags; @@ -36,11 +33,14 @@ use hvdef::HvSynicSint; use hvdef::HvVtlEntryReason; use hvdef::HvX64RegisterName; use hvdef::Vtl; +use hvdef::hypercall::HostVisibilityType; +use hvdef::hypercall::HvFlushFlags; +use hvdef::hypercall::TranslateGvaResultCode; use std::iter::zip; +use virt::Processor; use virt::io::CpuIo; use virt::vp::AccessVpState; use virt::x86::MsrError; -use virt::Processor; use virt_support_x86emu::emulate::TranslateGvaSupport; use virt_support_x86emu::translate::TranslateCachingInfo; use virt_support_x86emu::translate::TranslationRegisters; diff --git a/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/tlb_lock.rs b/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/tlb_lock.rs index 4226e021df..5194ea14ca 100644 --- a/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/tlb_lock.rs +++ b/openhcl/virt_mshv_vtl/src/processor/hardware_cvm/tlb_lock.rs @@ -3,9 +3,9 @@ //! TLB lock infrastructure support for hardware-isolated partitions. -use crate::processor::HardwareIsolatedBacking; use crate::UhCvmPartitionState; use crate::UhProcessor; +use crate::processor::HardwareIsolatedBacking; use hcl::GuestVtl; use hvdef::Vtl; use std::sync::atomic::Ordering; diff --git a/openhcl/virt_mshv_vtl/src/processor/mod.rs b/openhcl/virt_mshv_vtl/src/processor/mod.rs index ba89fd5622..c445dd7db5 100644 --- a/openhcl/virt_mshv_vtl/src/processor/mod.rs +++ b/openhcl/virt_mshv_vtl/src/processor/mod.rs @@ -44,12 +44,12 @@ use hv1_emulator::message_queues::MessageQueues; use hv1_hypercall::HvRepResult; use hv1_structs::ProcessorSet; use hv1_structs::VtlArray; -use hvdef::hypercall::HostVisibilityType; use hvdef::HvError; use hvdef::HvMessage; use hvdef::HvSynicSint; -use hvdef::Vtl; use hvdef::NUM_SINTS; +use hvdef::Vtl; +use hvdef::hypercall::HostVisibilityType; use inspect::Inspect; use inspect::InspectMut; use pal::unix::affinity; @@ -63,15 +63,15 @@ use private::BackingPrivate; use std::convert::Infallible; use std::future::poll_fn; use std::marker::PhantomData; -use std::sync::atomic::Ordering; use std::sync::Arc; +use std::sync::atomic::Ordering; use std::task::Poll; use std::time::Duration; -use virt::io::CpuIo; use virt::Processor; use virt::StopVp; use virt::VpHaltReason; use virt::VpIndex; +use virt::io::CpuIo; use vm_topology::processor::TargetVpInfo; use vmcore::vmtime::VmTimeAccess; @@ -171,22 +171,21 @@ impl LapicState { } mod private { - use super::vp_state; use super::UhRunVpError; - use crate::processor::UhProcessor; + use super::vp_state; use crate::BackingShared; use crate::Error; use crate::GuestVtl; use crate::UhPartitionInner; + use crate::processor::UhProcessor; use hcl::ioctl::ProcessorRunner; use hv1_emulator::hv::ProcessorVtlHv; use hv1_emulator::synic::ProcessorSynic; use inspect::InspectMut; - use std::future::Future; - use virt::io::CpuIo; - use virt::vp::AccessVpState; use virt::StopVp; use virt::VpHaltReason; + use virt::io::CpuIo; + use virt::vp::AccessVpState; use vm_topology::processor::TargetVpInfo; pub struct BackingParams<'a, 'b, T: BackingPrivate> { @@ -676,61 +675,63 @@ impl<'p, T: Backing> Processor for UhProcessor<'p, T> { loop { // Process VP activity and wait for the VP to be ready. - poll_fn(|cx| loop { - stop.check()?; - - // Clear the run VP cancel request. - self.runner.clear_cancel(); - - // Cancel any pending timer. - self.vmtime.cancel_timeout(); - - // Ensure the waker is set. - if !last_waker - .as_ref() - .is_some_and(|waker| cx.waker().will_wake(waker)) - { - last_waker = Some(cx.waker().clone()); - self.inner.waker.write().clone_from(&last_waker); - } - - // Process wakes. - let scan_irr = if self.inner.wake_reasons.load(Ordering::Relaxed) != 0 { - self.handle_wake().map_err(VpHaltReason::Hypervisor)? - } else { - [false, false].into() - }; + poll_fn(|cx| { + loop { + stop.check()?; + + // Clear the run VP cancel request. + self.runner.clear_cancel(); + + // Cancel any pending timer. + self.vmtime.cancel_timeout(); + + // Ensure the waker is set. + if !last_waker + .as_ref() + .is_some_and(|waker| cx.waker().will_wake(waker)) + { + last_waker = Some(cx.waker().clone()); + self.inner.waker.write().clone_from(&last_waker); + } - if self.backing.untrusted_synic().is_some() { - self.update_synic(GuestVtl::Vtl0, true); - } + // Process wakes. + let scan_irr = if self.inner.wake_reasons.load(Ordering::Relaxed) != 0 { + self.handle_wake().map_err(VpHaltReason::Hypervisor)? + } else { + [false, false].into() + }; - for vtl in [GuestVtl::Vtl1, GuestVtl::Vtl0] { - // Process interrupts. - if self.backing.hv(vtl).is_some() { - self.update_synic(vtl, false); + if self.backing.untrusted_synic().is_some() { + self.update_synic(GuestVtl::Vtl0, true); } - T::poll_apic(self, vtl, scan_irr[vtl] || first_scan_irr) - .map_err(VpHaltReason::Hypervisor)?; - } - first_scan_irr = false; + for vtl in [GuestVtl::Vtl1, GuestVtl::Vtl0] { + // Process interrupts. + if self.backing.hv(vtl).is_some() { + self.update_synic(vtl, false); + } - if T::handle_cross_vtl_interrupts(self, dev) - .map_err(VpHaltReason::InvalidVmState)? - { - continue; - } + T::poll_apic(self, vtl, scan_irr[vtl] || first_scan_irr) + .map_err(VpHaltReason::Hypervisor)?; + } + first_scan_irr = false; - // Arm the timer. - if let Some(timeout) = self.vmtime.get_timeout() { - let deadline = self.vmtime.host_time(timeout); - if self.timer.poll_timer(cx, deadline).is_ready() { + if T::handle_cross_vtl_interrupts(self, dev) + .map_err(VpHaltReason::InvalidVmState)? + { continue; } - } - return >>::Ok(()).into(); + // Arm the timer. + if let Some(timeout) = self.vmtime.get_timeout() { + let deadline = self.vmtime.host_time(timeout); + if self.timer.poll_timer(cx, deadline).is_ready() { + continue; + } + } + + return >>::Ok(()).into(); + } }) .await?; diff --git a/openhcl/virt_mshv_vtl/src/processor/mshv/arm64.rs b/openhcl/virt_mshv_vtl/src/processor/mshv/arm64.rs index b87fbc0fa1..feb41c6827 100644 --- a/openhcl/virt_mshv_vtl/src/processor/mshv/arm64.rs +++ b/openhcl/virt_mshv_vtl/src/processor/mshv/arm64.rs @@ -7,27 +7,26 @@ type VpRegisterName = HvArm64RegisterName; +use super::super::BackingPrivate; +use super::super::UhRunVpError; use super::super::private::BackingParams; use super::super::signal_mnf; use super::super::vp_state; use super::super::vp_state::UhVpStateAccess; -use super::super::BackingPrivate; -use super::super::UhRunVpError; +use crate::BackingShared; +use crate::Error; use crate::processor::UhEmulationState; use crate::processor::UhHypercallHandler; use crate::processor::UhProcessor; -use crate::BackingShared; -use crate::Error; use aarch64defs::Cpsr64; use aarch64emu::AccessCpuState; use aarch64emu::InterceptState; -use hcl::ioctl; -use hcl::ioctl::aarch64::MshvArm64; use hcl::GuestVtl; use hcl::UnsupportedGuestVtl; +use hcl::ioctl; +use hcl::ioctl::aarch64::MshvArm64; use hv1_emulator::hv::ProcessorVtlHv; use hv1_emulator::synic::ProcessorSynic; -use hvdef::hypercall; use hvdef::HvAarch64PendingEvent; use hvdef::HvArm64RegisterName; use hvdef::HvArm64ResetType; @@ -36,16 +35,17 @@ use hvdef::HvMapGpaFlags; use hvdef::HvMessageType; use hvdef::HvRegisterValue; use hvdef::Vtl; +use hvdef::hypercall; use inspect::Inspect; use inspect::InspectMut; use inspect_counters::Counter; +use virt::VpHaltReason; +use virt::VpIndex; use virt::aarch64::vp; use virt::aarch64::vp::AccessVpState; use virt::io::CpuIo; use virt::state::HvRegisterState; use virt::state::StateElement; -use virt::VpHaltReason; -use virt::VpIndex; use virt_support_aarch64emu::emulate; use virt_support_aarch64emu::emulate::EmuCheckVtlAccessError; use virt_support_aarch64emu::emulate::EmuTranslateError; @@ -308,7 +308,7 @@ impl UhProcessor<'_, HypervisorBackedArm64> { ) .unwrap() .0; // TODO: zerocopy: err, use-rest-of-range (https://github.com/microsoft/openvmm/issues/759) - // tracing::trace!(msg = %format_args!("{:x?}", message), "mmio"); + // tracing::trace!(msg = %format_args!("{:x?}", message), "mmio"); let intercept_state = InterceptState { instruction_bytes: message.instruction_bytes, diff --git a/openhcl/virt_mshv_vtl/src/processor/mshv/tlb_lock.rs b/openhcl/virt_mshv_vtl/src/processor/mshv/tlb_lock.rs index 4ad234dd12..4ad409d9f7 100644 --- a/openhcl/virt_mshv_vtl/src/processor/mshv/tlb_lock.rs +++ b/openhcl/virt_mshv_vtl/src/processor/mshv/tlb_lock.rs @@ -6,9 +6,9 @@ use crate::HypervisorBacked; use crate::UhProcessor; use hcl::GuestVtl; -use hvdef::hypercall::HvInputVtl; use hvdef::HvAllArchRegisterName; use hvdef::Vtl; +use hvdef::hypercall::HvInputVtl; impl UhProcessor<'_, HypervisorBacked> { /// Causes the specified VTL on the current VP to wait on all TLB locks. diff --git a/openhcl/virt_mshv_vtl/src/processor/mshv/x64.rs b/openhcl/virt_mshv_vtl/src/processor/mshv/x64.rs index fe6fbe8754..b21a4954e9 100644 --- a/openhcl/virt_mshv_vtl/src/processor/mshv/x64.rs +++ b/openhcl/virt_mshv_vtl/src/processor/mshv/x64.rs @@ -7,32 +7,32 @@ type VpRegisterName = HvX64RegisterName; +use super::super::BackingPrivate; +use super::super::UhEmulationState; +use super::super::UhRunVpError; use super::super::private::BackingParams; use super::super::signal_mnf; use super::super::vp_state; use super::super::vp_state::UhVpStateAccess; -use super::super::BackingPrivate; -use super::super::UhEmulationState; -use super::super::UhRunVpError; -use crate::processor::SidecarExitReason; -use crate::processor::SidecarRemoveExit; -use crate::processor::UhHypercallHandler; -use crate::processor::UhProcessor; -use crate::validate_vtl_gpa_flags; use crate::BackingShared; use crate::Error; use crate::GuestVsmState; use crate::GuestVsmVtl1State; use crate::GuestVtl; +use crate::processor::SidecarExitReason; +use crate::processor::SidecarRemoveExit; +use crate::processor::UhHypercallHandler; +use crate::processor::UhProcessor; +use crate::validate_vtl_gpa_flags; use hcl::ioctl; -use hcl::ioctl::x64::MshvX64; use hcl::ioctl::ApplyVtlProtectionsError; +use hcl::ioctl::x64::MshvX64; use hcl::protocol; use hv1_emulator::hv::ProcessorVtlHv; use hv1_emulator::synic::ProcessorSynic; use hv1_hypercall::HvRepResult; use hv1_structs::VtlSet; -use hvdef::hypercall; +use hvdef::HV_PAGE_SIZE; use hvdef::HvDeliverabilityNotificationsRegister; use hvdef::HvError; use hvdef::HvInterceptAccessType; @@ -45,30 +45,30 @@ use hvdef::HvX64PendingEvent; use hvdef::HvX64PendingInterruptionType; use hvdef::HvX64RegisterName; use hvdef::Vtl; -use hvdef::HV_PAGE_SIZE; +use hvdef::hypercall; use inspect::Inspect; use inspect::InspectMut; use inspect_counters::Counter; use std::sync::atomic::Ordering::Relaxed; +use virt::StopVp; +use virt::VpHaltReason; +use virt::VpIndex; use virt::io::CpuIo; use virt::state::HvRegisterState; use virt::state::StateElement; use virt::vp; use virt::vp::AccessVpState; use virt::x86::MsrError; -use virt::StopVp; -use virt::VpHaltReason; -use virt::VpIndex; use virt_support_x86emu::emulate::EmuCheckVtlAccessError; use virt_support_x86emu::emulate::EmuTranslateError; use virt_support_x86emu::emulate::EmuTranslateResult; use virt_support_x86emu::emulate::EmulatorSupport; +use x86defs::RFlags; +use x86defs::SegmentRegister; use x86defs::xsave::Fxsave; -use x86defs::xsave::XsaveHeader; use x86defs::xsave::XFEATURE_SSE; use x86defs::xsave::XFEATURE_X87; -use x86defs::RFlags; -use x86defs::SegmentRegister; +use x86defs::xsave::XsaveHeader; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::Immutable; @@ -421,7 +421,7 @@ impl<'a, 'b> InterceptHandler<'a, 'b> { let intercepted_vtl = match vp.runner.reg_page_vtl() { Ok(vtl) => vtl, Err(ioctl::x64::RegisterPageVtlError::InvalidVtl(vtl)) => { - return Err(UhRunVpError::InvalidInterceptedVtl(vtl)) + return Err(UhRunVpError::InvalidInterceptedVtl(vtl)); } Err(ioctl::x64::RegisterPageVtlError::NoRegisterPage) => { if matches!(&message_type, &HvMessageType::HvMessageTypeX64ApicEoi) { @@ -1833,10 +1833,10 @@ mod save_restore { use hvdef::HvInternalActivityRegister; use hvdef::HvX64RegisterName; use hvdef::Vtl; + use virt::Processor; use virt::irqcon::MsiRequest; use virt::vp::AccessVpState; use virt::vp::Mtrrs; - use virt::Processor; use vmcore::save_restore::RestoreError; use vmcore::save_restore::SaveError; use vmcore::save_restore::SaveRestore; @@ -1970,8 +1970,24 @@ mod save_restore { let startup_suspend = internal_activity .map(|a| HvInternalActivityRegister::from(a.as_u64()).startup_suspend()); - let [rax, rcx, rdx, rbx, cr2, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15] = - self.runner.cpu_context().gps; + let [ + rax, + rcx, + rdx, + rbx, + cr2, + rbp, + rsi, + rdi, + r8, + r9, + r10, + r11, + r12, + r13, + r14, + r15, + ] = self.runner.cpu_context().gps; // We are responsible for saving shared MSRs too, but other than // the MTRRs all shared MSRs are read-only. So this is all we need. diff --git a/openhcl/virt_mshv_vtl/src/processor/snp/mod.rs b/openhcl/virt_mshv_vtl/src/processor/snp/mod.rs index 9e500168d1..2073c7503a 100644 --- a/openhcl/virt_mshv_vtl/src/processor/snp/mod.rs +++ b/openhcl/virt_mshv_vtl/src/processor/snp/mod.rs @@ -3,18 +3,15 @@ //! Processor support for SNP partitions. -use super::hardware_cvm; -use super::private::BackingParams; -use super::vp_state; -use super::vp_state::UhVpStateAccess; use super::BackingPrivate; use super::BackingSharedParams; use super::HardwareIsolatedBacking; use super::UhEmulationState; use super::UhRunVpError; -use crate::devmsr; -use crate::processor::UhHypercallHandler; -use crate::processor::UhProcessor; +use super::hardware_cvm; +use super::private::BackingParams; +use super::vp_state; +use super::vp_state::UhVpStateAccess; use crate::BackingShared; use crate::Error; use crate::GuestVtl; @@ -23,6 +20,9 @@ use crate::UhCvmPartitionState; use crate::UhCvmVpState; use crate::UhPartitionInner; use crate::WakeReason; +use crate::devmsr; +use crate::processor::UhHypercallHandler; +use crate::processor::UhProcessor; use hcl::vmsa::VmsaWrapper; use hv1_emulator::hv::ProcessorVtlHv; use hv1_emulator::synic::ProcessorSynic; @@ -30,20 +30,23 @@ use hv1_hypercall::HvRepResult; use hv1_hypercall::HypercallIo; use hv1_structs::ProcessorSet; use hv1_structs::VtlArray; -use hvdef::hypercall::Control; -use hvdef::hypercall::HvFlushFlags; -use hvdef::hypercall::HvGvaRange; -use hvdef::hypercall::HypercallOutput; +use hvdef::HV_PAGE_SIZE; use hvdef::HvDeliverabilityNotificationsRegister; use hvdef::HvError; use hvdef::HvMessageType; use hvdef::HvX64PendingExceptionEvent; use hvdef::HvX64RegisterName; use hvdef::Vtl; -use hvdef::HV_PAGE_SIZE; +use hvdef::hypercall::Control; +use hvdef::hypercall::HvFlushFlags; +use hvdef::hypercall::HvGvaRange; +use hvdef::hypercall::HypercallOutput; use inspect::Inspect; use inspect::InspectMut; use inspect_counters::Counter; +use virt::Processor; +use virt::VpHaltReason; +use virt::VpIndex; use virt::io::CpuIo; use virt::state::StateElement; use virt::vp; @@ -53,15 +56,13 @@ use virt::x86::MsrError; use virt::x86::MsrErrorExt; use virt::x86::SegmentRegister; use virt::x86::TableRegister; -use virt::Processor; -use virt::VpHaltReason; -use virt::VpIndex; use virt_support_apic::ApicClient; +use virt_support_x86emu::emulate::EmulatorSupport as X86EmulatorSupport; use virt_support_x86emu::emulate::emulate_io; use virt_support_x86emu::emulate::emulate_translate_gva; -use virt_support_x86emu::emulate::EmulatorSupport as X86EmulatorSupport; use virt_support_x86emu::translate::TranslationRegisters; use vmcore::vmtime::VmTimeAccess; +use x86defs::RFlags; use x86defs::cpuid::CpuidFunction; use x86defs::snp::SevEventInjectInfo; use x86defs::snp::SevExitCode; @@ -72,7 +73,6 @@ use x86defs::snp::SevSelector; use x86defs::snp::SevStatusMsr; use x86defs::snp::SevVmsa; use x86defs::snp::Vmpl; -use x86defs::RFlags; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::IntoBytes; diff --git a/openhcl/virt_mshv_vtl/src/processor/tdx/mod.rs b/openhcl/virt_mshv_vtl/src/processor/tdx/mod.rs index 79037d696f..2e7d94a542 100644 --- a/openhcl/virt_mshv_vtl/src/processor/tdx/mod.rs +++ b/openhcl/virt_mshv_vtl/src/processor/tdx/mod.rs @@ -5,15 +5,15 @@ mod tlb_flush; -use super::hardware_cvm; -use super::private::BackingPrivate; -use super::vp_state; -use super::vp_state::UhVpStateAccess; use super::BackingSharedParams; use super::HardwareIsolatedBacking; use super::UhEmulationState; use super::UhHypercallHandler; use super::UhRunVpError; +use super::hardware_cvm; +use super::private::BackingPrivate; +use super::vp_state; +use super::vp_state::UhVpStateAccess; use crate::BackingShared; use crate::GuestVtl; use crate::TlbFlushLockAccess; @@ -22,9 +22,9 @@ use crate::UhCvmVpState; use crate::UhPartitionInner; use crate::UhProcessor; use crate::WakeReason; +use hcl::ioctl::ProcessorRunner; use hcl::ioctl::tdx::Tdx; use hcl::ioctl::tdx::TdxPrivateRegs; -use hcl::ioctl::ProcessorRunner; use hcl::protocol::hcl_intr_offload_flags; use hcl::protocol::tdx_tdg_vp_enter_exit_info; use hv1_emulator::hv::ProcessorVtlHv; @@ -34,14 +34,14 @@ use hv1_hypercall::HvRepResult; use hv1_hypercall::HypercallIo; use hv1_structs::ProcessorSet; use hv1_structs::VtlArray; -use hvdef::hypercall::HvFlushFlags; -use hvdef::hypercall::HvGvaRange; +use hvdef::HV_PAGE_SIZE; use hvdef::HvError; use hvdef::HvSynicSimpSiefp; use hvdef::HvX64PendingExceptionEvent; use hvdef::HvX64RegisterName; use hvdef::Vtl; -use hvdef::HV_PAGE_SIZE; +use hvdef::hypercall::HvFlushFlags; +use hvdef::hypercall::HvGvaRange; use inspect::Inspect; use inspect::InspectMut; use inspect_counters::Counter; @@ -49,9 +49,12 @@ use parking_lot::RwLock; use std::sync::atomic::AtomicU8; use std::sync::atomic::Ordering; use thiserror::Error; +use tlb_flush::FLUSH_GVA_LIST_SIZE; use tlb_flush::TdxFlushState; use tlb_flush::TdxPartitionFlushState; -use tlb_flush::FLUSH_GVA_LIST_SIZE; +use virt::Processor; +use virt::VpHaltReason; +use virt::VpIndex; use virt::io::CpuIo; use virt::state::StateElement; use virt::vp; @@ -62,17 +65,27 @@ use virt::x86::MsrError; use virt::x86::MsrErrorExt; use virt::x86::SegmentRegister; use virt::x86::TableRegister; -use virt::Processor; -use virt::VpHaltReason; -use virt::VpIndex; use virt_support_apic::ApicClient; use virt_support_apic::OffloadNotSupported; -use virt_support_x86emu::emulate::emulate_io; -use virt_support_x86emu::emulate::emulate_translate_gva; use virt_support_x86emu::emulate::EmulatorSupport as X86EmulatorSupport; use virt_support_x86emu::emulate::TranslateMode; +use virt_support_x86emu::emulate::emulate_io; +use virt_support_x86emu::emulate::emulate_translate_gva; use virt_support_x86emu::translate::TranslationRegisters; use vmcore::vmtime::VmTimeAccess; +use x86defs::RFlags; +use x86defs::X64_CR0_ET; +use x86defs::X64_CR0_NE; +use x86defs::X64_CR0_PE; +use x86defs::X64_CR0_PG; +use x86defs::X64_CR4_MCE; +use x86defs::X64_CR4_VMXE; +use x86defs::X64_EFER_FFXSR; +use x86defs::X64_EFER_LMA; +use x86defs::X64_EFER_LME; +use x86defs::X64_EFER_NXE; +use x86defs::X64_EFER_SVME; +use x86defs::X86X_MSR_EFER; use x86defs::apic::X2APIC_MSR_BASE; use x86defs::cpuid::CpuidFunction; use x86defs::tdx::TdCallResultCode; @@ -83,38 +96,25 @@ use x86defs::tdx::TdxL2Ctls; use x86defs::tdx::TdxVpEnterRaxResult; use x86defs::vmx::ApicPage; use x86defs::vmx::ApicRegister; -use x86defs::vmx::CrAccessQualification; -use x86defs::vmx::ExitQualificationIo; -use x86defs::vmx::Interruptibility; -use x86defs::vmx::InterruptionInformation; -use x86defs::vmx::ProcessorControls; -use x86defs::vmx::SecondaryProcessorControls; -use x86defs::vmx::VmcsField; -use x86defs::vmx::VmxEptExitQualification; -use x86defs::vmx::VmxExit; use x86defs::vmx::CR_ACCESS_TYPE_LMSW; use x86defs::vmx::CR_ACCESS_TYPE_MOV_TO_CR; +use x86defs::vmx::CrAccessQualification; +use x86defs::vmx::ExitQualificationIo; use x86defs::vmx::INTERRUPT_TYPE_EXTERNAL; use x86defs::vmx::INTERRUPT_TYPE_HARDWARE_EXCEPTION; use x86defs::vmx::INTERRUPT_TYPE_NMI; +use x86defs::vmx::IO_SIZE_8_BIT; use x86defs::vmx::IO_SIZE_16_BIT; use x86defs::vmx::IO_SIZE_32_BIT; -use x86defs::vmx::IO_SIZE_8_BIT; +use x86defs::vmx::Interruptibility; +use x86defs::vmx::InterruptionInformation; +use x86defs::vmx::ProcessorControls; +use x86defs::vmx::SecondaryProcessorControls; use x86defs::vmx::VMX_ENTRY_CONTROL_LONG_MODE_GUEST; use x86defs::vmx::VMX_FEATURE_CONTROL_LOCKED; -use x86defs::RFlags; -use x86defs::X64_CR0_ET; -use x86defs::X64_CR0_NE; -use x86defs::X64_CR0_PE; -use x86defs::X64_CR0_PG; -use x86defs::X64_CR4_MCE; -use x86defs::X64_CR4_VMXE; -use x86defs::X64_EFER_FFXSR; -use x86defs::X64_EFER_LMA; -use x86defs::X64_EFER_LME; -use x86defs::X64_EFER_NXE; -use x86defs::X64_EFER_SVME; -use x86defs::X86X_MSR_EFER; +use x86defs::vmx::VmcsField; +use x86defs::vmx::VmxEptExitQualification; +use x86defs::vmx::VmxExit; use x86emu::Gp; use x86emu::Segment; @@ -1866,12 +1866,12 @@ impl UhProcessor<'_, TdxBacked> { VmxExit::TRIPLE_FAULT => { return Err(VpHaltReason::TripleFault { vtl: intercepted_vtl.into(), - }) + }); } _ => { return Err(VpHaltReason::Hypervisor(UhRunVpError::UnknownVmxExit( exit_info.code().vmx_exit(), - ))) + ))); } }; stat.increment(); diff --git a/openhcl/virt_mshv_vtl/src/processor/tdx/tlb_flush.rs b/openhcl/virt_mshv_vtl/src/processor/tdx/tlb_flush.rs index 298241f9e4..6c94032d4c 100644 --- a/openhcl/virt_mshv_vtl/src/processor/tdx/tlb_flush.rs +++ b/openhcl/virt_mshv_vtl/src/processor/tdx/tlb_flush.rs @@ -5,9 +5,9 @@ use crate::TdxBacked; use crate::UhProcessor; -use hcl::ioctl::tdx::Tdx; -use hcl::ioctl::ProcessorRunner; use hcl::GuestVtl; +use hcl::ioctl::ProcessorRunner; +use hcl::ioctl::tdx::Tdx; use hvdef::hypercall::HvGvaRange; use inspect::Inspect; use safeatomic::AtomicSliceOps; diff --git a/openhcl/vmfirmwareigvm_dll/build.rs b/openhcl/vmfirmwareigvm_dll/build.rs index 3aed0bc512..6b581fb782 100644 --- a/openhcl/vmfirmwareigvm_dll/build.rs +++ b/openhcl/vmfirmwareigvm_dll/build.rs @@ -59,7 +59,9 @@ fn main() { && std::env::var_os("UH_PATCH").is_none() && std::env::var_os("UH_REVISION").is_none() { - println!("cargo::warning=Attempted to build without setting UH_IGVM_PATH - resulting DLL will be empty!"); + println!( + "cargo::warning=Attempted to build without setting UH_IGVM_PATH - resulting DLL will be empty!" + ); return; } diff --git a/openvmm/hvlite_core/src/partition.rs b/openvmm/hvlite_core/src/partition.rs index e648ac6f66..d1b5765bda 100644 --- a/openvmm/hvlite_core/src/partition.rs +++ b/openvmm/hvlite_core/src/partition.rs @@ -21,13 +21,6 @@ use memory_range::MemoryRange; use pci_core::msi::MsiInterruptTarget; use std::convert::Infallible; use std::sync::Arc; -use virt::io::CpuIo; -#[cfg(guest_arch = "x86_64")] -use virt::irqcon::MsiRequest; -use virt::vm::AccessVmState; -use virt::vm::VmSavedState; -use virt::vp::AccessVpState; -use virt::vp::VpSavedState; #[cfg(guest_arch = "aarch64")] use virt::Aarch64Partition as ArchPartition; use virt::PageVisibility; @@ -42,6 +35,13 @@ use virt::Synic; use virt::VpHaltReason; #[cfg(guest_arch = "x86_64")] use virt::X86Partition as ArchPartition; +use virt::io::CpuIo; +#[cfg(guest_arch = "x86_64")] +use virt::irqcon::MsiRequest; +use virt::vm::AccessVmState; +use virt::vm::VmSavedState; +use virt::vp::AccessVpState; +use virt::vp::VpSavedState; #[cfg(guest_arch = "x86_64")] use vmcore::line_interrupt::LineSetTarget; use vmcore::save_restore::RestoreError; @@ -116,7 +116,7 @@ pub trait BasicPartitionStateAccess: 'static + Send + Sync + Inspect { fn reset(&self) -> anyhow::Result<()>; fn scrub_vtl(&self, vtl: Vtl) -> anyhow::Result<()>; fn accept_initial_pages(&self, pages: Vec<(MemoryRange, PageVisibility)>) - -> anyhow::Result<()>; + -> anyhow::Result<()>; } impl BasicPartitionStateAccess for T { diff --git a/openvmm/hvlite_core/src/worker/dispatch.rs b/openvmm/hvlite_core/src/worker/dispatch.rs index ba3d2ec622..e5eb4ffb57 100644 --- a/openvmm/hvlite_core/src/worker/dispatch.rs +++ b/openvmm/hvlite_core/src/worker/dispatch.rs @@ -11,19 +11,19 @@ use anyhow::Context; use cfg_if::cfg_if; use chipset_device_resources::IRQ_LINE_SET; use debug_ptr::DebugPtr; -use disk_backend::resolve::ResolveDiskParameters; use disk_backend::Disk; +use disk_backend::resolve::ResolveDiskParameters; use firmware_uefi::UefiCommandSet; use floppy_resources::FloppyDiskConfig; -use futures::executor::block_on; -use futures::future::try_join_all; use futures::FutureExt; use futures::StreamExt; +use futures::executor::block_on; +use futures::future::try_join_all; use futures_concurrency::prelude::*; use guestmem::GuestMemory; use guid::Guid; -use hvdef::Vtl; use hvdef::HV_PAGE_SIZE; +use hvdef::Vtl; use hvlite_defs::config::Aarch64TopologyConfig; use hvlite_defs::config::Config; use hvlite_defs::config::DeviceVtl; @@ -43,8 +43,8 @@ use hvlite_defs::config::X2ApicConfig; use hvlite_defs::config::X86TopologyConfig; use hvlite_defs::rpc::PulseSaveRestoreError; use hvlite_defs::rpc::VmRpc; -use hvlite_defs::worker::VmWorkerParameters; use hvlite_defs::worker::VM_WORKER; +use hvlite_defs::worker::VmWorkerParameters; use hvlite_pcat_locator::RomFileLocation; use ide_resources::GuestMedia; use ide_resources::IdeDeviceConfig; @@ -56,24 +56,24 @@ use membacking::GuestMemoryBuilder; use membacking::GuestMemoryManager; use membacking::SharedMemoryBacking; use memory_range::MemoryRange; +use mesh::MeshPayload; use mesh::error::RemoteError; -use mesh::payload::message::ProtobufMessage; use mesh::payload::Protobuf; -use mesh::MeshPayload; +use mesh::payload::message::ProtobufMessage; use mesh_worker::Worker; use mesh_worker::WorkerId; use mesh_worker::WorkerRpc; use missing_dev::MissingDevManifest; +use pal_async::DefaultDriver; +use pal_async::DefaultPool; use pal_async::local::block_with_io; use pal_async::task::Spawn; use pal_async::task::Task; -use pal_async::DefaultDriver; -use pal_async::DefaultPool; -use pci_core::msi::MsiInterruptSet; use pci_core::PciInterruptPin; +use pci_core::msi::MsiInterruptSet; use scsi_core::ResolveScsiDeviceHandleParams; -use scsidisk::atapi_scsi::AtapiScsiDisk; use scsidisk::SimpleScsiDisk; +use scsidisk::atapi_scsi::AtapiScsiDisk; use serial_16550_resources::ComPort; use state_unit::SavedStateUnit; use state_unit::SpawnedUnit; @@ -88,58 +88,58 @@ use storvsp::ScsiControllerDisk; use tracing_helpers::ErrorValueExt; use virt::ProtoPartition; use virt::VpIndex; -use virtio::resolve::VirtioResolveInput; use virtio::LegacyWrapper; use virtio::PciInterruptModel; use virtio::VirtioMmioDevice; use virtio::VirtioPciDevice; +use virtio::resolve::VirtioResolveInput; use virtio_serial::VirtioSerialDevice; use vm_loader::initial_regs::initial_regs; +use vm_resource::Resource; +use vm_resource::ResourceResolver; use vm_resource::kind::DiskHandleKind; use vm_resource::kind::KeyboardInputHandleKind; use vm_resource::kind::MouseInputHandleKind; use vm_resource::kind::VirtioDeviceHandle; use vm_resource::kind::VmbusDeviceHandleKind; -use vm_resource::Resource; -use vm_resource::ResourceResolver; use vm_topology::memory::MemoryLayout; +use vm_topology::processor::ArchTopology; +use vm_topology::processor::ProcessorTopology; +use vm_topology::processor::TopologyBuilder; use vm_topology::processor::aarch64::Aarch64Topology; use vm_topology::processor::aarch64::GicInfo; use vm_topology::processor::x86::X2ApicState; use vm_topology::processor::x86::X86Topology; -use vm_topology::processor::ArchTopology; -use vm_topology::processor::ProcessorTopology; -use vm_topology::processor::TopologyBuilder; use vmbus_channel::channel::VmbusDevice; -use vmbus_server::hvsock::HvsockRelay; use vmbus_server::HvsockRelayChannel; use vmbus_server::VmbusServer; +use vmbus_server::hvsock::HvsockRelay; use vmcore::save_restore::SavedStateRoot; -use vmcore::vm_task::thread::ThreadDriverBackend; use vmcore::vm_task::VmTaskDriverSource; +use vmcore::vm_task::thread::ThreadDriverBackend; use vmcore::vmtime::VmTime; use vmcore::vmtime::VmTimeKeeper; use vmcore::vmtime::VmTimeSource; use vmgs_broker::resolver::VmgsFileResolver; use vmm_core::acpi_builder::AcpiTablesBuilder; use vmm_core::input_distributor::InputDistributor; -use vmm_core::partition_unit::block_on_vp; use vmm_core::partition_unit::Halt; use vmm_core::partition_unit::PartitionUnit; use vmm_core::partition_unit::PartitionUnitParams; +use vmm_core::partition_unit::block_on_vp; use vmm_core::synic::SynicPorts; -use vmm_core::vmbus_unit::offer_channel_unit; -use vmm_core::vmbus_unit::offer_vmbus_device_handle_unit; use vmm_core::vmbus_unit::ChannelUnit; use vmm_core::vmbus_unit::VmbusServerHandle; +use vmm_core::vmbus_unit::offer_channel_unit; +use vmm_core::vmbus_unit::offer_vmbus_device_handle_unit; use vmm_core_defs::HaltReason; -use vmotherboard::options::BaseChipsetDevices; -use vmotherboard::options::BaseChipsetFoundation; -use vmotherboard::options::BaseChipsetManifest; use vmotherboard::BaseChipsetBuilder; use vmotherboard::BaseChipsetBuilderOutput; use vmotherboard::ChipsetDeviceHandle; use vmotherboard::ChipsetDevices; +use vmotherboard::options::BaseChipsetDevices; +use vmotherboard::options::BaseChipsetFoundation; +use vmotherboard::options::BaseChipsetManifest; use vpci::bus::VpciBus; const PM_BASE: u16 = 0x400; @@ -588,7 +588,9 @@ fn convert_vtl2_config( Vtl2BaseAddressType::Absolute(base) => { // This file must support relocations. if !crate::worker::vm_loaders::igvm::supports_relocations(igvm_file) { - anyhow::bail!("vtl2 base address is absolute but igvm file does not support relocations"); + anyhow::bail!( + "vtl2 base address is absolute but igvm file does not support relocations" + ); } // Use the size, but the base is the requested load @@ -603,7 +605,9 @@ fn convert_vtl2_config( Vtl2BaseAddressType::Vtl2Allocate { .. } => { // When VTL2 is doing allocation, we do not know which // ranges we should disallow late map access of. - anyhow::bail!("late map vtl0 memory is not supported when VTL2 is doing self allocation of ram"); + anyhow::bail!( + "late map vtl0 memory is not supported when VTL2 is doing self allocation of ram" + ); } } } else { @@ -2095,26 +2099,28 @@ impl InitializedVm { let virt_serial_read = virtio_serial.get_port_read_fn(0); thread::Builder::new() .name("virtio serial out".into()) - .spawn(move || loop { - let data = (virt_serial_read)(); - if data.is_empty() { - break; - } - if let Some(Some(stdout)) = &mut virtio_serial_output { - let result = stdout.write_all(data.as_slice()); - if let Err(error) = result { - tracing::error!( - error = error.as_error(), - "virtio console write failed" - ); + .spawn(move || { + loop { + let data = (virt_serial_read)(); + if data.is_empty() { break; } - let result = stdout.flush(); - if let Err(error) = result { - tracing::error!( - error = error.as_error(), - "virtio console flush failed" - ); + if let Some(Some(stdout)) = &mut virtio_serial_output { + let result = stdout.write_all(data.as_slice()); + if let Err(error) = result { + tracing::error!( + error = error.as_error(), + "virtio console write failed" + ); + break; + } + let result = stdout.flush(); + if let Err(error) = result { + tracing::error!( + error = error.as_error(), + "virtio console flush failed" + ); + } } } }) diff --git a/openvmm/hvlite_core/src/worker/vm_loaders/igvm.rs b/openvmm/hvlite_core/src/worker/vm_loaders/igvm.rs index 57ec78a265..6286bad603 100644 --- a/openvmm/hvlite_core/src/worker/vm_loaders/igvm.rs +++ b/openvmm/hvlite_core/src/worker/vm_loaders/igvm.rs @@ -7,18 +7,18 @@ use guestmem::GuestMemory; use hvdef::HV_PAGE_SIZE; use hvlite_defs::config::SerialInformation; use hvlite_defs::config::Vtl2BaseAddressType; -use igvm::page_table::CpuPagingState; use igvm::IgvmDirectiveHeader; use igvm::IgvmFile; use igvm::IgvmPlatformHeader; use igvm::IgvmRelocatableRegion; -use igvm_defs::IgvmPageDataType; -use igvm_defs::IgvmPlatformType; +use igvm::page_table::CpuPagingState; use igvm_defs::IGVM_VHS_MEMORY_MAP_ENTRY; use igvm_defs::IGVM_VHS_MEMORY_RANGE; use igvm_defs::IGVM_VHS_MMIO_RANGES; use igvm_defs::IGVM_VHS_PARAMETER; use igvm_defs::IGVM_VHS_PARAMETER_INSERT; +use igvm_defs::IgvmPageDataType; +use igvm_defs::IgvmPlatformType; use loader::importer::Aarch64Register; use loader::importer::BootPageAcceptance; use loader::importer::GuestArch; @@ -26,8 +26,8 @@ use loader::importer::ImageLoad; use loader::importer::StartupMemoryType; use loader::importer::TableRegister; use loader::importer::X86Register; -use memory_range::subtract_ranges; use memory_range::MemoryRange; +use memory_range::subtract_ranges; use range_map_vec::RangeMap; use std::collections::HashMap; use std::ffi::CString; @@ -38,10 +38,10 @@ use virt::PageVisibility; use vm_loader::Loader; use vm_topology::memory::MemoryLayout; use vm_topology::memory::MemoryRangeWithNode; -use vm_topology::processor::aarch64::Aarch64Topology; -use vm_topology::processor::x86::X86Topology; use vm_topology::processor::ArchTopology; use vm_topology::processor::ProcessorTopology; +use vm_topology::processor::aarch64::Aarch64Topology; +use vm_topology::processor::x86::X86Topology; use zerocopy::IntoBytes; #[derive(Debug, Error)] diff --git a/openvmm/hvlite_core/src/worker/vm_loaders/linux.rs b/openvmm/hvlite_core/src/worker/vm_loaders/linux.rs index 65816beb70..3d6ef271cd 100644 --- a/openvmm/hvlite_core/src/worker/vm_loaders/linux.rs +++ b/openvmm/hvlite_core/src/worker/vm_loaders/linux.rs @@ -16,8 +16,8 @@ use std::io::Seek; use thiserror::Error; use vm_loader::Loader; use vm_topology::memory::MemoryLayout; -use vm_topology::processor::aarch64::Aarch64Topology; use vm_topology::processor::ProcessorTopology; +use vm_topology::processor::aarch64::Aarch64Topology; #[derive(Debug, Error)] #[error("device tree error: {0:?}")] diff --git a/openvmm/hvlite_core/src/worker/vm_loaders/uefi.rs b/openvmm/hvlite_core/src/worker/vm_loaders/uefi.rs index a501c799ce..1dd8fc54c4 100644 --- a/openvmm/hvlite_core/src/worker/vm_loaders/uefi.rs +++ b/openvmm/hvlite_core/src/worker/vm_loaders/uefi.rs @@ -6,8 +6,8 @@ use guid::Guid; use hvdef::HV_PAGE_SIZE; use hvlite_defs::config::UefiConsoleMode; use loader::importer::Register; -use loader::uefi::config; use loader::uefi::IMAGE_SIZE; +use loader::uefi::config; use std::io::Read; use std::io::Seek; use thiserror::Error; diff --git a/openvmm/hvlite_defs/src/config.rs b/openvmm/hvlite_defs/src/config.rs index 9e44ac724c..e31206cc86 100644 --- a/openvmm/hvlite_defs/src/config.rs +++ b/openvmm/hvlite_defs/src/config.rs @@ -7,18 +7,18 @@ use guid::Guid; use hvlite_pcat_locator::RomFileLocation; use input_core::InputData; use memory_range::MemoryRange; -use mesh::payload::Protobuf; use mesh::MeshPayload; +use mesh::payload::Protobuf; use net_backend_resources::mac_address::MacAddress; use std::fmt; use std::fs::File; +use vm_resource::Resource; use vm_resource::kind::DiskHandleKind; use vm_resource::kind::PciDeviceHandleKind; use vm_resource::kind::VirtioDeviceHandle; use vm_resource::kind::VmbusDeviceHandleKind; -use vm_resource::Resource; -use vmotherboard::options::BaseChipsetManifest; use vmotherboard::ChipsetDeviceHandle; +use vmotherboard::options::BaseChipsetManifest; #[derive(MeshPayload, Debug)] pub struct Config { diff --git a/openvmm/hvlite_defs/src/rpc.rs b/openvmm/hvlite_defs/src/rpc.rs index 55fbeaa505..c668aad60e 100644 --- a/openvmm/hvlite_defs/src/rpc.rs +++ b/openvmm/hvlite_defs/src/rpc.rs @@ -5,16 +5,16 @@ use crate::config::DeviceVtl; use guid::Guid; +use mesh::CancelContext; +use mesh::MeshPayload; use mesh::error::RemoteError; use mesh::payload::message::ProtobufMessage; use mesh::rpc::FailableRpc; use mesh::rpc::Rpc; -use mesh::CancelContext; -use mesh::MeshPayload; use std::fmt; use std::fs::File; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::Resource; +use vm_resource::kind::VmbusDeviceHandleKind; #[derive(MeshPayload)] pub enum VmRpc { diff --git a/openvmm/hvlite_defs/src/worker.rs b/openvmm/hvlite_defs/src/worker.rs index bd300f06bc..48cd31b71b 100644 --- a/openvmm/hvlite_defs/src/worker.rs +++ b/openvmm/hvlite_defs/src/worker.rs @@ -6,8 +6,8 @@ use crate::config::Config; use crate::config::Hypervisor; use crate::rpc::VmRpc; -use mesh::payload::message::ProtobufMessage; use mesh::MeshPayload; +use mesh::payload::message::ProtobufMessage; use mesh_worker::WorkerId; use vmm_core_defs::HaltReason; diff --git a/openvmm/hvlite_helpers/src/disk.rs b/openvmm/hvlite_helpers/src/disk.rs index 14e15f4c7a..60e4ade078 100644 --- a/openvmm/hvlite_helpers/src/disk.rs +++ b/openvmm/hvlite_helpers/src/disk.rs @@ -4,8 +4,8 @@ //! Guest disk helpers. use std::path::Path; -use vm_resource::kind::DiskHandleKind; use vm_resource::Resource; +use vm_resource::kind::DiskHandleKind; /// Opens the resources needed for using a disk from a file at `path`. /// diff --git a/openvmm/hvlite_pcat_locator/src/resource_dll_parser.rs b/openvmm/hvlite_pcat_locator/src/resource_dll_parser.rs index 48c593f10d..608301c963 100644 --- a/openvmm/hvlite_pcat_locator/src/resource_dll_parser.rs +++ b/openvmm/hvlite_pcat_locator/src/resource_dll_parser.rs @@ -4,12 +4,12 @@ //! Function to parse a resource dll for a given ID. use crate::DllResourceDescriptor; -use anyhow::bail; use anyhow::Context; +use anyhow::bail; use fs_err::File; -use object::read::pe::PeFile64; use object::LittleEndian; use object::ReadCache; +use object::read::pe::PeFile64; /// Tries to read the given resource from a resource dll. If the given data /// buffer is not a valid PE file this function returns Ok(None). If it is a PE diff --git a/openvmm/membacking/src/mapping_manager/manager.rs b/openvmm/membacking/src/mapping_manager/manager.rs index f9df8811b2..2546db1bd4 100644 --- a/openvmm/membacking/src/mapping_manager/manager.rs +++ b/openvmm/membacking/src/mapping_manager/manager.rs @@ -11,14 +11,14 @@ use super::object_cache::ObjectId; use super::va_mapper::VaMapper; use super::va_mapper::VaMapperError; use crate::RemoteProcess; -use futures::future::join_all; use futures::StreamExt; +use futures::future::join_all; use inspect::Inspect; use inspect::InspectMut; use memory_range::MemoryRange; +use mesh::MeshPayload; use mesh::rpc::Rpc; use mesh::rpc::RpcSend; -use mesh::MeshPayload; use pal_async::task::Spawn; use slab::Slab; use std::sync::Arc; diff --git a/openvmm/membacking/src/mapping_manager/mappable.rs b/openvmm/membacking/src/mapping_manager/mappable.rs index d109374ef5..0e9e5cc03f 100644 --- a/openvmm/membacking/src/mapping_manager/mappable.rs +++ b/openvmm/membacking/src/mapping_manager/mappable.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use mesh::payload::encoding::ResourceField; use mesh::payload::DefaultEncoding; +use mesh::payload::encoding::ResourceField; use std::sync::Arc; /// A section handle. diff --git a/openvmm/membacking/src/mapping_manager/object_cache.rs b/openvmm/membacking/src/mapping_manager/object_cache.rs index 96ae99c8af..d146be280b 100644 --- a/openvmm/membacking/src/mapping_manager/object_cache.rs +++ b/openvmm/membacking/src/mapping_manager/object_cache.rs @@ -9,7 +9,6 @@ use mesh::MeshPayload; use parking_lot::Mutex; -use std::future::Future; use std::sync::Arc; use std::sync::Weak; diff --git a/openvmm/membacking/src/memory_manager/mod.rs b/openvmm/membacking/src/memory_manager/mod.rs index 26bd10dbc0..e6a3f5bf81 100644 --- a/openvmm/membacking/src/memory_manager/mod.rs +++ b/openvmm/membacking/src/memory_manager/mod.rs @@ -7,6 +7,7 @@ mod device_memory; pub use device_memory::DeviceMemoryMapper; +use crate::RemoteProcess; use crate::mapping_manager::Mappable; use crate::mapping_manager::MappingManager; use crate::mapping_manager::MappingManagerClient; @@ -16,7 +17,6 @@ use crate::partition_mapper::PartitionMapper; use crate::region_manager::MapParams; use crate::region_manager::RegionHandle; use crate::region_manager::RegionManager; -use crate::RemoteProcess; use guestmem::GuestMemory; use hvdef::Vtl; use inspect::Inspect; diff --git a/openvmm/membacking/src/region_manager.rs b/openvmm/membacking/src/region_manager.rs index 9f2948b980..f3b1b79562 100644 --- a/openvmm/membacking/src/region_manager.rs +++ b/openvmm/membacking/src/region_manager.rs @@ -11,9 +11,9 @@ use futures::StreamExt; use inspect::Inspect; use inspect::InspectMut; use memory_range::MemoryRange; +use mesh::MeshPayload; use mesh::rpc::Rpc; use mesh::rpc::RpcSend; -use mesh::MeshPayload; use pal_async::task::Spawn; use std::cmp::Ordering; use thiserror::Error; @@ -387,10 +387,12 @@ impl RegionManagerTask { // TODO: split and remove existing mappings, atomically. This is // technically required by virtiofs DAX support. - assert!(!region - .mappings - .iter() - .any(|m| m.params.range_in_region.overlaps(¶ms.range_in_region))); + assert!( + !region + .mappings + .iter() + .any(|m| m.params.range_in_region.overlaps(¶ms.range_in_region)) + ); if let Some(region_range) = region.active_range() { let range = range_within(region_range, params.range_in_region); diff --git a/openvmm/openvmm_entry/src/cli_args.rs b/openvmm/openvmm_entry/src/cli_args.rs index 3340063e42..7d9605b0d7 100644 --- a/openvmm/openvmm_entry/src/cli_args.rs +++ b/openvmm/openvmm_entry/src/cli_args.rs @@ -21,12 +21,12 @@ use anyhow::Context; use clap::Parser; use clap::ValueEnum; +use hvlite_defs::config::DEFAULT_PCAT_BOOT_ORDER; use hvlite_defs::config::DeviceVtl; use hvlite_defs::config::Hypervisor; use hvlite_defs::config::PcatBootDevice; use hvlite_defs::config::Vtl2BaseAddressType; use hvlite_defs::config::X2ApicConfig; -use hvlite_defs::config::DEFAULT_PCAT_BOOT_ORDER; use std::ffi::OsString; use std::net::SocketAddr; use std::path::PathBuf; diff --git a/openvmm/openvmm_entry/src/crash_dump.rs b/openvmm/openvmm_entry/src/crash_dump.rs index 38336080ea..f6ecf15db4 100644 --- a/openvmm/openvmm_entry/src/crash_dump.rs +++ b/openvmm/openvmm_entry/src/crash_dump.rs @@ -7,18 +7,18 @@ use anyhow::Context; use futures::StreamExt; use futures_concurrency::stream::Merge; use get_resources::crash::GuestCrashDeviceHandle; +use mesh::OneshotReceiver; use mesh::channel; use mesh::rpc::FailableRpc; -use mesh::OneshotReceiver; use pal_async::task::Spawn; use pal_async::task::Task; use std::fs::File; use std::path::Path; use std::path::PathBuf; use unicycle::FuturesUnordered; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::IntoResource; use vm_resource::Resource; +use vm_resource::kind::VmbusDeviceHandleKind; /// Spawns a crash dump handling task and returns a resource to instantiate a /// guest crash device. diff --git a/openvmm/openvmm_entry/src/lib.rs b/openvmm/openvmm_entry/src/lib.rs index f46c507e3e..6a6c8905b3 100644 --- a/openvmm/openvmm_entry/src/lib.rs +++ b/openvmm/openvmm_entry/src/lib.rs @@ -19,8 +19,8 @@ mod ttrpc; pub use cli_args::Options; use crate::cli_args::SecureBootTemplateCli; -use anyhow::bail; use anyhow::Context; +use anyhow::bail; use chipset_resources::battery::HostBatteryUpdate; use clap::CommandFactory; use clap::FromArgMatches; @@ -32,27 +32,30 @@ use cli_args::SerialConfigCli; use cli_args::UefiConsoleModeCli; use cli_args::VirtioBusCli; use crash_dump::spawn_dump_handler; +use disk_backend_resources::DiskLayerDescription; use disk_backend_resources::layer::DiskLayerHandle; use disk_backend_resources::layer::RamDiskLayerHandle; use disk_backend_resources::layer::SqliteAutoCacheDiskLayerHandle; use disk_backend_resources::layer::SqliteDiskLayerHandle; -use disk_backend_resources::DiskLayerDescription; use floppy_resources::FloppyDiskConfig; -use framebuffer::FramebufferAccess; use framebuffer::FRAMEBUFFER_SIZE; -use futures::executor::block_on; -use futures::io::AllowStdIo; +use framebuffer::FramebufferAccess; use futures::AsyncReadExt; use futures::AsyncWrite; use futures::AsyncWriteExt; use futures::FutureExt; use futures::StreamExt; +use futures::executor::block_on; +use futures::io::AllowStdIo; use futures_concurrency::stream::Merge; use gdma_resources::GdmaDeviceHandle; use gdma_resources::VportDefinition; use get_resources::ged::GuestServicingFlags; use guid::Guid; use hvlite_defs::config::Config; +use hvlite_defs::config::DEFAULT_MMIO_GAPS; +use hvlite_defs::config::DEFAULT_MMIO_GAPS_WITH_VTL2; +use hvlite_defs::config::DEFAULT_PCAT_BOOT_ORDER; use hvlite_defs::config::DeviceVtl; use hvlite_defs::config::HypervisorConfig; use hvlite_defs::config::LateMapVtl0MemoryPolicy; @@ -65,35 +68,32 @@ use hvlite_defs::config::VmbusConfig; use hvlite_defs::config::VpciDeviceConfig; use hvlite_defs::config::Vtl2BaseAddressType; use hvlite_defs::config::Vtl2Config; -use hvlite_defs::config::DEFAULT_MMIO_GAPS; -use hvlite_defs::config::DEFAULT_MMIO_GAPS_WITH_VTL2; -use hvlite_defs::config::DEFAULT_PCAT_BOOT_ORDER; use hvlite_defs::rpc::PulseSaveRestoreError; use hvlite_defs::rpc::VmRpc; -use hvlite_defs::worker::VmWorkerParameters; use hvlite_defs::worker::VM_WORKER; +use hvlite_defs::worker::VmWorkerParameters; use hvlite_helpers::disk::open_disk_type; use input_core::MultiplexedInputHandle; use inspect::InspectMut; use inspect::InspectionBuilder; use io::Read; +use mesh::CancelContext; use mesh::error::RemoteError; use mesh::rpc::Rpc; use mesh::rpc::RpcError; use mesh::rpc::RpcSend; -use mesh::CancelContext; -use mesh_worker::launch_local_worker; use mesh_worker::WorkerEvent; use mesh_worker::WorkerHandle; +use mesh_worker::launch_local_worker; use meshworker::VmmMesh; use net_backend_resources::mac_address::MacAddress; +use pal_async::DefaultDriver; +use pal_async::DefaultPool; use pal_async::pipe::PolledPipe; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; use pal_async::task::Task; use pal_async::timer::PolledTimer; -use pal_async::DefaultDriver; -use pal_async::DefaultPool; use scsidisk_resources::SimpleScsiDiskHandle; use scsidisk_resources::SimpleScsiDvdHandle; use serial_16550_resources::ComPort; @@ -131,13 +131,13 @@ use vm_manifest_builder::BaseChipsetType; use vm_manifest_builder::MachineArch; use vm_manifest_builder::VmChipsetResult; use vm_manifest_builder::VmManifestBuilder; +use vm_resource::IntoResource; +use vm_resource::Resource; use vm_resource::kind::DiskHandleKind; use vm_resource::kind::DiskLayerHandleKind; use vm_resource::kind::NetEndpointHandleKind; use vm_resource::kind::VirtioDeviceHandle; use vm_resource::kind::VmbusDeviceHandleKind; -use vm_resource::IntoResource; -use vm_resource::Resource; use vmbus_serial_resources::VmbusSerialDeviceHandle; use vmbus_serial_resources::VmbusSerialPort; use vmcore::non_volatile_store::resources::EphemeralNonVolatileStoreHandle; diff --git a/openvmm/openvmm_entry/src/meshworker.rs b/openvmm/openvmm_entry/src/meshworker.rs index e92458bb36..0563c7b566 100644 --- a/openvmm/openvmm_entry/src/meshworker.rs +++ b/openvmm/openvmm_entry/src/meshworker.rs @@ -7,9 +7,9 @@ use anyhow::Context; use hvlite_defs::entrypoint::MeshHostParams; use inspect::Inspect; -use mesh_process::try_run_mesh_host; use mesh_process::Mesh; use mesh_process::ProcessConfig; +use mesh_process::try_run_mesh_host; use mesh_worker::RegisteredWorkers; use mesh_worker::WorkerHost; use pal_async::task::Spawn; diff --git a/openvmm/openvmm_entry/src/serial_io.rs b/openvmm/openvmm_entry/src/serial_io.rs index 88e08039d0..4fa88c2524 100644 --- a/openvmm/openvmm_entry/src/serial_io.rs +++ b/openvmm/openvmm_entry/src/serial_io.rs @@ -3,8 +3,8 @@ use crate::cleanup_socket; use anyhow::Context; -use futures::stream; use futures::StreamExt; +use futures::stream; use futures_concurrency::prelude::*; use hvlite_defs::config::SerialPipes; use io::ErrorKind; @@ -21,9 +21,9 @@ use std::net::SocketAddr; use std::path::Path; use std::thread; use unix_socket::UnixListener; -use vm_resource::kind::SerialBackendHandle; use vm_resource::IntoResource; use vm_resource::Resource; +use vm_resource::kind::SerialBackendHandle; pub struct SerialIo { pub input: Option, @@ -49,14 +49,16 @@ impl SerialIo { if let Some(mut output) = self.output.take() { thread::Builder::new() .name(format!("{} copy out", name)) - .spawn(move || loop { - let mut buf = [0; 256]; - let n = output.read(&mut buf).unwrap_or(0); - if n == 0 { - break; + .spawn(move || { + loop { + let mut buf = [0; 256]; + let n = output.read(&mut buf).unwrap_or(0); + if n == 0 { + break; + } + f.write_all(&buf[..n]).expect("BUGBUG"); + f.flush().expect("BUGBUG"); } - f.write_all(&buf[..n]).expect("BUGBUG"); - f.flush().expect("BUGBUG"); }) .unwrap(); } diff --git a/openvmm/openvmm_entry/src/storage_builder.rs b/openvmm/openvmm_entry/src/storage_builder.rs index ba6398339e..130ea03e6f 100644 --- a/openvmm/openvmm_entry/src/storage_builder.rs +++ b/openvmm/openvmm_entry/src/storage_builder.rs @@ -3,10 +3,10 @@ //! Code to build storage configuration from command line arguments. +use crate::VmResources; use crate::cli_args::DiskCliKind; use crate::cli_args::UnderhillDiskSource; use crate::disk_open; -use crate::VmResources; use anyhow::Context; use guid::Guid; use hvlite_defs::config::Config; @@ -24,9 +24,9 @@ use storvsp_resources::ScsiControllerHandle; use storvsp_resources::ScsiDeviceAndPath; use storvsp_resources::ScsiPath; use vm_resource::IntoResource; -use vtl2_settings_proto::storage_controller; use vtl2_settings_proto::Lun; use vtl2_settings_proto::StorageController; +use vtl2_settings_proto::storage_controller; pub(super) struct StorageBuilder { vtl0_ide_disks: Vec, diff --git a/openvmm/openvmm_entry/src/tracing_init.rs b/openvmm/openvmm_entry/src/tracing_init.rs index edb988d669..5e2ba0a44a 100644 --- a/openvmm/openvmm_entry/src/tracing_init.rs +++ b/openvmm/openvmm_entry/src/tracing_init.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use anyhow::anyhow; use anyhow::Context as _; +use anyhow::anyhow; use std::io::IsTerminal; use tracing_subscriber::fmt::format::FmtSpan; use tracing_subscriber::fmt::format::Format; diff --git a/openvmm/openvmm_entry/src/ttrpc/mod.rs b/openvmm/openvmm_entry/src/ttrpc/mod.rs index 04a979e305..f582da6232 100644 --- a/openvmm/openvmm_entry/src/ttrpc/mod.rs +++ b/openvmm/openvmm_entry/src/ttrpc/mod.rs @@ -4,11 +4,11 @@ //! Worker for the prototype gRPC/ttrpc management endpoint. use self::vmservice::nic_config::Backend; -use crate::serial_io::bind_serial; use crate::DEFAULT_MMIO_GAPS; +use crate::serial_io::bind_serial; +use anyhow::Context; use anyhow::anyhow; use anyhow::bail; -use anyhow::Context; use awaitgroup::WaitGroup; use futures::FutureExt; use futures::StreamExt; @@ -23,8 +23,8 @@ use hvlite_defs::config::VirtioBus; use hvlite_defs::config::VmbusConfig; use hvlite_defs::config::VpciDeviceConfig; use hvlite_defs::rpc::VmRpc; -use hvlite_defs::worker::VmWorkerParameters; use hvlite_defs::worker::VM_WORKER; +use hvlite_defs::worker::VmWorkerParameters; use hvlite_helpers::disk::open_disk_type; use hvlite_ttrpc_vmservice as vmservice; use inspect::Inspect; @@ -32,10 +32,10 @@ use inspect::InspectionBuilder; use inspect_proto::InspectResponse2; use inspect_proto::InspectService; use inspect_proto::UpdateResponse2; -use mesh::error::RemoteError; -use mesh::rpc::RpcSend; use mesh::CancelReason; use mesh::MeshPayload; +use mesh::error::RemoteError; +use mesh::rpc::RpcSend; use mesh_rpc::service::Code; use mesh_rpc::service::Status; use mesh_worker::RegisteredWorkers; @@ -43,13 +43,12 @@ use mesh_worker::Worker; use mesh_worker::WorkerId; use mesh_worker::WorkerRpc; use netvsp_resources::NetvspHandle; -use pal_async::task::Spawn; use pal_async::DefaultDriver; use pal_async::DefaultPool; +use pal_async::task::Spawn; use parking_lot::Mutex; use scsidisk_resources::SimpleScsiDiskHandle; use std::fs::File; -use std::future::Future; use std::sync::Arc; use std::time::Duration; use storvsp_resources::ScsiControllerHandle; @@ -58,9 +57,9 @@ use storvsp_resources::ScsiDeviceAndPath; use unix_socket::UnixListener; use virtio_resources::VirtioPciDeviceHandle; use vm_manifest_builder::VmManifestBuilder; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::IntoResource; use vm_resource::Resource; +use vm_resource::kind::VmbusDeviceHandleKind; use vmm_core_defs::HaltReason; #[derive(mesh::MeshPayload)] diff --git a/petri/pipette/src/agent.rs b/petri/pipette/src/agent.rs index 14b5481121..388438b24e 100644 --- a/petri/pipette/src/agent.rs +++ b/petri/pipette/src/agent.rs @@ -9,10 +9,10 @@ use anyhow::Context; use futures::future::FutureExt; use futures_concurrency::future::RaceOk; use mesh_remote::PointToPointMesh; +use pal_async::DefaultDriver; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; use pal_async::timer::PolledTimer; -use pal_async::DefaultDriver; use pipette_protocol::DiagnosticFile; use pipette_protocol::PipetteBootstrap; use pipette_protocol::PipetteRequest; diff --git a/petri/pipette_client/src/lib.rs b/petri/pipette_client/src/lib.rs index 2ca6c9fa2a..b29b4387e3 100644 --- a/petri/pipette_client/src/lib.rs +++ b/petri/pipette_client/src/lib.rs @@ -13,13 +13,13 @@ pub use pipette_protocol::PIPETTE_VSOCK_PORT; use crate::send::PipetteSender; use anyhow::Context; -use futures::io::BufReader; use futures::AsyncBufReadExt; use futures::AsyncRead; use futures::AsyncWrite; use futures::AsyncWriteExt; use futures::StreamExt; use futures::TryFutureExt; +use futures::io::BufReader; use futures_concurrency::future::TryJoin; use mesh::rpc::RpcError; use mesh_remote::PointToPointMesh; diff --git a/petri/pipette_client/src/process.rs b/petri/pipette_client/src/process.rs index 83344c9ae5..e585cba642 100644 --- a/petri/pipette_client/src/process.rs +++ b/petri/pipette_client/src/process.rs @@ -5,9 +5,9 @@ use crate::PipetteClient; use anyhow::Context; +use futures::AsyncReadExt; use futures::executor::block_on; use futures::io::AllowStdIo; -use futures::AsyncReadExt; use futures_concurrency::future::Join; use mesh::pipe::ReadPipe; use mesh::pipe::WritePipe; diff --git a/petri/pipette_client/src/send.rs b/petri/pipette_client/src/send.rs index e5b08af616..c614dc4c61 100644 --- a/petri/pipette_client/src/send.rs +++ b/petri/pipette_client/src/send.rs @@ -4,10 +4,10 @@ //! A thin wrapper around a `mesh::Sender` that provides //! useful error handling semantics. +use mesh::CancelContext; use mesh::rpc::Rpc; use mesh::rpc::RpcError; use mesh::rpc::RpcSend; -use mesh::CancelContext; use pipette_protocol::PipetteRequest; use std::time::Duration; @@ -28,7 +28,9 @@ impl PipetteSender { { let result = self.0.call(f, input).await; if result.is_err() { - tracing::warn!("Pipette request channel failed, sleeping for 5 seconds to let outstanding work finish"); + tracing::warn!( + "Pipette request channel failed, sleeping for 5 seconds to let outstanding work finish" + ); let mut c = CancelContext::new().with_timeout(Duration::from_secs(5)); let _ = c.cancelled().await; } @@ -46,7 +48,9 @@ impl PipetteSender { { let result = self.0.call_failable(f, input).await; if result.is_err() { - tracing::warn!("Pipette request channel failed, sleeping for 5 seconds to let outstanding work finish"); + tracing::warn!( + "Pipette request channel failed, sleeping for 5 seconds to let outstanding work finish" + ); let mut c = CancelContext::new().with_timeout(Duration::from_secs(5)); let _ = c.cancelled().await; } diff --git a/petri/pipette_client/src/shell.rs b/petri/pipette_client/src/shell.rs index 979e3840e7..e28e64ddd6 100644 --- a/petri/pipette_client/src/shell.rs +++ b/petri/pipette_client/src/shell.rs @@ -10,10 +10,10 @@ #[doc(hidden)] pub use xshell_macros::__cmd; +use crate::PipetteClient; use crate::process::Command; use crate::process::Output; use crate::process::Stdio; -use crate::PipetteClient; use anyhow::Context; use futures::AsyncWriteExt; use futures_concurrency::future::Join; diff --git a/petri/pipette_protocol/src/lib.rs b/petri/pipette_protocol/src/lib.rs index 76af50ffaa..51f926fa1d 100644 --- a/petri/pipette_protocol/src/lib.rs +++ b/petri/pipette_protocol/src/lib.rs @@ -6,11 +6,11 @@ #![forbid(unsafe_code)] +use mesh::MeshPayload; use mesh::pipe::ReadPipe; use mesh::pipe::WritePipe; use mesh::rpc::FailableRpc; use mesh::rpc::Rpc; -use mesh::MeshPayload; /// The port used for the pipette connection over AF_VSOCK. pub const PIPETTE_VSOCK_PORT: u32 = 0x1337; diff --git a/petri/src/lib.rs b/petri/src/lib.rs index 23bc1a507d..1e0a175ccf 100644 --- a/petri/src/lib.rs +++ b/petri/src/lib.rs @@ -26,12 +26,12 @@ pub use petri_artifacts_core::ResolvedOptionalArtifact; pub use petri_artifacts_core::TestArtifactRequirements; pub use petri_artifacts_core::TestArtifacts; pub use pipette_client as pipette; -pub use test::test_macro_support; -pub use test::test_main; pub use test::PetriTestParams; pub use test::RunTest; pub use test::SimpleTest; pub use test::TestCase; +pub use test::test_macro_support; +pub use test::test_main; pub use tracing::*; pub use vm::*; diff --git a/petri/src/linux_direct_serial_agent.rs b/petri/src/linux_direct_serial_agent.rs index 250f7763a9..ace7a25b46 100644 --- a/petri/src/linux_direct_serial_agent.rs +++ b/petri/src/linux_direct_serial_agent.rs @@ -7,8 +7,7 @@ use pal_async::socket::ReadHalf; use pal_async::socket::WriteHalf; use unix_socket::UnixStream; -const BUSYBOX_INIT: &str = - "/bin/busybox --install /bin && mount none /dev -t devtmpfs && mount none /proc -t proc && mount none /sys -t sysfs"; +const BUSYBOX_INIT: &str = "/bin/busybox --install /bin && mount none /dev -t devtmpfs && mount none /proc -t proc && mount none /sys -t sysfs"; pub(crate) struct LinuxDirectSerialAgent { /// Writer to serial 0, the console we define in our kernel commandline diff --git a/petri/src/test.rs b/petri/src/test.rs index 68a83d4b41..16e0a65833 100644 --- a/petri/src/test.rs +++ b/petri/src/test.rs @@ -12,14 +12,14 @@ pub mod test_macro_support { pub static TESTS: [fn() -> (&'static str, Vec)]; } -use crate::tracing::try_init_tracing; use crate::PetriLogSource; use crate::TestArtifactRequirements; use crate::TestArtifacts; +use crate::tracing::try_init_tracing; use anyhow::Context as _; use petri_artifacts_core::ArtifactResolver; -use std::panic::catch_unwind; use std::panic::AssertUnwindSafe; +use std::panic::catch_unwind; use std::path::Path; use test_macro_support::TESTS; diff --git a/petri/src/tracing.rs b/petri/src/tracing.rs index 7c53a18bbe..2b695b6292 100644 --- a/petri/src/tracing.rs +++ b/petri/src/tracing.rs @@ -4,11 +4,11 @@ use diag_client::kmsg_stream::KmsgStream; use fs_err::File; use fs_err::PathExt; -use futures::io::BufReader; use futures::AsyncBufReadExt; use futures::AsyncRead; use futures::AsyncReadExt; use futures::StreamExt; +use futures::io::BufReader; use jiff::Timestamp; use parking_lot::Mutex; use std::collections::HashMap; @@ -16,11 +16,11 @@ use std::io::Write as _; use std::path::Path; use std::path::PathBuf; use std::sync::Arc; -use tracing::level_filters::LevelFilter; use tracing::Level; +use tracing::level_filters::LevelFilter; use tracing_subscriber::filter::Targets; -use tracing_subscriber::fmt::format::FmtSpan; use tracing_subscriber::fmt::MakeWriter; +use tracing_subscriber::fmt::format::FmtSpan; use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::util::SubscriberInitExt; @@ -288,7 +288,7 @@ impl<'a> MakeWriter<'a> for PetriWriter { fn make_writer(&'a self) -> Self::Writer { LogWriter { - inner: &self.0 .0, + inner: &self.0.0, level: Level::INFO, timestamp: None, } @@ -296,7 +296,7 @@ impl<'a> MakeWriter<'a> for PetriWriter { fn make_writer_for(&'a self, meta: &tracing::Metadata<'_>) -> Self::Writer { LogWriter { - inner: &self.0 .0, + inner: &self.0.0, level: *meta.level(), timestamp: None, } diff --git a/petri/src/vm/hyperv/hvc.rs b/petri/src/vm/hyperv/hvc.rs index 5e48035bd0..e20a27add3 100644 --- a/petri/src/vm/hyperv/hvc.rs +++ b/petri/src/vm/hyperv/hvc.rs @@ -6,8 +6,8 @@ use anyhow::Context; use anyhow::Ok; use guid::Guid; -use pal_async::timer::PolledTimer; use pal_async::DefaultDriver; +use pal_async::timer::PolledTimer; use std::ffi::OsStr; use std::process::Stdio; use std::time::Duration; diff --git a/petri/src/vm/hyperv/mod.rs b/petri/src/vm/hyperv/mod.rs index 943e333026..b4d2bb03f6 100644 --- a/petri/src/vm/hyperv/mod.rs +++ b/petri/src/vm/hyperv/mod.rs @@ -7,22 +7,22 @@ pub mod vm; use vmsocket::VmAddress; use vmsocket::VmSocket; -use crate::disk_image::AgentImage; -use crate::openhcl_diag::OpenHclDiagHandler; use crate::Firmware; use crate::IsolationType; use crate::PetriLogSource; use crate::PetriTestParams; use crate::PetriVm; use crate::PetriVmConfig; +use crate::disk_image::AgentImage; +use crate::openhcl_diag::OpenHclDiagHandler; use anyhow::Context; use async_trait::async_trait; +use pal_async::DefaultDriver; use pal_async::pipe::PolledPipe; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; use pal_async::task::Task; use pal_async::timer::PolledTimer; -use pal_async::DefaultDriver; use petri_artifacts_common::tags::MachineArch; use petri_artifacts_common::tags::OsFlavor; use petri_artifacts_core::ArtifactResolver; diff --git a/petri/src/vm/openvmm/construct.rs b/petri/src/vm/openvmm/construct.rs index 4efb3129ac..9e55370021 100644 --- a/petri/src/vm/openvmm/construct.rs +++ b/petri/src/vm/openvmm/construct.rs @@ -4,35 +4,38 @@ //! Contains [`PetriVmConfigOpenVmm::new`], which builds a [`PetriVmConfigOpenVmm`] with all //! default settings for a given [`Firmware`] and [`MachineArch`]. -use super::PetriVmArtifactsOpenVmm; -use super::PetriVmConfigOpenVmm; -use super::PetriVmResourcesOpenVmm; use super::BOOT_NVME_INSTANCE; use super::BOOT_NVME_LUN; use super::BOOT_NVME_NSID; +use super::PetriVmArtifactsOpenVmm; +use super::PetriVmConfigOpenVmm; +use super::PetriVmResourcesOpenVmm; use super::SCSI_INSTANCE; -use crate::linux_direct_serial_agent::LinuxDirectSerialAgent; -use crate::openhcl_diag::OpenHclDiagHandler; use crate::Firmware; use crate::IsolationType; use crate::PcatGuest; use crate::PetriLogSource; use crate::PetriTestParams; -use crate::UefiGuest; use crate::SIZE_1_GB; +use crate::UefiGuest; +use crate::linux_direct_serial_agent::LinuxDirectSerialAgent; +use crate::openhcl_diag::OpenHclDiagHandler; use anyhow::Context; +use disk_backend_resources::LayeredDiskHandle; use disk_backend_resources::layer::DiskLayerHandle; use disk_backend_resources::layer::RamDiskLayerHandle; -use disk_backend_resources::LayeredDiskHandle; +use framebuffer::FRAMEBUFFER_SIZE; use framebuffer::Framebuffer; use framebuffer::FramebufferAccess; -use framebuffer::FRAMEBUFFER_SIZE; use fs_err::File; use futures::StreamExt; use get_resources::crash::GuestCrashDeviceHandle; use get_resources::ged::FirmwareEvent; use guid::Guid; use hvlite_defs::config::Config; +use hvlite_defs::config::DEFAULT_MMIO_GAPS; +use hvlite_defs::config::DEFAULT_MMIO_GAPS_WITH_VTL2; +use hvlite_defs::config::DEFAULT_PCAT_BOOT_ORDER; use hvlite_defs::config::DeviceVtl; use hvlite_defs::config::HypervisorConfig; use hvlite_defs::config::LateMapVtl0MemoryPolicy; @@ -44,9 +47,6 @@ use hvlite_defs::config::VmbusConfig; use hvlite_defs::config::VpciDeviceConfig; use hvlite_defs::config::Vtl2BaseAddressType; use hvlite_defs::config::Vtl2Config; -use hvlite_defs::config::DEFAULT_MMIO_GAPS; -use hvlite_defs::config::DEFAULT_MMIO_GAPS_WITH_VTL2; -use hvlite_defs::config::DEFAULT_PCAT_BOOT_ORDER; use hvlite_helpers::disk::open_disk_type; use hvlite_pcat_locator::RomFileLocation; use hyperv_ic_resources::shutdown::ShutdownIcHandle; @@ -54,10 +54,10 @@ use ide_resources::GuestMedia; use ide_resources::IdeDeviceConfig; use nvme_resources::NamespaceDefinition; use nvme_resources::NvmeControllerHandle; +use pal_async::DefaultDriver; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; use pal_async::task::Task; -use pal_async::DefaultDriver; use petri_artifacts_common::tags::MachineArch; use pipette_client::PIPETTE_VSOCK_PORT; use scsidisk_resources::SimpleScsiDiskHandle; @@ -76,10 +76,10 @@ use unix_socket::UnixListener; use unix_socket::UnixStream; use video_core::SharedFramebufferHandle; use vm_manifest_builder::VmManifestBuilder; -use vm_resource::kind::SerialBackendHandle; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::IntoResource; use vm_resource::Resource; +use vm_resource::kind::SerialBackendHandle; +use vm_resource::kind::VmbusDeviceHandleKind; use vmbus_serial_resources::VmbusSerialDeviceHandle; use vmbus_serial_resources::VmbusSerialPort; use vtl2_settings_proto::Vtl2Settings; diff --git a/petri/src/vm/openvmm/mod.rs b/petri/src/vm/openvmm/mod.rs index 61c4de5484..cdf215a5a7 100644 --- a/petri/src/vm/openvmm/mod.rs +++ b/petri/src/vm/openvmm/mod.rs @@ -15,14 +15,14 @@ mod start; pub use runtime::PetriVmOpenVmm; -use crate::disk_image::AgentImage; -use crate::linux_direct_serial_agent::LinuxDirectSerialAgent; -use crate::openhcl_diag::OpenHclDiagHandler; use crate::Firmware; use crate::PetriLogFile; use crate::PetriLogSource; use crate::PetriVm; use crate::PetriVmConfig; +use crate::disk_image::AgentImage; +use crate::linux_direct_serial_agent::LinuxDirectSerialAgent; +use crate::openhcl_diag::OpenHclDiagHandler; use async_trait::async_trait; use framebuffer::FramebufferAccess; use get_resources::ged::FirmwareEvent; @@ -31,9 +31,9 @@ use hvlite_defs::config::Config; use hyperv_ic_resources::shutdown::ShutdownRpc; use mesh::Receiver; use mesh::Sender; +use pal_async::DefaultDriver; use pal_async::socket::PolledSocket; use pal_async::task::Task; -use pal_async::DefaultDriver; use petri_artifacts_common::tags::MachineArch; use petri_artifacts_common::tags::OsFlavor; use petri_artifacts_core::ArtifactResolver; diff --git a/petri/src/vm/openvmm/modify.rs b/petri/src/vm/openvmm/modify.rs index 2f29ff875d..730c8f7762 100644 --- a/petri/src/vm/openvmm/modify.rs +++ b/petri/src/vm/openvmm/modify.rs @@ -3,8 +3,8 @@ //! Helpers to modify a [`PetriVmConfigOpenVmm`] from its defaults. -use super::PetriVmConfigOpenVmm; use super::MANA_INSTANCE; +use super::PetriVmConfigOpenVmm; use chipset_resources::battery::BatteryDeviceHandleX64; use chipset_resources::battery::HostBatteryUpdate; use fs_err::File; diff --git a/petri/src/vm/openvmm/runtime.rs b/petri/src/vm/openvmm/runtime.rs index b50b1c8773..2be59aba25 100644 --- a/petri/src/vm/openvmm/runtime.rs +++ b/petri/src/vm/openvmm/runtime.rs @@ -4,31 +4,30 @@ //! Methods to interact with a running [`PetriVmOpenVmm`]. use super::PetriVmResourcesOpenVmm; -use crate::openhcl_diag::OpenHclDiagHandler; -use crate::worker::Worker; use crate::OpenHclServicingFlags; use crate::PetriVm; use crate::ShutdownKind; +use crate::openhcl_diag::OpenHclDiagHandler; +use crate::worker::Worker; use anyhow::Context; use async_trait::async_trait; use futures::FutureExt; use futures_concurrency::future::Race; use hvlite_defs::rpc::PulseSaveRestoreError; use hyperv_ic_resources::shutdown::ShutdownRpc; -use mesh::rpc::RpcError; -use mesh::rpc::RpcSend; use mesh::CancelContext; use mesh::Receiver; use mesh::RecvError; +use mesh::rpc::RpcError; +use mesh::rpc::RpcSend; use mesh_process::Mesh; +use pal_async::DefaultDriver; use pal_async::socket::PolledSocket; use pal_async::task::Task; use pal_async::timer::PolledTimer; -use pal_async::DefaultDriver; use petri_artifacts_common::tags::GuestQuirks; use petri_artifacts_core::ResolvedArtifact; use pipette_client::PipetteClient; -use std::future::Future; use std::path::Path; use std::sync::Arc; use std::time::Duration; @@ -251,13 +250,19 @@ impl PetriVmOpenVmm { match res { Either::Future(Ok(success)) => Ok(success), Either::Future(Err(e)) => { - tracing::warn!(?e, "Future returned with an error, sleeping for 5 seconds to let outstanding work finish"); + tracing::warn!( + ?e, + "Future returned with an error, sleeping for 5 seconds to let outstanding work finish" + ); let mut c = CancelContext::new().with_timeout(Duration::from_secs(5)); c.cancelled().await; Err(e) } Either::Halt(halt_result) => { - tracing::warn!(?halt_result, "Halt channel returned while waiting for other future, sleeping for 5 seconds to let outstanding work finish"); + tracing::warn!( + ?halt_result, + "Halt channel returned while waiting for other future, sleeping for 5 seconds to let outstanding work finish" + ); let mut c = CancelContext::new().with_timeout(Duration::from_secs(5)); let try_again = c.until_cancelled(future).await; @@ -265,7 +270,10 @@ impl PetriVmOpenVmm { Ok(fut_result) => { halt.already_received = Some(halt_result); if let Err(e) = &fut_result { - tracing::warn!(?e, "Future returned with an error, sleeping for 5 seconds to let outstanding work finish"); + tracing::warn!( + ?e, + "Future returned with an error, sleeping for 5 seconds to let outstanding work finish" + ); let mut c = CancelContext::new().with_timeout(Duration::from_secs(5)); c.cancelled().await; } diff --git a/petri/src/vm/openvmm/start.rs b/petri/src/vm/openvmm/start.rs index 61c1b8c475..dafcf37b25 100644 --- a/petri/src/vm/openvmm/start.rs +++ b/petri/src/vm/openvmm/start.rs @@ -6,10 +6,10 @@ use super::PetriVmConfigOpenVmm; use super::PetriVmOpenVmm; use super::PetriVmResourcesOpenVmm; -use crate::worker::Worker; use crate::Firmware; use crate::PetriLogFile; use crate::PetriLogSource; +use crate::worker::Worker; use anyhow::Context; use diag_client::DiagClient; use disk_backend_resources::FileDiskHandle; @@ -20,11 +20,11 @@ use image::ColorType; use mesh_process::Mesh; use mesh_process::ProcessConfig; use mesh_worker::WorkerHost; +use pal_async::DefaultDriver; use pal_async::pipe::PolledPipe; use pal_async::task::Spawn; use pal_async::task::Task; use pal_async::timer::PolledTimer; -use pal_async::DefaultDriver; use petri_artifacts_common::tags::MachineArch; use petri_artifacts_common::tags::OsFlavor; use pipette_client::PipetteClient; diff --git a/petri/src/worker.rs b/petri/src/worker.rs index ccc70811a1..a3a479f630 100644 --- a/petri/src/worker.rs +++ b/petri/src/worker.rs @@ -6,8 +6,8 @@ use get_resources::ged::GuestServicingFlags; use hvlite_defs::config::Config; use hvlite_defs::rpc::PulseSaveRestoreError; use hvlite_defs::rpc::VmRpc; -use hvlite_defs::worker::VmWorkerParameters; use hvlite_defs::worker::VM_WORKER; +use hvlite_defs::worker::VmWorkerParameters; use mesh::rpc::RpcError; use mesh::rpc::RpcSend; use mesh_worker::WorkerHandle; diff --git a/rustfmt.toml b/rustfmt.toml index 5f6defd3c1..bf0ec9fe68 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -3,4 +3,4 @@ newline_style="unix" use_field_init_shorthand=true -edition="2021" +edition="2024" diff --git a/support/arc_cyclic_builder/src/lib.rs b/support/arc_cyclic_builder/src/lib.rs index 7b76adf8a1..9393cc646c 100644 --- a/support/arc_cyclic_builder/src/lib.rs +++ b/support/arc_cyclic_builder/src/lib.rs @@ -69,10 +69,10 @@ use std::mem; use std::ptr; use std::ptr::NonNull; -use std::sync::atomic; -use std::sync::atomic::Ordering::*; use std::sync::Arc; use std::sync::Weak; +use std::sync::atomic; +use std::sync::atomic::Ordering::*; // Matches the definition of `ArcInner` in the `std` // diff --git a/support/clap_dyn_complete/src/lib.rs b/support/clap_dyn_complete/src/lib.rs index 6f03c02d3f..fe10da229f 100644 --- a/support/clap_dyn_complete/src/lib.rs +++ b/support/clap_dyn_complete/src/lib.rs @@ -286,7 +286,7 @@ pub trait CustomCompleterFactory: Send + Sync { type CustomCompleter: CustomCompleter + 'static; /// Build a new [`CustomCompleter`]. - fn build(&self, ctx: &RootCtx<'_>) -> impl std::future::Future; + fn build(&self, ctx: &RootCtx<'_>) -> impl Future; } /// A custom completer for a particular argument. @@ -297,7 +297,7 @@ pub trait CustomCompleter: Send + Sync { ctx: &RootCtx<'_>, subcommand_path: &[&str], arg_id: &str, - ) -> impl Send + std::future::Future>; + ) -> impl Send + Future>; } #[async_trait::async_trait] diff --git a/support/console_relay/src/lib.rs b/support/console_relay/src/lib.rs index 928f1a0a9b..79e570f1d7 100644 --- a/support/console_relay/src/lib.rs +++ b/support/console_relay/src/lib.rs @@ -7,12 +7,12 @@ mod unix; mod windows; use anyhow::Context as _; -use futures::executor::block_on; -use futures::io::AllowStdIo; -use futures::io::AsyncReadExt; use futures::AsyncRead; use futures::AsyncWrite; use futures::AsyncWriteExt; +use futures::executor::block_on; +use futures::io::AllowStdIo; +use futures::io::AsyncReadExt; use pal_async::driver::Driver; use pal_async::local::block_with_io; use std::borrow::Cow; diff --git a/support/console_relay/src/unix.rs b/support/console_relay/src/unix.rs index 4422c16696..015d9fba43 100644 --- a/support/console_relay/src/unix.rs +++ b/support/console_relay/src/unix.rs @@ -11,8 +11,8 @@ use pal_async::driver::Driver; use pal_async::socket::PolledSocket; use std::path::Path; use std::pin::Pin; -use std::task::ready; use std::task::Context; +use std::task::ready; use unix_socket::UnixListener; use unix_socket::UnixStream; diff --git a/support/fast_select/src/lib.rs b/support/fast_select/src/lib.rs index d0b904b55f..5cc1d90b4a 100644 --- a/support/fast_select/src/lib.rs +++ b/support/fast_select/src/lib.rs @@ -19,15 +19,14 @@ #![expect(unsafe_code)] use parking_lot::Mutex; -use std::future::Future; use std::marker::PhantomData; use std::mem::ManuallyDrop; use std::ops::Deref; -use std::pin::pin; use std::pin::Pin; +use std::pin::pin; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; -use std::sync::Arc; use std::task::Context; use std::task::Poll; use std::task::RawWaker; @@ -366,9 +365,9 @@ impl Deref for WakerRef<'_> { #[cfg(test)] mod tests { use crate::FastSelect; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::timer::PolledTimer; - use pal_async::DefaultDriver; use std::future::pending; use std::time::Duration; diff --git a/support/fdt/src/parser.rs b/support/fdt/src/parser.rs index 1cfda548dc..914fbe48da 100644 --- a/support/fdt/src/parser.rs +++ b/support/fdt/src/parser.rs @@ -580,7 +580,7 @@ impl<'a> PropertyIter<'a> { return Err(ErrorKind::PropertyToken { node_name: self.node_name, token: token.raw(), - }) + }); } }; diff --git a/support/guid/src/lib.rs b/support/guid/src/lib.rs index 4401ecff4c..40adc7ee23 100644 --- a/support/guid/src/lib.rs +++ b/support/guid/src/lib.rs @@ -309,8 +309,8 @@ mod windows { #[cfg(test)] mod tests { - use super::guid; use super::Guid; + use super::guid; #[test] fn test_display_guid() { diff --git a/support/headervec/src/lib.rs b/support/headervec/src/lib.rs index 9be667e9d5..5fbfa2d435 100644 --- a/support/headervec/src/lib.rs +++ b/support/headervec/src/lib.rs @@ -12,9 +12,9 @@ extern crate alloc; +use alloc::alloc::Layout; use alloc::alloc::alloc; use alloc::alloc::handle_alloc_error; -use alloc::alloc::Layout; use alloc::boxed::Box; use core::cmp; use core::mem::MaybeUninit; diff --git a/support/inspect/src/initiate.rs b/support/inspect/src/initiate.rs index 5c39f97ff7..dac1ee400a 100644 --- a/support/inspect/src/initiate.rs +++ b/support/inspect/src/initiate.rs @@ -22,7 +22,6 @@ use core::cmp::Ordering; use core::fmt; use core::fmt::Write; use core::future::poll_fn; -use core::future::Future; use core::pin::Pin; use core::task::Context; use core::task::Poll; diff --git a/support/inspect/src/lib.rs b/support/inspect/src/lib.rs index ee814b71fb..71ad934013 100644 --- a/support/inspect/src/lib.rs +++ b/support/inspect/src/lib.rs @@ -1626,7 +1626,7 @@ where for<'a> AsHex<&'a T>: Inspect, { fn inspect(&self, req: Request<'_>) { - Inspect::inspect(&AsHex(&self.0 .0), req) + Inspect::inspect(&AsHex(&self.0.0), req) } } @@ -2157,10 +2157,6 @@ where #[cfg(all(test, feature = "derive", feature = "initiate"))] mod tests { - use crate::adhoc; - use crate::adhoc_mut; - use crate::inspect; - use crate::update; use crate::AsBytes; use crate::AtomicMut; use crate::Error; @@ -2171,19 +2167,23 @@ mod tests { use crate::Request; use crate::SensitivityLevel; use crate::ValueKind; + use crate::adhoc; + use crate::adhoc_mut; + use crate::inspect; + use crate::update; use alloc::boxed::Box; use alloc::string::String; use alloc::string::ToString; use alloc::vec; use alloc::vec::Vec; use core::time::Duration; - use expect_test::expect; use expect_test::Expect; + use expect_test::expect; use futures::FutureExt; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::timer::Instant; use pal_async::timer::PolledTimer; - use pal_async::DefaultDriver; fn expected_node(node: Node, expect: Expect) -> Node { expect.assert_eq(&node.to_string()); diff --git a/support/inspect_derive/src/lib.rs b/support/inspect_derive/src/lib.rs index 5baeb56595..3c768ebfc8 100644 --- a/support/inspect_derive/src/lib.rs +++ b/support/inspect_derive/src/lib.rs @@ -7,9 +7,17 @@ use heck::ToSnakeCase; use proc_macro2::Ident; use proc_macro2::Span; use proc_macro2::TokenStream; +use quote::ToTokens; use quote::quote; use quote::quote_spanned; -use quote::ToTokens; +use syn::Attribute; +use syn::DataEnum; +use syn::DataStruct; +use syn::DeriveInput; +use syn::LitStr; +use syn::Token; +use syn::Type; +use syn::WherePredicate; use syn::ext::IdentExt; use syn::parse::Parse; use syn::parse::ParseStream; @@ -19,14 +27,6 @@ use syn::parse_quote_spanned; use syn::punctuated::Punctuated; use syn::spanned::Spanned; use syn::token::Comma; -use syn::Attribute; -use syn::DataEnum; -use syn::DataStruct; -use syn::DeriveInput; -use syn::LitStr; -use syn::Token; -use syn::Type; -use syn::WherePredicate; // Documented in the inspect crate. #[proc_macro_derive(Inspect, attributes(inspect))] @@ -581,7 +581,7 @@ fn field_response( return Err(syn::Error::new( field.span(), "type attribute incompatible with `mut` attribute", - )) + )); } } } diff --git a/support/loan_cell/src/lib.rs b/support/loan_cell/src/lib.rs index b5eaf42818..edde9fafbe 100644 --- a/support/loan_cell/src/lib.rs +++ b/support/loan_cell/src/lib.rs @@ -76,7 +76,7 @@ impl LoanCell { struct RestoreOnDrop<'a, T: ?Sized>(&'a LoanCell, Option>); impl Drop for RestoreOnDrop<'_, T> { fn drop(&mut self) { - self.0 .0.set(self.1); + self.0.0.set(self.1); } } diff --git a/support/mesh/mesh_channel/benches/channel.rs b/support/mesh/mesh_channel/benches/channel.rs index ff697850a0..b407c2fb61 100644 --- a/support/mesh/mesh_channel/benches/channel.rs +++ b/support/mesh/mesh_channel/benches/channel.rs @@ -3,10 +3,10 @@ #![expect(missing_docs)] +use criterion::Criterion; use criterion::async_executor::FuturesExecutor; use criterion::criterion_group; use criterion::criterion_main; -use criterion::Criterion; use mesh_channel::OneshotSender; use mesh_channel::Sender; use mesh_node::local_node::Port; diff --git a/support/mesh/mesh_channel/src/bidir.rs b/support/mesh/mesh_channel/src/bidir.rs index 5f9416a7c2..c28de9ea9e 100644 --- a/support/mesh/mesh_channel/src/bidir.rs +++ b/support/mesh/mesh_channel/src/bidir.rs @@ -3,15 +3,15 @@ //! A bidirectional channel implemented on top of [`Port`]. +use super::RecvError; +use super::TryRecvError; +use super::lazy::DeserializeFn; +use super::lazy::LazyMessage; +use super::lazy::SerializeFn; use super::lazy::deserializer; use super::lazy::ensure_serializable; use super::lazy::lazy_parse; use super::lazy::serializer; -use super::lazy::DeserializeFn; -use super::lazy::LazyMessage; -use super::lazy::SerializeFn; -use super::RecvError; -use super::TryRecvError; use mesh_node::local_node::HandleMessageError; use mesh_node::local_node::HandlePortEvent; use mesh_node::local_node::NodeError; @@ -28,7 +28,6 @@ use std::collections::VecDeque; use std::fmt; use std::fmt::Debug; use std::future::poll_fn; -use std::future::Future; use std::task::Context; use std::task::Poll; use std::task::Waker; diff --git a/support/mesh/mesh_channel/src/cancel.rs b/support/mesh/mesh_channel/src/cancel.rs index 5dff3d5c18..5e60d3110f 100644 --- a/support/mesh/mesh_channel/src/cancel.rs +++ b/support/mesh/mesh_channel/src/cancel.rs @@ -8,13 +8,12 @@ use super::deadline::DeadlineId; use super::deadline::DeadlineSet; use mesh_node::local_node::Port; use mesh_node::resource::Resource; -use mesh_protobuf::encoding::IgnoreField; use mesh_protobuf::EncodeAs; use mesh_protobuf::Protobuf; use mesh_protobuf::SerializedMessage; use mesh_protobuf::Timestamp; +use mesh_protobuf::encoding::IgnoreField; use parking_lot::Mutex; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::sync::Weak; diff --git a/support/mesh/mesh_channel/src/cell.rs b/support/mesh/mesh_channel/src/cell.rs index b4a388655e..8a1cc7afcc 100644 --- a/support/mesh/mesh_channel/src/cell.rs +++ b/support/mesh/mesh_channel/src/cell.rs @@ -19,7 +19,6 @@ use mesh_protobuf::EncodeAs; use mesh_protobuf::Protobuf; use mesh_protobuf::SerializedMessage; use std::future::poll_fn; -use std::future::Future; use std::task::Context; use std::task::Poll; use std::task::Waker; @@ -160,11 +159,7 @@ impl CellUpdater { } } } - if wait { - Poll::Pending - } else { - Poll::Ready(()) - } + if wait { Poll::Pending } else { Poll::Ready(()) } }) } } @@ -329,9 +324,9 @@ impl From> for Inne #[cfg(test)] mod tests { use super::CellUpdater; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::task::Spawn; - use pal_async::DefaultDriver; use std::future::poll_fn; use std::task::Poll; diff --git a/support/mesh/mesh_channel/src/lazy.rs b/support/mesh/mesh_channel/src/lazy.rs index 0e029b6fa2..41814401f3 100644 --- a/support/mesh/mesh_channel/src/lazy.rs +++ b/support/mesh/mesh_channel/src/lazy.rs @@ -41,10 +41,10 @@ use mesh_node::message::MeshPayload; use mesh_node::message::SerializeMessage; use mesh_node::resource::Resource; use mesh_node::resource::SerializedMessage; +use mesh_protobuf::MessageEncode; use mesh_protobuf::encoding::SerializedMessageEncoder; use mesh_protobuf::protobuf::MessageSizer; use mesh_protobuf::protobuf::MessageWriter; -use mesh_protobuf::MessageEncode; use parking_lot::RwLock; use std::any::TypeId; use std::collections::HashMap; diff --git a/support/mesh/mesh_channel/src/lib.rs b/support/mesh/mesh_channel/src/lib.rs index 8ec0bb178e..8fd86d5cd2 100644 --- a/support/mesh/mesh_channel/src/lib.rs +++ b/support/mesh/mesh_channel/src/lib.rs @@ -108,22 +108,21 @@ mod error_oldchan { #[cfg(feature = "newchan_spsc")] mod spsc_newchan { - pub use mesh_channel_core::channel; pub use mesh_channel_core::Receiver; pub use mesh_channel_core::Sender; + pub use mesh_channel_core::channel; } #[cfg(not(feature = "newchan_spsc"))] mod spsc { - use crate::bidir::Channel; use crate::RecvError; use crate::TryRecvError; + use crate::bidir::Channel; use mesh_node::local_node::Port; use mesh_node::local_node::PortField; use mesh_node::message::MeshField; use mesh_protobuf::DefaultEncoding; use std::fmt::Debug; - use std::future::Future; use std::pin::Pin; use std::task::Context; use std::task::Poll; @@ -336,14 +335,13 @@ mod spsc { #[cfg(not(feature = "newchan_oneshot"))] mod oneshot { - use crate::bidir::Channel; use crate::RecvError; + use crate::bidir::Channel; use mesh_node::local_node::Port; use mesh_node::local_node::PortField; use mesh_node::message::MeshField; use mesh_protobuf::DefaultEncoding; use std::fmt::Debug; - use std::future::Future; use std::pin::Pin; use std::task::Context; use std::task::Poll; @@ -450,26 +448,25 @@ mod oneshot { #[cfg(feature = "newchan_oneshot")] mod oneshot_newchan { - pub use mesh_channel_core::oneshot; pub use mesh_channel_core::OneshotReceiver; pub use mesh_channel_core::OneshotSender; + pub use mesh_channel_core::oneshot; } #[cfg(feature = "newchan_mpsc")] mod mpsc_newchan { - pub use mesh_channel_core::channel as mpsc_channel; pub use mesh_channel_core::Receiver as MpscReceiver; pub use mesh_channel_core::Sender as MpscSender; + pub use mesh_channel_core::channel as mpsc_channel; } #[cfg(not(feature = "newchan_mpsc"))] mod mpsc { - use crate::bidir::Channel; use crate::RecvError; + use crate::bidir::Channel; use mesh_node::message::MeshField; use mesh_protobuf::Protobuf; use std::fmt::Debug; - use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::Context; @@ -631,7 +628,7 @@ mod mpsc { impl Debug for MpscSender { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - Debug::fmt(&self.0 .0, f) + Debug::fmt(&self.0.0, f) } } diff --git a/support/mesh/mesh_channel/src/pipe.rs b/support/mesh/mesh_channel/src/pipe.rs index d1e8372c89..0ab4164b13 100644 --- a/support/mesh/mesh_channel/src/pipe.rs +++ b/support/mesh/mesh_channel/src/pipe.rs @@ -16,8 +16,8 @@ use mesh_node::local_node::PortWithHandler; use mesh_node::message::Message; use mesh_node::message::OwnedMessage; use mesh_node::resource::Resource; -use mesh_protobuf::encoding::OptionField; use mesh_protobuf::Protobuf; +use mesh_protobuf::encoding::OptionField; use std::collections::VecDeque; use std::io; use std::pin::Pin; @@ -322,12 +322,12 @@ mod encoding { use super::ReadPipeState; use mesh_node::local_node::Port; use mesh_node::resource::Resource; - use mesh_protobuf::encoding::MessageEncoding; - use mesh_protobuf::inplace_none; use mesh_protobuf::DefaultEncoding; use mesh_protobuf::MessageDecode; use mesh_protobuf::MessageEncode; use mesh_protobuf::Protobuf; + use mesh_protobuf::encoding::MessageEncoding; + use mesh_protobuf::inplace_none; use std::collections::VecDeque; pub struct ReadPipeEncoder; diff --git a/support/mesh/mesh_channel/src/rpc.rs b/support/mesh/mesh_channel/src/rpc.rs index 1d8587fb7c..988ae494e8 100644 --- a/support/mesh/mesh_channel/src/rpc.rs +++ b/support/mesh/mesh_channel/src/rpc.rs @@ -4,19 +4,18 @@ //! Remote Procedure Call functionality. use super::error::RemoteResult; -use crate::error::RemoteError; -use crate::oneshot; use crate::OneshotReceiver; use crate::OneshotSender; use crate::RecvError; +use crate::error::RemoteError; +use crate::oneshot; use mesh_node::message::MeshField; use mesh_protobuf::Protobuf; use std::convert::Infallible; use std::fmt::Debug; -use std::future::Future; use std::pin::Pin; -use std::task::ready; use std::task::Poll; +use std::task::ready; use thiserror::Error; /// An RPC message for a request with input of type `I` and output of type `R`. diff --git a/support/mesh/mesh_channel_core/src/deque.rs b/support/mesh/mesh_channel_core/src/deque.rs index 71d08b5306..04c5592d7c 100644 --- a/support/mesh/mesh_channel_core/src/deque.rs +++ b/support/mesh/mesh_channel_core/src/deque.rs @@ -9,8 +9,8 @@ use core::fmt; use std::alloc::Layout; use std::marker::PhantomData; -use std::ptr::drop_in_place; use std::ptr::NonNull; +use std::ptr::drop_in_place; /// A type-erased vector-based queue. /// diff --git a/support/mesh/mesh_channel_core/src/mpsc.rs b/support/mesh/mesh_channel_core/src/mpsc.rs index 9c6b61167d..1a8c34016f 100644 --- a/support/mesh/mesh_channel_core/src/mpsc.rs +++ b/support/mesh/mesh_channel_core/src/mpsc.rs @@ -29,7 +29,6 @@ use crate::error::RecvError; use crate::error::TryRecvError; use crate::sync_unsafe_cell::SyncUnsafeCell; use core::fmt::Debug; -use core::future::Future; use core::marker::PhantomData; use core::mem::ManuallyDrop; use core::mem::MaybeUninit; @@ -909,12 +908,12 @@ impl HandlePortEvent for RemotePortHandler { #[cfg(test)] mod tests { - use super::channel; use super::Receiver; use super::Sender; + use super::channel; use crate::RecvError; - use futures::executor::block_on; use futures::StreamExt; + use futures::executor::block_on; use futures_core::FusedStream; use mesh_node::local_node::Port; use mesh_protobuf::Protobuf; diff --git a/support/mesh/mesh_channel_core/src/oneshot.rs b/support/mesh/mesh_channel_core/src/oneshot.rs index 280a14ac86..2dd9bbe50e 100644 --- a/support/mesh/mesh_channel_core/src/oneshot.rs +++ b/support/mesh/mesh_channel_core/src/oneshot.rs @@ -17,9 +17,9 @@ // UNSAFETY: needed to avoid monomorphization. #![expect(unsafe_code)] -use crate::sync_unsafe_cell::SyncUnsafeCell; use crate::ChannelError; use crate::RecvError; +use crate::sync_unsafe_cell::SyncUnsafeCell; use mesh_node::local_node::HandleMessageError; use mesh_node::local_node::HandlePortEvent; use mesh_node::local_node::Port; @@ -31,15 +31,14 @@ use mesh_node::message::OwnedMessage; use mesh_protobuf::DefaultEncoding; use parking_lot::Mutex; use std::fmt::Debug; -use std::future::Future; use std::marker::PhantomData; use std::mem::ManuallyDrop; use std::ptr::NonNull; use std::sync::Arc; -use std::task::ready; use std::task::Context; use std::task::Poll; use std::task::Waker; +use std::task::ready; use thiserror::Error; /// Creates a unidirection channel for sending a single value of type `T`. @@ -624,9 +623,9 @@ mod tests { use crate::OneshotReceiver; use crate::OneshotSender; use crate::RecvError; + use futures::FutureExt; use futures::executor::block_on; use futures::task::SpawnExt; - use futures::FutureExt; use mesh_node::local_node::Port; use mesh_node::message::Message; use std::cell::Cell; @@ -697,9 +696,11 @@ mod tests { let (sender, mut receiver) = oneshot::(); let sender = OneshotSender::::from(Port::from(sender)); // Ensure the receiver has seen the sender's port before converting. - assert!(poll_fn(|cx| receiver.poll_recv(cx)) - .now_or_never() - .is_none()); + assert!( + poll_fn(|cx| receiver.poll_recv(cx)) + .now_or_never() + .is_none() + ); let receiver = OneshotReceiver::::from(Port::from(receiver)); sender.send(String::from("foo")); assert_eq!(receiver.await.unwrap(), "foo"); diff --git a/support/mesh/mesh_derive/src/lib.rs b/support/mesh/mesh_derive/src/lib.rs index a4f4a311d6..3a9fd0ba44 100644 --- a/support/mesh/mesh_derive/src/lib.rs +++ b/support/mesh/mesh_derive/src/lib.rs @@ -8,19 +8,11 @@ use heck::ToSnakeCase; use proc_macro2::Span; use proc_macro2::TokenStream; +use quote::ToTokens; use quote::format_ident; use quote::quote; use quote::quote_spanned; -use quote::ToTokens; use std::collections::BTreeSet; -use syn::ext::IdentExt; -use syn::parse::Parse; -use syn::parse::ParseStream; -use syn::parse_macro_input; -use syn::parse_quote; -use syn::parse_quote_spanned; -use syn::punctuated::Punctuated; -use syn::spanned::Spanned; use syn::Attribute; use syn::DataEnum; use syn::DataStruct; @@ -38,6 +30,14 @@ use syn::Path; use syn::Token; use syn::TypePath; use syn::WherePredicate; +use syn::ext::IdentExt; +use syn::parse::Parse; +use syn::parse::ParseStream; +use syn::parse_macro_input; +use syn::parse_quote; +use syn::parse_quote_spanned; +use syn::punctuated::Punctuated; +use syn::spanned::Spanned; /// The derive macro for `MeshPayload`. /// diff --git a/support/mesh/mesh_node/src/common.rs b/support/mesh/mesh_node/src/common.rs index 598b9fe05a..93efda86e5 100644 --- a/support/mesh/mesh_node/src/common.rs +++ b/support/mesh/mesh_node/src/common.rs @@ -57,10 +57,10 @@ mod debug { //! production use, but it simplifies mesh debugging. use super::Uuid; + use std::sync::Once; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; - use std::sync::Once; static CHECK_ONCE: Once = Once::new(); static USE_LINEAR_IDS: AtomicBool = AtomicBool::new(false); diff --git a/support/mesh/mesh_node/src/local_node.rs b/support/mesh/mesh_node/src/local_node.rs index 891da92c03..05d9dde217 100644 --- a/support/mesh/mesh_node/src/local_node.rs +++ b/support/mesh/mesh_node/src/local_node.rs @@ -11,30 +11,30 @@ use crate::message::OwnedMessage; use crate::resource::OsResource; use crate::resource::Resource; use futures_channel::oneshot; -use mesh_protobuf::buffer::write_with; +use mesh_protobuf::DefaultEncoding; use mesh_protobuf::buffer::Buf; use mesh_protobuf::buffer::Buffer; +use mesh_protobuf::buffer::write_with; use mesh_protobuf::protobuf::Encoder; -use mesh_protobuf::DefaultEncoding; use parking_lot::Mutex; use parking_lot::MutexGuard; use parking_lot::RwLock; use std::any::Any; use std::cmp::Reverse; -use std::collections::hash_map; use std::collections::BinaryHeap; use std::collections::HashMap; use std::collections::VecDeque; +use std::collections::hash_map; use std::fmt; use std::fmt::Debug; use std::fmt::Display; use std::marker::PhantomData; use std::num::Wrapping; +use std::sync::Arc; +use std::sync::Weak; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicIsize; use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::sync::Weak; use std::task::Waker; use thiserror::Error; use zerocopy::FromBytes; @@ -2326,15 +2326,14 @@ pub mod tests { use crate::message::MeshField; use crate::resource::SerializedMessage; use futures::stream::Stream; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::task::Spawn; use pal_async::task::Task; - use pal_async::DefaultDriver; use std::future::poll_fn; - use std::future::Future; use std::marker::PhantomData; - use std::pin::pin; use std::pin::Pin; + use std::pin::pin; use std::task::Context; use std::task::Poll; use test_with_tracing::test; diff --git a/support/mesh/mesh_node/src/message.rs b/support/mesh/mesh_node/src/message.rs index 67cb1edae9..8a2ae217ff 100644 --- a/support/mesh/mesh_node/src/message.rs +++ b/support/mesh/mesh_node/src/message.rs @@ -9,15 +9,15 @@ use crate::resource::Resource; use crate::resource::SerializedMessage; use mesh_protobuf; +use mesh_protobuf::DefaultEncoding; +use mesh_protobuf::MessageDecode; +use mesh_protobuf::MessageEncode; use mesh_protobuf::encoding::SerializedMessageEncoder; use mesh_protobuf::inplace; use mesh_protobuf::inplace_none; -use mesh_protobuf::protobuf::decode_with; use mesh_protobuf::protobuf::MessageSizer; use mesh_protobuf::protobuf::MessageWriter; -use mesh_protobuf::DefaultEncoding; -use mesh_protobuf::MessageDecode; -use mesh_protobuf::MessageEncode; +use mesh_protobuf::protobuf::decode_with; use std::any::Any; use std::any::TypeId; use std::borrow::Cow; @@ -445,12 +445,14 @@ impl MessageEncode, Resource> for MessageEncoder { /// in place on the stack. macro_rules! stack_message { ($v:expr) => { - // UNSAFETY: required to call unsafe function. - #[expect(unsafe_code)] - { + (|v| { + // UNSAFETY: required to call unsafe function. + #[expect(unsafe_code)] // SAFETY: The value is initialized and never used again. - unsafe { $crate::message::Message::new_stack(&mut ::core::mem::MaybeUninit::new($v)) } - } + unsafe { + $crate::message::Message::new_stack(v) + } + })(&mut ::core::mem::MaybeUninit::new($v)) }; } pub(crate) use stack_message; diff --git a/support/mesh/mesh_process/src/lib.rs b/support/mesh/mesh_process/src/lib.rs index e74ba4af6b..4a57b58fcf 100644 --- a/support/mesh/mesh_process/src/lib.rs +++ b/support/mesh/mesh_process/src/lib.rs @@ -10,18 +10,18 @@ use anyhow::Context; use base64::Engine; use debug_ptr::DebugPtr; -use futures::executor::block_on; use futures::FutureExt; use futures::StreamExt; +use futures::executor::block_on; use futures_concurrency::future::Race; use inspect::Inspect; use inspect::SensitivityLevel; +use mesh::MeshPayload; +use mesh::OneshotReceiver; use mesh::message::MeshField; use mesh::payload::Protobuf; use mesh::rpc::Rpc; use mesh::rpc::RpcSend; -use mesh::MeshPayload; -use mesh::OneshotReceiver; use mesh_remote::InvitationAddress; #[cfg(unix)] use pal::unix::process::Builder as ProcessBuilder; @@ -29,9 +29,9 @@ use pal::unix::process::Builder as ProcessBuilder; use pal::windows::process; #[cfg(windows)] use pal::windows::process::Builder as ProcessBuilder; +use pal_async::DefaultPool; use pal_async::task::Spawn; use pal_async::task::Task; -use pal_async::DefaultPool; use slab::Slab; use std::borrow::Cow; use std::ffi::OsString; @@ -42,8 +42,8 @@ use std::os::unix::prelude::*; use std::os::windows::prelude::*; use std::path::PathBuf; use std::thread; -use tracing::instrument; use tracing::Instrument; +use tracing::instrument; use unicycle::FuturesUnordered; #[cfg(windows)] @@ -159,8 +159,10 @@ async fn node_from_environment() -> anyhow::Result> { // current edition), either this function and its callers need to become // `unsafe`, or we need to avoid using the environment to propagate the // invitation so that we can avoid this call. - #[expect(deprecated_safe_2024)] - std::env::remove_var(INVITATION_ENV_NAME); + // SAFETY: Not + unsafe { + std::env::remove_var(INVITATION_ENV_NAME); + } let invitation: Invitation = mesh::payload::decode( &base64::engine::general_purpose::STANDARD diff --git a/support/mesh/mesh_protobuf/src/encode_with.rs b/support/mesh/mesh_protobuf/src/encode_with.rs index 4216990baa..6cbe8eb2fa 100644 --- a/support/mesh/mesh_protobuf/src/encode_with.rs +++ b/support/mesh/mesh_protobuf/src/encode_with.rs @@ -4,16 +4,16 @@ //! Helper type for mesh-encoding a type that must first be translated to //! another type. -use super::encoding::MessageEncoding; -use super::fmt; -use super::protobuf::MessageReader; -use super::protobuf::MessageSizer; -use super::protobuf::MessageWriter; use super::DefaultEncoding; use super::InplaceOption; use super::MessageDecode; use super::MessageEncode; use super::Result; +use super::encoding::MessageEncoding; +use super::fmt; +use super::protobuf::MessageReader; +use super::protobuf::MessageSizer; +use super::protobuf::MessageWriter; use crate::inplace; use core::ops::Deref; use core::ops::DerefMut; diff --git a/support/mesh/mesh_protobuf/src/encoding.rs b/support/mesh/mesh_protobuf/src/encoding.rs index 1e645ecb94..a86145fa66 100644 --- a/support/mesh/mesh_protobuf/src/encoding.rs +++ b/support/mesh/mesh_protobuf/src/encoding.rs @@ -5,17 +5,6 @@ pub use super::time::DurationEncoding; -use super::inplace_some; -use super::protobuf::decode_with; -use super::protobuf::FieldReader; -use super::protobuf::FieldSizer; -use super::protobuf::FieldWriter; -use super::protobuf::MessageReader; -use super::protobuf::MessageSizer; -use super::protobuf::MessageWriter; -use super::protobuf::PackedReader; -use super::protobuf::PackedSizer; -use super::protobuf::PackedWriter; use super::CopyExtend; use super::DecodeError; use super::DefaultEncoding; @@ -31,13 +20,24 @@ use super::Result; use super::ResultExt; use super::SerializedMessage; use super::Wrapping; +use super::inplace_some; +use super::protobuf::FieldReader; +use super::protobuf::FieldSizer; +use super::protobuf::FieldWriter; +use super::protobuf::MessageReader; +use super::protobuf::MessageSizer; +use super::protobuf::MessageWriter; +use super::protobuf::PackedReader; +use super::protobuf::PackedSizer; +use super::protobuf::PackedWriter; +use super::protobuf::decode_with; +use crate::Error; use crate::inplace_none; use crate::protobuf::WireType; use crate::protofile::DescribeField; use crate::protofile::DescribeMessage; use crate::protofile::FieldType; use crate::protofile::MessageDescription; -use crate::Error; use alloc::borrow::Cow; use alloc::boxed::Box; use alloc::collections::BTreeMap; @@ -46,15 +46,15 @@ use alloc::sync::Arc; use alloc::vec::Vec; use core::convert::Infallible; use core::marker::PhantomData; +use core::num::NonZeroI8; use core::num::NonZeroI16; use core::num::NonZeroI32; use core::num::NonZeroI64; -use core::num::NonZeroI8; use core::num::NonZeroIsize; +use core::num::NonZeroU8; use core::num::NonZeroU16; use core::num::NonZeroU32; use core::num::NonZeroU64; -use core::num::NonZeroU8; use core::num::NonZeroUsize; use core::time::Duration; use thiserror::Error; diff --git a/support/mesh/mesh_protobuf/src/lib.rs b/support/mesh/mesh_protobuf/src/lib.rs index 862de272ef..ec9c49be30 100644 --- a/support/mesh/mesh_protobuf/src/lib.rs +++ b/support/mesh/mesh_protobuf/src/lib.rs @@ -564,17 +564,17 @@ pub type Result = core::result::Result; mod tests { extern crate std; - use super::encode; use super::SerializedMessage; + use super::encode; + use crate::DecodeError; + use crate::FieldDecode; + use crate::FieldEncode; + use crate::NoResources; use crate::decode; use crate::encoding::BorrowedCowField; use crate::encoding::OwningCowField; use crate::encoding::VecField; use crate::protobuf::read_varint; - use crate::DecodeError; - use crate::FieldDecode; - use crate::FieldEncode; - use crate::NoResources; use alloc::borrow::Cow; use alloc::collections::BTreeMap; use alloc::vec; @@ -583,8 +583,8 @@ mod tests { use core::fmt::Write; use core::num::NonZeroU32; use core::time::Duration; - use expect_test::expect; use expect_test::Expect; + use expect_test::expect; use mesh_derive::Protobuf; use std::prelude::rust_2021::*; use std::println; diff --git a/support/mesh/mesh_protobuf/src/message.rs b/support/mesh/mesh_protobuf/src/message.rs index 915bca2c62..9bc694ac3a 100644 --- a/support/mesh/mesh_protobuf/src/message.rs +++ b/support/mesh/mesh_protobuf/src/message.rs @@ -3,6 +3,12 @@ //! Type-erased protobuf message support. +use crate::DefaultEncoding; +use crate::DescribedProtobuf; +use crate::Error; +use crate::MessageDecode; +use crate::MessageEncode; +use crate::Protobuf; use crate::decode; use crate::encode; use crate::encoding::MessageEncoding; @@ -14,12 +20,6 @@ use crate::protofile::DescribeField; use crate::protofile::FieldType; use crate::protofile::MessageDescription; use crate::table::DescribeTable; -use crate::DefaultEncoding; -use crate::DescribedProtobuf; -use crate::Error; -use crate::MessageDecode; -use crate::MessageEncode; -use crate::Protobuf; use alloc::string::String; use alloc::string::ToString; use alloc::vec::Vec; @@ -135,11 +135,11 @@ impl ProtobufAny { mod tests { extern crate std; + use crate::Protobuf; use crate::encode; use crate::message::ProtobufAny; use crate::message::ProtobufMessage; use crate::tests::as_expect_str; - use crate::Protobuf; use expect_test::expect; use std::println; diff --git a/support/mesh/mesh_protobuf/src/oneof.rs b/support/mesh/mesh_protobuf/src/oneof.rs index a033c913d7..4e8d95986a 100644 --- a/support/mesh/mesh_protobuf/src/oneof.rs +++ b/support/mesh/mesh_protobuf/src/oneof.rs @@ -4,6 +4,13 @@ //! Encoding support for protobuf `oneof` fields, which are derived from Rust //! enums. +use crate::Error; +use crate::FieldDecode; +use crate::FieldEncode; +use crate::MessageDecode; +use crate::MessageEncode; +use crate::Result; +use crate::ResultExt; use crate::inplace::InplaceOption; use crate::protobuf::FieldReader; use crate::protobuf::MessageReader; @@ -13,13 +20,6 @@ use crate::protofile::DescribeField; use crate::protofile::DescribeMessage; use crate::protofile::FieldType; use crate::protofile::MessageDescription; -use crate::Error; -use crate::FieldDecode; -use crate::FieldEncode; -use crate::MessageDecode; -use crate::MessageEncode; -use crate::Result; -use crate::ResultExt; use thiserror::Error; /// An encoder type for `oneof` fields derived from Rust enums. diff --git a/support/mesh/mesh_protobuf/src/prost.rs b/support/mesh/mesh_protobuf/src/prost.rs index f29fd07cba..a5b16fc51a 100644 --- a/support/mesh/mesh_protobuf/src/prost.rs +++ b/support/mesh/mesh_protobuf/src/prost.rs @@ -3,11 +3,11 @@ //! Support for encoding Prost types as Mesh types. -use super::inplace::InplaceOption; -use super::protobuf; use super::MessageDecode; use super::MessageEncode; use super::Result; +use super::inplace::InplaceOption; +use super::protobuf; use crate::Error; use alloc::vec::Vec; diff --git a/support/mesh/mesh_protobuf/src/protobuf.rs b/support/mesh/mesh_protobuf/src/protobuf.rs index 73dd3a8f9e..93a281dd21 100644 --- a/support/mesh/mesh_protobuf/src/protobuf.rs +++ b/support/mesh/mesh_protobuf/src/protobuf.rs @@ -3,15 +3,15 @@ //! Tools to encode and decode protobuf messages. -use super::buffer; -use super::buffer::Buf; -use super::buffer::Buffer; use super::DecodeError; use super::InplaceOption; use super::MessageDecode; use super::MessageEncode; use super::RefCell; use super::Result; +use super::buffer; +use super::buffer::Buf; +use super::buffer::Buffer; use crate::DefaultEncoding; use alloc::vec; use alloc::vec::Vec; diff --git a/support/mesh/mesh_protobuf/src/protofile/mod.rs b/support/mesh/mesh_protobuf/src/protofile/mod.rs index 0679e89666..a9f3a698d1 100644 --- a/support/mesh/mesh_protobuf/src/protofile/mod.rs +++ b/support/mesh/mesh_protobuf/src/protofile/mod.rs @@ -227,11 +227,13 @@ impl<'a> FieldType<'a> { [] => { return Self::external("google.protobuf.Empty", "google/protobuf/empty.proto"); } - &[Self { - kind: FieldKind::Builtin(ty), - sequence_type: None, - annotation, - }] if annotation.is_empty() => { + &[ + Self { + kind: FieldKind::Builtin(ty), + sequence_type: None, + annotation, + }, + ] if annotation.is_empty() => { let wrapper = match ty.as_bytes() { b"double" => Some("google.protobuf.DoubleValue"), b"float" => Some("google.protobuf.FloatValue"), diff --git a/support/mesh/mesh_protobuf/src/protofile/writer.rs b/support/mesh/mesh_protobuf/src/protofile/writer.rs index 9df4c2bce4..243d7d3e4c 100644 --- a/support/mesh/mesh_protobuf/src/protofile/writer.rs +++ b/support/mesh/mesh_protobuf/src/protofile/writer.rs @@ -474,8 +474,8 @@ impl OneofDescriptor<'_> { #[cfg(test)] mod tests { use super::DescriptorWriter; - use crate::protofile::message_description; use crate::Protobuf; + use crate::protofile::message_description; use alloc::string::String; use alloc::vec::Vec; use core::cell::RefCell; diff --git a/support/mesh/mesh_protobuf/src/table/decode.rs b/support/mesh/mesh_protobuf/src/table/decode.rs index 8cea2b6a69..5516d8ebd5 100644 --- a/support/mesh/mesh_protobuf/src/table/decode.rs +++ b/support/mesh/mesh_protobuf/src/table/decode.rs @@ -5,12 +5,12 @@ use super::StructMetadata; use super::TableEncoder; -use crate::inplace::InplaceOption; -use crate::protobuf::FieldReader; -use crate::protobuf::MessageReader; use crate::Error; use crate::FieldDecode; use crate::MessageDecode; +use crate::inplace::InplaceOption; +use crate::protobuf::FieldReader; +use crate::protobuf::MessageReader; use alloc::slice; use alloc::vec; use core::marker::PhantomData; diff --git a/support/mesh/mesh_protobuf/src/table/encode.rs b/support/mesh/mesh_protobuf/src/table/encode.rs index 8d73608227..dbdd4737d3 100644 --- a/support/mesh/mesh_protobuf/src/table/encode.rs +++ b/support/mesh/mesh_protobuf/src/table/encode.rs @@ -5,12 +5,12 @@ use super::StructMetadata; use super::TableEncoder; +use crate::FieldEncode; +use crate::MessageEncode; use crate::protobuf::FieldSizer; use crate::protobuf::FieldWriter; use crate::protobuf::MessageSizer; use crate::protobuf::MessageWriter; -use crate::FieldEncode; -use crate::MessageEncode; use alloc::slice; use core::marker::PhantomData; use core::mem::MaybeUninit; diff --git a/support/mesh/mesh_protobuf/src/table/mod.rs b/support/mesh/mesh_protobuf/src/table/mod.rs index 9365de6d43..c1c6930154 100644 --- a/support/mesh/mesh_protobuf/src/table/mod.rs +++ b/support/mesh/mesh_protobuf/src/table/mod.rs @@ -56,17 +56,17 @@ pub unsafe trait StructMetadata { #[cfg(test)] #[expect(clippy::undocumented_unsafe_blocks)] mod tests { + use super::StructMetadata; + use super::TableEncoder; use super::decode::ErasedDecoderEntry; use super::decode::StructDecodeMetadata; use super::encode::ErasedEncoderEntry; use super::encode::StructEncodeMetadata; - use super::StructMetadata; - use super::TableEncoder; + use crate::FieldDecode; + use crate::FieldEncode; use crate::encoding::StringField; use crate::encoding::VarintField; use crate::tests::as_expect_str; - use crate::FieldDecode; - use crate::FieldEncode; use core::mem::offset_of; use expect_test::expect; diff --git a/support/mesh/mesh_protobuf/src/table/tuple.rs b/support/mesh/mesh_protobuf/src/table/tuple.rs index 257a7feeba..5baa9b52c9 100644 --- a/support/mesh/mesh_protobuf/src/table/tuple.rs +++ b/support/mesh/mesh_protobuf/src/table/tuple.rs @@ -3,19 +3,19 @@ //! Table definitions for tuples. +use super::StructMetadata; +use super::TableEncoder; use super::decode::ErasedDecoderEntry; use super::decode::StructDecodeMetadata; use super::encode::ErasedEncoderEntry; use super::encode::StructEncodeMetadata; -use super::StructMetadata; -use super::TableEncoder; +use crate::DefaultEncoding; +use crate::FieldDecode; +use crate::FieldEncode; use crate::protofile::DescribeField; use crate::protofile::DescribeMessage; use crate::protofile::FieldType; use crate::protofile::MessageDescription; -use crate::DefaultEncoding; -use crate::FieldDecode; -use crate::FieldEncode; impl DescribeMessage<()> for TableEncoder { const DESCRIPTION: MessageDescription<'static> = MessageDescription::External { diff --git a/support/mesh/mesh_protobuf/src/time.rs b/support/mesh/mesh_protobuf/src/time.rs index f0bc1a403f..e7f34bb05d 100644 --- a/support/mesh/mesh_protobuf/src/time.rs +++ b/support/mesh/mesh_protobuf/src/time.rs @@ -3,6 +3,9 @@ //! Time types for mesh protobuf encoding. +use crate::DecodeError; +use crate::MessageDecode; +use crate::MessageEncode; use crate::inplace::InplaceOption; use crate::inplace_some; use crate::protobuf::MessageReader; @@ -13,9 +16,6 @@ use crate::protofile::FieldType; use crate::protofile::MessageDescription; use crate::table::DescribeTable; use crate::table::TableEncoder; -use crate::DecodeError; -use crate::MessageDecode; -use crate::MessageEncode; use core::time::Duration; use mesh_protobuf::Protobuf; use thiserror::Error; diff --git a/support/mesh/mesh_protobuf/src/transparent.rs b/support/mesh/mesh_protobuf/src/transparent.rs index 0019daaee3..5e6b46d270 100644 --- a/support/mesh/mesh_protobuf/src/transparent.rs +++ b/support/mesh/mesh_protobuf/src/transparent.rs @@ -3,6 +3,11 @@ //! Transparent encoding for types that are a wrapper around another type. +use crate::FieldDecode; +use crate::FieldEncode; +use crate::MessageDecode; +use crate::MessageEncode; +use crate::Result; use crate::inplace::InplaceOption; use crate::protobuf::FieldReader; use crate::protobuf::FieldSizer; @@ -16,11 +21,6 @@ use crate::protofile::FieldType; use crate::protofile::MessageDescription; use crate::table::decode::DecoderEntry; use crate::table::encode::EncoderEntry; -use crate::FieldDecode; -use crate::FieldEncode; -use crate::MessageDecode; -use crate::MessageEncode; -use crate::Result; use core::mem::MaybeUninit; use core::ptr; diff --git a/support/mesh/mesh_remote/src/alpc_node.rs b/support/mesh/mesh_remote/src/alpc_node.rs index c7ef9da844..fbf8425f8e 100644 --- a/support/mesh/mesh_remote/src/alpc_node.rs +++ b/support/mesh/mesh_remote/src/alpc_node.rs @@ -9,11 +9,11 @@ use crate::common::InvitationAddress; use crate::protocol; -use futures::channel::mpsc; -use futures::future::abortable; -use futures::future::AbortHandle; use futures::FutureExt; use futures::StreamExt; +use futures::channel::mpsc; +use futures::future::AbortHandle; +use futures::future::abortable; use mesh_node::common::Address; use mesh_node::common::NodeId; use mesh_node::common::PortId; @@ -26,17 +26,17 @@ use mesh_node::local_node::RemoteNodeHandle; use mesh_node::local_node::SendEvent; use mesh_node::resource::OsResource; use mesh_node::resource::Resource; -use mesh_protobuf::buffer::Buffer; use mesh_protobuf::Protobuf; +use mesh_protobuf::buffer::Buffer; use ntapi::ntobapi::DIRECTORY_ALL_ACCESS; -use pal::windows::alpc; -use pal::windows::alpc::PortSection; -use pal::windows::alpc::SendMessage; -use pal::windows::create_object_directory; use pal::windows::BorrowedHandleExt; use pal::windows::ObjectAttributes; use pal::windows::OwnedSocketExt; use pal::windows::UnicodeString; +use pal::windows::alpc; +use pal::windows::alpc::PortSection; +use pal::windows::alpc::SendMessage; +use pal::windows::create_object_directory; use pal_async::driver::Driver; use pal_async::task::Spawn; use pal_async::task::Task; @@ -44,7 +44,6 @@ use pal_async::wait::PolledWait; use parking_lot::Mutex; use std::collections::HashMap; use std::fmt::Debug; -use std::future::Future; use std::io; use std::ops::Deref; use std::os::windows::prelude::*; @@ -780,10 +779,10 @@ impl Deref for AlpcPort { #[cfg(test)] mod tests { use super::AlpcNode; - use mesh_channel::channel; use mesh_channel::RecvError; - use pal_async::async_test; + use mesh_channel::channel; use pal_async::DefaultDriver; + use pal_async::async_test; use pal_event::Event; use std::io::Read; use std::io::Write; diff --git a/support/mesh/mesh_remote/src/point_to_point.rs b/support/mesh/mesh_remote/src/point_to_point.rs index b7a9f6fa81..1600738cc4 100644 --- a/support/mesh/mesh_remote/src/point_to_point.rs +++ b/support/mesh/mesh_remote/src/point_to_point.rs @@ -3,8 +3,6 @@ //! Point-to-point mesh implementation. -use futures::future::try_join; -use futures::io::BufReader; use futures::AsyncBufReadExt; use futures::AsyncRead; use futures::AsyncReadExt; @@ -12,6 +10,8 @@ use futures::AsyncWrite; use futures::AsyncWriteExt; use futures::StreamExt; use futures::TryFutureExt; +use futures::future::try_join; +use futures::io::BufReader; use futures_concurrency::future::Race; use mesh_channel::cancel::Cancel; use mesh_channel::cancel::CancelContext; @@ -284,9 +284,9 @@ struct NoMesh; mod tests { use super::PointToPointMesh; use mesh_channel::channel; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::socket::PolledSocket; - use pal_async::DefaultDriver; use test_with_tracing::test; use unix_socket::UnixStream; diff --git a/support/mesh/mesh_remote/src/unix_node.rs b/support/mesh/mesh_remote/src/unix_node.rs index 3e92ff2ae2..ba7aadf7ab 100644 --- a/support/mesh/mesh_remote/src/unix_node.rs +++ b/support/mesh/mesh_remote/src/unix_node.rs @@ -21,17 +21,17 @@ mod memfd; use crate::common::InvitationAddress; use crate::protocol; +use futures::FutureExt; +use futures::StreamExt; use futures::channel::mpsc; use futures::future; use futures::future::BoxFuture; -use futures::FutureExt; -use futures::StreamExt; use io::ErrorKind; -use mesh_channel::channel; -use mesh_channel::oneshot; use mesh_channel::OneshotReceiver; use mesh_channel::OneshotSender; use mesh_channel::RecvError; +use mesh_channel::channel; +use mesh_channel::oneshot; use mesh_node::common::Address; use mesh_node::common::NodeId; use mesh_node::common::PortId; @@ -56,7 +56,6 @@ use std::collections::HashMap; use std::collections::VecDeque; use std::fmt::Debug; use std::future::poll_fn; -use std::future::Future; use std::io; use std::io::IoSlice; use std::io::IoSliceMut; @@ -539,30 +538,34 @@ async fn run_connection( handle: RemoteNodeHandle, ) { let mut retained_fds = VecDeque::new(); - let mut recv = pin!(async { - let r = run_receive(&local_node, &remote_id, &socket, &send_send).await; - match &r { - Ok(_) => { - tracing::debug!("incoming socket disconnected"); - } - Err(err) => { - tracing::error!(error = err as &dyn std::error::Error, "error receiving"); + let mut recv = pin!( + async { + let r = run_receive(&local_node, &remote_id, &socket, &send_send).await; + match &r { + Ok(_) => { + tracing::debug!("incoming socket disconnected"); + } + Err(err) => { + tracing::error!(error = err as &dyn std::error::Error, "error receiving"); + } } + r } - r - } - .fuse()); - let mut send = pin!(async { - match run_send(send_recv, &socket, &mut retained_fds).await { - Ok(_) => { - tracing::debug!("sending is done"); - } - Err(err) => { - tracing::error!(error = &err as &dyn std::error::Error, "failed send"); + .fuse() + ); + let mut send = pin!( + async { + match run_send(send_recv, &socket, &mut retained_fds).await { + Ok(_) => { + tracing::debug!("sending is done"); + } + Err(err) => { + tracing::error!(error = &err as &dyn std::error::Error, "failed send"); + } } } - } - .fuse()); + .fuse() + ); let r = futures::select! { // race semantics r = recv => { // Notify the remote node that no more data will be sent. @@ -1288,10 +1291,10 @@ fn set_cloexec(fd: impl AsFd) { #[cfg(test)] mod tests { use crate::unix::UnixNode; - use mesh_channel::channel; use mesh_channel::RecvError; - use pal_async::async_test; + use mesh_channel::channel; use pal_async::DefaultDriver; + use pal_async::async_test; use test_with_tracing::test; #[async_test] diff --git a/support/mesh/mesh_rpc/examples/rust-server.rs b/support/mesh/mesh_rpc/examples/rust-server.rs index 326ee123d7..8c8f039ffe 100644 --- a/support/mesh/mesh_rpc/examples/rust-server.rs +++ b/support/mesh/mesh_rpc/examples/rust-server.rs @@ -4,8 +4,8 @@ #![expect(missing_docs)] use anyhow::Context; -use futures::executor::block_on; use futures::StreamExt; +use futures::executor::block_on; use pal_async::local::block_with_io; use unix_socket::UnixListener; diff --git a/support/mesh/mesh_rpc/fuzz/fuzz_mesh_ttrpc_server.rs b/support/mesh/mesh_rpc/fuzz/fuzz_mesh_ttrpc_server.rs index 7df08af154..71d03f7b13 100644 --- a/support/mesh/mesh_rpc/fuzz/fuzz_mesh_ttrpc_server.rs +++ b/support/mesh/mesh_rpc/fuzz/fuzz_mesh_ttrpc_server.rs @@ -8,8 +8,8 @@ use futures::AsyncReadExt; use futures::AsyncWriteExt; use futures::FutureExt; use futures::StreamExt; -use pal_async::socket::PolledSocket; use pal_async::DefaultPool; +use pal_async::socket::PolledSocket; use unix_socket::UnixListener; use unix_socket::UnixStream; use xtask_fuzz::fuzz_eprintln; diff --git a/support/mesh/mesh_rpc/src/client.rs b/support/mesh/mesh_rpc/src/client.rs index 0796a1d2e2..0c6c9511c6 100644 --- a/support/mesh/mesh_rpc/src/client.rs +++ b/support/mesh/mesh_rpc/src/client.rs @@ -3,16 +3,16 @@ //! TTRPC client. -use crate::message::read_message; -use crate::message::write_message; +use crate::message::MESSAGE_TYPE_REQUEST; +use crate::message::MESSAGE_TYPE_RESPONSE; use crate::message::ReadResult; use crate::message::Request; use crate::message::Response; use crate::message::TooLongError; -use crate::message::MESSAGE_TYPE_REQUEST; -use crate::message::MESSAGE_TYPE_RESPONSE; -use crate::rpc::status_from_err; +use crate::message::read_message; +use crate::message::write_message; use crate::rpc::ProtocolError; +use crate::rpc::status_from_err; use crate::service::Code; use crate::service::DecodedRpc; use crate::service::GenericRpc; @@ -25,10 +25,10 @@ use futures::AsyncWrite; use futures::FutureExt; use futures::StreamExt; use futures_concurrency::future::Race; -use mesh::payload::EncodeAs; -use mesh::payload::Timestamp; use mesh::Deadline; use mesh::MeshPayload; +use mesh::payload::EncodeAs; +use mesh::payload::Timestamp; use pal_async::driver::Driver; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; @@ -39,7 +39,6 @@ use parking_lot::Mutex; use std::collections::HashMap; use std::collections::VecDeque; use std::future::pending; -use std::future::Future; use std::pin::pin; use std::task::ready; use std::time::Duration; @@ -503,9 +502,9 @@ mod tests { use crate::service::Code; use mesh::CancelContext; use mesh::Deadline; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::socket::PolledSocket; - use pal_async::DefaultDriver; use std::future::pending; use std::net::TcpStream; use std::time::Duration; diff --git a/support/mesh/mesh_rpc/src/server.rs b/support/mesh/mesh_rpc/src/server.rs index eca0265b21..fe795a9012 100644 --- a/support/mesh/mesh_rpc/src/server.rs +++ b/support/mesh/mesh_rpc/src/server.rs @@ -3,31 +3,31 @@ //! TTRPC server. -use crate::message::read_message; -use crate::message::write_message; +use crate::message::MESSAGE_TYPE_REQUEST; +use crate::message::MESSAGE_TYPE_RESPONSE; use crate::message::ReadResult; use crate::message::Request; use crate::message::Response; use crate::message::TooLongError; -use crate::message::MESSAGE_TYPE_REQUEST; -use crate::message::MESSAGE_TYPE_RESPONSE; -use crate::rpc::status_from_err; +use crate::message::read_message; +use crate::message::write_message; use crate::rpc::ProtocolError; +use crate::rpc::status_from_err; use crate::service::Code; use crate::service::DecodedRpc; use crate::service::GenericRpc; use crate::service::ServiceRpc; use crate::service::ServiceRpcError; use crate::service::Status; -use futures::stream::FusedStream; use futures::FutureExt; use futures::Stream; use futures::StreamExt; +use futures::stream::FusedStream; use futures_concurrency::future::TryJoin; use futures_concurrency::stream::Merge; -use mesh::local_node::Port; use mesh::CancelContext; use mesh::MeshPayload; +use mesh::local_node::Port; use pal_async::driver::Driver; use pal_async::socket::AsSockRef; use pal_async::socket::Listener; @@ -296,8 +296,8 @@ mod grpc { use futures::FutureExt; use futures::StreamExt; use futures_concurrency::stream::Merge; - use h2::server::SendResponse; use h2::RecvStream; + use h2::server::SendResponse; use http::HeaderMap; use http::HeaderValue; use mesh::CancelContext; @@ -375,9 +375,9 @@ mod grpc { cx: &mut std::task::Context<'_>, buf: &mut tokio::io::ReadBuf<'_>, ) -> std::task::Poll> { - let n = - ready!(Pin::new(&mut self.get_mut().0) - .poll_read(cx, buf.initialize_unfilled()))?; + let n = ready!( + Pin::new(&mut self.get_mut().0).poll_read(cx, buf.initialize_unfilled()) + )?; buf.advance(n); std::task::Poll::Ready(Ok(())) } @@ -611,16 +611,16 @@ mod grpc { #[cfg(test)] mod tests { + use crate::Client; + use crate::Server; use crate::client::ExistingConnection; use crate::service::Code; use crate::service::ServiceRpc; - use crate::Client; - use crate::Server; - use futures::executor::block_on; use futures::StreamExt; + use futures::executor::block_on; + use pal_async::DefaultPool; use pal_async::local::block_with_io; use pal_async::socket::PolledSocket; - use pal_async::DefaultPool; use test_with_tracing::test; mod items { diff --git a/support/mesh/mesh_rpc/src/service.rs b/support/mesh/mesh_rpc/src/service.rs index e8ba3f0d6d..67ff577442 100644 --- a/support/mesh/mesh_rpc/src/service.rs +++ b/support/mesh/mesh_rpc/src/service.rs @@ -6,16 +6,16 @@ pub use grpc::Code; pub use grpc::Status; use mesh::local_node::Port; +use mesh::payload::DefaultEncoding; +use mesh::payload::MessageDecode; +use mesh::payload::MessageEncode; +use mesh::payload::Result; use mesh::payload::encoding::MessageEncoding; use mesh::payload::protobuf::FieldSizer; use mesh::payload::protobuf::FieldWriter; use mesh::payload::protobuf::MessageReader; use mesh::payload::protobuf::MessageSizer; use mesh::payload::protobuf::MessageWriter; -use mesh::payload::DefaultEncoding; -use mesh::payload::MessageDecode; -use mesh::payload::MessageEncode; -use mesh::payload::Result; use mesh::resource::Resource; mod grpc { diff --git a/support/mesh/mesh_worker/src/worker.rs b/support/mesh/mesh_worker/src/worker.rs index 2e31d3fecc..90885addbf 100644 --- a/support/mesh/mesh_worker/src/worker.rs +++ b/support/mesh/mesh_worker/src/worker.rs @@ -4,16 +4,16 @@ //! Infrastructure for workers that can run on mesh nodes. use anyhow::Context; -use futures::executor::block_on; -use futures::stream::FusedStream; use futures::Stream; use futures::StreamExt; +use futures::executor::block_on; +use futures::stream::FusedStream; use futures_concurrency::stream::Merge; use inspect::Inspect; +use mesh::MeshPayload; use mesh::error::RemoteError; use mesh::rpc::FailableRpc; use mesh::rpc::RpcSend; -use mesh::MeshPayload; use std::fmt; use std::marker::PhantomData; use std::pin::Pin; @@ -726,12 +726,12 @@ mod tests { use super::WorkerRpc; use crate::launch_local_worker; use crate::worker::WorkerEvent; - use futures::executor::block_on; use futures::StreamExt; + use futures::executor::block_on; use mesh::MeshPayload; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::task::Spawn; - use pal_async::DefaultDriver; use test_with_tracing::test; struct TestWorker { diff --git a/support/mesh/src/lib.rs b/support/mesh/src/lib.rs index 20f766bbf7..41d16f70f5 100644 --- a/support/mesh/src/lib.rs +++ b/support/mesh/src/lib.rs @@ -14,28 +14,28 @@ pub mod payload { pub use mesh_protobuf::*; } +pub use mesh_channel::ChannelError; +pub use mesh_channel::ChannelErrorKind; +pub use mesh_channel::OneshotReceiver; +pub use mesh_channel::OneshotSender; +pub use mesh_channel::Receiver; +pub use mesh_channel::RecvError; +pub use mesh_channel::Sender; +pub use mesh_channel::TryRecvError; pub use mesh_channel::cancel::Cancel; pub use mesh_channel::cancel::CancelContext; pub use mesh_channel::cancel::CancelReason; pub use mesh_channel::cancel::Cancelled; pub use mesh_channel::cancel::Deadline; -pub use mesh_channel::cell::cell; pub use mesh_channel::cell::Cell; pub use mesh_channel::cell::CellUpdater; +pub use mesh_channel::cell::cell; pub use mesh_channel::channel; pub use mesh_channel::error; pub use mesh_channel::mpsc_channel; pub use mesh_channel::oneshot; pub use mesh_channel::pipe; pub use mesh_channel::rpc; -pub use mesh_channel::ChannelError; -pub use mesh_channel::ChannelErrorKind; -pub use mesh_channel::OneshotReceiver; -pub use mesh_channel::OneshotSender; -pub use mesh_channel::Receiver; -pub use mesh_channel::RecvError; -pub use mesh_channel::Sender; -pub use mesh_channel::TryRecvError; pub use mesh_derive::MeshPayload; pub use mesh_node::common::Address; pub use mesh_node::common::NodeId; diff --git a/support/mesh_tracing/src/bounded.rs b/support/mesh_tracing/src/bounded.rs index 1b664a8d1f..2aab18e16b 100644 --- a/support/mesh_tracing/src/bounded.rs +++ b/support/mesh_tracing/src/bounded.rs @@ -6,6 +6,9 @@ //! In the future, this should be generalized and move to `mesh_channel`. use futures::Stream; +use mesh::Message; +use mesh::OwnedMessage; +use mesh::RecvError; use mesh::local_node::HandleMessageError; use mesh::local_node::HandlePortEvent; use mesh::local_node::NodeError; @@ -16,16 +19,13 @@ use mesh::local_node::PortWithHandler; use mesh::message::MeshField; use mesh::payload::Protobuf; use mesh::resource::Resource; -use mesh::Message; -use mesh::OwnedMessage; -use mesh::RecvError; use std::collections::VecDeque; use std::future::poll_fn; use std::marker::PhantomData; -use std::task::ready; use std::task::Context; use std::task::Poll; use std::task::Waker; +use std::task::ready; pub struct BoundedReceiver { port: PortWithHandler, @@ -265,12 +265,12 @@ mod encoding { use super::ReceiverState; use mesh::local_node::Port; use mesh::message::MeshField; - use mesh::payload::encoding::MessageEncoding; - use mesh::payload::inplace_none; use mesh::payload::DefaultEncoding; use mesh::payload::MessageDecode; use mesh::payload::MessageEncode; use mesh::payload::Protobuf; + use mesh::payload::encoding::MessageEncoding; + use mesh::payload::inplace_none; use mesh::resource::Resource; use std::collections::VecDeque; use std::marker::PhantomData; diff --git a/support/mesh_tracing/src/lib.rs b/support/mesh_tracing/src/lib.rs index d28a37cab1..f63430feb7 100644 --- a/support/mesh_tracing/src/lib.rs +++ b/support/mesh_tracing/src/lib.rs @@ -7,30 +7,29 @@ mod bounded; -use self::bounded::bounded; use self::bounded::BoundedReceiver; use self::bounded::BoundedSender; +use self::bounded::bounded; use anyhow::Context as _; -use futures::future::join_all; use futures::FutureExt; use futures::Stream; +use futures::future::join_all; use guid::Guid; use inspect::InspectMut; +use mesh::MeshPayload; use mesh::rpc::Rpc; use mesh::rpc::RpcSend; -use mesh::MeshPayload; use pal_async::task::Spawn; use pal_async::task::Task; use std::fs::File; -use std::future::Future; use std::pin::Pin; use std::task::Context; use std::task::Poll; +use tracing_subscriber::Layer; use tracing_subscriber::filter::Filtered; use tracing_subscriber::filter::Targets; use tracing_subscriber::registry::LookupSpan; use tracing_subscriber::reload; -use tracing_subscriber::Layer; #[derive(Debug, MeshPayload)] pub struct RemoteTracer { diff --git a/support/openssl_kdf/src/kdf.rs b/support/openssl_kdf/src/kdf.rs index 81385e8777..a5b14b6057 100644 --- a/support/openssl_kdf/src/kdf.rs +++ b/support/openssl_kdf/src/kdf.rs @@ -4,13 +4,13 @@ // See also the LICENSE file in the root of the crate for additional copyright // information. +use super::sys::EVP_KDF; +use super::sys::EVP_KDF_CTX; use super::sys::EVP_KDF_CTX_free; use super::sys::EVP_KDF_CTX_new; use super::sys::EVP_KDF_derive; use super::sys::EVP_KDF_fetch; use super::sys::EVP_MD_get0_name; -use super::sys::EVP_KDF; -use super::sys::EVP_KDF_CTX; use super::sys::OSSL_KDF_PARAM_DIGEST; use super::sys::OSSL_KDF_PARAM_INFO; use super::sys::OSSL_KDF_PARAM_KBKDF_USE_L; diff --git a/support/openssl_kdf/src/params.rs b/support/openssl_kdf/src/params.rs index cd2547a797..af0283ff6a 100644 --- a/support/openssl_kdf/src/params.rs +++ b/support/openssl_kdf/src/params.rs @@ -5,11 +5,11 @@ // information. use crate::cvt_p; +use crate::sys::OSSL_PARAM; +use crate::sys::OSSL_PARAM_END; use crate::sys::OSSL_PARAM_construct_int; use crate::sys::OSSL_PARAM_construct_octet_string; use crate::sys::OSSL_PARAM_construct_utf8_string; -use crate::sys::OSSL_PARAM; -use crate::sys::OSSL_PARAM_END; use libc::c_char; use libc::c_int; use libc::c_void; diff --git a/support/pal/pal_async/src/driver.rs b/support/pal/pal_async/src/driver.rs index 4e70871717..d33fd0c421 100644 --- a/support/pal/pal_async/src/driver.rs +++ b/support/pal/pal_async/src/driver.rs @@ -21,8 +21,8 @@ use crate::timer::PollTimer; use crate::timer::TimerDriver; use crate::wait::PollWait; use crate::wait::WaitDriver; -use smallbox::space::S4; use smallbox::SmallBox; +use smallbox::space::S4; use std::io; #[cfg(unix)] use std::os::unix::prelude::*; diff --git a/support/pal/pal_async/src/executor_tests.rs b/support/pal/pal_async/src/executor_tests.rs index 63c909c4c7..2dce14cfa6 100644 --- a/support/pal/pal_async/src/executor_tests.rs +++ b/support/pal/pal_async/src/executor_tests.rs @@ -8,14 +8,14 @@ use crate::driver::Driver; use crate::socket::PolledSocket; -use crate::task::with_current_task_metadata; use crate::task::Spawn; +use crate::task::with_current_task_metadata; use crate::timer::Instant; -use futures::channel::oneshot; -use futures::executor::block_on; use futures::AsyncReadExt; use futures::AsyncWriteExt; use futures::FutureExt; +use futures::channel::oneshot; +use futures::executor::block_on; use pal_event::Event; use parking_lot::Mutex; use std::future::poll_fn; diff --git a/support/pal/pal_async/src/io_pool.rs b/support/pal/pal_async/src/io_pool.rs index 029f788283..018af2508a 100644 --- a/support/pal/pal_async/src/io_pool.rs +++ b/support/pal/pal_async/src/io_pool.rs @@ -3,14 +3,13 @@ //! Single-threaded task pools backed by platform-specific IO backends. -use crate::task::task_queue; use crate::task::Schedule; use crate::task::Scheduler; use crate::task::Spawn; use crate::task::TaskMetadata; use crate::task::TaskQueue; +use crate::task::task_queue; use std::future::poll_fn; -use std::future::Future; use std::pin::pin; use std::sync::Arc; use std::task::Poll; diff --git a/support/pal/pal_async/src/local.rs b/support/pal/pal_async/src/local.rs index e13272ce42..abc97f5826 100644 --- a/support/pal/pal_async/src/local.rs +++ b/support/pal/pal_async/src/local.rs @@ -11,15 +11,14 @@ use crate::timer::TimerDriver; use crate::timer::TimerQueue; use crate::timer::TimerResult; use crate::waker::WakerList; -use futures::task::waker_ref; use futures::task::ArcWake; +use futures::task::waker_ref; use parking_lot::Condvar; use parking_lot::MappedMutexGuard; use parking_lot::Mutex; use parking_lot::MutexGuard; -use std::future::Future; -use std::pin::pin; use std::pin::Pin; +use std::pin::pin; use std::sync::Arc; use std::task::Context; use std::task::Poll; diff --git a/support/pal/pal_async/src/socket.rs b/support/pal/pal_async/src/socket.rs index 4ebd516733..bffbf518e9 100644 --- a/support/pal/pal_async/src/socket.rs +++ b/support/pal/pal_async/src/socket.rs @@ -14,7 +14,6 @@ use futures::AsyncWrite; use parking_lot::Mutex; use std::fmt::Debug; use std::future::poll_fn; -use std::future::Future; use std::io; use std::io::Read; use std::io::Write; diff --git a/support/pal/pal_async/src/task.rs b/support/pal/pal_async/src/task.rs index 1f408967e6..f0adb31e3f 100644 --- a/support/pal/pal_async/src/task.rs +++ b/support/pal/pal_async/src/task.rs @@ -11,15 +11,14 @@ use parking_lot::Mutex; use slab::Slab; use std::fmt::Debug; use std::fmt::Display; -use std::future::Future; use std::panic::Location; use std::pin::Pin; +use std::sync::Arc; +use std::sync::Weak; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::sync::Weak; /// A handle to a task. pub type Task = async_task::Task; diff --git a/support/pal/pal_async/src/timer.rs b/support/pal/pal_async/src/timer.rs index 7d59f73c87..1d3e823053 100644 --- a/support/pal/pal_async/src/timer.rs +++ b/support/pal/pal_async/src/timer.rs @@ -7,7 +7,6 @@ use crate::driver::Driver; use crate::driver::PollImpl; use crate::sparsevec::SparseVec; use crate::waker::WakerList; -use std::future::Future; use std::pin::Pin; use std::task::Context; use std::task::Poll; diff --git a/support/pal/pal_async/src/unix/epoll.rs b/support/pal/pal_async/src/unix/epoll.rs index 505630f000..2bd51249b0 100644 --- a/support/pal/pal_async/src/unix/epoll.rs +++ b/support/pal/pal_async/src/unix/epoll.rs @@ -20,16 +20,15 @@ use crate::timer::TimerQueueId; use crate::timer::TimerResult; use crate::wait::WaitDriver; use crate::waker::WakerList; -use futures::task::waker_ref; -use futures::task::ArcWake; use futures::FutureExt; -use pal::unix::while_eintr; +use futures::task::ArcWake; +use futures::task::waker_ref; use pal::unix::Errno; use pal::unix::SyscallResult; +use pal::unix::while_eintr; use pal_event::Event; use parking_lot::Mutex; use std::fs::File; -use std::future::Future; use std::io; use std::os::unix::prelude::*; use std::pin::pin; diff --git a/support/pal/pal_async/src/unix/kqueue.rs b/support/pal/pal_async/src/unix/kqueue.rs index abee728b59..a5644591b9 100644 --- a/support/pal/pal_async/src/unix/kqueue.rs +++ b/support/pal/pal_async/src/unix/kqueue.rs @@ -20,15 +20,14 @@ use crate::timer::TimerQueueId; use crate::timer::TimerResult; use crate::wait::WaitDriver; use crate::waker::WakerList; -use futures::task::waker_ref; -use futures::task::ArcWake; use futures::FutureExt; -use pal::unix::while_eintr; +use futures::task::ArcWake; +use futures::task::waker_ref; use pal::unix::Errno; use pal::unix::SyscallResult; +use pal::unix::while_eintr; use parking_lot::Mutex; use std::fs::File; -use std::future::Future; use std::io; use std::os::unix::prelude::*; use std::pin::pin; diff --git a/support/pal/pal_async/src/unix/local.rs b/support/pal/pal_async/src/unix/local.rs index 4fe46f917d..0e72981834 100644 --- a/support/pal/pal_async/src/unix/local.rs +++ b/support/pal/pal_async/src/unix/local.rs @@ -14,8 +14,8 @@ use crate::local::LocalInner; use crate::sparsevec::SparseVec; use crate::wait::WaitDriver; use crate::waker::WakerList; -use pal::unix::while_eintr; use pal::unix::SyscallResult; +use pal::unix::while_eintr; use pal_event::Event; use std::io; use std::os::unix::prelude::*; diff --git a/support/pal/pal_async/src/unix/wait.rs b/support/pal/pal_async/src/unix/wait.rs index 791f5281e8..e3685da3c3 100644 --- a/support/pal/pal_async/src/unix/wait.rs +++ b/support/pal/pal_async/src/unix/wait.rs @@ -6,8 +6,8 @@ use crate::fd::PollFdReady; use crate::interest::InterestSlot; use crate::interest::PollEvents; -use crate::wait::PollWait; use crate::wait::MAXIMUM_WAIT_READ_SIZE; +use crate::wait::PollWait; use pal::unix::Errno; use pal::unix::SyscallResult; use std::os::unix::prelude::*; @@ -41,9 +41,10 @@ impl FdWait { impl PollWait for FdWait { fn poll_wait(&mut self, cx: &mut Context<'_>) -> Poll> { loop { - std::task::ready!(self - .fd_ready - .poll_fd_ready(cx, InterestSlot::Read, PollEvents::IN)); + std::task::ready!( + self.fd_ready + .poll_fd_ready(cx, InterestSlot::Read, PollEvents::IN) + ); self.fd_ready.clear_fd_ready(InterestSlot::Read); diff --git a/support/pal/pal_async/src/wait.rs b/support/pal/pal_async/src/wait.rs index 6998de42f9..3c33451903 100644 --- a/support/pal/pal_async/src/wait.rs +++ b/support/pal/pal_async/src/wait.rs @@ -7,7 +7,6 @@ use crate::any::AsAny; use crate::driver::Driver; use crate::driver::PollImpl; use std::future::poll_fn; -use std::future::Future; use std::io; #[cfg(unix)] use std::os::unix::prelude::*; diff --git a/support/pal/pal_async/src/windows/iocp.rs b/support/pal/pal_async/src/windows/iocp.rs index 0fa4561ff4..db50bfe712 100644 --- a/support/pal/pal_async/src/windows/iocp.rs +++ b/support/pal/pal_async/src/windows/iocp.rs @@ -24,20 +24,19 @@ use crate::timer::TimerResult; use crate::wait::PollWait; use crate::wait::WaitDriver; use crate::waker::WakerList; -use futures::task::waker_ref; -use futures::task::ArcWake; use futures::FutureExt; +use futures::task::ArcWake; +use futures::task::waker_ref; use once_cell::sync::OnceCell; -use pal::windows::afd; -use pal::windows::disassociate_completion_port; -use pal::windows::set_file_completion_notification_modes; use pal::windows::IoCompletionPort; use pal::windows::Overlapped; use pal::windows::SendSyncRawHandle; use pal::windows::WaitPacket; +use pal::windows::afd; +use pal::windows::disassociate_completion_port; +use pal::windows::set_file_completion_notification_modes; use parking_lot::Mutex; use std::fs::File; -use std::future::Future; use std::io; use std::os::windows::prelude::*; use std::pin::pin; diff --git a/support/pal/pal_async/src/windows/local.rs b/support/pal/pal_async/src/windows/local.rs index a0a9946f1a..c289138887 100644 --- a/support/pal/pal_async/src/windows/local.rs +++ b/support/pal/pal_async/src/windows/local.rs @@ -3,9 +3,9 @@ //! A thread-local executor backed by WaitForMultipleObjects. -use super::overlapped::overlapped_io_done; use super::overlapped::IoOverlapped; use super::overlapped::OverlappedIoDriver; +use super::overlapped::overlapped_io_done; use super::socket::make_poll_handle_info; use super::socket::parse_poll_handle_info; use crate::interest::InterestSlot; @@ -21,10 +21,10 @@ use crate::wait::WaitDriver; use crate::waker::WakerList; use headervec::HeaderVec; use once_cell::sync::OnceCell; -use pal::windows::afd; -use pal::windows::set_file_completion_notification_modes; use pal::windows::Overlapped; use pal::windows::SendSyncRawHandle; +use pal::windows::afd; +use pal::windows::set_file_completion_notification_modes; use pal_event::Event; use std::fs::File; use std::io; diff --git a/support/pal/pal_async/src/windows/overlapped.rs b/support/pal/pal_async/src/windows/overlapped.rs index dc889dfb84..c914cba582 100644 --- a/support/pal/pal_async/src/windows/overlapped.rs +++ b/support/pal/pal_async/src/windows/overlapped.rs @@ -6,12 +6,11 @@ use crate::driver::Driver; use crate::driver::PollImpl; use crate::waker::WakerList; -use pal::windows::chk_status; use pal::windows::Overlapped; use pal::windows::SendSyncRawHandle; +use pal::windows::chk_status; use parking_lot::Mutex; use std::fs::File; -use std::future::Future; use std::io; use std::mem::ManuallyDrop; use std::os::windows::prelude::*; diff --git a/support/pal/pal_async/src/windows/pipe.rs b/support/pal/pal_async/src/windows/pipe.rs index bed8bce513..0df37762c9 100644 --- a/support/pal/pal_async/src/windows/pipe.rs +++ b/support/pal/pal_async/src/windows/pipe.rs @@ -12,18 +12,17 @@ use crate::wait::PollWait; use crate::wait::PolledWait; use futures::AsyncRead; use futures::AsyncWrite; +use pal::windows::Overlapped; use pal::windows::chk_status; -use pal::windows::pipe::new_named_pipe; use pal::windows::pipe::Disposition; -use pal::windows::pipe::PipeExt; -use pal::windows::pipe::PipeMode; use pal::windows::pipe::FILE_PIPE_DISCONNECTED; use pal::windows::pipe::FILE_PIPE_READ_READY; use pal::windows::pipe::FILE_PIPE_WRITE_READY; -use pal::windows::Overlapped; +use pal::windows::pipe::PipeExt; +use pal::windows::pipe::PipeMode; +use pal::windows::pipe::new_named_pipe; use pal_event::Event; use std::fs::File; -use std::future::Future; use std::io; use std::io::Write; use std::os::windows::prelude::*; @@ -31,9 +30,9 @@ use std::path::Path; use std::path::PathBuf; use std::pin::Pin; use std::ptr::null_mut; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; use winapi::shared::winerror::ERROR_BROKEN_PIPE; use winapi::shared::winerror::ERROR_IO_PENDING; use winapi::shared::winerror::ERROR_NO_DATA; @@ -144,11 +143,12 @@ impl PolledPipe { self.refresh_events()?; } while self.events & FILE_PIPE_DISCONNECTED == 0 { - ready!(self - .wakers - .poll_wrapped(cx, InterestSlot::Read as usize, |cx| self - .wait - .poll_wait(cx)))?; + ready!( + self.wakers + .poll_wrapped(cx, InterestSlot::Read as usize, |cx| self + .wait + .poll_wait(cx)) + )?; self.refresh_events()?; } @@ -201,11 +201,12 @@ impl AsyncRead for PolledPipe { let this = self.get_mut(); let n = loop { while !this.is_read_ready() { - ready!(this - .wakers - .poll_wrapped(cx, InterestSlot::Read as usize, |cx| this - .wait - .poll_wait(cx)))?; + ready!( + this.wakers + .poll_wrapped(cx, InterestSlot::Read as usize, |cx| this + .wait + .poll_wait(cx)) + )?; this.refresh_events()?; } @@ -262,11 +263,12 @@ impl AsyncWrite for PolledPipe { let n = loop { while !this.is_write_ready() { - ready!(this - .wakers - .poll_wrapped(cx, InterestSlot::Write as usize, |cx| this - .wait - .poll_wait(cx)))?; + ready!( + this.wakers + .poll_wrapped(cx, InterestSlot::Write as usize, |cx| this + .wait + .poll_wait(cx)) + )?; this.refresh_events()?; } let n = this.file.write(buf)?; @@ -417,8 +419,8 @@ impl Future for ListeningPipe { #[cfg(test)] mod tests { use super::PolledPipe; - use crate::sys::pipe::NamedPipeServer; use crate::DefaultDriver; + use crate::sys::pipe::NamedPipeServer; use futures::AsyncReadExt; use futures::AsyncWriteExt; use pal_async_test::async_test; diff --git a/support/pal/pal_async/src/windows/socket.rs b/support/pal/pal_async/src/windows/socket.rs index 7cf6755853..84b5b5ac15 100644 --- a/support/pal/pal_async/src/windows/socket.rs +++ b/support/pal/pal_async/src/windows/socket.rs @@ -7,18 +7,18 @@ use crate::interest::InterestSlot; use crate::interest::PollEvents; use crate::interest::PollInterestSet; use crate::waker::WakerList; -use pal::windows::afd; -use pal::windows::status_to_error; use pal::windows::Overlapped; use pal::windows::SendSyncRawHandle; +use pal::windows::afd; +use pal::windows::status_to_error; use parking_lot::Mutex; use std::cell::UnsafeCell; use std::os::windows::prelude::*; use std::sync::Arc; use std::task::Context; use std::task::Poll; -use winapi::shared::ntdef::NTSTATUS; use winapi::shared::ntdef::NT_SUCCESS; +use winapi::shared::ntdef::NTSTATUS; use winapi::shared::ntstatus::STATUS_CANCELLED; use winapi::shared::ntstatus::STATUS_PENDING; use winapi::shared::ntstatus::STATUS_SUCCESS; diff --git a/support/pal/pal_async/src/windows/tp.rs b/support/pal/pal_async/src/windows/tp.rs index 06585f5f58..18415e1b53 100644 --- a/support/pal/pal_async/src/windows/tp.rs +++ b/support/pal/pal_async/src/windows/tp.rs @@ -3,9 +3,9 @@ //! An executor backed by the Windows thread pool. -use super::overlapped::overlapped_io_done; use super::overlapped::IoOverlapped; use super::overlapped::OverlappedIoDriver; +use super::overlapped::overlapped_io_done; use super::socket::AfdHandle; use super::socket::AfdSocketReady; use crate::interest::InterestSlot; @@ -24,6 +24,7 @@ use crate::wait::WaitDriver; use crate::waker::WakerList; use loan_cell::LoanCell; use once_cell::sync::OnceCell; +use pal::windows::SendSyncRawHandle; use pal::windows::afd; use pal::windows::disassociate_completion_port; use pal::windows::set_file_completion_notification_modes; @@ -31,7 +32,6 @@ use pal::windows::tp::TpIo; use pal::windows::tp::TpTimer; use pal::windows::tp::TpWait; use pal::windows::tp::TpWork; -use pal::windows::SendSyncRawHandle; use parking_lot::Mutex; use std::cell::Cell; use std::ffi::c_void; diff --git a/support/pal/pal_async_test/src/lib.rs b/support/pal/pal_async_test/src/lib.rs index de4f31b1c4..3ddf60b93a 100644 --- a/support/pal/pal_async_test/src/lib.rs +++ b/support/pal/pal_async_test/src/lib.rs @@ -4,10 +4,10 @@ //! Async test attribute macro for `pal_async` crate. use quote::quote; -use syn::parse_macro_input; -use syn::spanned::Spanned; use syn::Error; use syn::ItemFn; +use syn::parse_macro_input; +use syn::spanned::Spanned; /// Attribute macro on async tests. /// @@ -48,7 +48,7 @@ fn make_async_test(item: ItemFn) -> syn::Result { return Err(Error::new( item.sig.inputs.span(), "expected 0 arguments or 1 argument (the Driver or Spawn impl)", - )) + )); } }; let attrs = &item.attrs; diff --git a/support/pal/pal_uring/src/ioring.rs b/support/pal/pal_uring/src/ioring.rs index ca83efdda9..1e7d4c16ff 100644 --- a/support/pal/pal_uring/src/ioring.rs +++ b/support/pal/pal_uring/src/ioring.rs @@ -3,13 +3,13 @@ //! Lower-level async io-uring support, not tied to an executor model. -use ::smallbox::space::S4; use ::smallbox::SmallBox; -use io_uring::squeue; +use ::smallbox::space::S4; use io_uring::IoUring; +use io_uring::squeue; +use pal::unix::SyscallResult; use pal::unix::affinity::CpuSet; use pal::unix::while_eintr; -use pal::unix::SyscallResult; use parking_lot::Mutex; use slab::Slab; use smallbox::smallbox; @@ -18,9 +18,9 @@ use std::collections::VecDeque; use std::fmt::Debug; use std::io; use std::os::unix::prelude::*; +use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Arc; use std::task::Context; use std::task::Poll; use std::task::Waker; diff --git a/support/pal/pal_uring/src/threadpool.rs b/support/pal/pal_uring/src/threadpool.rs index 802b4f5f96..57766fc7a1 100644 --- a/support/pal/pal_uring/src/threadpool.rs +++ b/support/pal/pal_uring/src/threadpool.rs @@ -32,11 +32,10 @@ use std::cell::Cell; use std::cell::RefCell; use std::fmt::Debug; use std::future::poll_fn; -use std::future::Future; use std::io; use std::os::unix::prelude::*; -use std::pin::pin; use std::pin::Pin; +use std::pin::pin; use std::process::abort; use std::sync::Arc; use std::task::Context; @@ -624,7 +623,6 @@ mod tests { use io_uring::types; use pal_async::task::Spawn; use parking_lot::Mutex; - use std::future::Future; use std::os::unix::prelude::*; use std::pin::Pin; use std::sync::Arc; diff --git a/support/pal/pal_uring/src/uring.rs b/support/pal/pal_uring/src/uring.rs index 18cc193f57..ff645a80e0 100644 --- a/support/pal/pal_uring/src/uring.rs +++ b/support/pal/pal_uring/src/uring.rs @@ -17,9 +17,9 @@ use pal_async::interest::SLOT_COUNT; use pal_async::timer::Instant; use pal_async::timer::PollTimer; use pal_async::timer::TimerDriver; +use pal_async::wait::MAXIMUM_WAIT_READ_SIZE; use pal_async::wait::PollWait; use pal_async::wait::WaitDriver; -use pal_async::wait::MAXIMUM_WAIT_READ_SIZE; use std::fmt::Debug; use std::io; use std::os::unix::prelude::*; @@ -391,7 +391,6 @@ pub(crate) mod tests { use once_cell::sync::OnceCell; use pal_async::executor_tests; use pal_async::task::Spawn; - use std::future::Future; use std::io; use std::thread::JoinHandle; diff --git a/support/pal/src/unix.rs b/support/pal/src/unix.rs index 345984ce57..4de090fb2a 100644 --- a/support/pal/src/unix.rs +++ b/support/pal/src/unix.rs @@ -62,21 +62,13 @@ pub trait SyscallResult: Sized { impl SyscallResult for i32 { fn syscall_result(self) -> Result { - if self >= 0 { - Ok(self) - } else { - Err(errno()) - } + if self >= 0 { Ok(self) } else { Err(errno()) } } } impl SyscallResult for isize { fn syscall_result(self) -> Result { - if self >= 0 { - Ok(self) - } else { - Err(errno()) - } + if self >= 0 { Ok(self) } else { Err(errno()) } } } diff --git a/support/pal/src/unix/process.rs b/support/pal/src/unix/process.rs index e712db942e..0b62ab581c 100644 --- a/support/pal/src/unix/process.rs +++ b/support/pal/src/unix/process.rs @@ -10,8 +10,8 @@ mod linux; #[cfg(target_os = "macos")] mod posix_spawn; -use super::while_eintr; use super::SyscallResult; +use super::while_eintr; use std::collections::BTreeMap; use std::ffi::CString; use std::ffi::OsString; @@ -500,8 +500,8 @@ mod tests { #[cfg(target_os = "linux")] { - use crate::sys::while_eintr; use crate::sys::SyscallResult; + use crate::sys::while_eintr; use std::os::unix::prelude::*; let mut pollfd = libc::pollfd { @@ -524,8 +524,8 @@ mod tests { #[test] #[cfg(target_os = "linux")] fn test_landlock_sandbox() { - use crate::sys::while_eintr; use crate::sys::SyscallResult; + use crate::sys::while_eintr; use landlock::{AccessFs, PathBeneath, PathFd, Ruleset, RulesetAttr, RulesetCreatedAttr}; use std::os::unix::prelude::*; @@ -561,8 +561,8 @@ mod tests { #[cfg(target_os = "linux")] #[cfg(target_arch = "x86_64")] // xtask-fmt allow-target-arch sys-crate fn test_seccomp_sandbox() { - use crate::sys::while_eintr; use crate::sys::SyscallResult; + use crate::sys::while_eintr; use seccompiler::{SeccompAction, SeccompFilter, TargetArch}; use std::os::unix::prelude::*; diff --git a/support/pal/src/unix/process/linux.rs b/support/pal/src/unix/process/linux.rs index 00f3ac318b..e7d44306d3 100644 --- a/support/pal/src/unix/process/linux.rs +++ b/support/pal/src/unix/process/linux.rs @@ -7,8 +7,8 @@ use super::Builder; use super::Child; use super::FdOp; use super::SandboxFailureMode; -use crate::unix::errno; use crate::unix::SyscallResult; +use crate::unix::errno; use caps::CapsHashSet; use landlock::RulesetCreated; use seccompiler::SeccompFilter; diff --git a/support/pal/src/windows.rs b/support/pal/src/windows.rs index a293cc2bc0..96a3088cbc 100644 --- a/support/pal/src/windows.rs +++ b/support/pal/src/windows.rs @@ -18,13 +18,13 @@ pub mod tp; use self::security::SecurityDescriptor; use handleapi::INVALID_HANDLE_VALUE; +use ntapi::ntioapi::FILE_COMPLETION_INFORMATION; use ntapi::ntioapi::FileReplaceCompletionInformation; +use ntapi::ntioapi::IO_STATUS_BLOCK; use ntapi::ntioapi::NtAssociateWaitCompletionPacket; use ntapi::ntioapi::NtCancelWaitCompletionPacket; use ntapi::ntioapi::NtCreateWaitCompletionPacket; use ntapi::ntioapi::NtSetInformationFile; -use ntapi::ntioapi::FILE_COMPLETION_INFORMATION; -use ntapi::ntioapi::IO_STATUS_BLOCK; use ntapi::ntobapi::NtCreateDirectoryObject; use ntapi::ntobapi::NtOpenDirectoryObject; use ntapi::ntrtl; @@ -36,8 +36,8 @@ use ntrtl::RtlFreeUnicodeString; use ntrtl::RtlNtStatusToDosErrorNoTeb; use processthreadsapi::GetExitCodeProcess; use std::cell::UnsafeCell; -use std::ffi::c_void; use std::ffi::OsStr; +use std::ffi::c_void; use std::fs::File; use std::io; use std::io::Error; @@ -46,12 +46,12 @@ use std::marker::PhantomData; use std::mem::zeroed; use std::os::windows::prelude::*; use std::path::Path; +use std::ptr::NonNull; use std::ptr::addr_of; use std::ptr::null_mut; -use std::ptr::NonNull; +use std::sync::Once; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Once; use std::time::Duration; use widestring::U16CString; use widestring::Utf16Str; @@ -75,10 +75,10 @@ use winapi::um::processenv::SetStdHandle; use winapi::um::processthreadsapi; use winapi::um::processthreadsapi::TerminateProcess; use winapi::um::synchapi; -use winapi::um::winbase::SetFileCompletionNotificationModes; use winapi::um::winbase::INFINITE; use winapi::um::winbase::SEM_FAILCRITICALERRORS; use winapi::um::winbase::STD_OUTPUT_HANDLE; +use winapi::um::winbase::SetFileCompletionNotificationModes; use winapi::um::winnt; use winapi::um::winsock2; @@ -1120,11 +1120,13 @@ mod tests { #[test] fn test_dos_to_nt_path() { let pathu = dos_to_nt_path("c:\\foo").unwrap(); - assert!(pathu - .as_slice() - .iter() - .copied() - .eq("\\??\\c:\\foo".encode_utf16())); + assert!( + pathu + .as_slice() + .iter() + .copied() + .eq("\\??\\c:\\foo".encode_utf16()) + ); } #[test] diff --git a/support/pal/src/windows/afd.rs b/support/pal/src/windows/afd.rs index 6f5d38cff3..8dda9ae6aa 100644 --- a/support/pal/src/windows/afd.rs +++ b/support/pal/src/windows/afd.rs @@ -6,9 +6,9 @@ //! Code to interact with the Windows AFD (socket) driver. -use super::chk_status; use super::SendSyncRawHandle; use super::UnicodeString; +use super::chk_status; use ioapiset::DeviceIoControl; use minwinbase::OVERLAPPED; use ntapi::ntioapi::NtOpenFile; diff --git a/support/pal/src/windows/alpc.rs b/support/pal/src/windows/alpc.rs index 6a43703ed1..4cf190248a 100644 --- a/support/pal/src/windows/alpc.rs +++ b/support/pal/src/windows/alpc.rs @@ -3,9 +3,9 @@ #![cfg(windows)] -use super::chk_status; use super::IoCompletionPort; use super::ObjectAttributes; +use super::chk_status; use headervec::HeaderVec; use ntlpcapi::*; use std::cmp::min; @@ -15,8 +15,8 @@ use std::mem::MaybeUninit; use std::ops::Deref; use std::ops::DerefMut; use std::os::windows::prelude::*; -use std::ptr::null_mut; use std::ptr::NonNull; +use std::ptr::null_mut; use std::time::Duration; use winapi::shared::ntstatus::STATUS_TIMEOUT; diff --git a/support/pal/src/windows/fs.rs b/support/pal/src/windows/fs.rs index db5fd79d11..0adbf7f041 100644 --- a/support/pal/src/windows/fs.rs +++ b/support/pal/src/windows/fs.rs @@ -12,8 +12,8 @@ use std::os::windows::io::AsRawHandle; use std::path::Path; use std::ptr::null_mut; use widestring::U16CString; -use winapi::shared::ntdef::OBJECT_ATTRIBUTES; use winapi::shared::ntdef::OBJ_CASE_INSENSITIVE; +use winapi::shared::ntdef::OBJECT_ATTRIBUTES; use winapi::um::errhandlingapi::GetLastError; use winapi::um::minwinbase::WIN32_FIND_DATAW; diff --git a/support/pal/src/windows/pipe.rs b/support/pal/src/windows/pipe.rs index 8d10a4c413..c12dd273ed 100644 --- a/support/pal/src/windows/pipe.rs +++ b/support/pal/src/windows/pipe.rs @@ -1,27 +1,24 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use super::UnicodeString; use super::chk_status; use super::dos_to_nt_path; use super::status_to_error; -use super::UnicodeString; use namedpipeapi::GetNamedPipeHandleStateW; use namedpipeapi::SetNamedPipeHandleState; use ntapi::ntioapi; -use ntapi::ntioapi::FilePipeLocalInformation; -use ntapi::ntioapi::NtQueryInformationFile; use ntapi::ntioapi::FILE_OPEN; use ntapi::ntioapi::FILE_PIPE_CLOSING_STATE; use ntapi::ntioapi::FILE_PIPE_CONNECTED_STATE; use ntapi::ntioapi::FILE_PIPE_DISCONNECTED_STATE; use ntapi::ntioapi::FILE_PIPE_LISTENING_STATE; use ntapi::ntioapi::FILE_PIPE_LOCAL_INFORMATION; +use ntapi::ntioapi::FilePipeLocalInformation; +use ntapi::ntioapi::NtQueryInformationFile; use ntdef::LARGE_INTEGER; -use ntdef::OBJECT_ATTRIBUTES; use ntdef::OBJ_CASE_INSENSITIVE; -use ntioapi::NtCreateNamedPipeFile; -use ntioapi::NtFsControlFile; -use ntioapi::NtOpenFile; +use ntdef::OBJECT_ATTRIBUTES; use ntioapi::FILE_CREATE; use ntioapi::FILE_NON_DIRECTORY_FILE; use ntioapi::FILE_PIPE_BYTE_STREAM_MODE; @@ -30,6 +27,9 @@ use ntioapi::FILE_PIPE_MESSAGE_MODE; use ntioapi::FILE_PIPE_MESSAGE_TYPE; use ntioapi::FILE_PIPE_QUEUE_OPERATION; use ntioapi::FILE_SYNCHRONOUS_IO_NONALERT; +use ntioapi::NtCreateNamedPipeFile; +use ntioapi::NtFsControlFile; +use ntioapi::NtOpenFile; use pal_event::Event; use std::fs::File; use std::io; diff --git a/support/pal/src/windows/process.rs b/support/pal/src/windows/process.rs index 524156029c..b489a8c972 100644 --- a/support/pal/src/windows/process.rs +++ b/support/pal/src/windows/process.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::job::Job; use super::BorrowedHandleExt; use super::Process; +use super::job::Job; use ntapi::ntpsapi::NtCurrentProcess; use std::collections::BTreeMap; use std::ffi::OsStr; @@ -20,10 +20,10 @@ use winapi::um::processenv::GetStdHandle; use winapi::um::processthreadsapi::CreateProcessAsUserW; use winapi::um::processthreadsapi::DeleteProcThreadAttributeList; use winapi::um::processthreadsapi::InitializeProcThreadAttributeList; -use winapi::um::processthreadsapi::TerminateProcess; -use winapi::um::processthreadsapi::UpdateProcThreadAttribute; use winapi::um::processthreadsapi::LPPROC_THREAD_ATTRIBUTE_LIST; use winapi::um::processthreadsapi::STARTUPINFOW; +use winapi::um::processthreadsapi::TerminateProcess; +use winapi::um::processthreadsapi::UpdateProcThreadAttribute; use winapi::um::winbase::CREATE_SUSPENDED; use winapi::um::winbase::CREATE_UNICODE_ENVIRONMENT; use winapi::um::winbase::EXTENDED_STARTUPINFO_PRESENT; @@ -1004,8 +1004,8 @@ pub(crate) fn terminate(exit_code: i32) -> ! { #[cfg(test)] mod tests { - use super::empty_process; use super::EmptyProcess; + use super::empty_process; #[test] fn test_empty() { diff --git a/support/pal/src/windows/security.rs b/support/pal/src/windows/security.rs index e0dfd042fe..1375d030c4 100644 --- a/support/pal/src/windows/security.rs +++ b/support/pal/src/windows/security.rs @@ -9,8 +9,8 @@ use std::io::ErrorKind; use std::marker::PhantomData; use std::ops::Deref; use std::os::windows::prelude::*; -use std::ptr::null_mut; use std::ptr::NonNull; +use std::ptr::null_mut; use std::str::FromStr; use widestring::U16CStr; use widestring::U16CString; @@ -31,8 +31,8 @@ use winapi::um::winnt::PHANDLE; use winapi::um::winnt::PSECURITY_DESCRIPTOR; use winapi::um::winnt::PSID; use winapi::um::winnt::SACL_SECURITY_INFORMATION; -use winapi::um::winnt::SECURITY_CAPABILITIES; use winapi::um::winnt::SE_GROUP_ENABLED; +use winapi::um::winnt::SECURITY_CAPABILITIES; use winapi::um::winnt::SID_AND_ATTRIBUTES; const MAX_SUBAUTHORITY_COUNT: usize = 15; diff --git a/support/pal/src/windows/tp.rs b/support/pal/src/windows/tp.rs index ff17affee9..730a14e378 100644 --- a/support/pal/src/windows/tp.rs +++ b/support/pal/src/windows/tp.rs @@ -6,8 +6,8 @@ use std::ffi::c_void; use std::io; use std::os::windows::prelude::*; -use std::ptr::null_mut; use std::ptr::NonNull; +use std::ptr::null_mut; use std::time::Duration; use winapi::shared::minwindef::FILETIME; use winapi::um::threadpoolapiset::CancelThreadpoolIo; @@ -19,11 +19,11 @@ use winapi::um::threadpoolapiset::CreateThreadpoolIo; use winapi::um::threadpoolapiset::CreateThreadpoolTimer; use winapi::um::threadpoolapiset::CreateThreadpoolWait; use winapi::um::threadpoolapiset::CreateThreadpoolWork; +use winapi::um::threadpoolapiset::PTP_WIN32_IO_CALLBACK; use winapi::um::threadpoolapiset::SetThreadpoolTimerEx; use winapi::um::threadpoolapiset::SetThreadpoolWaitEx; use winapi::um::threadpoolapiset::StartThreadpoolIo; use winapi::um::threadpoolapiset::SubmitThreadpoolWork; -use winapi::um::threadpoolapiset::PTP_WIN32_IO_CALLBACK; use winapi::um::winnt::PTP_TIMER_CALLBACK; use winapi::um::winnt::PTP_WAIT_CALLBACK; use winapi::um::winnt::PTP_WORK_CALLBACK; diff --git a/support/sparse_mmap/fuzz/fuzz_sparse_mmap.rs b/support/sparse_mmap/fuzz/fuzz_sparse_mmap.rs index 43887022af..c93bd69368 100644 --- a/support/sparse_mmap/fuzz/fuzz_sparse_mmap.rs +++ b/support/sparse_mmap/fuzz/fuzz_sparse_mmap.rs @@ -6,8 +6,8 @@ use arbitrary::Arbitrary; use arbitrary::Unstructured; -use sparse_mmap::alloc_shared_memory; use sparse_mmap::SparseMapping; +use sparse_mmap::alloc_shared_memory; use std::fmt; use xtask_fuzz::fuzz_eprintln; use xtask_fuzz::fuzz_target; diff --git a/support/sparse_mmap/src/alloc.rs b/support/sparse_mmap/src/alloc.rs index c539d3a46c..ea7923d33d 100644 --- a/support/sparse_mmap/src/alloc.rs +++ b/support/sparse_mmap/src/alloc.rs @@ -77,12 +77,12 @@ impl Deref for SharedMem { #[cfg(windows)] mod windows { use std::ptr; - use windows_sys::Win32::System::Memory::VirtualAlloc; - use windows_sys::Win32::System::Memory::VirtualFree; use windows_sys::Win32::System::Memory::MEM_COMMIT; use windows_sys::Win32::System::Memory::MEM_RELEASE; use windows_sys::Win32::System::Memory::MEM_RESERVE; use windows_sys::Win32::System::Memory::PAGE_READWRITE; + use windows_sys::Win32::System::Memory::VirtualAlloc; + use windows_sys::Win32::System::Memory::VirtualFree; pub fn alloc(size: usize) -> std::io::Result<*mut u8> { let ptr = unsafe { diff --git a/support/sparse_mmap/src/lib.rs b/support/sparse_mmap/src/lib.rs index fb0be0f020..a8d8b97409 100644 --- a/support/sparse_mmap/src/lib.rs +++ b/support/sparse_mmap/src/lib.rs @@ -14,12 +14,12 @@ mod trycopy_windows_x64; pub mod unix; pub mod windows; -pub use sys::alloc_shared_memory; -pub use sys::new_mappable_from_file; pub use sys::AsMappableRef; pub use sys::Mappable; pub use sys::MappableRef; pub use sys::SparseMapping; +pub use sys::alloc_shared_memory; +pub use sys::new_mappable_from_file; use std::mem::MaybeUninit; use std::sync::atomic::AtomicU8; diff --git a/support/sparse_mmap/src/trycopy_windows_arm64.rs b/support/sparse_mmap/src/trycopy_windows_arm64.rs index 99b5b1886f..3117b43231 100644 --- a/support/sparse_mmap/src/trycopy_windows_arm64.rs +++ b/support/sparse_mmap/src/trycopy_windows_arm64.rs @@ -9,9 +9,9 @@ // xtask-fmt allow-target-arch sys-crate #![cfg(all(windows, target_arch = "aarch64"))] +use crate::AccessFailure; use crate::sys::EXCEPTION_CONTINUE_SEARCH; use crate::sys::EXCEPTION_EXECUTE_HANDLER; -use crate::AccessFailure; use windows_sys::Win32::Foundation::EXCEPTION_ACCESS_VIOLATION; /// The exception filter that runs when there is an access violation in one of diff --git a/support/sparse_mmap/src/trycopy_windows_x64.rs b/support/sparse_mmap/src/trycopy_windows_x64.rs index b960f62e3e..efabd69acf 100644 --- a/support/sparse_mmap/src/trycopy_windows_x64.rs +++ b/support/sparse_mmap/src/trycopy_windows_x64.rs @@ -9,9 +9,9 @@ // xtask-fmt allow-target-arch sys-crate #![cfg(all(windows, target_arch = "x86_64"))] +use crate::AccessFailure; use crate::sys::EXCEPTION_CONTINUE_SEARCH; use crate::sys::EXCEPTION_EXECUTE_HANDLER; -use crate::AccessFailure; use windows_sys::Win32::Foundation::EXCEPTION_ACCESS_VIOLATION; /// The exception filter that runs when there is an access violation in one of diff --git a/support/sparse_mmap/src/windows.rs b/support/sparse_mmap/src/windows.rs index 9eb25f9239..4b0e076126 100644 --- a/support/sparse_mmap/src/windows.rs +++ b/support/sparse_mmap/src/windows.rs @@ -5,27 +5,12 @@ #![cfg(windows)] -use pal::windows::BorrowedHandleExt; -use pal::windows::Process; -use parking_lot::Mutex; -use std::ffi::c_void; -use std::io; -use std::io::Error; -use std::os::windows::prelude::*; -use std::ptr::null; -use std::ptr::null_mut; -use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE; -use windows_sys::Win32::System::Memory; -use windows_sys::Win32::System::Threading::GetCurrentProcess; use Memory::CreateFileMappingW; -use Memory::MapViewOfFile3; -use Memory::UnmapViewOfFile2; -use Memory::VirtualAlloc2; -use Memory::VirtualFreeEx; -use Memory::MEMORY_MAPPED_VIEW_ADDRESS; use Memory::MEM_COMMIT; use Memory::MEM_RELEASE; use Memory::MEM_RESERVE; +use Memory::MEMORY_MAPPED_VIEW_ADDRESS; +use Memory::MapViewOfFile3; use Memory::PAGE_EXECUTE; use Memory::PAGE_EXECUTE_READ; use Memory::PAGE_EXECUTE_READWRITE; @@ -36,6 +21,21 @@ use Memory::PAGE_READWRITE; use Memory::PAGE_WRITECOPY; use Memory::SECTION_MAP_READ; use Memory::SECTION_MAP_WRITE; +use Memory::UnmapViewOfFile2; +use Memory::VirtualAlloc2; +use Memory::VirtualFreeEx; +use pal::windows::BorrowedHandleExt; +use pal::windows::Process; +use parking_lot::Mutex; +use std::ffi::c_void; +use std::io; +use std::io::Error; +use std::os::windows::prelude::*; +use std::ptr::null; +use std::ptr::null_mut; +use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE; +use windows_sys::Win32::System::Memory; +use windows_sys::Win32::System::Threading::GetCurrentProcess; const PAGE_SIZE: usize = 4096; @@ -693,8 +693,8 @@ pub fn alloc_shared_memory(size: usize) -> io::Result { #[cfg(test)] mod tests { - use super::alloc_shared_memory; use super::SparseMapping; + use super::alloc_shared_memory; use crate::initialize_try_copy; use crate::try_copy; use windows_sys::Win32::System::Memory::PAGE_READWRITE; diff --git a/support/task_control/src/lib.rs b/support/task_control/src/lib.rs index 8d77b08a55..81c79e3490 100644 --- a/support/task_control/src/lib.rs +++ b/support/task_control/src/lib.rs @@ -13,9 +13,8 @@ use pal_async::task::Spawn; use pal_async::task::Task; use parking_lot::Mutex; use std::future::poll_fn; -use std::future::Future; -use std::pin::pin; use std::pin::Pin; +use std::pin::pin; use std::sync::Arc; use std::task::Context; use std::task::Poll; @@ -94,9 +93,10 @@ impl StopTask<'_> { pub async fn until_stopped(&mut self, fut: F) -> Result { // Wrap the cancel task in a FastSelect to avoid taking the channel lock // at each wakeup. - let mut cancel = pin!(self - .fast_select - .select((poll_fn(|cx| self.inner.poll_ready(cx)),))); + let mut cancel = pin!( + self.fast_select + .select((poll_fn(|cx| self.inner.poll_ready(cx)),)) + ); let mut fut = pin!(fut); @@ -574,8 +574,8 @@ mod tests { use crate::StopTask; use crate::TaskControl; use futures::FutureExt; - use pal_async::async_test; use pal_async::DefaultDriver; + use pal_async::async_test; use std::task::Poll; struct Foo(u32); diff --git a/support/test_with_tracing/test_with_tracing_macro/src/lib.rs b/support/test_with_tracing/test_with_tracing_macro/src/lib.rs index acc9862d25..614173e03e 100644 --- a/support/test_with_tracing/test_with_tracing_macro/src/lib.rs +++ b/support/test_with_tracing/test_with_tracing_macro/src/lib.rs @@ -4,10 +4,10 @@ //! Test attribute macro for `test_with_tracing` crate. use quote::quote; -use syn::parse_macro_input; -use syn::spanned::Spanned; use syn::Error; use syn::ItemFn; +use syn::parse_macro_input; +use syn::spanned::Spanned; /// Attribute macro on tests that have tracing output. /// diff --git a/support/tracing_helpers/src/formatter.rs b/support/tracing_helpers/src/formatter.rs index 0be4202d8a..87f4a37d51 100644 --- a/support/tracing_helpers/src/formatter.rs +++ b/support/tracing_helpers/src/formatter.rs @@ -8,8 +8,8 @@ use std::io; use std::io::Write; use tracing::field::Visit; use tracing_subscriber::field::RecordFields; -use tracing_subscriber::fmt::format::Writer; use tracing_subscriber::fmt::FormatFields; +use tracing_subscriber::fmt::format::Writer; struct FieldFormatterVisitor<'a> { writer: Writer<'a>, diff --git a/support/uevent/src/lib.rs b/support/uevent/src/lib.rs index 71f68ccf8f..3966526ca7 100644 --- a/support/uevent/src/lib.rs +++ b/support/uevent/src/lib.rs @@ -22,7 +22,6 @@ use pal_async::driver::SpawnDriver; use pal_async::socket::PolledSocket; use pal_async::task::Task; use socket2::Socket; -use std::future::Future; use std::io; use std::path::Path; use std::path::PathBuf; diff --git a/support/vmsocket/src/af_hyperv.rs b/support/vmsocket/src/af_hyperv.rs index 3fee197a21..017d64354e 100644 --- a/support/vmsocket/src/af_hyperv.rs +++ b/support/vmsocket/src/af_hyperv.rs @@ -18,14 +18,14 @@ use std::io; use std::os::raw::c_int; use std::os::windows::prelude::*; use std::time::Duration; -use windows_sys::Win32::Networking::WinSock::setsockopt; -use windows_sys::Win32::Networking::WinSock::WSAGetLastError; use windows_sys::Win32::Networking::WinSock::AF_HYPERV; use windows_sys::Win32::Networking::WinSock::SOCKET_ERROR; -use windows_sys::Win32::System::Hypervisor::HVSOCKET_CONNECT_TIMEOUT; +use windows_sys::Win32::Networking::WinSock::WSAGetLastError; +use windows_sys::Win32::Networking::WinSock::setsockopt; use windows_sys::Win32::System::Hypervisor::HV_GUID_PARENT; use windows_sys::Win32::System::Hypervisor::HV_GUID_ZERO; use windows_sys::Win32::System::Hypervisor::HV_PROTOCOL_RAW; +use windows_sys::Win32::System::Hypervisor::HVSOCKET_CONNECT_TIMEOUT; use windows_sys::Win32::System::Hypervisor::SOCKADDR_HV; /// Creates an AF_HYPERV service ID from an AF_VSOCK port. diff --git a/support/win_prng_support/src/lib.rs b/support/win_prng_support/src/lib.rs index 9b4a5d7c74..d31802fc90 100644 --- a/support/win_prng_support/src/lib.rs +++ b/support/win_prng_support/src/lib.rs @@ -117,8 +117,8 @@ pub mod private { #![allow(non_snake_case)] use std::ffi::c_void; - use widestring::u16cstr; use widestring::U16CStr; + use widestring::u16cstr; const BCRYPT_RNG_USE_ENTROPY_IN_BUFFER: u32 = 1; // ignored in Win8+ const BCRYPT_USE_SYSTEM_PREFERRED_RNG: u32 = 2; diff --git a/vm/aarch64/aarch64emu/src/cpu.rs b/vm/aarch64/aarch64emu/src/cpu.rs index bc905a7bcc..a2ae12bb35 100644 --- a/vm/aarch64/aarch64emu/src/cpu.rs +++ b/vm/aarch64/aarch64emu/src/cpu.rs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use std::future::Future; - pub trait Cpu: AccessCpuState { /// The error type for IO access failures. type Error; diff --git a/vm/aarch64/aarch64emu/src/emulator.rs b/vm/aarch64/aarch64emu/src/emulator.rs index 3d9264033d..19510ea9de 100644 --- a/vm/aarch64/aarch64emu/src/emulator.rs +++ b/vm/aarch64/aarch64emu/src/emulator.rs @@ -3,14 +3,14 @@ //! Implements an arm64 instruction emulator. -use crate::opcodes::decode_group; +use crate::Cpu; use crate::opcodes::Aarch64DecodeGroup; use crate::opcodes::Aarch64DecodeLoadStoreGroup; use crate::opcodes::LoadRegisterLiteral; use crate::opcodes::LoadStoreAtomic; use crate::opcodes::LoadStoreRegister; use crate::opcodes::LoadStoreRegisterPair; -use crate::Cpu; +use crate::opcodes::decode_group; use aarch64defs::EsrEl2; use inspect::Inspect; use thiserror::Error; diff --git a/vm/aarch64/aarch64emu/src/opcodes.rs b/vm/aarch64/aarch64emu/src/opcodes.rs index 940e4d7c60..9f8b64f9bf 100644 --- a/vm/aarch64/aarch64emu/src/opcodes.rs +++ b/vm/aarch64/aarch64emu/src/opcodes.rs @@ -3,9 +3,9 @@ //! Structs to parse aarch64 instructions. +use crate::Cpu; use crate::emulator::EmulatorOperations; use crate::emulator::Error; -use crate::Cpu; #[derive(Debug, PartialEq)] pub enum Aarch64DecodeGroup { @@ -333,7 +333,7 @@ impl LoadStoreRegister { let size = self.data_size()?; match size { LoadStoreRegisterByteCount::One => { - return Err(Box::new(Error::UnsupportedInstruction(self.0))) + return Err(Box::new(Error::UnsupportedInstruction(self.0))); } LoadStoreRegisterByteCount::Two => offset << 1, LoadStoreRegisterByteCount::Four => offset << 2, @@ -776,7 +776,7 @@ impl LoadStoreAtomic { return Err(Box::new(Error::UnsupportedLoadStoreInstruction( Aarch64DecodeLoadStoreGroup::Atomic, self.0, - ))) + ))); } }; let new_value = value & !size_mask | new_value & size_mask; diff --git a/vm/aarch64/aarch64emu/tests/load_store.rs b/vm/aarch64/aarch64emu/tests/load_store.rs index 0905b2a7d7..ee3a9407a7 100644 --- a/vm/aarch64/aarch64emu/tests/load_store.rs +++ b/vm/aarch64/aarch64emu/tests/load_store.rs @@ -9,10 +9,10 @@ use aarch64emu::Emulator; use aarch64emu::InterceptState; use pal_async::async_test; use parking_lot::Mutex; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; #[derive(Debug)] pub enum TestCpuError { diff --git a/vm/acpi_spec/src/madt.rs b/vm/acpi_spec/src/madt.rs index 8dbf104707..e30bdaf516 100644 --- a/vm/acpi_spec/src/madt.rs +++ b/vm/acpi_spec/src/madt.rs @@ -13,11 +13,11 @@ use zerocopy::FromZeros; use zerocopy::Immutable; use zerocopy::IntoBytes; use zerocopy::KnownLayout; -use zerocopy::Unaligned; use zerocopy::LE; use zerocopy::U16; use zerocopy::U32; use zerocopy::U64; +use zerocopy::Unaligned; #[repr(C, packed)] #[derive(Copy, Clone, Debug, IntoBytes, Immutable, KnownLayout, FromBytes, Unaligned)] diff --git a/vm/acpi_spec/src/pptt.rs b/vm/acpi_spec/src/pptt.rs index 15da483682..bb467a1ea6 100644 --- a/vm/acpi_spec/src/pptt.rs +++ b/vm/acpi_spec/src/pptt.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use crate::Table; use crate::packed_nums::u16_ne; use crate::packed_nums::u32_ne; -use crate::Table; use bitfield_struct::bitfield; use open_enum::open_enum; use zerocopy::FromBytes; diff --git a/vm/chipset_arc_mutex_device/src/device.rs b/vm/chipset_arc_mutex_device/src/device.rs index 1feeb6675d..88233d2b90 100644 --- a/vm/chipset_arc_mutex_device/src/device.rs +++ b/vm/chipset_arc_mutex_device/src/device.rs @@ -7,9 +7,9 @@ use crate::services::ChipsetServices; use arc_cyclic_builder::ArcCyclicBuilder; use arc_cyclic_builder::ArcCyclicBuilderExt; +use chipset_device::ChipsetDevice; use chipset_device::mmio::RegisterMmioIntercept; use chipset_device::pio::RegisterPortIoIntercept; -use chipset_device::ChipsetDevice; use closeable_mutex::CloseableMutex; use std::sync::Arc; use std::sync::Weak; @@ -266,7 +266,7 @@ where let dev = match (f)(&mut self.services) { Ok(dev) => dev, Err(e) => { - return Err(AddDeviceErrorKind::DeviceError(e.into()).with_dev_name(self.dev_name)) + return Err(AddDeviceErrorKind::DeviceError(e.into()).with_dev_name(self.dev_name)); } }; self.inner_add(Ok(dev)) @@ -285,7 +285,7 @@ where let dev = match (f)(&mut self.services).await { Ok(dev) => dev, Err(e) => { - return Err(AddDeviceErrorKind::DeviceError(e.into()).with_dev_name(self.dev_name)) + return Err(AddDeviceErrorKind::DeviceError(e.into()).with_dev_name(self.dev_name)); } }; self.inner_add(Ok(dev)) diff --git a/vm/chipset_arc_mutex_device/src/test_chipset.rs b/vm/chipset_arc_mutex_device/src/test_chipset.rs index 66a6b28384..e94b4de28a 100644 --- a/vm/chipset_arc_mutex_device/src/test_chipset.rs +++ b/vm/chipset_arc_mutex_device/src/test_chipset.rs @@ -9,10 +9,10 @@ use crate::services::ChipsetServices; use crate::services::ChipsetServicesMeta; use crate::services::MmioInterceptServices; use crate::services::Unimplemented; +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::mmio::ControlMmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; -use chipset_device::ChipsetDevice; use closeable_mutex::CloseableMutex; use parking_lot::RwLock; use range_map_vec::RangeMap; diff --git a/vm/chipset_device/src/io/deferred.rs b/vm/chipset_device/src/io/deferred.rs index 086fcbd1f5..4dc266731b 100644 --- a/vm/chipset_device/src/io/deferred.rs +++ b/vm/chipset_device/src/io/deferred.rs @@ -28,11 +28,10 @@ //! } //! ``` -use std::future::Future; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; /// Token to return in [`IoResult::Defer`](super::IoResult::Defer) for deferred /// IOs. diff --git a/vm/chipset_device/src/mmio.rs b/vm/chipset_device/src/mmio.rs index 5aeb9fddb5..e6bc58b902 100644 --- a/vm/chipset_device/src/mmio.rs +++ b/vm/chipset_device/src/mmio.rs @@ -3,8 +3,8 @@ //! MMIO intercepts -use crate::io::IoResult; use crate::ChipsetDevice; +use crate::io::IoResult; use std::ops::RangeInclusive; /// Implemented by devices which use MMIO intercepts. diff --git a/vm/chipset_device/src/pci.rs b/vm/chipset_device/src/pci.rs index 019792e384..2556fe7ec7 100644 --- a/vm/chipset_device/src/pci.rs +++ b/vm/chipset_device/src/pci.rs @@ -3,8 +3,8 @@ //! PCI configuration space access -use crate::io::IoResult; use crate::ChipsetDevice; +use crate::io::IoResult; /// Implemented by devices which have a PCI config space. pub trait PciConfigSpace: ChipsetDevice { diff --git a/vm/chipset_device/src/pio.rs b/vm/chipset_device/src/pio.rs index ef9254f71b..d64566b45a 100644 --- a/vm/chipset_device/src/pio.rs +++ b/vm/chipset_device/src/pio.rs @@ -3,8 +3,8 @@ //! Port IO intercepts -use crate::io::IoResult; use crate::ChipsetDevice; +use crate::io::IoResult; use std::ops::RangeInclusive; /// Implemented by devices which use port IO intercepts. diff --git a/vm/chipset_device_fuzz/src/lib.rs b/vm/chipset_device_fuzz/src/lib.rs index 57c9bead14..4f14fb4b03 100644 --- a/vm/chipset_device_fuzz/src/lib.rs +++ b/vm/chipset_device_fuzz/src/lib.rs @@ -13,13 +13,13 @@ use chipset_arc_mutex_device::services::MmioInterceptServices; use chipset_arc_mutex_device::services::PciConfigSpaceServices; use chipset_arc_mutex_device::services::PollDeviceServices; use chipset_arc_mutex_device::services::PortIoInterceptServices; -use chipset_device::io::deferred::DeferredToken; +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; +use chipset_device::io::deferred::DeferredToken; use chipset_device::mmio::ControlMmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; -use chipset_device::ChipsetDevice; use closeable_mutex::CloseableMutex; use parking_lot::RwLock; use range_map_vec::RangeMap; @@ -221,7 +221,9 @@ impl FuzzChipset { } } if self.max_defer_poll_count == 0 { - panic!("Device operation returned a deferred read. Call FuzzChipset::new and set a non-zero max_poll_count to poll async operations."); + panic!( + "Device operation returned a deferred read. Call FuzzChipset::new and set a non-zero max_poll_count to poll async operations." + ); } else { panic!( "Device operation returned a deferred read that didn't complete after {} polls", @@ -249,7 +251,9 @@ impl FuzzChipset { } } if self.max_defer_poll_count == 0 { - panic!("Device operation returned a deferred write. Call FuzzChipset::new and set a non-zero max_poll_count to poll async operations."); + panic!( + "Device operation returned a deferred write. Call FuzzChipset::new and set a non-zero max_poll_count to poll async operations." + ); } else { panic!( "Device operation returned a deferred write that didn't complete after {} polls", diff --git a/vm/chipset_device_resources/src/lib.rs b/vm/chipset_device_resources/src/lib.rs index 3dd5bd7bd9..519e6e93fe 100644 --- a/vm/chipset_device_resources/src/lib.rs +++ b/vm/chipset_device_resources/src/lib.rs @@ -10,8 +10,8 @@ use chipset_device::ChipsetDevice; use guestmem::GuestMemory; use inspect::InspectMut; use std::ops::RangeInclusive; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::CanResolveTo; +use vm_resource::kind::ChipsetDeviceHandleKind; use vmcore::device_state::ChangeDeviceState; use vmcore::line_interrupt::LineInterrupt; use vmcore::save_restore::ProtobufSaveRestore; diff --git a/vm/cvm_tracing/src/lib.rs b/vm/cvm_tracing/src/lib.rs index 192616f6ec..c3b78a6534 100644 --- a/vm/cvm_tracing/src/lib.rs +++ b/vm/cvm_tracing/src/lib.rs @@ -11,8 +11,8 @@ #![forbid(unsafe_code)] -use tracing::field::Empty; use tracing::Subscriber; +use tracing::field::Empty; use tracing_subscriber::filter::FilterFn; use tracing_subscriber::layer::Filter; @@ -33,11 +33,11 @@ pub fn confidential_event_filter() -> impl Filter { mod test { use crate::CVM_ALLOWED; use crate::CVM_CONFIDENTIAL; - use std::sync::atomic::AtomicU32; use std::sync::Arc; + use std::sync::atomic::AtomicU32; use tracing::Subscriber; - use tracing_subscriber::layer::SubscriberExt; use tracing_subscriber::Layer; + use tracing_subscriber::layer::SubscriberExt; struct TestLayer { count: Arc, diff --git a/vm/devices/chipset/fuzz/fuzz_battery.rs b/vm/devices/chipset/fuzz/fuzz_battery.rs index ad650ecebf..f0f2daf448 100644 --- a/vm/devices/chipset/fuzz/fuzz_battery.rs +++ b/vm/devices/chipset/fuzz/fuzz_battery.rs @@ -5,9 +5,9 @@ #![expect(missing_docs)] use arbitrary::Unstructured; +use chipset::battery::BATTERY_MMIO_REGION_BASE_ADDRESS_X64; use chipset::battery::BatteryDevice; use chipset::battery::BatteryRuntimeDeps; -use chipset::battery::BATTERY_MMIO_REGION_BASE_ADDRESS_X64; use chipset_resources::battery::HostBatteryUpdate; use vmcore::line_interrupt::LineInterrupt; use xtask_fuzz::fuzz_eprintln; diff --git a/vm/devices/chipset/src/battery/mod.rs b/vm/devices/chipset/src/battery/mod.rs index 7968366d5b..f9a763143d 100644 --- a/vm/devices/chipset/src/battery/mod.rs +++ b/vm/devices/chipset/src/battery/mod.rs @@ -31,11 +31,11 @@ pub mod resolver; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use chipset_resources::battery::HostBatteryUpdate; use futures::StreamExt; use inspect::Inspect; @@ -274,7 +274,9 @@ impl PollDevice for BatteryDevice { if self.state.battery_present && self.state.max_capacity == 0 { // This configuration makes no sense. Just report no battery, // and set AC power accordingly. - tracelimit::warn_ratelimited!("BATTERY: Invalid state: max_capacity is 0 but battery is present. Marking battery as not present."); + tracelimit::warn_ratelimited!( + "BATTERY: Invalid state: max_capacity is 0 but battery is present. Marking battery as not present." + ); self.state.battery_present = false; } // Add the corresponding status bit to notification status diff --git a/vm/devices/chipset/src/battery/resolver.rs b/vm/devices/chipset/src/battery/resolver.rs index 7efb88ecf7..c31815d07a 100644 --- a/vm/devices/chipset/src/battery/resolver.rs +++ b/vm/devices/chipset/src/battery/resolver.rs @@ -3,25 +3,25 @@ //! Resolver for battery devices. -use super::BatteryDevice; -use super::BatteryRuntimeDeps; use super::BATTERY_MMIO_REGION_BASE_ADDRESS_ARM; use super::BATTERY_MMIO_REGION_BASE_ADDRESS_X64; use super::BATTERY_STATUS_GPE0_LINE; use super::BATTERY_STATUS_IRQ_NO; +use super::BatteryDevice; +use super::BatteryRuntimeDeps; use async_trait::async_trait; -use chipset_device_resources::ResolveChipsetDeviceHandleParams; -use chipset_device_resources::ResolvedChipsetDevice; use chipset_device_resources::GPE0_LINE_SET; use chipset_device_resources::IRQ_LINE_SET; +use chipset_device_resources::ResolveChipsetDeviceHandleParams; +use chipset_device_resources::ResolvedChipsetDevice; use chipset_resources::battery::BatteryDeviceHandleAArch64; use chipset_resources::battery::BatteryDeviceHandleX64; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::ChipsetDeviceHandleKind; /// A resolver for battery devices. pub struct BatteryResolver; diff --git a/vm/devices/chipset/src/cmos_rtc.rs b/vm/devices/chipset/src/cmos_rtc.rs index cf52d9e1aa..e23b51d513 100644 --- a/vm/devices/chipset/src/cmos_rtc.rs +++ b/vm/devices/chipset/src/cmos_rtc.rs @@ -7,16 +7,16 @@ #![warn(missing_docs)] use self::spec::CmosReg; +use self::spec::ENABLE_OSCILLATOR_CONTROL; use self::spec::StatusRegA; use self::spec::StatusRegB; use self::spec::StatusRegC; use self::spec::StatusRegD; -use self::spec::ENABLE_OSCILLATOR_CONTROL; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use local_clock::InspectableLocalClock; @@ -1206,7 +1206,10 @@ mod tests { let elapsed = end - start; let expected = Duration::from_secs(seconds_to_wait as u64); let allowance = Duration::from_secs(1); - println!("Expected: {:?} Start: {:?} End: {:?} Elapsed: {:?} Allowance: {:?}, RTC generates update strobe at expected rate.", expected, start, end, elapsed, allowance); + println!( + "Expected: {:?} Start: {:?} End: {:?} Elapsed: {:?} Allowance: {:?}, RTC generates update strobe at expected rate.", + expected, start, end, elapsed, allowance + ); assert!(elapsed <= (expected + allowance) && elapsed >= (expected - allowance)); } else { panic!("get_cmos_date_time failed"); diff --git a/vm/devices/chipset/src/dma.rs b/vm/devices/chipset/src/dma.rs index fa2decbb60..9cceec22a3 100644 --- a/vm/devices/chipset/src/dma.rs +++ b/vm/devices/chipset/src/dma.rs @@ -18,10 +18,10 @@ #![warn(missing_docs)] +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::PortIoIntercept; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use open_enum::open_enum; diff --git a/vm/devices/chipset/src/i8042/mod.rs b/vm/devices/chipset/src/i8042/mod.rs index 27f5e1b598..f15b86d359 100644 --- a/vm/devices/chipset/src/i8042/mod.rs +++ b/vm/devices/chipset/src/i8042/mod.rs @@ -12,11 +12,11 @@ mod spec; use self::ps2keyboard::Ps2Keyboard; use self::ps2mouse::Ps2Mouse; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use input_core::InputSource; use input_core::KeyboardData; use inspect::Inspect; diff --git a/vm/devices/chipset/src/i8042/ps2keyboard.rs b/vm/devices/chipset/src/i8042/ps2keyboard.rs index be96bfced1..6196cb2f6d 100644 --- a/vm/devices/chipset/src/i8042/ps2keyboard.rs +++ b/vm/devices/chipset/src/i8042/ps2keyboard.rs @@ -3,8 +3,8 @@ //! PS/2 keyboard. -use self::spec::Ps2KeyboardCommand; use self::spec::ACKNOWLEDGE_COMMAND; +use self::spec::Ps2KeyboardCommand; use futures::Stream; use input_core::InputSource; use input_core::KeyboardData; diff --git a/vm/devices/chipset/src/i8042/resolver.rs b/vm/devices/chipset/src/i8042/resolver.rs index e3ebff6e48..8870d8c8c8 100644 --- a/vm/devices/chipset/src/i8042/resolver.rs +++ b/vm/devices/chipset/src/i8042/resolver.rs @@ -5,20 +5,20 @@ use super::I8042Device; use async_trait::async_trait; +use chipset_device_resources::IRQ_LINE_SET; use chipset_device_resources::ResolveChipsetDeviceHandleParams; use chipset_device_resources::ResolvedChipsetDevice; -use chipset_device_resources::IRQ_LINE_SET; use chipset_resources::i8042::I8042DeviceHandle; use power_resources::PowerRequest; use power_resources::PowerRequestHandleKind; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::IntoResource; use vm_resource::PlatformResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::ChipsetDeviceHandleKind; /// A resolver for i8042 devices. pub struct I8042Resolver; diff --git a/vm/devices/chipset/src/ioapic.rs b/vm/devices/chipset/src/ioapic.rs index 2111c94f28..b5f0466b8e 100644 --- a/vm/devices/chipset/src/ioapic.rs +++ b/vm/devices/chipset/src/ioapic.rs @@ -6,21 +6,21 @@ //! Currently this supports IO-APIC version 0x11, from the PIIX4 era. This //! version does not support an EOI register (unlike version 0x20 and newer). +use self::spec::IO_APIC_VERSION; +use self::spec::IOAPIC_DEVICE_MMIO_REGION_SIZE; use self::spec::IndexRegister; use self::spec::IoApicId; use self::spec::IoApicVersion; -use self::spec::RedirectionEntry; -use self::spec::IOAPIC_DEVICE_MMIO_REGION_SIZE; -use self::spec::IO_APIC_VERSION; use self::spec::REDIRECTION_WRITE_MASK; -use crate::ioapic::spec::Register; +use self::spec::RedirectionEntry; use crate::ioapic::spec::IOAPIC_DEVICE_MMIO_REGION_MASK; +use crate::ioapic::spec::Register; +use chipset_device::ChipsetDevice; use chipset_device::interrupt::HandleEoi; use chipset_device::interrupt::LineInterruptTarget; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use inspect_counters::Counter; @@ -416,9 +416,9 @@ impl ChipsetDevice for IoApicDevice { } mod save_restore { + use super::IoApicDevice; use super::spec::IndexRegister; use super::spec::RedirectionEntry; - use super::IoApicDevice; use thiserror::Error; use vmcore::save_restore::RestoreError; use vmcore::save_restore::SaveError; diff --git a/vm/devices/chipset/src/pic.rs b/vm/devices/chipset/src/pic.rs index e93952fb52..11f1860bb9 100644 --- a/vm/devices/chipset/src/pic.rs +++ b/vm/devices/chipset/src/pic.rs @@ -2,6 +2,7 @@ // Licensed under the MIT License. use bitfield_struct::bitfield; +use chipset_device::ChipsetDevice; use chipset_device::interrupt::AcknowledgePicInterrupt; use chipset_device::interrupt::LineInterruptTarget; use chipset_device::io::IoError; @@ -9,7 +10,6 @@ use chipset_device::io::IoResult; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use inspect_counters::Counter; @@ -555,10 +555,10 @@ struct Ocw3 { mod save_restore { use super::DualPic; + use super::IRQ_MASK; use super::InitStage; use super::Ocw3; use super::Pic; - use super::IRQ_MASK; use thiserror::Error; use vmcore::save_restore::RestoreError; use vmcore::save_restore::SaveError; diff --git a/vm/devices/chipset/src/pit.rs b/vm/devices/chipset/src/pit.rs index 285a751c9f..9832610462 100644 --- a/vm/devices/chipset/src/pit.rs +++ b/vm/devices/chipset/src/pit.rs @@ -2,11 +2,11 @@ // Licensed under the MIT License. use bitfield_struct::bitfield; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use open_enum::open_enum; @@ -862,11 +862,11 @@ mod save_restore { #[cfg(test)] mod tests { - use super::to_bcd; use super::ControlWord; use super::Mode; use super::RwMode; use super::Timer; + use super::to_bcd; use crate::pit::from_bcd; #[test] diff --git a/vm/devices/chipset/src/pm.rs b/vm/devices/chipset/src/pm.rs index 6eb64c3024..905649a1bf 100644 --- a/vm/devices/chipset/src/pm.rs +++ b/vm/devices/chipset/src/pm.rs @@ -28,13 +28,13 @@ #![warn(missing_docs)] +use chipset_device::ChipsetDevice; use chipset_device::interrupt::LineInterruptTarget; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use open_enum::open_enum; diff --git a/vm/devices/chipset_legacy/src/i440bx_host_pci_bridge.rs b/vm/devices/chipset_legacy/src/i440bx_host_pci_bridge.rs index 2c54200cf4..7848cf77cb 100644 --- a/vm/devices/chipset_legacy/src/i440bx_host_pci_bridge.rs +++ b/vm/devices/chipset_legacy/src/i440bx_host_pci_bridge.rs @@ -5,10 +5,10 @@ pub use pam::GpaState; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pci::PciConfigSpace; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use memory_range::MemoryRange; diff --git a/vm/devices/chipset_legacy/src/piix4_cmos_rtc.rs b/vm/devices/chipset_legacy/src/piix4_cmos_rtc.rs index 39b9e897f1..d32668c78c 100644 --- a/vm/devices/chipset_legacy/src/piix4_cmos_rtc.rs +++ b/vm/devices/chipset_legacy/src/piix4_cmos_rtc.rs @@ -5,11 +5,11 @@ //! //! Extends basic x86 CMOS RTC with a few additional ports + more RAM. +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use local_clock::InspectableLocalClock; @@ -95,10 +95,10 @@ impl PortIoIntercept for Piix4CmosRtc { // (zero-extended to the size of the access). data[0] = match Piix4CmosRtcIoPort(io_port) { Piix4CmosRtcIoPort::ADDRESS | Piix4CmosRtcIoPort::DATA => { - return self.inner.io_read(io_port, data) + return self.inner.io_read(io_port, data); } Piix4CmosRtcIoPort::ADDRESS_SHADOW_2 | Piix4CmosRtcIoPort::DATA_SHADOW_2 => { - return self.inner.io_read(io_port - 4, data) + return self.inner.io_read(io_port - 4, data); } Piix4CmosRtcIoPort::EXTENDED_ADDRESS | Piix4CmosRtcIoPort::ADDRESS_SHADOW_3 => { self.state.ext_addr @@ -118,10 +118,10 @@ impl PortIoIntercept for Piix4CmosRtc { // (zero-extended to the size of the access). match Piix4CmosRtcIoPort(io_port) { Piix4CmosRtcIoPort::ADDRESS | Piix4CmosRtcIoPort::DATA => { - return self.inner.io_write(io_port, data) + return self.inner.io_write(io_port, data); } Piix4CmosRtcIoPort::ADDRESS_SHADOW_2 | Piix4CmosRtcIoPort::DATA_SHADOW_2 => { - return self.inner.io_write(io_port - 4, data) + return self.inner.io_write(io_port - 4, data); } Piix4CmosRtcIoPort::EXTENDED_ADDRESS | Piix4CmosRtcIoPort::ADDRESS_SHADOW_3 => { self.state.ext_addr = data[0] & 0x7F; diff --git a/vm/devices/chipset_legacy/src/piix4_pci_bus.rs b/vm/devices/chipset_legacy/src/piix4_pci_bus.rs index 8d4caf4c27..a4d1b92883 100644 --- a/vm/devices/chipset_legacy/src/piix4_pci_bus.rs +++ b/vm/devices/chipset_legacy/src/piix4_pci_bus.rs @@ -3,11 +3,11 @@ //! PIIX4 - PCI bus +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use inspect::InspectMut; use pci_bus::GenericPciBus; use vmcore::device_state::ChangeDeviceState; diff --git a/vm/devices/chipset_legacy/src/piix4_pci_isa_bridge.rs b/vm/devices/chipset_legacy/src/piix4_pci_isa_bridge.rs index d8dfbaa860..b29d9a11f9 100644 --- a/vm/devices/chipset_legacy/src/piix4_pci_isa_bridge.rs +++ b/vm/devices/chipset_legacy/src/piix4_pci_isa_bridge.rs @@ -3,11 +3,11 @@ //! PIIX4 - PCI to ISA Bridge +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pci::PciConfigSpace; use chipset_device::pio::PortIoIntercept; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use open_enum::open_enum; diff --git a/vm/devices/chipset_legacy/src/piix4_pm.rs b/vm/devices/chipset_legacy/src/piix4_pm.rs index 58bdd205cb..0bc4984197 100644 --- a/vm/devices/chipset_legacy/src/piix4_pm.rs +++ b/vm/devices/chipset_legacy/src/piix4_pm.rs @@ -7,6 +7,7 @@ use chipset::pm::PmTimerAssist; use chipset::pm::PowerAction; use chipset::pm::PowerActionFn; use chipset::pm::PowerManagementDevice; +use chipset_device::ChipsetDevice; use chipset_device::interrupt::LineInterruptTarget; use chipset_device::io::IoError; use chipset_device::io::IoResult; @@ -14,7 +15,6 @@ use chipset_device::pci::PciConfigSpace; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use open_enum::open_enum; diff --git a/vm/devices/chipset_legacy/src/piix4_uhci.rs b/vm/devices/chipset_legacy/src/piix4_uhci.rs index 24cf9637c6..999ad7322d 100644 --- a/vm/devices/chipset_legacy/src/piix4_uhci.rs +++ b/vm/devices/chipset_legacy/src/piix4_uhci.rs @@ -3,10 +3,10 @@ //! PIIX4 - USB configuration +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pci::PciConfigSpace; -use chipset_device::ChipsetDevice; use inspect::InspectMut; use vmcore::device_state::ChangeDeviceState; diff --git a/vm/devices/chipset_legacy/src/winbond83977_sio/mod.rs b/vm/devices/chipset_legacy/src/winbond83977_sio/mod.rs index 2300b30619..509be98e74 100644 --- a/vm/devices/chipset_legacy/src/winbond83977_sio/mod.rs +++ b/vm/devices/chipset_legacy/src/winbond83977_sio/mod.rs @@ -13,12 +13,12 @@ pub use self::maybe_floppy_disk_controller::MaybeStubFloppyDiskController; use self::super_io::SioController; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use floppy::DriveRibbon; use guestmem::GuestMemory; use inspect::InspectMut; @@ -193,10 +193,10 @@ impl PortIoIntercept for Winbond83977FloppyS } mod maybe_floppy_disk_controller { + use chipset_device::ChipsetDevice; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; - use chipset_device::ChipsetDevice; use floppy::DriveRibbon; use guestmem::GuestMemory; use inspect::InspectMut; diff --git a/vm/devices/chipset_resources/src/lib.rs b/vm/devices/chipset_resources/src/lib.rs index 66d6b6402d..5afdcf2e09 100644 --- a/vm/devices/chipset_resources/src/lib.rs +++ b/vm/devices/chipset_resources/src/lib.rs @@ -9,10 +9,10 @@ pub mod i8042 { //! Resource definitions for the i8042 PS2 keyboard/mouse controller. use mesh::MeshPayload; - use vm_resource::kind::ChipsetDeviceHandleKind; - use vm_resource::kind::KeyboardInputHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; + use vm_resource::kind::ChipsetDeviceHandleKind; + use vm_resource::kind::KeyboardInputHandleKind; /// A handle to an i8042 PS2 keyboard/mouse controller controller. #[derive(MeshPayload)] @@ -33,8 +33,8 @@ pub mod battery { use arbitrary::Arbitrary; use inspect::Inspect; use mesh::MeshPayload; - use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::ResourceId; + use vm_resource::kind::ChipsetDeviceHandleKind; /// A handle to a battery device for x64 #[derive(MeshPayload)] pub struct BatteryDeviceHandleX64 { diff --git a/vm/devices/firmware/firmware_pcat/src/lib.rs b/vm/devices/firmware/firmware_pcat/src/lib.rs index e3adbbfd84..f44deb5275 100644 --- a/vm/devices/firmware/firmware_pcat/src/lib.rs +++ b/vm/devices/firmware/firmware_pcat/src/lib.rs @@ -19,17 +19,17 @@ mod root_cpu_data; pub use default_cmos_values::default_cmos_values; use self::bios_boot_order::bios_boot_order; -use chipset_device::io::deferred::defer_write; -use chipset_device::io::deferred::DeferredToken; -use chipset_device::io::deferred::DeferredWrite; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; +use chipset_device::io::deferred::DeferredToken; +use chipset_device::io::deferred::DeferredWrite; +use chipset_device::io::deferred::defer_write; use chipset_device::mmio::MmioIntercept; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use guestmem::GuestMemory; use guestmem::MapRom; use guestmem::UnmapRom; @@ -52,8 +52,8 @@ pub mod config { use guid::Guid; use inspect::Inspect; use vm_topology::memory::MemoryLayout; - use vm_topology::processor::x86::X86Topology; use vm_topology::processor::ProcessorTopology; + use vm_topology::processor::x86::X86Topology; /// Subset of SMBIOS v2.4 CPU Information structure. #[derive(Debug, Inspect)] @@ -535,7 +535,7 @@ impl PcatBiosDevice { PcatAddress::WAIT_NANO100 => { return Ok(Some( self.defer_wait(Duration::from_nanos(data as u64 * 100)), - )) + )); } PcatAddress::GENERATION_ID_PTR_LOW => self.generation_id.write_generation_id_low(data), PcatAddress::GENERATION_ID_PTR_HIGH => { @@ -560,13 +560,13 @@ impl PcatBiosDevice { // register (so as to save an additional VMEXIT). match PcatAddress(addr) { PcatAddress::WAIT1_MILLISECOND => { - return Some(self.defer_wait(Duration::from_millis(1))) + return Some(self.defer_wait(Duration::from_millis(1))); } PcatAddress::WAIT10_MILLISECONDS => { - return Some(self.defer_wait(Duration::from_millis(10))) + return Some(self.defer_wait(Duration::from_millis(10))); } PcatAddress::WAIT2_MILLISECOND => { - return Some(self.defer_wait(Duration::from_millis(2))) + return Some(self.defer_wait(Duration::from_millis(2))); } PcatAddress::REPORT_BOOT_FAILURE => { tracelimit::info_ratelimited!("pcat boot: failure"); diff --git a/vm/devices/firmware/firmware_uefi/fuzz/fuzz_firmware_uefi.rs b/vm/devices/firmware/firmware_uefi/fuzz/fuzz_firmware_uefi.rs index 6fbf50692a..727eb436b1 100644 --- a/vm/devices/firmware/firmware_uefi/fuzz/fuzz_firmware_uefi.rs +++ b/vm/devices/firmware/firmware_uefi/fuzz/fuzz_firmware_uefi.rs @@ -7,8 +7,8 @@ use arbitrary::Arbitrary; use firmware_uefi::platform::nvram::EFI_TIME; -use firmware_uefi::service::nvram::spec_services::auth_var_crypto; use firmware_uefi::service::nvram::spec_services::ParsedAuthVar; +use firmware_uefi::service::nvram::spec_services::auth_var_crypto; use guid::Guid; use openssl::asn1::Asn1Time; use openssl::hash::MessageDigest; @@ -19,10 +19,10 @@ use openssl::pkey::PKeyRef; use openssl::pkey::Private; use openssl::rsa::Rsa; use openssl::stack::Stack; +use openssl::x509::X509; use openssl::x509::X509Builder; use openssl::x509::X509NameBuilder; use openssl::x509::X509Ref; -use openssl::x509::X509; use std::borrow::Cow; use ucs2::Ucs2LeVec; use uefi_nvram_specvars::signature_list::SignatureData; diff --git a/vm/devices/firmware/firmware_uefi/src/lib.rs b/vm/devices/firmware/firmware_uefi/src/lib.rs index cfd7f33b37..13d505d0d7 100644 --- a/vm/devices/firmware/firmware_uefi/src/lib.rs +++ b/vm/devices/firmware/firmware_uefi/src/lib.rs @@ -56,12 +56,12 @@ pub mod service; #[cfg(not(feature = "fuzzing"))] mod service; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use firmware_uefi_custom_vars::CustomVars; use guestmem::GuestMemory; use inspect::Inspect; diff --git a/vm/devices/firmware/firmware_uefi/src/service/event_log.rs b/vm/devices/firmware/firmware_uefi/src/service/event_log.rs index eceaaa30b8..23dd563a38 100644 --- a/vm/devices/firmware/firmware_uefi/src/service/event_log.rs +++ b/vm/devices/firmware/firmware_uefi/src/service/event_log.rs @@ -3,10 +3,10 @@ //! UEFI Event Logging subsystem. +use crate::UefiDevice; use crate::platform::logger::BootInfo; use crate::platform::logger::UefiEvent; use crate::platform::logger::UefiLogger; -use crate::UefiDevice; use guestmem::GuestMemory; use guestmem::GuestMemoryError; use inspect::Inspect; diff --git a/vm/devices/firmware/firmware_uefi/src/service/nvram/mod.rs b/vm/devices/firmware/firmware_uefi/src/service/nvram/mod.rs index 6b8d3aa87d..a438b3af4a 100644 --- a/vm/devices/firmware/firmware_uefi/src/service/nvram/mod.rs +++ b/vm/devices/firmware/firmware_uefi/src/service/nvram/mod.rs @@ -16,8 +16,8 @@ pub use spec_services::NvramResult; pub use spec_services::NvramServicesExt; pub use spec_services::NvramSpecServices; -use crate::platform::nvram::VsmConfig; use crate::UefiDevice; +use crate::platform::nvram::VsmConfig; use firmware_uefi_custom_vars::CustomVars; use guestmem::GuestMemoryError; use inspect::Inspect; diff --git a/vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/auth_var_crypto.rs b/vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/auth_var_crypto.rs index b389f90605..f59c2f544e 100644 --- a/vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/auth_var_crypto.rs +++ b/vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/auth_var_crypto.rs @@ -171,13 +171,13 @@ pub fn authenticate_variable( } mod pkcs7_details { - use der::asn1::AnyRef; - use der::asn1::ContextSpecific; - use der::asn1::ObjectIdentifier; use der::Encode; use der::Sequence; use der::TagMode; use der::TagNumber; + use der::asn1::AnyRef; + use der::asn1::ContextSpecific; + use der::asn1::ObjectIdentifier; #[derive(Copy, Clone, Debug, Eq, PartialEq, Sequence)] struct ContentInfo<'a> { diff --git a/vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/mod.rs b/vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/mod.rs index 224a23638a..be44329294 100644 --- a/vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/mod.rs +++ b/vm/devices/firmware/firmware_uefi/src/service/nvram/spec_services/mod.rs @@ -567,7 +567,7 @@ impl NvramSpecServices { (), EfiStatus::DEVICE_ERROR, Some(NvramError::NvramStorage(err)), - ) + ); } }; @@ -690,8 +690,8 @@ impl NvramSpecServices { // UEFI spec 8.2.2 - Using the EFI_VARIABLE_AUTHENTICATION_2 descriptor use uefi_specs::uefi::nvram::EFI_VARIABLE_AUTHENTICATION_2; use uefi_specs::uefi::signing::EFI_CERT_TYPE_PKCS7_GUID; - use uefi_specs::uefi::signing::WIN_CERTIFICATE_UEFI_GUID; use uefi_specs::uefi::signing::WIN_CERT_TYPE_EFI_GUID; + use uefi_specs::uefi::signing::WIN_CERTIFICATE_UEFI_GUID; tracing::trace!( "variable is attempting to use TIME_BASED_AUTHENTICATED_WRITE_ACCESS" @@ -705,7 +705,7 @@ impl NvramSpecServices { (), EfiStatus::INVALID_PARAMETER, Some(NvramError::DataNull), - ) + ); } }; @@ -719,7 +719,7 @@ impl NvramSpecServices { (), EfiStatus::SECURITY_VIOLATION, Some(NvramError::AuthError(AuthError::NotEnoughHdrData)), - ) + ); } }; let timestamp = auth_hdr.timestamp; @@ -1037,7 +1037,7 @@ impl NvramSpecServices { (0, _) => return NvramResult((), EfiStatus::SUCCESS, None), // If data len is non-zero, data cannot be nullptr (_, None) => { - return NvramResult((), EfiStatus::SUCCESS, Some(NvramError::DataNull)) + return NvramResult((), EfiStatus::SUCCESS, Some(NvramError::DataNull)); } (_, Some(data)) => data, }; @@ -1105,7 +1105,7 @@ impl NvramSpecServices { (), EfiStatus::INVALID_PARAMETER, Some(NvramError::SignatureList(e)), - ) + ); } }; @@ -1214,7 +1214,7 @@ impl NvramSpecServices { (), EfiStatus::INVALID_PARAMETER, Some(NvramError::DataNull), - ) + ); } }; @@ -1304,7 +1304,9 @@ impl NvramSpecServices { _: (Guid, &Ucs2LeSlice), _: ParsedAuthVar<'_>, ) -> Result<(), (EfiStatus, Option)> { - tracing::warn!("compiled without 'auth-var-verify-crypto' - unconditionally failing auth var validation!"); + tracing::warn!( + "compiled without 'auth-var-verify-crypto' - unconditionally failing auth var validation!" + ); Err((EfiStatus::SECURITY_VIOLATION, None)) } @@ -1391,7 +1393,7 @@ impl NvramSpecServices { loop { match res { Ok(NextVariable::EndOfList) => { - return NvramResult(None, EfiStatus::NOT_FOUND, None) + return NvramResult(None, EfiStatus::NOT_FOUND, None); } Ok(NextVariable::InvalidKey) => { return NvramResult(None, EfiStatus::INVALID_PARAMETER, None); diff --git a/vm/devices/firmware/firmware_uefi/src/service/time.rs b/vm/devices/firmware/firmware_uefi/src/service/time.rs index e70e0b0c28..2cdd0f818b 100644 --- a/vm/devices/firmware/firmware_uefi/src/service/time.rs +++ b/vm/devices/firmware/firmware_uefi/src/service/time.rs @@ -15,9 +15,9 @@ use thiserror::Error; use time::OffsetDateTime; use uefi_specs::hyperv::time::VmEfiTime; use uefi_specs::uefi::common::EfiStatus; +use uefi_specs::uefi::time::EFI_TIME; use uefi_specs::uefi::time::EfiDaylight; use uefi_specs::uefi::time::EfiTimezone; -use uefi_specs::uefi::time::EFI_TIME; #[derive(Debug, Error)] pub enum TimeServiceError { diff --git a/vm/devices/firmware/firmware_uefi/src/service/uefi_watchdog.rs b/vm/devices/firmware/firmware_uefi/src/service/uefi_watchdog.rs index 5d9512d719..c846c5c937 100644 --- a/vm/devices/firmware/firmware_uefi/src/service/uefi_watchdog.rs +++ b/vm/devices/firmware/firmware_uefi/src/service/uefi_watchdog.rs @@ -4,8 +4,8 @@ use crate::UefiDevice; use inspect::Inspect; use vmcore::vmtime::VmTimeAccess; -use watchdog_core::platform::WatchdogPlatform; use watchdog_core::WatchdogServices; +use watchdog_core::platform::WatchdogPlatform; #[derive(Inspect)] pub struct UefiWatchdogServices { diff --git a/vm/devices/firmware/hcl_compat_uefi_nvram_storage/src/lib.rs b/vm/devices/firmware/hcl_compat_uefi_nvram_storage/src/lib.rs index c6493e99d8..311ca8fafe 100644 --- a/vm/devices/firmware/hcl_compat_uefi_nvram_storage/src/lib.rs +++ b/vm/devices/firmware/hcl_compat_uefi_nvram_storage/src/lib.rs @@ -20,11 +20,11 @@ use guid::Guid; use std::fmt::Debug; use storage_backend::StorageBackend; use ucs2::Ucs2LeSlice; -use uefi_nvram_storage::in_memory; +use uefi_nvram_storage::EFI_TIME; use uefi_nvram_storage::NextVariable; use uefi_nvram_storage::NvramStorage; use uefi_nvram_storage::NvramStorageError; -use uefi_nvram_storage::EFI_TIME; +use uefi_nvram_storage::in_memory; use zerocopy::FromBytes; use zerocopy::Immutable; use zerocopy::IntoBytes; @@ -190,7 +190,7 @@ impl HclCompatNvram { _ => { return Err(NvramStorageError::Load( format!("unknown header type: {:?}", header.header_type).into(), - )) + )); } } diff --git a/vm/devices/firmware/hyperv_uefi_custom_vars_json/src/lib.rs b/vm/devices/firmware/hyperv_uefi_custom_vars_json/src/lib.rs index 11d4787228..e9ee6a8f6c 100644 --- a/vm/devices/firmware/hyperv_uefi_custom_vars_json/src/lib.rs +++ b/vm/devices/firmware/hyperv_uefi_custom_vars_json/src/lib.rs @@ -41,13 +41,13 @@ pub enum JsonToTemplateError { pub fn load_template_from_json( data: &[u8], ) -> Result { + use firmware_uefi_custom_vars::CustomVars; + use firmware_uefi_custom_vars::Signature; + use firmware_uefi_custom_vars::Signatures; use firmware_uefi_custom_vars::delta::CustomVarsDelta; use firmware_uefi_custom_vars::delta::SignatureDelta; use firmware_uefi_custom_vars::delta::SignatureDeltaVec; use firmware_uefi_custom_vars::delta::SignaturesDelta; - use firmware_uefi_custom_vars::CustomVars; - use firmware_uefi_custom_vars::Signature; - use firmware_uefi_custom_vars::Signatures; fn deny_default(sig: SignatureDelta) -> Result { match sig { @@ -257,7 +257,7 @@ mod json { return Err(serde::de::Error::custom(format!( "expected 4 bytes. found {} bytes", other.len() - ))) + ))); } }; Ok(u32::from_le_bytes(v)) diff --git a/vm/devices/firmware/uefi_nvram_storage/src/in_memory.rs b/vm/devices/firmware/uefi_nvram_storage/src/in_memory.rs index 3000d7f42a..9819d2d130 100644 --- a/vm/devices/firmware/uefi_nvram_storage/src/in_memory.rs +++ b/vm/devices/firmware/uefi_nvram_storage/src/in_memory.rs @@ -4,10 +4,10 @@ //! Provides an in-memory implementation of [`NvramStorage`] that doesn't //! automatically persist to disk. +use crate::EFI_TIME; use crate::NextVariable; use crate::NvramStorage; use crate::NvramStorageError; -use crate::EFI_TIME; use guid::Guid; use std::collections::BTreeMap; use std::fmt::Display; @@ -188,9 +188,9 @@ impl NvramStorage for InMemoryNvram { /// A collection of test-implementation helpers that operate on a generic /// implementation of [`NvramStorage`] pub mod impl_agnostic_tests { + use crate::EFI_TIME; use crate::NextVariable; use crate::NvramStorage; - use crate::EFI_TIME; use guid::Guid; use ucs2::Ucs2LeSlice; use wchar::wchz; diff --git a/vm/devices/firmware/uefi_specs/src/uefi/nvram.rs b/vm/devices/firmware/uefi_specs/src/uefi/nvram.rs index 347e564209..634325111f 100644 --- a/vm/devices/firmware/uefi_specs/src/uefi/nvram.rs +++ b/vm/devices/firmware/uefi_specs/src/uefi/nvram.rs @@ -77,8 +77,8 @@ impl EFI_VARIABLE_AUTHENTICATION_2 { /// itself. pub const DUMMY: Self = { use crate::uefi::signing::EFI_CERT_TYPE_PKCS7_GUID; - use crate::uefi::signing::WIN_CERTIFICATE; use crate::uefi::signing::WIN_CERT_TYPE_EFI_GUID; + use crate::uefi::signing::WIN_CERTIFICATE; EFI_VARIABLE_AUTHENTICATION_2 { timestamp: EFI_TIME::ZEROED, diff --git a/vm/devices/framebuffer/src/lib.rs b/vm/devices/framebuffer/src/lib.rs index 4057f8508b..f6f104fac1 100644 --- a/vm/devices/framebuffer/src/lib.rs +++ b/vm/devices/framebuffer/src/lib.rs @@ -27,8 +27,8 @@ use guestmem::MemoryMapper; use inspect::Inspect; use inspect::InspectMut; use memory_range::MemoryRange; -use mesh::payload::Protobuf; use mesh::MeshPayload; +use mesh::payload::Protobuf; use parking_lot::Mutex; use sparse_mmap::Mappable; use sparse_mmap::SparseMapping; @@ -39,8 +39,8 @@ use video_core::FramebufferControl; use video_core::FramebufferFormat; use video_core::ResolvedFramebuffer; use video_core::SharedFramebufferHandle; -use vm_resource::kind::FramebufferHandleKind; use vm_resource::ResolveResource; +use vm_resource::kind::FramebufferHandleKind; use vmcore::device_state::ChangeDeviceState; use vmcore::save_restore::RestoreError; use vmcore::save_restore::SaveError; diff --git a/vm/devices/get/get_helpers/src/lib.rs b/vm/devices/get/get_helpers/src/lib.rs index a646c388b5..b88c4b34e7 100644 --- a/vm/devices/get/get_helpers/src/lib.rs +++ b/vm/devices/get/get_helpers/src/lib.rs @@ -8,12 +8,12 @@ use get_protocol::LogFlags; use get_protocol::LogLevel; use get_protocol::LogType; -use get_protocol::TraceLoggingBufferOffset; -use get_protocol::TraceLoggingNotificationHeader; use get_protocol::TRACE_LOGGING_FIELDS_MAX_SIZE; use get_protocol::TRACE_LOGGING_MESSAGE_MAX_SIZE; use get_protocol::TRACE_LOGGING_NAME_MAX_SIZE; use get_protocol::TRACE_LOGGING_TARGET_MAX_SIZE; +use get_protocol::TraceLoggingBufferOffset; +use get_protocol::TraceLoggingNotificationHeader; use guid::Guid; use zerocopy::IntoBytes; diff --git a/vm/devices/get/get_resources/src/lib.rs b/vm/devices/get/get_resources/src/lib.rs index 16ca2835b7..a25ce39dc6 100644 --- a/vm/devices/get/get_resources/src/lib.rs +++ b/vm/devices/get/get_resources/src/lib.rs @@ -8,8 +8,8 @@ /// Guest Emulation Log device resources. pub mod gel { use mesh::MeshPayload; - use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::ResourceId; + use vm_resource::kind::VmbusDeviceHandleKind; /// Handle to a guest emulation log device. #[derive(MeshPayload)] @@ -22,11 +22,11 @@ pub mod gel { /// Guest crash device resources. pub mod crash { - use mesh::rpc::FailableRpc; use mesh::MeshPayload; + use mesh::rpc::FailableRpc; use std::fs::File; - use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::ResourceId; + use vm_resource::kind::VmbusDeviceHandleKind; /// Handle to a guest crash dump device. #[derive(MeshPayload)] @@ -44,16 +44,16 @@ pub mod crash { /// Guest Emulation Device resources. pub mod ged { + use mesh::MeshPayload; use mesh::error::RemoteError; use mesh::payload::Protobuf; use mesh::rpc::Rpc; - use mesh::MeshPayload; use thiserror::Error; + use vm_resource::Resource; + use vm_resource::ResourceId; use vm_resource::kind::DiskHandleKind; use vm_resource::kind::FramebufferHandleKind; use vm_resource::kind::VmbusDeviceHandleKind; - use vm_resource::Resource; - use vm_resource::ResourceId; /// A resource handle for a guest emulation device. #[derive(MeshPayload)] diff --git a/vm/devices/get/guest_crash_device/src/resolver.rs b/vm/devices/get/guest_crash_device/src/resolver.rs index 92e112ad0f..13fc2bf328 100644 --- a/vm/devices/get/guest_crash_device/src/resolver.rs +++ b/vm/devices/get/guest_crash_device/src/resolver.rs @@ -6,9 +6,9 @@ use crate::GuestCrashDevice; use get_resources::crash::GuestCrashDeviceHandle; use std::convert::Infallible; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::VmbusDeviceHandleKind; -use vm_resource::ResolveResource; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; use vmbus_channel::simple::SimpleDeviceWrapper; diff --git a/vm/devices/get/guest_emulation_device/src/lib.rs b/vm/devices/get/guest_emulation_device/src/lib.rs index 797cf0020c..fd856f647c 100644 --- a/vm/devices/get/guest_emulation_device/src/lib.rs +++ b/vm/devices/get/guest_emulation_device/src/lib.rs @@ -21,21 +21,21 @@ use core::mem::size_of; use disk_backend::Disk; use futures::FutureExt; use futures::StreamExt; -use get_protocol::dps_json::HclSecureBootTemplateId; -use get_protocol::dps_json::PcatBootDevice; use get_protocol::BatteryStatusFlags; use get_protocol::BatteryStatusNotification; use get_protocol::HeaderGeneric; use get_protocol::HostNotifications; use get_protocol::HostRequests; use get_protocol::IgvmAttestRequest; +use get_protocol::MAX_PAYLOAD_SIZE; use get_protocol::RegisterState; use get_protocol::SaveGuestVtl2StateFlags; use get_protocol::SecureBootTemplateType; use get_protocol::StartVtl0Status; use get_protocol::UefiConsoleMode; use get_protocol::VmgsIoStatus; -use get_protocol::MAX_PAYLOAD_SIZE; +use get_protocol::dps_json::HclSecureBootTemplateId; +use get_protocol::dps_json::PcatBootDevice; use get_resources::ged::FirmwareEvent; use get_resources::ged::GuestEmulationRequest; use get_resources::ged::GuestServicingFlags; @@ -48,10 +48,10 @@ use inspect::Inspect; use inspect::InspectMut; use mesh::error::RemoteError; use mesh::rpc::Rpc; +use openhcl_attestation_protocol::igvm_attest::get::AK_CERT_RESPONSE_HEADER_VERSION; use openhcl_attestation_protocol::igvm_attest::get::IgvmAttestAkCertResponseHeader; use openhcl_attestation_protocol::igvm_attest::get::IgvmAttestRequestHeader; use openhcl_attestation_protocol::igvm_attest::get::IgvmAttestRequestType; -use openhcl_attestation_protocol::igvm_attest::get::AK_CERT_RESPONSE_HEADER_VERSION; use power_resources::PowerRequest; use power_resources::PowerRequestClient; use scsi_buffers::OwnedRequestBuffers; @@ -61,12 +61,12 @@ use thiserror::Error; use video_core::FramebufferControl; use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::pipe::MessagePipe; +use vmbus_channel::RawAsyncChannel; use vmbus_channel::bus::ChannelType; use vmbus_channel::bus::OfferParams; use vmbus_channel::channel::ChannelOpenError; use vmbus_channel::gpadl_ring::GpadlRingMem; use vmbus_channel::simple::SimpleVmbusDevice; -use vmbus_channel::RawAsyncChannel; use vmbus_ring::RingMem; use vmcore::save_restore::SavedStateNotSupported; use zerocopy::FromBytes; @@ -934,7 +934,9 @@ impl GedChannel { framebuffer_control.map(gpa).await; get_protocol::MapFramebufferStatus::SUCCESS } else { - tracing::warn!("Guest requested framebuffer mapping but no framebuffer control was provided to the GET"); + tracing::warn!( + "Guest requested framebuffer mapping but no framebuffer control was provided to the GET" + ); get_protocol::MapFramebufferStatus::FAILURE }, ); @@ -954,7 +956,9 @@ impl GedChannel { framebuffer_control.unmap().await; get_protocol::UnmapFramebufferStatus::SUCCESS } else { - tracing::warn!("Guest requested framebuffer mapping but no framebuffer control was provided to the GET"); + tracing::warn!( + "Guest requested framebuffer mapping but no framebuffer control was provided to the GET" + ); get_protocol::UnmapFramebufferStatus::FAILURE }, ); diff --git a/vm/devices/get/guest_emulation_device/src/resolver.rs b/vm/devices/get/guest_emulation_device/src/resolver.rs index 45d8db7fae..f35637a3d7 100644 --- a/vm/devices/get/guest_emulation_device/src/resolver.rs +++ b/vm/devices/get/guest_emulation_device/src/resolver.rs @@ -12,13 +12,13 @@ use get_resources::ged::PcatBootDevice; use get_resources::ged::UefiConsoleMode; use power_resources::PowerRequestHandleKind; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::IntoResource; use vm_resource::PlatformResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::VmbusDeviceHandleKind; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; use vmbus_channel::simple::SimpleDeviceWrapper; diff --git a/vm/devices/get/guest_emulation_device/src/test_utilities.rs b/vm/devices/get/guest_emulation_device/src/test_utilities.rs index 884563e115..db39faa060 100644 --- a/vm/devices/get/guest_emulation_device/src/test_utilities.rs +++ b/vm/devices/get/guest_emulation_device/src/test_utilities.rs @@ -6,11 +6,11 @@ use crate::GedChannel; use crate::GuestConfig; use crate::GuestEmulationDevice; use crate::GuestFirmwareConfig; -use get_protocol::test_utilities::TEST_VMGS_CAPACITY; use get_protocol::HostNotifications; use get_protocol::HostRequests; use get_protocol::SecureBootTemplateType; use get_protocol::UefiConsoleMode; +use get_protocol::test_utilities::TEST_VMGS_CAPACITY; use get_resources::ged::GuestEmulationRequest; use get_resources::ged::GuestServicingFlags; use guestmem::GuestMemory; diff --git a/vm/devices/get/guest_emulation_log/src/lib.rs b/vm/devices/get/guest_emulation_log/src/lib.rs index 98b1d19cec..776a09ee6b 100644 --- a/vm/devices/get/guest_emulation_log/src/lib.rs +++ b/vm/devices/get/guest_emulation_log/src/lib.rs @@ -20,13 +20,13 @@ use task_control::StopTask; use thiserror::Error; use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::pipe::MessagePipe; +use vmbus_channel::RawAsyncChannel; use vmbus_channel::bus::ChannelType; use vmbus_channel::bus::OfferParams; use vmbus_channel::channel::ChannelOpenError; use vmbus_channel::gpadl_ring::GpadlRingMem; use vmbus_channel::simple::SaveRestoreSimpleVmbusDevice; use vmbus_channel::simple::SimpleVmbusDevice; -use vmbus_channel::RawAsyncChannel; use vmbus_ring::RingMem; use vmcore::save_restore::NoSavedState; use zerocopy::FromBytes; diff --git a/vm/devices/get/guest_emulation_log/src/resolver.rs b/vm/devices/get/guest_emulation_log/src/resolver.rs index 6e5551000d..62469c5aaf 100644 --- a/vm/devices/get/guest_emulation_log/src/resolver.rs +++ b/vm/devices/get/guest_emulation_log/src/resolver.rs @@ -4,9 +4,9 @@ use crate::GuestEmulationLog; use get_resources::gel::GuestEmulationLogHandle; use std::convert::Infallible; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::VmbusDeviceHandleKind; -use vm_resource::ResolveResource; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; use vmbus_channel::simple::SimpleDeviceWrapper; diff --git a/vm/devices/get/guest_emulation_transport/src/api.rs b/vm/devices/get/guest_emulation_transport/src/api.rs index e7b73b6389..311ff1ea4d 100644 --- a/vm/devices/get/guest_emulation_transport/src/api.rs +++ b/vm/devices/get/guest_emulation_transport/src/api.rs @@ -7,16 +7,16 @@ // the GET and GED to also import get_protocol. pub use get_protocol::CreateRamGpaRangeFlags; pub use get_protocol::EventLogId; +pub use get_protocol::GSP_CIPHERTEXT_MAX; pub use get_protocol::GspCiphertextContent; pub use get_protocol::GspCleartextContent; pub use get_protocol::GspExtendedStatusFlags; -pub use get_protocol::ProtocolVersion; -pub use get_protocol::SaveGuestVtl2StateFlags; -pub use get_protocol::VmgsIoStatus; -pub use get_protocol::GSP_CIPHERTEXT_MAX; pub use get_protocol::IGVM_ATTEST_MSG_REQ_AGENT_DATA_MAX_SIZE; pub use get_protocol::MAX_TRANSFER_SIZE; pub use get_protocol::NUMBER_GSP; +pub use get_protocol::ProtocolVersion; +pub use get_protocol::SaveGuestVtl2StateFlags; +pub use get_protocol::VmgsIoStatus; use zerocopy::FromZeros; use guid::Guid; diff --git a/vm/devices/get/guest_emulation_transport/src/client.rs b/vm/devices/get/guest_emulation_transport/src/client.rs index d1e241a4ff..d52bf126a8 100644 --- a/vm/devices/get/guest_emulation_transport/src/client.rs +++ b/vm/devices/get/guest_emulation_transport/src/client.rs @@ -3,8 +3,8 @@ use super::process_loop::msg; use super::process_loop::msg::IgvmAttestRequestData; -use crate::api::platform_settings; use crate::api::GuestSaveRequest; +use crate::api::platform_settings; use chipset_resources::battery::HostBatteryUpdate; use get_protocol::RegisterState; use get_protocol::TripleFaultType; @@ -267,7 +267,7 @@ impl GuestEmulationTransportClient { o => { return Err( crate::error::DevicePlatformSettingsError::InvalidConsoleMode(o), - ) + ); } } }, @@ -512,7 +512,9 @@ impl GuestEmulationTransportClient { .until_cancelled(std::future::pending::<()>()) .await .unwrap_or_else(|_| { - panic!("should have been terminated after reporting start failure: {error_msg}") + panic!( + "should have been terminated after reporting start failure: {error_msg}" + ) }); } } diff --git a/vm/devices/get/guest_emulation_transport/src/lib.rs b/vm/devices/get/guest_emulation_transport/src/lib.rs index aa232eff33..7db95b2155 100644 --- a/vm/devices/get/guest_emulation_transport/src/lib.rs +++ b/vm/devices/get/guest_emulation_transport/src/lib.rs @@ -115,14 +115,14 @@ mod tests { use super::test_utilities::*; use super::worker::GuestEmulationTransportWorker; use crate::process_loop::FatalError; - use get_protocol::test_utilities::TEST_VMGS_SECTOR_SIZE; use get_protocol::ProtocolVersion; use get_protocol::VmgsIoStatus; + use get_protocol::test_utilities::TEST_VMGS_SECTOR_SIZE; use guest_emulation_device::test_utilities::Event; use guest_emulation_device::test_utilities::TestGetResponses; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::task::Spawn; - use pal_async::DefaultDriver; use test_with_tracing::test; use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::async_dgram::AsyncSendExt; diff --git a/vm/devices/get/guest_emulation_transport/src/process_loop.rs b/vm/devices/get/guest_emulation_transport/src/process_loop.rs index 3b38cb11f2..1dcc69c0c5 100644 --- a/vm/devices/get/guest_emulation_transport/src/process_loop.rs +++ b/vm/devices/get/guest_emulation_transport/src/process_loop.rs @@ -19,16 +19,15 @@ use guid::Guid; use inspect::Inspect; use inspect::InspectMut; use inspect_counters::Counter; +use mesh::RecvError; use mesh::rpc::Rpc; use mesh::rpc::RpcError; use mesh::rpc::TryRpcSend; -use mesh::RecvError; use parking_lot::Mutex; use std::cmp::min; use std::collections::HashMap; use std::collections::VecDeque; use std::future::pending; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; use thiserror::Error; @@ -93,7 +92,9 @@ pub(crate) enum FatalError { GpaMemoryAllocationError(#[source] anyhow::Error), #[error("failed to deserialize the asynchronous `IGVM_ATTEST` response")] DeserializeIgvmAttestResponse, - #[error("malformed `IGVM_ATTEST` response - reported size {response_size} was larger than maximum size {maximum_size}")] + #[error( + "malformed `IGVM_ATTEST` response - reported size {response_size} was larger than maximum size {maximum_size}" + )] InvalidIgvmAttestResponseSize { response_size: usize, maximum_size: usize, @@ -1624,7 +1625,7 @@ async fn request_device_platform_settings_v2( return Err(FatalError::ResponseHeaderMismatchId( header.message_id, HostRequests::DEVICE_PLATFORM_SETTINGS_V2, - )) + )); } } } diff --git a/vm/devices/get/guest_emulation_transport/src/worker.rs b/vm/devices/get/guest_emulation_transport/src/worker.rs index 0b43454f1a..f30bdf02ca 100644 --- a/vm/devices/get/guest_emulation_transport/src/worker.rs +++ b/vm/devices/get/guest_emulation_transport/src/worker.rs @@ -2,10 +2,10 @@ // Licensed under the MIT License. use super::client::GuestEmulationTransportClient; -use super::process_loop::msg::Msg; use super::process_loop::ProcessLoop; -use crate::process_loop::FatalError; +use super::process_loop::msg::Msg; use crate::FatalGetError; +use crate::process_loop::FatalError; use pal_async::task::Spawn; use tracing_helpers::ErrorValueExt; use vmbus_async::pipe::MessagePipe; diff --git a/vm/devices/get/underhill_config/src/schema/mod.rs b/vm/devices/get/underhill_config/src/schema/mod.rs index bd05357d24..d8be997e57 100644 --- a/vm/devices/get/underhill_config/src/schema/mod.rs +++ b/vm/devices/get/underhill_config/src/schema/mod.rs @@ -8,11 +8,11 @@ use self::v1::NAMESPACE_BASE; use self::v1::NAMESPACE_NETWORK_ACCELERATION; use self::v1::NAMESPACE_NETWORK_DEVICE; +use crate::Vtl2SettingsErrorInfoVec; use crate::errors::ParseErrors; use crate::errors::ParseErrorsBase; use crate::errors::ParseResultExt; use crate::errors::ParsingStopped; -use crate::Vtl2SettingsErrorInfoVec; use thiserror::Error; use vtl2_settings_proto::*; diff --git a/vm/devices/get/underhill_config/src/schema/v1.rs b/vm/devices/get/underhill_config/src/schema/v1.rs index 79a7911b5f..abd48dd9cb 100644 --- a/vm/devices/get/underhill_config/src/schema/v1.rs +++ b/vm/devices/get/underhill_config/src/schema/v1.rs @@ -8,13 +8,13 @@ //! definitions in MARS files. use super::ParseSchemaExt; +use crate::Vtl2SettingsErrorCode; +use crate::Vtl2SettingsErrorInfo; use crate::errors::ErrorContext; use crate::errors::ParseErrors; use crate::schema::ParseResultExt; use crate::schema::ParseSchema; use crate::schema::ParsingStopped; -use crate::Vtl2SettingsErrorCode; -use crate::Vtl2SettingsErrorInfo; use guid::Guid; use physical_device::DeviceType; use std::error::Error as _; diff --git a/vm/devices/hyperv_ic/src/resolver.rs b/vm/devices/hyperv_ic/src/resolver.rs index 5355890494..d5c95a80c8 100644 --- a/vm/devices/hyperv_ic/src/resolver.rs +++ b/vm/devices/hyperv_ic/src/resolver.rs @@ -6,9 +6,9 @@ use crate::shutdown::ShutdownIc; use hyperv_ic_resources::shutdown::ShutdownIcHandle; use std::convert::Infallible; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::VmbusDeviceHandleKind; -use vm_resource::ResolveResource; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; use vmbus_channel::simple::SimpleDeviceWrapper; diff --git a/vm/devices/hyperv_ic/src/shutdown.rs b/vm/devices/hyperv_ic/src/shutdown.rs index e38d650a7a..672c2281a9 100644 --- a/vm/devices/hyperv_ic/src/shutdown.rs +++ b/vm/devices/hyperv_ic/src/shutdown.rs @@ -4,9 +4,9 @@ //! The shutdown IC. use async_trait::async_trait; -use futures::stream::once; use futures::FutureExt; use futures::StreamExt; +use futures::stream::once; use futures_concurrency::stream::Merge; use hyperv_ic_protocol::shutdown::FRAMEWORK_VERSIONS; use hyperv_ic_protocol::shutdown::SHUTDOWN_VERSIONS; @@ -25,13 +25,13 @@ use thiserror::Error; use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::async_dgram::AsyncSendExt; use vmbus_async::pipe::MessagePipe; +use vmbus_channel::RawAsyncChannel; use vmbus_channel::bus::ChannelType; use vmbus_channel::bus::OfferParams; use vmbus_channel::channel::ChannelOpenError; use vmbus_channel::gpadl_ring::GpadlRingMem; use vmbus_channel::simple::SaveRestoreSimpleVmbusDevice; use vmbus_channel::simple::SimpleVmbusDevice; -use vmbus_channel::RawAsyncChannel; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::IntoBytes; @@ -126,14 +126,16 @@ impl ShutdownChannel { } loop { - let event = pin!(( - once( - self.process_state_machine(&mut ic.wait_ready) - .map(Event::StateMachine) - ), - (&mut ic.recv).map(Event::Request), + let event = pin!( + ( + once( + self.process_state_machine(&mut ic.wait_ready) + .map(Event::StateMachine) + ), + (&mut ic.recv).map(Event::Request), + ) + .merge() ) - .merge()) .next() .await .unwrap(); diff --git a/vm/devices/hyperv_ic_guest/src/shutdown.rs b/vm/devices/hyperv_ic_guest/src/shutdown.rs index 0ffa66800e..0d097c73fd 100644 --- a/vm/devices/hyperv_ic_guest/src/shutdown.rs +++ b/vm/devices/hyperv_ic_guest/src/shutdown.rs @@ -25,13 +25,13 @@ use thiserror::Error; use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::async_dgram::AsyncSendExt; use vmbus_async::pipe::MessagePipe; -use vmbus_channel::channel::ChannelOpenError; use vmbus_channel::RawAsyncChannel; -use vmbus_relay_intercept_device::ring_buffer::MemoryBlockRingBuffer; +use vmbus_channel::channel::ChannelOpenError; use vmbus_relay_intercept_device::OfferResponse; use vmbus_relay_intercept_device::SaveRestoreSimpleVmbusClientDevice; use vmbus_relay_intercept_device::SimpleVmbusClientDevice; use vmbus_relay_intercept_device::SimpleVmbusClientDeviceAsync; +use vmbus_relay_intercept_device::ring_buffer::MemoryBlockRingBuffer; use vmbus_ring::RingMem; use vmcore::save_restore::NoSavedState; use zerocopy::FromBytes; diff --git a/vm/devices/hyperv_ic_resources/src/shutdown.rs b/vm/devices/hyperv_ic_resources/src/shutdown.rs index 36b9098a31..bb72318cc2 100644 --- a/vm/devices/hyperv_ic_resources/src/shutdown.rs +++ b/vm/devices/hyperv_ic_resources/src/shutdown.rs @@ -3,10 +3,10 @@ //! Resource definitions for the shutdown IC. -use mesh::rpc::Rpc; use mesh::MeshPayload; -use vm_resource::kind::VmbusDeviceHandleKind; +use mesh::rpc::Rpc; use vm_resource::ResourceId; +use vm_resource::kind::VmbusDeviceHandleKind; /// A handle to a shutdown IC. #[derive(MeshPayload)] diff --git a/vm/devices/input_core/src/lib.rs b/vm/devices/input_core/src/lib.rs index 0042a86ff6..cd7877b9aa 100644 --- a/vm/devices/input_core/src/lib.rs +++ b/vm/devices/input_core/src/lib.rs @@ -9,10 +9,10 @@ pub mod mesh_input; use mesh::MeshPayload; use std::pin::Pin; -use vm_resource::kind::KeyboardInputHandleKind; -use vm_resource::kind::MouseInputHandleKind; use vm_resource::CanResolveTo; use vm_resource::ResourceId; +use vm_resource::kind::KeyboardInputHandleKind; +use vm_resource::kind::MouseInputHandleKind; /// Keyboard or mouse input data. #[derive(Debug, Copy, Clone, MeshPayload)] @@ -47,10 +47,7 @@ pub struct KeyboardData { pub trait InputSource: futures::Stream + Unpin + Send { /// Sets this input source active, so that the sending side can choose which /// device to send input to. - fn set_active( - &mut self, - active: bool, - ) -> Pin + Send>>; + fn set_active(&mut self, active: bool) -> Pin + Send>>; } /// A resolved [`InputSource`]. diff --git a/vm/devices/input_core/src/mesh_input.rs b/vm/devices/input_core/src/mesh_input.rs index f486d75d1d..7cec0d6a37 100644 --- a/vm/devices/input_core/src/mesh_input.rs +++ b/vm/devices/input_core/src/mesh_input.rs @@ -4,8 +4,8 @@ //! Mesh-backed [`InputSource`] implementation. use crate::InputSource; -use mesh::message::MeshField; use mesh::MeshPayload; +use mesh::message::MeshField; use std::pin::Pin; /// An input source that receives input over a mesh channel. @@ -17,10 +17,7 @@ pub struct MeshInputSource { } impl InputSource for MeshInputSource { - fn set_active( - &mut self, - active: bool, - ) -> Pin + Send>> { + fn set_active(&mut self, active: bool) -> Pin + Send>> { Box::pin(async move { if *self.active.get() != active { self.active.set(active).await; diff --git a/vm/devices/mcr_resources/src/lib.rs b/vm/devices/mcr_resources/src/lib.rs index b468846e32..80ca6f38e3 100644 --- a/vm/devices/mcr_resources/src/lib.rs +++ b/vm/devices/mcr_resources/src/lib.rs @@ -8,8 +8,8 @@ // #![warn(missing_docs)] // TODO MCR use mesh::MeshPayload; -use vm_resource::kind::PciDeviceHandleKind; use vm_resource::ResourceId; +use vm_resource::kind::PciDeviceHandleKind; #[derive(MeshPayload)] pub struct McrControllerHandle { diff --git a/vm/devices/missing_dev/src/lib.rs b/vm/devices/missing_dev/src/lib.rs index 69983663b5..1489bd5297 100644 --- a/vm/devices/missing_dev/src/lib.rs +++ b/vm/devices/missing_dev/src/lib.rs @@ -9,6 +9,7 @@ #![forbid(unsafe_code)] +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::mmio::ControlMmioIntercept; use chipset_device::mmio::MmioIntercept; @@ -17,7 +18,6 @@ use chipset_device::pci::PciConfigSpace; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use pci_core::spec::hwid::ProgrammingInterface; @@ -132,11 +132,7 @@ impl ChipsetDevice for MissingDev { fn supports_pci(&mut self) -> Option<&mut dyn PciConfigSpace> { // this is technically IDET abuse... - if self.pci.is_some() { - Some(self) - } else { - None - } + if self.pci.is_some() { Some(self) } else { None } } } @@ -252,9 +248,9 @@ pub mod resolver { use chipset_device_resources::ResolvedChipsetDevice; use missing_dev_resources::MissingDevHandle; use std::convert::Infallible; + use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::ChipsetDeviceHandleKind; - use vm_resource::ResolveResource; /// A resolver for [`MissingDevHandle`] resources. pub struct MissingDevResolver; diff --git a/vm/devices/missing_dev_resources/src/lib.rs b/vm/devices/missing_dev_resources/src/lib.rs index cc0b6e5364..3ece29ebe7 100644 --- a/vm/devices/missing_dev_resources/src/lib.rs +++ b/vm/devices/missing_dev_resources/src/lib.rs @@ -7,8 +7,8 @@ use mesh::MeshPayload; use std::ops::RangeInclusive; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::ResourceId; +use vm_resource::kind::ChipsetDeviceHandleKind; /// A handle to a device that ignores accesses to specified regions. #[derive(MeshPayload, Default)] diff --git a/vm/devices/net/gdma/src/bnic.rs b/vm/devices/net/gdma/src/bnic.rs index de90f6ecaa..b6d8fe0ebe 100644 --- a/vm/devices/net/gdma/src/bnic.rs +++ b/vm/devices/net/gdma/src/bnic.rs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use self::bnic_defs::CQE_TX_OKAY; +use self::bnic_defs::MANA_CQE_COMPLETION; use self::bnic_defs::ManaCommandCode; use self::bnic_defs::ManaCqeHeader; use self::bnic_defs::ManaQueryVportCfgReq; @@ -9,8 +11,8 @@ use self::bnic_defs::ManaRxcompOobFlags; use self::bnic_defs::ManaSetVportSerialNo; use self::bnic_defs::ManaTxCompOob; use self::bnic_defs::ManaTxCompOobOffsets; -use self::bnic_defs::CQE_TX_OKAY; -use self::bnic_defs::MANA_CQE_COMPLETION; +use crate::VportConfig; +use crate::bnic::bnic_defs::CQE_RX_OKAY; use crate::bnic::bnic_defs::ManaCfgRxSteerReq; use crate::bnic::bnic_defs::ManaConfigVportReq; use crate::bnic::bnic_defs::ManaConfigVportResp; @@ -20,20 +22,18 @@ use crate::bnic::bnic_defs::ManaQueryDeviceCfgReq; use crate::bnic::bnic_defs::ManaQueryDeviceCfgResp; use crate::bnic::bnic_defs::ManaQueryVportCfgResp; use crate::bnic::bnic_defs::ManaTxOob; -use crate::bnic::bnic_defs::CQE_RX_OKAY; use crate::hwc::HwState; use crate::queues::Queues; -use crate::VportConfig; -use anyhow::anyhow; use anyhow::Context; +use anyhow::anyhow; +use gdma_defs::GdmaQueueType; +use gdma_defs::GdmaReqHdr; +use gdma_defs::Wqe; use gdma_defs::access::WqeAccess; use gdma_defs::bnic as bnic_defs; use gdma_defs::bnic::ManaDestroyWqobjReq; use gdma_defs::bnic::ManaTxShortOob; use gdma_defs::bnic::Tristate; -use gdma_defs::GdmaQueueType; -use gdma_defs::GdmaReqHdr; -use gdma_defs::Wqe; use guestmem::GuestMemory; use guestmem::Limit; use guestmem::MemoryRead; diff --git a/vm/devices/net/gdma/src/hwc.rs b/vm/devices/net/gdma/src/hwc.rs index 5fad934fdf..1355b3808c 100644 --- a/vm/devices/net/gdma/src/hwc.rs +++ b/vm/devices/net/gdma/src/hwc.rs @@ -5,9 +5,12 @@ use crate::bnic::BasicNic; use crate::dma::DmaRegion; use crate::queues::QueueAllocError; use crate::queues::Queues; -use anyhow::anyhow; use anyhow::Context; -use gdma_defs::access::WqeAccess; +use anyhow::anyhow; +use gdma_defs::GDMA_EQE_HWC_INIT_DATA; +use gdma_defs::GDMA_EQE_HWC_INIT_DONE; +use gdma_defs::GDMA_EQE_HWC_INIT_EQ_ID_DB; +use gdma_defs::GDMA_EQE_TEST_EVENT; use gdma_defs::GdmaChangeMsixVectorIndexForEq; use gdma_defs::GdmaCreateDmaRegionReq; use gdma_defs::GdmaCreateDmaRegionResp; @@ -26,14 +29,6 @@ use gdma_defs::GdmaRequestType; use gdma_defs::GdmaRespHdr; use gdma_defs::GdmaVerifyVerReq; use gdma_defs::GdmaVerifyVerResp; -use gdma_defs::HwcInitEqIdDb; -use gdma_defs::HwcInitTypeData; -use gdma_defs::HwcRxOob; -use gdma_defs::HwcTxOob; -use gdma_defs::GDMA_EQE_HWC_INIT_DATA; -use gdma_defs::GDMA_EQE_HWC_INIT_DONE; -use gdma_defs::GDMA_EQE_HWC_INIT_EQ_ID_DB; -use gdma_defs::GDMA_EQE_TEST_EVENT; use gdma_defs::HWC_DEV_ID; use gdma_defs::HWC_INIT_DATA_CQID; use gdma_defs::HWC_INIT_DATA_GPA_MKEY; @@ -44,7 +39,12 @@ use gdma_defs::HWC_INIT_DATA_PDID; use gdma_defs::HWC_INIT_DATA_QUEUE_DEPTH; use gdma_defs::HWC_INIT_DATA_RQID; use gdma_defs::HWC_INIT_DATA_SQID; +use gdma_defs::HwcInitEqIdDb; +use gdma_defs::HwcInitTypeData; +use gdma_defs::HwcRxOob; +use gdma_defs::HwcTxOob; use gdma_defs::PAGE_SIZE64; +use gdma_defs::access::WqeAccess; use guestmem::Limit; use guestmem::MemoryRead; use guestmem::MemoryWrite; diff --git a/vm/devices/net/gdma/src/lib.rs b/vm/devices/net/gdma/src/lib.rs index 5781a0cb93..ad752875be 100644 --- a/vm/devices/net/gdma/src/lib.rs +++ b/vm/devices/net/gdma/src/lib.rs @@ -9,29 +9,29 @@ mod hwc; mod queues; pub mod resolver; +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; use chipset_device::pci::PciConfigSpace; -use chipset_device::ChipsetDevice; +use device_emulators::ReadWriteRequestType; use device_emulators::read_as_u32_chunks; use device_emulators::write_as_u32_chunks; -use device_emulators::ReadWriteRequestType; use futures::FutureExt; use gdma_defs::CqEqDoorbellValue; -use gdma_defs::RegMap; -use gdma_defs::SmcMessageType; -use gdma_defs::SmcProtoHdr; -use gdma_defs::WqDoorbellValue; use gdma_defs::DB_CQ; use gdma_defs::DB_EQ; use gdma_defs::DB_RQ; use gdma_defs::DB_RQ_CLIENT_DATA; use gdma_defs::DB_SQ; use gdma_defs::PAGE_SIZE64; +use gdma_defs::RegMap; use gdma_defs::SMC_MSG_TYPE_DESTROY_HWC_VERSION; use gdma_defs::SMC_MSG_TYPE_ESTABLISH_HWC_VERSION; use gdma_defs::SMC_MSG_TYPE_REPORT_HWC_TIMEOUT_VERSION; +use gdma_defs::SmcMessageType; +use gdma_defs::SmcProtoHdr; +use gdma_defs::WqDoorbellValue; use guestmem::GuestMemory; use hwc::Devices; use hwc::HwControl; diff --git a/vm/devices/net/gdma/src/queues.rs b/vm/devices/net/gdma/src/queues.rs index 2d0d98a1d4..29ded8bb38 100644 --- a/vm/devices/net/gdma/src/queues.rs +++ b/vm/devices/net/gdma/src/queues.rs @@ -7,14 +7,14 @@ use gdma_defs::Cqe; use gdma_defs::CqeParams; use gdma_defs::Eqe; use gdma_defs::EqeParams; -use gdma_defs::WqDoorbellValue; -use gdma_defs::Wqe; -use gdma_defs::WqeHeader; use gdma_defs::GDMA_EQE_COMPLETION; use gdma_defs::OWNER_BITS; use gdma_defs::OWNER_MASK; use gdma_defs::PAGE_SIZE64; use gdma_defs::WQE_ALIGNMENT; +use gdma_defs::WqDoorbellValue; +use gdma_defs::Wqe; +use gdma_defs::WqeHeader; use guestmem::GuestMemory; use guestmem::MemoryRead; use guestmem::MemoryWrite; diff --git a/vm/devices/net/gdma/src/resolver.rs b/vm/devices/net/gdma/src/resolver.rs index ab842dfc72..5e4a38eefc 100644 --- a/vm/devices/net/gdma/src/resolver.rs +++ b/vm/devices/net/gdma/src/resolver.rs @@ -12,11 +12,11 @@ use net_backend::resolve::ResolveEndpointParams; use pci_resources::ResolvePciDeviceHandleParams; use pci_resources::ResolvedPciDevice; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::PciDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::PciDeviceHandleKind; /// Resource resolver for [`GdmaDeviceHandle`]. pub struct GdmaDeviceResolver; diff --git a/vm/devices/net/gdma_resources/src/lib.rs b/vm/devices/net/gdma_resources/src/lib.rs index 4b48100974..9bbc7d0e3f 100644 --- a/vm/devices/net/gdma_resources/src/lib.rs +++ b/vm/devices/net/gdma_resources/src/lib.rs @@ -7,10 +7,10 @@ use mesh::MeshPayload; use net_backend_resources::mac_address::MacAddress; -use vm_resource::kind::NetEndpointHandleKind; -use vm_resource::kind::PciDeviceHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::NetEndpointHandleKind; +use vm_resource::kind::PciDeviceHandleKind; /// A resource handle to a GDMA device. #[derive(MeshPayload)] diff --git a/vm/devices/net/linux_net_bindings/src/gen_if.rs b/vm/devices/net/linux_net_bindings/src/gen_if.rs index 20fa8dfcb5..b9cf5944e3 100644 --- a/vm/devices/net/linux_net_bindings/src/gen_if.rs +++ b/vm/devices/net/linux_net_bindings/src/gen_if.rs @@ -1169,7 +1169,7 @@ unsafe extern "C" { } unsafe extern "C" { pub fn listen(__fd: ::std::os::raw::c_int, __n: ::std::os::raw::c_int) - -> ::std::os::raw::c_int; + -> ::std::os::raw::c_int; } unsafe extern "C" { pub fn accept( diff --git a/vm/devices/net/mana_driver/src/bnic_driver.rs b/vm/devices/net/mana_driver/src/bnic_driver.rs index fd9de36fc6..a3cc4042c6 100644 --- a/vm/devices/net/mana_driver/src/bnic_driver.rs +++ b/vm/devices/net/mana_driver/src/bnic_driver.rs @@ -6,6 +6,13 @@ use crate::gdma_driver::GdmaDriver; use crate::mana::ResourceArena; use crate::resources::Resource; +use gdma_defs::GdmaDevId; +use gdma_defs::GdmaQueueType; +use gdma_defs::GdmaReqHdr; +use gdma_defs::bnic::MANA_VTL2_ASSIGN_SERIAL_NUMBER_REQUEST_V1; +use gdma_defs::bnic::MANA_VTL2_ASSIGN_SERIAL_NUMBER_RESPONSE_V1; +use gdma_defs::bnic::MANA_VTL2_MOVE_FILTER_REQUEST_V2; +use gdma_defs::bnic::MANA_VTL2_MOVE_FILTER_RESPONSE_V1; use gdma_defs::bnic::ManaCfgRxSteerReq; use gdma_defs::bnic::ManaCommandCode; use gdma_defs::bnic::ManaConfigVportReq; @@ -23,13 +30,6 @@ use gdma_defs::bnic::ManaQueryStatisticsResponse; use gdma_defs::bnic::ManaQueryVportCfgReq; use gdma_defs::bnic::ManaQueryVportCfgResp; use gdma_defs::bnic::ManaSetVportSerialNo; -use gdma_defs::bnic::MANA_VTL2_ASSIGN_SERIAL_NUMBER_REQUEST_V1; -use gdma_defs::bnic::MANA_VTL2_ASSIGN_SERIAL_NUMBER_RESPONSE_V1; -use gdma_defs::bnic::MANA_VTL2_MOVE_FILTER_REQUEST_V2; -use gdma_defs::bnic::MANA_VTL2_MOVE_FILTER_RESPONSE_V1; -use gdma_defs::GdmaDevId; -use gdma_defs::GdmaQueueType; -use gdma_defs::GdmaReqHdr; use user_driver::DeviceBacking; use zerocopy::FromBytes; use zerocopy::FromZeros; diff --git a/vm/devices/net/mana_driver/src/gdma_driver.rs b/vm/devices/net/mana_driver/src/gdma_driver.rs index 297a6bd12c..60e409c6eb 100644 --- a/vm/devices/net/mana_driver/src/gdma_driver.rs +++ b/vm/devices/net/mana_driver/src/gdma_driver.rs @@ -12,8 +12,20 @@ use crate::resources::ResourceArena; use anyhow::Context; use futures::FutureExt; use gdma_defs::Cqe; +use gdma_defs::DRIVER_CAP_FLAG_1_HW_VPORT_LINK_AWARE; +use gdma_defs::DRIVER_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG; +use gdma_defs::DRIVER_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT; use gdma_defs::EqeDataReconfig; use gdma_defs::EstablishHwc; +use gdma_defs::GDMA_EQE_COMPLETION; +use gdma_defs::GDMA_EQE_HWC_INIT_DATA; +use gdma_defs::GDMA_EQE_HWC_INIT_DONE; +use gdma_defs::GDMA_EQE_HWC_INIT_EQ_ID_DB; +use gdma_defs::GDMA_EQE_HWC_RECONFIG_DATA; +use gdma_defs::GDMA_EQE_TEST_EVENT; +use gdma_defs::GDMA_MESSAGE_V1; +use gdma_defs::GDMA_PAGE_TYPE_4K; +use gdma_defs::GDMA_STANDARD_HEADER_TYPE; use gdma_defs::GdmaChangeMsixVectorIndexForEq; use gdma_defs::GdmaCreateDmaRegionReq; use gdma_defs::GdmaCreateDmaRegionResp; @@ -33,27 +45,6 @@ use gdma_defs::GdmaRequestType; use gdma_defs::GdmaRespHdr; use gdma_defs::GdmaVerifyVerReq; use gdma_defs::GdmaVerifyVerResp; -use gdma_defs::HwcInitEqIdDb; -use gdma_defs::HwcInitTypeData; -use gdma_defs::HwcTxOob; -use gdma_defs::HwcTxOobFlags3; -use gdma_defs::HwcTxOobFlags4; -use gdma_defs::RegMap; -use gdma_defs::Sge; -use gdma_defs::SmcMessageType; -use gdma_defs::SmcProtoHdr; -use gdma_defs::DRIVER_CAP_FLAG_1_HWC_TIMEOUT_RECONFIG; -use gdma_defs::DRIVER_CAP_FLAG_1_HW_VPORT_LINK_AWARE; -use gdma_defs::DRIVER_CAP_FLAG_1_VARIABLE_INDIRECTION_TABLE_SUPPORT; -use gdma_defs::GDMA_EQE_COMPLETION; -use gdma_defs::GDMA_EQE_HWC_INIT_DATA; -use gdma_defs::GDMA_EQE_HWC_INIT_DONE; -use gdma_defs::GDMA_EQE_HWC_INIT_EQ_ID_DB; -use gdma_defs::GDMA_EQE_HWC_RECONFIG_DATA; -use gdma_defs::GDMA_EQE_TEST_EVENT; -use gdma_defs::GDMA_MESSAGE_V1; -use gdma_defs::GDMA_PAGE_TYPE_4K; -use gdma_defs::GDMA_STANDARD_HEADER_TYPE; use gdma_defs::HWC_DATA_CONFIG_HWC_TIMEOUT; use gdma_defs::HWC_DATA_TYPE_HW_VPORT_LINK_CONNECT; use gdma_defs::HWC_DATA_TYPE_HW_VPORT_LINK_DISCONNECT; @@ -63,22 +54,31 @@ use gdma_defs::HWC_INIT_DATA_GPA_MKEY; use gdma_defs::HWC_INIT_DATA_PDID; use gdma_defs::HWC_INIT_DATA_RQID; use gdma_defs::HWC_INIT_DATA_SQID; +use gdma_defs::HwcInitEqIdDb; +use gdma_defs::HwcInitTypeData; +use gdma_defs::HwcTxOob; +use gdma_defs::HwcTxOobFlags3; +use gdma_defs::HwcTxOobFlags4; +use gdma_defs::RegMap; use gdma_defs::SMC_MSG_TYPE_DESTROY_HWC_VERSION; use gdma_defs::SMC_MSG_TYPE_ESTABLISH_HWC_VERSION; use gdma_defs::SMC_MSG_TYPE_REPORT_HWC_TIMEOUT_VERSION; +use gdma_defs::Sge; +use gdma_defs::SmcMessageType; +use gdma_defs::SmcProtoHdr; use inspect::Inspect; use pal_async::driver::Driver; use std::collections::HashMap; use std::mem::ManuallyDrop; use std::sync::Arc; use std::time::Duration; +use user_driver::DeviceBacking; +use user_driver::DeviceRegisterIo; use user_driver::backoff::Backoff; use user_driver::interrupt::DeviceInterrupt; use user_driver::memory::MemoryBlock; use user_driver::memory::PAGE_SIZE; use user_driver::memory::PAGE_SIZE64; -use user_driver::DeviceBacking; -use user_driver::DeviceRegisterIo; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::Immutable; diff --git a/vm/devices/net/mana_driver/src/mana.rs b/vm/devices/net/mana_driver/src/mana.rs index 947af9b84c..8bfa10cd12 100644 --- a/vm/devices/net/mana_driver/src/mana.rs +++ b/vm/devices/net/mana_driver/src/mana.rs @@ -13,28 +13,28 @@ use crate::queues; use crate::queues::Doorbell; use crate::queues::DoorbellPage; use anyhow::Context; -use futures::lock::Mutex; use futures::StreamExt; +use futures::lock::Mutex; +use gdma_defs::GdmaDevId; +use gdma_defs::GdmaDevType; +use gdma_defs::GdmaQueueType; +use gdma_defs::GdmaRegisterDeviceResp; use gdma_defs::bnic::ManaQueryDeviceCfgResp; use gdma_defs::bnic::ManaQueryFilterStateResponse; use gdma_defs::bnic::ManaQueryStatisticsResponse; use gdma_defs::bnic::ManaQueryVportCfgResp; use gdma_defs::bnic::STATISTICS_FLAGS_ALL; -use gdma_defs::GdmaDevId; -use gdma_defs::GdmaDevType; -use gdma_defs::GdmaQueueType; -use gdma_defs::GdmaRegisterDeviceResp; use inspect::Inspect; use net_backend_resources::mac_address::MacAddress; use pal_async::driver::SpawnDriver; use pal_async::task::Spawn; use pal_async::task::Task; use std::sync::Arc; +use user_driver::DeviceBacking; +use user_driver::DmaClient; use user_driver::interrupt::DeviceInterrupt; use user_driver::memory::MemoryBlock; use user_driver::memory::PAGE_SIZE; -use user_driver::DeviceBacking; -use user_driver::DmaClient; use vmcore::vm_task::VmTaskDriverSource; enum LinkStatus { diff --git a/vm/devices/net/mana_driver/src/queues.rs b/vm/devices/net/mana_driver/src/queues.rs index f23479dab5..f0c696ab32 100644 --- a/vm/devices/net/mana_driver/src/queues.rs +++ b/vm/devices/net/mana_driver/src/queues.rs @@ -3,28 +3,28 @@ //! Types to access work, completion, and event queues. -use gdma_defs::CqEqDoorbellValue; -use gdma_defs::Cqe; -use gdma_defs::Eqe; -use gdma_defs::GdmaQueueType; -use gdma_defs::Sge; -use gdma_defs::WqDoorbellValue; -use gdma_defs::WqeHeader; -use gdma_defs::WqeParams; +use gdma_defs::CLIENT_OOB_8; use gdma_defs::CLIENT_OOB_24; use gdma_defs::CLIENT_OOB_32; -use gdma_defs::CLIENT_OOB_8; +use gdma_defs::CqEqDoorbellValue; +use gdma_defs::Cqe; use gdma_defs::DB_CQ; use gdma_defs::DB_EQ; use gdma_defs::DB_RQ; use gdma_defs::DB_SQ; +use gdma_defs::Eqe; +use gdma_defs::GdmaQueueType; use gdma_defs::OWNER_BITS; use gdma_defs::OWNER_MASK; +use gdma_defs::Sge; use gdma_defs::WQE_ALIGNMENT; +use gdma_defs::WqDoorbellValue; +use gdma_defs::WqeHeader; +use gdma_defs::WqeParams; use inspect::Inspect; use std::marker::PhantomData; -use std::sync::atomic::Ordering::Acquire; use std::sync::Arc; +use std::sync::atomic::Ordering::Acquire; use user_driver::memory::MemoryBlock; use zerocopy::FromBytes; use zerocopy::Immutable; diff --git a/vm/devices/net/mana_driver/src/resources.rs b/vm/devices/net/mana_driver/src/resources.rs index f2db4c17bb..9066c17b3e 100644 --- a/vm/devices/net/mana_driver/src/resources.rs +++ b/vm/devices/net/mana_driver/src/resources.rs @@ -6,8 +6,8 @@ use crate::gdma_driver::GdmaDriver; use gdma_defs::GdmaDevId; use gdma_defs::GdmaQueueType; use std::mem::ManuallyDrop; -use user_driver::memory::MemoryBlock; use user_driver::DeviceBacking; +use user_driver::memory::MemoryBlock; /// A list of allocated device resources. /// diff --git a/vm/devices/net/mana_driver/src/tests.rs b/vm/devices/net/mana_driver/src/tests.rs index 13fb28f92e..597f6ceae1 100644 --- a/vm/devices/net/mana_driver/src/tests.rs +++ b/vm/devices/net/mana_driver/src/tests.rs @@ -14,15 +14,15 @@ use gdma::VportConfig; use gdma_defs::GdmaDevType; use gdma_defs::GdmaQueueType; use net_backend::null::NullEndpoint; -use pal_async::async_test; use pal_async::DefaultDriver; +use pal_async::async_test; use pci_core::msi::MsiInterruptSet; use std::sync::Arc; use test_with_tracing::test; +use user_driver::DeviceBacking; use user_driver::emulated::DeviceSharedMemory; use user_driver::emulated::EmulatedDevice; use user_driver::memory::PAGE_SIZE; -use user_driver::DeviceBacking; use vmcore::vm_task::SingleDriverBackend; use vmcore::vm_task::VmTaskDriverSource; diff --git a/vm/devices/net/net_backend/src/lib.rs b/vm/devices/net/net_backend/src/lib.rs index 883f7635d6..97391f676b 100644 --- a/vm/devices/net/net_backend/src/lib.rs +++ b/vm/devices/net/net_backend/src/lib.rs @@ -12,10 +12,10 @@ pub mod resolve; pub mod tests; use async_trait::async_trait; -use futures::lock::Mutex; use futures::FutureExt; use futures::StreamExt; use futures::TryFutureExt; +use futures::lock::Mutex; use futures_concurrency::future::Race; use guestmem::GuestMemory; use guestmem::GuestMemoryError; diff --git a/vm/devices/net/net_backend/src/loopback.rs b/vm/devices/net/net_backend/src/loopback.rs index 87e0e4d541..d1319da3d8 100644 --- a/vm/devices/net/net_backend/src/loopback.rs +++ b/vm/devices/net/net_backend/src/loopback.rs @@ -6,8 +6,6 @@ //! //! This is useful for testing. -use crate::linearize; -use crate::packet_count; use crate::BufferAccess; use crate::Endpoint; use crate::MultiQueueSupport; @@ -18,6 +16,8 @@ use crate::RxId; use crate::RxMetadata; use crate::TxId; use crate::TxSegment; +use crate::linearize; +use crate::packet_count; use async_trait::async_trait; use inspect::InspectMut; use std::collections::VecDeque; diff --git a/vm/devices/net/net_backend/src/null.rs b/vm/devices/net/net_backend/src/null.rs index f73920abd1..b92f10da2d 100644 --- a/vm/devices/net/net_backend/src/null.rs +++ b/vm/devices/net/net_backend/src/null.rs @@ -3,8 +3,6 @@ //! Null (disconnected) endpoint. -use crate::resolve::ResolveEndpointParams; -use crate::resolve::ResolvedEndpoint; use crate::BufferAccess; use crate::Endpoint; use crate::MultiQueueSupport; @@ -15,15 +13,17 @@ use crate::RxId; use crate::TxId; use crate::TxOffloadSupport; use crate::TxSegment; +use crate::resolve::ResolveEndpointParams; +use crate::resolve::ResolvedEndpoint; use async_trait::async_trait; use inspect::InspectMut; use net_backend_resources::null::NullHandle; use std::convert::Infallible; use std::task::Context; use std::task::Poll; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::NetEndpointHandleKind; -use vm_resource::ResolveResource; pub struct NullResolver; diff --git a/vm/devices/net/net_backend/src/resolve.rs b/vm/devices/net/net_backend/src/resolve.rs index ffc7fb2102..e58507c7a8 100644 --- a/vm/devices/net/net_backend/src/resolve.rs +++ b/vm/devices/net/net_backend/src/resolve.rs @@ -5,8 +5,8 @@ use crate::Endpoint; use net_backend_resources::mac_address::MacAddress; -use vm_resource::kind::NetEndpointHandleKind; use vm_resource::CanResolveTo; +use vm_resource::kind::NetEndpointHandleKind; pub struct ResolveEndpointParams { pub mac_address: MacAddress, diff --git a/vm/devices/net/net_backend_resources/src/lib.rs b/vm/devices/net/net_backend_resources/src/lib.rs index 1f5a449cb6..6cb1aa12e5 100644 --- a/vm/devices/net/net_backend_resources/src/lib.rs +++ b/vm/devices/net/net_backend_resources/src/lib.rs @@ -12,8 +12,8 @@ pub mod mac_address; /// Null backend. pub mod null { use mesh::MeshPayload; - use vm_resource::kind::NetEndpointHandleKind; use vm_resource::ResourceId; + use vm_resource::kind::NetEndpointHandleKind; /// Handle to a null network endpoint, which drops sent packets and never /// receives packets. @@ -28,8 +28,8 @@ pub mod null { /// Consomme backend. pub mod consomme { use mesh::MeshPayload; - use vm_resource::kind::NetEndpointHandleKind; use vm_resource::ResourceId; + use vm_resource::kind::NetEndpointHandleKind; /// Handle to a Consomme network endpoint. #[derive(MeshPayload)] @@ -47,8 +47,8 @@ pub mod consomme { pub mod dio { use guid::Guid; use mesh::MeshPayload; - use vm_resource::kind::NetEndpointHandleKind; use vm_resource::ResourceId; + use vm_resource::kind::NetEndpointHandleKind; /// A Hyper-V networking switch port ID. #[derive(Copy, Clone, MeshPayload)] @@ -74,8 +74,8 @@ pub mod dio { /// Linux TAP backend. pub mod tap { use mesh::MeshPayload; - use vm_resource::kind::NetEndpointHandleKind; use vm_resource::ResourceId; + use vm_resource::kind::NetEndpointHandleKind; /// A handle to a TAP device. #[derive(MeshPayload)] diff --git a/vm/devices/net/net_consomme/consomme/src/dhcp.rs b/vm/devices/net/net_consomme/consomme/src/dhcp.rs index 350d3a810b..12aa91b4a1 100644 --- a/vm/devices/net/net_consomme/consomme/src/dhcp.rs +++ b/vm/devices/net/net_consomme/consomme/src/dhcp.rs @@ -7,6 +7,7 @@ use super::DropReason; use crate::ChecksumState; use crate::MIN_MTU; use smoltcp::phy::ChecksumCapabilities; +use smoltcp::wire::DHCP_MAX_DNS_SERVER_COUNT; use smoltcp::wire::DhcpMessageType; use smoltcp::wire::DhcpPacket; use smoltcp::wire::DhcpRepr; @@ -20,7 +21,6 @@ use smoltcp::wire::Ipv4Packet; use smoltcp::wire::Ipv4Repr; use smoltcp::wire::UdpPacket; use smoltcp::wire::UdpRepr; -use smoltcp::wire::DHCP_MAX_DNS_SERVER_COUNT; pub const DHCP_SERVER: u16 = 67; pub const DHCP_CLIENT: u16 = 68; diff --git a/vm/devices/net/net_consomme/consomme/src/dns_windows.rs b/vm/devices/net/net_consomme/consomme/src/dns_windows.rs index d77f175cd2..1ef3fae50c 100644 --- a/vm/devices/net/net_consomme/consomme/src/dns_windows.rs +++ b/vm/devices/net/net_consomme/consomme/src/dns_windows.rs @@ -8,17 +8,17 @@ use smoltcp::wire::Ipv4Address; use std::alloc::Layout; use std::io; use std::net::Ipv4Addr; -use std::ptr::null_mut; use std::ptr::NonNull; +use std::ptr::null_mut; use thiserror::Error; use windows_sys::Win32::Foundation::ERROR_BUFFER_OVERFLOW; use windows_sys::Win32::Foundation::ERROR_SUCCESS; -use windows_sys::Win32::NetworkManagement::IpHelper::GetAdaptersAddresses; use windows_sys::Win32::NetworkManagement::IpHelper::GAA_FLAG_INCLUDE_ALL_INTERFACES; use windows_sys::Win32::NetworkManagement::IpHelper::GAA_FLAG_SKIP_ANYCAST; use windows_sys::Win32::NetworkManagement::IpHelper::GAA_FLAG_SKIP_FRIENDLY_NAME; use windows_sys::Win32::NetworkManagement::IpHelper::GAA_FLAG_SKIP_MULTICAST; use windows_sys::Win32::NetworkManagement::IpHelper::GAA_FLAG_SKIP_UNICAST; +use windows_sys::Win32::NetworkManagement::IpHelper::GetAdaptersAddresses; use windows_sys::Win32::NetworkManagement::IpHelper::IP_ADAPTER_ADDRESSES_LH; use windows_sys::Win32::Networking::WinSock::AF_INET; use windows_sys::Win32::Networking::WinSock::SOCKADDR_IN; @@ -53,7 +53,7 @@ pub fn nameservers() -> Result, Error> { err => { return Err(Error::AdapterAddresses(io::Error::from_raw_os_error( err as i32, - ))) + ))); } } diff --git a/vm/devices/net/net_consomme/consomme/src/lib.rs b/vm/devices/net/net_consomme/consomme/src/lib.rs index f938e94b3e..79428b6cca 100644 --- a/vm/devices/net/net_consomme/consomme/src/lib.rs +++ b/vm/devices/net/net_consomme/consomme/src/lib.rs @@ -35,10 +35,10 @@ use smoltcp::wire::EthernetAddress; use smoltcp::wire::EthernetFrame; use smoltcp::wire::EthernetProtocol; use smoltcp::wire::EthernetRepr; +use smoltcp::wire::IPV4_HEADER_LEN; use smoltcp::wire::IpProtocol; use smoltcp::wire::Ipv4Address; use smoltcp::wire::Ipv4Packet; -use smoltcp::wire::IPV4_HEADER_LEN; use std::net::Ipv4Addr; use std::net::SocketAddrV4; use std::task::Context; diff --git a/vm/devices/net/net_consomme/consomme/src/tcp.rs b/vm/devices/net/net_consomme/consomme/src/tcp.rs index 2d5f19ccfd..d02ea578c5 100644 --- a/vm/devices/net/net_consomme/consomme/src/tcp.rs +++ b/vm/devices/net/net_consomme/consomme/src/tcp.rs @@ -18,8 +18,10 @@ use pal_async::interest::PollEvents; use pal_async::socket::PollReady; use pal_async::socket::PolledSocket; use smoltcp::phy::ChecksumCapabilities; +use smoltcp::wire::ETHERNET_HEADER_LEN; use smoltcp::wire::EthernetFrame; use smoltcp::wire::EthernetProtocol; +use smoltcp::wire::IPV4_HEADER_LEN; use smoltcp::wire::IpProtocol; use smoltcp::wire::Ipv4Packet; use smoltcp::wire::Ipv4Repr; @@ -27,16 +29,14 @@ use smoltcp::wire::TcpControl; use smoltcp::wire::TcpPacket; use smoltcp::wire::TcpRepr; use smoltcp::wire::TcpSeqNumber; -use smoltcp::wire::ETHERNET_HEADER_LEN; -use smoltcp::wire::IPV4_HEADER_LEN; use socket2::Domain; use socket2::Protocol; use socket2::SockAddr; use socket2::Socket; use socket2::Type; -use std::collections::hash_map; use std::collections::HashMap; use std::collections::VecDeque; +use std::collections::hash_map; use std::io; use std::io::ErrorKind; use std::io::IoSlice; diff --git a/vm/devices/net/net_consomme/consomme/src/udp.rs b/vm/devices/net/net_consomme/consomme/src/udp.rs index 8a7f404abf..e2e531c5f1 100644 --- a/vm/devices/net/net_consomme/consomme/src/udp.rs +++ b/vm/devices/net/net_consomme/consomme/src/udp.rs @@ -1,12 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::dhcp::DHCP_SERVER; use super::Access; use super::Client; use super::ConsommeState; use super::DropReason; use super::SocketAddress; +use super::dhcp::DHCP_SERVER; use crate::ChecksumState; use crate::Ipv4Addresses; use inspect::Inspect; @@ -16,20 +16,20 @@ use pal_async::interest::InterestSlot; use pal_async::interest::PollEvents; use pal_async::socket::PolledSocket; use smoltcp::phy::ChecksumCapabilities; +use smoltcp::wire::ETHERNET_HEADER_LEN; use smoltcp::wire::EthernetAddress; use smoltcp::wire::EthernetFrame; use smoltcp::wire::EthernetProtocol; use smoltcp::wire::EthernetRepr; +use smoltcp::wire::IPV4_HEADER_LEN; use smoltcp::wire::IpProtocol; use smoltcp::wire::Ipv4Packet; use smoltcp::wire::Ipv4Repr; +use smoltcp::wire::UDP_HEADER_LEN; use smoltcp::wire::UdpPacket; use smoltcp::wire::UdpRepr; -use smoltcp::wire::ETHERNET_HEADER_LEN; -use smoltcp::wire::IPV4_HEADER_LEN; -use smoltcp::wire::UDP_HEADER_LEN; -use std::collections::hash_map; use std::collections::HashMap; +use std::collections::hash_map; use std::io::ErrorKind; use std::net::IpAddr; use std::net::Ipv4Addr; diff --git a/vm/devices/net/net_consomme/src/resolver.rs b/vm/devices/net/net_consomme/src/resolver.rs index c58b892c3d..7e3dc5b656 100644 --- a/vm/devices/net/net_consomme/src/resolver.rs +++ b/vm/devices/net/net_consomme/src/resolver.rs @@ -7,9 +7,9 @@ use net_backend::resolve::ResolveEndpointParams; use net_backend::resolve::ResolvedEndpoint; use net_backend_resources::consomme::ConsommeHandle; use thiserror::Error; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::NetEndpointHandleKind; -use vm_resource::ResolveResource; pub struct ConsommeResolver; diff --git a/vm/devices/net/net_dio/src/lib.rs b/vm/devices/net/net_dio/src/lib.rs index 3fb0251743..6fa374aafd 100644 --- a/vm/devices/net/net_dio/src/lib.rs +++ b/vm/devices/net/net_dio/src/lib.rs @@ -11,7 +11,6 @@ pub mod resolver; use anyhow::Context as _; use async_trait::async_trait; use inspect::InspectMut; -use net_backend::next_packet; use net_backend::BufferAccess; use net_backend::Endpoint; use net_backend::Queue; @@ -21,6 +20,7 @@ use net_backend::RxId; use net_backend::RxMetadata; use net_backend::TxId; use net_backend::TxSegment; +use net_backend::next_packet; use pal_async::driver::Driver; use parking_lot::Mutex; use std::io::ErrorKind; diff --git a/vm/devices/net/net_dio/src/resolver.rs b/vm/devices/net/net_dio/src/resolver.rs index cb14e8131c..821966fbd3 100644 --- a/vm/devices/net/net_dio/src/resolver.rs +++ b/vm/devices/net/net_dio/src/resolver.rs @@ -7,9 +7,9 @@ use guid::Guid; use net_backend::resolve::ResolveEndpointParams; use net_backend::resolve::ResolvedEndpoint; use net_backend_resources::dio::WindowsDirectIoHandle; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::NetEndpointHandleKind; -use vm_resource::ResolveResource; pub struct DioResolver; diff --git a/vm/devices/net/net_mana/src/lib.rs b/vm/devices/net/net_mana/src/lib.rs index dda4b2c228..1bd8f77ac8 100644 --- a/vm/devices/net/net_mana/src/lib.rs +++ b/vm/devices/net/net_mana/src/lib.rs @@ -7,17 +7,17 @@ use anyhow::Context as _; use async_trait::async_trait; use futures::FutureExt; use futures::StreamExt; -use gdma_defs::bnic::ManaQueryStatisticsResponse; -use gdma_defs::bnic::ManaRxcompOob; -use gdma_defs::bnic::ManaTxCompOob; -use gdma_defs::bnic::ManaTxOob; +use gdma_defs::Cqe; +use gdma_defs::GDMA_EQE_COMPLETION; +use gdma_defs::Sge; use gdma_defs::bnic::CQE_RX_OKAY; use gdma_defs::bnic::CQE_TX_OKAY; use gdma_defs::bnic::MANA_LONG_PKT_FMT; use gdma_defs::bnic::MANA_SHORT_PKT_FMT; -use gdma_defs::Cqe; -use gdma_defs::Sge; -use gdma_defs::GDMA_EQE_COMPLETION; +use gdma_defs::bnic::ManaQueryStatisticsResponse; +use gdma_defs::bnic::ManaRxcompOob; +use gdma_defs::bnic::ManaTxCompOob; +use gdma_defs::bnic::ManaTxOob; use guestmem::GuestMemory; use inspect::Inspect; use inspect::InspectMut; @@ -50,20 +50,20 @@ use net_backend::TxSegmentType; use pal_async::task::Spawn; use safeatomic::AtomicSliceOps; use std::collections::VecDeque; +use std::sync::Arc; +use std::sync::Weak; use std::sync::atomic::AtomicU8; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Arc; -use std::sync::Weak; use std::task::Context; use std::task::Poll; use thiserror::Error; +use user_driver::DeviceBacking; +use user_driver::DmaClient; use user_driver::interrupt::DeviceInterrupt; use user_driver::memory::MemoryBlock; use user_driver::memory::PAGE_SIZE32; use user_driver::memory::PAGE_SIZE64; -use user_driver::DeviceBacking; -use user_driver::DmaClient; use vmcore::slim_event::SlimEvent; use zerocopy::FromBytes; use zerocopy::FromZeros; @@ -1286,14 +1286,14 @@ mod tests { use gdma::VportConfig; use gdma_defs::bnic::ManaQueryDeviceCfgResp; use mana_driver::mana::ManaDevice; - use net_backend::loopback::LoopbackEndpoint; use net_backend::Endpoint; use net_backend::QueueConfig; use net_backend::RxId; use net_backend::TxId; use net_backend::TxSegment; - use pal_async::async_test; + use net_backend::loopback::LoopbackEndpoint; use pal_async::DefaultDriver; + use pal_async::async_test; use pci_core::msi::MsiInterruptSet; use std::future::poll_fn; use test_with_tracing::test; diff --git a/vm/devices/net/net_packet_capture/src/lib.rs b/vm/devices/net/net_packet_capture/src/lib.rs index 5f3975f1d2..61f6e8e258 100644 --- a/vm/devices/net/net_packet_capture/src/lib.rs +++ b/vm/devices/net/net_packet_capture/src/lib.rs @@ -6,16 +6,15 @@ #![expect(missing_docs)] use async_trait::async_trait; -use futures::lock::Mutex; use futures::FutureExt; use futures::StreamExt; +use futures::lock::Mutex; use futures_concurrency::future::Race; use guestmem::GuestMemory; use inspect::InspectMut; use mesh::error::RemoteError; use mesh::rpc::FailableRpc; use mesh::rpc::RpcSend; -use net_backend::next_packet; use net_backend::BufferAccess; use net_backend::Endpoint; use net_backend::EndpointAction; @@ -27,18 +26,19 @@ use net_backend::RxId; use net_backend::TxId; use net_backend::TxOffloadSupport; use net_backend::TxSegment; -use pcap_file::pcapng::blocks::enhanced_packet::EnhancedPacketBlock; -use pcap_file::pcapng::blocks::interface_description::InterfaceDescriptionBlock; -use pcap_file::pcapng::PcapNgWriter; +use net_backend::next_packet; use pcap_file::DataLink; use pcap_file::PcapError; use pcap_file::PcapResult; +use pcap_file::pcapng::PcapNgWriter; +use pcap_file::pcapng::blocks::enhanced_packet::EnhancedPacketBlock; +use pcap_file::pcapng::blocks::interface_description::InterfaceDescriptionBlock; use std::borrow::Cow; use std::io::Write; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Arc; use std::task::Context; use std::task::Poll; use std::time::Duration; diff --git a/vm/devices/net/net_tap/src/lib.rs b/vm/devices/net/net_tap/src/lib.rs index 226c75892f..8816586f43 100644 --- a/vm/devices/net/net_tap/src/lib.rs +++ b/vm/devices/net/net_tap/src/lib.rs @@ -12,7 +12,6 @@ mod tap; use async_trait::async_trait; use futures::io::AsyncRead; use inspect::InspectMut; -use net_backend::linearize; use net_backend::BufferAccess; use net_backend::Endpoint; use net_backend::Queue; @@ -22,6 +21,7 @@ use net_backend::RxId; use net_backend::RxMetadata; use net_backend::TxId; use net_backend::TxSegment; +use net_backend::linearize; use pal_async::driver::Driver; use parking_lot::Mutex; use std::collections::VecDeque; diff --git a/vm/devices/net/net_tap/src/resolver.rs b/vm/devices/net/net_tap/src/resolver.rs index 02c8230ef0..bfabd63534 100644 --- a/vm/devices/net/net_tap/src/resolver.rs +++ b/vm/devices/net/net_tap/src/resolver.rs @@ -5,9 +5,9 @@ use crate::TapEndpoint; use net_backend::resolve::ResolveEndpointParams; use net_backend::resolve::ResolvedEndpoint; use net_backend_resources::tap::TapHandle; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::NetEndpointHandleKind; -use vm_resource::ResolveResource; pub struct TapResolver; diff --git a/vm/devices/net/netvsp/src/buffers.rs b/vm/devices/net/netvsp/src/buffers.rs index 6812ec6860..3c6c11f1fc 100644 --- a/vm/devices/net/netvsp/src/buffers.rs +++ b/vm/devices/net/netvsp/src/buffers.rs @@ -4,8 +4,8 @@ //! Implementation of [`RxBufferAccess`] and friends on top of the receive //! buffers. -use crate::rndisprot; use crate::MAX_MTU; +use crate::rndisprot; use arrayvec::ArrayVec; use guestmem::GuestMemory; use guestmem::GuestMemoryError; diff --git a/vm/devices/net/netvsp/src/lib.rs b/vm/devices/net/netvsp/src/lib.rs index 5b7da59b8e..473869469c 100644 --- a/vm/devices/net/netvsp/src/lib.rs +++ b/vm/devices/net/netvsp/src/lib.rs @@ -17,25 +17,25 @@ mod test; use crate::buffers::GuestBuffers; use crate::protocol::Message1RevokeReceiveBuffer; use crate::protocol::Message1RevokeSendBuffer; -use crate::protocol::Version; use crate::protocol::VMS_SWITCH_RSS_MAX_SEND_INDIRECTION_TABLE_ENTRIES; +use crate::protocol::Version; use crate::rndisprot::NDIS_HASH_FUNCTION_MASK; use crate::rndisprot::NDIS_RSS_PARAM_FLAG_DISABLE_RSS; use async_trait::async_trait; -use buffers::sub_allocation_size_for_mtu; pub use buffers::BufferPool; -use futures::channel::mpsc; +use buffers::sub_allocation_size_for_mtu; use futures::FutureExt; use futures::StreamExt; +use futures::channel::mpsc; use futures_concurrency::future::Race; -use guestmem::ranges::PagedRange; -use guestmem::ranges::PagedRanges; -use guestmem::ranges::PagedRangesReader; use guestmem::AccessError; use guestmem::GuestMemory; use guestmem::GuestMemoryError; use guestmem::MemoryRead; use guestmem::MemoryWrite; +use guestmem::ranges::PagedRange; +use guestmem::ranges::PagedRanges; +use guestmem::ranges::PagedRangesReader; use guid::Guid; use hvdef::hypercall::HvGuestOsId; use hvdef::hypercall::HvGuestOsMicrosoft; @@ -66,9 +66,9 @@ use std::fmt::Debug; use std::future::pending; use std::mem::offset_of; use std::ops::Range; +use std::sync::Arc; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Arc; use std::task::Poll; use std::time::Duration; use task_control::AsyncRun; @@ -93,13 +93,13 @@ use vmbus_channel::gpadl::GpadlId; use vmbus_channel::gpadl::GpadlMapView; use vmbus_channel::gpadl::GpadlView; use vmbus_channel::gpadl::UnknownGpadlId; -use vmbus_channel::gpadl_ring::gpadl_channel; use vmbus_channel::gpadl_ring::GpadlRingMem; +use vmbus_channel::gpadl_ring::gpadl_channel; use vmbus_ring as ring; -use vmbus_ring::gparange::GpnList; -use vmbus_ring::gparange::MultiPagedRangeBuf; use vmbus_ring::OutgoingPacketType; use vmbus_ring::RingMem; +use vmbus_ring::gparange::GpnList; +use vmbus_ring::gparange::MultiPagedRangeBuf; use vmcore::save_restore::RestoreError; use vmcore::save_restore::SaveError; use vmcore::save_restore::SavedStateBlob; @@ -488,24 +488,34 @@ impl std::fmt::Display for PrimaryChannelGuestVfState { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { PrimaryChannelGuestVfState::Initializing => write!(f, "initializing"), - PrimaryChannelGuestVfState::Restoring(saved_state::GuestVfState::NoState) => write!(f, "restoring"), - PrimaryChannelGuestVfState::Restoring(saved_state::GuestVfState::AvailableAdvertised) => write!(f, "restoring from guest notified of vfid"), - PrimaryChannelGuestVfState::Restoring(saved_state::GuestVfState::Ready) => write!(f, "restoring from vf present"), - PrimaryChannelGuestVfState::Restoring(saved_state::GuestVfState::DataPathSwitchPending{to_guest, result, ..}) => { - write!(f, "restoring from client requested data path switch: to {} {}", + PrimaryChannelGuestVfState::Restoring(saved_state::GuestVfState::NoState) => { + write!(f, "restoring") + } + PrimaryChannelGuestVfState::Restoring( + saved_state::GuestVfState::AvailableAdvertised, + ) => write!(f, "restoring from guest notified of vfid"), + PrimaryChannelGuestVfState::Restoring(saved_state::GuestVfState::Ready) => { + write!(f, "restoring from vf present") + } + PrimaryChannelGuestVfState::Restoring( + saved_state::GuestVfState::DataPathSwitchPending { + to_guest, result, .. + }, + ) => { + write!( + f, + "restoring from client requested data path switch: to {} {}", if *to_guest { "guest" } else { "synthetic" }, if let Some(result) = result { - if *result { - "succeeded\"" - } else { - "failed\"" - } + if *result { "succeeded\"" } else { "failed\"" } } else { "in progress\"" } ) } - PrimaryChannelGuestVfState::Restoring(saved_state::GuestVfState::DataPathSwitched) => write!(f, "restoring from data path in guest"), + PrimaryChannelGuestVfState::Restoring(saved_state::GuestVfState::DataPathSwitched) => { + write!(f, "restoring from data path in guest") + } PrimaryChannelGuestVfState::Unavailable => write!(f, "unavailable"), PrimaryChannelGuestVfState::UnavailableFromAvailable => { write!(f, "\"unavailable (previously available)\"") @@ -516,8 +526,10 @@ impl std::fmt::Display for PrimaryChannelGuestVfState { PrimaryChannelGuestVfState::UnavailableFromDataPathSwitched => { write!(f, "\"unavailable (previously using guest VF)\"") } - PrimaryChannelGuestVfState::Available{vfid} => write!(f, "available vfid: {}", vfid), - PrimaryChannelGuestVfState::AvailableAdvertised => write!(f, "\"available, guest notified\""), + PrimaryChannelGuestVfState::Available { vfid } => write!(f, "available vfid: {}", vfid), + PrimaryChannelGuestVfState::AvailableAdvertised => { + write!(f, "\"available, guest notified\"") + } PrimaryChannelGuestVfState::Ready => write!(f, "\"available and present in guest\""), PrimaryChannelGuestVfState::DataPathSwitchPending { to_guest, result, .. @@ -527,11 +539,7 @@ impl std::fmt::Display for PrimaryChannelGuestVfState { "\"switching to {} {}", if *to_guest { "guest" } else { "synthetic" }, if let Some(result) = result { - if *result { - "succeeded\"" - } else { - "failed\"" - } + if *result { "succeeded\"" } else { "failed\"" } } else { "in progress\"" } @@ -2561,7 +2569,9 @@ impl NetChannel { primary.guest_vf_state = PrimaryChannelGuestVfState::AvailableAdvertised; return Ok(Some(CoordinatorMessage::UpdateGuestVfState)); } else if let Some(true) = primary.is_data_path_switched { - tracing::error!("Data path switched, but current guest negotiation does not support VTL0 VF"); + tracing::error!( + "Data path switched, but current guest negotiation does not support VTL0 VF" + ); } } return Ok(None); @@ -2702,7 +2712,9 @@ impl NetChannel { self.restart = Some(CoordinatorMessage::UpdateGuestVfState); } } else if let Some(true) = primary.is_data_path_switched { - tracing::error!("Data path switched, but current guest negotiation does not support VTL0 VF"); + tracing::error!( + "Data path switched, but current guest negotiation does not support VTL0 VF" + ); } } } @@ -2772,10 +2784,10 @@ impl NetChannel { self.send_rndis_control_message(buffers, id, message_length)?; } rndisprot::MESSAGE_TYPE_RESET_MSG => { - return Err(WorkerError::RndisMessageTypeNotImplemented) + return Err(WorkerError::RndisMessageTypeNotImplemented); } rndisprot::MESSAGE_TYPE_INDICATE_STATUS_MSG => { - return Err(WorkerError::RndisMessageTypeNotImplemented) + return Err(WorkerError::RndisMessageTypeNotImplemented); } rndisprot::MESSAGE_TYPE_KEEPALIVE_MSG => { let request: rndisprot::KeepaliveRequest = reader.read_plain()?; @@ -2797,7 +2809,7 @@ impl NetChannel { self.send_rndis_control_message(buffers, id, message_length)?; } rndisprot::MESSAGE_TYPE_SET_EX_MSG => { - return Err(WorkerError::RndisMessageTypeNotImplemented) + return Err(WorkerError::RndisMessageTypeNotImplemented); } _ => return Err(WorkerError::UnknownRndisMessageType(message_type)), }; @@ -4695,7 +4707,7 @@ impl NetChannel { PendingLinkAction::Delay(_) => { return Ok(CoordinatorMessage::StartTimer( Instant::now() + LINK_DELAY_DURATION, - )) + )); } PendingLinkAction::Active(_) => panic!("State should not be Active"), _ => {} diff --git a/vm/devices/net/netvsp/src/resolver.rs b/vm/devices/net/netvsp/src/resolver.rs index 4253397d60..110c070737 100644 --- a/vm/devices/net/netvsp/src/resolver.rs +++ b/vm/devices/net/netvsp/src/resolver.rs @@ -5,11 +5,11 @@ use crate::Nic; use async_trait::async_trait; use net_backend::resolve::ResolveEndpointParams; use netvsp_resources::NetvspHandle; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::VmbusDeviceHandleKind; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; diff --git a/vm/devices/net/netvsp/src/rx_bufs.rs b/vm/devices/net/netvsp/src/rx_bufs.rs index 8a5a90e770..dc01c3324f 100644 --- a/vm/devices/net/netvsp/src/rx_bufs.rs +++ b/vm/devices/net/netvsp/src/rx_bufs.rs @@ -156,9 +156,10 @@ mod tests { assert!(bufs.free(9).is_none()); assert!(bufs.free(12).is_none()); assert!(bufs.free(6).unwrap().eq([6, 9, 5])); - assert!(bufs - .allocated() - .map(Vec::from_iter) - .eq([[0, 1, 2], [3, 10, 12]])); + assert!( + bufs.allocated() + .map(Vec::from_iter) + .eq([[0, 1, 2], [3, 10, 12]]) + ); } } diff --git a/vm/devices/net/netvsp/src/test.rs b/vm/devices/net/netvsp/src/test.rs index efeead6097..7efee7f11b 100644 --- a/vm/devices/net/netvsp/src/test.rs +++ b/vm/devices/net/netvsp/src/test.rs @@ -4,33 +4,33 @@ #![cfg(test)] use super::*; -use crate::protocol::Version; -use crate::rndisprot; use crate::Arc; use crate::GuestMemory; use crate::Guid; use crate::InspectMut; +use crate::protocol::Version; +use crate::rndisprot; use async_trait::async_trait; use buffers::sub_allocation_size_for_mtu; use futures::FutureExt; use futures::StreamExt; use futures::TryFutureExt; -use guestmem::ranges::PagedRanges; use guestmem::MemoryRead; use guestmem::MemoryWrite; +use guestmem::ranges::PagedRanges; use hvdef::hypercall::HvGuestOsId; use hvdef::hypercall::HvGuestOsMicrosoft; use hvdef::hypercall::HvGuestOsMicrosoftIds; use mesh::rpc::Rpc; use mesh::rpc::RpcError; use mesh::rpc::RpcSend; -use net_backend::null::NullEndpoint; use net_backend::DisconnectableEndpoint; use net_backend::Endpoint; use net_backend::EndpointAction; use net_backend::QueueConfig; -use pal_async::async_test; +use net_backend::null::NullEndpoint; use pal_async::DefaultDriver; +use pal_async::async_test; use std::collections::HashMap; use std::collections::VecDeque; use std::sync::atomic::AtomicBool; @@ -40,6 +40,9 @@ use test_with_tracing::test; use vmbus_async::queue::IncomingPacket; use vmbus_async::queue::OutgoingPacket; use vmbus_async::queue::Queue; +use vmbus_channel::ChannelClosed; +use vmbus_channel::RawAsyncChannel; +use vmbus_channel::SignalVmbusChannel; use vmbus_channel::bus::ChannelRequest; use vmbus_channel::bus::GpadlRequest; use vmbus_channel::bus::ModifyRequest; @@ -49,28 +52,25 @@ use vmbus_channel::bus::OpenData; use vmbus_channel::bus::OpenRequest; use vmbus_channel::bus::OpenResult; use vmbus_channel::bus::ParentBus; -use vmbus_channel::channel::offer_channel; use vmbus_channel::channel::ChannelHandle; use vmbus_channel::channel::VmbusDevice; +use vmbus_channel::channel::offer_channel; use vmbus_channel::gpadl::GpadlId; use vmbus_channel::gpadl::GpadlMap; use vmbus_channel::gpadl::GpadlMapView; use vmbus_channel::gpadl_ring::AlignedGpadlView; use vmbus_channel::gpadl_ring::GpadlRingMem; -use vmbus_channel::ChannelClosed; -use vmbus_channel::RawAsyncChannel; -use vmbus_channel::SignalVmbusChannel; use vmbus_core::protocol::UserDefinedData; -use vmbus_ring::gparange::MultiPagedRangeBuf; use vmbus_ring::IncomingRing; use vmbus_ring::OutgoingRing; use vmbus_ring::PAGE_SIZE; +use vmbus_ring::gparange::MultiPagedRangeBuf; use vmcore::interrupt::Interrupt; use vmcore::save_restore::SavedStateBlob; use vmcore::slim_event::SlimEvent; -use vmcore::vm_task::thread::ThreadDriverBackend; use vmcore::vm_task::SingleDriverBackend; use vmcore::vm_task::VmTaskDriverSource; +use vmcore::vm_task::thread::ThreadDriverBackend; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::Immutable; @@ -1475,10 +1475,12 @@ async fn initialize_rndis(driver: DefaultDriver) { assert_eq!(initialize_complete.minor_version, rndisprot::MINOR_VERSION); // Not expecting an association packet because virtual function is not present - assert!(channel - .read_with(|_| panic!("No packet expected")) - .await - .is_err()); + assert!( + channel + .read_with(|_| panic!("No packet expected")) + .await + .is_err() + ); assert_eq!(endpoint_state.lock().stop_endpoint_counter, 1); } @@ -1535,10 +1537,12 @@ async fn initialize_rndis_no_sendbuffer(driver: DefaultDriver) { assert_eq!(initialize_complete.minor_version, rndisprot::MINOR_VERSION); // Not expecting an association packet because virtual function is not present - assert!(channel - .read_with(|_| panic!("No packet expected")) - .await - .is_err()); + assert!( + channel + .read_with(|_| panic!("No packet expected")) + .await + .is_err() + ); assert_eq!(endpoint_state.lock().stop_endpoint_counter, 1); } @@ -1651,10 +1655,12 @@ async fn initialize_rndis_with_vf(driver: DefaultDriver) { .expect("association packet"); // Device will be made ready after packet is sent because Linux netvsc does not send completion packet. - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); channel .write(OutgoingPacket { @@ -1797,10 +1803,12 @@ async fn initialize_rndis_with_vf_alternate_id(driver: DefaultDriver) { // Device will be made ready after packet is sent because Linux netvsc does // not send completion packet. - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); channel .write(OutgoingPacket { @@ -1891,10 +1899,12 @@ async fn initialize_rndis_with_vf_multi_open(driver: DefaultDriver) { .await .expect("association packet"); - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); // // Revoke and open a new vmbus channel. This happens from a normal @@ -2073,10 +2083,12 @@ async fn initialize_rndis_with_prev_vf_switch_data_path(driver: DefaultDriver) { // The data path was already switched before the device started, so not // expecting any VF state change. - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_err()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_err() + ); // send switch data path message let message = NvspMessage { @@ -2173,10 +2185,12 @@ async fn stop_start_with_vf(driver: DefaultDriver) { }) .await; - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); // VF should remain visible through start/stop channel.stop().await; @@ -2216,10 +2230,12 @@ async fn stop_start_with_vf(driver: DefaultDriver) { // The switch data path triggers a VF update as it uses the common restore // 'guest VF' state logic. - assert!(test_vf_state - .await_ready(true, Duration::ZERO) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::ZERO) + .await + .is_ok() + ); // VF should remain visible through start/stop channel.stop().await; @@ -2287,10 +2303,12 @@ async fn save_restore_with_vf(driver: DefaultDriver) { .await .expect("association packet"); - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); // // Save/restore. @@ -2329,10 +2347,12 @@ async fn save_restore_with_vf(driver: DefaultDriver) { }) .await; - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); channel.stop().await; let restore_state = channel.save().await.unwrap().unwrap(); @@ -2367,10 +2387,12 @@ async fn save_restore_with_vf(driver: DefaultDriver) { payload: &[], }) .await; - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); endpoint_state.lock().poll_iterations_required = 5; let message = NvspMessage { @@ -2484,10 +2506,12 @@ async fn save_restore_with_vf_multi_open(driver: DefaultDriver) { }) .await; - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); // // Disconnect/reconnect vmbus a couple of times, re-establishing connection on the second. @@ -2503,10 +2527,12 @@ async fn save_restore_with_vf_multi_open(driver: DefaultDriver) { let mut channel = nic.connect_vmbus_channel().await; // No network init has been done on newer channels, so VF should not be present. - assert!(test_vf_state - .await_ready(false, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(false, Duration::from_millis(333)) + .await + .is_ok() + ); channel .initialize(0, protocol::NdisConfigCapabilities::new().with_sriov(true)) @@ -2552,10 +2578,12 @@ async fn save_restore_with_vf_multi_open(driver: DefaultDriver) { }) .await; - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); // // Invoke save/restore @@ -2845,10 +2873,12 @@ async fn dynamic_vf_support(driver: DefaultDriver) { }) .await; - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); // // Remove VF ID. @@ -2921,10 +2951,12 @@ async fn dynamic_vf_support(driver: DefaultDriver) { }) .await; - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); let message = NvspMessage { header: protocol::MessageHeader { @@ -2951,10 +2983,12 @@ async fn dynamic_vf_support(driver: DefaultDriver) { .expect("completion message"); assert_eq!(endpoint_state.lock().use_vf.take().unwrap(), true); - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); // // Remove VF ID. The VF state that tracks whether the VF can be offered @@ -3020,10 +3054,12 @@ async fn dynamic_vf_support(driver: DefaultDriver) { }) .await; - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); let message = NvspMessage { header: protocol::MessageHeader { @@ -3063,14 +3099,18 @@ async fn dynamic_vf_support(driver: DefaultDriver) { endpoint_state.lock().stop_endpoint_counter, stop_endpoint_counter + 1 ); - assert!(channel - .read_with(|_| panic!("No packet expected")) - .await - .is_err()); - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + channel + .read_with(|_| panic!("No packet expected")) + .await + .is_err() + ); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); assert!(endpoint_state.lock().use_vf.is_none()); } @@ -3637,10 +3677,12 @@ async fn set_rss_parameter_unused_first_queue(driver: DefaultDriver) { .await .expect("association packet"); - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); let message = NvspMessage { header: protocol::MessageHeader { @@ -3852,10 +3894,12 @@ async fn race_coordinator_and_worker_stop_events(driver: DefaultDriver) { .await .expect("association packet"); - assert!(test_vf_state - .await_ready(true, Duration::from_millis(333)) - .await - .is_ok()); + assert!( + test_vf_state + .await_ready(true, Duration::from_millis(333)) + .await + .is_ok() + ); let link_update_completion_message = NvspMessage { header: protocol::MessageHeader { diff --git a/vm/devices/net/netvsp_resources/src/lib.rs b/vm/devices/net/netvsp_resources/src/lib.rs index 6e481f63b0..6ab461b6e2 100644 --- a/vm/devices/net/netvsp_resources/src/lib.rs +++ b/vm/devices/net/netvsp_resources/src/lib.rs @@ -8,10 +8,10 @@ use guid::Guid; use mesh::MeshPayload; use net_backend_resources::mac_address::MacAddress; -use vm_resource::kind::NetEndpointHandleKind; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::NetEndpointHandleKind; +use vm_resource::kind::VmbusDeviceHandleKind; /// A handle to a netvsp device. #[derive(MeshPayload)] diff --git a/vm/devices/net/vmswitch/src/dio.rs b/vm/devices/net/vmswitch/src/dio.rs index db5fd351f9..139f930732 100644 --- a/vm/devices/net/vmswitch/src/dio.rs +++ b/vm/devices/net/vmswitch/src/dio.rs @@ -5,14 +5,14 @@ //! type. This provides a tap-like interface to vmswitch on Windows, allowing //! Ethernet frames to be sent and received. -use super::kernel::c16; use super::kernel::SwitchPortId; +use super::kernel::c16; use super::vmsif; use futures::AsyncRead; use guid::Guid; -use pal::windows::status_to_error; use pal::windows::Overlapped; use pal::windows::SendSyncRawHandle; +use pal::windows::status_to_error; use pal_async::driver::Driver; use pal_async::wait::PolledWait; use pal_event::Event; @@ -348,9 +348,9 @@ mod tests { use futures::AsyncReadExt; use futures::FutureExt; use guid::Guid; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::driver::Driver; - use pal_async::DefaultDriver; const MAC_ADDRESS: [u8; 6] = [0x00, 0x15, 0x5D, 0x18, 0x99, 0x25]; diff --git a/vm/devices/net/vmswitch/src/hcn.rs b/vm/devices/net/vmswitch/src/hcn.rs index cb0a6664f2..09f5926276 100644 --- a/vm/devices/net/vmswitch/src/hcn.rs +++ b/vm/devices/net/vmswitch/src/hcn.rs @@ -3,8 +3,8 @@ use guid::Guid; use std::ffi::c_void; -use std::ptr::null_mut; use std::ptr::NonNull; +use std::ptr::null_mut; use thiserror::Error; pal::delayload!("computenetwork.dll" { diff --git a/vm/devices/pci/pci_bus/src/lib.rs b/vm/devices/pci/pci_bus/src/lib.rs index 1541cae7ec..e5c7bef9b2 100644 --- a/vm/devices/pci/pci_bus/src/lib.rs +++ b/vm/devices/pci/pci_bus/src/lib.rs @@ -15,18 +15,18 @@ //! [`GenericPciBusDevice`] devices. use bitfield_struct::bitfield; -use chipset_device::io::deferred::defer_read; -use chipset_device::io::deferred::defer_write; +use chipset_device::ChipsetDevice; +use chipset_device::io::IoError; +use chipset_device::io::IoResult; use chipset_device::io::deferred::DeferredRead; use chipset_device::io::deferred::DeferredToken; use chipset_device::io::deferred::DeferredWrite; -use chipset_device::io::IoError; -use chipset_device::io::IoResult; +use chipset_device::io::deferred::defer_read; +use chipset_device::io::deferred::defer_write; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use std::collections::BTreeMap; diff --git a/vm/devices/pci/pci_core/src/capabilities/msix.rs b/vm/devices/pci/pci_core/src/capabilities/msix.rs index 34c395413b..4d0ed41236 100644 --- a/vm/devices/pci/pci_core/src/capabilities/msix.rs +++ b/vm/devices/pci/pci_core/src/capabilities/msix.rs @@ -6,9 +6,9 @@ use super::PciCapability; use crate::msi::MsiInterrupt; use crate::msi::RegisterMsi; +use crate::spec::caps::CapabilityId; use crate::spec::caps::msix::MsixCapabilityHeader; use crate::spec::caps::msix::MsixTableEntryIdx; -use crate::spec::caps::CapabilityId; use inspect::Inspect; use inspect::InspectMut; use parking_lot::Mutex; diff --git a/vm/devices/pci/pci_core/src/cfg_space_emu.rs b/vm/devices/pci/pci_core/src/cfg_space_emu.rs index 9c55287017..cbb11348a7 100644 --- a/vm/devices/pci/pci_core/src/cfg_space_emu.rs +++ b/vm/devices/pci/pci_core/src/cfg_space_emu.rs @@ -8,19 +8,19 @@ #![warn(missing_docs)] +use crate::PciInterruptPin; use crate::bar_mapping::BarMappings; use crate::capabilities::PciCapability; use crate::spec::cfg_space; use crate::spec::hwid::HardwareIds; -use crate::PciInterruptPin; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::mmio::ControlMmioIntercept; use guestmem::MappableGuestMemory; use inspect::Inspect; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; -use std::sync::Arc; use vmcore::line_interrupt::LineInterrupt; const SUPPORTED_COMMAND_BITS: u16 = cfg_space::Command::new() diff --git a/vm/devices/pci/pci_core/src/chipset_device_ext.rs b/vm/devices/pci/pci_core/src/chipset_device_ext.rs index dd540b1599..68682be74c 100644 --- a/vm/devices/pci/pci_core/src/chipset_device_ext.rs +++ b/vm/devices/pci/pci_core/src/chipset_device_ext.rs @@ -7,8 +7,8 @@ use crate::spec::hwid::ClassCode; use crate::spec::hwid::HardwareIds; use crate::spec::hwid::ProgrammingInterface; use crate::spec::hwid::Subclass; -use chipset_device::pci::PciConfigSpace; use chipset_device::ChipsetDevice; +use chipset_device::pci::PciConfigSpace; /// An extension trait to simplify probing PCI [`ChipsetDevice`] devices. pub trait PciChipsetDeviceExt: ChipsetDevice + PciConfigSpace { diff --git a/vm/devices/pci/pci_resources/src/lib.rs b/vm/devices/pci/pci_resources/src/lib.rs index 767e9ee8f6..1783fa5361 100644 --- a/vm/devices/pci/pci_resources/src/lib.rs +++ b/vm/devices/pci/pci_resources/src/lib.rs @@ -13,8 +13,8 @@ use guestmem::GuestMemory; use guestmem::MemoryMapper; use pci_core::msi::RegisterMsi; use std::sync::Arc; -use vm_resource::kind::PciDeviceHandleKind; use vm_resource::CanResolveTo; +use vm_resource::kind::PciDeviceHandleKind; use vmcore::vm_task::VmTaskDriverSource; impl CanResolveTo for PciDeviceHandleKind { diff --git a/vm/devices/pci/vpci/src/bus.rs b/vm/devices/pci/vpci/src/bus.rs index 7df75e1fe2..29ec021d5c 100644 --- a/vm/devices/pci/vpci/src/bus.rs +++ b/vm/devices/pci/vpci/src/bus.rs @@ -9,22 +9,22 @@ use crate::device::VpciConfigSpace; use crate::device::VpciConfigSpaceOffset; use crate::protocol; use crate::protocol::SlotNumber; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; -use chipset_device::ChipsetDevice; use closeable_mutex::CloseableMutex; +use device_emulators::ReadWriteRequestType; use device_emulators::read_as_u32_chunks; use device_emulators::write_as_u32_chunks; -use device_emulators::ReadWriteRequestType; use guid::Guid; use hvdef::HV_PAGE_SIZE; use inspect::InspectMut; use std::sync::Arc; use thiserror::Error; -use vmbus_channel::simple::offer_simple_device; use vmbus_channel::simple::SimpleDeviceHandle; +use vmbus_channel::simple::offer_simple_device; use vmcore::device_state::ChangeDeviceState; use vmcore::save_restore::NoSavedState; use vmcore::save_restore::RestoreError; diff --git a/vm/devices/pci/vpci/src/bus_control.rs b/vm/devices/pci/vpci/src/bus_control.rs index 045b06c6ca..49c6ad911d 100644 --- a/vm/devices/pci/vpci/src/bus_control.rs +++ b/vm/devices/pci/vpci/src/bus_control.rs @@ -10,8 +10,8 @@ use anyhow::Result; use async_trait::async_trait; -use mesh::payload::Protobuf; use mesh::Receiver; +use mesh::payload::Protobuf; /// Events signaled on a Virtual PCI bus. #[derive(Debug, Protobuf)] diff --git a/vm/devices/pci/vpci/src/device.rs b/vm/devices/pci/vpci/src/device.rs index 0f59d41eba..cf898cf216 100644 --- a/vm/devices/pci/vpci/src/device.rs +++ b/vm/devices/pci/vpci/src/device.rs @@ -6,8 +6,8 @@ use super::protocol; use crate::protocol::SlotNumber; use async_trait::async_trait; -use chipset_device::mmio::ControlMmioIntercept; use chipset_device::ChipsetDevice; +use chipset_device::mmio::ControlMmioIntercept; use closeable_mutex::CloseableMutex; use guestmem::AccessError; use guestmem::MemoryRead; @@ -20,9 +20,9 @@ use pci_core::spec::cfg_space; use pci_core::spec::hwid::HardwareIds; use ring::OutgoingPacketType; use std::fmt::Debug; +use std::sync::Arc; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; use task_control::Cancelled; use task_control::StopTask; use thiserror::Error; @@ -30,12 +30,12 @@ use vmbus_async::queue; use vmbus_async::queue::IncomingPacket; use vmbus_async::queue::OutgoingPacket; use vmbus_async::queue::Queue; +use vmbus_channel::RawAsyncChannel; use vmbus_channel::bus::OfferParams; use vmbus_channel::channel::ChannelOpenError; use vmbus_channel::gpadl_ring::GpadlRingMem; use vmbus_channel::simple::SaveRestoreSimpleVmbusDevice; use vmbus_channel::simple::SimpleVmbusDevice; -use vmbus_channel::RawAsyncChannel; use vmbus_ring as ring; use vmbus_ring::RingMem; use vmcore::save_restore::NoSavedState; @@ -1174,25 +1174,25 @@ mod tests { use crate::test_helpers::TestVpciInterruptController; use chipset_arc_mutex_device::services::MmioInterceptServices; use chipset_arc_mutex_device::test_chipset::TestChipset; + use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::mmio::ExternallyManagedMmioIntercepts; use chipset_device::mmio::MmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; use chipset_device::pci::PciConfigSpace; - use chipset_device::ChipsetDevice; use closeable_mutex::CloseableMutex; + use device_emulators::ReadWriteRequestType; use device_emulators::read_as_u32_chunks; use device_emulators::write_as_u32_chunks; - use device_emulators::ReadWriteRequestType; use guestmem::AccessError; use guestmem::MemoryRead; use guid::Guid; use hvdef::HV_PAGE_SIZE; use inspect::Inspect; use inspect::InspectMut; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::driver::SpawnDriver; - use pal_async::DefaultDriver; use pci_core::cfg_space_emu::BarMemoryKind; use pci_core::cfg_space_emu::ConfigSpaceType0Emulator; use pci_core::cfg_space_emu::DeviceBars; @@ -1204,15 +1204,15 @@ mod tests { use pci_core::spec::hwid::Subclass; use ring::FlatRingMem; use ring::OutgoingPacketType; + use std::sync::Arc; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; - use std::sync::Arc; use test_with_tracing::test; use thiserror::Error; - use vmbus_async::queue::connected_queues; use vmbus_async::queue::IncomingPacket; use vmbus_async::queue::OutgoingPacket; use vmbus_async::queue::Queue; + use vmbus_async::queue::connected_queues; use vmbus_ring as ring; use vmcore::vpci_msi::VpciInterruptMapper; use zerocopy::FromBytes; @@ -1787,9 +1787,11 @@ mod tests { guest_driver.start_device(base_address).await; let write_u32 = |address, value: u32| { - assert!(vm_chipset - .mmio_write(address, &value.to_ne_bytes()) - .is_some()); + assert!( + vm_chipset + .mmio_write(address, &value.to_ne_bytes()) + .is_some() + ); }; let read_u32 = |address| { let mut value = [0; 4]; diff --git a/vm/devices/serial/serial_16550/src/lib.rs b/vm/devices/serial/serial_16550/src/lib.rs index c88cb640bf..05e4dc0eb5 100644 --- a/vm/devices/serial/serial_16550/src/lib.rs +++ b/vm/devices/serial/serial_16550/src/lib.rs @@ -6,6 +6,7 @@ pub mod resolver; mod spec; +use self::spec::FIFO_SIZE; use self::spec::FifoControlRegister; use self::spec::FifoState; use self::spec::InterruptEnableRegister; @@ -17,13 +18,12 @@ use self::spec::ModemControlRegister; use self::spec::ModemStatusRegister; use self::spec::Register; use self::spec::RxFifoInterruptTrigger; -use self::spec::FIFO_SIZE; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use futures::AsyncRead; use futures::AsyncWrite; use inspect::Inspect; @@ -35,10 +35,10 @@ use std::collections::VecDeque; use std::io::ErrorKind; use std::ops::RangeInclusive; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; use std::task::Waker; +use std::task::ready; use thiserror::Error; use vmcore::device_state::ChangeDeviceState; use vmcore::line_interrupt::LineInterrupt; diff --git a/vm/devices/serial/serial_16550/src/resolver.rs b/vm/devices/serial/serial_16550/src/resolver.rs index b3ff896ed9..021e22f5a6 100644 --- a/vm/devices/serial/serial_16550/src/resolver.rs +++ b/vm/devices/serial/serial_16550/src/resolver.rs @@ -5,17 +5,17 @@ use crate::Serial16550; use async_trait::async_trait; +use chipset_device_resources::IRQ_LINE_SET; use chipset_device_resources::ResolveChipsetDeviceHandleParams; use chipset_device_resources::ResolvedChipsetDevice; -use chipset_device_resources::IRQ_LINE_SET; use serial_16550_resources::Serial16550DeviceHandle; use serial_core::resources::ResolveSerialBackendParams; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::ChipsetDeviceHandleKind; /// The resource resolver for [`Serial16550`]. pub struct Serial16550Resolver; diff --git a/vm/devices/serial/serial_16550_resources/src/lib.rs b/vm/devices/serial/serial_16550_resources/src/lib.rs index 5f0dc40ca7..9b6007c9cc 100644 --- a/vm/devices/serial/serial_16550_resources/src/lib.rs +++ b/vm/devices/serial/serial_16550_resources/src/lib.rs @@ -6,10 +6,10 @@ #![forbid(unsafe_code)] use mesh::MeshPayload; -use vm_resource::kind::ChipsetDeviceHandleKind; -use vm_resource::kind::SerialBackendHandle; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::ChipsetDeviceHandleKind; +use vm_resource::kind::SerialBackendHandle; /// A handle to a 16550A serial device. #[derive(MeshPayload)] diff --git a/vm/devices/serial/serial_core/src/disconnected.rs b/vm/devices/serial/serial_core/src/disconnected.rs index 044afe7582..25d040c446 100644 --- a/vm/devices/serial/serial_core/src/disconnected.rs +++ b/vm/devices/serial/serial_core/src/disconnected.rs @@ -65,11 +65,11 @@ pub mod resolver { use crate::resources::ResolveSerialBackendParams; use crate::resources::ResolvedSerialBackend; use std::convert::Infallible; - use vm_resource::declare_static_resolver; - use vm_resource::kind::SerialBackendHandle; use vm_resource::IntoResource; use vm_resource::ResolveResource; use vm_resource::Resource; + use vm_resource::declare_static_resolver; + use vm_resource::kind::SerialBackendHandle; /// A resolver for [`DisconnectedSerialBackendHandle`]. pub struct DisconnectedSerialBackendResolver; diff --git a/vm/devices/serial/serial_core/src/resources.rs b/vm/devices/serial/serial_core/src/resources.rs index 1bf98e8494..a3fc5a6434 100644 --- a/vm/devices/serial/serial_core/src/resources.rs +++ b/vm/devices/serial/serial_core/src/resources.rs @@ -6,10 +6,10 @@ use super::SerialIo; use mesh::MeshPayload; use pal_async::driver::Driver; -use vm_resource::kind::SerialBackendHandle; use vm_resource::CanResolveTo; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::SerialBackendHandle; impl CanResolveTo for SerialBackendHandle { type Input<'a> = ResolveSerialBackendParams<'a>; diff --git a/vm/devices/serial/serial_debugcon/src/lib.rs b/vm/devices/serial/serial_debugcon/src/lib.rs index 8e788e0ede..55cf5991c5 100644 --- a/vm/devices/serial/serial_debugcon/src/lib.rs +++ b/vm/devices/serial/serial_debugcon/src/lib.rs @@ -9,11 +9,11 @@ pub mod resolver; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use futures::AsyncWrite; use inspect::InspectMut; use serial_core::SerialIo; @@ -21,10 +21,10 @@ use std::collections::VecDeque; use std::io::ErrorKind; use std::ops::RangeInclusive; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; use std::task::Waker; +use std::task::ready; use vmcore::device_state::ChangeDeviceState; // the bound here is entirely arbitrary. we pick a relatively large number, just diff --git a/vm/devices/serial/serial_debugcon/src/resolver.rs b/vm/devices/serial/serial_debugcon/src/resolver.rs index 0710681246..8a3ee84cd0 100644 --- a/vm/devices/serial/serial_debugcon/src/resolver.rs +++ b/vm/devices/serial/serial_debugcon/src/resolver.rs @@ -10,11 +10,11 @@ use chipset_device_resources::ResolvedChipsetDevice; use serial_core::resources::ResolveSerialBackendParams; use serial_debugcon_resources::SerialDebugconDeviceHandle; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::ChipsetDeviceHandleKind; /// The resource resolver for [`SerialDebugcon`]. pub struct SerialDebugconResolver; diff --git a/vm/devices/serial/serial_debugcon_resources/src/lib.rs b/vm/devices/serial/serial_debugcon_resources/src/lib.rs index e01ebf5952..873df9c45e 100644 --- a/vm/devices/serial/serial_debugcon_resources/src/lib.rs +++ b/vm/devices/serial/serial_debugcon_resources/src/lib.rs @@ -6,10 +6,10 @@ #![forbid(unsafe_code)] use mesh::MeshPayload; -use vm_resource::kind::ChipsetDeviceHandleKind; -use vm_resource::kind::SerialBackendHandle; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::ChipsetDeviceHandleKind; +use vm_resource::kind::SerialBackendHandle; /// A handle to a 16550A serial device. #[derive(MeshPayload)] diff --git a/vm/devices/serial/serial_pl011/src/lib.rs b/vm/devices/serial/serial_pl011/src/lib.rs index 1659f22218..956f7934a1 100644 --- a/vm/devices/serial/serial_pl011/src/lib.rs +++ b/vm/devices/serial/serial_pl011/src/lib.rs @@ -20,21 +20,21 @@ mod spec; use self::spec::ControlRegister; use self::spec::DmaControlRegister; +use self::spec::FIFO_SIZE; use self::spec::FifoLevelSelect; use self::spec::FractionalBaudRateRegister; use self::spec::InterruptFifoLevelSelectRegister; use self::spec::InterruptRegister; use self::spec::LineControlRegister; -use self::spec::Register; -use self::spec::FIFO_SIZE; use self::spec::REGISTERS_SIZE; +use self::spec::Register; use self::spec::UARTPCELL_ID; use self::spec::UARTPERIPH_ID; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use futures::AsyncRead; use futures::AsyncWrite; use inspect::Inspect; @@ -45,10 +45,10 @@ use std::collections::VecDeque; use std::io::ErrorKind; use std::ops::RangeInclusive; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; use std::task::Waker; +use std::task::ready; use thiserror::Error; use vmcore::device_state::ChangeDeviceState; use vmcore::line_interrupt::LineInterrupt; diff --git a/vm/devices/serial/serial_pl011/src/resolver.rs b/vm/devices/serial/serial_pl011/src/resolver.rs index fabac3cff4..33b02a1b7e 100644 --- a/vm/devices/serial/serial_pl011/src/resolver.rs +++ b/vm/devices/serial/serial_pl011/src/resolver.rs @@ -5,17 +5,17 @@ use crate::SerialPl011; use async_trait::async_trait; +use chipset_device_resources::IRQ_LINE_SET; use chipset_device_resources::ResolveChipsetDeviceHandleParams; use chipset_device_resources::ResolvedChipsetDevice; -use chipset_device_resources::IRQ_LINE_SET; use serial_core::resources::ResolveSerialBackendParams; use serial_pl011_resources::SerialPl011DeviceHandle; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::ChipsetDeviceHandleKind; /// The resource resolver for [`SerialPl011`]. pub struct SerialPl011Resolver; diff --git a/vm/devices/serial/serial_pl011_resources/src/lib.rs b/vm/devices/serial/serial_pl011_resources/src/lib.rs index c00278685f..7d5ac74633 100644 --- a/vm/devices/serial/serial_pl011_resources/src/lib.rs +++ b/vm/devices/serial/serial_pl011_resources/src/lib.rs @@ -6,10 +6,10 @@ #![forbid(unsafe_code)] use mesh::MeshPayload; -use vm_resource::kind::ChipsetDeviceHandleKind; -use vm_resource::kind::SerialBackendHandle; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::ChipsetDeviceHandleKind; +use vm_resource::kind::SerialBackendHandle; /// A handle for a PL011 device. #[derive(MeshPayload)] diff --git a/vm/devices/serial/serial_socket/src/net.rs b/vm/devices/serial/serial_socket/src/net.rs index 28f52601e8..10cdce09e7 100644 --- a/vm/devices/serial/serial_socket/src/net.rs +++ b/vm/devices/serial/serial_socket/src/net.rs @@ -12,24 +12,24 @@ use pal_async::driver::Driver; use pal_async::interest::PollEvents; use pal_async::socket::PollReady; use pal_async::socket::PolledSocket; +use serial_core::SerialIo; use serial_core::resources::ResolveSerialBackendParams; use serial_core::resources::ResolvedSerialBackend; -use serial_core::SerialIo; use socket2::Socket; use std::io; use std::net::TcpListener; use std::net::TcpStream; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; use unix_socket::UnixListener; use unix_socket::UnixStream; -use vm_resource::declare_static_resolver; -use vm_resource::kind::SerialBackendHandle; use vm_resource::ResolveResource; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::declare_static_resolver; +use vm_resource::kind::SerialBackendHandle; #[derive(Debug, MeshPayload)] pub struct OpenSocketSerialConfig { diff --git a/vm/devices/serial/serial_socket/src/windows.rs b/vm/devices/serial/serial_socket/src/windows.rs index 17e00e40c8..eeb7c591bb 100644 --- a/vm/devices/serial/serial_socket/src/windows.rs +++ b/vm/devices/serial/serial_socket/src/windows.rs @@ -13,20 +13,20 @@ use pal::windows::pipe::PipeExt; use pal_async::driver::Driver; use pal_async::pipe::PolledPipe; use pal_async::windows::pipe::ListeningPipe; +use serial_core::SerialIo; use serial_core::resources::ResolveSerialBackendParams; use serial_core::resources::ResolvedSerialBackend; -use serial_core::SerialIo; use std::fs::File; use std::io; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; -use vm_resource::declare_static_resolver; -use vm_resource::kind::SerialBackendHandle; +use std::task::ready; use vm_resource::ResolveResource; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::declare_static_resolver; +use vm_resource::kind::SerialBackendHandle; #[derive(Debug, MeshPayload)] pub struct OpenWindowsPipeSerialConfig { diff --git a/vm/devices/serial/vmbus_serial_guest/src/lib.rs b/vm/devices/serial/vmbus_serial_guest/src/lib.rs index 3338912494..343801ee48 100644 --- a/vm/devices/serial/vmbus_serial_guest/src/lib.rs +++ b/vm/devices/serial/vmbus_serial_guest/src/lib.rs @@ -16,9 +16,9 @@ use inspect_counters::Counter; use mesh::MeshPayload; use protocol::GuestNotifications; use protocol::HostRequests; +use protocol::MAX_MESSAGE_SIZE; use protocol::MessageTypes; use protocol::MessageVersions; -use protocol::MAX_MESSAGE_SIZE; use protocol::UART_MSG_MAX_PAYLOAD; use serial_core::SerialIo; use std::collections::VecDeque; @@ -29,14 +29,14 @@ use std::io; use std::io::IoSlice; use std::io::IoSliceMut; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; use std::task::Waker; +use std::task::ready; use thiserror::Error; -use vm_resource::kind::SerialBackendHandle; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::SerialBackendHandle; use vmbus_async::async_dgram::AsyncRecv; use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::async_dgram::AsyncSend; @@ -69,10 +69,10 @@ mod user_pipe { use guid::Guid; use serial_core::resources::ResolveSerialBackendParams; use serial_core::resources::ResolvedSerialBackend; - use vm_resource::declare_static_async_resolver; - use vm_resource::kind::SerialBackendHandle; use vm_resource::AsyncResolveResource; use vm_resource::ResourceResolver; + use vm_resource::declare_static_async_resolver; + use vm_resource::kind::SerialBackendHandle; impl OpenVmbusSerialGuestConfig { /// Opens the UIO device for the specified instance GUID and returns the @@ -442,13 +442,13 @@ impl AsyncWrite for VmbusSerialDriver { mod tests { use crate::ErrorInner; use crate::VmbusSerialDriver; + use futures::AsyncWriteExt; use futures::io::AsyncReadExt; use futures::join; - use futures::AsyncWriteExt; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; - use pal_async::DefaultDriver; use serial_core::serial_io::Connected; use test_with_tracing::test; use unix_socket::UnixStream; diff --git a/vm/devices/serial/vmbus_serial_host/src/lib.rs b/vm/devices/serial/vmbus_serial_host/src/lib.rs index 7a5cf8ef7d..5a23709239 100644 --- a/vm/devices/serial/vmbus_serial_host/src/lib.rs +++ b/vm/devices/serial/vmbus_serial_host/src/lib.rs @@ -16,22 +16,21 @@ use std::cmp::min; use std::collections::VecDeque; use std::fmt::Debug; use std::future::poll_fn; -use std::future::Future; -use std::pin::pin; use std::pin::Pin; -use std::task::ready; +use std::pin::pin; use std::task::Context; use std::task::Poll; +use std::task::ready; use task_control::StopTask; use thiserror::Error; use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::pipe::MessagePipe; +use vmbus_channel::RawAsyncChannel; use vmbus_channel::bus::ChannelType; use vmbus_channel::bus::OfferParams; use vmbus_channel::channel::ChannelOpenError; use vmbus_channel::gpadl_ring::GpadlRingMem; use vmbus_channel::simple::SimpleVmbusDevice; -use vmbus_channel::RawAsyncChannel; use vmbus_ring::RingMem; use vmbus_serial_protocol as protocol; use vmcore::save_restore::SavedStateNotSupported; diff --git a/vm/devices/serial/vmbus_serial_host/src/resolver.rs b/vm/devices/serial/vmbus_serial_host/src/resolver.rs index b28f175682..296490832f 100644 --- a/vm/devices/serial/vmbus_serial_host/src/resolver.rs +++ b/vm/devices/serial/vmbus_serial_host/src/resolver.rs @@ -7,10 +7,10 @@ use crate::Port; use crate::Serial; use async_trait::async_trait; use serial_core::resources::ResolveSerialBackendParams; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::VmbusDeviceHandleKind; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; use vmbus_channel::simple::SimpleDeviceWrapper; diff --git a/vm/devices/serial/vmbus_serial_resources/src/lib.rs b/vm/devices/serial/vmbus_serial_resources/src/lib.rs index 89aea2d55e..da32c22286 100644 --- a/vm/devices/serial/vmbus_serial_resources/src/lib.rs +++ b/vm/devices/serial/vmbus_serial_resources/src/lib.rs @@ -6,10 +6,10 @@ #![forbid(unsafe_code)] use mesh::MeshPayload; -use vm_resource::kind::SerialBackendHandle; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::SerialBackendHandle; +use vm_resource::kind::VmbusDeviceHandleKind; /// A handle to a vmbus serial device. #[derive(MeshPayload)] diff --git a/vm/devices/storage/block_crypto/src/lib.rs b/vm/devices/storage/block_crypto/src/lib.rs index 38a6ffd8f1..ab8bcba5ff 100644 --- a/vm/devices/storage/block_crypto/src/lib.rs +++ b/vm/devices/storage/block_crypto/src/lib.rs @@ -118,8 +118,8 @@ mod bcrypt { use std::sync::OnceLock; use thiserror::Error; - use windows::Win32::Foundation::RtlNtStatusToDosError; use windows::Win32::Foundation::NTSTATUS; + use windows::Win32::Foundation::RtlNtStatusToDosError; use windows::Win32::Security::Cryptography::BCRYPT_ALG_HANDLE; use windows::Win32::Security::Cryptography::BCRYPT_HANDLE; use windows::Win32::Security::Cryptography::BCRYPT_KEY_HANDLE; @@ -302,7 +302,7 @@ mod bcrypt { // SAFETY: the key handle is valid. let status = unsafe { windows::Win32::Security::Cryptography::BCryptSetProperty( - BCRYPT_HANDLE(key.0 .0), + BCRYPT_HANDLE(key.0.0), windows::Win32::Security::Cryptography::BCRYPT_MESSAGE_BLOCK_LENGTH, &data_unit_size.to_ne_bytes(), 0, diff --git a/vm/devices/storage/disk_backend/src/lib.rs b/vm/devices/storage/disk_backend/src/lib.rs index 1220635008..ff29cc6743 100644 --- a/vm/devices/storage/disk_backend/src/lib.rs +++ b/vm/devices/storage/disk_backend/src/lib.rs @@ -21,7 +21,6 @@ use scsi_buffers::RequestBuffers; use stackfuture::StackFuture; use std::fmt::Debug; use std::future::ready; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; use thiserror::Error; diff --git a/vm/devices/storage/disk_backend/src/resolve.rs b/vm/devices/storage/disk_backend/src/resolve.rs index 69b7d7f858..544ddb30f9 100644 --- a/vm/devices/storage/disk_backend/src/resolve.rs +++ b/vm/devices/storage/disk_backend/src/resolve.rs @@ -6,8 +6,8 @@ use crate::Disk; use crate::DiskIo; use crate::InvalidDisk; -use vm_resource::kind::DiskHandleKind; use vm_resource::CanResolveTo; +use vm_resource::kind::DiskHandleKind; impl CanResolveTo for DiskHandleKind { type Input<'a> = ResolveDiskParameters<'a>; diff --git a/vm/devices/storage/disk_backend_resources/src/layer.rs b/vm/devices/storage/disk_backend_resources/src/layer.rs index 9160062de9..cdcad90514 100644 --- a/vm/devices/storage/disk_backend_resources/src/layer.rs +++ b/vm/devices/storage/disk_backend_resources/src/layer.rs @@ -4,10 +4,10 @@ //! Disk layer resources. use mesh::MeshPayload; -use vm_resource::kind::DiskHandleKind; -use vm_resource::kind::DiskLayerHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::DiskHandleKind; +use vm_resource::kind::DiskLayerHandleKind; /// RAM disk layer handle. /// diff --git a/vm/devices/storage/disk_backend_resources/src/lib.rs b/vm/devices/storage/disk_backend_resources/src/lib.rs index d610b9db69..c56787dc2c 100644 --- a/vm/devices/storage/disk_backend_resources/src/lib.rs +++ b/vm/devices/storage/disk_backend_resources/src/lib.rs @@ -8,11 +8,11 @@ pub mod layer; use mesh::MeshPayload; -use vm_resource::kind::DiskHandleKind; -use vm_resource::kind::DiskLayerHandleKind; use vm_resource::IntoResource; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::DiskHandleKind; +use vm_resource::kind::DiskLayerHandleKind; // Define config types here so that you don't have to pull in the individual // crates just to describe the configuration. diff --git a/vm/devices/storage/disk_blob/src/blob/http.rs b/vm/devices/storage/disk_blob/src/blob/http.rs index bf3e3797f7..446163aad4 100644 --- a/vm/devices/storage/disk_blob/src/blob/http.rs +++ b/vm/devices/storage/disk_blob/src/blob/http.rs @@ -18,8 +18,8 @@ use hyper::Request; use hyper::StatusCode; use hyper::Uri; use hyper_tls::HttpsConnector; -use hyper_util::client::legacy::connect::HttpConnector; use hyper_util::client::legacy::Client; +use hyper_util::client::legacy::connect::HttpConnector; use hyper_util::rt::TokioExecutor; use inspect::Inspect; use once_cell::sync::OnceCell; diff --git a/vm/devices/storage/disk_blob/src/resolver.rs b/vm/devices/storage/disk_blob/src/resolver.rs index 1c3f63a8e9..49eee08c14 100644 --- a/vm/devices/storage/disk_blob/src/resolver.rs +++ b/vm/devices/storage/disk_blob/src/resolver.rs @@ -3,17 +3,17 @@ //! Resolver implementation for [`BlobDisk`]. -use crate::blob::http::HttpBlob; use crate::BlobDisk; +use crate::blob::http::HttpBlob; use async_trait::async_trait; use disk_backend::resolve::ResolveDiskParameters; use disk_backend::resolve::ResolvedDisk; use disk_backend_resources::BlobDiskFormat; use disk_backend_resources::BlobDiskHandle; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::DiskHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::DiskHandleKind; /// A resolver for blob disks. pub struct BlobDiskResolver; diff --git a/vm/devices/storage/disk_blockdevice/src/lib.rs b/vm/devices/storage/disk_blockdevice/src/lib.rs index 704df5f374..ec896ed4b2 100644 --- a/vm/devices/storage/disk_blockdevice/src/lib.rs +++ b/vm/devices/storage/disk_blockdevice/src/lib.rs @@ -16,15 +16,15 @@ mod nvme; use anyhow::Context; use async_trait::async_trait; use blocking::unblock; +use disk_backend::DiskError; +use disk_backend::DiskIo; +use disk_backend::UnmapBehavior; use disk_backend::pr::PersistentReservation; use disk_backend::pr::ReservationCapabilities; use disk_backend::pr::ReservationReport; use disk_backend::pr::ReservationType; use disk_backend::resolve::ResolveDiskParameters; use disk_backend::resolve::ResolvedDisk; -use disk_backend::DiskError; -use disk_backend::DiskIo; -use disk_backend::UnmapBehavior; use fs_err::PathExt; use guestmem::MemoryRead; use guestmem::MemoryWrite; @@ -48,16 +48,16 @@ use std::os::unix::prelude::MetadataExt; use std::path::Path; use std::path::PathBuf; use std::str::FromStr; +use std::sync::Arc; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; use thiserror::Error; use uevent::CallbackHandle; use uevent::UeventListener; -use vm_resource::kind::DiskHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResourceId; use vm_resource::ResourceResolver; +use vm_resource::kind::DiskHandleKind; pub struct BlockDeviceResolver { uring: Arc, @@ -531,11 +531,7 @@ impl DiskIo for BlockDevice { } fn pr(&self) -> Option<&dyn PersistentReservation> { - if self.supports_pr { - Some(self) - } else { - None - } + if self.supports_pr { Some(self) } else { None } } async fn eject(&self) -> Result<(), DiskError> { @@ -706,7 +702,7 @@ impl DiskIo for BlockDevice { match unblock(move || ioctl::discard(&file, file_offset, length)).await { Ok(()) => {} Err(_) if sector_offset + sector_count > self.sector_count() => { - return Err(DiskError::IllegalBlock) + return Err(DiskError::IllegalBlock); } Err(err) => return Err(self.map_io_error(err)), } diff --git a/vm/devices/storage/disk_blockdevice/src/nvme.rs b/vm/devices/storage/disk_blockdevice/src/nvme.rs index a503741900..37ff2d7237 100644 --- a/vm/devices/storage/disk_blockdevice/src/nvme.rs +++ b/vm/devices/storage/disk_blockdevice/src/nvme.rs @@ -308,7 +308,7 @@ pub fn check_nvme_status(status: i32) -> io::Result<()> { return Err(io::Error::new( io::ErrorKind::Other, format!("nvme error {:#x?}", status), - )) + )); } }; Err(io::Error::from_raw_os_error(errno)) diff --git a/vm/devices/storage/disk_crypt/src/lib.rs b/vm/devices/storage/disk_crypt/src/lib.rs index b9f4eb0d6d..51d889eb7d 100644 --- a/vm/devices/storage/disk_crypt/src/lib.rs +++ b/vm/devices/storage/disk_crypt/src/lib.rs @@ -167,7 +167,7 @@ impl DiskIo for CryptDisk { sector: u64, count: u64, block_level_only: bool, - ) -> impl std::future::Future> + Send { + ) -> impl Future> + Send { self.inner.unmap(sector, count, block_level_only) } diff --git a/vm/devices/storage/disk_crypt/src/resolver.rs b/vm/devices/storage/disk_crypt/src/resolver.rs index acf055d9e4..dc423317b4 100644 --- a/vm/devices/storage/disk_crypt/src/resolver.rs +++ b/vm/devices/storage/disk_crypt/src/resolver.rs @@ -9,11 +9,11 @@ use disk_backend::resolve::ResolveDiskParameters; use disk_backend::resolve::ResolvedDisk; use disk_crypt_resources::DiskCryptHandle; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::DiskHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::DiskHandleKind; declare_static_async_resolver! { DiskCryptResolver, diff --git a/vm/devices/storage/disk_crypt_resources/src/lib.rs b/vm/devices/storage/disk_crypt_resources/src/lib.rs index c4a6670e79..6f2c4eec7b 100644 --- a/vm/devices/storage/disk_crypt_resources/src/lib.rs +++ b/vm/devices/storage/disk_crypt_resources/src/lib.rs @@ -4,9 +4,9 @@ //! Resources for the encrypted disk device. use mesh::MeshPayload; -use vm_resource::kind::DiskHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::DiskHandleKind; /// A handle to an encrypted disk. #[derive(MeshPayload)] diff --git a/vm/devices/storage/disk_file/src/lib.rs b/vm/devices/storage/disk_file/src/lib.rs index f7a4df91d5..945cdeacb1 100644 --- a/vm/devices/storage/disk_file/src/lib.rs +++ b/vm/devices/storage/disk_file/src/lib.rs @@ -8,10 +8,10 @@ mod readwriteat; use self::readwriteat::ReadWriteAt; use blocking::unblock; -use disk_backend::resolve::ResolveDiskParameters; -use disk_backend::resolve::ResolvedDisk; use disk_backend::DiskError; use disk_backend::DiskIo; +use disk_backend::resolve::ResolveDiskParameters; +use disk_backend::resolve::ResolvedDisk; use disk_backend_resources::FileDiskHandle; use guestmem::MemoryRead; use guestmem::MemoryWrite; @@ -20,9 +20,9 @@ use scsi_buffers::RequestBuffers; use std::fs; use std::sync::Arc; use thiserror::Error; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::DiskHandleKind; -use vm_resource::ResolveResource; pub struct FileDiskResolver; declare_static_resolver!(FileDiskResolver, (DiskHandleKind, FileDiskHandle)); diff --git a/vm/devices/storage/disk_get_vmgs/src/lib.rs b/vm/devices/storage/disk_get_vmgs/src/lib.rs index e035311d34..f7fbd25dc2 100644 --- a/vm/devices/storage/disk_get_vmgs/src/lib.rs +++ b/vm/devices/storage/disk_get_vmgs/src/lib.rs @@ -279,15 +279,15 @@ mod tests { use super::*; use disk_backend::Disk; use guest_emulation_transport::api::ProtocolVersion; - use guest_emulation_transport::test_utilities::new_transport_pair; use guest_emulation_transport::test_utilities::TestGet; + use guest_emulation_transport::test_utilities::new_transport_pair; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::task::Task; - use pal_async::DefaultDriver; use vmgs::FileId; use vmgs::Vmgs; - use vmgs_broker::spawn_vmgs_broker; use vmgs_broker::VmgsClient; + use vmgs_broker::spawn_vmgs_broker; async fn spawn_vmgs(driver: &DefaultDriver) -> (VmgsClient, TestGet, Task<()>) { let get = new_transport_pair(driver, None, ProtocolVersion::NICKEL_REV2).await; diff --git a/vm/devices/storage/disk_layered/src/lib.rs b/vm/devices/storage/disk_layered/src/lib.rs index 6ae0f4e110..e7206a1f38 100644 --- a/vm/devices/storage/disk_layered/src/lib.rs +++ b/vm/devices/storage/disk_layered/src/lib.rs @@ -40,7 +40,6 @@ use inspect::Inspect; use scsi_buffers::OwnedRequestBuffers; use scsi_buffers::RequestBuffers; use std::convert::Infallible; -use std::future::Future; use std::pin::Pin; use thiserror::Error; @@ -922,8 +921,8 @@ mod tests { use pal_async::async_test; use parking_lot::Mutex; use scsi_buffers::OwnedRequestBuffers; - use std::collections::btree_map::Entry; use std::collections::BTreeMap; + use std::collections::btree_map::Entry; use std::sync::Arc; #[derive(Inspect)] diff --git a/vm/devices/storage/disk_layered/src/resolve.rs b/vm/devices/storage/disk_layered/src/resolve.rs index 419befa8f5..27e4b26580 100644 --- a/vm/devices/storage/disk_layered/src/resolve.rs +++ b/vm/devices/storage/disk_layered/src/resolve.rs @@ -5,8 +5,8 @@ use super::DiskLayer; use crate::LayerAttach; -use vm_resource::kind::DiskLayerHandleKind; use vm_resource::CanResolveTo; +use vm_resource::kind::DiskLayerHandleKind; impl CanResolveTo for DiskLayerHandleKind { type Input<'a> = ResolveDiskLayerParameters<'a>; diff --git a/vm/devices/storage/disk_layered/src/resolver.rs b/vm/devices/storage/disk_layered/src/resolver.rs index 02857e6c34..e02c9c2237 100644 --- a/vm/devices/storage/disk_layered/src/resolver.rs +++ b/vm/devices/storage/disk_layered/src/resolver.rs @@ -3,26 +3,26 @@ //! Resolvers for layered disks. -use super::resolve::ResolveDiskLayerParameters; -use super::resolve::ResolvedDiskLayer; use super::InvalidLayeredDisk; use super::LayerConfiguration; use super::LayeredDisk; +use super::resolve::ResolveDiskLayerParameters; +use super::resolve::ResolvedDiskLayer; use crate::DiskLayer; use async_trait::async_trait; +use disk_backend::InvalidDisk; use disk_backend::resolve::ResolveDiskParameters; use disk_backend::resolve::ResolvedDisk; -use disk_backend::InvalidDisk; -use disk_backend_resources::layer::DiskLayerHandle; use disk_backend_resources::LayeredDiskHandle; +use disk_backend_resources::layer::DiskLayerHandle; use futures::future::TryJoinAll; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::DiskHandleKind; -use vm_resource::kind::DiskLayerHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::DiskHandleKind; +use vm_resource::kind::DiskLayerHandleKind; declare_static_async_resolver! { LayeredDiskResolver, diff --git a/vm/devices/storage/disk_nvme/nvme_driver/fuzz/fuzz_emulated_device.rs b/vm/devices/storage/disk_nvme/nvme_driver/fuzz/fuzz_emulated_device.rs index c8c944339d..222056e0a8 100644 --- a/vm/devices/storage/disk_nvme/nvme_driver/fuzz/fuzz_emulated_device.rs +++ b/vm/devices/storage/disk_nvme/nvme_driver/fuzz/fuzz_emulated_device.rs @@ -14,12 +14,12 @@ use chipset_device::pci::PciConfigSpace; use inspect::Inspect; use inspect::InspectMut; use pci_core::msi::MsiInterruptSet; +use user_driver::DeviceBacking; +use user_driver::DmaClient; use user_driver::emulated::DeviceSharedMemory; use user_driver::emulated::EmulatedDevice; use user_driver::emulated::Mapping; use user_driver::interrupt::DeviceInterrupt; -use user_driver::DeviceBacking; -use user_driver::DmaClient; /// An EmulatedDevice fuzzer that requires a working EmulatedDevice backend. #[derive(Inspect)] diff --git a/vm/devices/storage/disk_nvme/nvme_driver/src/driver.rs b/vm/devices/storage/disk_nvme/nvme_driver/src/driver.rs index f421a9d182..3bd95846f0 100644 --- a/vm/devices/storage/disk_nvme/nvme_driver/src/driver.rs +++ b/vm/devices/storage/disk_nvme/nvme_driver/src/driver.rs @@ -4,20 +4,20 @@ //! Implementation of the device driver core. use super::spec; +use crate::NVME_PAGE_SHIFT; +use crate::Namespace; +use crate::NamespaceError; +use crate::NvmeDriverSavedState; +use crate::RequestError; use crate::driver::save_restore::IoQueueSavedState; -use crate::queue_pair::admin_cmd; use crate::queue_pair::Issuer; use crate::queue_pair::QueuePair; +use crate::queue_pair::admin_cmd; use crate::registers::Bar0; use crate::registers::DeviceRegisters; -use crate::Namespace; -use crate::NamespaceError; -use crate::NvmeDriverSavedState; -use crate::RequestError; -use crate::NVME_PAGE_SHIFT; use anyhow::Context as _; -use futures::future::join_all; use futures::StreamExt; +use futures::future::join_all; use inspect::Inspect; use mesh::payload::Protobuf; use mesh::rpc::Rpc; @@ -31,12 +31,12 @@ use task_control::AsyncRun; use task_control::InspectTask; use task_control::TaskControl; use thiserror::Error; -use tracing::info_span; use tracing::Instrument; +use tracing::info_span; +use user_driver::DeviceBacking; use user_driver::backoff::Backoff; use user_driver::interrupt::DeviceInterrupt; use user_driver::memory::MemoryBlock; -use user_driver::DeviceBacking; use vmcore::vm_task::VmTaskDriver; use vmcore::vm_task::VmTaskDriverSource; use zerocopy::FromBytes; @@ -455,7 +455,7 @@ impl NvmeDriver { drop(self); } - fn reset(&mut self) -> impl Send + std::future::Future + use { + fn reset(&mut self) -> impl Send + Future + use { let driver = self.driver.clone(); let mut task = std::mem::take(&mut self.task).unwrap(); async move { diff --git a/vm/devices/storage/disk_nvme/nvme_driver/src/lib.rs b/vm/devices/storage/disk_nvme/nvme_driver/src/lib.rs index bade4527d6..3efc12dd39 100644 --- a/vm/devices/storage/disk_nvme/nvme_driver/src/lib.rs +++ b/vm/devices/storage/disk_nvme/nvme_driver/src/lib.rs @@ -13,9 +13,9 @@ mod registers; #[cfg(test)] mod tests; +pub use self::driver::NvmeDriver; pub use self::driver::save_restore::Error; pub use self::driver::save_restore::NvmeDriverSavedState; -pub use self::driver::NvmeDriver; pub use self::namespace::Namespace; pub use self::namespace::NamespaceError; pub use self::queue_pair::RequestError; diff --git a/vm/devices/storage/disk_nvme/nvme_driver/src/namespace.rs b/vm/devices/storage/disk_nvme/nvme_driver/src/namespace.rs index adf48f2e99..3c712361e1 100644 --- a/vm/devices/storage/disk_nvme/nvme_driver/src/namespace.rs +++ b/vm/devices/storage/disk_nvme/nvme_driver/src/namespace.rs @@ -5,22 +5,22 @@ use super::spec; use super::spec::nvm; -use crate::driver::save_restore::SavedNamespaceData; +use crate::NVME_PAGE_SHIFT; use crate::driver::IoIssuers; -use crate::queue_pair::admin_cmd; +use crate::driver::save_restore::SavedNamespaceData; use crate::queue_pair::Issuer; use crate::queue_pair::RequestError; -use crate::NVME_PAGE_SHIFT; -use guestmem::ranges::PagedRange; +use crate::queue_pair::admin_cmd; use guestmem::GuestMemory; +use guestmem::ranges::PagedRange; use inspect::Inspect; use mesh::CancelContext; use pal_async::task::Spawn; use parking_lot::Mutex; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; use thiserror::Error; use vmcore::vm_task::VmTaskDriver; use zerocopy::FromBytes; diff --git a/vm/devices/storage/disk_nvme/nvme_driver/src/queue_pair.rs b/vm/devices/storage/disk_nvme/nvme_driver/src/queue_pair.rs index f67ab3e0b3..95ee213b1a 100644 --- a/vm/devices/storage/disk_nvme/nvme_driver/src/queue_pair.rs +++ b/vm/devices/storage/disk_nvme/nvme_driver/src/queue_pair.rs @@ -14,16 +14,16 @@ use crate::queues::SubmissionQueue; use crate::registers::DeviceRegisters; use anyhow::Context; use futures::StreamExt; -use guestmem::ranges::PagedRange; use guestmem::GuestMemory; use guestmem::GuestMemoryError; +use guestmem::ranges::PagedRange; use inspect::Inspect; use inspect_counters::Counter; +use mesh::Cancel; +use mesh::CancelContext; use mesh::rpc::Rpc; use mesh::rpc::RpcError; use mesh::rpc::RpcSend; -use mesh::Cancel; -use mesh::CancelContext; use pal_async::driver::SpawnDriver; use pal_async::task::Task; use safeatomic::AtomicSliceOps; @@ -33,13 +33,13 @@ use std::num::Wrapping; use std::sync::Arc; use std::task::Poll; use thiserror::Error; +use user_driver::DeviceBacking; use user_driver::interrupt::DeviceInterrupt; use user_driver::memory::MemoryBlock; use user_driver::memory::PAGE_SIZE; use user_driver::memory::PAGE_SIZE64; use user_driver::page_allocator::PageAllocator; use user_driver::page_allocator::ScopedPages; -use user_driver::DeviceBacking; use zerocopy::FromZeros; /// Value for unused PRP entries, to catch/mitigate buffer size mismatches. diff --git a/vm/devices/storage/disk_nvme/nvme_driver/src/queues.rs b/vm/devices/storage/disk_nvme/nvme_driver/src/queues.rs index 049aa7bba2..eec2a90fe0 100644 --- a/vm/devices/storage/disk_nvme/nvme_driver/src/queues.rs +++ b/vm/devices/storage/disk_nvme/nvme_driver/src/queues.rs @@ -12,8 +12,8 @@ use safeatomic::AtomicSliceOps; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering::Acquire; use std::sync::atomic::Ordering::Relaxed; -use user_driver::memory::MemoryBlock; use user_driver::DeviceBacking; +use user_driver::memory::MemoryBlock; #[derive(Inspect)] pub(crate) struct SubmissionQueue { @@ -204,9 +204,5 @@ impl CompletionQueue { } fn advance(n: u32, l: u32) -> u32 { - if n + 1 < l { - n + 1 - } else { - 0 - } + if n + 1 < l { n + 1 } else { 0 } } diff --git a/vm/devices/storage/disk_nvme/nvme_driver/src/registers.rs b/vm/devices/storage/disk_nvme/nvme_driver/src/registers.rs index 013c833399..52f0f303c0 100644 --- a/vm/devices/storage/disk_nvme/nvme_driver/src/registers.rs +++ b/vm/devices/storage/disk_nvme/nvme_driver/src/registers.rs @@ -9,9 +9,9 @@ use pal_async::driver::Driver; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::Relaxed; use tracing::instrument; -use user_driver::backoff::Backoff; use user_driver::DeviceBacking; use user_driver::DeviceRegisterIo; +use user_driver::backoff::Backoff; #[derive(Inspect)] #[inspect(extra = "Self::inspect_extra")] diff --git a/vm/devices/storage/disk_nvme/nvme_driver/src/tests.rs b/vm/devices/storage/disk_nvme/nvme_driver/src/tests.rs index 0cdd4a30ce..5181af62d4 100644 --- a/vm/devices/storage/disk_nvme/nvme_driver/src/tests.rs +++ b/vm/devices/storage/disk_nvme/nvme_driver/src/tests.rs @@ -9,22 +9,22 @@ use guid::Guid; use inspect::Inspect; use inspect::InspectMut; use nvme::NvmeControllerCaps; -use nvme_spec::nvm::DsmRange; use nvme_spec::Cap; -use pal_async::async_test; +use nvme_spec::nvm::DsmRange; use pal_async::DefaultDriver; +use pal_async::async_test; use parking_lot::Mutex; use pci_core::msi::MsiInterruptSet; use scsi_buffers::OwnedRequestBuffers; use std::sync::Arc; use test_with_tracing::test; +use user_driver::DeviceBacking; +use user_driver::DeviceRegisterIo; +use user_driver::DmaClient; use user_driver::emulated::DeviceSharedMemory; use user_driver::emulated::EmulatedDevice; use user_driver::emulated::Mapping; use user_driver::interrupt::DeviceInterrupt; -use user_driver::DeviceBacking; -use user_driver::DeviceRegisterIo; -use user_driver::DmaClient; use vmcore::vm_task::SingleDriverBackend; use vmcore::vm_task::VmTaskDriverSource; use zerocopy::IntoBytes; diff --git a/vm/devices/storage/disk_nvme/src/lib.rs b/vm/devices/storage/disk_nvme/src/lib.rs index e8eadaeef4..5e7ee8b6dd 100644 --- a/vm/devices/storage/disk_nvme/src/lib.rs +++ b/vm/devices/storage/disk_nvme/src/lib.rs @@ -7,14 +7,14 @@ #![expect(missing_docs)] use async_trait::async_trait; -use disk_backend::pr; use disk_backend::DiskError; use disk_backend::DiskIo; use disk_backend::MediumErrorDetails; +use disk_backend::pr; use inspect::Inspect; use nvme_common::from_nvme_reservation_report; -use nvme_spec::nvm; use nvme_spec::Status; +use nvme_spec::nvm; use pal::unix::affinity::get_cpu_number; use std::io; diff --git a/vm/devices/storage/disk_prwrap/src/lib.rs b/vm/devices/storage/disk_prwrap/src/lib.rs index aff5f8f4c8..8df862a191 100644 --- a/vm/devices/storage/disk_prwrap/src/lib.rs +++ b/vm/devices/storage/disk_prwrap/src/lib.rs @@ -10,26 +10,25 @@ #![expect(missing_docs)] use async_trait::async_trait; +use disk_backend::Disk; +use disk_backend::DiskError; +use disk_backend::DiskIo; use disk_backend::pr; use disk_backend::pr::ReservationType; use disk_backend::resolve::ResolveDiskParameters; use disk_backend::resolve::ResolvedDisk; -use disk_backend::Disk; -use disk_backend::DiskError; -use disk_backend::DiskIo; use disk_backend_resources::DiskWithReservationsHandle; use inspect::Inspect; use parking_lot::Mutex; use scsi_buffers::RequestBuffers; -use std::future::Future; use std::num::NonZeroU64; use std::num::Wrapping; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::DiskHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::DiskHandleKind; pub struct DiskWithReservationsResolver; declare_static_async_resolver!( diff --git a/vm/devices/storage/disk_striped/src/lib.rs b/vm/devices/storage/disk_striped/src/lib.rs index f72edb4fb1..62fc2d85dc 100644 --- a/vm/devices/storage/disk_striped/src/lib.rs +++ b/vm/devices/storage/disk_striped/src/lib.rs @@ -8,12 +8,12 @@ #![forbid(unsafe_code)] use async_trait::async_trait; -use disk_backend::resolve::ResolveDiskParameters; -use disk_backend::resolve::ResolvedDisk; use disk_backend::Disk; use disk_backend::DiskError; use disk_backend::DiskIo; use disk_backend::UnmapBehavior; +use disk_backend::resolve::ResolveDiskParameters; +use disk_backend::resolve::ResolvedDisk; use disk_backend_resources::StripedDiskHandle; use futures::future::join_all; use futures::future::try_join_all; @@ -21,10 +21,10 @@ use inspect::Inspect; use scsi_buffers::RequestBuffers; use std::fmt::Debug; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::DiskHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::DiskHandleKind; pub struct StripedDiskResolver; declare_static_async_resolver!(StripedDiskResolver, (DiskHandleKind, StripedDiskHandle)); @@ -72,7 +72,9 @@ const CHUNK_SIZE_128K: u32 = 128 * 1024; pub enum NewDeviceError { #[error("Can't create a striping disk since the input device list is empty")] EmptyDeviceList, - #[error("The files are not compatible to form a striping disk: sector_size-{sector_size} != cur_sector_size-{cur_sector_size} OR sector_count-{sector_count} != cur_sector_count-{cur_sector_count}")] + #[error( + "The files are not compatible to form a striping disk: sector_size-{sector_size} != cur_sector_size-{cur_sector_size} OR sector_count-{sector_count} != cur_sector_count-{cur_sector_count}" + )] DeviceNotCompatible { sector_size: u32, cur_sector_size: u32, @@ -547,7 +549,7 @@ impl DiskIo for StripedDisk { async fn await_all_and_check(futures: T) -> Result<(), E> where T: IntoIterator, - T::Item: core::future::Future>, + T::Item: Future>, { // Use join_all to wait for all IOs even if one fails. This is necessary to // avoid dropping IOs while they are in flight. diff --git a/vm/devices/storage/disk_vhd1/src/lib.rs b/vm/devices/storage/disk_vhd1/src/lib.rs index 83b1143e90..7b96fb35c1 100644 --- a/vm/devices/storage/disk_vhd1/src/lib.rs +++ b/vm/devices/storage/disk_vhd1/src/lib.rs @@ -6,10 +6,10 @@ #![expect(missing_docs)] #![forbid(unsafe_code)] -use disk_backend::resolve::ResolveDiskParameters; -use disk_backend::resolve::ResolvedDisk; use disk_backend::DiskError; use disk_backend::DiskIo; +use disk_backend::resolve::ResolveDiskParameters; +use disk_backend::resolve::ResolvedDisk; use disk_backend_resources::FixedVhd1DiskHandle; use disk_file::FileDisk; use guid::Guid; @@ -22,9 +22,9 @@ use std::io::Seek; use std::io::Write; use thiserror::Error; use vhd1_defs::VhdFooter; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::DiskHandleKind; -use vm_resource::ResolveResource; use zerocopy::FromZeros; use zerocopy::IntoBytes; diff --git a/vm/devices/storage/disk_vhdmp/src/lib.rs b/vm/devices/storage/disk_vhdmp/src/lib.rs index 45fa3a74f9..356cf5e438 100644 --- a/vm/devices/storage/disk_vhdmp/src/lib.rs +++ b/vm/devices/storage/disk_vhdmp/src/lib.rs @@ -7,10 +7,10 @@ #![expect(unsafe_code)] #![expect(clippy::undocumented_unsafe_blocks)] -use disk_backend::resolve::ResolveDiskParameters; -use disk_backend::resolve::ResolvedDisk; use disk_backend::DiskError; use disk_backend::DiskIo; +use disk_backend::resolve::ResolveDiskParameters; +use disk_backend::resolve::ResolvedDisk; use disk_file::FileDisk; use guid::Guid; use inspect::Inspect; @@ -20,10 +20,10 @@ use std::fs; use std::os::windows::prelude::*; use std::path::Path; use thiserror::Error; -use vm_resource::declare_static_resolver; -use vm_resource::kind::DiskHandleKind; use vm_resource::ResolveResource; use vm_resource::ResourceId; +use vm_resource::declare_static_resolver; +use vm_resource::kind::DiskHandleKind; mod virtdisk { #![allow( diff --git a/vm/devices/storage/disklayer_ram/src/lib.rs b/vm/devices/storage/disklayer_ram/src/lib.rs index b0905d0408..6e97e9dd94 100644 --- a/vm/devices/storage/disklayer_ram/src/lib.rs +++ b/vm/devices/storage/disklayer_ram/src/lib.rs @@ -23,8 +23,8 @@ use guestmem::MemoryWrite; use inspect::Inspect; use parking_lot::RwLock; use scsi_buffers::RequestBuffers; -use std::collections::btree_map::Entry; use std::collections::BTreeMap; +use std::collections::btree_map::Entry; use std::fmt; use std::fmt::Debug; use std::sync::atomic::AtomicU64; diff --git a/vm/devices/storage/disklayer_ram/src/resolver.rs b/vm/devices/storage/disklayer_ram/src/resolver.rs index 9fd2b14544..2ac342ff59 100644 --- a/vm/devices/storage/disklayer_ram/src/resolver.rs +++ b/vm/devices/storage/disklayer_ram/src/resolver.rs @@ -9,9 +9,9 @@ use crate::LazyRamDiskLayer; use disk_backend_resources::layer::RamDiskLayerHandle; use disk_layered::resolve::ResolveDiskLayerParameters; use disk_layered::resolve::ResolvedDiskLayer; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::DiskLayerHandleKind; -use vm_resource::ResolveResource; /// Resolver for a [`RamDiskLayerHandle`]. pub struct RamDiskLayerResolver; diff --git a/vm/devices/storage/disklayer_sqlite/src/resolver.rs b/vm/devices/storage/disklayer_sqlite/src/resolver.rs index 6c8224ee69..90a8bc93bc 100644 --- a/vm/devices/storage/disklayer_sqlite/src/resolver.rs +++ b/vm/devices/storage/disklayer_sqlite/src/resolver.rs @@ -4,16 +4,16 @@ //! Resource resolver for sqlite-backed disk layers. use super::SqliteDiskLayer; -use crate::auto_cache::AutoCacheSqliteDiskLayer; use crate::FormatOnAttachSqliteDiskLayer; +use crate::auto_cache::AutoCacheSqliteDiskLayer; use disk_backend_resources::layer::SqliteAutoCacheDiskLayerHandle; use disk_backend_resources::layer::SqliteDiskLayerFormatParams; use disk_backend_resources::layer::SqliteDiskLayerHandle; use disk_layered::resolve::ResolveDiskLayerParameters; use disk_layered::resolve::ResolvedDiskLayer; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::DiskLayerHandleKind; -use vm_resource::ResolveResource; /// Resolver for a [`SqliteDiskLayerHandle`]. pub struct SqliteDiskLayerResolver; diff --git a/vm/devices/storage/floppy/src/lib.rs b/vm/devices/storage/floppy/src/lib.rs index 64fcb1bf9e..82b6a307a6 100644 --- a/vm/devices/storage/floppy/src/lib.rs +++ b/vm/devices/storage/floppy/src/lib.rs @@ -29,28 +29,27 @@ #![forbid(unsafe_code)] use self::floppy_sizes::FloppyImageType; -use self::protocol::FloppyCommand; -use self::protocol::RegisterOffset; use self::protocol::FLOPPY_TOTAL_CYLINDERS; +use self::protocol::FloppyCommand; use self::protocol::INVALID_COMMAND_STATUS; +use self::protocol::RegisterOffset; use self::protocol::STANDARD_FLOPPY_SECTOR_SIZE; use arrayvec::ArrayVec; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use core::sync::atomic::Ordering; use disk_backend::Disk; -use guestmem::ranges::PagedRange; use guestmem::AlignedHeapMemory; use guestmem::GuestMemory; +use guestmem::ranges::PagedRange; use inspect::Inspect; use inspect::InspectMut; use scsi_buffers::RequestBuffers; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::Context; @@ -1412,7 +1411,10 @@ impl FloppyDiskController { // through which is not a sense-interrupt-status and there // is already an interrupt pending, we will deassert the INT signal. if self.state.interrupt_level && command != FloppyCommand::SENSE_INTERRUPT_STATUS { - tracing::trace!(?command, "Floppy interrupt level was high before command execution. Now de-asserting interrupt"); + tracing::trace!( + ?command, + "Floppy interrupt level was high before command execution. Now de-asserting interrupt" + ); self.lower_interrupt(); self.state.main_status.set_active_drives(0); } diff --git a/vm/devices/storage/floppy_pcat_stub/src/lib.rs b/vm/devices/storage/floppy_pcat_stub/src/lib.rs index f8b88975cd..9cbf660062 100644 --- a/vm/devices/storage/floppy_pcat_stub/src/lib.rs +++ b/vm/devices/storage/floppy_pcat_stub/src/lib.rs @@ -10,13 +10,13 @@ use arrayvec::ArrayVec; use bitfield_struct::bitfield; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use open_enum::open_enum; diff --git a/vm/devices/storage/floppy_resources/src/lib.rs b/vm/devices/storage/floppy_resources/src/lib.rs index 02fab78b3a..64b741e526 100644 --- a/vm/devices/storage/floppy_resources/src/lib.rs +++ b/vm/devices/storage/floppy_resources/src/lib.rs @@ -9,8 +9,8 @@ #![forbid(unsafe_code)] use mesh::MeshPayload; -use vm_resource::kind::DiskHandleKind; use vm_resource::Resource; +use vm_resource::kind::DiskHandleKind; /// The configuration for a floppy disk. #[derive(Debug, MeshPayload)] diff --git a/vm/devices/storage/ide/src/drive/atapi_drive.rs b/vm/devices/storage/ide/src/drive/atapi_drive.rs index 9af8fcaa9b..123b8cfcec 100644 --- a/vm/devices/storage/ide/src/drive/atapi_drive.rs +++ b/vm/devices/storage/ide/src/drive/atapi_drive.rs @@ -4,16 +4,16 @@ //! Implements atapi commands handler of optical drive. use super::DriveRegister; +use crate::DmaType; use crate::protocol; use crate::protocol::DeviceControlReg; use crate::protocol::DeviceHeadReg; use crate::protocol::ErrorReg; use crate::protocol::IdeCommand; use crate::protocol::Status; -use crate::DmaType; -use guestmem::ranges::PagedRange; use guestmem::AlignedHeapMemory; use guestmem::GuestMemory; +use guestmem::ranges::PagedRange; use ide_resources::IdePath; use inspect::Inspect; use safeatomic::AtomicSliceOps; @@ -23,7 +23,6 @@ use scsi_buffers::RequestBuffers; use scsi_core::AsyncScsiDisk; use scsi_core::ScsiResult; use scsi_defs as scsi; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::Context; diff --git a/vm/devices/storage/ide/src/drive/hard_drive.rs b/vm/devices/storage/ide/src/drive/hard_drive.rs index 597c29ab0c..366dd4928f 100644 --- a/vm/devices/storage/ide/src/drive/hard_drive.rs +++ b/vm/devices/storage/ide/src/drive/hard_drive.rs @@ -5,24 +5,23 @@ //! [`Disk`]. use super::DriveRegister; +use crate::DmaType; +use crate::NewDeviceError; use crate::protocol; use crate::protocol::DeviceControlReg; use crate::protocol::DeviceHeadReg; use crate::protocol::ErrorReg; use crate::protocol::IdeCommand; use crate::protocol::Status; -use crate::DmaType; -use crate::NewDeviceError; use disk_backend::Disk; use disk_backend::DiskError; -use guestmem::ranges::PagedRange; use guestmem::AlignedHeapMemory; use guestmem::GuestMemory; +use guestmem::ranges::PagedRange; use ide_resources::IdePath; use inspect::Inspect; use safeatomic::AtomicSliceOps; use scsi_buffers::RequestBuffers; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::Context; @@ -563,7 +562,9 @@ impl HardDrive { && data != self.disk_path.drive && self.state.command.is_some() { - tracing::warn!("Changing selected drive in the middle of operation. Resetting previously selected drive"); + tracing::warn!( + "Changing selected drive in the middle of operation. Resetting previously selected drive" + ); self.reset(); } self.state.regs.device_head = data.into(); diff --git a/vm/devices/storage/ide/src/lib.rs b/vm/devices/storage/ide/src/lib.rs index 40c0db64ff..8f1ade1aeb 100644 --- a/vm/devices/storage/ide/src/lib.rs +++ b/vm/devices/storage/ide/src/lib.rs @@ -13,16 +13,16 @@ use crate::protocol::DeviceControlReg; use crate::protocol::IdeCommand; use crate::protocol::IdeConfigSpace; use crate::protocol::Status; -use chipset_device::io::deferred::defer_write; -use chipset_device::io::deferred::DeferredWrite; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; +use chipset_device::io::deferred::DeferredWrite; +use chipset_device::io::deferred::defer_write; use chipset_device::pci::PciConfigSpace; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use disk_backend::Disk; use drive::DiskDrive; use drive::DriveRegister; @@ -32,8 +32,8 @@ use inspect::Inspect; use inspect::InspectMut; use open_enum::open_enum; use pci_core::spec::cfg_space::Command; -use pci_core::spec::cfg_space::HeaderType00; use pci_core::spec::cfg_space::HEADER_TYPE_00_SIZE; +use pci_core::spec::cfg_space::HeaderType00; use protocol::BusMasterCommandReg; use protocol::BusMasterStatusReg; use scsi::CdbFlags; @@ -1716,12 +1716,12 @@ mod save_restore { (Some(_), None) => { return Err(RestoreError::InvalidSavedState( ChannelRestoreError::MissingStateForDrive.into(), - )) + )); } (None, Some(_)) => { return Err(RestoreError::InvalidSavedState( ChannelRestoreError::MissingDriveForState.into(), - )) + )); } } } @@ -1734,10 +1734,10 @@ mod save_restore { #[cfg(test)] mod tests { use super::*; + use crate::IdeIoPort; use crate::protocol::BusMasterDmaDesc; use crate::protocol::DeviceHeadReg; use crate::protocol::IdeCommand; - use crate::IdeIoPort; use chipset_device::pio::ExternallyManagedPortIoIntercepts; use disk_file::FileDisk; use pal_async::async_test; diff --git a/vm/devices/storage/ide_resources/src/lib.rs b/vm/devices/storage/ide_resources/src/lib.rs index 08b22ea09c..4845192abc 100644 --- a/vm/devices/storage/ide_resources/src/lib.rs +++ b/vm/devices/storage/ide_resources/src/lib.rs @@ -10,9 +10,9 @@ use inspect::Inspect; use mesh::MeshPayload; +use vm_resource::Resource; use vm_resource::kind::DiskHandleKind; use vm_resource::kind::ScsiDeviceHandleKind; -use vm_resource::Resource; /// The location of an IDE device on a controller. #[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash, MeshPayload, Inspect)] diff --git a/vm/devices/storage/nvme/src/namespace/reservations.rs b/vm/devices/storage/nvme/src/namespace/reservations.rs index 6665e42ee0..cbe497e951 100644 --- a/vm/devices/storage/nvme/src/namespace/reservations.rs +++ b/vm/devices/storage/nvme/src/namespace/reservations.rs @@ -3,8 +3,8 @@ //! Persistent reservation support -use super::map_disk_error; use super::Namespace; +use super::map_disk_error; use crate::error::NvmeError; use crate::prp::PrpRange; use crate::spec; diff --git a/vm/devices/storage/nvme/src/pci.rs b/vm/devices/storage/nvme/src/pci.rs index 375a3437af..c42704d99e 100644 --- a/vm/devices/storage/nvme/src/pci.rs +++ b/vm/devices/storage/nvme/src/pci.rs @@ -3,28 +3,28 @@ //! The NVMe PCI device implementation. -use crate::spec; -use crate::workers::IoQueueEntrySizes; -use crate::workers::NvmeWorkers; -use crate::NvmeControllerClient; use crate::BAR0_LEN; use crate::DOORBELL_STRIDE_BITS; use crate::IOCQES; use crate::IOSQES; use crate::MAX_QES; use crate::NVME_VERSION; +use crate::NvmeControllerClient; use crate::PAGE_MASK; use crate::VENDOR_ID; +use crate::spec; +use crate::workers::IoQueueEntrySizes; +use crate::workers::NvmeWorkers; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoError::InvalidRegister; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; use chipset_device::pci::PciConfigSpace; -use chipset_device::ChipsetDevice; +use device_emulators::ReadWriteRequestType; use device_emulators::read_as_u32_chunks; use device_emulators::write_as_u32_chunks; -use device_emulators::ReadWriteRequestType; use guestmem::GuestMemory; use guid::Guid; use inspect::Inspect; diff --git a/vm/devices/storage/nvme/src/prp.rs b/vm/devices/storage/nvme/src/prp.rs index 6c96d776a0..242852fa31 100644 --- a/vm/devices/storage/nvme/src/prp.rs +++ b/vm/devices/storage/nvme/src/prp.rs @@ -3,15 +3,15 @@ //! Types for parsing NVMe PRP (Physical Region Page) entries and lists. -use crate::error::NvmeError; -use crate::spec; use crate::PAGE_MASK; use crate::PAGE_SHIFT; use crate::PAGE_SIZE; #[cfg(test)] use crate::PAGE_SIZE64; -use guestmem::ranges::PagedRange; +use crate::error::NvmeError; +use crate::spec; use guestmem::GuestMemory; +use guestmem::ranges::PagedRange; use zerocopy::IntoBytes; const PRP_PER_PAGE: usize = PAGE_SIZE / 8; diff --git a/vm/devices/storage/nvme/src/queue.rs b/vm/devices/storage/nvme/src/queue.rs index 22b5420aba..833c3499d6 100644 --- a/vm/devices/storage/nvme/src/queue.rs +++ b/vm/devices/storage/nvme/src/queue.rs @@ -7,9 +7,9 @@ use crate::spec; use guestmem::GuestMemory; use guestmem::GuestMemoryError; use inspect::Inspect; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; -use std::sync::Arc; use thiserror::Error; use vmcore::interrupt::Interrupt; @@ -322,9 +322,5 @@ impl CompletionQueue { } fn advance(n: u32, l: u32) -> u32 { - if n + 1 < l { - n + 1 - } else { - 0 - } + if n + 1 < l { n + 1 } else { 0 } } diff --git a/vm/devices/storage/nvme/src/resolver.rs b/vm/devices/storage/nvme/src/resolver.rs index a23a3a008b..6cd4ecf2cc 100644 --- a/vm/devices/storage/nvme/src/resolver.rs +++ b/vm/devices/storage/nvme/src/resolver.rs @@ -13,11 +13,11 @@ use nvme_resources::NvmeControllerHandle; use pci_resources::ResolvePciDeviceHandleParams; use pci_resources::ResolvedPciDevice; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::PciDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::PciDeviceHandleKind; /// Resource resolver for [`NvmeControllerHandle`]. pub struct NvmeControllerResolver; diff --git a/vm/devices/storage/nvme/src/tests/controller_tests.rs b/vm/devices/storage/nvme/src/tests/controller_tests.rs index cb972ce85c..615eafdc4a 100644 --- a/vm/devices/storage/nvme/src/tests/controller_tests.rs +++ b/vm/devices/storage/nvme/src/tests/controller_tests.rs @@ -2,21 +2,21 @@ // Licensed under the MIT License. use super::test_helpers::TestNvmeMmioRegistration; +use crate::BAR0_LEN; +use crate::NvmeController; +use crate::NvmeControllerCaps; +use crate::PAGE_SIZE64; use crate::prp::PrpRange; use crate::spec; use crate::tests::test_helpers::read_completion_from_queue; use crate::tests::test_helpers::test_memory; use crate::tests::test_helpers::write_command_to_queue; -use crate::NvmeController; -use crate::NvmeControllerCaps; -use crate::BAR0_LEN; -use crate::PAGE_SIZE64; use chipset_device::mmio::MmioIntercept; use chipset_device::pci::PciConfigSpace; use guestmem::GuestMemory; use guid::Guid; -use pal_async::async_test; use pal_async::DefaultDriver; +use pal_async::async_test; use pci_core::msi::MsiInterruptSet; use pci_core::test_helpers::TestPciInterruptController; use user_driver::backoff::Backoff; diff --git a/vm/devices/storage/nvme/src/tests/shadow_doorbell_tests.rs b/vm/devices/storage/nvme/src/tests/shadow_doorbell_tests.rs index 3885a2adf0..06382f1d67 100644 --- a/vm/devices/storage/nvme/src/tests/shadow_doorbell_tests.rs +++ b/vm/devices/storage/nvme/src/tests/shadow_doorbell_tests.rs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use crate::DOORBELL_STRIDE_BITS; +use crate::PAGE_SIZE64; use crate::prp::PrpRange; use crate::queue::ShadowDoorbell; use crate::spec; @@ -9,11 +11,9 @@ use crate::tests::controller_tests::wait_for_msi; use crate::tests::test_helpers::read_completion_from_queue; use crate::tests::test_helpers::test_memory; use crate::tests::test_helpers::write_command_to_queue; -use crate::DOORBELL_STRIDE_BITS; -use crate::PAGE_SIZE64; use guestmem::GuestMemory; -use pal_async::async_test; use pal_async::DefaultDriver; +use pal_async::async_test; use pci_core::test_helpers::TestPciInterruptController; use user_driver::backoff::Backoff; use zerocopy::FromZeros; diff --git a/vm/devices/storage/nvme/src/tests/test_helpers.rs b/vm/devices/storage/nvme/src/tests/test_helpers.rs index b1e5b9bd89..5c0d594c07 100644 --- a/vm/devices/storage/nvme/src/tests/test_helpers.rs +++ b/vm/devices/storage/nvme/src/tests/test_helpers.rs @@ -3,10 +3,10 @@ //! Mock types for unit-testing various NVMe behaviors. -use crate::prp::PrpRange; -use crate::spec; use crate::PAGE_SIZE; use crate::PAGE_SIZE64; +use crate::prp::PrpRange; +use crate::spec; use chipset_device::mmio::ControlMmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; use guestmem::GuestMemory; diff --git a/vm/devices/storage/nvme/src/workers/admin.rs b/vm/devices/storage/nvme/src/workers/admin.rs index 64f76f9359..7441cd791a 100644 --- a/vm/devices/storage/nvme/src/workers/admin.rs +++ b/vm/devices/storage/nvme/src/workers/admin.rs @@ -3,10 +3,16 @@ //! Admin queue handler. -use super::io::IoHandler; -use super::io::IoState; use super::IoQueueEntrySizes; use super::MAX_DATA_TRANSFER_SIZE; +use super::io::IoHandler; +use super::io::IoState; +use crate::DOORBELL_STRIDE_BITS; +use crate::MAX_QES; +use crate::NVME_VERSION; +use crate::PAGE_MASK; +use crate::PAGE_SIZE; +use crate::VENDOR_ID; use crate::error::CommandResult; use crate::error::NvmeError; use crate::namespace::Namespace; @@ -17,12 +23,6 @@ use crate::queue::QueueError; use crate::queue::ShadowDoorbell; use crate::queue::SubmissionQueue; use crate::spec; -use crate::DOORBELL_STRIDE_BITS; -use crate::MAX_QES; -use crate::NVME_VERSION; -use crate::PAGE_MASK; -use crate::PAGE_SIZE; -use crate::VENDOR_ID; use disk_backend::Disk; use futures::FutureExt; use futures::SinkExt; @@ -34,8 +34,8 @@ use inspect::Inspect; use pal_async::task::Spawn; use pal_async::task::Task; use parking_lot::Mutex; -use std::collections::btree_map; use std::collections::BTreeMap; +use std::collections::btree_map; use std::future::pending; use std::io::Cursor; use std::io::Write; diff --git a/vm/devices/storage/nvme/src/workers/coordinator.rs b/vm/devices/storage/nvme/src/workers/coordinator.rs index 47ea54611b..f8f5257964 100644 --- a/vm/devices/storage/nvme/src/workers/coordinator.rs +++ b/vm/devices/storage/nvme/src/workers/coordinator.rs @@ -3,11 +3,11 @@ //! Coordinator between queues and hot add/remove of namespaces. +use super::IoQueueEntrySizes; use super::admin::AdminConfig; use super::admin::AdminHandler; use super::admin::AdminState; use super::admin::NsidConflict; -use super::IoQueueEntrySizes; use crate::queue::DoorbellRegister; use disk_backend::Disk; use futures::FutureExt; diff --git a/vm/devices/storage/nvme/src/workers/io.rs b/vm/devices/storage/nvme/src/workers/io.rs index 1650069c6a..6b4b854bc3 100644 --- a/vm/devices/storage/nvme/src/workers/io.rs +++ b/vm/devices/storage/nvme/src/workers/io.rs @@ -19,7 +19,6 @@ use guestmem::GuestMemory; use inspect::Inspect; use std::collections::BTreeMap; use std::future::pending; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; use task_control::AsyncRun; diff --git a/vm/devices/storage/nvme_resources/src/lib.rs b/vm/devices/storage/nvme_resources/src/lib.rs index 261b22fb52..294dc53593 100644 --- a/vm/devices/storage/nvme_resources/src/lib.rs +++ b/vm/devices/storage/nvme_resources/src/lib.rs @@ -7,10 +7,10 @@ use guid::Guid; use mesh::MeshPayload; -use vm_resource::kind::DiskHandleKind; -use vm_resource::kind::PciDeviceHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::DiskHandleKind; +use vm_resource::kind::PciDeviceHandleKind; /// A handle to an NVMe controller. #[derive(MeshPayload)] diff --git a/vm/devices/storage/scsi_buffers/fuzz/fuzz_scsi_buffers.rs b/vm/devices/storage/scsi_buffers/fuzz/fuzz_scsi_buffers.rs index 8cd6a98d8b..f5cabdf7c4 100644 --- a/vm/devices/storage/scsi_buffers/fuzz/fuzz_scsi_buffers.rs +++ b/vm/devices/storage/scsi_buffers/fuzz/fuzz_scsi_buffers.rs @@ -8,8 +8,8 @@ use arbitrary::Arbitrary; use arbitrary::Unstructured; -use guestmem::ranges::PagedRange; use guestmem::GuestMemory; +use guestmem::ranges::PagedRange; use scsi_buffers::BounceBuffer; use scsi_buffers::IoBuffer; use scsi_buffers::RequestBuffers; diff --git a/vm/devices/storage/scsi_buffers/src/lib.rs b/vm/devices/storage/scsi_buffers/src/lib.rs index ebcbcfddc8..6616ed3699 100644 --- a/vm/devices/storage/scsi_buffers/src/lib.rs +++ b/vm/devices/storage/scsi_buffers/src/lib.rs @@ -7,13 +7,13 @@ // UNSAFETY: Handling raw pointers and transmuting between types for different use cases. #![expect(unsafe_code)] -use guestmem::ranges::PagedRange; use guestmem::AccessError; use guestmem::GuestMemory; use guestmem::LockedRange; use guestmem::LockedRangeImpl; use guestmem::MemoryRead; use guestmem::MemoryWrite; +use guestmem::ranges::PagedRange; use safeatomic::AsAtomicBytes; use smallvec::SmallVec; use std::marker::PhantomData; diff --git a/vm/devices/storage/scsi_core/src/lib.rs b/vm/devices/storage/scsi_core/src/lib.rs index 3bd461b58a..ef43c22c47 100644 --- a/vm/devices/storage/scsi_core/src/lib.rs +++ b/vm/devices/storage/scsi_core/src/lib.rs @@ -7,13 +7,13 @@ use inspect::Inspect; use scsi_buffers::RequestBuffers; -use scsi_defs::srb::SrbStatus; use scsi_defs::ScsiOp; use scsi_defs::ScsiStatus; +use scsi_defs::srb::SrbStatus; use stackfuture::StackFuture; use std::sync::Arc; -use vm_resource::kind::ScsiDeviceHandleKind; use vm_resource::CanResolveTo; +use vm_resource::kind::ScsiDeviceHandleKind; use vmcore::save_restore::RestoreError; use vmcore::save_restore::SaveError; use vmcore::vm_task::VmTaskDriverSource; diff --git a/vm/devices/storage/scsidisk/src/atapi_scsi.rs b/vm/devices/storage/scsidisk/src/atapi_scsi.rs index 1e98915bbe..814bd5bb22 100644 --- a/vm/devices/storage/scsidisk/src/atapi_scsi.rs +++ b/vm/devices/storage/scsidisk/src/atapi_scsi.rs @@ -5,24 +5,24 @@ //! [`AsyncScsiDisk`]. //! -use crate::illegal_request_sense; use crate::SenseDataSlot; +use crate::illegal_request_sense; use guestmem::MemoryWrite; use inspect::Inspect; -use scsi::srb::SrbStatus; use scsi::AdditionalSenseCode; use scsi::ScsiOp; use scsi::ScsiStatus; use scsi::SenseKey; +use scsi::srb::SrbStatus; use scsi_buffers::RequestBuffers; -use scsi_core::save_restore::SavedSenseData; -use scsi_core::save_restore::ScsiDvdSavedState; -use scsi_core::save_restore::ScsiSavedState; +use scsi_core::ASYNC_SCSI_DISK_STACK_SIZE; use scsi_core::AsyncScsiDisk; use scsi_core::Request; use scsi_core::ScsiResult; use scsi_core::ScsiSaveRestore; -use scsi_core::ASYNC_SCSI_DISK_STACK_SIZE; +use scsi_core::save_restore::SavedSenseData; +use scsi_core::save_restore::ScsiDvdSavedState; +use scsi_core::save_restore::ScsiSavedState; use scsi_defs as scsi; use stackfuture::StackFuture; use std::sync::Arc; diff --git a/vm/devices/storage/scsidisk/src/inquiry.rs b/vm/devices/storage/scsidisk/src/inquiry.rs index 769535182b..44e7ee38b2 100644 --- a/vm/devices/storage/scsidisk/src/inquiry.rs +++ b/vm/devices/storage/scsidisk/src/inquiry.rs @@ -3,9 +3,9 @@ use super::ScsiError; use super::SimpleScsiDisk; -use crate::scsi; use crate::UNMAP_RANGE_DESCRIPTOR_COUNT_MAX; use crate::VHDMP_MAX_WRITE_SAME_LENGTH_BYTES; +use crate::scsi; use guestmem::MemoryWrite; use guid::Guid; use scsi::AdditionalSenseCode; diff --git a/vm/devices/storage/scsidisk/src/lib.rs b/vm/devices/storage/scsidisk/src/lib.rs index 531bc3cc33..bb8a3035ca 100644 --- a/vm/devices/storage/scsidisk/src/lib.rs +++ b/vm/devices/storage/scsidisk/src/lib.rs @@ -26,20 +26,20 @@ use guestmem::MemoryWrite; use guid::Guid; use inspect::Inspect; use parking_lot::Mutex; -use scsi::srb::SrbStatus; use scsi::AdditionalSenseCode; use scsi::ScsiOp; use scsi::ScsiStatus; use scsi::SenseKey; +use scsi::srb::SrbStatus; use scsi_buffers::RequestBuffers; -use scsi_core::save_restore::SavedSenseData; -use scsi_core::save_restore::ScsiDiskSavedState; -use scsi_core::save_restore::ScsiSavedState; +use scsi_core::ASYNC_SCSI_DISK_STACK_SIZE; use scsi_core::AsyncScsiDisk; use scsi_core::Request; use scsi_core::ScsiResult; use scsi_core::ScsiSaveRestore; -use scsi_core::ASYNC_SCSI_DISK_STACK_SIZE; +use scsi_core::save_restore::SavedSenseData; +use scsi_core::save_restore::ScsiDiskSavedState; +use scsi_core::save_restore::ScsiSavedState; use scsi_defs as scsi; use scsidisk_resources::DiskIdentity; use scsidisk_resources::DiskParameters; @@ -164,11 +164,7 @@ impl SimpleScsiDisk { } = disk_parameters; fn nonzero_id(id: [u8; 16]) -> Option<[u8; 16]> { - if id == [0; 16] { - None - } else { - Some(id) - } + if id == [0; 16] { None } else { Some(id) } } // Choose the first non-zero disk ID from the passed in parameters, diff --git a/vm/devices/storage/scsidisk/src/reservation.rs b/vm/devices/storage/scsidisk/src/reservation.rs index bab2c14ee7..e86d89a957 100644 --- a/vm/devices/storage/scsidisk/src/reservation.rs +++ b/vm/devices/storage/scsidisk/src/reservation.rs @@ -5,6 +5,7 @@ use super::ScsiError; use super::SimpleScsiDisk; +use crate::RequestBuffers; use crate::scsi; use crate::scsi::PriFullStatusDescriptorHeader; use crate::scsi::PriFullStatusListHeader; @@ -12,7 +13,6 @@ use crate::scsi::PriRegistrationListHeader; use crate::scsi::PriReportCapabilities; use crate::scsi::PriReservationDescriptor; use crate::scsi::PriReservationListHeader; -use crate::RequestBuffers; use guestmem::MemoryRead; use guestmem::MemoryWrite; use scsi::AdditionalSenseCode; diff --git a/vm/devices/storage/scsidisk/src/resolver.rs b/vm/devices/storage/scsidisk/src/resolver.rs index cac499bd98..b456624887 100644 --- a/vm/devices/storage/scsidisk/src/resolver.rs +++ b/vm/devices/storage/scsidisk/src/resolver.rs @@ -3,8 +3,8 @@ //! Resolver for SCSI devices. -use crate::scsidvd::SimpleScsiDvd; use crate::SimpleScsiDisk; +use crate::scsidvd::SimpleScsiDvd; use anyhow::Context; use async_trait::async_trait; use disk_backend::resolve::ResolveDiskParameters; @@ -18,11 +18,11 @@ use scsidisk_resources::SimpleScsiDvdRequest; use std::sync::Arc; use std::sync::Weak; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::ScsiDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::ScsiDeviceHandleKind; /// A resolver for [`SimpleScsiDiskHandle`] and [`SimpleScsiDvdHandle`]. pub struct SimpleScsiResolver; diff --git a/vm/devices/storage/scsidisk/src/scsidvd/mod.rs b/vm/devices/storage/scsidisk/src/scsidvd/mod.rs index 461106f193..d8d9800a57 100644 --- a/vm/devices/storage/scsidisk/src/scsidvd/mod.rs +++ b/vm/devices/storage/scsidisk/src/scsidvd/mod.rs @@ -1,11 +1,11 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::scsi; use super::AsyncScsiDisk; use super::SavedSenseData; use super::ScsiResult; use super::ScsiSaveRestore; +use super::scsi; use crate::Request; use crate::ScsiSavedState; use crate::SenseDataSlot; @@ -16,13 +16,13 @@ use guestmem::MemoryRead; use guestmem::MemoryWrite; use parking_lot::Mutex; use parking_lot::RwLock; -use scsi::srb::SrbStatus; use scsi::AdditionalSenseCode; use scsi::FeatureNumber::{FeaturePowerManagement, FeatureRealTimeStreaming, FeatureTimeout}; use scsi::ScsiOp; use scsi::ScsiStatus; use scsi::SenseData; use scsi::SenseKey; +use scsi::srb::SrbStatus; use scsi_buffers::RequestBuffers; use scsi_core::save_restore::DriveState; use scsi_core::save_restore::IsoMediumEvent; @@ -2373,12 +2373,12 @@ fn illegal_request_sense_iso(sense_code: AdditionalSenseCode, sense_qualifier: u #[cfg(test)] mod tests { use super::Media; - use crate::scsi; - use crate::scsidvd::SimpleScsiDvd; - use crate::scsidvd::ISO_SECTOR_SIZE; use crate::SavedSenseData; use crate::ScsiSaveRestore; use crate::ScsiSavedState; + use crate::scsi; + use crate::scsidvd::ISO_SECTOR_SIZE; + use crate::scsidvd::SimpleScsiDvd; use disk_backend::Disk; use disk_backend::DiskError; use disk_backend::DiskIo; @@ -2391,9 +2391,9 @@ mod tests { use scsi::SenseKey; use scsi_buffers::OwnedRequestBuffers; use scsi_buffers::RequestBuffers; - use scsi_core::save_restore::ScsiDvdSavedState; use scsi_core::AsyncScsiDisk; use scsi_core::Request; + use scsi_core::save_restore::ScsiDvdSavedState; use zerocopy::IntoBytes; diff --git a/vm/devices/storage/scsidisk/src/tests/basic_tests.rs b/vm/devices/storage/scsidisk/src/tests/basic_tests.rs index 76ed1da5cb..3cfedf8474 100644 --- a/vm/devices/storage/scsidisk/src/tests/basic_tests.rs +++ b/vm/devices/storage/scsidisk/src/tests/basic_tests.rs @@ -12,8 +12,8 @@ use super::test_helpers::make_repeat_data_buffer; use super::test_helpers::new_atapi_disk; use super::test_helpers::new_scsi_disk; use super::test_helpers::new_scsi_dvd; -use crate::scsi; use crate::SimpleScsiDisk; +use crate::scsi; use guestmem::GuestMemory; use pal_async::async_test; use scsi::AdditionalSenseCode; @@ -21,14 +21,14 @@ use scsi::ScsiOp; use scsi::ScsiStatus; use scsi::SenseKey; use scsi_buffers::OwnedRequestBuffers; -use scsi_core::save_restore::SavedSenseData; -use scsi_core::save_restore::ScsiDiskSavedState; -use scsi_core::save_restore::ScsiSavedState; use scsi_core::AsyncScsiDisk; use scsi_core::Request; use scsi_core::ScsiSaveRestore; -use std::sync::atomic::Ordering; +use scsi_core::save_restore::SavedSenseData; +use scsi_core::save_restore::ScsiDiskSavedState; +use scsi_core::save_restore::ScsiSavedState; use std::sync::Arc; +use std::sync::atomic::Ordering; use zerocopy::IntoBytes; fn save_scsi_disk(scsi_disk: &SimpleScsiDisk) -> ScsiDiskSavedState { diff --git a/vm/devices/storage/scsidisk/src/tests/pr_tests.rs b/vm/devices/storage/scsidisk/src/tests/pr_tests.rs index 3b4d19f909..4efb66cf88 100644 --- a/vm/devices/storage/scsidisk/src/tests/pr_tests.rs +++ b/vm/devices/storage/scsidisk/src/tests/pr_tests.rs @@ -9,16 +9,16 @@ use super::test_helpers::check_execute_scsi_pass_with_tx; use super::test_helpers::check_guest_memory; use super::test_helpers::make_guest_memory; use super::test_helpers::new_scsi_disk; -use crate::scsi; use crate::SimpleScsiDisk; +use crate::scsi; use disk_backend::pr; use guestmem::GuestMemory; use pal_async::async_test; -use scsi::srb::SrbStatus; use scsi::AdditionalSenseCode; use scsi::ScsiStatus; use scsi::SenseData; use scsi::SenseKey; +use scsi::srb::SrbStatus; use scsi_buffers::OwnedRequestBuffers; use scsi_core::Request; use scsi_core::ScsiResult; diff --git a/vm/devices/storage/scsidisk/src/tests/test_helpers.rs b/vm/devices/storage/scsidisk/src/tests/test_helpers.rs index ac04b533a6..0e61eaa832 100644 --- a/vm/devices/storage/scsidisk/src/tests/test_helpers.rs +++ b/vm/devices/storage/scsidisk/src/tests/test_helpers.rs @@ -3,10 +3,10 @@ //! ScsiDisk test helpers. +use crate::SimpleScsiDisk; use crate::atapi_scsi::AtapiScsiDisk; use crate::scsi; use crate::scsidvd::SimpleScsiDvd; -use crate::SimpleScsiDisk; use disk_backend::Disk; use disk_backend::DiskError; use disk_backend::DiskIo; diff --git a/vm/devices/storage/scsidisk/src/unmap.rs b/vm/devices/storage/scsidisk/src/unmap.rs index 1af218369f..7a4222c40f 100644 --- a/vm/devices/storage/scsidisk/src/unmap.rs +++ b/vm/devices/storage/scsidisk/src/unmap.rs @@ -3,8 +3,8 @@ use super::ScsiError; use super::SimpleScsiDisk; -use crate::scsi; use crate::UNMAP_RANGE_DESCRIPTOR_COUNT_MAX; +use crate::scsi; use guestmem::MemoryRead; use scsi::AdditionalSenseCode; use scsi_buffers::RequestBuffers; diff --git a/vm/devices/storage/scsidisk_resources/src/lib.rs b/vm/devices/storage/scsidisk_resources/src/lib.rs index 9fb9918d1f..3f183b6137 100644 --- a/vm/devices/storage/scsidisk_resources/src/lib.rs +++ b/vm/devices/storage/scsidisk_resources/src/lib.rs @@ -6,14 +6,14 @@ #![forbid(unsafe_code)] use inspect::Inspect; +use mesh::MeshPayload; use mesh::payload::Protobuf; use mesh::rpc::FailableRpc; -use mesh::MeshPayload; use storage_string::AsciiString; -use vm_resource::kind::DiskHandleKind; -use vm_resource::kind::ScsiDeviceHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::DiskHandleKind; +use vm_resource::kind::ScsiDeviceHandleKind; /// Resource handle for an emulated SCSI disk. #[derive(MeshPayload)] diff --git a/vm/devices/storage/storvsp/benches/ioperf.rs b/vm/devices/storage/storvsp/benches/ioperf.rs index 61693c09df..4ddf570d89 100644 --- a/vm/devices/storage/storvsp/benches/ioperf.rs +++ b/vm/devices/storage/storvsp/benches/ioperf.rs @@ -5,11 +5,11 @@ #![expect(missing_docs)] +use criterion::BenchmarkId; +use criterion::Criterion; use criterion::async_executor::AsyncExecutor; use criterion::criterion_group; use criterion::criterion_main; -use criterion::BenchmarkId; -use criterion::Criterion; use pal_async::DefaultPool; use std::cell::Cell; use std::cell::RefCell; @@ -17,7 +17,7 @@ use std::cell::RefCell; struct WrappedExecutor(RefCell); impl AsyncExecutor for &'_ WrappedExecutor { - fn block_on(&self, future: impl std::future::Future) -> T { + fn block_on(&self, future: impl Future) -> T { self.0.borrow_mut().run_until(future) } } diff --git a/vm/devices/storage/storvsp/fuzz/fuzz_storvsp.rs b/vm/devices/storage/storvsp/fuzz/fuzz_storvsp.rs index d9927bd8a4..d1222c23cb 100644 --- a/vm/devices/storage/storvsp/fuzz/fuzz_storvsp.rs +++ b/vm/devices/storage/storvsp/fuzz/fuzz_storvsp.rs @@ -6,20 +6,20 @@ use arbitrary::Arbitrary; use arbitrary::Unstructured; -use futures::select; use futures::FutureExt; -use guestmem::ranges::PagedRange; +use futures::select; use guestmem::GuestMemory; +use guestmem::ranges::PagedRange; use pal_async::DefaultPool; use scsi_defs::Cdb10; use scsi_defs::ScsiOp; use std::pin::pin; use std::sync::Arc; +use storvsp::ScsiController; +use storvsp::ScsiControllerDisk; use storvsp::protocol; use storvsp::test_helpers::TestGuest; use storvsp::test_helpers::TestWorker; -use storvsp::ScsiController; -use storvsp::ScsiControllerDisk; use storvsp_resources::ScsiPath; use vmbus_async::queue::OutgoingPacket; use vmbus_async::queue::Queue; diff --git a/vm/devices/storage/storvsp/src/ioperf.rs b/vm/devices/storage/storvsp/src/ioperf.rs index 954e752add..e5831225c8 100644 --- a/vm/devices/storage/storvsp/src/ioperf.rs +++ b/vm/devices/storage/storvsp/src/ioperf.rs @@ -3,13 +3,13 @@ //! Test instructure for criterion benchmarks. +use crate::ScsiController; +use crate::ScsiControllerDisk; +use crate::ScsiPath; use crate::protocol; use crate::test_helpers; use crate::test_helpers::TestGuest; use crate::test_helpers::TestWorker; -use crate::ScsiController; -use crate::ScsiControllerDisk; -use crate::ScsiPath; use disklayer_ram::ram_disk; use guestmem::GuestMemory; use pal_async::driver::SpawnDriver; diff --git a/vm/devices/storage/storvsp/src/lib.rs b/vm/devices/storage/storvsp/src/lib.rs index 47be94e682..c114012fba 100644 --- a/vm/devices/storage/storvsp/src/lib.rs +++ b/vm/devices/storage/storvsp/src/lib.rs @@ -25,14 +25,14 @@ use crate::ring::gparange::MultiPagedRangeBuf; use anyhow::Context as _; use async_trait::async_trait; use fast_select::FastSelect; -use futures::select_biased; use futures::FutureExt; use futures::StreamExt; -use guestmem::ranges::PagedRange; +use futures::select_biased; use guestmem::AccessError; use guestmem::GuestMemory; use guestmem::MemoryRead; use guestmem::MemoryWrite; +use guestmem::ranges::PagedRange; use guid::Guid; use inspect::Inspect; use inspect::InspectMut; @@ -43,11 +43,11 @@ use parking_lot::Mutex; use parking_lot::RwLock; use protocol::NtStatus; use ring::OutgoingPacketType; -use scsi::srb::SrbStatus; -use scsi::srb::SrbStatusAndFlags; use scsi::AdditionalSenseCode; use scsi::ScsiOp; use scsi::ScsiStatus; +use scsi::srb::SrbStatus; +use scsi::srb::SrbStatusAndFlags; use scsi_buffers::RequestBuffers; use scsi_core::AsyncScsiDisk; use scsi_core::Request; @@ -59,7 +59,6 @@ use std::collections::hash_map::Entry; use std::collections::hash_map::HashMap; use std::fmt::Debug; use std::future::poll_fn; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::Context; @@ -77,6 +76,7 @@ use vmbus_async::queue::ExternalDataError; use vmbus_async::queue::IncomingPacket; use vmbus_async::queue::OutgoingPacket; use vmbus_async::queue::Queue; +use vmbus_channel::RawAsyncChannel; use vmbus_channel::bus::ChannelType; use vmbus_channel::bus::OfferParams; use vmbus_channel::bus::OpenRequest; @@ -86,9 +86,8 @@ use vmbus_channel::channel::DeviceResources; use vmbus_channel::channel::RestoreControl; use vmbus_channel::channel::SaveRestoreVmbusDevice; use vmbus_channel::channel::VmbusDevice; -use vmbus_channel::gpadl_ring::gpadl_channel; use vmbus_channel::gpadl_ring::GpadlRingMem; -use vmbus_channel::RawAsyncChannel; +use vmbus_channel::gpadl_ring::gpadl_channel; use vmbus_core::protocol::UserDefinedData; use vmbus_ring as ring; use vmbus_ring::RingMem; @@ -883,7 +882,7 @@ impl Worker { } } } - } + }; } ProtocolState::Init(state) => { let (mut reader, mut writer) = self.queue.split(); @@ -1738,11 +1737,11 @@ impl SaveRestoreVmbusDevice for StorageDevice { mod tests { use super::protocol; use super::*; + use crate::test_helpers::TestWorker; use crate::test_helpers::parse_guest_completion; use crate::test_helpers::parse_guest_completion_check_flags_status; - use crate::test_helpers::TestWorker; - use pal_async::async_test; use pal_async::DefaultDriver; + use pal_async::async_test; use scsi::srb::SrbStatus; use test_with_tracing::test; use vmbus_channel::connected_async_channels; diff --git a/vm/devices/storage/storvsp/src/protocol.rs b/vm/devices/storage/storvsp/src/protocol.rs index e78531ab9f..d317c53660 100644 --- a/vm/devices/storage/storvsp/src/protocol.rs +++ b/vm/devices/storage/storvsp/src/protocol.rs @@ -5,8 +5,8 @@ use guid::Guid; use open_enum::open_enum; -use scsi_defs::srb::SrbStatusAndFlags; use scsi_defs::ScsiStatus; +use scsi_defs::srb::SrbStatusAndFlags; use std::fmt::Debug; use zerocopy::FromBytes; use zerocopy::Immutable; diff --git a/vm/devices/storage/storvsp/src/resolver.rs b/vm/devices/storage/storvsp/src/resolver.rs index 3e19ce613e..23e0f0f502 100644 --- a/vm/devices/storage/storvsp/src/resolver.rs +++ b/vm/devices/storage/storvsp/src/resolver.rs @@ -20,11 +20,11 @@ use storvsp_resources::ScsiControllerRequest; use storvsp_resources::ScsiDeviceAndPath; use storvsp_resources::ScsiPath; use thiserror::Error; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::VmbusDeviceHandleKind; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; use vmcore::vm_task::VmTaskDriverSource; diff --git a/vm/devices/storage/storvsp/src/save_restore.rs b/vm/devices/storage/storvsp/src/save_restore.rs index 8ff57a171d..bc477631b2 100644 --- a/vm/devices/storage/storvsp/src/save_restore.rs +++ b/vm/devices/storage/storvsp/src/save_restore.rs @@ -5,7 +5,6 @@ use self::state::Drive; use self::state::DriveSavedState; -use crate::protocol; use crate::Range; use crate::ScsiPath; use crate::ScsiRequestAndRange; @@ -13,6 +12,7 @@ use crate::ScsiRequestState; use crate::StorageDevice; use crate::UnsupportedVersion; use crate::Version; +use crate::protocol; use scsi_core::save_restore::ScsiSavedState; use std::sync::Arc; use thiserror::Error; diff --git a/vm/devices/storage/storvsp/src/test_helpers.rs b/vm/devices/storage/storvsp/src/test_helpers.rs index f784166ba9..8b41cf61ca 100644 --- a/vm/devices/storage/storvsp/src/test_helpers.rs +++ b/vm/devices/storage/storvsp/src/test_helpers.rs @@ -17,14 +17,14 @@ use crate::ScsiController; use crate::ScsiPath; use crate::Worker; use crate::WorkerError; -use guestmem::ranges::PagedRange; use guestmem::GuestMemory; use guestmem::MemoryRead; +use guestmem::ranges::PagedRange; use pal_async::task::Spawn; use pal_async::task::Task; use parking_lot::RwLock; -use scsi::srb::SrbStatus; use scsi::ScsiOp; +use scsi::srb::SrbStatus; use scsi_defs as scsi; use std::sync::Arc; use vmbus_async::queue::IncomingPacket; diff --git a/vm/devices/storage/storvsp_resources/src/lib.rs b/vm/devices/storage/storvsp_resources/src/lib.rs index 385f85c734..accb9207cc 100644 --- a/vm/devices/storage/storvsp_resources/src/lib.rs +++ b/vm/devices/storage/storvsp_resources/src/lib.rs @@ -6,13 +6,13 @@ #![forbid(unsafe_code)] use guid::Guid; +use mesh::MeshPayload; use mesh::payload::Protobuf; use mesh::rpc::FailableRpc; -use mesh::MeshPayload; -use vm_resource::kind::ScsiDeviceHandleKind; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::ScsiDeviceHandleKind; +use vm_resource::kind::VmbusDeviceHandleKind; /// A path at which to enumerate a SCSI logical unit. #[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Hash, Protobuf)] diff --git a/vm/devices/support/fs/fuse/src/session.rs b/vm/devices/support/fs/fuse/src/session.rs index fa5f3d5aad..0424a0b64d 100644 --- a/vm/devices/support/fs/fuse/src/session.rs +++ b/vm/devices/support/fs/fuse/src/session.rs @@ -1,13 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use super::Fuse; +use super::Mapper; use super::protocol::*; use super::reply::ReplySender; use super::request::FuseOperation; use super::request::Request; use super::request::RequestReader; -use super::Fuse; -use super::Mapper; use parking_lot::RwLock; use std::io; use std::sync::atomic; diff --git a/vm/devices/support/fs/fuse/tests/fuse_hello.rs b/vm/devices/support/fs/fuse/tests/fuse_hello.rs index d51cdde5a1..e69bdd121b 100644 --- a/vm/devices/support/fs/fuse/tests/fuse_hello.rs +++ b/vm/devices/support/fs/fuse/tests/fuse_hello.rs @@ -4,8 +4,8 @@ #![expect(missing_docs)] #![cfg(target_os = "linux")] -use fuse::protocol::*; use fuse::Connection; +use fuse::protocol::*; use fuse::*; use std::fs; use std::os::linux::fs::MetadataExt; diff --git a/vm/devices/support/fs/lxutil/src/windows/fs.rs b/vm/devices/support/fs/lxutil/src/windows/fs.rs index c4985c15c3..d2131f2da7 100644 --- a/vm/devices/support/fs/lxutil/src/windows/fs.rs +++ b/vm/devices/support/fs/lxutil/src/windows/fs.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use super::VolumeState; use super::symlink; use super::util; -use super::VolumeState; use ::windows::Wdk::Storage::FileSystem; use ::windows::Wdk::System::SystemServices; use ::windows::Win32::Foundation; diff --git a/vm/devices/support/fs/lxutil/src/windows/mod.rs b/vm/devices/support/fs/lxutil/src/windows/mod.rs index 859fe42231..cbf65d165a 100644 --- a/vm/devices/support/fs/lxutil/src/windows/mod.rs +++ b/vm/devices/support/fs/lxutil/src/windows/mod.rs @@ -30,9 +30,9 @@ use std::path::Component; use std::path::Path; use std::path::PathBuf; use std::ptr; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; -use std::sync::Arc; use winapi::shared::basetsd; use winapi::shared::ntdef; use winapi::um::winnt; diff --git a/vm/devices/support/fs/plan9/src/lib.rs b/vm/devices/support/fs/plan9/src/lib.rs index f90864fd6d..213e1d3454 100644 --- a/vm/devices/support/fs/plan9/src/lib.rs +++ b/vm/devices/support/fs/plan9/src/lib.rs @@ -13,12 +13,12 @@ use fid::*; use lxutil::LxVolume; use parking_lot::RwLock; use protocol::*; -use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::collections::hash_map::Entry; use std::str; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; -use std::sync::Arc; const MINIMUM_REQUEST_BUFFER_SIZE: u32 = 4096; const MAXIMUM_REQUEST_BUFFER_SIZE: u32 = 256 * 1024; diff --git a/vm/devices/tpm/src/lib.rs b/vm/devices/tpm/src/lib.rs index 2bac32581e..b16070da72 100644 --- a/vm/devices/tpm/src/lib.rs +++ b/vm/devices/tpm/src/lib.rs @@ -19,35 +19,34 @@ mod tpm_helper; use self::io_port_interface::PpiOperation; use self::io_port_interface::TpmIoCommand; use crate::ak_cert::TpmAkCertType; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use guestmem::GuestMemory; use inspect::Inspect; use inspect::InspectMut; use ms_tpm_20_ref::MsTpm20RefPlatform; use parking_lot::Mutex; -use std::future::Future; use std::ops::RangeInclusive; use std::pin::Pin; use std::sync::Arc; use std::task::Poll; use std::task::Waker; use thiserror::Error; -use tpm20proto::CommandCodeEnum; -use tpm20proto::ReservedHandle; -use tpm20proto::NV_INDEX_RANGE_BASE_PLATFORM_MANUFACTURER; -use tpm20proto::NV_INDEX_RANGE_BASE_TCG_ASSIGNED; -use tpm20proto::TPM20_HT_PERSISTENT; -use tpm20proto::TPM20_RH_PLATFORM; use tpm_helper::CommandDebugInfo; use tpm_helper::TpmCommandError; use tpm_helper::TpmEngineHelper; use tpm_helper::TpmHelperError; use tpm_resources::TpmRegisterLayout; +use tpm20proto::CommandCodeEnum; +use tpm20proto::NV_INDEX_RANGE_BASE_PLATFORM_MANUFACTURER; +use tpm20proto::NV_INDEX_RANGE_BASE_TCG_ASSIGNED; +use tpm20proto::ReservedHandle; +use tpm20proto::TPM20_HT_PERSISTENT; +use tpm20proto::TPM20_RH_PLATFORM; use vmcore::device_state::ChangeDeviceState; use vmcore::non_volatile_store::NonVolatileStore; use vmcore::non_volatile_store::NonVolatileStoreError; diff --git a/vm/devices/tpm/src/resolver.rs b/vm/devices/tpm/src/resolver.rs index bad8491f7b..1789e38125 100644 --- a/vm/devices/tpm/src/resolver.rs +++ b/vm/devices/tpm/src/resolver.rs @@ -1,20 +1,20 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::ak_cert::TpmAkCertType; use crate::Tpm; use crate::TpmError; +use crate::ak_cert::TpmAkCertType; use async_trait::async_trait; use chipset_device_resources::ResolveChipsetDeviceHandleParams; use chipset_device_resources::ResolvedChipsetDevice; use thiserror::Error; use tpm_resources::TpmAkCertTypeResource; use tpm_resources::TpmDeviceHandle; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::ChipsetDeviceHandleKind; pub struct TpmDeviceResolver; diff --git a/vm/devices/tpm/src/tpm20proto.rs b/vm/devices/tpm/src/tpm20proto.rs index 3d305d2808..95a9e2018f 100644 --- a/vm/devices/tpm/src/tpm20proto.rs +++ b/vm/devices/tpm/src/tpm20proto.rs @@ -64,13 +64,17 @@ pub enum TpmProtoError { pub enum ResponseValidationError { #[error("response size is too small to fit into the buffer")] ResponseSizeTooSmall, - #[error("size {size} specified in the response header does not meet the minimal size of command type {expected_size}, command succeeded: {command_succeeded}")] + #[error( + "size {size} specified in the response header does not meet the minimal size of command type {expected_size}, command succeeded: {command_succeeded}" + )] HeaderResponseSizeMismatch { size: u32, expected_size: usize, command_succeeded: bool, }, - #[error("unexpected session tag {response_session_tag} specified in the response header, expected: {expected_session_tag}, command succeeded: {command_succeeded}")] + #[error( + "unexpected session tag {response_session_tag} specified in the response header, expected: {expected_session_tag}, command succeeded: {command_succeeded}" + )] HeaderSessionTagMismatch { response_session_tag: u16, expected_session_tag: u16, diff --git a/vm/devices/tpm/src/tpm_helper.rs b/vm/devices/tpm/src/tpm_helper.rs index 8d91998637..623ed4f29f 100644 --- a/vm/devices/tpm/src/tpm_helper.rs +++ b/vm/devices/tpm/src/tpm_helper.rs @@ -3,8 +3,27 @@ //! The module includes the helper functions for sending TPM commands. +use crate::TPM_AZURE_AIK_HANDLE; +use crate::TPM_GUEST_SECRET_HANDLE; +use crate::TPM_NV_INDEX_AIK_CERT; +use crate::TPM_NV_INDEX_ATTESTATION_REPORT; +use crate::TPM_RSA_SRK_HANDLE; +use crate::TpmRsa2kPublic; use crate::tpm20proto; -use crate::tpm20proto::protocol::common::CmdAuth; +use crate::tpm20proto::AlgIdEnum; +use crate::tpm20proto::CommandCodeEnum; +use crate::tpm20proto::MAX_DIGEST_BUFFER_SIZE; +use crate::tpm20proto::ReservedHandle; +use crate::tpm20proto::ResponseCode; +use crate::tpm20proto::ResponseValidationError; +use crate::tpm20proto::SessionTagEnum; +use crate::tpm20proto::TPM20_RH_ENDORSEMENT; +use crate::tpm20proto::TPM20_RH_OWNER; +use crate::tpm20proto::TPM20_RH_PLATFORM; +use crate::tpm20proto::TPM20_RS_PW; +use crate::tpm20proto::TpmProtoError; +use crate::tpm20proto::TpmaNvBits; +use crate::tpm20proto::TpmaObjectBits; use crate::tpm20proto::protocol::CreatePrimaryReply; use crate::tpm20proto::protocol::ImportReply; use crate::tpm20proto::protocol::LoadReply; @@ -20,26 +39,7 @@ use crate::tpm20proto::protocol::TpmsRsaParams; use crate::tpm20proto::protocol::TpmtPublic; use crate::tpm20proto::protocol::TpmtRsaScheme; use crate::tpm20proto::protocol::TpmtSymDefObject; -use crate::tpm20proto::AlgIdEnum; -use crate::tpm20proto::CommandCodeEnum; -use crate::tpm20proto::ReservedHandle; -use crate::tpm20proto::ResponseCode; -use crate::tpm20proto::ResponseValidationError; -use crate::tpm20proto::SessionTagEnum; -use crate::tpm20proto::TpmProtoError; -use crate::tpm20proto::TpmaNvBits; -use crate::tpm20proto::TpmaObjectBits; -use crate::tpm20proto::MAX_DIGEST_BUFFER_SIZE; -use crate::tpm20proto::TPM20_RH_ENDORSEMENT; -use crate::tpm20proto::TPM20_RH_OWNER; -use crate::tpm20proto::TPM20_RH_PLATFORM; -use crate::tpm20proto::TPM20_RS_PW; -use crate::TpmRsa2kPublic; -use crate::TPM_AZURE_AIK_HANDLE; -use crate::TPM_GUEST_SECRET_HANDLE; -use crate::TPM_NV_INDEX_AIK_CERT; -use crate::TPM_NV_INDEX_ATTESTATION_REPORT; -use crate::TPM_RSA_SRK_HANDLE; +use crate::tpm20proto::protocol::common::CmdAuth; use inspect::InspectMut; use ms_tpm_20_ref::MsTpm20RefPlatform; use thiserror::Error; @@ -96,7 +96,9 @@ pub enum TpmHelperError { NoOwnerReadFlag(u32), #[error("nv index {0:#x} with invalid write permission")] InvalidWritePermission(u32), - #[error("input size {input_size} to nv write exceeds the allocated size {allocated_size} of nv index {nv_index:#x}")] + #[error( + "input size {input_size} to nv write exceeds the allocated size {allocated_size} of nv index {nv_index:#x}" + )] NvWriteInputTooLarge { nv_index: u32, input_size: usize, @@ -1604,14 +1606,14 @@ fn export_rsa_public(public: &Tpm2bPublic) -> Result KeyboardChannel { mod tests { use super::*; use input_core::mesh_input::input_pair; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::task::Spawn; use pal_async::task::Task; - use pal_async::DefaultDriver; use std::io::ErrorKind; use test_with_tracing::test; use tracing_helpers::ErrorValueExt; diff --git a/vm/devices/uidevices/src/mouse/mod.rs b/vm/devices/uidevices/src/mouse/mod.rs index 65cff7521a..8697d88823 100644 --- a/vm/devices/uidevices/src/mouse/mod.rs +++ b/vm/devices/uidevices/src/mouse/mod.rs @@ -18,13 +18,13 @@ use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::async_dgram::AsyncSend; use vmbus_async::async_dgram::AsyncSendExt; use vmbus_async::pipe::MessagePipe; +use vmbus_channel::RawAsyncChannel; use vmbus_channel::bus::ChannelType; use vmbus_channel::bus::OfferParams; use vmbus_channel::channel::ChannelOpenError; use vmbus_channel::gpadl_ring::GpadlRingMem; use vmbus_channel::simple::SaveRestoreSimpleVmbusDevice; use vmbus_channel::simple::SimpleVmbusDevice; -use vmbus_channel::RawAsyncChannel; use vmbus_ring::RingMem; use vmcore::save_restore::SavedStateRoot; use zerocopy::FromBytes; @@ -405,10 +405,10 @@ async fn post_mouse_packet( mod tests { use super::*; use input_core::mesh_input::input_pair; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::task::Spawn; use pal_async::task::Task; - use pal_async::DefaultDriver; use std::io::ErrorKind; use test_with_tracing::test; use vmbus_async::pipe::connected_message_pipes; diff --git a/vm/devices/uidevices/src/resolver.rs b/vm/devices/uidevices/src/resolver.rs index 42f78d1573..e18efe5e42 100644 --- a/vm/devices/uidevices/src/resolver.rs +++ b/vm/devices/uidevices/src/resolver.rs @@ -11,11 +11,11 @@ use thiserror::Error; use uidevices_resources::SynthKeyboardHandle; use uidevices_resources::SynthMouseHandle; use uidevices_resources::SynthVideoHandle; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::VmbusDeviceHandleKind; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; use vmbus_channel::simple::SimpleDeviceWrapper; diff --git a/vm/devices/uidevices/src/video/mod.rs b/vm/devices/uidevices/src/video/mod.rs index 3b678e42d2..e416acee00 100644 --- a/vm/devices/uidevices/src/video/mod.rs +++ b/vm/devices/uidevices/src/video/mod.rs @@ -19,13 +19,13 @@ use vmbus_async::async_dgram::AsyncRecvExt; use vmbus_async::async_dgram::AsyncSend; use vmbus_async::async_dgram::AsyncSendExt; use vmbus_async::pipe::MessagePipe; +use vmbus_channel::RawAsyncChannel; use vmbus_channel::bus::ChannelType; use vmbus_channel::bus::OfferParams; use vmbus_channel::channel::ChannelOpenError; use vmbus_channel::gpadl_ring::GpadlRingMem; use vmbus_channel::simple::SaveRestoreSimpleVmbusDevice; use vmbus_channel::simple::SimpleVmbusDevice; -use vmbus_channel::RawAsyncChannel; use vmcore::save_restore::SavedStateRoot; use zerocopy::FromBytes; use zerocopy::Immutable; diff --git a/vm/devices/uidevices_resources/src/lib.rs b/vm/devices/uidevices_resources/src/lib.rs index 0439d1260c..19c824eadc 100644 --- a/vm/devices/uidevices_resources/src/lib.rs +++ b/vm/devices/uidevices_resources/src/lib.rs @@ -6,12 +6,12 @@ #![forbid(unsafe_code)] use mesh::MeshPayload; +use vm_resource::Resource; +use vm_resource::ResourceId; use vm_resource::kind::FramebufferHandleKind; use vm_resource::kind::KeyboardInputHandleKind; use vm_resource::kind::MouseInputHandleKind; use vm_resource::kind::VmbusDeviceHandleKind; -use vm_resource::Resource; -use vm_resource::ResourceId; /// Handle for a synthetic keyboard device. #[derive(MeshPayload)] diff --git a/vm/devices/user_driver/src/backoff.rs b/vm/devices/user_driver/src/backoff.rs index 239f072f84..977a8a2bfc 100644 --- a/vm/devices/user_driver/src/backoff.rs +++ b/vm/devices/user_driver/src/backoff.rs @@ -5,7 +5,6 @@ use pal_async::driver::Driver; use pal_async::timer::PolledTimer; -use std::future::Future; use std::pin::Pin; use std::task::Context; use std::task::Poll; diff --git a/vm/devices/user_driver/src/emulated.rs b/vm/devices/user_driver/src/emulated.rs index fba6d9612c..43e73eb4bd 100644 --- a/vm/devices/user_driver/src/emulated.rs +++ b/vm/devices/user_driver/src/emulated.rs @@ -4,14 +4,14 @@ //! This implements the user-mode driver device traits using an emulated PCI //! device. +use crate::DeviceBacking; +use crate::DeviceRegisterIo; +use crate::DmaClient; use crate::interrupt::DeviceInterrupt; use crate::interrupt::DeviceInterruptSource; use crate::memory::MappedDmaTarget; use crate::memory::MemoryBlock; use crate::memory::PAGE_SIZE; -use crate::DeviceBacking; -use crate::DeviceRegisterIo; -use crate::DmaClient; use anyhow::Context; use chipset_device::mmio::MmioIntercept; use chipset_device::pci::PciConfigSpace; @@ -27,8 +27,8 @@ use pci_core::msi::MsiInterruptSet; use pci_core::msi::MsiInterruptTarget; use safeatomic::AtomicSliceOps; use std::ptr::NonNull; -use std::sync::atomic::AtomicU8; use std::sync::Arc; +use std::sync::atomic::AtomicU8; /// An emulated device. pub struct EmulatedDevice { diff --git a/vm/devices/user_driver/src/interrupt.rs b/vm/devices/user_driver/src/interrupt.rs index 7a989ca86c..3809b67a1f 100644 --- a/vm/devices/user_driver/src/interrupt.rs +++ b/vm/devices/user_driver/src/interrupt.rs @@ -5,11 +5,11 @@ use parking_lot::Mutex; use std::future::poll_fn; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering::Acquire; use std::sync::atomic::Ordering::Relaxed; use std::sync::atomic::Ordering::Release; -use std::sync::Arc; use std::task::Context; use std::task::Poll; use std::task::Waker; @@ -163,9 +163,9 @@ impl DeviceInterruptSource { #[cfg(test)] mod tests { use super::DeviceInterruptSource; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::task::Spawn; - use pal_async::DefaultDriver; #[async_test] async fn test_interrupt(driver: DefaultDriver) { diff --git a/vm/devices/user_driver/src/memory.rs b/vm/devices/user_driver/src/memory.rs index b6f3a3de88..d341ebd958 100644 --- a/vm/devices/user_driver/src/memory.rs +++ b/vm/devices/user_driver/src/memory.rs @@ -4,8 +4,8 @@ //! Traits and types for sharing host memory with the device. use safeatomic::AtomicSliceOps; -use std::sync::atomic::AtomicU8; use std::sync::Arc; +use std::sync::atomic::AtomicU8; use zerocopy::FromBytes; use zerocopy::Immutable; use zerocopy::IntoBytes; diff --git a/vm/devices/user_driver/src/page_allocator.rs b/vm/devices/user_driver/src/page_allocator.rs index 2e3eea2ed6..4de5d1ac6e 100644 --- a/vm/devices/user_driver/src/page_allocator.rs +++ b/vm/devices/user_driver/src/page_allocator.rs @@ -9,9 +9,9 @@ use crate::memory::MemoryBlock; use crate::memory::PAGE_SIZE; use crate::memory::PAGE_SIZE64; -use guestmem::ranges::PagedRange; use guestmem::GuestMemory; use guestmem::GuestMemoryError; +use guestmem::ranges::PagedRange; use inspect::Inspect; use parking_lot::Mutex; use std::sync::atomic::AtomicU8; diff --git a/vm/devices/user_driver/src/vfio.rs b/vm/devices/user_driver/src/vfio.rs index f6a2ace2bb..0bc6a7670b 100644 --- a/vm/devices/user_driver/src/vfio.rs +++ b/vm/devices/user_driver/src/vfio.rs @@ -6,11 +6,11 @@ #![cfg(target_os = "linux")] #![cfg(feature = "vfio")] -use crate::interrupt::DeviceInterrupt; -use crate::interrupt::DeviceInterruptSource; use crate::DeviceBacking; use crate::DeviceRegisterIo; use crate::DmaClient; +use crate::interrupt::DeviceInterrupt; +use crate::interrupt::DeviceInterruptSource; use anyhow::Context; use futures::FutureExt; use futures_concurrency::future::Race; @@ -23,9 +23,9 @@ use pal_event::Event; use std::os::fd::AsFd; use std::os::unix::fs::FileExt; use std::path::Path; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering::Relaxed; -use std::sync::Arc; use std::time::Duration; use uevent::UeventListener; use vfio_bindings::bindings::vfio::VFIO_PCI_CONFIG_REGION_INDEX; diff --git a/vm/devices/user_driver/vfio_sys/src/lib.rs b/vm/devices/user_driver/vfio_sys/src/lib.rs index f47c56c4c4..77dbc7f2f1 100644 --- a/vm/devices/user_driver/vfio_sys/src/lib.rs +++ b/vm/devices/user_driver/vfio_sys/src/lib.rs @@ -16,27 +16,27 @@ use std::io::BufRead; use std::io::BufReader; use std::os::unix::prelude::*; use std::path::Path; +use vfio_bindings::bindings::vfio::VFIO_IRQ_SET_ACTION_TRIGGER; +use vfio_bindings::bindings::vfio::VFIO_IRQ_SET_DATA_EVENTFD; +use vfio_bindings::bindings::vfio::VFIO_IRQ_SET_DATA_NONE; +use vfio_bindings::bindings::vfio::VFIO_PCI_MSIX_IRQ_INDEX; use vfio_bindings::bindings::vfio::vfio_device_info; use vfio_bindings::bindings::vfio::vfio_group_status; use vfio_bindings::bindings::vfio::vfio_irq_info; use vfio_bindings::bindings::vfio::vfio_irq_set; use vfio_bindings::bindings::vfio::vfio_region_info; -use vfio_bindings::bindings::vfio::VFIO_IRQ_SET_ACTION_TRIGGER; -use vfio_bindings::bindings::vfio::VFIO_IRQ_SET_DATA_EVENTFD; -use vfio_bindings::bindings::vfio::VFIO_IRQ_SET_DATA_NONE; -use vfio_bindings::bindings::vfio::VFIO_PCI_MSIX_IRQ_INDEX; mod ioctl { use nix::request_code_none; use std::os::raw::c_char; use std::os::raw::c_int; + use vfio_bindings::bindings::vfio::VFIO_BASE; + use vfio_bindings::bindings::vfio::VFIO_TYPE; use vfio_bindings::bindings::vfio::vfio_device_info; use vfio_bindings::bindings::vfio::vfio_group_status; use vfio_bindings::bindings::vfio::vfio_irq_info; use vfio_bindings::bindings::vfio::vfio_irq_set; use vfio_bindings::bindings::vfio::vfio_region_info; - use vfio_bindings::bindings::vfio::VFIO_BASE; - use vfio_bindings::bindings::vfio::VFIO_TYPE; const VFIO_PRIVATE_BASE: u32 = 200; diff --git a/vm/devices/vga/src/emu.rs b/vm/devices/vga/src/emu.rs index 9c6d6915c9..f1a93d6ffd 100644 --- a/vm/devices/vga/src/emu.rs +++ b/vm/devices/vga/src/emu.rs @@ -9,13 +9,13 @@ use crate::render::RenderState; use crate::render::TextRenderState; use crate::spec; use crate::spec::CrtControlReg; +use crate::spec::VGA_FUNCTION_SELECT_AND; +use crate::spec::VGA_FUNCTION_SELECT_NORMAL; +use crate::spec::VGA_FUNCTION_SELECT_OR; use crate::spec::VgaAttribReg; use crate::spec::VgaGraphicsReg; use crate::spec::VgaPort; use crate::spec::VgaSequencerReg; -use crate::spec::VGA_FUNCTION_SELECT_AND; -use crate::spec::VGA_FUNCTION_SELECT_NORMAL; -use crate::spec::VGA_FUNCTION_SELECT_OR; use chipset_device::io::IoError; use chipset_device::io::IoResult; use framebuffer::FramebufferLocalControl; diff --git a/vm/devices/vga/src/emu/bluescreen.rs b/vm/devices/vga/src/emu/bluescreen.rs index 9cf6f520ad..9152c08326 100644 --- a/vm/devices/vga/src/emu/bluescreen.rs +++ b/vm/devices/vga/src/emu/bluescreen.rs @@ -37,11 +37,7 @@ impl Emulator { fn get_crt_port(&mut self) -> u16 { let data = self.emulate_in(0x3CC); - if data & 1 != 0 { - 0x3D4 - } else { - 0x3B4 - } + if data & 1 != 0 { 0x3D4 } else { 0x3B4 } } fn turn_screen_on_off(&mut self, on: bool) { @@ -184,11 +180,7 @@ impl Emulator { let data = registers[0]; *registers = ®isters[1..]; self.emulate_out(0x3C2, data); - if data & 1 != 0 { - 0x3DA - } else { - 0x3BA - } + if data & 1 != 0 { 0x3DA } else { 0x3BA } } fn program_attribute(&mut self, input_status1_port: u16, registers: &mut &[u8]) { diff --git a/vm/devices/vga/src/lib.rs b/vm/devices/vga/src/lib.rs index c85cb86e17..4c11221177 100644 --- a/vm/devices/vga/src/lib.rs +++ b/vm/devices/vga/src/lib.rs @@ -22,11 +22,11 @@ mod render; mod spec; mod text_mode; +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::pci::PciConfigSpace; use chipset_device::pio::PortIoIntercept; -use chipset_device::ChipsetDevice; use framebuffer::FramebufferLocalControl; use guestmem::MapRom; use inspect::InspectMut; diff --git a/vm/devices/vga_proxy/src/lib.rs b/vm/devices/vga_proxy/src/lib.rs index b67dab51c1..967b4a5561 100644 --- a/vm/devices/vga_proxy/src/lib.rs +++ b/vm/devices/vga_proxy/src/lib.rs @@ -5,18 +5,17 @@ #![expect(missing_docs)] -use chipset_device::io::deferred::defer_read; -use chipset_device::io::deferred::defer_write; -use chipset_device::io::deferred::DeferredRead; -use chipset_device::io::deferred::DeferredWrite; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; +use chipset_device::io::deferred::DeferredRead; +use chipset_device::io::deferred::DeferredWrite; +use chipset_device::io::deferred::defer_read; +use chipset_device::io::deferred::defer_write; use chipset_device::pci::PciConfigSpace; use chipset_device::pio::PortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use inspect::InspectMut; -use std::future::Future; use std::ops::RangeInclusive; use std::pin::Pin; use std::sync::Arc; diff --git a/vm/devices/video_core/src/lib.rs b/vm/devices/video_core/src/lib.rs index d708df57fd..1a6817b8c3 100644 --- a/vm/devices/video_core/src/lib.rs +++ b/vm/devices/video_core/src/lib.rs @@ -6,11 +6,11 @@ #![forbid(unsafe_code)] use inspect::Inspect; -use mesh::payload::Protobuf; use mesh::MeshPayload; -use vm_resource::kind::FramebufferHandleKind; +use mesh::payload::Protobuf; use vm_resource::CanResolveTo; use vm_resource::ResourceId; +use vm_resource::kind::FramebufferHandleKind; impl CanResolveTo for FramebufferHandleKind { type Input<'a> = (); diff --git a/vm/devices/virtio/virtio/src/common.rs b/vm/devices/virtio/virtio/src/common.rs index 3c1ebeeb1f..9c1ab70b95 100644 --- a/vm/devices/virtio/virtio/src/common.rs +++ b/vm/devices/virtio/virtio/src/common.rs @@ -13,18 +13,18 @@ use guestmem::DoorbellRegistration; use guestmem::GuestMemory; use guestmem::GuestMemoryError; use guestmem::MappedMemoryRegion; +use pal_async::DefaultPool; use pal_async::driver::Driver; use pal_async::task::Spawn; use pal_async::wait::PolledWait; -use pal_async::DefaultPool; use pal_event::Event; use parking_lot::Mutex; use std::io::Error; use std::pin::Pin; use std::sync::Arc; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; use task_control::AsyncRun; use task_control::StopTask; use task_control::TaskControl; @@ -611,21 +611,21 @@ impl Drop for LegacyWrapper { #[cfg(test)] mod tests { use super::*; + use crate::PciInterruptModel; use crate::spec::pci::*; use crate::spec::queue::*; use crate::spec::*; use crate::transport::VirtioMmioDevice; use crate::transport::VirtioPciDevice; - use crate::PciInterruptModel; use chipset_device::mmio::ExternallyManagedMmioIntercepts; use chipset_device::mmio::MmioIntercept; use chipset_device::pci::PciConfigSpace; use futures::StreamExt; use guestmem::GuestMemoryAccess; use guestmem::GuestMemoryBackingError; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::timer::PolledTimer; - use pal_async::DefaultDriver; use pci_core::msi::MsiInterruptSet; use pci_core::spec::caps::CapabilityId; use pci_core::spec::cfg_space; @@ -636,8 +636,8 @@ mod tests { use std::ptr::NonNull; use std::time::Duration; use test_with_tracing::test; - use vmcore::line_interrupt::test_helpers::TestLineInterruptTarget; use vmcore::line_interrupt::LineInterrupt; + use vmcore::line_interrupt::test_helpers::TestLineInterruptTarget; use vmcore::vm_task::SingleDriverBackend; use vmcore::vm_task::VmTaskDriverSource; @@ -686,7 +686,9 @@ mod tests { { if end > next { let next_end = next + next_data.len() as u64; - panic!("overlapping memory map: {address:#x}..{end:#x} > {next:#x}..={next_end:#x}"); + panic!( + "overlapping memory map: {address:#x}..{end:#x} > {next:#x}..={next_end:#x}" + ); } if end == next && next_writable == writable { data.extend(next_data.as_slice()); @@ -699,7 +701,9 @@ mod tests { { let prev_end = prev + prev_data.len() as u64; if prev_end > address { - panic!("overlapping memory map: {prev:#x}..{prev_end:#x} > {address:#x}..={end:#x}"); + panic!( + "overlapping memory map: {prev:#x}..{prev_end:#x} > {address:#x}..={end:#x}" + ); } if prev_end == address && prev_writable == writable { prev_data.extend_from_slice(&data); diff --git a/vm/devices/virtio/virtio/src/resolve.rs b/vm/devices/virtio/virtio/src/resolve.rs index e0e0963415..88d6413c83 100644 --- a/vm/devices/virtio/virtio/src/resolve.rs +++ b/vm/devices/virtio/virtio/src/resolve.rs @@ -5,8 +5,8 @@ use crate::VirtioDevice; use guestmem::GuestMemory; -use vm_resource::kind::VirtioDeviceHandle; use vm_resource::CanResolveTo; +use vm_resource::kind::VirtioDeviceHandle; use vmcore::vm_task::VmTaskDriverSource; impl CanResolveTo for VirtioDeviceHandle { diff --git a/vm/devices/virtio/virtio/src/resolver.rs b/vm/devices/virtio/virtio/src/resolver.rs index b1c962cd72..f418ad1237 100644 --- a/vm/devices/virtio/virtio/src/resolver.rs +++ b/vm/devices/virtio/virtio/src/resolver.rs @@ -3,19 +3,19 @@ //! Resolver for virtio device infrastructure. -use crate::resolve::VirtioResolveInput; use crate::PciInterruptModel; use crate::VirtioPciDevice; +use crate::resolve::VirtioResolveInput; use async_trait::async_trait; use pci_resources::ResolvePciDeviceHandleParams; use pci_resources::ResolvedPciDevice; use thiserror::Error; use virtio_resources::VirtioPciDeviceHandle; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::PciDeviceHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResolveError; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::PciDeviceHandleKind; declare_static_async_resolver! { VirtioPciResolver, diff --git a/vm/devices/virtio/virtio/src/transport/mmio.rs b/vm/devices/virtio/virtio/src/transport/mmio.rs index c93f550ff5..6bb6e9392d 100644 --- a/vm/devices/virtio/virtio/src/transport/mmio.rs +++ b/vm/devices/virtio/virtio/src/transport/mmio.rs @@ -1,19 +1,19 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::queue::QueueParams; -use crate::spec::*; +use crate::QUEUE_MAX_SIZE; use crate::QueueResources; use crate::Resources; use crate::VirtioDevice; use crate::VirtioDoorbells; -use crate::QUEUE_MAX_SIZE; +use crate::queue::QueueParams; +use crate::spec::*; +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; -use chipset_device::ChipsetDevice; +use device_emulators::ReadWriteRequestType; use device_emulators::read_as_u32_chunks; use device_emulators::write_as_u32_chunks; -use device_emulators::ReadWriteRequestType; use guestmem::DoorbellRegistration; use inspect::InspectMut; use parking_lot::Mutex; diff --git a/vm/devices/virtio/virtio/src/transport/pci.rs b/vm/devices/virtio/virtio/src/transport/pci.rs index 2aa65a5022..635f897e0d 100644 --- a/vm/devices/virtio/virtio/src/transport/pci.rs +++ b/vm/devices/virtio/virtio/src/transport/pci.rs @@ -4,30 +4,31 @@ //! PCI transport for virtio devices use self::capabilities::*; -use crate::queue::QueueParams; -use crate::spec::pci::*; -use crate::spec::*; +use crate::QUEUE_MAX_SIZE; use crate::QueueResources; use crate::Resources; use crate::VirtioDevice; use crate::VirtioDoorbells; -use crate::QUEUE_MAX_SIZE; +use crate::queue::QueueParams; +use crate::spec::pci::*; +use crate::spec::*; +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; use chipset_device::pci::PciConfigSpace; -use chipset_device::ChipsetDevice; +use device_emulators::ReadWriteRequestType; use device_emulators::read_as_u32_chunks; use device_emulators::write_as_u32_chunks; -use device_emulators::ReadWriteRequestType; use guestmem::DoorbellRegistration; use guestmem::MappedMemoryRegion; use guestmem::MemoryMapper; use inspect::InspectMut; use parking_lot::Mutex; -use pci_core::capabilities::msix::MsixEmulator; +use pci_core::PciInterruptPin; use pci_core::capabilities::PciCapability; use pci_core::capabilities::ReadOnlyCapability; +use pci_core::capabilities::msix::MsixEmulator; use pci_core::cfg_space_emu::BarMemoryKind; use pci_core::cfg_space_emu::ConfigSpaceType0Emulator; use pci_core::cfg_space_emu::DeviceBars; @@ -37,7 +38,6 @@ use pci_core::spec::hwid::ClassCode; use pci_core::spec::hwid::HardwareIds; use pci_core::spec::hwid::ProgrammingInterface; use pci_core::spec::hwid::Subclass; -use pci_core::PciInterruptPin; use std::io; use std::sync::Arc; use vmcore::device_state::ChangeDeviceState; diff --git a/vm/devices/virtio/virtio_net/src/buffers.rs b/vm/devices/virtio/virtio_net/src/buffers.rs index 08a485d90c..3733e5c5ae 100644 --- a/vm/devices/virtio/virtio_net/src/buffers.rs +++ b/vm/devices/virtio/virtio_net/src/buffers.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::header_size; use crate::VirtioNetHeader; +use crate::header_size; use guestmem::GuestMemory; use net_backend::BufferAccess; use net_backend::RxBufferSegment; diff --git a/vm/devices/virtio/virtio_net/src/resolver.rs b/vm/devices/virtio/virtio_net/src/resolver.rs index 23b4a24b66..3dff91af52 100644 --- a/vm/devices/virtio/virtio_net/src/resolver.rs +++ b/vm/devices/virtio/virtio_net/src/resolver.rs @@ -9,10 +9,10 @@ use net_backend::resolve::ResolveEndpointParams; use virtio::resolve::ResolvedVirtioDevice; use virtio::resolve::VirtioResolveInput; use virtio_resources::net::VirtioNetHandle; -use vm_resource::declare_static_async_resolver; -use vm_resource::kind::VirtioDeviceHandle; use vm_resource::AsyncResolveResource; use vm_resource::ResourceResolver; +use vm_resource::declare_static_async_resolver; +use vm_resource::kind::VirtioDeviceHandle; /// Resolver for virtio-pmem devices. pub struct VirtioNetResolver; diff --git a/vm/devices/virtio/virtio_p9/src/resolver.rs b/vm/devices/virtio/virtio_p9/src/resolver.rs index e96fa00271..d421ba04c6 100644 --- a/vm/devices/virtio/virtio_p9/src/resolver.rs +++ b/vm/devices/virtio/virtio_p9/src/resolver.rs @@ -5,13 +5,13 @@ use crate::VirtioPlan9Device; use plan9::Plan9FileSystem; +use virtio::LegacyWrapper; use virtio::resolve::ResolvedVirtioDevice; use virtio::resolve::VirtioResolveInput; -use virtio::LegacyWrapper; use virtio_resources::p9::VirtioPlan9Handle; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::VirtioDeviceHandle; -use vm_resource::ResolveResource; /// Resolver for virtio-9p devices. pub struct VirtioPlan9Resolver; diff --git a/vm/devices/virtio/virtio_pmem/src/resolver.rs b/vm/devices/virtio/virtio_pmem/src/resolver.rs index 6994817e1b..e299685519 100644 --- a/vm/devices/virtio/virtio_pmem/src/resolver.rs +++ b/vm/devices/virtio/virtio_pmem/src/resolver.rs @@ -7,9 +7,9 @@ use crate::Device; use virtio::resolve::ResolvedVirtioDevice; use virtio::resolve::VirtioResolveInput; use virtio_resources::pmem::VirtioPmemHandle; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::VirtioDeviceHandle; -use vm_resource::ResolveResource; /// Resolver for virtio-pmem devices. pub struct VirtioPmemResolver; diff --git a/vm/devices/virtio/virtio_resources/src/lib.rs b/vm/devices/virtio/virtio_resources/src/lib.rs index 343a91330e..e448d812e2 100644 --- a/vm/devices/virtio/virtio_resources/src/lib.rs +++ b/vm/devices/virtio/virtio_resources/src/lib.rs @@ -10,10 +10,10 @@ #![forbid(unsafe_code)] use mesh::MeshPayload; -use vm_resource::kind::PciDeviceHandleKind; -use vm_resource::kind::VirtioDeviceHandle; use vm_resource::Resource; use vm_resource::ResourceId; +use vm_resource::kind::PciDeviceHandleKind; +use vm_resource::kind::VirtioDeviceHandle; /// A resource for mapping a virtio device as a PCI device. #[derive(MeshPayload)] @@ -25,8 +25,8 @@ impl ResourceId for VirtioPciDeviceHandle { pub mod p9 { use mesh::MeshPayload; - use vm_resource::kind::VirtioDeviceHandle; use vm_resource::ResourceId; + use vm_resource::kind::VirtioDeviceHandle; #[derive(MeshPayload)] pub struct VirtioPlan9Handle { @@ -42,8 +42,8 @@ pub mod p9 { pub mod fs { use mesh::MeshPayload; - use vm_resource::kind::VirtioDeviceHandle; use vm_resource::ResourceId; + use vm_resource::kind::VirtioDeviceHandle; #[derive(MeshPayload)] pub struct VirtioFsHandle { @@ -69,8 +69,8 @@ pub mod fs { pub mod pmem { use mesh::MeshPayload; - use vm_resource::kind::VirtioDeviceHandle; use vm_resource::ResourceId; + use vm_resource::kind::VirtioDeviceHandle; #[derive(MeshPayload)] pub struct VirtioPmemHandle { @@ -85,10 +85,10 @@ pub mod pmem { pub mod net { use mesh::MeshPayload; use net_backend_resources::mac_address::MacAddress; - use vm_resource::kind::NetEndpointHandleKind; - use vm_resource::kind::VirtioDeviceHandle; use vm_resource::Resource; use vm_resource::ResourceId; + use vm_resource::kind::NetEndpointHandleKind; + use vm_resource::kind::VirtioDeviceHandle; #[derive(MeshPayload)] pub struct VirtioNetHandle { diff --git a/vm/devices/virtio/virtio_serial/src/lib.rs b/vm/devices/virtio/virtio_serial/src/lib.rs index a72a284447..8338e3d0bf 100644 --- a/vm/devices/virtio/virtio_serial/src/lib.rs +++ b/vm/devices/virtio/virtio_serial/src/lib.rs @@ -346,30 +346,32 @@ impl VirtioSerialControlPort { let read_fn = port_read_fn(port, mem); std::thread::Builder::new() .name("virtio control".into()) - .spawn(move || loop { - let data = (read_fn)(); - if data.is_empty() { - break; - } - let message = VirtioSerialControl::from_bytes(&data); - if message.is_err() { - continue; - } + .spawn(move || { + loop { + let data = (read_fn)(); + if data.is_empty() { + break; + } + let message = VirtioSerialControl::from_bytes(&data); + if message.is_err() { + continue; + } - let message = message.unwrap(); - match message.event { - VIRTIO_CONSOLE_DEVICE_READY => { - if message.value != 0 { - (ready_callback)() + let message = message.unwrap(); + match message.event { + VIRTIO_CONSOLE_DEVICE_READY => { + if message.value != 0 { + (ready_callback)() + } } + VIRTIO_CONSOLE_PORT_READY => (), + _ => tracing::warn!( + event = message.event, + port_number = message.port_number, + value = message.value, + "[SERIAL] Unhandled control event", + ), } - VIRTIO_CONSOLE_PORT_READY => (), - _ => tracing::warn!( - event = message.event, - port_number = message.port_number, - value = message.value, - "[SERIAL] Unhandled control event", - ), } }) .unwrap() diff --git a/vm/devices/virtio/virtiofs/src/file.rs b/vm/devices/virtio/virtiofs/src/file.rs index 19c73aba8d..d52bc094a7 100644 --- a/vm/devices/virtio/virtiofs/src/file.rs +++ b/vm/devices/virtio/virtiofs/src/file.rs @@ -3,10 +3,10 @@ use crate::inode::VirtioFsInode; use crate::util; +use fuse::DirEntryWriter; use fuse::protocol::fuse_attr; use fuse::protocol::fuse_entry_out; use fuse::protocol::fuse_setattr_in; -use fuse::DirEntryWriter; use lxutil::LxFile; use parking_lot::RwLock; use std::sync::Arc; diff --git a/vm/devices/virtio/virtiofs/src/inode.rs b/vm/devices/virtio/virtiofs/src/inode.rs index 57e15fdfcd..6a39460cd1 100644 --- a/vm/devices/virtio/virtiofs/src/inode.rs +++ b/vm/devices/virtio/virtiofs/src/inode.rs @@ -11,9 +11,9 @@ use lxutil::LxVolume; use lxutil::PathBufExt; use parking_lot::RwLock; use std::path::PathBuf; +use std::sync::Arc; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; /// Implements inode callbacks for virtio-fs. pub struct VirtioFsInode { diff --git a/vm/devices/virtio/virtiofs/src/lib.rs b/vm/devices/virtio/virtiofs/src/lib.rs index a5d6737155..9f0012a6b5 100644 --- a/vm/devices/virtio/virtiofs/src/lib.rs +++ b/vm/devices/virtio/virtiofs/src/lib.rs @@ -22,8 +22,8 @@ use fuse::*; use inode::VirtioFsInode; pub use lxutil::LxVolumeOptions; use parking_lot::RwLock; -use std::collections::hash_map::Entry; use std::collections::HashMap; +use std::collections::hash_map::Entry; use std::path::Path; use std::path::PathBuf; use std::sync::Arc; diff --git a/vm/devices/virtio/virtiofs/src/resolver.rs b/vm/devices/virtio/virtiofs/src/resolver.rs index 3463864a57..67f94a3f00 100644 --- a/vm/devices/virtio/virtiofs/src/resolver.rs +++ b/vm/devices/virtio/virtiofs/src/resolver.rs @@ -3,16 +3,16 @@ //! Defines the resource resolver for virtiofs devices. -use crate::virtio::VirtioFsDevice; use crate::VirtioFs; +use crate::virtio::VirtioFsDevice; use lxutil::LxVolumeOptions; use virtio::resolve::ResolvedVirtioDevice; use virtio::resolve::VirtioResolveInput; use virtio_resources::fs::VirtioFsBackend; use virtio_resources::fs::VirtioFsHandle; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::VirtioDeviceHandle; -use vm_resource::ResolveResource; /// Resolver for virtiofs devices. pub struct VirtioFsResolver; diff --git a/vm/devices/virtio/virtiofs/src/section.rs b/vm/devices/virtio/virtiofs/src/section.rs index 82472bd47f..782bfcbd6b 100644 --- a/vm/devices/virtio/virtiofs/src/section.rs +++ b/vm/devices/virtio/virtiofs/src/section.rs @@ -8,25 +8,25 @@ #![expect(unsafe_code)] use crate::HandleMap; -use fuse::protocol::FUSE_SETUPMAPPING_FLAG_WRITE; use fuse::Mapper; +use fuse::protocol::FUSE_SETUPMAPPING_FLAG_WRITE; use lxutil::PathExt; use ntapi::ntmmapi::NtCreateSection; use ntapi::ntmmapi::NtOpenSection; use ntapi::ntmmapi::NtQuerySection; -use ntapi::ntmmapi::SectionBasicInformation; use ntapi::ntmmapi::SECTION_BASIC_INFORMATION; +use ntapi::ntmmapi::SectionBasicInformation; use ntapi::ntobapi::DIRECTORY_TRAVERSE; use ntapi::winapi::shared::ntdef::LARGE_INTEGER; use ntapi::winapi::um::winnt::PAGE_READWRITE; +use ntapi::winapi::um::winnt::SEC_COMMIT; use ntapi::winapi::um::winnt::SECTION_MAP_READ; use ntapi::winapi::um::winnt::SECTION_MAP_WRITE; use ntapi::winapi::um::winnt::SECTION_QUERY; -use ntapi::winapi::um::winnt::SEC_COMMIT; -use pal::windows::chk_status; -use pal::windows::open_object_directory; use pal::windows::ObjectAttributes; use pal::windows::UnicodeString; +use pal::windows::chk_status; +use pal::windows::open_object_directory; use parking_lot::Mutex; use parking_lot::RwLock; use std::io; diff --git a/vm/devices/virtio/virtiofs/src/virtio_util.rs b/vm/devices/virtio/virtiofs/src/virtio_util.rs index 9ff873f7fe..e7389b766d 100644 --- a/vm/devices/virtio/virtiofs/src/virtio_util.rs +++ b/vm/devices/virtio/virtiofs/src/virtio_util.rs @@ -6,8 +6,8 @@ use std::cmp; use std::io; use std::io::Read; use std::io::Write; -use virtio::queue::VirtioQueuePayload; use virtio::VirtioQueueCallbackWork; +use virtio::queue::VirtioQueuePayload; /// An implementation of `Read` that allows reading data from a virtio payload that may use /// multiple buffers. diff --git a/vm/devices/vmbus/vmbfs/src/protocol.rs b/vm/devices/vmbus/vmbfs/src/protocol.rs index e6babb58ad..43c0d04f12 100644 --- a/vm/devices/vmbus/vmbfs/src/protocol.rs +++ b/vm/devices/vmbus/vmbfs/src/protocol.rs @@ -6,11 +6,11 @@ use bitfield_struct::bitfield; use guid::Guid; use open_enum::open_enum; -use zerocopy::little_endian::U64 as u64_le; use zerocopy::FromBytes; use zerocopy::Immutable; use zerocopy::IntoBytes; use zerocopy::KnownLayout; +use zerocopy::little_endian::U64 as u64_le; pub const INTERFACE_TYPE: Guid = guid::guid!("c376c1c3-d276-48d2-90a9-c04748072c60"); pub const IMC_INSTANCE: Guid = guid::guid!("c4e5e7d1-d748-4afc-979d-683167910a55"); diff --git a/vm/devices/vmbus/vmbfs/src/resolver.rs b/vm/devices/vmbus/vmbfs/src/resolver.rs index e3df2cfaf4..e163662bfe 100644 --- a/vm/devices/vmbus/vmbfs/src/resolver.rs +++ b/vm/devices/vmbus/vmbfs/src/resolver.rs @@ -3,12 +3,12 @@ //! Provides a resolver for the vmbfs device. -use crate::single_file_backing::VmbfsSingleFileBacking; use crate::VmbfsDevice; +use crate::single_file_backing::VmbfsSingleFileBacking; use std::convert::Infallible; +use vm_resource::ResolveResource; use vm_resource::declare_static_resolver; use vm_resource::kind::VmbusDeviceHandleKind; -use vm_resource::ResolveResource; use vmbfs_resources::VmbfsImcDeviceHandle; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; use vmbus_channel::resources::ResolvedVmbusDevice; diff --git a/vm/devices/vmbus/vmbfs_resources/src/lib.rs b/vm/devices/vmbus/vmbfs_resources/src/lib.rs index 39b24cb917..fce42ae06a 100644 --- a/vm/devices/vmbus/vmbfs_resources/src/lib.rs +++ b/vm/devices/vmbus/vmbfs_resources/src/lib.rs @@ -7,8 +7,8 @@ use mesh::MeshPayload; use std::fs::File; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::ResourceId; +use vm_resource::kind::VmbusDeviceHandleKind; /// A handle to a vmbfs device for providing an IMC hive to the Windows boot /// loader. diff --git a/vm/devices/vmbus/vmbus_async/src/async_dgram.rs b/vm/devices/vmbus/vmbus_async/src/async_dgram.rs index a7f4e292bb..8cdb975a08 100644 --- a/vm/devices/vmbus/vmbus_async/src/async_dgram.rs +++ b/vm/devices/vmbus/vmbus_async/src/async_dgram.rs @@ -11,14 +11,13 @@ //! [`futures::AsyncRead`]), where one send can be split into multiple receives, //! or multiple sends can be combined into one receive. -use std::future::Future; use std::io; use std::io::IoSlice; use std::io::IoSliceMut; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; use thiserror::Error; /// Trait implemented by types that can receive datagrams. diff --git a/vm/devices/vmbus/vmbus_async/src/pipe.rs b/vm/devices/vmbus/vmbus_async/src/pipe.rs index 48dfa1bc2f..871f3a39e8 100644 --- a/vm/devices/vmbus/vmbus_async/src/pipe.rs +++ b/vm/devices/vmbus/vmbus_async/src/pipe.rs @@ -21,12 +21,12 @@ use std::io; use std::io::IoSlice; use std::io::IoSliceMut; use std::pin::Pin; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; use thiserror::Error; -use vmbus_channel::connected_async_channels; use vmbus_channel::RawAsyncChannel; +use vmbus_channel::connected_async_channels; use vmbus_ring as ring; use vmbus_ring::FlatRingMem; use vmbus_ring::RingMem; @@ -773,11 +773,12 @@ impl AsyncRecv for MessagePipe { impl AsyncSend for MessagePipe { fn poll_send(&mut self, cx: &mut Context<'_>, bufs: &[IoSlice<'_>]) -> Poll> { - ready!(self - .0 - .write - .writer(&self.0.core) - .poll_write_message(cx, bufs))?; + ready!( + self.0 + .write + .writer(&self.0.core) + .poll_write_message(cx, bufs) + )?; Poll::Ready(Ok(())) } @@ -911,9 +912,9 @@ mod tests { use crate::pipe::connected_message_pipes; use futures::AsyncReadExt; use futures::AsyncWriteExt; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::timer::PolledTimer; - use pal_async::DefaultDriver; use std::io::ErrorKind; use std::time::Duration; use zerocopy::IntoBytes; diff --git a/vm/devices/vmbus/vmbus_async/src/queue.rs b/vm/devices/vmbus/vmbus_async/src/queue.rs index 85a701b7ed..d7380b02ef 100644 --- a/vm/devices/vmbus/vmbus_async/src/queue.rs +++ b/vm/devices/vmbus/vmbus_async/src/queue.rs @@ -9,31 +9,30 @@ use super::core::ReadState; use super::core::WriteState; use crate::core::PollError; use futures::FutureExt; -use guestmem::ranges::PagedRange; use guestmem::AccessError; use guestmem::MemoryRead; use guestmem::MemoryWrite; +use guestmem::ranges::PagedRange; use inspect::Inspect; use ring::OutgoingPacketType; use ring::TransferPageRange; use smallvec::smallvec; use std::future::poll_fn; -use std::future::Future; use std::ops::Deref; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; use thiserror::Error; -use vmbus_channel::connected_async_channels; use vmbus_channel::RawAsyncChannel; +use vmbus_channel::connected_async_channels; use vmbus_ring as ring; -use vmbus_ring::gparange::zeroed_gpn_list; -use vmbus_ring::gparange::GpnList; -use vmbus_ring::gparange::MultiPagedRangeBuf; use vmbus_ring::FlatRingMem; use vmbus_ring::IncomingPacketType; use vmbus_ring::IncomingRing; use vmbus_ring::RingMem; +use vmbus_ring::gparange::GpnList; +use vmbus_ring::gparange::MultiPagedRangeBuf; +use vmbus_ring::gparange::zeroed_gpn_list; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::IntoBytes; @@ -756,10 +755,10 @@ pub fn connected_queues(ring_size: usize) -> (Queue, Queue for VmbusDeviceHandleKind { diff --git a/vm/devices/vmbus/vmbus_channel/src/simple.rs b/vm/devices/vmbus/vmbus_channel/src/simple.rs index e583f17a4b..cbc90ef09a 100644 --- a/vm/devices/vmbus/vmbus_channel/src/simple.rs +++ b/vm/devices/vmbus/vmbus_channel/src/simple.rs @@ -11,19 +11,19 @@ //! * The VMBus device needs to spawn an asynchronous task to handle a channel //! when the channel is opened. +use crate::RawAsyncChannel; use crate::bus::OfferParams; use crate::bus::OpenRequest; use crate::bus::ParentBus; -use crate::channel::offer_channel; use crate::channel::ChannelHandle; use crate::channel::ChannelOpenError; use crate::channel::DeviceResources; use crate::channel::RestoreControl; use crate::channel::SaveRestoreVmbusDevice; use crate::channel::VmbusDevice; -use crate::gpadl_ring::gpadl_channel; +use crate::channel::offer_channel; use crate::gpadl_ring::GpadlRingMem; -use crate::RawAsyncChannel; +use crate::gpadl_ring::gpadl_channel; use async_trait::async_trait; use guestmem::GuestMemory; use inspect::Inspect; diff --git a/vm/devices/vmbus/vmbus_client/src/hvsock.rs b/vm/devices/vmbus/vmbus_client/src/hvsock.rs index dd576e9f7e..42a65ef540 100644 --- a/vm/devices/vmbus/vmbus_client/src/hvsock.rs +++ b/vm/devices/vmbus/vmbus_client/src/hvsock.rs @@ -4,8 +4,8 @@ use crate::OfferInfo; use inspect::Inspect; use mesh::rpc::Rpc; -use vmbus_core::protocol; use vmbus_core::HvsockConnectRequest; +use vmbus_core::protocol; /// Tracks guest-to-host hvsocket requests that the host has not responded to yet. #[derive(Inspect)] diff --git a/vm/devices/vmbus/vmbus_client/src/lib.rs b/vm/devices/vmbus/vmbus_client/src/lib.rs index 6c87efce62..a5c3ae22e0 100644 --- a/vm/devices/vmbus/vmbus_client/src/lib.rs +++ b/vm/devices/vmbus/vmbus_client/src/lib.rs @@ -10,10 +10,10 @@ pub mod saved_state; pub use self::saved_state::SavedState; use anyhow::Context as _; use anyhow::Result; -use futures::future::OptionFuture; -use futures::stream::SelectAll; use futures::FutureExt; use futures::StreamExt; +use futures::future::OptionFuture; +use futures::stream::SelectAll; use guid::Guid; use inspect::Inspect; use mesh::rpc::FailableRpc; @@ -26,12 +26,11 @@ use std::collections::HashMap; use std::collections::VecDeque; use std::convert::TryInto; use std::future::poll_fn; -use std::future::Future; use std::pin::pin; use std::sync::Arc; -use std::task::ready; use std::task::Context; use std::task::Poll; +use std::task::ready; use thiserror::Error; use vmbus_async::async_dgram::AsyncRecv; use vmbus_async::async_dgram::AsyncRecvExt; @@ -39,6 +38,11 @@ use vmbus_channel::bus::GpadlRequest; use vmbus_channel::bus::ModifyRequest; use vmbus_channel::bus::OpenData; use vmbus_channel::gpadl::GpadlId; +use vmbus_core::HvsockConnectRequest; +use vmbus_core::MonitorPageGpas; +use vmbus_core::OutgoingMessage; +use vmbus_core::TaggedStream; +use vmbus_core::VersionInfo; use vmbus_core::protocol; use vmbus_core::protocol::ChannelId; use vmbus_core::protocol::ConnectionState; @@ -46,11 +50,6 @@ use vmbus_core::protocol::FeatureFlags; use vmbus_core::protocol::Message; use vmbus_core::protocol::OpenChannelFlags; use vmbus_core::protocol::Version; -use vmbus_core::HvsockConnectRequest; -use vmbus_core::MonitorPageGpas; -use vmbus_core::OutgoingMessage; -use vmbus_core::TaggedStream; -use vmbus_core::VersionInfo; use vmcore::interrupt::Interrupt; use zerocopy::Immutable; use zerocopy::IntoBytes; @@ -1792,9 +1791,9 @@ mod tests { use super::*; use futures_concurrency::future::Join; use guid::Guid; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::timer::PolledTimer; - use pal_async::DefaultDriver; use protocol::TargetInfo; use std::fmt::Debug; use std::task::ready; diff --git a/vm/devices/vmbus/vmbus_client/src/saved_state.rs b/vm/devices/vmbus/vmbus_client/src/saved_state.rs index 360bae78a7..af0b3f794f 100644 --- a/vm/devices/vmbus/vmbus_client/src/saved_state.rs +++ b/vm/devices/vmbus/vmbus_client/src/saved_state.rs @@ -8,12 +8,12 @@ use crate::SUPPORTED_FEATURE_FLAGS; use guid::Guid; use mesh::payload::Protobuf; use vmbus_channel::bus::OfferKey; +use vmbus_core::OutgoingMessage; +use vmbus_core::VersionInfo; use vmbus_core::protocol; use vmbus_core::protocol::ChannelId; use vmbus_core::protocol::FeatureFlags; use vmbus_core::protocol::GpadlId; -use vmbus_core::OutgoingMessage; -use vmbus_core::VersionInfo; impl super::ClientTask { pub fn handle_save(&mut self) -> SavedState { diff --git a/vm/devices/vmbus/vmbus_client_hcl/src/lib.rs b/vm/devices/vmbus/vmbus_client_hcl/src/lib.rs index 45bfcf616d..7c8ed4ccb4 100644 --- a/vm/devices/vmbus/vmbus_client_hcl/src/lib.rs +++ b/vm/devices/vmbus/vmbus_client_hcl/src/lib.rs @@ -25,8 +25,8 @@ use std::io::IoSliceMut; use std::os::fd::AsFd; use std::pin::Pin; use std::sync::Arc; -use std::task::ready; use std::task::Poll; +use std::task::ready; use std::time::Duration; use vmbus_async::async_dgram::AsyncRecv; use vmbus_client::PollPostMessage; diff --git a/vm/devices/vmbus/vmbus_core/src/lib.rs b/vm/devices/vmbus/vmbus_core/src/lib.rs index 5eb8cee592..a396cea2a7 100644 --- a/vm/devices/vmbus/vmbus_core/src/lib.rs +++ b/vm/devices/vmbus/vmbus_core/src/lib.rs @@ -10,11 +10,10 @@ use futures::FutureExt; use futures::StreamExt; use guid::Guid; use inspect::Inspect; -use protocol::MessageHeader; -use protocol::VmbusMessage; use protocol::HEADER_SIZE; use protocol::MAX_MESSAGE_SIZE; -use std::future::Future; +use protocol::MessageHeader; +use protocol::VmbusMessage; use std::str::FromStr; use std::task::Poll; use thiserror::Error; diff --git a/vm/devices/vmbus/vmbus_proxy/src/lib.rs b/vm/devices/vmbus/vmbus_proxy/src/lib.rs index 82c9027692..87a20fa092 100644 --- a/vm/devices/vmbus/vmbus_proxy/src/lib.rs +++ b/vm/devices/vmbus/vmbus_proxy/src/lib.rs @@ -25,8 +25,8 @@ use vmbus_core::HvsockConnectRequest; use vmbus_core::HvsockConnectResult; use vmbusioctl::VMBUS_CHANNEL_OFFER; use vmbusioctl::VMBUS_SERVER_OPEN_CHANNEL_OUTPUT_PARAMETERS; -use widestring::utf16str; use widestring::Utf16Str; +use widestring::utf16str; use windows::Wdk::Storage::FileSystem::NtOpenFile; use windows::Win32::Foundation::ERROR_CANCELLED; use windows::Win32::Foundation::HANDLE; diff --git a/vm/devices/vmbus/vmbus_proxy/src/proxyioctl.rs b/vm/devices/vmbus/vmbus_proxy/src/proxyioctl.rs index 7d74296430..b4c36a34be 100644 --- a/vm/devices/vmbus/vmbus_proxy/src/proxyioctl.rs +++ b/vm/devices/vmbus/vmbus_proxy/src/proxyioctl.rs @@ -12,12 +12,12 @@ use super::vmbusioctl::VMBUS_CHANNEL_OFFER; use super::vmbusioctl::VMBUS_SERVER_OPEN_CHANNEL_OUTPUT_PARAMETERS; use bitfield_struct::bitfield; -use windows::core::GUID; use windows::Win32::Foundation::NTSTATUS; use windows::Win32::System::Ioctl::FILE_DEVICE_UNKNOWN; use windows::Win32::System::Ioctl::FILE_READ_ACCESS; use windows::Win32::System::Ioctl::FILE_WRITE_ACCESS; use windows::Win32::System::Ioctl::METHOD_BUFFERED; +use windows::core::GUID; use zerocopy::Immutable; use zerocopy::IntoBytes; diff --git a/vm/devices/vmbus/vmbus_relay/src/lib.rs b/vm/devices/vmbus/vmbus_relay/src/lib.rs index f1458b3604..66b431e4a6 100644 --- a/vm/devices/vmbus/vmbus_relay/src/lib.rs +++ b/vm/devices/vmbus/vmbus_relay/src/lib.rs @@ -20,11 +20,11 @@ pub use saved_state::SavedState; use anyhow::Context; use anyhow::Result; use client::ModifyConnectionRequest; -use futures::future::join_all; -use futures::future::BoxFuture; -use futures::future::OptionFuture; use futures::FutureExt; use futures::StreamExt; +use futures::future::BoxFuture; +use futures::future::OptionFuture; +use futures::future::join_all; use guid::Guid; use inspect::Inspect; use inspect::InspectMut; @@ -37,11 +37,10 @@ use pal_async::task::Task; use pal_event::Event; use std::collections::HashMap; use std::fmt::Debug; -use std::future::Future; use std::pin::Pin; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; -use std::sync::Arc; use unicycle::FuturesUnordered; use vmbus_channel::bus::ChannelRequest; use vmbus_channel::bus::ChannelServerRequest; @@ -50,13 +49,13 @@ use vmbus_channel::bus::ModifyRequest; use vmbus_channel::bus::OpenRequest; use vmbus_channel::bus::OpenResult; use vmbus_client as client; +use vmbus_core::HvsockConnectRequest; +use vmbus_core::HvsockConnectResult; +use vmbus_core::VersionInfo; use vmbus_core::protocol; use vmbus_core::protocol::ChannelId; use vmbus_core::protocol::FeatureFlags; use vmbus_core::protocol::GpadlId; -use vmbus_core::HvsockConnectRequest; -use vmbus_core::HvsockConnectResult; -use vmbus_core::VersionInfo; use vmbus_server::HvsockRelayChannelHalf; use vmbus_server::ModifyConnectionResponse; use vmbus_server::OfferInfo; diff --git a/vm/devices/vmbus/vmbus_relay/src/saved_state.rs b/vm/devices/vmbus/vmbus_relay/src/saved_state.rs index 81033ef631..861e88cdc4 100644 --- a/vm/devices/vmbus/vmbus_relay/src/saved_state.rs +++ b/vm/devices/vmbus/vmbus_relay/src/saved_state.rs @@ -13,9 +13,9 @@ use anyhow::Result; use mesh::payload::Protobuf; use mesh::rpc::RpcSend; use pal_event::Event; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::OnceLock; +use std::sync::atomic::Ordering; use vmbus_channel::bus::ChannelServerRequest; use vmbus_channel::bus::OpenResult; use vmbus_client as client; diff --git a/vm/devices/vmbus/vmbus_relay_intercept_device/src/lib.rs b/vm/devices/vmbus/vmbus_relay_intercept_device/src/lib.rs index 48dcee67c0..34fffccc35 100644 --- a/vm/devices/vmbus/vmbus_relay_intercept_device/src/lib.rs +++ b/vm/devices/vmbus/vmbus_relay_intercept_device/src/lib.rs @@ -23,7 +23,6 @@ use inspect::InspectMut; use mesh::rpc::RpcSend; use pal_async::driver::SpawnDriver; use std::future::pending; -use std::future::Future; use std::pin::pin; use std::sync::Arc; use task_control::AsyncRun; @@ -32,13 +31,13 @@ use task_control::InspectTaskMut; use task_control::StopTask; use task_control::TaskControl; use tracing::Instrument; -use user_driver::memory::MemoryBlock; use user_driver::DmaClient; -use vmbus_channel::bus::GpadlRequest; -use vmbus_channel::bus::OpenData; +use user_driver::memory::MemoryBlock; use vmbus_channel::ChannelClosed; use vmbus_channel::RawAsyncChannel; use vmbus_channel::SignalVmbusChannel; +use vmbus_channel::bus::GpadlRequest; +use vmbus_channel::bus::OpenData; use vmbus_client::ChannelRequest; use vmbus_client::OfferInfo; use vmbus_client::OpenOutput; diff --git a/vm/devices/vmbus/vmbus_relay_intercept_device/src/ring_buffer.rs b/vm/devices/vmbus/vmbus_relay_intercept_device/src/ring_buffer.rs index c7b311f2f1..ae319809d1 100644 --- a/vm/devices/vmbus/vmbus_relay_intercept_device/src/ring_buffer.rs +++ b/vm/devices/vmbus/vmbus_relay_intercept_device/src/ring_buffer.rs @@ -8,9 +8,9 @@ use safeatomic::AtomicSliceOps; use std::sync::atomic::AtomicU32; use user_driver::memory::MemoryBlock; -use vmbus_ring::RingMem; use vmbus_ring::CONTROL_WORD_COUNT; use vmbus_ring::PAGE_SIZE; +use vmbus_ring::RingMem; pub struct MemoryBlockRingBuffer(MemoryBlock); diff --git a/vm/devices/vmbus/vmbus_ring/benches/ring.rs b/vm/devices/vmbus/vmbus_ring/benches/ring.rs index 61d21d53bc..50384d3a1c 100644 --- a/vm/devices/vmbus/vmbus_ring/benches/ring.rs +++ b/vm/devices/vmbus/vmbus_ring/benches/ring.rs @@ -5,21 +5,21 @@ #![expect(missing_docs)] -use criterion::black_box; -use criterion::criterion_group; -use criterion::criterion_main; use criterion::BenchmarkId; use criterion::Criterion; use criterion::Throughput; +use criterion::black_box; +use criterion::criterion_group; +use criterion::criterion_main; use safeatomic::AsAtomicBytes; use safeatomic::AtomicSliceOps; -use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicU8; +use std::sync::atomic::AtomicU32; +use vmbus_ring::CONTROL_WORD_COUNT; +use vmbus_ring::PAGE_SIZE; use vmbus_ring::PagedMemory; use vmbus_ring::PagedRingMem; use vmbus_ring::RingMem; -use vmbus_ring::CONTROL_WORD_COUNT; -use vmbus_ring::PAGE_SIZE; criterion_main!(benches); diff --git a/vm/devices/vmbus/vmbus_ring/src/gparange.rs b/vm/devices/vmbus/vmbus_ring/src/gparange.rs index 565deefb5d..cddf970273 100644 --- a/vm/devices/vmbus/vmbus_ring/src/gparange.rs +++ b/vm/devices/vmbus/vmbus_ring/src/gparange.rs @@ -2,8 +2,8 @@ // Licensed under the MIT License. use guestmem::ranges::PagedRange; -use smallvec::smallvec; use smallvec::SmallVec; +use smallvec::smallvec; use thiserror::Error; use zerocopy::FromBytes; use zerocopy::FromZeros; diff --git a/vm/devices/vmbus/vmbus_ring/src/lib.rs b/vm/devices/vmbus/vmbus_ring/src/lib.rs index 031f8a20b4..11b49df933 100644 --- a/vm/devices/vmbus/vmbus_ring/src/lib.rs +++ b/vm/devices/vmbus/vmbus_ring/src/lib.rs @@ -18,23 +18,23 @@ pub mod gparange; pub use pipe_protocol::*; -pub use protocol::TransferPageRange; pub use protocol::PAGE_SIZE; +pub use protocol::TransferPageRange; use crate::gparange::GpaRange; -use guestmem::ranges::PagedRange; use guestmem::AccessError; use guestmem::MemoryRead; use guestmem::MemoryWrite; +use guestmem::ranges::PagedRange; use inspect::Inspect; use protocol::*; use safeatomic::AtomicSliceOps; use std::fmt::Debug; +use std::sync::Arc; +use std::sync::atomic::AtomicU8; use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicU64; -use std::sync::atomic::AtomicU8; use std::sync::atomic::Ordering; -use std::sync::Arc; use thiserror::Error; use zerocopy::FromZeros; use zerocopy::IntoBytes; diff --git a/vm/devices/vmbus/vmbus_server/src/channel_bitmap.rs b/vm/devices/vmbus/vmbus_server/src/channel_bitmap.rs index 12403b988f..918fc091dd 100644 --- a/vm/devices/vmbus/vmbus_server/src/channel_bitmap.rs +++ b/vm/devices/vmbus/vmbus_server/src/channel_bitmap.rs @@ -4,9 +4,9 @@ use guestmem::LockedPages; use parking_lot::RwLock; use safeatomic::AtomicSliceOps; +use std::sync::Arc; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; use vmcore::interrupt::Interrupt; pub(crate) struct ChannelBitmap { diff --git a/vm/devices/vmbus/vmbus_server/src/channels.rs b/vm/devices/vmbus/vmbus_server/src/channels.rs index f201aa6d21..9396eaf2aa 100644 --- a/vm/devices/vmbus/vmbus_server/src/channels.rs +++ b/vm/devices/vmbus/vmbus_server/src/channels.rs @@ -3,25 +3,25 @@ mod saved_state; -use crate::monitor::AssignedMonitors; -use crate::protocol::Version; use crate::Guid; -use crate::SynicMessage; use crate::SINT; +use crate::SynicMessage; +use crate::monitor::AssignedMonitors; +use crate::protocol::Version; use hvdef::Vtl; use inspect::Inspect; pub use saved_state::RestoreError; pub use saved_state::SavedState; use slab::Slab; use std::cmp::min; +use std::collections::VecDeque; use std::collections::hash_map::Entry; use std::collections::hash_map::HashMap; -use std::collections::VecDeque; use std::fmt::Display; use std::ops::Index; use std::ops::IndexMut; -use std::task::ready; use std::task::Poll; +use std::task::ready; use thiserror::Error; use vmbus_channel::bus::ChannelType; use vmbus_channel::bus::GpadlRequest; @@ -29,6 +29,12 @@ use vmbus_channel::bus::OfferKey; use vmbus_channel::bus::OfferParams; use vmbus_channel::bus::OpenData; use vmbus_channel::bus::RestoredGpadl; +use vmbus_core::HvsockConnectRequest; +use vmbus_core::HvsockConnectResult; +use vmbus_core::MaxVersionInfo; +use vmbus_core::MonitorPageGpas; +use vmbus_core::OutgoingMessage; +use vmbus_core::VersionInfo; use vmbus_core::protocol; use vmbus_core::protocol::ChannelId; use vmbus_core::protocol::ConnectionId; @@ -37,12 +43,6 @@ use vmbus_core::protocol::GpadlId; use vmbus_core::protocol::Message; use vmbus_core::protocol::OfferFlags; use vmbus_core::protocol::UserDefinedData; -use vmbus_core::HvsockConnectRequest; -use vmbus_core::HvsockConnectResult; -use vmbus_core::MaxVersionInfo; -use vmbus_core::MonitorPageGpas; -use vmbus_core::OutgoingMessage; -use vmbus_core::VersionInfo; use vmbus_ring::gparange; use vmcore::monitor::MonitorId; use zerocopy::FromZeros; @@ -893,9 +893,11 @@ impl AssignmentEntry<'_> { } pub fn insert(self, offer_id: OfferId) { - assert!(self.list.assignments[self.index] - .replace(offer_id) - .is_none()); + assert!( + self.list.assignments[self.index] + .replace(offer_id) + .is_none() + ); if self.index < self.list.reserved_offset { self.list.count_in_reserved_range += 1; @@ -1339,7 +1341,7 @@ impl Server { RestoreState::Restoring => {} RestoreState::Unmatched => unreachable!(), RestoreState::Restored => { - return Err(RestoreError::AlreadyRestored(channel.offer.key())) + return Err(RestoreError::AlreadyRestored(channel.offer.key())); } } @@ -1425,7 +1427,7 @@ impl<'a, N: 'a + Notifier> ServerWithNotifier<'a, N> { RestoreState::Restoring => {} RestoreState::Unmatched => unreachable!(), RestoreState::Restored => { - return Err(RestoreError::AlreadyRestored(channel.offer.key())) + return Err(RestoreError::AlreadyRestored(channel.offer.key())); } } @@ -2868,11 +2870,11 @@ impl<'a, N: 'a + Notifier> ServerWithNotifier<'a, N> { ChannelState::Revoked | ChannelState::Reoffered => {} ChannelState::Open { .. } | ChannelState::Opening { .. } => { - return Err(ChannelError::ChannelAlreadyOpen) + return Err(ChannelError::ChannelAlreadyOpen); } ChannelState::Closing { .. } | ChannelState::ClosingReopen { .. } => { - return Err(ChannelError::InvalidChannelState) + return Err(ChannelError::InvalidChannelState); } ChannelState::ClientReleased diff --git a/vm/devices/vmbus/vmbus_server/src/hvsock.rs b/vm/devices/vmbus/vmbus_server/src/hvsock.rs index 2fbbd4535c..e30b19b95d 100644 --- a/vm/devices/vmbus/vmbus_server/src/hvsock.rs +++ b/vm/devices/vmbus/vmbus_server/src/hvsock.rs @@ -9,8 +9,8 @@ //! [1]: use super::Guid; -use crate::ring::RingMem; use crate::HvsockRelayChannelHalf; +use crate::ring::RingMem; use anyhow::Context; use futures::AsyncReadExt; use futures::AsyncWriteExt; @@ -113,7 +113,7 @@ impl HvsockRelay { &self, ctx: &mut CancelContext, service_id: Guid, - ) -> impl std::future::Future> + Send + use<> { + ) -> impl Future> + Send + use<> { let inner = self.inner.clone(); let host_send = self.host_send.clone(); let (send, recv) = mesh::oneshot(); @@ -584,15 +584,15 @@ mod tests { use crate::ring::FlatRingMem; use futures::AsyncReadExt; use futures::AsyncWriteExt; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::driver::Driver; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; use pal_async::task::Task; - use pal_async::DefaultDriver; use unix_socket::UnixStream; - use vmbus_async::pipe::connected_byte_pipes; use vmbus_async::pipe::BytePipe; + use vmbus_async::pipe::connected_byte_pipes; fn setup_relay( driver: &T, diff --git a/vm/devices/vmbus/vmbus_server/src/lib.rs b/vm/devices/vmbus/vmbus_server/src/lib.rs index a0c5e95709..257bd98835 100644 --- a/vm/devices/vmbus/vmbus_server/src/lib.rs +++ b/vm/devices/vmbus/vmbus_server/src/lib.rs @@ -27,13 +27,13 @@ pub use channels::OfferParamsInternal; use channels::OpenParams; use channels::RestoreError; pub use channels::Update; +use futures::FutureExt; +use futures::StreamExt; use futures::channel::mpsc; use futures::channel::mpsc::SendError; -use futures::future::poll_fn; use futures::future::OptionFuture; +use futures::future::poll_fn; use futures::stream::SelectAll; -use futures::FutureExt; -use futures::StreamExt; use guestmem::GuestMemory; use hvdef::Vtl; use inspect::Inspect; @@ -52,11 +52,10 @@ pub use proxyintegration::ProxyServerInfo; use ring::PAGE_SIZE; use std::collections::HashMap; use std::future; -use std::future::Future; use std::pin::Pin; use std::sync::Arc; -use std::task::ready; use std::task::Poll; +use std::task::ready; use unicycle::FuturesUnordered; use vmbus_channel::bus::ChannelRequest; use vmbus_channel::bus::ChannelServerRequest; @@ -73,8 +72,6 @@ use vmbus_channel::bus::RestoreResult; use vmbus_channel::gpadl::GpadlMap; use vmbus_channel::gpadl_ring::AlignedGpadlView; use vmbus_channel::gpadl_ring::GpadlRingMem; -use vmbus_core::protocol; -pub use vmbus_core::protocol::GpadlId; use vmbus_core::HvsockConnectRequest; use vmbus_core::HvsockConnectResult; use vmbus_core::MaxVersionInfo; @@ -82,6 +79,8 @@ use vmbus_core::MonitorPageGpas; use vmbus_core::OutgoingMessage; use vmbus_core::TaggedStream; use vmbus_core::VersionInfo; +use vmbus_core::protocol; +pub use vmbus_core::protocol::GpadlId; #[cfg(windows)] use vmbus_proxy::ProxyHandle; use vmbus_ring as ring; @@ -961,7 +960,9 @@ impl ServerTask { if !self.inner.running { self.inner.running = true; if self.unstick_on_start { - tracing::info!("lost synic bug fix is not in yet, call unstick_channels to mitigate the issue."); + tracing::info!( + "lost synic bug fix is not in yet, call unstick_channels to mitigate the issue." + ); self.unstick_channels(false); self.unstick_on_start = false; } @@ -1016,7 +1017,7 @@ impl ServerTask { async fn run( &mut self, mut relay_response_recv: impl futures::stream::FusedStream - + Unpin, + + Unpin, mut hvsock_recv: impl futures::stream::FusedStream + Unpin, ) { loop { @@ -1931,11 +1932,11 @@ impl ParentBus for VmbusServerControl { #[cfg(test)] mod tests { use super::*; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::driver::SpawnDriver; use pal_async::timer::Instant; use pal_async::timer::PolledTimer; - use pal_async::DefaultDriver; use parking_lot::Mutex; use protocol::UserDefinedData; use std::time::Duration; diff --git a/vm/devices/vmbus/vmbus_server/src/proxyintegration.rs b/vm/devices/vmbus/vmbus_server/src/proxyintegration.rs index 63c465cc7d..d3bf2dc60e 100644 --- a/vm/devices/vmbus/vmbus_server/src/proxyintegration.rs +++ b/vm/devices/vmbus/vmbus_server/src/proxyintegration.rs @@ -15,14 +15,14 @@ use super::TaggedStream; use super::VmbusServerControl; use crate::HvsockRelayChannelHalf; use anyhow::Context; -use futures::future::OptionFuture; -use futures::stream::SelectAll; use futures::FutureExt; use futures::StreamExt; +use futures::future::OptionFuture; +use futures::stream::SelectAll; use guestmem::GuestMemory; -use mesh::rpc::RpcSend; use mesh::Cancel; use mesh::CancelContext; +use mesh::rpc::RpcSend; use pal_async::driver::SpawnDriver; use pal_async::task::Spawn; use pal_event::Event; @@ -38,15 +38,15 @@ use vmbus_channel::bus::OfferParams; use vmbus_channel::bus::OpenRequest; use vmbus_channel::bus::OpenResult; use vmbus_channel::gpadl::GpadlId; -use vmbus_core::protocol; use vmbus_core::HvsockConnectRequest; use vmbus_core::HvsockConnectResult; -use vmbus_proxy::vmbusioctl::VMBUS_SERVER_OPEN_CHANNEL_OUTPUT_PARAMETERS; +use vmbus_core::protocol; use vmbus_proxy::ProxyAction; use vmbus_proxy::VmbusProxy; +use vmbus_proxy::vmbusioctl::VMBUS_SERVER_OPEN_CHANNEL_OUTPUT_PARAMETERS; use vmcore::interrupt::Interrupt; -use windows::core::HRESULT; use windows::Win32::Foundation::ERROR_CANCELLED; +use windows::core::HRESULT; use zerocopy::IntoBytes; /// Provides access to a vmbus server, and its optional hvsocket relay. diff --git a/vm/devices/watchdog/guest_watchdog/src/lib.rs b/vm/devices/watchdog/guest_watchdog/src/lib.rs index 721a154810..4cef8626cf 100644 --- a/vm/devices/watchdog/guest_watchdog/src/lib.rs +++ b/vm/devices/watchdog/guest_watchdog/src/lib.rs @@ -3,20 +3,20 @@ #![expect(missing_docs)] +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::PortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; use chipset_device::poll_device::PollDevice; -use chipset_device::ChipsetDevice; use inspect::Inspect; use inspect::InspectMut; use std::task::Context; use vmcore::device_state::ChangeDeviceState; use vmcore::vmtime::VmTimeAccess; -use watchdog_core::platform::WatchdogPlatform; use watchdog_core::WatchdogServices; +use watchdog_core::platform::WatchdogPlatform; open_enum::open_enum! { enum WatchdogPort: u16 { diff --git a/vm/devices/watchdog/watchdog_vmgs_format/src/lib.rs b/vm/devices/watchdog/watchdog_vmgs_format/src/lib.rs index 57c686d083..7f2b69e396 100644 --- a/vm/devices/watchdog/watchdog_vmgs_format/src/lib.rs +++ b/vm/devices/watchdog/watchdog_vmgs_format/src/lib.rs @@ -46,11 +46,7 @@ impl WatchdogVmgsFormat { /// Return a slice to persist to VMGS. fn as_slice(&self) -> &[u8] { - if self.boot_failure { - &[1] - } else { - &[0] - } + if self.boot_failure { &[1] } else { &[0] } } } diff --git a/vm/hv1/hv1_emulator/src/cpuid.rs b/vm/hv1/hv1_emulator/src/cpuid.rs index 0499623b48..8e3a113b56 100644 --- a/vm/hv1/hv1_emulator/src/cpuid.rs +++ b/vm/hv1/hv1_emulator/src/cpuid.rs @@ -6,8 +6,8 @@ use virt::CpuidLeaf; use virt::IsolationType; -use vm_topology::processor::x86::X86Topology; use vm_topology::processor::ProcessorTopology; +use vm_topology::processor::x86::X86Topology; const MAX_CPUS: usize = 2048; diff --git a/vm/hv1/hv1_emulator/src/hv.rs b/vm/hv1/hv1_emulator/src/hv.rs index 05f9d3d59a..cfeebaa6a7 100644 --- a/vm/hv1/hv1_emulator/src/hv.rs +++ b/vm/hv1/hv1_emulator/src/hv.rs @@ -10,13 +10,13 @@ use super::synic::ProcessorSynic; use guestmem::GuestMemory; use guestmem::GuestMemoryError; use hv1_structs::VtlArray; +use hvdef::HV_PAGE_SIZE; +use hvdef::HV_PAGE_SIZE_USIZE; +use hvdef::HV_REFERENCE_TSC_SEQUENCE_INVALID; use hvdef::HvRegisterVpAssistPage; use hvdef::HvVpVtlControl; use hvdef::HvVtlEntryReason; use hvdef::Vtl; -use hvdef::HV_PAGE_SIZE; -use hvdef::HV_PAGE_SIZE_USIZE; -use hvdef::HV_REFERENCE_TSC_SEQUENCE_INVALID; use inspect::Inspect; use parking_lot::Mutex; use std::mem::offset_of; diff --git a/vm/hv1/hv1_emulator/src/synic.rs b/vm/hv1/hv1_emulator/src/synic.rs index 5fc5a4b0a1..60613d3086 100644 --- a/vm/hv1/hv1_emulator/src/synic.rs +++ b/vm/hv1/hv1_emulator/src/synic.rs @@ -5,6 +5,9 @@ use crate::RequestInterrupt; use guestmem::GuestMemory; +use hvdef::HV_MESSAGE_SIZE; +use hvdef::HV_PAGE_SIZE; +use hvdef::HV_PAGE_SIZE_USIZE; use hvdef::HvAllArchRegisterName; use hvdef::HvError; use hvdef::HvMessage; @@ -16,11 +19,8 @@ use hvdef::HvRegisterVsmVina; use hvdef::HvResult; use hvdef::HvSynicSimpSiefp; use hvdef::HvSynicStimerConfig; -use hvdef::TimerMessagePayload; -use hvdef::HV_MESSAGE_SIZE; -use hvdef::HV_PAGE_SIZE; -use hvdef::HV_PAGE_SIZE_USIZE; use hvdef::NUM_SINTS; +use hvdef::TimerMessagePayload; use inspect::Inspect; use parking_lot::RwLock; use std::array; diff --git a/vm/hv1/hv1_hypercall/src/imp.rs b/vm/hv1/hv1_hypercall/src/imp.rs index a2c2345c88..b524276f02 100644 --- a/vm/hv1/hv1_hypercall/src/imp.rs +++ b/vm/hv1/hv1_hypercall/src/imp.rs @@ -12,12 +12,6 @@ use super::support::VtlHypercall; use crate::support::HvRepResult; use crate::support::VariableRepHypercall; use hv1_structs::ProcessorSet; -use hvdef::hypercall as defs; -use hvdef::hypercall::AcceptPagesAttributes; -use hvdef::hypercall::HostVisibilityType; -use hvdef::hypercall::HvRegisterAssoc; -use hvdef::hypercall::HypercallOutput; -use hvdef::hypercall::VtlPermissionSet; use hvdef::HvError; use hvdef::HvMessage; use hvdef::HvRegisterName; @@ -25,6 +19,12 @@ use hvdef::HvRegisterValue; use hvdef::HvResult; use hvdef::HypercallCode; use hvdef::Vtl; +use hvdef::hypercall as defs; +use hvdef::hypercall::AcceptPagesAttributes; +use hvdef::hypercall::HostVisibilityType; +use hvdef::hypercall::HvRegisterAssoc; +use hvdef::hypercall::HypercallOutput; +use hvdef::hypercall::VtlPermissionSet; use zerocopy::IntoBytes; /// Implements the `HvPostMessage` hypercall. diff --git a/vm/hv1/hv1_hypercall/src/support.rs b/vm/hv1/hv1_hypercall/src/support.rs index 80bf1e8d4d..aa0afc1c08 100644 --- a/vm/hv1/hv1_hypercall/src/support.rs +++ b/vm/hv1/hv1_hypercall/src/support.rs @@ -5,13 +5,13 @@ use guestmem::GuestMemory; use guestmem::GuestMemoryError; -use hvdef::hypercall::Control; -use hvdef::hypercall::HypercallOutput; +use hvdef::HV_PAGE_SIZE; +use hvdef::HV_PAGE_SIZE_USIZE; use hvdef::HvError; use hvdef::HvResult; use hvdef::HypercallCode; -use hvdef::HV_PAGE_SIZE; -use hvdef::HV_PAGE_SIZE_USIZE; +use hvdef::hypercall::Control; +use hvdef::hypercall::HypercallOutput; use std::marker::PhantomData; use thiserror::Error; use zerocopy::FromBytes; diff --git a/vm/hv1/hv1_hypercall/src/tests.rs b/vm/hv1/hv1_hypercall/src/tests.rs index 8b8a11ec3c..efa5621660 100644 --- a/vm/hv1/hv1_hypercall/src/tests.rs +++ b/vm/hv1/hv1_hypercall/src/tests.rs @@ -17,11 +17,11 @@ use crate::X64RegisterIo; use crate::X64RegisterState; use guestmem::GuestMemory; use guestmem::PAGE_SIZE; -use hvdef::hypercall::Control; -use hvdef::hypercall::HypercallOutput; +use hvdef::HV_PAGE_SIZE_USIZE; use hvdef::HvError; use hvdef::HvResult; -use hvdef::HV_PAGE_SIZE_USIZE; +use hvdef::hypercall::Control; +use hvdef::hypercall::HypercallOutput; use open_enum::open_enum; use sparse_mmap::SparseMapping; use std::vec; diff --git a/vm/hv1/hv1_hypercall/src/x86.rs b/vm/hv1/hv1_hypercall/src/x86.rs index 4aea366d13..370b38f520 100644 --- a/vm/hv1/hv1_hypercall/src/x86.rs +++ b/vm/hv1/hv1_hypercall/src/x86.rs @@ -116,11 +116,7 @@ impl HypercallIo for X64RegisterIo { } fn fast_register_pair_count(&mut self) -> usize { - if self.is_64bit { - 7 - } else { - 1 - } + if self.is_64bit { 7 } else { 1 } } fn extended_fast_hypercalls_ok(&mut self) -> bool { diff --git a/vm/kvm/src/lib.rs b/vm/kvm/src/lib.rs index 2b8ee10d60..f26aa134df 100644 --- a/vm/kvm/src/lib.rs +++ b/vm/kvm/src/lib.rs @@ -16,10 +16,10 @@ use std::fs::File; use std::io; use std::marker::PhantomData; use std::os::unix::prelude::*; +use std::sync::Once; use std::sync::atomic::AtomicU8; use std::sync::atomic::AtomicUsize; use std::sync::atomic::Ordering; -use std::sync::Once; use thiserror::Error; mod ioctl { @@ -1128,12 +1128,13 @@ impl<'a> Processor<'a> { pub fn runner(&self) -> VpRunner<'a> { // Ensure this thread is uniquely running the VP, and store the thread // ID to support cancellation. - assert!(self - .get() - .thread - .write() - .replace(Pthread::current()) - .is_none()); + assert!( + self.get() + .thread + .write() + .replace(Pthread::current()) + .is_none() + ); VpRunner { partition: self.0, diff --git a/vm/loader/igvmfilegen/src/file_loader.rs b/vm/loader/igvmfilegen/src/file_loader.rs index 573e8cb758..b00967d0b6 100644 --- a/vm/loader/igvmfilegen/src/file_loader.rs +++ b/vm/loader/igvmfilegen/src/file_loader.rs @@ -10,32 +10,32 @@ use crate::identity_mapping::VbsMeasurement; use crate::signed_measurement::generate_snp_measurement; use crate::signed_measurement::generate_tdx_measurement; use crate::signed_measurement::generate_vbs_measurement; +use crate::vp_context_builder::VpContextBuilder; +use crate::vp_context_builder::VpContextPageState; +use crate::vp_context_builder::VpContextState; use crate::vp_context_builder::snp::InjectionType; use crate::vp_context_builder::snp::SnpHardwareContext; use crate::vp_context_builder::tdx::TdxHardwareContext; use crate::vp_context_builder::vbs::VbsRegister; use crate::vp_context_builder::vbs::VbsVpContext; -use crate::vp_context_builder::VpContextBuilder; -use crate::vp_context_builder::VpContextPageState; -use crate::vp_context_builder::VpContextState; use anyhow::Context; use hvdef::Vtl; -use igvm::snp_defs::SevVmsa; use igvm::IgvmDirectiveHeader; use igvm::IgvmFile; use igvm::IgvmInitializationHeader; use igvm::IgvmPlatformHeader; use igvm::IgvmRelocatableRegion; use igvm::IgvmRevision; +use igvm::snp_defs::SevVmsa; +use igvm_defs::IGVM_VHS_PARAMETER; +use igvm_defs::IGVM_VHS_PARAMETER_INSERT; +use igvm_defs::IGVM_VHS_SUPPORTED_PLATFORM; use igvm_defs::IgvmPageDataFlags; use igvm_defs::IgvmPageDataType; use igvm_defs::IgvmPlatformType; +use igvm_defs::PAGE_SIZE_4K; use igvm_defs::SnpPolicy; use igvm_defs::TdxPolicy; -use igvm_defs::IGVM_VHS_PARAMETER; -use igvm_defs::IGVM_VHS_PARAMETER_INSERT; -use igvm_defs::IGVM_VHS_SUPPORTED_PLATFORM; -use igvm_defs::PAGE_SIZE_4K; use loader::importer::Aarch64Register; use loader::importer::BootPageAcceptance; use loader::importer::GuestArch; @@ -1120,7 +1120,9 @@ impl ImageLoad for IgvmVtlLoader } if gpa % relocation_alignment != 0 { - anyhow::bail!("relocation base {gpa:#x} must be aligned to relocation alignment {relocation_alignment:#x}"); + anyhow::bail!( + "relocation base {gpa:#x} must be aligned to relocation alignment {relocation_alignment:#x}" + ); } if minimum_relocation_gpa % relocation_alignment != 0 { diff --git a/vm/loader/igvmfilegen/src/main.rs b/vm/loader/igvmfilegen/src/main.rs index 0cccb019c8..9115bdad78 100644 --- a/vm/loader/igvmfilegen/src/main.rs +++ b/vm/loader/igvmfilegen/src/main.rs @@ -10,15 +10,15 @@ mod vp_context_builder; use crate::file_loader::IgvmLoader; use crate::file_loader::LoaderIsolationType; -use anyhow::bail; use anyhow::Context; +use anyhow::bail; use clap::Parser; use file_loader::IgvmLoaderRegister; use file_loader::IgvmVtlLoader; use igvm::IgvmFile; +use igvm_defs::IGVM_FIXED_HEADER; use igvm_defs::SnpPolicy; use igvm_defs::TdxPolicy; -use igvm_defs::IGVM_FIXED_HEADER; use igvmfilegen_config::Config; use igvmfilegen_config::ConfigIsolationType; use igvmfilegen_config::Image; @@ -38,8 +38,8 @@ use loader::paravisor::Vtl0Config; use loader::paravisor::Vtl0Linux; use std::io::Write; use std::path::PathBuf; -use tracing_subscriber::filter::LevelFilter; use tracing_subscriber::EnvFilter; +use tracing_subscriber::filter::LevelFilter; use underhill_confidentiality::OPENHCL_CONFIDENTIAL_DEBUG_ENV_VAR_NAME; use zerocopy::FromBytes; use zerocopy::IntoBytes; diff --git a/vm/loader/igvmfilegen/src/signed_measurement/vbs.rs b/vm/loader/igvmfilegen/src/signed_measurement/vbs.rs index e51b3cf195..47184e697a 100644 --- a/vm/loader/igvmfilegen/src/signed_measurement/vbs.rs +++ b/vm/loader/igvmfilegen/src/signed_measurement/vbs.rs @@ -7,24 +7,24 @@ use super::SHA_256_OUTPUT_SIZE_BYTES; use crate::file_loader::DEFAULT_COMPATIBILITY_MASK; use igvm::IgvmDirectiveHeader; use igvm_defs::IgvmPageDataType; +use igvm_defs::PAGE_SIZE_4K; use igvm_defs::VbsDigestAlgorithm; use igvm_defs::VbsSigningAlgorithm; use igvm_defs::VbsVpContextRegister; -use igvm_defs::PAGE_SIZE_4K; use sha2::Digest; use sha2::Sha256; use std::collections::HashMap; use thiserror::Error; use vbs_defs::BootMeasurementType; -use vbs_defs::VbsChunkHeader; -use vbs_defs::VbsRegisterChunk; -use vbs_defs::VpGpaPageChunk; use vbs_defs::VBS_POLICY_FLAGS; use vbs_defs::VBS_VM_BOOT_MEASUREMENT_SIGNED_DATA; use vbs_defs::VBS_VM_GPA_PAGE_BOOT_METADATA; use vbs_defs::VBS_VP_CHUNK_SIZE_BYTES; use vbs_defs::VM_GPA_PAGE_READABLE; use vbs_defs::VM_GPA_PAGE_WRITABLE; +use vbs_defs::VbsChunkHeader; +use vbs_defs::VbsRegisterChunk; +use vbs_defs::VpGpaPageChunk; use zerocopy::IntoBytes; #[derive(Debug, Error)] diff --git a/vm/loader/igvmfilegen/src/vp_context_builder/snp.rs b/vm/loader/igvmfilegen/src/vp_context_builder/snp.rs index 5402cdd631..473e34fad7 100644 --- a/vm/loader/igvmfilegen/src/vp_context_builder/snp.rs +++ b/vm/loader/igvmfilegen/src/vp_context_builder/snp.rs @@ -14,9 +14,9 @@ use loader::importer::TableRegister; use loader::importer::X86Register; use loader::paravisor::HCL_SECURE_VTL; use std::fmt::Debug; +use x86defs::X64_EFER_SVME; use x86defs::snp::SevSelector; use x86defs::snp::SevVmsa; -use x86defs::X64_EFER_SVME; use zerocopy::FromZeros; use zerocopy::IntoBytes; diff --git a/vm/loader/page_table/src/aarch64.rs b/vm/loader/page_table/src/aarch64.rs index 87f0fc1d7d..b9e67bc44a 100644 --- a/vm/loader/page_table/src/aarch64.rs +++ b/vm/loader/page_table/src/aarch64.rs @@ -693,7 +693,9 @@ pub fn build_identity_page_tables_aarch64( panic!("size not 2mb aligned"); } - tracing::debug!("Creating Aarch64 page tables at {page_table_gpa:#x} mapping starting at {start_gpa:#x} of size {size} bytes"); + tracing::debug!( + "Creating Aarch64 page tables at {page_table_gpa:#x} mapping starting at {start_gpa:#x} of size {size} bytes" + ); let mut page_table_space = vec![0; page_table_region_size]; let mut page_tables = diff --git a/vm/loader/page_table/src/x64.rs b/vm/loader/page_table/src/x64.rs index 11ed4ea8a6..bbf13e7aaf 100644 --- a/vm/loader/page_table/src/x64.rs +++ b/vm/loader/page_table/src/x64.rs @@ -610,10 +610,10 @@ fn flatten_page_table(page_table: Vec) -> Vec { #[cfg(test)] mod tests { + use super::X64_1GB_PAGE_SIZE; use super::align_up_to_large_page_size; use super::align_up_to_page_size; use super::calculate_pde_table_count; - use super::X64_1GB_PAGE_SIZE; #[test] fn test_align_up() { diff --git a/vm/loader/src/elf.rs b/vm/loader/src/elf.rs index 32f0c93b7f..28575115f1 100644 --- a/vm/loader/src/elf.rs +++ b/vm/loader/src/elf.rs @@ -14,10 +14,10 @@ use crate::importer::GuestArch; use crate::importer::GuestArchKind; use crate::importer::ImageLoad; use hvdef::HV_PAGE_SIZE; -use object::elf; -use object::read::elf::FileHeader; use object::ReadCache; use object::ReadRef; +use object::elf; +use object::read::elf::FileHeader; use std::io::Read; use std::io::Seek; use thiserror::Error; @@ -35,7 +35,9 @@ pub enum Error { TargetMachineMismatch, #[error("unsupported ELF file byte order")] BigEndianElfOnLittle, - #[error("invalid entry address found in ELF header: {e_entry:#x}, start address: {start_address:#x}, load offset: {load_offset:#x}")] + #[error( + "invalid entry address found in ELF header: {e_entry:#x}, start address: {start_address:#x}, load offset: {load_offset:#x}" + )] InvalidEntryAddress { e_entry: u64, start_address: u64, @@ -47,7 +49,9 @@ pub enum Error { LoadOffsetOverflow { load_offset: u64, p_paddr: u64 }, #[error("invalid ELF program header memory offset {mem_offset}, below start {start_address}")] InvalidProgramHeaderMemoryOffset { mem_offset: u64, start_address: u64 }, - #[error("adding reloc bias {reloc_bias} and load offset {load_offset} to paddr {p_paddr} overflowed")] + #[error( + "adding reloc bias {reloc_bias} and load offset {load_offset} to paddr {p_paddr} overflowed" + )] RelocBiasOverflow { load_offset: u64, reloc_bias: u64, diff --git a/vm/loader/src/linux.rs b/vm/loader/src/linux.rs index d42d1a6a11..7036dc8a81 100644 --- a/vm/loader/src/linux.rs +++ b/vm/loader/src/linux.rs @@ -20,10 +20,10 @@ use aarch64defs::TranslationGranule1; use bitfield_struct::bitfield; use hvdef::HV_PAGE_SIZE; use loader_defs::linux as defs; +use page_table::IdentityMapSize; use page_table::x64::align_up_to_large_page_size; use page_table::x64::align_up_to_page_size; use page_table::x64::build_page_tables_64; -use page_table::IdentityMapSize; use std::ffi::CString; use thiserror::Error; use vm_topology::memory::MemoryLayout; diff --git a/vm/loader/src/paravisor.rs b/vm/loader/src/paravisor.rs index 1fb0ffd385..5502d0597f 100644 --- a/vm/loader/src/paravisor.rs +++ b/vm/loader/src/paravisor.rs @@ -14,11 +14,11 @@ use crate::importer::SegmentRegister; use crate::importer::StartupMemoryType; use crate::importer::TableRegister; use crate::importer::X86Register; -use crate::linux::load_kernel_and_initrd_arm64; use crate::linux::InitrdAddressType; use crate::linux::InitrdConfig; use crate::linux::InitrdInfo; use crate::linux::KernelInfo; +use crate::linux::load_kernel_and_initrd_arm64; use aarch64defs::Cpsr64; use aarch64defs::IntermPhysAddrSize; use aarch64defs::SctlrEl1; @@ -26,8 +26,8 @@ use aarch64defs::TranslationBaseEl1; use aarch64defs::TranslationControlEl1; use aarch64defs::TranslationGranule0; use aarch64defs::TranslationGranule1; -use hvdef::Vtl; use hvdef::HV_PAGE_SIZE; +use hvdef::Vtl; use igvm::registers::AArch64Register; use loader_defs::paravisor::*; use loader_defs::shim::ShimParamsRaw; @@ -35,17 +35,17 @@ use memory_range::MemoryRange; use page_table::aarch64::Arm64PageSize; use page_table::aarch64::MemoryAttributeEl1; use page_table::aarch64::MemoryAttributeIndirectionEl1; +use page_table::x64::PageTableBuilder; +use page_table::x64::X64_LARGE_PAGE_SIZE; use page_table::x64::align_up_to_large_page_size; use page_table::x64::align_up_to_page_size; use page_table::x64::calculate_pde_table_count; -use page_table::x64::PageTableBuilder; -use page_table::x64::X64_LARGE_PAGE_SIZE; use thiserror::Error; -use x86defs::cpuid::CpuidFunction; use x86defs::GdtEntry; use x86defs::X64_BUSY_TSS_SEGMENT_ATTRIBUTES; use x86defs::X64_DEFAULT_CODE_SEGMENT_ATTRIBUTES; use x86defs::X64_DEFAULT_DATA_SEGMENT_ATTRIBUTES; +use x86defs::cpuid::CpuidFunction; use zerocopy::FromZeros; use zerocopy::IntoBytes; diff --git a/vm/loader/src/uefi/mod.rs b/vm/loader/src/uefi/mod.rs index dc936fac4a..1eded01baa 100644 --- a/vm/loader/src/uefi/mod.rs +++ b/vm/loader/src/uefi/mod.rs @@ -11,9 +11,9 @@ use aarch64 as arch; #[cfg(guest_arch = "x86_64")] use x86_64 as arch; -pub use arch::load; pub use arch::CONFIG_BLOB_GPA_BASE; pub use arch::IMAGE_SIZE; +pub use arch::load; use guid::Guid; use thiserror::Error; @@ -359,8 +359,8 @@ pub mod x86_64 { use super::ConfigType; use super::Error; use super::LoadInfo; - use crate::common::import_default_gdt; use crate::common::DEFAULT_GDT_SIZE; + use crate::common::import_default_gdt; use crate::cpuid::HV_PSP_CPUID_PAGE; use crate::importer::BootPageAcceptance; use crate::importer::IgvmParameterType; @@ -368,12 +368,12 @@ pub mod x86_64 { use crate::importer::IsolationType; use crate::importer::StartupMemoryType; use crate::importer::X86Register; - use crate::uefi::get_sec_entry_point_offset; use crate::uefi::SEC_FIRMWARE_VOLUME_OFFSET; + use crate::uefi::get_sec_entry_point_offset; use hvdef::HV_PAGE_SIZE; + use page_table::IdentityMapSize; use page_table::x64::align_up_to_page_size; use page_table::x64::build_page_tables_64; - use page_table::IdentityMapSize; use zerocopy::FromZeros; use zerocopy::IntoBytes; @@ -932,7 +932,7 @@ pub mod aarch64 { } ConfigType::None => 0, ConfigType::Igvm => { - return Err(Error::InvalidConfigType("igvm not supported".to_owned())) + return Err(Error::InvalidConfigType("igvm not supported".to_owned())); } }; diff --git a/vm/page_pool_alloc/src/device_dma.rs b/vm/page_pool_alloc/src/device_dma.rs index 5beeab09ec..75b65dba9f 100644 --- a/vm/page_pool_alloc/src/device_dma.rs +++ b/vm/page_pool_alloc/src/device_dma.rs @@ -8,8 +8,8 @@ // `base()..len()` mapped for the lifetime of the struct. #![expect(unsafe_code)] -use crate::PagePoolHandle; use crate::PAGE_SIZE; +use crate::PagePoolHandle; use user_driver::memory::MappedDmaTarget; /// Page pool memory representing a DMA buffer useable by devices. diff --git a/vm/page_pool_alloc/src/lib.rs b/vm/page_pool_alloc/src/lib.rs index b78166c437..efa16cd9b9 100644 --- a/vm/page_pool_alloc/src/lib.rs +++ b/vm/page_pool_alloc/src/lib.rs @@ -14,24 +14,24 @@ use inspect::Response; use memory_range::MemoryRange; use parking_lot::Mutex; use safeatomic::AtomicSliceOps; -use sparse_mmap::alloc_shared_memory; use sparse_mmap::Mappable; use sparse_mmap::MappableRef; use sparse_mmap::SparseMapping; +use sparse_mmap::alloc_shared_memory; use std::fmt::Debug; use std::num::NonZeroU64; -use std::sync::atomic::AtomicU8; use std::sync::Arc; +use std::sync::atomic::AtomicU8; use thiserror::Error; const PAGE_SIZE: u64 = 4096; /// Save restore suport for [`PagePool`]. pub mod save_restore { + use super::PAGE_SIZE; use super::PagePool; use super::Slot; use super::SlotState; - use super::PAGE_SIZE; use crate::ResolvedSlotState; use memory_range::MemoryRange; use mesh::payload::Protobuf; @@ -859,10 +859,10 @@ impl user_driver::DmaClient for PagePoolAllocator { #[cfg(test)] mod test { + use crate::PAGE_SIZE; use crate::PagePool; use crate::PoolSource; use crate::TestMapper; - use crate::PAGE_SIZE; use inspect::Inspect; use memory_range::MemoryRange; use safeatomic::AtomicSliceOps; @@ -1033,9 +1033,11 @@ mod test { pool.restore(state).unwrap(); let alloc = pool.allocator("test2".into()).unwrap(); - assert!(alloc - .restore_alloc(a1.base_pfn, a1.size_pages.try_into().unwrap()) - .is_err()); + assert!( + alloc + .restore_alloc(a1.base_pfn, a1.size_pages.try_into().unwrap()) + .is_err() + ); } #[test] diff --git a/vm/vmcore/guestmem/fuzz/fuzz_guestmem.rs b/vm/vmcore/guestmem/fuzz/fuzz_guestmem.rs index e5905508c0..a911232c94 100644 --- a/vm/vmcore/guestmem/fuzz/fuzz_guestmem.rs +++ b/vm/vmcore/guestmem/fuzz/fuzz_guestmem.rs @@ -7,11 +7,11 @@ #![expect(missing_docs)] use arbitrary::Arbitrary; -use guestmem::ranges::PagedRange; use guestmem::BitmapInfo; use guestmem::GuestMemory; use guestmem::GuestMemoryAccess; use guestmem::LockedRange; +use guestmem::ranges::PagedRange; use smallvec::SmallVec; use sparse_mmap::SparseMapping; use std::ptr::NonNull; diff --git a/vm/vmcore/guestmem/src/lib.rs b/vm/vmcore/guestmem/src/lib.rs index a9dbd3ff36..d1fb5fdab5 100644 --- a/vm/vmcore/guestmem/src/lib.rs +++ b/vm/vmcore/guestmem/src/lib.rs @@ -19,9 +19,9 @@ use std::ops::Deref; use std::ops::DerefMut; use std::ops::Range; use std::ptr::NonNull; +use std::sync::Arc; use std::sync::atomic::AtomicU8; use std::sync::atomic::Ordering; -use std::sync::Arc; use thiserror::Error; use zerocopy::FromBytes; use zerocopy::FromZeros; @@ -970,7 +970,9 @@ pub enum MultiRegionError { NotPowerOfTwo(u64), #[error("region size {0:#x} is smaller than a page")] RegionSizeTooSmall(u64), - #[error("too many regions ({region_count}) for region size {region_size:#x}; max is {max_region_count}")] + #[error( + "too many regions ({region_count}) for region size {region_size:#x}; max is {max_region_count}" + )] TooManyRegions { region_count: usize, max_region_count: usize, @@ -1251,7 +1253,7 @@ impl GuestMemory { true, ) { PageFaultAction::Fail(err) => { - return Err(GuestMemoryBackingError::new(gpa + fault_offset, err)) + return Err(GuestMemoryBackingError::new(gpa + fault_offset, err)); } PageFaultAction::Retry => {} PageFaultAction::Fallback => break, @@ -1295,7 +1297,7 @@ impl GuestMemory { return Err(GuestMemoryBackingError::new( gpa + fault.offset() as u64, err, - )) + )); } PageFaultAction::Retry => {} PageFaultAction::Fallback => return fallback(&mut param), @@ -2206,8 +2208,8 @@ pub trait UnmapRom: Send + Sync { mod tests { use crate::BitmapInfo; use crate::GuestMemory; - use crate::PageFaultAction; use crate::PAGE_SIZE64; + use crate::PageFaultAction; use sparse_mmap::SparseMapping; use std::ptr::NonNull; use std::sync::Arc; diff --git a/vm/vmcore/memory_range/src/lib.rs b/vm/vmcore/memory_range/src/lib.rs index 44cd8cf236..9aa04efddc 100644 --- a/vm/vmcore/memory_range/src/lib.rs +++ b/vm/vmcore/memory_range/src/lib.rs @@ -464,12 +464,8 @@ impl, T> PeekableSorted { } } -impl< - I: Iterator, - J: Iterator, - T: Clone, - U: Clone, - > Iterator for RangeWalkIter +impl, J: Iterator, T: Clone, U: Clone> + Iterator for RangeWalkIter { type Item = (MemoryRange, RangeWalkResult); @@ -641,11 +637,11 @@ mod tests { extern crate alloc; use super::MemoryRange; use super::TWO_MB; + use crate::AlignedSubranges; use crate::flatten_ranges; use crate::merge_adjacent_ranges; use crate::overlapping_ranges; use crate::subtract_ranges; - use crate::AlignedSubranges; use alloc::vec; use alloc::vec::Vec; diff --git a/vm/vmcore/save_restore_derive/src/lib.rs b/vm/vmcore/save_restore_derive/src/lib.rs index 713cff9e46..86629b74b1 100644 --- a/vm/vmcore/save_restore_derive/src/lib.rs +++ b/vm/vmcore/save_restore_derive/src/lib.rs @@ -4,8 +4,8 @@ #![expect(missing_docs)] use quote::quote; -use syn::parse_macro_input; use syn::DeriveInput; +use syn::parse_macro_input; // Documented in the save_restore module. #[proc_macro_derive(SavedStateRoot)] diff --git a/vm/vmcore/src/device_state.rs b/vm/vmcore/src/device_state.rs index 7056bb5cc9..43b0e6c94e 100644 --- a/vm/vmcore/src/device_state.rs +++ b/vm/vmcore/src/device_state.rs @@ -1,8 +1,6 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use std::future::Future; - /// Trait for transitioning device state. pub trait ChangeDeviceState { /// Starts a device, allowing it to interact with the guest asynchronously. diff --git a/vm/vmcore/src/line_interrupt.rs b/vm/vmcore/src/line_interrupt.rs index b9f93fe68c..2a2de08358 100644 --- a/vm/vmcore/src/line_interrupt.rs +++ b/vm/vmcore/src/line_interrupt.rs @@ -8,8 +8,8 @@ use inspect::Inspect; use parking_lot::Mutex; use std::borrow::Cow; -use std::collections::btree_map::Entry; use std::collections::BTreeMap; +use std::collections::btree_map::Entry; use std::fmt::Debug; use std::fmt::Display; use std::ops::RangeInclusive; diff --git a/vm/vmcore/src/local_only.rs b/vm/vmcore/src/local_only.rs index bc5d2b4333..68cb7b355f 100644 --- a/vm/vmcore/src/local_only.rs +++ b/vm/vmcore/src/local_only.rs @@ -1,13 +1,13 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use mesh::payload::Error; +use mesh::payload::FieldDecode; +use mesh::payload::FieldEncode; use mesh::payload::inplace::InplaceOption; use mesh::payload::protobuf::FieldReader; use mesh::payload::protobuf::FieldSizer; use mesh::payload::protobuf::FieldWriter; -use mesh::payload::Error; -use mesh::payload::FieldDecode; -use mesh::payload::FieldEncode; use thiserror::Error; /// A wrapper type that skips serializing the type and fails deserialization. diff --git a/vm/vmcore/src/monitor.rs b/vm/vmcore/src/monitor.rs index 48cc326ce4..988271bda0 100644 --- a/vm/vmcore/src/monitor.rs +++ b/vm/vmcore/src/monitor.rs @@ -1,15 +1,15 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use hvdef::HV_PAGE_SIZE; use hvdef::HvMonitorPage; use hvdef::HvMonitorPageSmall; -use hvdef::HV_PAGE_SIZE; use inspect::Inspect; use std::mem::offset_of; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::AtomicU64; use std::sync::atomic::Ordering; -use std::sync::Arc; use zerocopy::FromZeros; use zerocopy::IntoBytes; diff --git a/vm/vmcore/src/non_volatile_store.rs b/vm/vmcore/src/non_volatile_store.rs index 04f76acb90..6c04aedf74 100644 --- a/vm/vmcore/src/non_volatile_store.rs +++ b/vm/vmcore/src/non_volatile_store.rs @@ -98,11 +98,11 @@ pub mod resources { use super::NonVolatileStore; use mesh::MeshPayload; use std::convert::Infallible; - use vm_resource::declare_static_resolver; - use vm_resource::kind::NonVolatileStoreKind; use vm_resource::CanResolveTo; use vm_resource::ResolveResource; use vm_resource::ResourceId; + use vm_resource::declare_static_resolver; + use vm_resource::kind::NonVolatileStoreKind; impl CanResolveTo for NonVolatileStoreKind { type Input<'a> = (); diff --git a/vm/vmcore/src/notify.rs b/vm/vmcore/src/notify.rs index 399ff26bc6..2f49e04e5e 100644 --- a/vm/vmcore/src/notify.rs +++ b/vm/vmcore/src/notify.rs @@ -13,7 +13,6 @@ use pal_async::wait::PolledWait; use pal_event::Event; use parking_lot::Mutex; use std::future::poll_fn; -use std::future::Future; use std::sync::Arc; use std::task::Context; use std::task::Poll; diff --git a/vm/vmcore/src/save_restore.rs b/vm/vmcore/src/save_restore.rs index c2fd239a71..d4f6552fc8 100644 --- a/vm/vmcore/src/save_restore.rs +++ b/vm/vmcore/src/save_restore.rs @@ -69,12 +69,12 @@ pub use save_restore_derive::SavedStateRoot; use mesh::payload; -use mesh::payload::encoding::ImpossibleField; -use mesh::payload::message::ProtobufAny; -use mesh::payload::protofile::MessageDescription; use mesh::payload::DefaultEncoding; use mesh::payload::DescribedProtobuf; use mesh::payload::Protobuf; +use mesh::payload::encoding::ImpossibleField; +use mesh::payload::message::ProtobufAny; +use mesh::payload::protofile::MessageDescription; /// Implemented by objects which can be saved/restored pub trait SaveRestore { @@ -245,7 +245,7 @@ pub mod private { fn do_not_impl_this_manually(&self) {} } const _: () = { - use $crate::save_restore::private::{linkme, protofile, SAVED_STATE_ROOTS}; + use $crate::save_restore::private::{SAVED_STATE_ROOTS, linkme, protofile}; #[linkme::distributed_slice(SAVED_STATE_ROOTS)] #[linkme(crate = linkme)] diff --git a/vm/vmcore/src/slim_event.rs b/vm/vmcore/src/slim_event.rs index 4df731c231..55176df892 100644 --- a/vm/vmcore/src/slim_event.rs +++ b/vm/vmcore/src/slim_event.rs @@ -6,7 +6,6 @@ use futures::Stream; use parking_lot::Mutex; use std::future::poll_fn; -use std::future::Future; use std::pin::Pin; use std::task::Context; use std::task::Poll; @@ -90,8 +89,8 @@ impl Stream for SlimEventStream<'_> { #[cfg(test)] mod tests { use crate::slim_event::SlimEvent; - use futures::executor::block_on; use futures::FutureExt; + use futures::executor::block_on; #[test] fn test() { diff --git a/vm/vmcore/src/vm_task.rs b/vm/vmcore/src/vm_task.rs index 7ed73c86ae..7fcf28ab31 100644 --- a/vm/vmcore/src/vm_task.rs +++ b/vm/vmcore/src/vm_task.rs @@ -78,7 +78,7 @@ pub trait TargetedDriver: 'static + Send + Sync + Inspect { true } /// Waits for this driver's target VP to be ready for tasks and IO. - fn wait_target_vp_ready(&self) -> impl std::future::Future + Send { + fn wait_target_vp_ready(&self) -> impl Future + Send { std::future::ready(()) } } @@ -88,7 +88,7 @@ trait DynTargetedDriver: 'static + Send + Sync + Inspect { fn driver(&self) -> &dyn Driver; fn retarget_vp(&self, target_vp: u32); fn is_ready(&self) -> bool; - fn wait_ready(&self) -> Pin + Send>>; + fn wait_ready(&self) -> Pin + Send>>; } impl DynTargetedDriver for T { @@ -108,7 +108,7 @@ impl DynTargetedDriver for T { self.is_target_vp_ready() } - fn wait_ready(&self) -> Pin + Send>> { + fn wait_ready(&self) -> Pin + Send>> { Box::pin(self.wait_target_vp_ready()) } } @@ -320,10 +320,10 @@ pub mod thread { use super::BuildVmTaskDriver; use super::TargetedDriver; use inspect::Inspect; - use pal_async::driver::Driver; - use pal_async::task::Spawn; use pal_async::DefaultDriver; use pal_async::DefaultPool; + use pal_async::driver::Driver; + use pal_async::task::Spawn; /// A backend for [`VmTaskDriverSource`](super::VmTaskDriverSource) based on /// individual threads. diff --git a/vm/vmcore/src/vmtime.rs b/vm/vmcore/src/vmtime.rs index 1e62344195..88d38a318e 100644 --- a/vm/vmcore/src/vmtime.rs +++ b/vm/vmcore/src/vmtime.rs @@ -23,17 +23,17 @@ #![warn(missing_docs)] -use futures::future::join_all; use futures::StreamExt; +use futures::future::join_all; use futures_concurrency::future::Race; use futures_concurrency::stream::Merge; -use inspect::adhoc; use inspect::Inspect; use inspect::InspectMut; +use inspect::adhoc; +use mesh::MeshPayload; use mesh::payload::Protobuf; use mesh::rpc::Rpc; use mesh::rpc::RpcSend; -use mesh::MeshPayload; use pal_async::driver::Driver; use pal_async::driver::PollImpl; use pal_async::driver::SpawnDriver; @@ -104,20 +104,12 @@ impl VmTime { /// Returns `self` or `t`, whichever is earlier. pub fn min(self, t: Self) -> Self { - if self.is_before(t) { - self - } else { - t - } + if self.is_before(t) { self } else { t } } /// Returns `self` or `t`, whichever is later. pub fn max(self, t: Self) -> Self { - if self.is_before(t) { - t - } else { - self - } + if self.is_before(t) { t } else { self } } } @@ -982,9 +974,9 @@ mod tests { use super::VmTime; use super::VmTimeKeeper; use futures::FutureExt; + use pal_async::DefaultDriver; use pal_async::async_test; use pal_async::timer::PolledTimer; - use pal_async::DefaultDriver; use std::future::poll_fn; use std::time::Duration; @@ -1017,9 +1009,11 @@ mod tests { } } // Timeout should be cleared by the successful poll. - assert!(poll_fn(|cx| access.poll_timeout(cx)) - .now_or_never() - .is_none()); + assert!( + poll_fn(|cx| access.poll_timeout(cx)) + .now_or_never() + .is_none() + ); // Test changing timeout. let now = access.now(); diff --git a/vm/vmcore/vm_resource/src/lib.rs b/vm/vmcore/vm_resource/src/lib.rs index a9a4faa596..de5e15dca1 100644 --- a/vm/vmcore/vm_resource/src/lib.rs +++ b/vm/vmcore/vm_resource/src/lib.rs @@ -635,8 +635,8 @@ mod tests { use super::ResourceKind; use super::ResourceResolver; use crate::CanResolveTo; - use mesh::payload::Protobuf; use mesh::MeshPayload; + use mesh::payload::Protobuf; use pal_async::async_test; use std::convert::Infallible; diff --git a/vm/vmcore/vm_topology/src/processor.rs b/vm/vmcore/vm_topology/src/processor.rs index fe90bb1ba5..a88d12f9bd 100644 --- a/vm/vmcore/vm_topology/src/processor.rs +++ b/vm/vmcore/vm_topology/src/processor.rs @@ -119,9 +119,9 @@ impl TopologyBuilder { } impl< - #[cfg(feature = "inspect")] T: ArchTopology + inspect::Inspect, - #[cfg(not(feature = "inspect"))] T: ArchTopology, - > ProcessorTopology + #[cfg(feature = "inspect")] T: ArchTopology + inspect::Inspect, + #[cfg(not(feature = "inspect"))] T: ArchTopology, +> ProcessorTopology { /// Returns the number of VPs. pub fn vp_count(&self) -> u32 { diff --git a/vm/vmgs/vmgs/src/lib.rs b/vm/vmgs/vmgs/src/lib.rs index ab6459808d..fd03c27996 100644 --- a/vm/vmgs/vmgs/src/lib.rs +++ b/vm/vmgs/vmgs/src/lib.rs @@ -29,10 +29,10 @@ mod vmgs_impl; pub use error::Error; pub use vmgs_format::EncryptionAlgorithm; pub use vmgs_format::FileId; -#[cfg(feature = "save_restore")] -pub use vmgs_impl::save_restore; pub use vmgs_impl::Vmgs; pub use vmgs_impl::VmgsFileInfo; +#[cfg(feature = "save_restore")] +pub use vmgs_impl::save_restore; /// VMGS helper functions pub mod vmgs_helpers { diff --git a/vm/vmgs/vmgs/src/vmgs_impl.rs b/vm/vmgs/vmgs/src/vmgs_impl.rs index 370af84b9e..808bbe005f 100644 --- a/vm/vmgs/vmgs/src/vmgs_impl.rs +++ b/vm/vmgs/vmgs/src/vmgs_impl.rs @@ -4,9 +4,9 @@ use crate::error::Error; use crate::storage::VmgsStorage; #[cfg(with_encryption)] -use anyhow::anyhow; -#[cfg(with_encryption)] use anyhow::Context; +#[cfg(with_encryption)] +use anyhow::anyhow; use disk_backend::Disk; #[cfg(feature = "inspect")] use inspect::Inspect; @@ -17,6 +17,12 @@ use std::num::NonZeroU32; use vmgs_format::EncryptionAlgorithm; use vmgs_format::FileAttribute; use vmgs_format::FileId; +use vmgs_format::VMGS_BYTES_PER_BLOCK; +use vmgs_format::VMGS_EXTENDED_FILE_TABLE_BLOCK_SIZE; +use vmgs_format::VMGS_FILE_TABLE_BLOCK_SIZE; +use vmgs_format::VMGS_MIN_FILE_BLOCK_OFFSET; +use vmgs_format::VMGS_SIGNATURE; +use vmgs_format::VMGS_VERSION_3_0; use vmgs_format::VmgsAuthTag; use vmgs_format::VmgsDatastoreKey; use vmgs_format::VmgsEncryptionKey; @@ -24,12 +30,6 @@ use vmgs_format::VmgsExtendedFileTable; use vmgs_format::VmgsFileTable; use vmgs_format::VmgsHeader; use vmgs_format::VmgsNonce; -use vmgs_format::VMGS_BYTES_PER_BLOCK; -use vmgs_format::VMGS_EXTENDED_FILE_TABLE_BLOCK_SIZE; -use vmgs_format::VMGS_FILE_TABLE_BLOCK_SIZE; -use vmgs_format::VMGS_MIN_FILE_BLOCK_OFFSET; -use vmgs_format::VMGS_SIGNATURE; -use vmgs_format::VMGS_VERSION_3_0; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::IntoBytes; @@ -1188,7 +1188,9 @@ impl Vmgs { if self.encryption_algorithm != EncryptionAlgorithm::NONE && encryption_algorithm != self.encryption_algorithm { - return Err(Error::Other(anyhow!("Encryption algorithm provided to add_new_encryption_key does not match VMGS's encryption algorithm."))); + return Err(Error::Other(anyhow!( + "Encryption algorithm provided to add_new_encryption_key does not match VMGS's encryption algorithm." + ))); } let mut new_key_index = 0; diff --git a/vm/vmgs/vmgs_broker/src/broker.rs b/vm/vmgs/vmgs_broker/src/broker.rs index 03b6e6ef35..fc73520f0a 100644 --- a/vm/vmgs/vmgs_broker/src/broker.rs +++ b/vm/vmgs/vmgs_broker/src/broker.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use mesh_channel::rpc::Rpc; use mesh_channel::Receiver; +use mesh_channel::rpc::Rpc; use vmgs::Vmgs; use vmgs::VmgsFileInfo; use vmgs_format::FileId; diff --git a/vm/vmgs/vmgs_broker/src/resolver.rs b/vm/vmgs/vmgs_broker/src/resolver.rs index 839fdf166d..e819efaed4 100644 --- a/vm/vmgs/vmgs_broker/src/resolver.rs +++ b/vm/vmgs/vmgs_broker/src/resolver.rs @@ -3,11 +3,11 @@ //! Resource resolver for VMGS files. +use crate::VmgsClient; use crate::non_volatile_store::EncryptionNotSupported; use crate::non_volatile_store::VmgsNonVolatileStore; -use crate::VmgsClient; -use vm_resource::kind::NonVolatileStoreKind; use vm_resource::ResolveResource; +use vm_resource::kind::NonVolatileStoreKind; use vmcore::non_volatile_store::resources::ResolvedNonVolatileStore; use vmgs_resources::VmgsFileHandle; diff --git a/vm/vmgs/vmgs_lib/src/lib.rs b/vm/vmgs/vmgs_lib/src/lib.rs index aa8924c554..cc2d83ffb4 100644 --- a/vm/vmgs/vmgs_lib/src/lib.rs +++ b/vm/vmgs/vmgs_lib/src/lib.rs @@ -12,8 +12,8 @@ use core::slice; use disk_backend::Disk; use disk_vhd1::Vhd1Disk; use futures::executor::block_on; -use std::ffi::c_char; use std::ffi::CStr; +use std::ffi::c_char; use std::fs::File; use std::io::Read; use std::path::Path; diff --git a/vm/vmgs/vmgs_resources/src/lib.rs b/vm/vmgs/vmgs_resources/src/lib.rs index 0f6f44a405..0ca29b16c9 100644 --- a/vm/vmgs/vmgs_resources/src/lib.rs +++ b/vm/vmgs/vmgs_resources/src/lib.rs @@ -6,8 +6,8 @@ #![forbid(unsafe_code)] use mesh::MeshPayload; -use vm_resource::kind::NonVolatileStoreKind; use vm_resource::ResourceId; +use vm_resource::kind::NonVolatileStoreKind; use vmgs_format::FileId; /// A handle to an individual file within a VMGS file. diff --git a/vm/vmgs/vmgstool/src/main.rs b/vm/vmgs/vmgstool/src/main.rs index e624652c6a..4716ea6f68 100644 --- a/vm/vmgs/vmgstool/src/main.rs +++ b/vm/vmgs/vmgstool/src/main.rs @@ -19,17 +19,17 @@ use std::path::Path; use std::path::PathBuf; use thiserror::Error; use uefi_nvram::UefiNvramOperation; +use vmgs::Error as VmgsError; +use vmgs::Vmgs; use vmgs::vmgs_helpers::get_active_header; use vmgs::vmgs_helpers::read_headers; use vmgs::vmgs_helpers::validate_header; -use vmgs::Error as VmgsError; -use vmgs::Vmgs; use vmgs_format::EncryptionAlgorithm; use vmgs_format::FileId; -use vmgs_format::VmgsHeader; use vmgs_format::VMGS_BYTES_PER_BLOCK; use vmgs_format::VMGS_DEFAULT_CAPACITY; use vmgs_format::VMGS_ENCRYPTION_KEY_SIZE; +use vmgs_format::VmgsHeader; const ONE_MEGA_BYTE: u64 = 1024 * 1024; const ONE_GIGA_BYTE: u64 = ONE_MEGA_BYTE * 1024; @@ -537,7 +537,7 @@ fn vhdfiledisk_create( { Ok(file) => file, Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => { - return Err(Error::FileExists) + return Err(Error::FileExists); } Err(err) => return Err(Error::VmgsFile(err)), }; diff --git a/vm/vmgs/vmgstool/src/uefi_nvram.rs b/vm/vmgs/vmgstool/src/uefi_nvram.rs index 91ef4067f8..6dfd60a220 100644 --- a/vm/vmgs/vmgstool/src/uefi_nvram.rs +++ b/vm/vmgs/vmgstool/src/uefi_nvram.rs @@ -3,13 +3,13 @@ //! Functions for interacting with the BIOS_NVRAM file in a VMGS file -use crate::storage_backend::VmgsStorageBackend; -use crate::vmgs_file_open; -use crate::vmgs_json; use crate::Error; use crate::FilePathArg; use crate::KeyPathArg; use crate::OpenMode; +use crate::storage_backend::VmgsStorageBackend; +use crate::vmgs_file_open; +use crate::vmgs_json; use anyhow::Result; use clap::Args; use clap::Subcommand; @@ -22,10 +22,10 @@ use std::path::Path; use std::path::PathBuf; use std::str::FromStr; use ucs2::Ucs2LeVec; +use uefi_nvram_specvars::ParsedNvramEntry; use uefi_nvram_specvars::boot_order; use uefi_nvram_specvars::parse_nvram_entry; use uefi_nvram_specvars::signature_list::SignatureList; -use uefi_nvram_specvars::ParsedNvramEntry; use uefi_nvram_storage::NvramStorage; use uefi_specs::uefi::nvram::vars::EFI_GLOBAL_VARIABLE; use uefi_specs::uefi::time::EFI_TIME; diff --git a/vm/whp/benches/primitives.rs b/vm/whp/benches/primitives.rs index 45d4c7c55c..cd4374d46d 100644 --- a/vm/whp/benches/primitives.rs +++ b/vm/whp/benches/primitives.rs @@ -9,14 +9,14 @@ #[expect(unsafe_code)] #[expect(clippy::undocumented_unsafe_blocks)] mod windows { - use criterion::criterion_group; use criterion::BenchmarkId; use criterion::Criterion; use criterion::Throughput; + use criterion::criterion_group; use std::os::windows::io::RawHandle; + use std::sync::Arc; use std::sync::atomic::AtomicU8; use std::sync::atomic::Ordering; - use std::sync::Arc; use winapi::um::memoryapi::*; use winapi::um::synchapi::*; use winapi::um::winnt::MEM_COMMIT; @@ -184,10 +184,12 @@ mod windows { { let an = ea as usize; let bn = eb as usize; - std::thread::spawn(move || loop { - unsafe { - assert!(WaitForSingleObject(an as RawHandle, 0xffffffff) == 0); - assert!(SetEvent(bn as RawHandle) != 0); + std::thread::spawn(move || { + loop { + unsafe { + assert!(WaitForSingleObject(an as RawHandle, 0xffffffff) == 0); + assert!(SetEvent(bn as RawHandle) != 0); + } } }) }; diff --git a/vm/whp/src/abi/x64.rs b/vm/whp/src/abi/x64.rs index c17f0adae6..d50797d3fc 100644 --- a/vm/whp/src/abi/x64.rs +++ b/vm/whp/src/abi/x64.rs @@ -3,8 +3,6 @@ #![cfg(target_arch = "x86_64")] -use super::bitops; -use super::bitops_base; use super::WHV_CPUID_OUTPUT; use super::WHV_MEMORY_ACCESS_TYPE; use super::WHV_PROCESSOR_FEATURES; @@ -12,6 +10,8 @@ use super::WHV_PROCESSOR_FEATURES1; use super::WHV_REGISTER_NAME; use super::WHV_RUN_VP_EXIT_REASON; use super::WHV_UINT128; +use super::bitops; +use super::bitops_base; pub const WHvX64RegisterRax: WHV_REGISTER_NAME = WHV_REGISTER_NAME(0x00000000); pub const WHvX64RegisterRcx: WHV_REGISTER_NAME = WHV_REGISTER_NAME(0x00000001); diff --git a/vm/whp/src/lib.rs b/vm/whp/src/lib.rs index 012b34f5f6..e43af8b429 100644 --- a/vm/whp/src/lib.rs +++ b/vm/whp/src/lib.rs @@ -26,9 +26,9 @@ use std::marker::PhantomData; use std::num::NonZeroI32; use std::num::NonZeroU16; use std::os::windows::prelude::*; +use std::ptr::NonNull; use std::ptr::null; use std::ptr::null_mut; -use std::ptr::NonNull; use winapi::shared::guiddef::GUID; use winapi::shared::ntdef::LUID; use winapi::shared::winerror; diff --git a/vm/whp/src/x64.rs b/vm/whp/src/x64.rs index acddd23751..53b89e2b3c 100644 --- a/vm/whp/src/x64.rs +++ b/vm/whp/src/x64.rs @@ -3,9 +3,9 @@ #![cfg(target_arch = "x86_64")] -use crate::abi; use crate::RegisterName; use crate::RegisterValue; +use crate::abi; /// 64-bit registers #[repr(u32)] diff --git a/vm/x86/tdcall/src/lib.rs b/vm/x86/tdcall/src/lib.rs index f60657a26d..c1dc9c0538 100644 --- a/vm/x86/tdcall/src/lib.rs +++ b/vm/x86/tdcall/src/lib.rs @@ -7,6 +7,7 @@ use hvdef::HV_PAGE_SIZE; use memory_range::MemoryRange; +use x86defs::tdx::TDX_SHARED_GPA_BOUNDARY_ADDRESS_BIT; use x86defs::tdx::TdCallLeaf; use x86defs::tdx::TdCallResult; use x86defs::tdx::TdCallResultCode; @@ -21,7 +22,6 @@ use x86defs::tdx::TdgMemPageGpaAttr; use x86defs::tdx::TdgMemPageLevel; use x86defs::tdx::TdxExtendedFieldCode; use x86defs::tdx::TdxGlaListInfo; -use x86defs::tdx::TDX_SHARED_GPA_BOUNDARY_ADDRESS_BIT; /// Input to a tdcall. This is not defined in the TDX specification, but a /// contract between callers of this module and this module's handling of diff --git a/vm/x86/x86emu/src/cpu.rs b/vm/x86/x86emu/src/cpu.rs index bd3848115f..53df82a8be 100644 --- a/vm/x86/x86emu/src/cpu.rs +++ b/vm/x86/x86emu/src/cpu.rs @@ -5,7 +5,6 @@ use crate::registers::RegisterIndex; use crate::registers::Segment; -use std::future::Future; use x86defs::RFlags; use x86defs::SegmentRegister; diff --git a/vm/x86/x86emu/src/emulator.rs b/vm/x86/x86emu/src/emulator.rs index e77863b334..510947e947 100644 --- a/vm/x86/x86emu/src/emulator.rs +++ b/vm/x86/x86emu/src/emulator.rs @@ -3,13 +3,13 @@ //! Implements an x86 instruction emulator. -use crate::registers::bitness; +use crate::Cpu; use crate::registers::Bitness; use crate::registers::Gp; use crate::registers::GpSize; use crate::registers::RegisterIndex; use crate::registers::Segment; -use crate::Cpu; +use crate::registers::bitness; use iced_x86::Code; use iced_x86::Decoder; use iced_x86::DecoderError; diff --git a/vm/x86/x86emu/src/emulator/arith.rs b/vm/x86/x86emu/src/emulator/arith.rs index 94ce12bc8f..99714e8345 100644 --- a/vm/x86/x86emu/src/emulator/arith.rs +++ b/vm/x86/x86emu/src/emulator/arith.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::rflags::update_flags_szp; use super::Emulator; use super::InternalError; +use super::rflags::update_flags_szp; use crate::Cpu; use iced_x86::Instruction; use iced_x86::Register; diff --git a/vm/x86/x86emu/src/emulator/bt.rs b/vm/x86/x86emu/src/emulator/bt.rs index 5b540db7cd..466b6e5531 100644 --- a/vm/x86/x86emu/src/emulator/bt.rs +++ b/vm/x86/x86emu/src/emulator/bt.rs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::instruction; use super::AlignmentMode; use super::Emulator; use super::InternalError; +use super::instruction; use crate::Cpu; use iced_x86::Instruction; diff --git a/vm/x86/x86emu/src/emulator/fast_path.rs b/vm/x86/x86emu/src/emulator/fast_path.rs index 414e27e0ff..b13c00bac0 100644 --- a/vm/x86/x86emu/src/emulator/fast_path.rs +++ b/vm/x86/x86emu/src/emulator/fast_path.rs @@ -4,12 +4,12 @@ //! Emulation fast paths for specific use cases. use super::instruction; +use crate::Cpu; use crate::emulator::arith::ArithOp; use crate::emulator::arith::OrOp; -use crate::registers::bitness; use crate::registers::Bitness; use crate::registers::Segment; -use crate::Cpu; +use crate::registers::bitness; use iced_x86::OpKind; const PAGE_SIZE: u32 = 4096; diff --git a/vm/x86/x86emu/src/emulator/rep.rs b/vm/x86/x86emu/src/emulator/rep.rs index f71df93b6d..ffb5d2d2b3 100644 --- a/vm/x86/x86emu/src/emulator/rep.rs +++ b/vm/x86/x86emu/src/emulator/rep.rs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::arith::ArithOp; use super::AlignmentMode; use super::Emulator; use super::InternalError; +use super::arith::ArithOp; use crate::Cpu; use iced_x86::Instruction; use iced_x86::OpKind; diff --git a/vm/x86/x86emu/src/emulator/shift_rotate.rs b/vm/x86/x86emu/src/emulator/shift_rotate.rs index e0a12b9558..a37f56fbfe 100644 --- a/vm/x86/x86emu/src/emulator/shift_rotate.rs +++ b/vm/x86/x86emu/src/emulator/shift_rotate.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::rflags::update_flags_szp; use super::Emulator; use super::InternalError; +use super::rflags::update_flags_szp; use crate::Cpu; use iced_x86::Instruction; use x86defs::RFlags; diff --git a/vm/x86/x86emu/src/lib.rs b/vm/x86/x86emu/src/lib.rs index 3a1b0c996b..87c659ad90 100644 --- a/vm/x86/x86emu/src/lib.rs +++ b/vm/x86/x86emu/src/lib.rs @@ -9,10 +9,10 @@ mod emulator; mod registers; pub use cpu::Cpu; -pub use emulator::fast_path; pub use emulator::Emulator; pub use emulator::Error; pub use emulator::MAX_REP_LOOPS; +pub use emulator::fast_path; pub use registers::Gp; pub use registers::GpSize; pub use registers::RegisterIndex; diff --git a/vm/x86/x86emu/tests/tests/arith/adc.rs b/vm/x86/x86emu/tests/tests/arith/adc.rs index 460f8e8626..6f57ddf744 100644 --- a/vm/x86/x86emu/tests/tests/arith/adc.rs +++ b/vm/x86/x86emu/tests/tests/arith/adc.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/add.rs b/vm/x86/x86emu/tests/tests/arith/add.rs index 15d741df93..801a92d70b 100644 --- a/vm/x86/x86emu/tests/tests/arith/add.rs +++ b/vm/x86/x86emu/tests/tests/arith/add.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/and.rs b/vm/x86/x86emu/tests/tests/arith/and.rs index 38aeffd49a..990a13f616 100644 --- a/vm/x86/x86emu/tests/tests/arith/and.rs +++ b/vm/x86/x86emu/tests/tests/arith/and.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_LOGIC_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/cmp.rs b/vm/x86/x86emu/tests/tests/arith/cmp.rs index b46fff1af5..cae375c097 100644 --- a/vm/x86/x86emu/tests/tests/arith/cmp.rs +++ b/vm/x86/x86emu/tests/tests/arith/cmp.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/cmpxchg.rs b/vm/x86/x86emu/tests/tests/arith/cmpxchg.rs index 95cbe80e90..77c5f99cf4 100644 --- a/vm/x86/x86emu/tests/tests/arith/cmpxchg.rs +++ b/vm/x86/x86emu/tests/tests/arith/cmpxchg.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_lockable_test; use crate::tests::common::LockTestBehavior; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_lockable_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/incdec.rs b/vm/x86/x86emu/tests/tests/arith/incdec.rs index ab64873393..8ffdc45a61 100644 --- a/vm/x86/x86emu/tests/tests/arith/incdec.rs +++ b/vm/x86/x86emu/tests/tests/arith/incdec.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_lockable_test; use crate::tests::common::LockTestBehavior; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_lockable_test; use iced_x86::code_asm::*; use x86defs::RFlags; use x86emu::Cpu; diff --git a/vm/x86/x86emu/tests/tests/arith/neg.rs b/vm/x86/x86emu/tests/tests/arith/neg.rs index 1d18dcf130..a495f0627b 100644 --- a/vm/x86/x86emu/tests/tests/arith/neg.rs +++ b/vm/x86/x86emu/tests/tests/arith/neg.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_lockable_test; use crate::tests::common::LockTestBehavior; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_lockable_test; use iced_x86::code_asm::*; use x86emu::Cpu; diff --git a/vm/x86/x86emu/tests/tests/arith/not.rs b/vm/x86/x86emu/tests/tests/arith/not.rs index 12a9d71f2f..0382143523 100644 --- a/vm/x86/x86emu/tests/tests/arith/not.rs +++ b/vm/x86/x86emu/tests/tests/arith/not.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_lockable_test; use crate::tests::common::LockTestBehavior; +use crate::tests::common::run_lockable_test; use iced_x86::code_asm::*; use x86defs::RFlags; diff --git a/vm/x86/x86emu/tests/tests/arith/or.rs b/vm/x86/x86emu/tests/tests/arith/or.rs index 2d8ea6217f..ee45ffdba5 100644 --- a/vm/x86/x86emu/tests/tests/arith/or.rs +++ b/vm/x86/x86emu/tests/tests/arith/or.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_LOGIC_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/sbb.rs b/vm/x86/x86emu/tests/tests/arith/sbb.rs index 5476a41498..067881a5c6 100644 --- a/vm/x86/x86emu/tests/tests/arith/sbb.rs +++ b/vm/x86/x86emu/tests/tests/arith/sbb.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/sub.rs b/vm/x86/x86emu/tests/tests/arith/sub.rs index de1f5b80d1..d5427f5cb5 100644 --- a/vm/x86/x86emu/tests/tests/arith/sub.rs +++ b/vm/x86/x86emu/tests/tests/arith/sub.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/test.rs b/vm/x86/x86emu/tests/tests/arith/test.rs index 0f1f80f485..fa76bc3504 100644 --- a/vm/x86/x86emu/tests/tests/arith/test.rs +++ b/vm/x86/x86emu/tests/tests/arith/test.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_LOGIC_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/xadd.rs b/vm/x86/x86emu/tests/tests/arith/xadd.rs index 12c10d7ad3..2a14b5ded8 100644 --- a/vm/x86/x86emu/tests/tests/arith/xadd.rs +++ b/vm/x86/x86emu/tests/tests/arith/xadd.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_lockable_test; use crate::tests::common::LockTestBehavior; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_lockable_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/arith/xor.rs b/vm/x86/x86emu/tests/tests/arith/xor.rs index daa023b09b..d568d3d6ec 100644 --- a/vm/x86/x86emu/tests/tests/arith/xor.rs +++ b/vm/x86/x86emu/tests/tests/arith/xor.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_LOGIC_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/cmpxchg816.rs b/vm/x86/x86emu/tests/tests/cmpxchg816.rs index 93977e7cba..e9a112f366 100644 --- a/vm/x86/x86emu/tests/tests/cmpxchg816.rs +++ b/vm/x86/x86emu/tests/tests/cmpxchg816.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_lockable_test; use crate::tests::common::LockTestBehavior; +use crate::tests::common::run_lockable_test; use iced_x86::code_asm::*; use x86defs::RFlags; use x86emu::Cpu; diff --git a/vm/x86/x86emu/tests/tests/common.rs b/vm/x86/x86emu/tests/tests/common.rs index 710c5010f1..6eaa7a0d1c 100644 --- a/vm/x86/x86emu/tests/tests/common.rs +++ b/vm/x86/x86emu/tests/tests/common.rs @@ -2,13 +2,13 @@ // Licensed under the MIT License. use futures::FutureExt; -use iced_x86::code_asm::CodeAssembler; use iced_x86::IcedError; +use iced_x86::code_asm::CodeAssembler; use std::fmt::Debug; -use x86defs::cpuid::Vendor; use x86defs::RFlags; use x86defs::SegmentAttributes; use x86defs::SegmentRegister; +use x86defs::cpuid::Vendor; use x86emu::Cpu; use x86emu::Emulator; use x86emu::Error; diff --git a/vm/x86/x86emu/tests/tests/mov/mod.rs b/vm/x86/x86emu/tests/tests/mov/mod.rs index bf5bb3b465..74bff50811 100644 --- a/vm/x86/x86emu/tests/tests/mov/mod.rs +++ b/vm/x86/x86emu/tests/tests/mov/mod.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::TestCpu; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86defs::RFlags; use x86emu::Cpu; diff --git a/vm/x86/x86emu/tests/tests/mov/others.rs b/vm/x86/x86emu/tests/tests/mov/others.rs index 5d204985f6..c44f20b56f 100644 --- a/vm/x86/x86emu/tests/tests/mov/others.rs +++ b/vm/x86/x86emu/tests/tests/mov/others.rs @@ -4,8 +4,8 @@ use super::RFLAGS_MOV_MASK; use crate::tests::common::run_test; use crate::tests::common::run_wide_test; -use iced_x86::code_asm::*; use iced_x86::Register; +use iced_x86::code_asm::*; use x86defs::RFlags; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/mov/xchg.rs b/vm/x86/x86emu/tests/tests/mov/xchg.rs index 4f5a69eead..899a9bdd79 100644 --- a/vm/x86/x86emu/tests/tests/mov/xchg.rs +++ b/vm/x86/x86emu/tests/tests/mov/xchg.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_lockable_test; use crate::tests::common::LockTestBehavior; +use crate::tests::common::run_lockable_test; use iced_x86::code_asm::dword_ptr; use iced_x86::code_asm::ebx; use x86emu::Cpu; diff --git a/vm/x86/x86emu/tests/tests/rep/cmps.rs b/vm/x86/x86emu/tests/tests/rep/cmps.rs index 5e04a42a09..4565d2e2d7 100644 --- a/vm/x86/x86emu/tests/tests/rep/cmps.rs +++ b/vm/x86/x86emu/tests/tests/rep/cmps.rs @@ -4,8 +4,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_wide_test; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::run_wide_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/rep/scas.rs b/vm/x86/x86emu/tests/tests/rep/scas.rs index c2afdf26f0..51acc3af85 100644 --- a/vm/x86/x86emu/tests/tests/rep/scas.rs +++ b/vm/x86/x86emu/tests/tests/rep/scas.rs @@ -1,10 +1,10 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_wide_test; use crate::tests::common::MultipleCellCpu; -use crate::tests::common::TestCpu; use crate::tests::common::RFLAGS_ARITH_MASK; +use crate::tests::common::TestCpu; +use crate::tests::common::run_wide_test; use futures::FutureExt; use iced_x86::code_asm::*; use x86defs::cpuid::Vendor; diff --git a/vm/x86/x86emu/tests/tests/segments.rs b/vm/x86/x86emu/tests/tests/segments.rs index f2a4b62a6e..bdebb937e1 100644 --- a/vm/x86/x86emu/tests/tests/segments.rs +++ b/vm/x86/x86emu/tests/tests/segments.rs @@ -6,9 +6,9 @@ use super::common::SingleCellCpu; use super::common::TestCpu; use futures::FutureExt; use iced_x86::code_asm::*; -use x86defs::cpuid::Vendor; use x86defs::SegmentAttributes; use x86defs::SegmentRegister; +use x86defs::cpuid::Vendor; use x86emu::Cpu; use x86emu::Emulator; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/shiftrotate/shift.rs b/vm/x86/x86emu/tests/tests/shiftrotate/shift.rs index ca2d634a1d..10772c446c 100644 --- a/vm/x86/x86emu/tests/tests/shiftrotate/shift.rs +++ b/vm/x86/x86emu/tests/tests/shiftrotate/shift.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_LOGIC_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vm/x86/x86emu/tests/tests/shiftrotate/shiftd.rs b/vm/x86/x86emu/tests/tests/shiftrotate/shiftd.rs index 4e6e766c35..c2a8e12740 100644 --- a/vm/x86/x86emu/tests/tests/shiftrotate/shiftd.rs +++ b/vm/x86/x86emu/tests/tests/shiftrotate/shiftd.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::tests::common::run_test; use crate::tests::common::RFLAGS_LOGIC_MASK; +use crate::tests::common::run_test; use iced_x86::code_asm::*; use x86emu::Cpu; use x86emu::Gp; diff --git a/vmm_core/src/acpi_builder.rs b/vmm_core/src/acpi_builder.rs index 1c8289df23..4f9a6ec774 100644 --- a/vmm_core/src/acpi_builder.rs +++ b/vmm_core/src/acpi_builder.rs @@ -16,10 +16,10 @@ use chipset::psp; use inspect::Inspect; use std::collections::BTreeMap; use vm_topology::memory::MemoryLayout; -use vm_topology::processor::aarch64::Aarch64Topology; -use vm_topology::processor::x86::X86Topology; use vm_topology::processor::ArchTopology; use vm_topology::processor::ProcessorTopology; +use vm_topology::processor::aarch64::Aarch64Topology; +use vm_topology::processor::x86::X86Topology; use x86defs::apic::APIC_BASE_ADDRESS; use zerocopy::IntoBytes; @@ -567,8 +567,8 @@ mod test { use memory_range::MemoryRange; use virt::VpIndex; use virt::VpInfo; - use vm_topology::processor::x86::X86VpInfo; use vm_topology::processor::TopologyBuilder; + use vm_topology::processor::x86::X86VpInfo; const KB: u64 = 1024; const MB: u64 = 1024 * KB; diff --git a/vmm_core/src/device_builder.rs b/vmm_core/src/device_builder.rs index 38b21ba7c2..7347ff2ecf 100644 --- a/vmm_core/src/device_builder.rs +++ b/vmm_core/src/device_builder.rs @@ -9,9 +9,9 @@ use guestmem::GuestMemory; use pci_core::msi::MsiInterruptSet; use pci_core::msi::MsiInterruptTarget; use std::sync::Arc; -use vm_resource::kind::PciDeviceHandleKind; use vm_resource::Resource; use vm_resource::ResourceResolver; +use vm_resource::kind::PciDeviceHandleKind; use vmbus_server::Guid; use vmbus_server::VmbusServerControl; use vmcore::vm_task::VmTaskDriverSource; diff --git a/vmm_core/src/input_distributor.rs b/vmm_core/src/input_distributor.rs index a0b2f604e0..6aafd50d85 100644 --- a/vmm_core/src/input_distributor.rs +++ b/vmm_core/src/input_distributor.rs @@ -7,14 +7,14 @@ use async_trait::async_trait; use futures::StreamExt; use futures_concurrency::stream::Merge; -use input_core::mesh_input::input_pair; -use input_core::mesh_input::MeshInputSink; -use input_core::mesh_input::MeshInputSource; use input_core::InputData; use input_core::KeyboardData; use input_core::MouseData; use input_core::MultiplexedInputHandle; use input_core::ResolvedInputSource; +use input_core::mesh_input::MeshInputSink; +use input_core::mesh_input::MeshInputSource; +use input_core::mesh_input::input_pair; use inspect::Inspect; use inspect::InspectMut; use mesh::rpc::Rpc; @@ -22,10 +22,10 @@ use mesh::rpc::RpcSend; use state_unit::StateRequest; use state_unit::StateUnit; use thiserror::Error; -use vm_resource::kind::KeyboardInputHandleKind; -use vm_resource::kind::MouseInputHandleKind; use vm_resource::AsyncResolveResource; use vm_resource::ResourceResolver; +use vm_resource::kind::KeyboardInputHandleKind; +use vm_resource::kind::MouseInputHandleKind; use vmcore::save_restore::RestoreError; use vmcore::save_restore::SaveError; use vmcore::save_restore::SavedStateBlob; diff --git a/vmm_core/src/partition_unit.rs b/vmm_core/src/partition_unit.rs index 748a4983f4..ec50080e02 100644 --- a/vmm_core/src/partition_unit.rs +++ b/vmm_core/src/partition_unit.rs @@ -6,12 +6,12 @@ mod debug; mod vp_set; -pub use vp_set::block_on_vp; pub use vp_set::Halt; pub use vp_set::RequestYield; pub use vp_set::RunCancelled; pub use vp_set::RunnerCanceller; pub use vp_set::VpRunner; +pub use vp_set::block_on_vp; use self::vp_set::RegisterSetError; use async_trait::async_trait; @@ -21,9 +21,9 @@ use guestmem::GuestMemory; use hvdef::Vtl; use inspect::InspectMut; use memory_range::MemoryRange; +use mesh::Receiver; use mesh::rpc::Rpc; use mesh::rpc::RpcSend; -use mesh::Receiver; use pal_async::task::Spawn; use state_unit::NameInUse; use state_unit::SpawnedUnit; diff --git a/vmm_core/src/partition_unit/debug.rs b/vmm_core/src/partition_unit/debug.rs index a95ae0a59a..a8ea45aae1 100644 --- a/vmm_core/src/partition_unit/debug.rs +++ b/vmm_core/src/partition_unit/debug.rs @@ -11,10 +11,10 @@ use anyhow::Context; use futures::StreamExt; use guestmem::GuestMemory; use virt::VpIndex; +use vmm_core_defs::HaltReason; use vmm_core_defs::debug_rpc::DebugRequest; use vmm_core_defs::debug_rpc::DebugStopReason; use vmm_core_defs::debug_rpc::GuestAddress; -use vmm_core_defs::HaltReason; pub struct DebuggerState { guest_memory: GuestMemory, diff --git a/vmm_core/src/partition_unit/vp_set.rs b/vmm_core/src/partition_unit/vp_set.rs index 6daab0e105..0903f3edc9 100644 --- a/vmm_core/src/partition_unit/vp_set.rs +++ b/vmm_core/src/partition_unit/vp_set.rs @@ -9,11 +9,11 @@ use super::InternalHaltReason; #[cfg(feature = "gdb")] use anyhow::Context as _; use async_trait::async_trait; +use futures::FutureExt; +use futures::StreamExt; use futures::future::JoinAll; use futures::future::TryJoinAll; use futures::stream::select_with_strategy; -use futures::FutureExt; -use futures::StreamExt; use futures_concurrency::future::Race; use futures_concurrency::stream::Merge; use guestmem::GuestMemory; @@ -24,17 +24,14 @@ use mesh::rpc::RpcError; use mesh::rpc::RpcSend; use parking_lot::Mutex; use slab::Slab; -use std::future::Future; -use std::pin::pin; use std::pin::Pin; +use std::pin::pin; use std::sync::Arc; use std::task::Context; use std::task::Poll; use std::task::Waker; use thiserror::Error; use tracing::instrument; -use virt::io::CpuIo; -use virt::vp::AccessVpState; use virt::InitialRegs; use virt::Processor; use virt::StopVp; @@ -42,6 +39,8 @@ use virt::StopVpSource; use virt::VpHaltReason; use virt::VpIndex; use virt::VpStopped; +use virt::io::CpuIo; +use virt::vp::AccessVpState; use vm_topology::processor::TargetVpInfo; use vmcore::save_restore::ProtobufSaveRestore; use vmcore::save_restore::RestoreError; diff --git a/vmm_core/src/synic.rs b/vmm_core/src/synic.rs index f853f1af63..72effd702e 100644 --- a/vmm_core/src/synic.rs +++ b/vmm_core/src/synic.rs @@ -6,8 +6,8 @@ use hvdef::HvResult; use hvdef::Vtl; use inspect::Inspect; use parking_lot::Mutex; -use std::collections::hash_map; use std::collections::HashMap; +use std::collections::hash_map; use std::fmt::Debug; use std::sync::Arc; use std::sync::Weak; @@ -99,7 +99,7 @@ impl SynicPortAccess for SynicPorts { ) -> Result, vmcore::synic::Error> { match self.ports.lock().entry(connection_id) { hash_map::Entry::Occupied(_) => { - return Err(vmcore::synic::Error::ConnectionIdInUse(connection_id)) + return Err(vmcore::synic::Error::ConnectionIdInUse(connection_id)); } hash_map::Entry::Vacant(e) => { e.insert(Port { @@ -131,7 +131,7 @@ impl SynicPortAccess for SynicPorts { match self.ports.lock().entry(connection_id) { hash_map::Entry::Occupied(_) => { - return Err(vmcore::synic::Error::ConnectionIdInUse(connection_id)) + return Err(vmcore::synic::Error::ConnectionIdInUse(connection_id)); } hash_map::Entry::Vacant(e) => { e.insert(Port { diff --git a/vmm_core/src/vmbus_unit.rs b/vmm_core/src/vmbus_unit.rs index 554a4682e4..54ec84ecaa 100644 --- a/vmm_core/src/vmbus_unit.rs +++ b/vmm_core/src/vmbus_unit.rs @@ -7,25 +7,25 @@ use inspect::Inspect; use pal_async::task::Spawn; -use state_unit::run_async_unit; use state_unit::NameInUse; use state_unit::SpawnedUnit; use state_unit::StateUnit; use state_unit::StateUnits; use state_unit::UnitBuilder; use state_unit::UnitHandle; +use state_unit::run_async_unit; use std::sync::Arc; -use vm_resource::kind::VmbusDeviceHandleKind; use vm_resource::Resource; use vm_resource::ResourceResolver; -use vmbus_channel::channel::offer_channel; -use vmbus_channel::channel::offer_generic_channel; +use vm_resource::kind::VmbusDeviceHandleKind; use vmbus_channel::channel::ChannelHandle; use vmbus_channel::channel::VmbusDevice; +use vmbus_channel::channel::offer_channel; +use vmbus_channel::channel::offer_generic_channel; use vmbus_channel::resources::ResolveVmbusDeviceHandleParams; -use vmbus_channel::simple::offer_simple_device; use vmbus_channel::simple::SimpleDeviceHandle; use vmbus_channel::simple::SimpleVmbusDevice; +use vmbus_channel::simple::offer_simple_device; use vmbus_server::VmbusServer; use vmbus_server::VmbusServerControl; use vmcore::save_restore::RestoreError; diff --git a/vmm_core/src/vmotherboard_adapter.rs b/vmm_core/src/vmotherboard_adapter.rs index 1c14faacca..9bc76166b2 100644 --- a/vmm_core/src/vmotherboard_adapter.rs +++ b/vmm_core/src/vmotherboard_adapter.rs @@ -8,8 +8,8 @@ use crate::partition_unit::Halt; use crate::synic::SynicPorts; use hvdef::Vtl; use std::sync::Arc; -use virt::io::CpuIo; use virt::VpIndex; +use virt::io::CpuIo; use vmm_core_defs::HaltReason; use vmotherboard::Chipset; @@ -58,39 +58,19 @@ impl CpuIo for ChipsetPlusSynic { .on_post_message(vtl, connection_id, secure, message) } - fn read_mmio( - &self, - vp: VpIndex, - address: u64, - data: &mut [u8], - ) -> impl std::future::Future { + fn read_mmio(&self, vp: VpIndex, address: u64, data: &mut [u8]) -> impl Future { self.chipset.mmio_read(vp.index(), address, data) } - fn write_mmio( - &self, - vp: VpIndex, - address: u64, - data: &[u8], - ) -> impl std::future::Future { + fn write_mmio(&self, vp: VpIndex, address: u64, data: &[u8]) -> impl Future { self.chipset.mmio_write(vp.index(), address, data) } - fn read_io( - &self, - vp: VpIndex, - port: u16, - data: &mut [u8], - ) -> impl std::future::Future { + fn read_io(&self, vp: VpIndex, port: u16, data: &mut [u8]) -> impl Future { self.chipset.io_read(vp.index(), port, data) } - fn write_io( - &self, - vp: VpIndex, - port: u16, - data: &[u8], - ) -> impl std::future::Future { + fn write_io(&self, vp: VpIndex, port: u16, data: &[u8]) -> impl Future { self.chipset.io_write(vp.index(), port, data) } } diff --git a/vmm_core/state_unit/src/lib.rs b/vmm_core/state_unit/src/lib.rs index 7752cac3b2..6ac21a14b1 100644 --- a/vmm_core/state_unit/src/lib.rs +++ b/vmm_core/state_unit/src/lib.rs @@ -28,34 +28,33 @@ //! This model allows for asynchronous, highly concurrent state changes, and it //! works across process boundaries thanks to `mesh`. -use futures::future::join_all; use futures::FutureExt; use futures::StreamExt; +use futures::future::join_all; use futures_concurrency::stream::Merge; use inspect::Inspect; use inspect::InspectMut; +use mesh::MeshPayload; +use mesh::Receiver; +use mesh::Sender; use mesh::payload::Protobuf; use mesh::rpc::FailableRpc; use mesh::rpc::Rpc; use mesh::rpc::RpcError; use mesh::rpc::RpcSend; -use mesh::MeshPayload; -use mesh::Receiver; -use mesh::Sender; use pal_async::task::Spawn; use pal_async::task::Task; use parking_lot::Mutex; -use std::collections::hash_map; use std::collections::BTreeMap; use std::collections::HashMap; +use std::collections::hash_map; use std::fmt::Debug; use std::fmt::Display; -use std::future::Future; use std::pin::pin; -use std::sync::atomic::AtomicU32; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::Weak; +use std::sync::atomic::AtomicU32; +use std::sync::atomic::Ordering; use std::time::Instant; use thiserror::Error; use tracing::Instrument; @@ -1098,11 +1097,11 @@ mod tests { use crate::run_unit; use inspect::InspectMut; use mesh::payload::Protobuf; - use pal_async::async_test; use pal_async::DefaultDriver; + use pal_async::async_test; + use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; - use std::sync::Arc; use std::time::Duration; use test_with_tracing::test; use vmcore::save_restore::RestoreError; diff --git a/vmm_core/virt/src/aarch64/vp.rs b/vmm_core/virt/src/aarch64/vp.rs index 686d231d60..2801f98039 100644 --- a/vmm_core/virt/src/aarch64/vp.rs +++ b/vmm_core/virt/src/aarch64/vp.rs @@ -2,9 +2,9 @@ // Licensed under the MIT License. use crate::aarch64::Aarch64PartitionCapabilities; -use crate::state::state_trait; use crate::state::HvRegisterState; use crate::state::StateElement; +use crate::state::state_trait; use aarch64defs::Cpsr64; use aarch64defs::SctlrEl1; use hvdef::HvArm64RegisterName; diff --git a/vmm_core/virt/src/generic.rs b/vmm_core/virt/src/generic.rs index 3680ce08a7..0dbe39337c 100644 --- a/vmm_core/virt/src/generic.rs +++ b/vmm_core/virt/src/generic.rs @@ -6,14 +6,14 @@ mod partition_memory_map; pub use partition_memory_map::PartitionMemoryMap; pub use vm_topology::processor::VpIndex; +use crate::CpuidLeaf; +use crate::PartitionCapabilities; use crate::io::CpuIo; use crate::irqcon::ControlGic; use crate::irqcon::IoApicRouting; use crate::irqcon::MsiRequest; use crate::x86::DebugState; use crate::x86::HardwareBreakpoint; -use crate::CpuidLeaf; -use crate::PartitionCapabilities; use guestmem::DoorbellRegistration; use guestmem::GuestMemory; use hvdef::Vtl; @@ -25,11 +25,10 @@ use std::cell::Cell; use std::convert::Infallible; use std::fmt::Debug; use std::future::poll_fn; -use std::future::Future; use std::pin::pin; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; -use std::sync::Arc; use std::task::Poll; use std::task::Waker; use vm_topology::memory::MemoryLayout; diff --git a/vmm_core/virt/src/io.rs b/vmm_core/virt/src/io.rs index 0284b25fe4..f59309e809 100644 --- a/vmm_core/virt/src/io.rs +++ b/vmm_core/virt/src/io.rs @@ -2,7 +2,6 @@ // Licensed under the MIT License. use hvdef::Vtl; -use std::future::Future; use vm_topology::processor::VpIndex; /// This trait provides the operations between the VP dispatch loop and the diff --git a/vmm_core/virt/src/lib.rs b/vmm_core/virt/src/lib.rs index 20951c3322..57a991b31a 100644 --- a/vmm_core/virt/src/lib.rs +++ b/vmm_core/virt/src/lib.rs @@ -20,18 +20,18 @@ mod arch { #[cfg(guest_arch = "x86_64")] mod x86 { #![cfg_attr(not(guest_arch = "x86_64"), allow(unused_imports))] - pub use crate::x86::vm; - pub use crate::x86::vp; pub use crate::x86::X86InitialRegs as InitialRegs; pub use crate::x86::X86PartitionCapabilities as PartitionCapabilities; + pub use crate::x86::vm; + pub use crate::x86::vp; } #[cfg(guest_arch = "aarch64")] mod aarch64 { #![cfg_attr(not(guest_arch = "aarch64"), allow(unused_imports))] - pub use crate::aarch64::vm; - pub use crate::aarch64::vp; pub use crate::aarch64::Aarch64InitialRegs as InitialRegs; pub use crate::aarch64::Aarch64PartitionCapabilities as PartitionCapabilities; + pub use crate::aarch64::vm; + pub use crate::aarch64::vp; } #[cfg(guest_arch = "aarch64")] diff --git a/vmm_core/virt/src/x86/apic_software_device.rs b/vmm_core/virt/src/x86/apic_software_device.rs index 10d9a95527..c3972ecf3d 100644 --- a/vmm_core/virt/src/x86/apic_software_device.rs +++ b/vmm_core/virt/src/x86/apic_software_device.rs @@ -11,17 +11,17 @@ use parking_lot::Mutex; use pci_core::msi::MsiControl; use pci_core::msi::MsiInterruptTarget; use slab::Slab; -use std::collections::hash_map; use std::collections::HashMap; +use std::collections::hash_map; use std::sync::Arc; use thiserror::Error; use vmcore::vpci_msi::MsiAddressData; use vmcore::vpci_msi::RegisterInterruptError; use vmcore::vpci_msi::VpciInterruptMapper; use vmcore::vpci_msi::VpciInterruptParameters; +use x86defs::msi::MSI_ADDRESS; use x86defs::msi::MsiAddress; use x86defs::msi::MsiData; -use x86defs::msi::MSI_ADDRESS; /// A set of software devices that can be used to implement VPCI devices on an /// APIC (x86) platform. diff --git a/vmm_core/virt/src/x86/mod.rs b/vmm_core/virt/src/x86/mod.rs index 1ccecc1259..c572933c1a 100644 --- a/vmm_core/virt/src/x86/mod.rs +++ b/vmm_core/virt/src/x86/mod.rs @@ -11,10 +11,10 @@ use crate::state::StateElement; use inspect::Inspect; use mesh_protobuf::Protobuf; use std::fmt::Debug; +use vm_topology::processor::ProcessorTopology; use vm_topology::processor::x86::ApicMode; use vm_topology::processor::x86::X86Topology; use vm_topology::processor::x86::X86VpInfo; -use vm_topology::processor::ProcessorTopology; use x86defs::cpuid::CpuidFunction; use x86defs::cpuid::SgxCpuidSubleafEax; use x86defs::cpuid::Vendor; diff --git a/vmm_core/virt/src/x86/vm.rs b/vmm_core/virt/src/x86/vm.rs index d01f053224..1dda3a92ae 100644 --- a/vmm_core/virt/src/x86/vm.rs +++ b/vmm_core/virt/src/x86/vm.rs @@ -4,9 +4,9 @@ //! Per-VM state. use super::X86PartitionCapabilities; -use crate::state::state_trait; use crate::state::HvRegisterState; use crate::state::StateElement; +use crate::state::state_trait; use hvdef::HvRegisterValue; use hvdef::HvX64RegisterName; use inspect::Inspect; diff --git a/vmm_core/virt/src/x86/vp.rs b/vmm_core/virt/src/x86/vp.rs index 7c8b814e43..2728b82767 100644 --- a/vmm_core/virt/src/x86/vp.rs +++ b/vmm_core/virt/src/x86/vp.rs @@ -6,9 +6,10 @@ use super::SegmentRegister; use super::TableRegister; use super::X86PartitionCapabilities; -use crate::state::state_trait; use crate::state::HvRegisterState; use crate::state::StateElement; +use crate::state::state_trait; +use hvdef::HV_MESSAGE_SIZE; use hvdef::HvInternalActivityRegister; use hvdef::HvRegisterValue; use hvdef::HvX64InterruptStateRegister; @@ -20,17 +21,21 @@ use hvdef::HvX64PendingInterruptionType; use hvdef::HvX64RegisterName; use hvdef::HvX64SegmentRegister; use hvdef::HvX64TableRegister; -use hvdef::HV_MESSAGE_SIZE; use inspect::Inspect; use mesh_protobuf::Protobuf; use std::fmt::Debug; use vm_topology::processor::x86::X86VpInfo; +use x86defs::RFlags; +use x86defs::X64_CR0_CD; +use x86defs::X64_CR0_ET; +use x86defs::X64_CR0_NW; +use x86defs::X64_EFER_NXE; +use x86defs::X86X_MSR_DEFAULT_PAT; +use x86defs::apic::APIC_BASE_PAGE; use x86defs::apic::ApicBase; use x86defs::apic::ApicVersion; -use x86defs::apic::APIC_BASE_PAGE; -use x86defs::xsave::Fxsave; -use x86defs::xsave::XsaveHeader; use x86defs::xsave::DEFAULT_MXCSR; +use x86defs::xsave::Fxsave; use x86defs::xsave::INIT_FCW; use x86defs::xsave::XCOMP_COMPRESSED; use x86defs::xsave::XFEATURE_SSE; @@ -38,12 +43,7 @@ use x86defs::xsave::XFEATURE_X87; use x86defs::xsave::XFEATURE_YMM; use x86defs::xsave::XSAVE_LEGACY_LEN; use x86defs::xsave::XSAVE_VARIABLE_OFFSET; -use x86defs::RFlags; -use x86defs::X64_CR0_CD; -use x86defs::X64_CR0_ET; -use x86defs::X64_CR0_NW; -use x86defs::X64_EFER_NXE; -use x86defs::X86X_MSR_DEFAULT_PAT; +use x86defs::xsave::XsaveHeader; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::Immutable; diff --git a/vmm_core/virt_hvf/src/abi.rs b/vmm_core/virt_hvf/src/abi.rs index a9e45654a1..983ac0420f 100644 --- a/vmm_core/virt_hvf/src/abi.rs +++ b/vmm_core/virt_hvf/src/abi.rs @@ -38,9 +38,15 @@ impl Display for HvfError { Self::SUCCESS => "The operation completed successfully.", Self::ERROR => "The operation was unsuccessful.", Self::BUSY => "The operation was unsuccessful because the owning resource was busy.", - Self::BAD_ARGUMENT => "The operation was unsuccessful because the function call had an invalid argument.", - Self::NO_RESOURCES => "The operation was unsuccessful because the host had no resources available to complete the request.", - Self::NO_DEVICE => "The operation was unsuccessful because no VM or vCPU was available.", + Self::BAD_ARGUMENT => { + "The operation was unsuccessful because the function call had an invalid argument." + } + Self::NO_RESOURCES => { + "The operation was unsuccessful because the host had no resources available to complete the request." + } + Self::NO_DEVICE => { + "The operation was unsuccessful because no VM or vCPU was available." + } Self::DENIED => "The system didn’t allow the requested operation.", // Self::FAULT => "", Self::UNSUPPORTED => "The operation requested isn’t supported by the hypervisor.", diff --git a/vmm_core/virt_hvf/src/hypercall.rs b/vmm_core/virt_hvf/src/hypercall.rs index 0b797a0186..e0b0ac09fc 100644 --- a/vmm_core/virt_hvf/src/hypercall.rs +++ b/vmm_core/virt_hvf/src/hypercall.rs @@ -3,18 +3,18 @@ //! Hypercall exit handling. -use crate::abi; use crate::HvfProcessor; +use crate::abi; use hv1_hypercall::Arm64RegisterState; use hv1_hypercall::GetVpRegisters; use hv1_hypercall::HvRepResult; use hv1_hypercall::PostMessage; use hv1_hypercall::SetVpRegisters; use hv1_hypercall::SignalEvent; -use hvdef::hypercall::HvRegisterAssoc; use hvdef::HvArm64RegisterName; use hvdef::HvError; use hvdef::Vtl; +use hvdef::hypercall::HvRegisterAssoc; use std::sync::atomic::Ordering; use virt::io::CpuIo; diff --git a/vmm_core/virt_hvf/src/lib.rs b/vmm_core/virt_hvf/src/lib.rs index 93e551e66b..fb4e3f96d7 100644 --- a/vmm_core/virt_hvf/src/lib.rs +++ b/vmm_core/virt_hvf/src/lib.rs @@ -14,15 +14,15 @@ mod hypercall; mod vp_state; use crate::hypercall::HvfHypercallHandler; -use aarch64defs::psci::FastCall; -use aarch64defs::psci::PsciCall; -use aarch64defs::psci::PsciError; -use aarch64defs::psci::PSCI; use aarch64defs::Cpsr64; use aarch64defs::ExceptionClass; use aarch64defs::IssDataAbort; use aarch64defs::IssSystem; use aarch64defs::MpidrEl1; +use aarch64defs::psci::FastCall; +use aarch64defs::psci::PSCI; +use aarch64defs::psci::PsciCall; +use aarch64defs::psci::PsciError; use abi::HvfError; use anyhow::Context; use guestmem::GuestMemory; @@ -41,26 +41,26 @@ use std::future::poll_fn; use std::ops::Deref; use std::ops::Range; use std::ptr::null_mut; -use std::sync::atomic::AtomicU64; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::Weak; -use std::task::ready; +use std::sync::atomic::AtomicU64; +use std::sync::atomic::Ordering; use std::task::Poll; use std::task::Waker; +use std::task::ready; use std::time::Duration; use thiserror::Error; -use virt::aarch64::vm::AccessVmState; -use virt::aarch64::Aarch64PartitionCapabilities; -use virt::io::CpuIo; -use virt::state::StateElement; -use virt::vp::AccessVpState; use virt::BindProcessor; use virt::NeedsYield; use virt::Processor; use virt::StopVp; use virt::VpHaltReason; use virt::VpIndex; +use virt::aarch64::Aarch64PartitionCapabilities; +use virt::aarch64::vm::AccessVmState; +use virt::io::CpuIo; +use virt::state::StateElement; +use virt::vp::AccessVpState; use virt_support_gic as gic; use vm_topology::processor::aarch64::Aarch64VpInfo; use vmcore::interrupt::Interrupt; @@ -775,87 +775,89 @@ impl<'p> Processor for HvfProcessor<'p> { loop { self.inner.needs_yield.maybe_yield().await; - poll_fn(|cx| loop { - stop.check()?; + poll_fn(|cx| { + loop { + stop.check()?; - if !last_waker - .as_ref() - .is_some_and(|waker| cx.waker().will_wake(waker)) - { - last_waker = Some(cx.waker().clone()); - self.inner.waker.write().clone_from(&last_waker); - } + if !last_waker + .as_ref() + .is_some_and(|waker| cx.waker().will_wake(waker)) + { + last_waker = Some(cx.waker().clone()); + self.inner.waker.write().clone_from(&last_waker); + } - if let Some(cpu_on) = self.inner.cpu_on.lock().take() { - if self.on { - todo!("block this"); - } else { - tracing::debug!(x0 = cpu_on.x0, pc = cpu_on.pc, "cpu on"); - self.vcpu.set_gp(0, cpu_on.x0).unwrap(); - self.vcpu.set_reg(abi::HvReg::PC, cpu_on.pc).unwrap(); - self.on = true; + if let Some(cpu_on) = self.inner.cpu_on.lock().take() { + if self.on { + todo!("block this"); + } else { + tracing::debug!(x0 = cpu_on.x0, pc = cpu_on.pc, "cpu on"); + self.vcpu.set_gp(0, cpu_on.x0).unwrap(); + self.vcpu.set_reg(abi::HvReg::PC, cpu_on.pc).unwrap(); + self.on = true; + } } - } - if !self.on { - break Poll::Pending; - } + if !self.on { + break Poll::Pending; + } - self.hv1 - .request_sint_readiness(self.inner.message_queues.pending_sints()); + self.hv1 + .request_sint_readiness(self.inner.message_queues.pending_sints()); - let ref_time_now = self.vmtime.now().as_100ns(); - let (ready_sints, next_ref_time) = self.hv1.scan( - ref_time_now, - &self.partition.guest_memory, - &mut |ppi, _auto_eoi| { - tracing::debug!(ppi, "ppi from message"); - self.gicr.raise(ppi); - }, - ); - - if let Some(next_ref_time) = next_ref_time { - // Convert from reference timer basis to vmtime basis via - // difference of programmed timer and current reference time. - const NUM_100NS_IN_SEC: u64 = 10 * 1000 * 1000; - let ref_diff = next_ref_time.saturating_sub(ref_time_now); - let ref_duration = Duration::new( - ref_diff / NUM_100NS_IN_SEC, - (ref_diff % NUM_100NS_IN_SEC) as u32 * 100, + let ref_time_now = self.vmtime.now().as_100ns(); + let (ready_sints, next_ref_time) = self.hv1.scan( + ref_time_now, + &self.partition.guest_memory, + &mut |ppi, _auto_eoi| { + tracing::debug!(ppi, "ppi from message"); + self.gicr.raise(ppi); + }, ); - let timeout = self.vmtime.now().wrapping_add(ref_duration); - self.vmtime.set_timeout_if_before(timeout); - } - if ready_sints != 0 { - self.deliver_sints(ready_sints); - continue; - } + if let Some(next_ref_time) = next_ref_time { + // Convert from reference timer basis to vmtime basis via + // difference of programmed timer and current reference time. + const NUM_100NS_IN_SEC: u64 = 10 * 1000 * 1000; + let ref_diff = next_ref_time.saturating_sub(ref_time_now); + let ref_duration = Duration::new( + ref_diff / NUM_100NS_IN_SEC, + (ref_diff % NUM_100NS_IN_SEC) as u32 * 100, + ); + let timeout = self.vmtime.now().wrapping_add(ref_duration); + self.vmtime.set_timeout_if_before(timeout); + } - if self.partition.gicd.irq_pending(&self.gicr) { - // SAFETY: no requirements. - unsafe { - abi::hv_vcpu_set_pending_interrupt( - self.vcpu.vcpu, - abi::HvInterruptType::IRQ, - true, - ) + if ready_sints != 0 { + self.deliver_sints(ready_sints); + continue; } - .chk() - .map_err(|err| VpHaltReason::Hypervisor(err.into()))?; - self.wfi = false; - } - if self.wfi { - self.vmtime.set_timeout_if_before( - self.vmtime.now().wrapping_add(Duration::from_millis(2)), - ); - ready!(self.vmtime.poll_timeout(cx)); - self.gicr.raise(PPI_VTIMER); - continue; - } + if self.partition.gicd.irq_pending(&self.gicr) { + // SAFETY: no requirements. + unsafe { + abi::hv_vcpu_set_pending_interrupt( + self.vcpu.vcpu, + abi::HvInterruptType::IRQ, + true, + ) + } + .chk() + .map_err(|err| VpHaltReason::Hypervisor(err.into()))?; + self.wfi = false; + } - break Poll::Ready(Result::<_, VpHaltReason<_>>::Ok(())); + if self.wfi { + self.vmtime.set_timeout_if_before( + self.vmtime.now().wrapping_add(Duration::from_millis(2)), + ); + ready!(self.vmtime.poll_timeout(cx)); + self.gicr.raise(PPI_VTIMER); + continue; + } + + break Poll::Ready(Result::<_, VpHaltReason<_>>::Ok(())); + } }) .await?; diff --git a/vmm_core/virt_hvf/src/vp_state.rs b/vmm_core/virt_hvf/src/vp_state.rs index 961230579a..feaeff9272 100644 --- a/vmm_core/virt_hvf/src/vp_state.rs +++ b/vmm_core/virt_hvf/src/vp_state.rs @@ -3,12 +3,12 @@ //! VP state handling. -use crate::abi; use crate::Error; use crate::HvfProcessor; +use crate::abi; use hvdef::HvArm64RegisterName; -use virt::aarch64::vp::AccessVpState; use virt::aarch64::Aarch64PartitionCapabilities; +use virt::aarch64::vp::AccessVpState; use virt::state::HvRegisterState; enum Reg { diff --git a/vmm_core/virt_kvm/src/arch/aarch64/mod.rs b/vmm_core/virt_kvm/src/arch/aarch64/mod.rs index 758f63f85b..c2d5121f43 100644 --- a/vmm_core/virt_kvm/src/arch/aarch64/mod.rs +++ b/vmm_core/virt_kvm/src/arch/aarch64/mod.rs @@ -20,9 +20,6 @@ use core::panic; use hvdef::Vtl; use inspect::Inspect; use inspect::InspectMut; -use kvm::kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V3; -use kvm::kvm_regs; -use kvm::user_pt_regs; use kvm::KVM_CAP_ARM_VM_IPA_SIZE; use kvm::KVM_DEV_ARM_VGIC_CTRL_INIT; use kvm::KVM_DEV_ARM_VGIC_GRP_ADDR; @@ -30,20 +27,23 @@ use kvm::KVM_DEV_ARM_VGIC_GRP_CTRL; use kvm::KVM_DEV_ARM_VGIC_GRP_NR_IRQS; use kvm::KVM_VGIC_V3_ADDR_TYPE_DIST; use kvm::KVM_VGIC_V3_ADDR_TYPE_REDIST; +use kvm::kvm_device_type_KVM_DEV_TYPE_ARM_VGIC_V3; +use kvm::kvm_regs; +use kvm::user_pt_regs; use std::convert::Infallible; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; -use std::sync::Arc; -use virt::io::CpuIo; -use virt::vp::Registers; -use virt::vp::SystemRegisters; -use virt::x86::DebugState; use virt::NeedsYield; use virt::PartitionCapabilities; use virt::ProtoPartitionConfig; use virt::StopVp; use virt::VpHaltReason; use virt::VpIndex; +use virt::io::CpuIo; +use virt::vp::Registers; +use virt::vp::SystemRegisters; +use virt::x86::DebugState; use vm_topology::processor::aarch64::Aarch64VpInfo; use vmcore::vmtime::VmTimeAccess; diff --git a/vmm_core/virt_kvm/src/arch/x86_64/mod.rs b/vmm_core/virt_kvm/src/arch/x86_64/mod.rs index 30ed35f57f..5e277bcb5c 100644 --- a/vmm_core/virt_kvm/src/arch/x86_64/mod.rs +++ b/vmm_core/virt_kvm/src/arch/x86_64/mod.rs @@ -9,18 +9,18 @@ mod regs; mod vm_state; mod vp_state; -use crate::gsi; -use crate::gsi::GsiRouting; use crate::KvmError; use crate::KvmPartition; use crate::KvmPartitionInner; use crate::KvmProcessorBinder; use crate::KvmRunVpError; +use crate::gsi; +use crate::gsi::GsiRouting; use guestmem::DoorbellRegistration; use guestmem::GuestMemory; use guestmem::GuestMemoryError; use hv1_emulator::message_queues::MessageQueues; -use hvdef::hypercall::Control; +use hvdef::HV_PAGE_SIZE; use hvdef::HvError; use hvdef::HvMessage; use hvdef::HvMessageType; @@ -28,12 +28,12 @@ use hvdef::HvSynicScontrol; use hvdef::HvSynicSimpSiefp; use hvdef::HypercallCode; use hvdef::Vtl; -use hvdef::HV_PAGE_SIZE; +use hvdef::hypercall::Control; use inspect::Inspect; use inspect::InspectMut; +use kvm::KVM_CPUID_FLAG_SIGNIFCANT_INDEX; use kvm::kvm_ioeventfd_flag_nr_datamatch; use kvm::kvm_ioeventfd_flag_nr_deassign; -use kvm::KVM_CPUID_FLAG_SIGNIFCANT_INDEX; use pal_event::Event; use parking_lot::Mutex; use parking_lot::RwLock; @@ -43,22 +43,13 @@ use std::convert::Infallible; use std::future::poll_fn; use std::io; use std::os::unix::prelude::*; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::Weak; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering; use std::task::Poll; use std::time::Duration; use thiserror::Error; -use virt::io::CpuIo; -use virt::irqcon::DeliveryMode; -use virt::irqcon::IoApicRouting; -use virt::irqcon::MsiRequest; -use virt::state::StateElement; -use virt::vm::AccessVmState; -use virt::x86::max_physical_address_size_from_cpuid; -use virt::x86::vp::AccessVpState; -use virt::x86::HardwareBreakpoint; use virt::CpuidLeaf; use virt::CpuidLeafSet; use virt::Hv1; @@ -73,6 +64,15 @@ use virt::ResetPartition; use virt::StopVp; use virt::VpHaltReason; use virt::VpIndex; +use virt::io::CpuIo; +use virt::irqcon::DeliveryMode; +use virt::irqcon::IoApicRouting; +use virt::irqcon::MsiRequest; +use virt::state::StateElement; +use virt::vm::AccessVmState; +use virt::x86::HardwareBreakpoint; +use virt::x86::max_physical_address_size_from_cpuid; +use virt::x86::vp::AccessVpState; use vm_topology::processor::x86::ApicMode; use vm_topology::processor::x86::X86VpInfo; use vmcore::interrupt::Interrupt; diff --git a/vmm_core/virt_kvm/src/arch/x86_64/vm_state.rs b/vmm_core/virt_kvm/src/arch/x86_64/vm_state.rs index d2aaeca5b1..11aff9ce12 100644 --- a/vmm_core/virt_kvm/src/arch/x86_64/vm_state.rs +++ b/vmm_core/virt_kvm/src/arch/x86_64/vm_state.rs @@ -3,10 +3,10 @@ use crate::KvmError; use crate::KvmPartition; +use virt::VpIndex; use virt::state::HvRegisterState; use virt::x86::vm; use virt::x86::vm::AccessVmState; -use virt::VpIndex; impl AccessVmState for &'_ KvmPartition { type Error = KvmError; diff --git a/vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs b/vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs index 6c8e1a20f6..ef213e05c2 100644 --- a/vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs +++ b/vmm_core/virt_kvm/src/arch/x86_64/vp_state.rs @@ -6,12 +6,12 @@ use crate::KvmError; use crate::KvmPartitionInner; use hvdef::HvRegisterValue; use hvdef::HvX64RegisterName; +use virt::VpIndex; use virt::state::HvRegisterState; -use virt::x86::vp; -use virt::x86::vp::AccessVpState; use virt::x86::SegmentRegister; use virt::x86::TableRegister; -use virt::VpIndex; +use virt::x86::vp; +use virt::x86::vp::AccessVpState; use vm_topology::processor::x86::X86VpInfo; use x86defs::SegmentAttributes; use zerocopy::FromZeros; @@ -285,7 +285,7 @@ impl AccessVpState for KvmVpStateAccess<'_> { vp::MpState::WaitForSipi => kvm::KVM_MP_STATE_INIT_RECEIVED, vp::MpState::Halted => kvm::KVM_MP_STATE_HALTED, vp::MpState::Idle => { - return Err(KvmError::InvalidState("Hyper-V idle state not supported")) + return Err(KvmError::InvalidState("Hyper-V idle state not supported")); } }; self.kvm().set_mp_state(state)?; diff --git a/vmm_core/virt_kvm/src/gsi.rs b/vmm_core/virt_kvm/src/gsi.rs index ba49cfcc39..fa81afaa70 100644 --- a/vmm_core/virt_kvm/src/gsi.rs +++ b/vmm_core/virt_kvm/src/gsi.rs @@ -7,10 +7,10 @@ use crate::KvmPartitionInner; use pal_event::Event; use parking_lot::Mutex; use std::os::unix::prelude::*; -use std::sync::atomic::AtomicBool; -use std::sync::atomic::Ordering; use std::sync::Arc; use std::sync::Weak; +use std::sync::atomic::AtomicBool; +use std::sync::atomic::Ordering; const NUM_GSIS: usize = 2048; diff --git a/vmm_core/virt_mshv/src/lib.rs b/vmm_core/virt_mshv/src/lib.rs index e6df422873..3544152a08 100644 --- a/vmm_core/virt_mshv/src/lib.rs +++ b/vmm_core/virt_mshv/src/lib.rs @@ -16,8 +16,6 @@ use guestmem::DoorbellRegistration; use guestmem::GuestMemory; use hv1_emulator::message_queues::MessageQueues; use hv1_hypercall::X64RegisterIo; -use hvdef::hypercall::HvRegisterAssoc; -use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_EXECUTE; use hvdef::HvDeliverabilityNotificationsRegister; use hvdef::HvError; use hvdef::HvMessage; @@ -25,8 +23,13 @@ use hvdef::HvMessageType; use hvdef::HvX64RegisterName; use hvdef::HvX64VpExecutionState; use hvdef::Vtl; +use hvdef::hypercall::HV_INTERCEPT_ACCESS_MASK_EXECUTE; +use hvdef::hypercall::HvRegisterAssoc; use inspect::Inspect; use inspect::InspectMut; +use mshv_bindings::HV_MAP_GPA_EXECUTABLE; +use mshv_bindings::HV_MAP_GPA_READABLE; +use mshv_bindings::HV_MAP_GPA_WRITABLE; use mshv_bindings::hv_message; use mshv_bindings::hv_register_assoc; use mshv_bindings::hv_register_value; @@ -36,14 +39,11 @@ use mshv_bindings::hv_x64_memory_intercept_message; use mshv_bindings::hv_x64_segment_register; use mshv_bindings::mshv_install_intercept; use mshv_bindings::mshv_user_mem_region; -use mshv_bindings::HV_MAP_GPA_EXECUTABLE; -use mshv_bindings::HV_MAP_GPA_READABLE; -use mshv_bindings::HV_MAP_GPA_WRITABLE; -use mshv_ioctls::set_registers_64; use mshv_ioctls::InterruptRequest; use mshv_ioctls::Mshv; use mshv_ioctls::VcpuFd; use mshv_ioctls::VmFd; +use mshv_ioctls::set_registers_64; use pal::unix::pthread::*; use pal_event::Event; use parking_lot::Mutex; @@ -54,9 +54,6 @@ use std::sync::Arc; use std::sync::Once; use std::sync::Weak; use thiserror::Error; -use virt::io::CpuIo; -use virt::irqcon::MsiRequest; -use virt::x86::max_physical_address_size_from_cpuid; use virt::Hv1; use virt::NeedsYield; use virt::PartitionAccessState; @@ -66,12 +63,15 @@ use virt::ProtoPartitionConfig; use virt::StopVp; use virt::VpHaltReason; use virt::VpIndex; -use virt_support_x86emu::emulate::emulate_translate_gva; +use virt::io::CpuIo; +use virt::irqcon::MsiRequest; +use virt::x86::max_physical_address_size_from_cpuid; use virt_support_x86emu::emulate::EmuTranslateError; use virt_support_x86emu::emulate::EmuTranslateResult; use virt_support_x86emu::emulate::EmulatorSupport; use virt_support_x86emu::emulate::TranslateGvaSupport; use virt_support_x86emu::emulate::TranslateMode; +use virt_support_x86emu::emulate::emulate_translate_gva; use virt_support_x86emu::translate::TranslationRegisters; use vmcore::interrupt::Interrupt; use vmcore::synic::GuestEventPort; diff --git a/vmm_core/virt_mshv/src/vp_state.rs b/vmm_core/virt_mshv/src/vp_state.rs index 6906ba1ea6..21f8ac6974 100644 --- a/vmm_core/virt_mshv/src/vp_state.rs +++ b/vmm_core/virt_mshv/src/vp_state.rs @@ -3,8 +3,8 @@ use super::Error; use crate::MshvProcessor; -use hvdef::hypercall::HvRegisterAssoc; use hvdef::HvX64RegisterName; +use hvdef::hypercall::HvRegisterAssoc; use mshv_bindings::hv_register_assoc; use static_assertions::assert_eq_size; use std::mem::offset_of; diff --git a/vmm_core/virt_support_aarch64emu/src/emulate.rs b/vmm_core/virt_support_aarch64emu/src/emulate.rs index d6078af8b8..48726642ee 100644 --- a/vmm_core/virt_support_aarch64emu/src/emulate.rs +++ b/vmm_core/virt_support_aarch64emu/src/emulate.rs @@ -11,14 +11,14 @@ use aarch64emu::AccessCpuState; use aarch64emu::InterceptState; use guestmem::GuestMemory; use guestmem::GuestMemoryError; +use hvdef::HV_PAGE_SIZE; use hvdef::HvAarch64PendingEvent; use hvdef::HvAarch64PendingEventType; use hvdef::HvInterceptAccessType; use hvdef::HvMapGpaFlags; -use hvdef::HV_PAGE_SIZE; use thiserror::Error; -use virt::io::CpuIo; use virt::VpHaltReason; +use virt::io::CpuIo; use vm_topology::processor::VpIndex; use zerocopy::FromBytes; use zerocopy::IntoBytes; diff --git a/vmm_core/virt_support_aarch64emu/src/translate.rs b/vmm_core/virt_support_aarch64emu/src/translate.rs index 52c0e6bd38..2c70167a09 100644 --- a/vmm_core/virt_support_aarch64emu/src/translate.rs +++ b/vmm_core/virt_support_aarch64emu/src/translate.rs @@ -20,9 +20,9 @@ use aarch64defs::TranslationControlEl1; use aarch64defs::TranslationGranule0; use aarch64defs::TranslationGranule1; use guestmem::GuestMemory; +use hvdef::HV_PAGE_SHIFT; use hvdef::hypercall::TranslateGvaControlFlagsArm64; use hvdef::hypercall::TranslateGvaResultCode; -use hvdef::HV_PAGE_SHIFT; use thiserror::Error; /// Registers needed to walk the page table. @@ -537,7 +537,7 @@ pub fn translate_gva_to_gpa( &mut is_executable_address, )? { PageTableWalkResult::BaseGpa(base_address, mask) => { - break Ok(base_address + (gva & mask)) + break Ok(base_address + (gva & mask)); } PageTableWalkResult::Table(next_table) => next_table, }; diff --git a/vmm_core/virt_support_apic/src/lib.rs b/vmm_core/virt_support_apic/src/lib.rs index 58aa36c955..bfef89d67e 100644 --- a/vmm_core/virt_support_apic/src/lib.rs +++ b/vmm_core/virt_support_apic/src/lib.rs @@ -12,17 +12,19 @@ use bitfield_struct::bitfield; use inspect::Inspect; use inspect_counters::Counter; use parking_lot::RwLock; +use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; -use std::sync::Arc; use std::time::Duration; use thiserror::Error; -use virt::x86::vp::ApicRegisters; use virt::x86::MsrError; -use vm_topology::processor::x86::X86VpInfo; +use virt::x86::vp::ApicRegisters; use vm_topology::processor::VpIndex; +use vm_topology::processor::x86::X86VpInfo; use vmcore::vmtime::VmTime; use vmcore::vmtime::VmTimeAccess; +use x86defs::X86X_MSR_APIC_BASE; +use x86defs::apic::APIC_BASE_PAGE; use x86defs::apic::ApicBase; use x86defs::apic::ApicRegister; use x86defs::apic::Dcr; @@ -33,14 +35,12 @@ use x86defs::apic::Icr; use x86defs::apic::Lvt; use x86defs::apic::Svr; use x86defs::apic::TimerMode; -use x86defs::apic::X2ApicLogicalId; -use x86defs::apic::XApicClusterLogicalId; -use x86defs::apic::APIC_BASE_PAGE; use x86defs::apic::X2APIC_MSR_BASE; use x86defs::apic::X2APIC_MSR_END; +use x86defs::apic::X2ApicLogicalId; +use x86defs::apic::XApicClusterLogicalId; use x86defs::msi::MsiAddress; use x86defs::msi::MsiData; -use x86defs::X86X_MSR_APIC_BASE; const NANOS_PER_TICK: u64 = 5; // 200Mhz const TIMER_FREQUENCY: u64 = 1_000_000_000 / NANOS_PER_TICK; @@ -771,7 +771,7 @@ impl LocalApicAccess<'_, T> { TIMER_FREQUENCY } hvdef::HV_X64_MSR_EOI if self.apic.global.hyperv_enlightenments => { - return Err(MsrError::InvalidAccess) + return Err(MsrError::InvalidAccess); } hvdef::HV_X64_MSR_ICR if self.apic.global.hyperv_enlightenments => { if !self.apic.hardware_enabled() { @@ -813,7 +813,7 @@ impl LocalApicAccess<'_, T> { } } hvdef::HV_X64_MSR_APIC_FREQUENCY if self.apic.global.hyperv_enlightenments => { - return Err(MsrError::InvalidAccess) + return Err(MsrError::InvalidAccess); } hvdef::HV_X64_MSR_EOI if self.apic.global.hyperv_enlightenments => { if !self.apic.hardware_enabled() { diff --git a/vmm_core/virt_support_gic/src/lib.rs b/vmm_core/virt_support_gic/src/lib.rs index 1ca9d237da..c9163f1137 100644 --- a/vmm_core/virt_support_gic/src/lib.rs +++ b/vmm_core/virt_support_gic/src/lib.rs @@ -10,15 +10,15 @@ pub use gicd::Distributor; pub use gicr::Redistributor; mod gicd { - use super::gicr::SharedState; use super::Redistributor; + use super::gicr::SharedState; + use aarch64defs::MpidrEl1; + use aarch64defs::SystemReg; use aarch64defs::gic::GicdCtlr; use aarch64defs::gic::GicdRegister; use aarch64defs::gic::GicdTyper; use aarch64defs::gic::GicdTyper2; use aarch64defs::gic::GicrSgi; - use aarch64defs::MpidrEl1; - use aarch64defs::SystemReg; use inspect::Inspect; use memory_range::MemoryRange; use parking_lot::Mutex; @@ -497,17 +497,17 @@ mod gicd { } mod gicr { + use aarch64defs::MpidrEl1; use aarch64defs::gic::GicrCtlr; use aarch64defs::gic::GicrRdRegister; use aarch64defs::gic::GicrSgiRegister; use aarch64defs::gic::GicrTyper; use aarch64defs::gic::GicrWaker; - use aarch64defs::MpidrEl1; use inspect::Inspect; use parking_lot::Mutex; + use std::sync::Arc; use std::sync::atomic::AtomicU32; use std::sync::atomic::Ordering; - use std::sync::Arc; #[derive(Debug, Inspect)] pub struct Redistributor { diff --git a/vmm_core/virt_support_x86emu/src/emulate.rs b/vmm_core/virt_support_x86emu/src/emulate.rs index 6a85143a17..c66021c109 100644 --- a/vmm_core/virt_support_x86emu/src/emulate.rs +++ b/vmm_core/virt_support_x86emu/src/emulate.rs @@ -3,17 +3,17 @@ //! Wrapper around x86emu for emulating single instructions to handle VM exits. -use crate::translate::translate_gva_to_gpa; use crate::translate::TranslateFlags; use crate::translate::TranslatePrivilegeCheck; +use crate::translate::translate_gva_to_gpa; use guestmem::GuestMemory; use guestmem::GuestMemoryError; +use hvdef::HV_PAGE_SIZE; use hvdef::HvInterceptAccessType; use hvdef::HvMapGpaFlags; -use hvdef::HV_PAGE_SIZE; use thiserror::Error; -use virt::io::CpuIo; use virt::VpHaltReason; +use virt::io::CpuIo; use vm_topology::processor::VpIndex; use x86defs::Exception; use x86defs::RFlags; diff --git a/vmm_core/virt_support_x86emu/tests/tests/checkvtlaccess.rs b/vmm_core/virt_support_x86emu/tests/tests/checkvtlaccess.rs index 2281a986a6..65db238247 100644 --- a/vmm_core/virt_support_x86emu/tests/tests/checkvtlaccess.rs +++ b/vmm_core/virt_support_x86emu/tests/tests/checkvtlaccess.rs @@ -8,8 +8,8 @@ use iced_x86::code_asm::*; use pal_async::async_test; use virt_support_x86emu::emulate::*; use vm_topology::processor::VpIndex; -use x86defs::cpuid::Vendor; use x86defs::RFlags; +use x86defs::cpuid::Vendor; use x86emu::Gp; use x86emu::Segment; use zerocopy::FromBytes; diff --git a/vmm_core/virt_support_x86emu/tests/tests/common.rs b/vmm_core/virt_support_x86emu/tests/tests/common.rs index 353a7bb399..e9f8e752be 100644 --- a/vmm_core/virt_support_x86emu/tests/tests/common.rs +++ b/vmm_core/virt_support_x86emu/tests/tests/common.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use virt::io::CpuIo; use virt::VpIndex; +use virt::io::CpuIo; use x86defs::RFlags; use x86defs::SegmentAttributes; use x86defs::SegmentRegister; diff --git a/vmm_core/virt_support_x86emu/tests/tests/emulate.rs b/vmm_core/virt_support_x86emu/tests/tests/emulate.rs index d708a901ce..8bd34700a3 100644 --- a/vmm_core/virt_support_x86emu/tests/tests/emulate.rs +++ b/vmm_core/virt_support_x86emu/tests/tests/emulate.rs @@ -6,12 +6,12 @@ use guestmem::GuestMemory; use iced_x86::code_asm::CodeAssembler; use pal_async::async_test; use virt::VpIndex; -use virt_support_x86emu::emulate::emulate; use virt_support_x86emu::emulate::EmuTranslateError; use virt_support_x86emu::emulate::EmuTranslateResult; use virt_support_x86emu::emulate::EmulatorSupport; -use x86defs::cpuid::Vendor; +use virt_support_x86emu::emulate::emulate; use x86defs::RFlags; +use x86defs::cpuid::Vendor; use x86emu::Gp; use x86emu::Segment; diff --git a/vmm_core/virt_support_x86emu/tests/tests/translate.rs b/vmm_core/virt_support_x86emu/tests/tests/translate.rs index af315790a6..c09c5ac0c0 100644 --- a/vmm_core/virt_support_x86emu/tests/tests/translate.rs +++ b/vmm_core/virt_support_x86emu/tests/tests/translate.rs @@ -8,8 +8,8 @@ use iced_x86::code_asm::*; use pal_async::async_test; use virt_support_x86emu::emulate::*; use vm_topology::processor::VpIndex; -use x86defs::cpuid::Vendor; use x86defs::RFlags; +use x86defs::cpuid::Vendor; use x86emu::Gp; use x86emu::Segment; use zerocopy::IntoBytes; @@ -253,7 +253,10 @@ impl EmulatorSupport for MockSupport { // located at a previously translated gva. Just return the gva. gva } else { - panic!("accessing {:x}, not the expected gva {:x}; was the instruction stream created incorrectly?", gva, test_gva) + panic!( + "accessing {:x}, not the expected gva {:x}; was the instruction stream created incorrectly?", + gva, test_gva + ) }; println!("translated gva {:x} to {:x}", gva, gpa); diff --git a/vmm_core/virt_whp/src/apic.rs b/vmm_core/virt_whp/src/apic.rs index 6ff3fd5bcf..616fbe60c1 100644 --- a/vmm_core/virt_whp/src/apic.rs +++ b/vmm_core/virt_whp/src/apic.rs @@ -8,26 +8,26 @@ #![cfg(guest_arch = "x86_64")] -use crate::vp::WhpRunVpError; use crate::Error; use crate::LocalApicKind; use crate::WhpPartitionInner; use crate::WhpProcessor; use crate::WhpResultExt; use crate::WhpVpRef; +use crate::vp::WhpRunVpError; use hvdef::HvVtlEntryReason; use hvdef::HvX64PendingEventReg0; use hvdef::HvX64PendingInterruptionRegister; use hvdef::Vtl; use inspect::Inspect; use std::sync::atomic::Ordering; +use virt::VpIndex; use virt::io::CpuIo; use virt::irqcon::MsiRequest; +use virt::x86::MsrError; use virt::x86::vp; use virt::x86::vp::hv_apic_nmi_pending; use virt::x86::vp::set_hv_apic_nmi_pending; -use virt::x86::MsrError; -use virt::VpIndex; use virt_support_apic::ApicClient; use virt_support_apic::ApicWork; use virt_support_apic::LocalApic; diff --git a/vmm_core/virt_whp/src/device.rs b/vmm_core/virt_whp/src/device.rs index 3b2b6a4a64..bc0eb75b78 100644 --- a/vmm_core/virt_whp/src/device.rs +++ b/vmm_core/virt_whp/src/device.rs @@ -2,10 +2,10 @@ // Licensed under the MIT License. use super::WhpPartitionInner; +use chipset_device::ChipsetDevice; use chipset_device::io::IoResult; use chipset_device::mmio::MmioIntercept; use chipset_device::pci::PciConfigSpace; -use chipset_device::ChipsetDevice; use hv1_hypercall::HvInterruptParameters; use hvdef::Vtl; use inspect::InspectMut; diff --git a/vmm_core/virt_whp/src/emu.rs b/vmm_core/virt_whp/src/emu.rs index 082f09506c..795e0a5f13 100644 --- a/vmm_core/virt_whp/src/emu.rs +++ b/vmm_core/virt_whp/src/emu.rs @@ -3,18 +3,18 @@ #![cfg(guest_arch = "x86_64")] +use crate::WhpProcessor; use crate::memory::x86::GpaBackingType; use crate::vp::WhpRunVpError; -use crate::WhpProcessor; -use hvdef::Vtl; use hvdef::HV_PAGE_SIZE; -use virt::io::CpuIo; +use hvdef::Vtl; use virt::VpIndex; -use virt_support_x86emu::emulate::emulate_translate_gva; +use virt::io::CpuIo; use virt_support_x86emu::emulate::EmuTranslateError; use virt_support_x86emu::emulate::EmuTranslateResult; use virt_support_x86emu::emulate::TranslateGvaSupport; use virt_support_x86emu::emulate::TranslateMode; +use virt_support_x86emu::emulate::emulate_translate_gva; use virt_support_x86emu::translate::TranslationRegisters; use x86defs::RFlags; use x86defs::SegmentRegister; diff --git a/vmm_core/virt_whp/src/hypercalls.rs b/vmm_core/virt_whp/src/hypercalls.rs index 6a900ae213..67d8e2f141 100644 --- a/vmm_core/virt_whp/src/hypercalls.rs +++ b/vmm_core/virt_whp/src/hypercalls.rs @@ -1,27 +1,27 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::memory::VtlAccess; -use crate::vtl2; use crate::Hv1State; use crate::WhpProcessor; +use crate::memory::VtlAccess; +use crate::vtl2; #[cfg(guest_arch = "aarch64")] use aarch64 as arch; use hv1_hypercall::HvRepResult; -use hvdef::hypercall::HostVisibilityType; -use hvdef::hypercall::HvInterceptType; -use hvdef::HvError; -use hvdef::HvMapGpaFlags; -use hvdef::Vtl; use hvdef::HV_PAGE_SIZE; use hvdef::HV_PARTITION_ID_SELF; use hvdef::HV_VP_INDEX_SELF; +use hvdef::HvError; +use hvdef::HvMapGpaFlags; +use hvdef::Vtl; +use hvdef::hypercall::HostVisibilityType; +use hvdef::hypercall::HvInterceptType; use memory_range::MemoryRange; use std::iter::zip; use std::ops::RangeInclusive; -use virt::io::CpuIo; use virt::PageVisibility; use virt::VpIndex; +use virt::io::CpuIo; #[cfg(guest_arch = "x86_64")] use x86 as arch; @@ -683,18 +683,19 @@ impl hv1_hypercall::ModifySparseGpaPageHostVisibility for WhpHypercall #[cfg(guest_arch = "x86_64")] mod x86 { use super::WhpHypercallExit; - use crate::regs; - use crate::vtl2; use crate::WhpProcessor; use crate::WhpRunVpError; + use crate::regs; + use crate::vtl2; use arrayvec::ArrayVec; use hv1_hypercall::HvInterruptParameters; use hv1_hypercall::HvRepResult; use hv1_hypercall::HypercallIo; use hv1_hypercall::SignalEventDirect; use hv1_hypercall::TranslateVirtualAddressExX64; - use hvdef::hypercall::TranslateGvaControlFlagsX64; - use hvdef::hypercall::TranslateGvaResultCode; + use hvdef::HV_PAGE_SIZE; + use hvdef::HV_PARTITION_ID_SELF; + use hvdef::HV_VP_INDEX_SELF; use hvdef::HvError; use hvdef::HvInterceptAccessType; use hvdef::HvInterruptType; @@ -706,21 +707,20 @@ mod x86 { use hvdef::HvVpAssistPageActionSignalEvent; use hvdef::HvX64RegisterName; use hvdef::Vtl; - use hvdef::HV_PAGE_SIZE; - use hvdef::HV_PARTITION_ID_SELF; - use hvdef::HV_VP_INDEX_SELF; + use hvdef::hypercall::TranslateGvaControlFlagsX64; + use hvdef::hypercall::TranslateGvaResultCode; use std::mem::offset_of; use std::sync::atomic::Ordering; use tracing_helpers::ErrorValueExt; - use virt::io::CpuIo; use virt::VpIndex; - use virt_support_x86emu::translate::translate_gva_to_gpa; + use virt::io::CpuIo; use virt_support_x86emu::translate::TranslateFlags; use virt_support_x86emu::translate::TranslateResult; + use virt_support_x86emu::translate::translate_gva_to_gpa; use vmcore::vpci_msi::VpciInterruptParameters; - use whp::abi::WHV_REGISTER_VALUE; use whp::RegisterName; use whp::RegisterValue; + use whp::abi::WHV_REGISTER_VALUE; use zerocopy::FromBytes; use zerocopy::FromZeros; use zerocopy::IntoBytes; @@ -1670,24 +1670,24 @@ mod x86 { #[cfg(guest_arch = "aarch64")] mod aarch64 { use super::WhpHypercallExit; - use crate::regs; use crate::WhpProcessor; + use crate::regs; use arrayvec::ArrayVec; - use hvdef::hypercall::TranslateGvaControlFlagsArm64; - use hvdef::hypercall::TranslateGvaResultCode; + use hvdef::HV_PAGE_SIZE; + use hvdef::HV_PARTITION_ID_SELF; + use hvdef::HV_VP_INDEX_SELF; use hvdef::HvArm64RegisterName; use hvdef::HvError; use hvdef::HvRegisterName; use hvdef::HvRegisterValue; use hvdef::HvResult; use hvdef::Vtl; - use hvdef::HV_PAGE_SIZE; - use hvdef::HV_PARTITION_ID_SELF; - use hvdef::HV_VP_INDEX_SELF; + use hvdef::hypercall::TranslateGvaControlFlagsArm64; + use hvdef::hypercall::TranslateGvaResultCode; use virt::io::CpuIo; - use virt_support_aarch64emu::translate::translate_gva_to_gpa; use virt_support_aarch64emu::translate::TranslateFlags; use virt_support_aarch64emu::translate::TranslationRegisters; + use virt_support_aarch64emu::translate::translate_gva_to_gpa; use whp::RegisterValue; use zerocopy::FromZeros; diff --git a/vmm_core/virt_whp/src/lib.rs b/vmm_core/virt_whp/src/lib.rs index 260da44402..d2f17a67cf 100644 --- a/vmm_core/virt_whp/src/lib.rs +++ b/vmm_core/virt_whp/src/lib.rs @@ -44,14 +44,11 @@ use range_map_vec::RangeMap; use std::convert::Infallible; use std::ops::Index; use std::ops::IndexMut; +use std::sync::Arc; use std::sync::atomic::AtomicBool; use std::sync::atomic::Ordering; -use std::sync::Arc; use std::task::Waker; use thiserror::Error; -use virt::io::CpuIo; -use virt::irqcon::MsiRequest; -use virt::vm::AccessVmState; use virt::IsolationType; use virt::NeedsYield; use virt::PageVisibility; @@ -62,6 +59,9 @@ use virt::ProtoPartitionConfig; use virt::StopVp; use virt::VpHaltReason; use virt::VpIndex; +use virt::io::CpuIo; +use virt::irqcon::MsiRequest; +use virt::vm::AccessVmState; use vm_topology::memory::MemoryLayout; use vm_topology::processor::TargetVpInfo; use vmcore::monitor::MonitorPage; @@ -1575,8 +1575,8 @@ mod x86 { use crate::WhpPartition; use crate::WhpPartitionInner; use hvdef::Vtl; - use virt::irqcon::MsiRequest; use virt::VpIndex; + use virt::irqcon::MsiRequest; impl WhpPartitionInner { pub(crate) fn synic_interrupt( @@ -1634,8 +1634,8 @@ mod aarch64 { use crate::WhpPartitionAndVtl; use crate::WhpPartitionInner; use hvdef::Vtl; - use virt::irqcon::MsiRequest; use virt::VpIndex; + use virt::irqcon::MsiRequest; impl WhpPartitionInner { pub(crate) fn synic_interrupt( diff --git a/vmm_core/virt_whp/src/memory.rs b/vmm_core/virt_whp/src/memory.rs index 351135f199..631e4a84b6 100644 --- a/vmm_core/virt_whp/src/memory.rs +++ b/vmm_core/virt_whp/src/memory.rs @@ -386,9 +386,11 @@ impl VtlPartition { ) -> Result<(), virt::Error> { let range = MemoryRange::new(addr..addr + size as u64); let mut ranges = self.ranges.write(); - assert!(ranges - .iter() - .all(|r| range.contains(&r.range) || !range.overlaps(&r.range))); + assert!( + ranges + .iter() + .all(|r| range.contains(&r.range) || !range.overlaps(&r.range)) + ); // SAFETY: Caller must past valid arguments. unsafe { @@ -775,8 +777,8 @@ pub(crate) mod x86 { use super::VtlAccess; use crate::VtlPartition; use crate::WhpPartitionInner; - use hvdef::Vtl; use hvdef::HV_PAGE_SIZE; + use hvdef::Vtl; /// Different backing types for a given GPA. #[derive(Debug, Clone, Copy, PartialEq, Eq)] diff --git a/vmm_core/virt_whp/src/synic.rs b/vmm_core/virt_whp/src/synic.rs index 88da55b38e..4c9d336ea7 100644 --- a/vmm_core/virt_whp/src/synic.rs +++ b/vmm_core/virt_whp/src/synic.rs @@ -6,10 +6,10 @@ use crate::WhpPartition; use crate::WhpPartitionAndVtl; use crate::WhpPartitionInner; use guestmem::DoorbellRegistration; +use hvdef::HV_PAGE_SIZE_USIZE; use hvdef::HvError; use hvdef::HvMessageType; use hvdef::Vtl; -use hvdef::HV_PAGE_SIZE_USIZE; use pal_event::Event; use parking_lot::Mutex; use sparse_mmap::alloc::Allocation; diff --git a/vmm_core/virt_whp/src/vp.rs b/vmm_core/virt_whp/src/vp.rs index 5d836bcdb8..35362ce5ec 100644 --- a/vmm_core/virt_whp/src/vp.rs +++ b/vmm_core/virt_whp/src/vp.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::vtl2::Vtl2InterceptState; use super::Vplc; use super::VtlPartition; +use super::vtl2::Vtl2InterceptState; use crate::WhpProcessor; use guestmem::GuestMemoryError; use hvdef::HvDeliverabilityNotificationsRegister; @@ -21,10 +21,10 @@ use std::sync::atomic::Ordering; use std::task::Poll; use thiserror::Error; use tracing_helpers::ErrorValueExt; -use virt::io::CpuIo; -use virt::vp::AccessVpState; use virt::StopVp; use virt::VpHaltReason; +use virt::io::CpuIo; +use virt::vp::AccessVpState; use zerocopy::IntoBytes; #[derive(Debug, Error)] @@ -570,31 +570,31 @@ impl<'a> WhpProcessor<'a> { #[cfg(guest_arch = "x86_64")] mod x86 { use super::WhpRunVpError; + use crate::Hv1State; + use crate::WhpProcessor; use crate::emu; use crate::emu::WhpVpRefEmulation; use crate::memory::x86::GpaBackingType; use crate::vtl2; - use crate::Hv1State; - use crate::WhpProcessor; - use hvdef::hypercall::InitialVpContextX64; use hvdef::HvCacheType; use hvdef::HvInterceptAccessType; use hvdef::HvMessageType; use hvdef::HvVtlEntryReason; use hvdef::HvX64VpExecutionState; use hvdef::Vtl; + use hvdef::hypercall::InitialVpContextX64; + use virt::LateMapVtl0MemoryPolicy; + use virt::VpHaltReason; use virt::io::CpuIo; use virt::state::StateElement; use virt::x86::MsrError; use virt::x86::MsrErrorExt; - use virt::LateMapVtl0MemoryPolicy; - use virt::VpHaltReason; use whp::get_registers; use whp::set_registers; + use x86defs::X86X_MSR_APIC_BASE; use x86defs::apic::X2APIC_MSR_BASE; use x86defs::apic::X2APIC_MSR_END; use x86defs::cpuid::CpuidFunction; - use x86defs::X86X_MSR_APIC_BASE; use zerocopy::FromZeros; use zerocopy::IntoBytes; @@ -1732,8 +1732,8 @@ mod aarch64 { use aarch64defs::IssDataAbort; use hvdef::HvMessageType; use hvdef::Vtl; - use virt::io::CpuIo; use virt::VpHaltReason; + use virt::io::CpuIo; impl WhpProcessor<'_> { pub(super) fn process_apic(&mut self, _dev: &impl CpuIo) -> Result { @@ -1896,7 +1896,7 @@ mod aarch64 { ec => { return Err(VpHaltReason::EmulationFailure( anyhow::anyhow!("unknown memory access exception: {ec:?}").into(), - )) + )); } } Ok(()) diff --git a/vmm_core/virt_whp/src/vp_state.rs b/vmm_core/virt_whp/src/vp_state.rs index e2b1d6dfcd..3bd8a7c98e 100644 --- a/vmm_core/virt_whp/src/vp_state.rs +++ b/vmm_core/virt_whp/src/vp_state.rs @@ -2,11 +2,11 @@ // Licensed under the MIT License. use super::Error; -use crate::regs::hv_register_to_whp; -use crate::regs::ToWhpRegister; use crate::WhpProcessor; use crate::WhpResultExt; use crate::WhpVpRef; +use crate::regs::ToWhpRegister; +use crate::regs::hv_register_to_whp; use hvdef::HvRegisterValue; use hvdef::Vtl; use virt::state::HvRegisterState; diff --git a/vmm_core/vm_loader/src/lib.rs b/vmm_core/vm_loader/src/lib.rs index 3d6895511f..f50a40f475 100644 --- a/vmm_core/vm_loader/src/lib.rs +++ b/vmm_core/vm_loader/src/lib.rs @@ -9,8 +9,8 @@ use anyhow::Context; use guestmem::GuestMemory; -use hvdef::Vtl; use hvdef::HV_PAGE_SIZE; +use hvdef::Vtl; use loader::importer::BootPageAcceptance; use loader::importer::GuestArch; use loader::importer::ImageLoad; @@ -221,7 +221,8 @@ impl ImageLoad for Loader<'_, R> { // Thus the memory request must live completely within a single // range, since any gaps are mmio. if end_address > range.range.end() { - anyhow::bail!("requested memory at base {:#x} and end {:#x} is not covered fully by the corresponding range {:?}", + anyhow::bail!( + "requested memory at base {:#x} and end {:#x} is not covered fully by the corresponding range {:?}", base_address, end_address, range @@ -243,7 +244,8 @@ impl ImageLoad for Loader<'_, R> { if base_address >= range.start() && (page_count * HV_PAGE_SIZE) <= range.len() { memory_found = true; } else { - anyhow::bail!("startup vtl2 memory at base {:#x} and end {:#x} is not covered fully by vtl2 specific ram range {:?}", + anyhow::bail!( + "startup vtl2 memory at base {:#x} and end {:#x} is not covered fully by vtl2 specific ram range {:?}", base_address, end_address, range diff --git a/vmm_core/vm_manifest_builder/src/lib.rs b/vmm_core/vm_manifest_builder/src/lib.rs index fb7e53f1f2..6f6b6934c7 100644 --- a/vmm_core/vm_manifest_builder/src/lib.rs +++ b/vmm_core/vm_manifest_builder/src/lib.rs @@ -26,11 +26,11 @@ use serial_debugcon_resources::SerialDebugconDeviceHandle; use serial_pl011_resources::SerialPl011DeviceHandle; use std::iter::zip; use thiserror::Error; -use vm_resource::kind::SerialBackendHandle; use vm_resource::IntoResource; use vm_resource::Resource; -use vmotherboard::options::BaseChipsetManifest; +use vm_resource::kind::SerialBackendHandle; use vmotherboard::ChipsetDeviceHandle; +use vmotherboard::options::BaseChipsetManifest; /// Builder for a VM manifest. pub struct VmManifestBuilder { diff --git a/vmm_core/vmm_core_defs/src/debug_rpc.rs b/vmm_core/vmm_core_defs/src/debug_rpc.rs index 962b73857f..ec0fdb7100 100644 --- a/vmm_core/vmm_core_defs/src/debug_rpc.rs +++ b/vmm_core/vmm_core_defs/src/debug_rpc.rs @@ -10,8 +10,8 @@ pub use virt::x86::BreakpointType; pub use virt::x86::DebugState; pub use virt::x86::HardwareBreakpoint; -use mesh::rpc::FailableRpc; use mesh::MeshPayload; +use mesh::rpc::FailableRpc; use virt::x86::SegmentRegister; #[derive(Debug, MeshPayload)] diff --git a/vmm_core/vmotherboard/src/base_chipset.rs b/vmm_core/vmotherboard/src/base_chipset.rs index a045385610..b18f22cde3 100644 --- a/vmm_core/vmotherboard/src/base_chipset.rs +++ b/vmm_core/vmotherboard/src/base_chipset.rs @@ -4,18 +4,18 @@ //! A flexible chipset builder that pre-populates a [`Chipset`](super::Chipset) //! with a customizable configuration of semi-standardized device. -use crate::chipset::backing::arc_mutex::device::AddDeviceError; -use crate::chipset::backing::arc_mutex::services::ArcMutexChipsetServices; -use crate::chipset::ChipsetBuilder; use crate::ChipsetDeviceHandle; use crate::PowerEvent; +use crate::chipset::ChipsetBuilder; +use crate::chipset::backing::arc_mutex::device::AddDeviceError; +use crate::chipset::backing::arc_mutex::services::ArcMutexChipsetServices; use chipset::*; use chipset_device::interrupt::LineInterruptTarget; -use chipset_device_resources::ConfigureChipsetDevice; -use chipset_device_resources::ResolveChipsetDeviceHandleParams; use chipset_device_resources::BSP_LINT_LINE_SET; +use chipset_device_resources::ConfigureChipsetDevice; use chipset_device_resources::GPE0_LINE_SET; use chipset_device_resources::IRQ_LINE_SET; +use chipset_device_resources::ResolveChipsetDeviceHandleParams; use closeable_mutex::CloseableMutex; use firmware_uefi::UefiCommandSet; use framebuffer::Framebuffer; @@ -716,8 +716,7 @@ impl<'a> BaseChipsetBuilder<'a> { macro_rules! feature_gate_check { ($feature:literal, $dep:ident) => { #[cfg(not(feature = $feature))] - let None::<()> = $dep - else { + let None::<()> = $dep else { return Err(BaseChipsetBuilderError::FeatureGatedDevice($feature)); }; }; @@ -792,11 +791,11 @@ impl ConfigureChipsetDevice for ArcMutexChipsetServices<'_, '_> { } mod weak_mutex_pci { - use crate::chipset::backing::arc_mutex::pci::RegisterWeakMutexPci; use crate::chipset::PciConflict; use crate::chipset::PciConflictReason; - use chipset_device::io::IoResult; + use crate::chipset::backing::arc_mutex::pci::RegisterWeakMutexPci; use chipset_device::ChipsetDevice; + use chipset_device::io::IoResult; use closeable_mutex::CloseableMutex; use pci_bus::GenericPciBusDevice; use std::sync::Arc; diff --git a/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/device.rs b/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/device.rs index 578cd43d5b..6473bf698c 100644 --- a/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/device.rs +++ b/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/device.rs @@ -162,15 +162,21 @@ where let (ob, od, of) = override_bdf; let (sb, sd, sf) = suggested_bdf; tracing::info!( - "overriding suggested bdf: using {:02x}:{:02x}:{} instead of {:02x}:{:02x}:{}", - ob, od, of, - sb, sd, sf - ); + "overriding suggested bdf: using {:02x}:{:02x}:{} instead of {:02x}:{:02x}:{}", + ob, + od, + of, + sb, + sd, + sf + ); override_bdf } (None, Some(bdf)) | (Some(bdf), None) => bdf, (None, None) => { - return Err(AddDeviceErrorKind::NoPciBusAddress.with_dev_name(self.dev_name)) + return Err( + AddDeviceErrorKind::NoPciBusAddress.with_dev_name(self.dev_name) + ); } }; @@ -233,7 +239,7 @@ where let dev = match (f)(&mut self.services) { Ok(dev) => dev, Err(e) => { - return Err(AddDeviceErrorKind::DeviceError(e.into()).with_dev_name(self.dev_name)) + return Err(AddDeviceErrorKind::DeviceError(e.into()).with_dev_name(self.dev_name)); } }; self.inner_add(Ok(dev)) @@ -252,7 +258,7 @@ where let dev = match (f)(&mut self.services).await { Ok(dev) => dev, Err(e) => { - return Err(AddDeviceErrorKind::DeviceError(e.into()).with_dev_name(self.dev_name)) + return Err(AddDeviceErrorKind::DeviceError(e.into()).with_dev_name(self.dev_name)); } }; self.inner_add(Ok(dev)) diff --git a/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/pci.rs b/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/pci.rs index a2f40005dd..7f514ca0c5 100644 --- a/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/pci.rs +++ b/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/pci.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use crate::BusIdPci; use crate::chipset::PciConflict; use crate::chipset::PciConflictReason; -use crate::BusIdPci; use chipset_device::ChipsetDevice; use closeable_mutex::CloseableMutex; use std::collections::HashMap; @@ -65,10 +65,6 @@ impl BusResolverWeakMutexPci { } } - if !errs.is_empty() { - Err(errs) - } else { - Ok(()) - } + if !errs.is_empty() { Err(errs) } else { Ok(()) } } } diff --git a/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/services.rs b/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/services.rs index 29807f25ce..58543c9619 100644 --- a/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/services.rs +++ b/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/services.rs @@ -6,10 +6,10 @@ use self::device_range::DeviceRangeMapper; use super::device::ArcMutexChipsetServicesFinalize; use super::state_unit::ArcMutexChipsetDeviceUnit; -use crate::chipset::line_sets::LineSetTargetDevice; use crate::BusIdPci; use crate::ChipsetBuilder; use crate::VmmChipsetDevice; +use crate::chipset::line_sets::LineSetTargetDevice; use chipset_device::ChipsetDevice; use chipset_device_resources::LineSetId; use closeable_mutex::CloseableMutex; @@ -209,11 +209,11 @@ impl<'a, 'b> ArcMutexChipsetServices<'a, 'b> { mod device_range { use crate::chipset::io_ranges::IoRanges; + use chipset_device::ChipsetDevice; use chipset_device::mmio::ControlMmioIntercept; use chipset_device::mmio::RegisterMmioIntercept; use chipset_device::pio::ControlPortIoIntercept; use chipset_device::pio::RegisterPortIoIntercept; - use chipset_device::ChipsetDevice; use closeable_mutex::CloseableMutex; use std::sync::Arc; use std::sync::Weak; diff --git a/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/state_unit.rs b/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/state_unit.rs index 1825819423..5b0ebb0772 100644 --- a/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/state_unit.rs +++ b/vmm_core/vmotherboard/src/chipset/backing/arc_mutex/state_unit.rs @@ -4,11 +4,11 @@ use crate::VmmChipsetDevice; use async_trait::async_trait; use closeable_mutex::CloseableMutex; -use futures::task::waker_ref; -use futures::task::ArcWake; -use futures::task::WakerRef; use futures::FutureExt; use futures::StreamExt; +use futures::task::ArcWake; +use futures::task::WakerRef; +use futures::task::waker_ref; use inspect::InspectMut; use state_unit::StateRequest; use state_unit::StateUnit; diff --git a/vmm_core/vmotherboard/src/chipset/builder/errors.rs b/vmm_core/vmotherboard/src/chipset/builder/errors.rs index 3dd4404482..83b16d9cfd 100644 --- a/vmm_core/vmotherboard/src/chipset/builder/errors.rs +++ b/vmm_core/vmotherboard/src/chipset/builder/errors.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::chipset::io_ranges::IoRangeConflict; use crate::chipset::PciConflict; +use crate::chipset::io_ranges::IoRangeConflict; use std::fmt::Debug; use thiserror::Error; diff --git a/vmm_core/vmotherboard/src/chipset/builder/mod.rs b/vmm_core/vmotherboard/src/chipset/builder/mod.rs index 5f30306547..cb2156b344 100644 --- a/vmm_core/vmotherboard/src/chipset/builder/mod.rs +++ b/vmm_core/vmotherboard/src/chipset/builder/mod.rs @@ -14,11 +14,11 @@ use super::backing::arc_mutex::pci::RegisterWeakMutexPci; use super::backing::arc_mutex::pci::WeakMutexPciEntry; use super::backing::arc_mutex::services::ArcMutexChipsetServices; use super::backing::arc_mutex::state_unit::ArcMutexChipsetDeviceUnit; -use crate::chipset::io_ranges::IoRanges; -use crate::chipset::Chipset; use crate::BusIdPci; use crate::DebugEventHandler; use crate::VmmChipsetDevice; +use crate::chipset::Chipset; +use crate::chipset::io_ranges::IoRanges; use chipset_device::ChipsetDevice; use chipset_device_resources::LineSetId; use closeable_mutex::CloseableMutex; diff --git a/vmm_core/vmotherboard/src/chipset/mod.rs b/vmm_core/vmotherboard/src/chipset/mod.rs index f10b40d93b..56bc07b79e 100644 --- a/vmm_core/vmotherboard/src/chipset/mod.rs +++ b/vmm_core/vmotherboard/src/chipset/mod.rs @@ -14,9 +14,9 @@ pub use self::builder::ChipsetDevices; use self::io_ranges::IoRanges; use self::io_ranges::LookupResult; use crate::DebugEventHandler; +use chipset_device::ChipsetDevice; use chipset_device::io::IoError; use chipset_device::io::IoResult; -use chipset_device::ChipsetDevice; use closeable_mutex::CloseableMutex; use inspect::Inspect; use std::future::poll_fn; diff --git a/vmm_core/vmotherboard/src/lib.rs b/vmm_core/vmotherboard/src/lib.rs index 9bb1b5f6a9..2fcbd054e5 100644 --- a/vmm_core/vmotherboard/src/lib.rs +++ b/vmm_core/vmotherboard/src/lib.rs @@ -12,26 +12,26 @@ mod base_chipset; mod chipset; -pub use self::base_chipset::options; pub use self::base_chipset::BaseChipsetBuilder; pub use self::base_chipset::BaseChipsetBuilderError; pub use self::base_chipset::BaseChipsetBuilderOutput; pub use self::base_chipset::BaseChipsetDeviceInterfaces; +pub use self::base_chipset::options; pub use self::chipset::Chipset; pub use self::chipset::ChipsetDevices; // API wart: future changes should avoid exposing the `ChipsetBuilder`, and move // _all_ device instantiation into `vmotherboard` itself. -pub use self::chipset::backing::arc_mutex::device::ArcMutexChipsetDeviceBuilder; pub use self::chipset::ChipsetBuilder; +pub use self::chipset::backing::arc_mutex::device::ArcMutexChipsetDeviceBuilder; use chipset_device::ChipsetDevice; use inspect::InspectMut; use mesh::MeshPayload; use std::marker::PhantomData; use std::sync::Arc; -use vm_resource::kind::ChipsetDeviceHandleKind; use vm_resource::Resource; +use vm_resource::kind::ChipsetDeviceHandleKind; use vmcore::device_state::ChangeDeviceState; use vmcore::save_restore::ProtobufSaveRestore; diff --git a/vmm_tests/petri_artifact_resolver_openvmm_known_paths/src/lib.rs b/vmm_tests/petri_artifact_resolver_openvmm_known_paths/src/lib.rs index be0e65aac5..14a01c7371 100644 --- a/vmm_tests/petri_artifact_resolver_openvmm_known_paths/src/lib.rs +++ b/vmm_tests/petri_artifact_resolver_openvmm_known_paths/src/lib.rs @@ -487,7 +487,8 @@ impl MissingCommand<'_> { match self { MissingCommand::Build { package, target } => anyhow::bail!( "Failed to find {package} binary. Run `cargo build {target_args}-p {package}` to build it.", - target_args = target.map_or(String::new(), |target| format!("--target {} ", target)), + target_args = + target.map_or(String::new(), |target| format!("--target {} ", target)), ), MissingCommand::Xtask { description, @@ -499,13 +500,19 @@ impl MissingCommand<'_> { args.join(" ") ) } - MissingCommand::XFlowey { description, xflowey_args: args } => anyhow::bail!( - "Failed to find {}. Run `cargo xflowey {}` to create it.", - description, - args.join(" ") - ), + MissingCommand::XFlowey { + description, + xflowey_args: args, + } => anyhow::bail!( + "Failed to find {}. Run `cargo xflowey {}` to create it.", + description, + args.join(" ") + ), MissingCommand::Restore { description } => { - anyhow::bail!("Failed to find {}. Run `cargo xflowey restore-packages`.", description) + anyhow::bail!( + "Failed to find {}. Run `cargo xflowey restore-packages`.", + description + ) } MissingCommand::Custom { description, cmd } => { anyhow::bail!( diff --git a/vmm_tests/vmm_test_macros/src/lib.rs b/vmm_tests/vmm_test_macros/src/lib.rs index ad54646845..481fad7473 100644 --- a/vmm_tests/vmm_test_macros/src/lib.rs +++ b/vmm_tests/vmm_test_macros/src/lib.rs @@ -9,17 +9,17 @@ use petri_artifacts_common::tags::MachineArch; use proc_macro2::Ident; use proc_macro2::Span; use proc_macro2::TokenStream; -use quote::quote; use quote::ToTokens; +use quote::quote; use std::collections::HashSet; -use syn::parse::Parse; -use syn::parse::ParseStream; -use syn::parse_macro_input; -use syn::spanned::Spanned; use syn::Error; use syn::ItemFn; use syn::Path; use syn::Token; +use syn::parse::Parse; +use syn::parse::ParseStream; +use syn::parse_macro_input; +use syn::spanned::Spanned; struct Config { vmm: Option, @@ -594,16 +594,17 @@ pub fn hyperv_test( } fn make_vmm_test(args: Args, item: ItemFn, specific_vmm: Option) -> syn::Result { - let original_args = - match item.sig.inputs.len() { - 1 => quote! {config}, - 2 => quote! {config, extra_deps}, - 3 => quote! {config, extra_deps, driver }, - _ => return Err(Error::new( + let original_args = match item.sig.inputs.len() { + 1 => quote! {config}, + 2 => quote! {config, extra_deps}, + 3 => quote! {config, extra_deps, driver }, + _ => { + return Err(Error::new( item.sig.inputs.span(), "expected 1, 2, or 3 arguments (the PetriVmConfig, ArtifactResolver, and Driver)", - )), - }; + )); + } + }; let original_name = &item.sig.ident; let mut tests = TokenStream::new(); diff --git a/vmm_tests/vmm_tests/tests/tests/multiarch.rs b/vmm_tests/vmm_tests/tests/tests/multiarch.rs index 58960998cd..d32cc23ad3 100644 --- a/vmm_tests/vmm_tests/tests/tests/multiarch.rs +++ b/vmm_tests/vmm_tests/tests/tests/multiarch.rs @@ -3,8 +3,8 @@ //! Integration tests that run on more than one architecture. -use petri::openvmm::PetriVmConfigOpenVmm; use petri::PetriVmConfig; +use petri::openvmm::PetriVmConfigOpenVmm; use vmm_core_defs::HaltReason; use vmm_test_macros::openvmm_test; use vmm_test_macros::vmm_test; diff --git a/vmm_tests/vmm_tests/tests/tests/ttrpc.rs b/vmm_tests/vmm_tests/tests/tests/ttrpc.rs index 546bcf2f4c..ddcff8c4d5 100644 --- a/vmm_tests/vmm_tests/tests/tests/ttrpc.rs +++ b/vmm_tests/vmm_tests/tests/tests/ttrpc.rs @@ -8,10 +8,10 @@ use anyhow::Context; use guid::Guid; use hvlite_ttrpc_vmservice as vmservice; +use pal_async::DefaultPool; use pal_async::pipe::PolledPipe; use pal_async::socket::PolledSocket; use pal_async::task::Spawn; -use pal_async::DefaultPool; use petri::ResolvedArtifact; use petri_artifacts_vmm_test::artifacts; use std::io::Read; diff --git a/vmm_tests/vmm_tests/tests/tests/x86_64.rs b/vmm_tests/vmm_tests/tests/tests/x86_64.rs index 44f0f666e1..b6227ac341 100644 --- a/vmm_tests/vmm_tests/tests/tests/x86_64.rs +++ b/vmm_tests/vmm_tests/tests/tests/x86_64.rs @@ -8,10 +8,10 @@ mod openhcl_servicing; mod openhcl_uefi; use anyhow::Context; +use petri::SIZE_1_GB; +use petri::ShutdownKind; use petri::openvmm::PetriVmConfigOpenVmm; use petri::pipette::cmd; -use petri::ShutdownKind; -use petri::SIZE_1_GB; use petri_artifacts_common::tags::OsFlavor; use vmm_core_defs::HaltReason; use vmm_test_macros::openvmm_test; @@ -315,10 +315,14 @@ async fn mtrrs(config: PetriVmConfigOpenVmm) -> Result<(), anyhow::Error> { // assert!(mtrr_output.contains("default type: uncachable")); // assert!(mtrr_output.contains("fixed ranges enabled")); // assert!(mtrr_output.contains("variable ranges enabled")); - assert!(mtrr_output - .contains("reg00: base=0x000000000 ( 0MB), size= 128MB, count=1: write-back")); - assert!(mtrr_output - .contains("reg01: base=0x008000000 ( 128MB), size= 4096MB, count=1: write-back")); + assert!( + mtrr_output + .contains("reg00: base=0x000000000 ( 0MB), size= 128MB, count=1: write-back") + ); + assert!( + mtrr_output + .contains("reg01: base=0x008000000 ( 128MB), size= 4096MB, count=1: write-back") + ); Ok(()) } diff --git a/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_linux_direct.rs b/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_linux_direct.rs index 42067ea8ce..f4663cf617 100644 --- a/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_linux_direct.rs +++ b/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_linux_direct.rs @@ -4,8 +4,8 @@ //! Integration tests for x86_64 Linux direct boot with OpenHCL. use anyhow::Context; -use disk_backend_resources::layer::RamDiskLayerHandle; use disk_backend_resources::LayeredDiskHandle; +use disk_backend_resources::layer::RamDiskLayerHandle; use guid::Guid; use hvlite_defs::config::DeviceVtl; use hvlite_defs::config::VpciDeviceConfig; @@ -13,11 +13,11 @@ use hvlite_defs::config::Vtl2BaseAddressType; use mesh::rpc::RpcSend; use nvme_resources::NamespaceDefinition; use nvme_resources::NvmeControllerHandle; -use petri::openvmm::PetriVmConfigOpenVmm; -use petri::pipette::cmd; -use petri::pipette::PipetteClient; use petri::OpenHclServicingFlags; use petri::ResolvedArtifact; +use petri::openvmm::PetriVmConfigOpenVmm; +use petri::pipette::PipetteClient; +use petri::pipette::cmd; use petri_artifacts_vmm_test::artifacts::openhcl_igvm::LATEST_LINUX_DIRECT_TEST_X64; use scsidisk_resources::SimpleScsiDiskHandle; use scsidisk_resources::SimpleScsiDvdHandle; diff --git a/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_servicing.rs b/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_servicing.rs index 2677ceee1e..f2317b2eab 100644 --- a/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_servicing.rs +++ b/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_servicing.rs @@ -3,13 +3,13 @@ //! Integration tests for x86_64 OpenHCL servicing. -use disk_backend_resources::layer::RamDiskLayerHandle; use disk_backend_resources::LayeredDiskHandle; +use disk_backend_resources::layer::RamDiskLayerHandle; use hvlite_defs::config::DeviceVtl; -use petri::openvmm::PetriVmConfigOpenVmm; -use petri::pipette::cmd; use petri::OpenHclServicingFlags; use petri::ResolvedArtifact; +use petri::openvmm::PetriVmConfigOpenVmm; +use petri::pipette::cmd; #[cfg(guest_arch = "x86_64")] use petri_artifacts_vmm_test::artifacts::openhcl_igvm::LATEST_LINUX_DIRECT_TEST_X64; use scsidisk_resources::SimpleScsiDiskHandle; diff --git a/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_uefi.rs b/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_uefi.rs index d588bda769..354c2cc43f 100644 --- a/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_uefi.rs +++ b/vmm_tests/vmm_tests/tests/tests/x86_64/openhcl_uefi.rs @@ -3,9 +3,9 @@ //! Integration tests for Generation 2 UEFI x86_64 guests with OpenHCL. -use petri::openvmm::PetriVmConfigOpenVmm; use petri::OpenHclServicingFlags; use petri::ResolvedArtifact; +use petri::openvmm::PetriVmConfigOpenVmm; #[cfg(guest_arch = "x86_64")] use petri_artifacts_vmm_test::artifacts::openhcl_igvm::LATEST_STANDARD_X64; use vmm_core_defs::HaltReason; diff --git a/workers/debug_worker/src/gdb/arch/x86/reg/core32.rs b/workers/debug_worker/src/gdb/arch/x86/reg/core32.rs index 916734683b..10d4a58b8e 100644 --- a/workers/debug_worker/src/gdb/arch/x86/reg/core32.rs +++ b/workers/debug_worker/src/gdb/arch/x86/reg/core32.rs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use super::{X86SegmentRegs, X87FpuInternalRegs, F80}; +use super::{F80, X86SegmentRegs, X87FpuInternalRegs}; use core::convert::TryInto; use gdbstub::arch::Registers; diff --git a/workers/debug_worker/src/gdb/arch/x86/reg/core64.rs b/workers/debug_worker/src/gdb/arch/x86/reg/core64.rs index 5efe9c9174..e4576460e0 100644 --- a/workers/debug_worker/src/gdb/arch/x86/reg/core64.rs +++ b/workers/debug_worker/src/gdb/arch/x86/reg/core64.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use super::F80; use super::X86SegmentRegs; use super::X87FpuInternalRegs; -use super::F80; use gdbstub::arch::Registers; #[derive(Debug, Default, Clone, PartialEq, Eq)] diff --git a/workers/debug_worker/src/gdb/targets/base.rs b/workers/debug_worker/src/gdb/targets/base.rs index d0ec2d1263..e4b6edbd66 100644 --- a/workers/debug_worker/src/gdb/targets/base.rs +++ b/workers/debug_worker/src/gdb/targets/base.rs @@ -7,13 +7,13 @@ use crate::gdb::targets::ToTargetResult; use futures::executor::block_on; use gdbstub::common::Signal; use gdbstub::common::Tid; +use gdbstub::target::TargetResult; use gdbstub::target::ext::base::multithread::MultiThreadBase; use gdbstub::target::ext::base::multithread::MultiThreadResume; use gdbstub::target::ext::base::multithread::MultiThreadResumeOps; use gdbstub::target::ext::base::multithread::MultiThreadSingleStep; use gdbstub::target::ext::base::multithread::MultiThreadSingleStepOps; use gdbstub::target::ext::base::single_register_access::SingleRegisterAccess; -use gdbstub::target::TargetResult; use mesh::rpc::RpcSend; use vmm_core_defs::debug_rpc::DebugRequest; use vmm_core_defs::debug_rpc::DebugState; diff --git a/workers/debug_worker/src/gdb/targets/breakpoints.rs b/workers/debug_worker/src/gdb/targets/breakpoints.rs index ab84d531bd..c70104ca5d 100644 --- a/workers/debug_worker/src/gdb/targets/breakpoints.rs +++ b/workers/debug_worker/src/gdb/targets/breakpoints.rs @@ -5,9 +5,9 @@ use super::TargetArch; use super::VmTarget; use crate::gdb::VmProxy; use gdbstub::target; -use gdbstub::target::ext::breakpoints::WatchKind; use gdbstub::target::TargetError; use gdbstub::target::TargetResult; +use gdbstub::target::ext::breakpoints::WatchKind; use vmm_core_defs::debug_rpc::BreakpointSize; use vmm_core_defs::debug_rpc::BreakpointType; use vmm_core_defs::debug_rpc::HardwareBreakpoint; diff --git a/workers/debug_worker/src/gdb/targets/mod.rs b/workers/debug_worker/src/gdb/targets/mod.rs index fce3cc1917..7b3d433ad1 100644 --- a/workers/debug_worker/src/gdb/targets/mod.rs +++ b/workers/debug_worker/src/gdb/targets/mod.rs @@ -2,9 +2,9 @@ // Licensed under the MIT License. use super::VmProxy; -use gdbstub::target::ext::target_description_xml_override::TargetDescriptionXmlOverrideOps; use gdbstub::target::Target; use gdbstub::target::TargetError; +use gdbstub::target::ext::target_description_xml_override::TargetDescriptionXmlOverrideOps; use std::marker::PhantomData; use std::ops::Deref; use std::ops::DerefMut; diff --git a/workers/debug_worker/src/gdb/targets/target_x86_64_qemu/mod.rs b/workers/debug_worker/src/gdb/targets/target_x86_64_qemu/mod.rs index 97eafc8fb3..5fca6b584f 100644 --- a/workers/debug_worker/src/gdb/targets/target_x86_64_qemu/mod.rs +++ b/workers/debug_worker/src/gdb/targets/target_x86_64_qemu/mod.rs @@ -6,10 +6,10 @@ use super::ArchError; use super::TargetArch; -use crate::gdb::arch::x86::reg::id::X86SegmentRegId; -use crate::gdb::arch::x86::reg::id::X86_64CoreRegId; -use crate::gdb::arch::x86::reg::X86SegmentRegs; use crate::gdb::arch::x86::reg::X86_64CoreRegs; +use crate::gdb::arch::x86::reg::X86SegmentRegs; +use crate::gdb::arch::x86::reg::id::X86_64CoreRegId; +use crate::gdb::arch::x86::reg::id::X86SegmentRegId; use vmm_core_defs::debug_rpc::DebuggerVpState; mod target_xml; @@ -43,8 +43,24 @@ impl TargetArch for crate::gdb::arch::x86::X86_64_QEMU { return Err(ArchError); }; let gp_regs = { - let [rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15] = - state.gp; + let [ + rax, + rcx, + rdx, + rbx, + rsp, + rbp, + rsi, + rdi, + r8, + r9, + r10, + r11, + r12, + r13, + r14, + r15, + ] = state.gp; [ rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15, ] @@ -94,8 +110,24 @@ impl TargetArch for crate::gdb::arch::x86::X86_64_QEMU { return Err(ArchError); }; state.gp = { - let [rax, rbx, rcx, rdx, rsi, rdi, rbp, rsp, r8, r9, r10, r11, r12, r13, r14, r15] = - regs.regs; + let [ + rax, + rbx, + rcx, + rdx, + rsi, + rdi, + rbp, + rsp, + r8, + r9, + r10, + r11, + r12, + r13, + r14, + r15, + ] = regs.regs; [ rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi, r8, r9, r10, r11, r12, r13, r14, r15, ] diff --git a/workers/debug_worker/src/lib.rs b/workers/debug_worker/src/lib.rs index c797292aea..afb01c3a40 100644 --- a/workers/debug_worker/src/lib.rs +++ b/workers/debug_worker/src/lib.rs @@ -12,26 +12,25 @@ mod gdb; use anyhow::Context; -use debug_worker_defs::DebuggerParameters; use debug_worker_defs::DEBUGGER_WORKER; +use debug_worker_defs::DebuggerParameters; use futures::AsyncReadExt; use futures::FutureExt; +use gdb::VmProxy; use gdb::targets::TargetArch; use gdb::targets::VmTarget; -use gdb::VmProxy; use gdbstub::target::ext::breakpoints::WatchKind; use inspect::InspectMut; use mesh::message::MeshField; use mesh_worker::Worker; use mesh_worker::WorkerId; use mesh_worker::WorkerRpc; -use pal_async::local::block_with_io; use pal_async::local::LocalDriver; +use pal_async::local::block_with_io; use pal_async::socket::Listener; use pal_async::socket::PolledSocket; use socket2::Socket; use std::fmt::Display; -use std::future::Future; use std::io::Write; use std::net::TcpListener; use std::pin::Pin; @@ -274,10 +273,10 @@ async fn run_state_machine( mut vm_target: VmTarget<'_, T>, ) -> Result<(), gdbstub::stub::GdbStubError> { use gdbstub::common::Signal; - use gdbstub::stub::state_machine::GdbStubStateMachine; use gdbstub::stub::DisconnectReason; use gdbstub::stub::GdbStubError; use gdbstub::stub::MultiThreadStopReason; + use gdbstub::stub::state_machine::GdbStubStateMachine; vm_target.send_req(DebugRequest::Attach); let (init_break_send, init_break_recv) = mesh::oneshot(); diff --git a/workers/debug_worker_defs/src/lib.rs b/workers/debug_worker_defs/src/lib.rs index dab84e0aac..cf6f839f80 100644 --- a/workers/debug_worker_defs/src/lib.rs +++ b/workers/debug_worker_defs/src/lib.rs @@ -6,8 +6,8 @@ #![expect(missing_docs)] #![forbid(unsafe_code)] -use mesh::payload::Protobuf; use mesh::MeshPayload; +use mesh::payload::Protobuf; use mesh_worker::WorkerId; use std::net::TcpListener; use vmm_core_defs::debug_rpc::DebugRequest; diff --git a/workers/vnc_worker/src/lib.rs b/workers/vnc_worker/src/lib.rs index f3a32c0f03..c589fda1ea 100644 --- a/workers/vnc_worker/src/lib.rs +++ b/workers/vnc_worker/src/lib.rs @@ -3,8 +3,8 @@ //! A worker for running a VNC server. -use anyhow::anyhow; use anyhow::Context; +use anyhow::anyhow; use futures::FutureExt; use input_core::InputData; use input_core::KeyboardData; @@ -13,12 +13,11 @@ use mesh::message::MeshField; use mesh_worker::Worker; use mesh_worker::WorkerId; use mesh_worker::WorkerRpc; -use pal_async::local::block_with_io; use pal_async::local::LocalDriver; +use pal_async::local::block_with_io; use pal_async::socket::Listener; use pal_async::socket::PolledSocket; use pal_async::timer::PolledTimer; -use std::future::Future; use std::net::TcpListener; use std::pin::Pin; use std::time::Duration; diff --git a/workers/vnc_worker/vnc/src/lib.rs b/workers/vnc_worker/vnc/src/lib.rs index c5defdafa2..1cf954728e 100644 --- a/workers/vnc_worker/vnc/src/lib.rs +++ b/workers/vnc_worker/vnc/src/lib.rs @@ -7,12 +7,12 @@ mod rfb; mod scancode; -use futures::channel::mpsc; -use futures::future::OptionFuture; use futures::AsyncReadExt; use futures::AsyncWriteExt; use futures::FutureExt; use futures::StreamExt; +use futures::channel::mpsc; +use futures::future::OptionFuture; use pal_async::socket::PolledSocket; use thiserror::Error; use zerocopy::FromZeros; diff --git a/xsync/Cargo.toml b/xsync/Cargo.toml index 98e033d1fe..14b5b0f18f 100644 --- a/xsync/Cargo.toml +++ b/xsync/Cargo.toml @@ -8,7 +8,7 @@ resolver = "2" [workspace.package] rust-version = "1.85" -edition = "2021" +edition = "2024" [workspace.dependencies] anyhow = "1.0" diff --git a/xsync/xsync/src/tasks/cargo_toml.rs b/xsync/xsync/src/tasks/cargo_toml.rs index 955c7a1e6d..b94c23d0f2 100644 --- a/xsync/xsync/src/tasks/cargo_toml.rs +++ b/xsync/xsync/src/tasks/cargo_toml.rs @@ -115,7 +115,7 @@ impl Cmd for CargoToml { Ok(base_clippy_toml) => { log::info!("base clippy.toml found, regenerating overlay clippy.toml",); let mut base_clippy_toml = - toml_edit::Document::from_str(&base_clippy_toml)?; + toml_edit::DocumentMut::from_str(&base_clippy_toml)?; base_clippy_toml.fmt(); let generated_clippy_toml = format!( "{}{}", diff --git a/xsync/xsync/src/tasks/rustfmt_toml.rs b/xsync/xsync/src/tasks/rustfmt_toml.rs index 1486a9831b..7b1e67a0ad 100644 --- a/xsync/xsync/src/tasks/rustfmt_toml.rs +++ b/xsync/xsync/src/tasks/rustfmt_toml.rs @@ -58,7 +58,7 @@ impl Cmd for RustfmtToml { match base_fmt_toml { Ok(base_fmt_toml) => { log::info!("base rustfmt.toml found, regenerating overlay rustfmt.toml",); - let mut base_fmt_toml = toml_edit::Document::from_str(&base_fmt_toml)?; + let mut base_fmt_toml = toml_edit::DocumentMut::from_str(&base_fmt_toml)?; base_fmt_toml.fmt(); let generated_fmt_toml = format!( "{}{}", diff --git a/xtask/src/tasks/build_igvm.rs b/xtask/src/tasks/build_igvm.rs index f676bf5101..b809c0799e 100644 --- a/xtask/src/tasks/build_igvm.rs +++ b/xtask/src/tasks/build_igvm.rs @@ -2,8 +2,8 @@ // Licensed under the MIT License. use crate::Xtask; -use clap::builder::PossibleValue; use clap::Parser; +use clap::builder::PossibleValue; use std::fmt; use std::path::PathBuf; diff --git a/xtask/src/tasks/fmt/house_rules.rs b/xtask/src/tasks/fmt/house_rules.rs index acae682645..44edbe4917 100644 --- a/xtask/src/tasks/fmt/house_rules.rs +++ b/xtask/src/tasks/fmt/house_rules.rs @@ -1,9 +1,9 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +use crate::Xtask; use crate::fs_helpers::git_diffed; use crate::fs_helpers::git_ls_files; -use crate::Xtask; use clap::Parser; use std::path::PathBuf; diff --git a/xtask/src/tasks/fmt/house_rules/crate_name_nodash.rs b/xtask/src/tasks/fmt/house_rules/crate_name_nodash.rs index f3085ff229..27fc57f1db 100644 --- a/xtask/src/tasks/fmt/house_rules/crate_name_nodash.rs +++ b/xtask/src/tasks/fmt/house_rules/crate_name_nodash.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use anyhow::anyhow; use anyhow::Context; +use anyhow::anyhow; use std::ffi::OsStr; use std::path::Path; @@ -16,7 +16,7 @@ pub fn check_crate_name_nodash(path: &Path) -> anyhow::Result<()> { } let contents = fs_err::read_to_string(path)?; - let parsed = contents.parse::()?; + let parsed = contents.parse::()?; let package_name = match parsed .as_table() diff --git a/xtask/src/tasks/fmt/house_rules/package_info.rs b/xtask/src/tasks/fmt/house_rules/package_info.rs index 7e8c4a1317..932e11e298 100644 --- a/xtask/src/tasks/fmt/house_rules/package_info.rs +++ b/xtask/src/tasks/fmt/house_rules/package_info.rs @@ -32,7 +32,7 @@ pub fn check_package_info(f: &Path, fix: bool) -> anyhow::Result<()> { } let contents = fs_err::read_to_string(f)?; - let mut parsed = contents.parse::()?; + let mut parsed = contents.parse::()?; let mut excluded_from_workspace = false; if let Some(metadata) = parsed diff --git a/xtask/src/tasks/fmt/rustfmt.rs b/xtask/src/tasks/fmt/rustfmt.rs index 87eca63bc9..c1b812faba 100644 --- a/xtask/src/tasks/fmt/rustfmt.rs +++ b/xtask/src/tasks/fmt/rustfmt.rs @@ -1,8 +1,8 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -use crate::fs_helpers::git_diffed; use crate::Xtask; +use crate::fs_helpers::git_diffed; use clap::Parser; use std::path::PathBuf; use xshell::cmd; diff --git a/xtask/src/tasks/fmt/unused_deps.rs b/xtask/src/tasks/fmt/unused_deps.rs index 545c7e5619..5637e2ce63 100644 --- a/xtask/src/tasks/fmt/unused_deps.rs +++ b/xtask/src/tasks/fmt/unused_deps.rs @@ -179,7 +179,7 @@ impl Xtask for UnusedDeps { } fn remove_dependencies(manifest: &str, analysis_results: &[DepResult]) -> anyhow::Result { - let mut manifest = toml_edit::Document::from_str(manifest)?; + let mut manifest = toml_edit::DocumentMut::from_str(manifest)?; let mut unused_deps = Vec::new(); let mut ignored_and_shouldnt_be = Vec::new(); diff --git a/xtask/src/tasks/fmt/workspace.rs b/xtask/src/tasks/fmt/workspace.rs index c810cd29f1..87753950dc 100644 --- a/xtask/src/tasks/fmt/workspace.rs +++ b/xtask/src/tasks/fmt/workspace.rs @@ -34,7 +34,7 @@ impl Xtask for VerifyWorkspace { let excluded = { // will always be root Cargo.toml, as xtasks run from project root let contents = fs_err::read_to_string("Cargo.toml")?; - let parsed = contents.parse::()?; + let parsed = contents.parse::()?; if let Some(excluded) = parsed .as_table() @@ -138,7 +138,7 @@ fn workspace_manifests() -> anyhow::Result> { fn verify_dependencies(path: &PathBuf) -> Result<(), anyhow::Error> { // TODO: Convert this to a better crate like cargo_toml once it supports inherited dependencies fully. let contents = fs_err::read_to_string(path)?; - let parsed = contents.parse::()?; + let parsed = contents.parse::()?; let package_name = match parsed .as_table() @@ -192,7 +192,11 @@ fn verify_dependencies(path: &PathBuf) -> Result<(), anyhow::Error> { ); } else { found_bad_deps.set(true); - log::error!("{} contains non-workspaced dependency {}. Please move this dependency to the root Cargo.toml.", package_name, dep_name); + log::error!( + "{} contains non-workspaced dependency {}. Please move this dependency to the root Cargo.toml.", + package_name, + dep_name + ); } }; let check_table_like = |t: &dyn TableLike, dep_name| { @@ -210,7 +214,11 @@ fn verify_dependencies(path: &PathBuf) -> Result<(), anyhow::Error> { if t.len() == 1 { found_bad_deps.set(true); - log::error!("{} uses inline table syntax for its dependency on {}, but only contains one table entry. Please change to the dotted syntax.", package_name, dep_name); + log::error!( + "{} uses inline table syntax for its dependency on {}, but only contains one table entry. Please change to the dotted syntax.", + package_name, + dep_name + ); } } Item::Table(t) => check_table_like(t, dep_name), diff --git a/xtask/src/tasks/fuzz/html_coverage.rs b/xtask/src/tasks/fuzz/html_coverage.rs index 72bfea2414..6911ef8219 100644 --- a/xtask/src/tasks/fuzz/html_coverage.rs +++ b/xtask/src/tasks/fuzz/html_coverage.rs @@ -64,11 +64,15 @@ pub(super) fn generate_html_coverage_report( } } - anyhow::bail!("failed to find `llvm-tools` directory. did you run `rustup +nightly component add llvm-tools`?") + anyhow::bail!( + "failed to find `llvm-tools` directory. did you run `rustup +nightly component add llvm-tools`?" + ) }; if which::which("lcov").is_err() { - anyhow::bail!("could not find `lcov` on your $PATH! make sure it's installed (e.g: `apt install lcov`)") + anyhow::bail!( + "could not find `lcov` on your $PATH! make sure it's installed (e.g: `apt install lcov`)" + ) } let coverage_dir = coverage_bin.parent().unwrap(); diff --git a/xtask/src/tasks/fuzz/init_from_template.rs b/xtask/src/tasks/fuzz/init_from_template.rs index e7ea390ab0..895a972270 100644 --- a/xtask/src/tasks/fuzz/init_from_template.rs +++ b/xtask/src/tasks/fuzz/init_from_template.rs @@ -79,7 +79,7 @@ pub(super) fn init_from_template( let new_workspace_entry = new_fuzz_dir.strip_prefix(&ctx.root)?.display().to_string(); let root_toml_raw = fs_err::read_to_string(ctx.root.join("Cargo.toml"))?; let mut root_toml = root_toml_raw - .parse::() + .parse::() .context("invalid root workspace Cargo.toml")?; let members = &mut root_toml["workspace"]["members"].as_array_mut().unwrap(); // TODO: slot the new fuzz crate into the workspace members array in *sorted order* diff --git a/xtask/src/tasks/fuzz/mod.rs b/xtask/src/tasks/fuzz/mod.rs index 390c044682..3a95e1bd9c 100644 --- a/xtask/src/tasks/fuzz/mod.rs +++ b/xtask/src/tasks/fuzz/mod.rs @@ -300,7 +300,9 @@ impl Xtask for Fuzz { ); if let Err(e) = res { - log::warn!("Reminder: Make sure you swap `cargo fuzz` with `cargo xtask fuzz` when repro-ing / minimizing failures in the HvLite repo!"); + log::warn!( + "Reminder: Make sure you swap `cargo fuzz` with `cargo xtask fuzz` when repro-ing / minimizing failures in the HvLite repo!" + ); return Err(e); } } @@ -351,7 +353,9 @@ impl Xtask for Fuzz { ); if let Err(e) = res { - log::warn!("Reminder: Make sure you swap `cargo fuzz` with `cargo xtask fuzz` when repro-ing / minimizing failures in the HvLite repo!"); + log::warn!( + "Reminder: Make sure you swap `cargo fuzz` with `cargo xtask fuzz` when repro-ing / minimizing failures in the HvLite repo!" + ); return Err(e); } } @@ -424,7 +428,9 @@ impl Xtask for Fuzz { let Ok(path) = path.strip_prefix(&ctx.root) else { // Ok to throw away `std::path::StripPrefixError`, // it doesn't contain any additional context - anyhow::bail!("allowlist for '{name}' references file(s) outside of the HvLite directory") + anyhow::bail!( + "allowlist for '{name}' references file(s) outside of the HvLite directory" + ) }; // add in "*/" to appease the OneFuzz allowlist syntax writeln!(allowlist_file, "*/{}", path.display())?;