Merge branch 'main' into dependabot/cargo/memchr-2.5.0

This commit is contained in:
Viresh Kumar 2022-05-03 19:02:38 +05:30 committed by GitHub
commit 7ca8728df2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 15 deletions

4
Cargo.lock generated
View File

@ -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"

View File

@ -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<T> = std::result::Result<T, Error>;
@ -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

View File

@ -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<D: 'static + GpioDevice + Sync + Send> VhostUserBackendMut<VringRwLock, ()>
VhostUserProtocolFeatures::MQ | VhostUserProtocolFeatures::CONFIG
}
fn get_config(&self, _offset: u32, _size: u32) -> Vec<u8> {
fn get_config(&self, offset: u32, size: u32) -> Vec<u8> {
unsafe {
from_raw_parts(
self.controller.get_config() as *const _ as *const _,
size_of::<VirtioGpioConfig>(),
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::<VirtioGpioConfig>(),
)
.to_vec()
});
assert_eq!(
backend.get_config(0, size_of::<VirtioGpioConfig>() as u32),
unsafe {
from_raw_parts(
&config as *const _ as *const _,
size_of::<VirtioGpioConfig>(),
)
.to_vec()
}
);
let mem = GuestMemoryAtomic::new(
GuestMemoryMmap::<()>::from_ranges(&[(GuestAddress(0), 0x1000)]).unwrap(),