From 413a840d0b9b786b15af693d285a705f117aa2af Mon Sep 17 00:00:00 2001 From: Viresh Kumar Date: Fri, 29 Apr 2022 12:57:14 +0530 Subject: [PATCH 1/2] gpio: Fix get_config() get_config() must return only the relevant part of the config, as requested by the caller, instead of returning entire config structure. Signed-off-by: Viresh Kumar --- gpio/src/gpio.rs | 6 ++++-- gpio/src/vhu_gpio.rs | 29 ++++++++++++++++++----------- 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/gpio/src/gpio.rs b/gpio/src/gpio.rs index 0a6f3ca..f14bfb3 100644 --- a/gpio/src/gpio.rs +++ b/gpio/src/gpio.rs @@ -14,7 +14,7 @@ use libgpiod::{ RequestConfig, }; use thiserror::Error as ThisError; -use vm_memory::{Le16, Le32}; +use vm_memory::{ByteValued, Le16, Le32}; type Result = std::result::Result; @@ -79,7 +79,7 @@ const VIRTIO_GPIO_IRQ_TYPE_ALL: u16 = VIRTIO_GPIO_IRQ_TYPE_EDGE_BOTH | VIRTIO_GPIO_IRQ_TYPE_LEVEL_LOW; /// Virtio GPIO Configuration -#[derive(Clone, Debug, PartialEq)] +#[derive(Copy, Clone, Debug, Default, PartialEq)] #[repr(C)] pub(crate) struct VirtioGpioConfig { pub(crate) ngpio: Le16, @@ -87,6 +87,8 @@ pub(crate) struct VirtioGpioConfig { pub(crate) gpio_names_size: Le32, } +unsafe impl ByteValued for VirtioGpioConfig {} + /// Trait that represents an GPIO Device. /// /// This trait is introduced for development purposes only, and should not diff --git a/gpio/src/vhu_gpio.rs b/gpio/src/vhu_gpio.rs index 5f82def..67774f5 100644 --- a/gpio/src/vhu_gpio.rs +++ b/gpio/src/vhu_gpio.rs @@ -27,7 +27,7 @@ use vm_memory::{ use vmm_sys_util::epoll::EventSet; use vmm_sys_util::eventfd::{EventFd, EFD_NONBLOCK}; -use crate::gpio::{GpioController, GpioDevice, VirtioGpioConfig, VIRTIO_GPIO_IRQ_TYPE_NONE}; +use crate::gpio::{GpioController, GpioDevice, VIRTIO_GPIO_IRQ_TYPE_NONE}; /// Possible values of the status field const VIRTIO_GPIO_STATUS_OK: u8 = 0x0; @@ -394,11 +394,15 @@ impl VhostUserBackendMut VhostUserProtocolFeatures::MQ | VhostUserProtocolFeatures::CONFIG } - fn get_config(&self, _offset: u32, _size: u32) -> Vec { + fn get_config(&self, offset: u32, size: u32) -> Vec { unsafe { from_raw_parts( - self.controller.get_config() as *const _ as *const _, - size_of::(), + self.controller + .get_config() + .as_slice() + .as_ptr() + .offset(offset as isize) as *const _ as *const _, + size as usize, ) .to_vec() } @@ -1110,13 +1114,16 @@ mod tests { gpio_names_size: From::from(names_size as u32), }; - assert_eq!(backend.get_config(0, 0), unsafe { - from_raw_parts( - &config as *const _ as *const _, - size_of::(), - ) - .to_vec() - }); + assert_eq!( + backend.get_config(0, size_of::() as u32), + unsafe { + from_raw_parts( + &config as *const _ as *const _, + size_of::(), + ) + .to_vec() + } + ); let mem = GuestMemoryAtomic::new( GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x1000)]).unwrap(), From 014cc2bdd57c5789195850302f42b3287406657f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 May 2022 13:02:36 +0000 Subject: [PATCH 2/2] build(deps): bump unicode-xid from 0.2.2 to 0.2.3 Bumps [unicode-xid](https://github.com/unicode-rs/unicode-xid) from 0.2.2 to 0.2.3. - [Release notes](https://github.com/unicode-rs/unicode-xid/releases) - [Commits](https://github.com/unicode-rs/unicode-xid/commits) --- updated-dependencies: - dependency-name: unicode-xid dependency-type: indirect update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0484ade..4987e8a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -352,9 +352,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b683b2b825c8eef438b77c36a06dc262294da3d5a5813fac20da149241dcd44d" +checksum = "7ff7c592601f11445996a06f8ad0c27f094a58857c2f89e97974ab9235b92c52" dependencies = [ "proc-macro2", "quote", @@ -412,9 +412,9 @@ dependencies = [ [[package]] name = "unicode-xid" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "957e51f3646910546462e67d5f7599b9e4fb8acdd304b087a6494730f9eebf04" [[package]] name = "version_check"