diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index fc02f7ee..58b8537e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -293,10 +293,10 @@ jobs: toolchain: stable components: clippy - - name: Set up Python 3.7 🐍 + - name: Set up Python 3.8 🐍 uses: actions/setup-python@v1 with: - python-version: '3.7' + python-version: '3.8' - uses: actions/checkout@v1 @@ -328,10 +328,6 @@ jobs: - name: smoke test run: python3 -c 'from microvmi import Microvmi, DriverType, CommonInitParamsPy, DriverInitParamsPy, KVMInitParamsPy' - # setup docker cache to speedup rest of the job - - name: Docker Layer Caching - uses: satackey/action-docker-layer-caching@v0.0.11 - - name: Build Wheels with manylinux run: nox -r -s generate_wheels -- --features xen,kvm,virtualbox,mflow --release working-directory: python diff --git a/Cargo.lock b/Cargo.lock index 35b61ecc..b7608a81 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -205,7 +205,7 @@ checksum = "51e3973b165dc0f435831a9e426de67e894de532754ff7a3f307c03ee5dec7dc" dependencies = [ "clap", "heck", - "indexmap", + "indexmap 1.9.3", "log", "proc-macro2 1.0.78", "quote 1.0.35", @@ -501,6 +501,12 @@ dependencies = [ "termcolor", ] +[[package]] +name = "equivalent" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" + [[package]] name = "errno" version = "0.3.8" @@ -638,6 +644,12 @@ version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" +[[package]] +name = "hashbrown" +version = "0.14.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" + [[package]] name = "heck" version = "0.3.3" @@ -687,6 +699,16 @@ dependencies = [ "hashbrown 0.12.3", ] +[[package]] +name = "indexmap" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233cf39063f058ea2caae4091bf4a3ef70a653afbc026f5c4a4135d114e3c177" +dependencies = [ + "equivalent", + "hashbrown 0.14.3", +] + [[package]] name = "indicatif" version = "0.16.2" @@ -831,6 +853,16 @@ dependencies = [ "winapi", ] +[[package]] +name = "libloading" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c571b676ddfc9a8c12f1f3d3085a7b163966a8fd8098a90640953ce5f6170161" +dependencies = [ + "cfg-if 1.0.0", + "windows-sys 0.48.0", +] + [[package]] name = "libredox" version = "0.0.1" @@ -1110,6 +1142,27 @@ dependencies = [ "autocfg", ] +[[package]] +name = "num_enum" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02339744ee7253741199f897151b38e72257d13802d4ee837285cc2990a90845" +dependencies = [ + "num_enum_derive", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" +dependencies = [ + "proc-macro-crate", + "proc-macro2 1.0.78", + "quote 1.0.35", + "syn 2.0.50", +] + [[package]] name = "number_prefix" version = "0.4.0" @@ -1216,6 +1269,15 @@ dependencies = [ "termtree", ] +[[package]] +name = "proc-macro-crate" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284" +dependencies = [ + "toml_edit", +] + [[package]] name = "proc-macro-hack" version = "0.5.20+deprecated" @@ -1599,6 +1661,23 @@ dependencies = [ "serde", ] +[[package]] +name = "toml_datetime" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" + +[[package]] +name = "toml_edit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1" +dependencies = [ + "indexmap 2.2.3", + "toml_datetime", + "winnow", +] + [[package]] name = "unicode-ident" version = "1.0.12" @@ -1942,6 +2021,15 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dff9641d1cd4be8d1a070daf9e3773c5f67e78b4d9d42263020c057706765c04" +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + [[package]] name = "x86_64" version = "0.12.4" @@ -1954,14 +2042,14 @@ dependencies = [ [[package]] name = "xenctrl" -version = "0.4.7" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8772f904a8f3851074434e58aa0a760c9f5b4022338e10217b7cd680d925cd42" +checksum = "6eec9ca9a7a076fd711e9e27bad61c0b90e0e0620784fdc53d4104e1df3100a9" dependencies = [ - "enum-primitive-derive", - "libloading 0.7.4", + "libloading 0.8.1", "log", "num-traits 0.2.18", + "num_enum", "xenctrl-sys", "xenvmevent-sys", ] diff --git a/Cargo.toml b/Cargo.toml index 0afd8963..12fa4d18 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,14 @@ crate-type = ["cdylib", "lib"] [features] # Xen driver -xen = ["xenctrl", "xenstore-rs", "xenforeignmemory", "xenevtchn", "xenvmevent-sys", "libc"] +xen = [ + "xenctrl", + "xenstore-rs", + "xenforeignmemory", + "xenevtchn", + "xenvmevent-sys", + "libc", +] # KVM driver kvm = ["kvmi"] # VirtualBox driver @@ -34,17 +41,24 @@ nix = "^0.23.0" enum-iterator = "0.7.0" thiserror = "1.0" libc = { version = "0.2.58", optional = true } -xenctrl = { version = "=0.4.7", optional = true } +xenctrl = { version = "=0.6.0", optional = true } xenstore-rs = { version = "=0.3.2", optional = true } xenforeignmemory = { version = "=0.2.3", optional = true } xenevtchn = { version = "=0.1.6", optional = true } xenvmevent-sys = { version = "=0.1.3", optional = true } kvmi = { version = "0.4.0", optional = true } fdp = { version = "=0.2.5", optional = true } -winapi = { version = "0.3", features = ["tlhelp32", "winnt", "handleapi", "securitybaseapi"], optional = true } +winapi = { version = "0.3", features = [ + "tlhelp32", + "winnt", + "handleapi", + "securitybaseapi", +], optional = true } widestring = { version = "0.4", optional = true } ntapi = { version = "0.3", optional = true } -vid-sys = { version = "=0.3.0", features = ["deprecated-apis"], optional = true } +vid-sys = { version = "=0.3.0", features = [ + "deprecated-apis", +], optional = true } memflow = { version = "0.1.5", optional = true } [dev-dependencies] @@ -78,8 +92,16 @@ section = "libs" priority = "optional" # add generated libmicrovmi.h header assets = [ - ["target/release/libmicrovmi.so", "usr/lib/libmicrovmi.so", "644"], - ["target/release/capi/libmicrovmi.h", "usr/include/libmicrovmi.h", "644"], + [ + "target/release/libmicrovmi.so", + "usr/lib/libmicrovmi.so", + "644", + ], + [ + "target/release/capi/libmicrovmi.h", + "usr/include/libmicrovmi.h", + "644", + ], ] [package.metadata.release] @@ -89,6 +111,4 @@ assets = [ disable-publish = true [workspace] -members = [ - "python" -] +members = ["python"] diff --git a/build.rs b/build.rs index 344aa66c..89600d51 100644 --- a/build.rs +++ b/build.rs @@ -38,8 +38,5 @@ fn main() { println!("cargo:rerun-if-changed=src/capi.rs"); // if it has been removed - println!( - "{}", - format!("cargo:rerun-if-changed={}", &out_path.display()) - ); + println!("cargo:rerun-if-changed={}", &out_path.display()); } diff --git a/python/noxfile.py b/python/noxfile.py index 520b6e44..afebbef8 100644 --- a/python/noxfile.py +++ b/python/noxfile.py @@ -6,12 +6,12 @@ CUR_DIR = Path(__file__).parent # default sessions for nox -nox.options.sessions = ["fmt", "lint", "type", "test"] +nox.options.sessions = ["fmt", "lint", "test"] @nox.session def fmt(session): - session.install("black==20.8b1") + session.install("black==24.2.0") # note: black doesn't support setup.cfg # so we hardcode the config here session.run("black", "--line-length", "120", ".") diff --git a/python/requirements.txt b/python/requirements.txt index 1e43179a..a40f4232 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -1,4 +1,4 @@ -setuptools-rust -setuptools==65.5.1 +setuptools-rust==1.1.2 +setuptools==59.6.0 wheel toml==0.10.2 diff --git a/python/src/lib.rs b/python/src/lib.rs index da927482..33878009 100644 --- a/python/src/lib.rs +++ b/python/src/lib.rs @@ -118,9 +118,9 @@ impl MicrovmiExt { size: usize, ) -> PyResult<(&'p PyBytes, u64)> { let mut bytes_read: u64 = 0; - let pybuffer: &PyBytes = PyBytes::new_with(py, size, |mut buffer| { + let pybuffer: &PyBytes = PyBytes::new_with(py, size, |buffer| { self.driver - .read_physical(paddr, &mut buffer, &mut bytes_read) + .read_physical(paddr, buffer, &mut bytes_read) .ok(); Ok(()) })?; diff --git a/src/api/mod.rs b/src/api/mod.rs index e9c9ded0..89bf7234 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -8,18 +8,22 @@ pub mod events; pub mod params; pub mod registers; -bitflags! { - pub struct Access: u32 { - const R=0b00000001; - const W=0b00000010; - const X=0b00000100; - const NIL=0b00000000; - const RW=Self::R.bits | Self::W.bits; - const WX=Self::W.bits | Self::X.bits; - const RX=Self::R.bits | Self::X.bits; - const RWX=Self::R.bits | Self::W.bits | Self::X.bits; +#[allow(clippy::bad_bit_mask)] +mod flags { + bitflags! { + pub struct Access: u32 { + const NIL=0b00000000; + const R=0b00000001; + const W=0b00000010; + const X=0b00000100; + const RW=Self::R.bits | Self::W.bits; + const WX=Self::W.bits | Self::X.bits; + const RX=Self::R.bits | Self::X.bits; + const RWX=Self::R.bits | Self::W.bits | Self::X.bits; + } } } +pub use flags::Access; ///Represents the available hypervisor VMI drivers supported by libmicrovmi #[repr(C)] diff --git a/src/driver/kvm.rs b/src/driver/kvm.rs index 0b81886b..c25ba4ff 100644 --- a/src/driver/kvm.rs +++ b/src/driver/kvm.rs @@ -1,9 +1,6 @@ -use std::convert::From; use std::convert::TryFrom; use std::convert::TryInto; use std::error::Error; -use std::mem; -use std::vec::Vec; use kvmi::constants::PAGE_SIZE; #[cfg(test)] // only needed for tests @@ -130,7 +127,7 @@ impl Kvm { // set vec_events size let vcpu_count = kvm.get_vcpu_count()?; - kvm.vec_events.resize_with(vcpu_count.try_into()?, || None); + kvm.vec_events.resize_with(vcpu_count.into(), || None); // enable CR event intercept by default // (interception will take place when CR register will be specified) @@ -323,7 +320,7 @@ impl Introspectable for Kvm { }; let vcpu = kvmi_event.vcpu; - let vcpu_index: usize = vcpu.try_into()?; + let vcpu_index: usize = vcpu.into(); self.vec_events[vcpu_index] = Some(kvmi_event); Ok(Some(Event { @@ -343,9 +340,9 @@ impl Introspectable for Kvm { EventReplyType::Continue => KVMiEventReply::Continue, }; // get KVMiEvent associated with this VCPU - let vcpu_index: usize = event.vcpu.try_into()?; - let kvmi_event = mem::replace(&mut self.vec_events[vcpu_index], None).unwrap(); - Ok(self.kvmi.reply(&kvmi_event, kvm_reply_type)?) + let vcpu_index: usize = event.vcpu.into(); + let kvmi_event = &mut self.vec_events[vcpu_index].take().unwrap(); + Ok(self.kvmi.reply(kvmi_event, kvm_reply_type)?) } fn get_driver_type(&self) -> DriverType { diff --git a/src/driver/memflow.rs b/src/driver/memflow.rs index 417e97fe..dbec168e 100644 --- a/src/driver/memflow.rs +++ b/src/driver/memflow.rs @@ -42,7 +42,7 @@ impl Memflow { // then insert vm_name value as 'name' connector args if init_params.common.is_some() { create_connector_args = - create_connector_args.insert("name", &*init_params.common.unwrap().vm_name); + create_connector_args.insert("name", &init_params.common.unwrap().vm_name); } } _ => {} @@ -54,7 +54,7 @@ impl Memflow { // for each string, split at '=' to get key, value for s in args.iter() { let (key, value) = s - .split_once("=") + .split_once('=') .ok_or_else(|| MemflowDriverError::InvalidConnectorArgument(s.clone()))?; // push it into memflow ConnectorArgs type create_connector_args = create_connector_args.insert(key, value); diff --git a/src/driver/xen.rs b/src/driver/xen.rs index 042b017f..d174826b 100644 --- a/src/driver/xen.rs +++ b/src/driver/xen.rs @@ -30,7 +30,7 @@ pub struct Xen { xc: XenControl, xev: XenEventChannel, xen_fgn: XenForeignMem, - dom_name: String, + _dom_name: String, domid: u32, back_ring: vm_event_back_ring, } @@ -110,7 +110,7 @@ impl Xen { xc, xev, xen_fgn, - dom_name: domain_name, + _dom_name: domain_name, domid: cand_domid, back_ring, }; @@ -142,7 +142,7 @@ impl Introspectable for Xen { .map(self.domid, PROT_READ, gfn) .map_err(XenDriverError::from)?; // determine how much we can read - let read_len = if (page_offset + count_mut as u64) > u64::from(PAGE_SIZE) { + let read_len = if (page_offset + count_mut) > u64::from(PAGE_SIZE) { u64::from(PAGE_SIZE) - page_offset } else { count_mut @@ -182,10 +182,10 @@ impl Introspectable for Xen { .map(self.domid, PROT_WRITE, pfn) .map_err(XenDriverError::from)?; // determine how much we can write - let write_len = if (offset + count_mut as u64) > u64::from(PAGE_SIZE) { + let write_len = if (offset + count_mut) > u64::from(PAGE_SIZE) { u64::from(PAGE_SIZE) - offset } else { - count_mut as u64 + count_mut }; // do the write @@ -204,6 +204,7 @@ impl Introspectable for Xen { .xc .domain_maximum_gpfn(self.domid) .map_err(XenDriverError::from)?; + Ok(max_gpfn << PAGE_SHIFT) } @@ -211,10 +212,9 @@ impl Introspectable for Xen { let domain_info = self .xc .domain_getinfo(self.domid) - .map_err(XenDriverError::from)?; - Ok((domain_info.max_vcpu_id + 1) - .try_into() - .map_err(XenDriverError::from)?) + .map_err(XenDriverError::from)? + .ok_or("Domain info not found")?; + Ok((domain_info.max_vcpu_id + 1).try_into().unwrap()) } fn read_registers(&self, vcpu: u16) -> Result> { @@ -345,41 +345,13 @@ impl Introspectable for Xen { cpu.gs_limit = x86_registers.gs.limit; cpu.ss_limit = x86_registers.ss.limit; cpu.tr_limit = x86_registers.tr.limit; - cpu.cs_sel = x86_registers - .cs - .selector - .try_into() - .map_err(XenDriverError::from)?; - cpu.ds_sel = x86_registers - .ds - .selector - .try_into() - .map_err(XenDriverError::from)?; - cpu.es_sel = x86_registers - .es - .selector - .try_into() - .map_err(XenDriverError::from)?; - cpu.fs_sel = x86_registers - .fs - .selector - .try_into() - .map_err(XenDriverError::from)?; - cpu.gs_sel = x86_registers - .gs - .selector - .try_into() - .map_err(XenDriverError::from)?; - cpu.ss_sel = x86_registers - .ss - .selector - .try_into() - .map_err(XenDriverError::from)?; - cpu.tr_sel = x86_registers - .tr - .selector - .try_into() - .map_err(XenDriverError::from)?; + cpu.cs_sel = x86_registers.cs.selector.into(); + cpu.ds_sel = x86_registers.ds.selector.into(); + cpu.es_sel = x86_registers.es.selector.into(); + cpu.fs_sel = x86_registers.fs.selector.into(); + cpu.gs_sel = x86_registers.gs.selector.into(); + cpu.ss_sel = x86_registers.ss.selector.into(); + cpu.tr_sel = x86_registers.tr.selector.into(); } } self.xc.domain_hvm_setcontext(