Merge remote-tracking branch 'upstream/main' into HEAD

Signed-off-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
This commit is contained in:
Manos Pitsidianakis 2023-10-16 14:48:56 +03:00
commit d40c707f2f
No known key found for this signature in database
GPG key ID: 7729C7707F7E09D0
104 changed files with 125 additions and 93 deletions

50
Cargo.lock generated
View file

@ -101,9 +101,9 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9"
[[package]]
name = "async-trait"
version = "0.1.73"
version = "0.1.74"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc00ceb34980c03614e35a3a4e218276a0a824e911d07651cd0d858a51e8c0f0"
checksum = "a66537f1bb974b254c98ed142ff995236e81b9d0fe4db0575f46612cb15eb0f9"
dependencies = [
"proc-macro2",
"quote",
@ -144,7 +144,7 @@ version = "0.66.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"cexpr",
"clang-sys",
"lazy_static",
@ -166,9 +166,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.4.0"
version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635"
checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07"
[[package]]
name = "byteorder"
@ -334,7 +334,7 @@ version = "4.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74351c3392ea1ff6cd2628e0042d268ac2371cb613252ff383b6dfa50d22fa79"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"libc",
]
@ -597,9 +597,9 @@ checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b"
[[package]]
name = "libgpiod"
version = "0.1.0"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9e9fdf4b437063f5697151f9ead12bafa223958e243f2f736107ec68c2b88231"
checksum = "f726cc57967d3b982e1b3074cdfa8f68a3b36f345fd80b5c0ccb0dfd7dee0f79"
dependencies = [
"errno 0.2.8",
"intmap",
@ -633,7 +633,7 @@ name = "libspa"
version = "0.7.2"
source = "git+https://gitlab.freedesktop.org/pipewire/pipewire-rs.git?rev=5fe090b3ac8f6fed756c4871ac18f26edda3ac89#5fe090b3ac8f6fed756c4871ac18f26edda3ac89"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"cc",
"convert_case",
"cookie-factory",
@ -817,7 +817,7 @@ version = "0.7.2"
source = "git+https://gitlab.freedesktop.org/pipewire/pipewire-rs.git?rev=5fe090b3ac8f6fed756c4871ac18f26edda3ac89#5fe090b3ac8f6fed756c4871ac18f26edda3ac89"
dependencies = [
"anyhow",
"bitflags 2.4.0",
"bitflags 2.4.1",
"libc",
"libspa",
"libspa-sys",
@ -918,9 +918,9 @@ dependencies = [
[[package]]
name = "regex"
version = "1.10.0"
version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d119d7c7ca818f8a53c300863d4f87566aac09943aef5b355bb83969dae75d87"
checksum = "aaac441002f822bc9705a681810a4dd2963094b9ca0ddc41cb963a4c189189ea"
dependencies = [
"aho-corasick",
"memchr",
@ -930,9 +930,9 @@ dependencies = [
[[package]]
name = "regex-automata"
version = "0.4.1"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "465c6fc0621e4abc4187a2bda0937bfd4f722c2730b29562e19689ea796c9a4b"
checksum = "5011c7e263a695dc8ca064cddb722af1be54e517a280b12a5356f98366899e5d"
dependencies = [
"aho-corasick",
"memchr",
@ -941,9 +941,9 @@ dependencies = [
[[package]]
name = "regex-syntax"
version = "0.8.0"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3cbb081b9784b07cceb8824c8583f86db4814d172ab043f3c23f7dc600bf83d"
checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
[[package]]
name = "relative-path"
@ -997,11 +997,11 @@ dependencies = [
[[package]]
name = "rustix"
version = "0.38.18"
version = "0.38.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a74ee2d7c2581cd139b42447d7d9389b889bdaad3a73f1ebb16f2a3237bb19c"
checksum = "745ecfa778e66b2b63c88a61cb36e0eea109e803b0b86bf9879fbc77c70e86ed"
dependencies = [
"bitflags 2.4.0",
"bitflags 2.4.1",
"errno 0.3.5",
"libc",
"linux-raw-sys",
@ -1028,18 +1028,18 @@ checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090"
[[package]]
name = "serde"
version = "1.0.188"
version = "1.0.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9e0fcba69a370eed61bcf2b728575f726b50b55cba78064753d708ddc7549e"
checksum = "8e422a44e74ad4001bdc8eede9a4570ab52f71190e9c076d14369f38b9200537"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.188"
version = "1.0.189"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4eca7ac642d82aa35b60049a6eccb4be6be75e599bd2e9adb5f875a737654af2"
checksum = "1e48d1f918009ce3145511378cf68d613e3b3d9137d67272562080d68a2b32d5"
dependencies = [
"proc-macro2",
"quote",
@ -1718,9 +1718,9 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "winnow"
version = "0.5.16"
version = "0.5.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "037711d82167854aff2018dfd193aa0fef5370f456732f0d5a0c59b0f1b4b907"
checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c"
dependencies = [
"memchr",
]

View file

@ -2,11 +2,11 @@
resolver = "2"
members = [
"crates/vhost-device-gpio",
"crates/vhost-device-i2c",
"crates/vhost-device-rng",
"crates/vhost-device-scsi",
"crates/vhost-device-scmi",
"vhost-device-gpio",
"vhost-device-i2c",
"vhost-device-rng",
"vhost-device-scsi",
"vhost-device-scmi",
"crates/sound",
"crates/vhost-device-vsock",
"vhost-device-vsock",
]

View file

@ -8,13 +8,29 @@ crates.
Here is the list of device backends that we support:
- [GPIO](https://github.com/rust-vmm/vhost-device/blob/main/crates/vhost-device-gpio/README.md)
- [I2C](https://github.com/rust-vmm/vhost-device/blob/main/crates/vhost-device-i2c/README.md)
- [RNG](https://github.com/rust-vmm/vhost-device/blob/main/crates/vhost-device-rng/README.md)
- [SCMI](https://github.com/rust-vmm/vhost-device/blob/main/crates/vhost-device-scmi/README.md)
- [SCSI](https://github.com/rust-vmm/vhost-device/blob/main/crates/vhost-device-scsi/README.md)
- [GPIO](https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-gpio/README.md)
- [I2C](https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-i2c/README.md)
- [RNG](https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-rng/README.md)
- [SCMI](https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-scmi/README.md)
- [SCSI](https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-scsi/README.md)
- [Sound](https://github.com/rust-vmm/vhost-device/blob/main/crates/sound/README.md)
- [VSOCK](https://github.com/rust-vmm/vhost-device/blob/main/crates/vhost-device-vsock/README.md)
- [VSOCK](https://github.com/rust-vmm/vhost-device/blob/main/vhost-device-vsock/README.md)
For `vhost-user` device backends that have no final specification merged into
the [VIRTIO specification](https://github.com/oasis-tcs/virtio-spec), or have partial functionality, we have a [staging
workspace](./staging/).
More information may be found in its [README file](./staging/README.md).
Here is the list of device backends in **staging**:
- Currently none.
<!--
Template:
- [`_DEVICE_NAME_`](https://github.com/rust-vmm/vhost-device/blob/main/staging/vhost-device-_DEVICE_NAME_/README.md)
-->
## Testing and Code Coverage

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -1 +0,0 @@
../../LICENSE-BSD-3-Clause

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -1 +0,0 @@
../../LICENSE-BSD-3-Clause

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -1 +0,0 @@
../../LICENSE-BSD-3-Clause

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -1 +0,0 @@
../../LICENSE-BSD-3-Clause

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -1 +0,0 @@
../../LICENSE-BSD-3-Clause

View file

@ -1 +0,0 @@
../../LICENSE-APACHE

View file

@ -1 +0,0 @@
../../LICENSE-BSD-3-Clause

1
staging/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
target/

3
staging/Cargo.toml Normal file
View file

@ -0,0 +1,3 @@
[workspace]
resolver = "2"
members = []

17
staging/README.md Normal file
View file

@ -0,0 +1,17 @@
# vhost-device `staging` workspace
This directory includes a separate Cargo workspace to include working vhost-user backend implementations that concern devices that have partial functionality and devices (and/or functionality) not yet ratified in the [VIRTIO specification](https://github.com/oasis-tcs/virtio-spec).
For more details about vhost-device you can refer to the repository [README](../README.md).
To add a new member crate:
1. Place it under this directory, [`./staging`](../staging).
2. Append its name in the `workspace.members` array field of [the workspace manifest file](./Cargo.toml).
3. Update the crate list in the repository [README](../README.md).
## Testing and Continuous Integration
**Notice** : The CI runs on the root workspace only.
This means that `staging` crates can have failing tests and bring down code coverage without automatic checks.
Tests can still be run locally as part of the development process.
To add a crate to the CI, add it to the root `Cargo.toml` `workspace.members` array as well as the `staging` manifest.

View file

@ -29,7 +29,7 @@ vm-memory = "0.12"
vmm-sys-util = "0.11"
[target.'cfg(target_env = "gnu")'.dependencies]
libgpiod = { version = "0.1" }
libgpiod = "0.2"
[dev-dependencies]
assert_matches = "1.5"

View file

@ -0,0 +1 @@
../LICENSE-APACHE

View file

@ -0,0 +1 @@
../LICENSE-BSD-3-Clause

View file

@ -91,18 +91,11 @@ pub(crate) struct PhysLineState {
}
pub(crate) struct PhysDevice {
chip: chip::Chip,
chip: Mutex<chip::Chip>,
ngpio: u16,
state: Vec<RwLock<PhysLineState>>,
state: Vec<Mutex<PhysLineState>>,
}
// SAFETY: Safe as the structure can be sent to another thread.
unsafe impl Send for PhysDevice {}
// SAFETY: Safe as the structure can be shared with another thread as the state
// is protected with a lock.
unsafe impl Sync for PhysDevice {}
impl GpioDevice for PhysDevice {
fn open(device: u32) -> Result<Self>
where
@ -113,15 +106,19 @@ impl GpioDevice for PhysDevice {
let ngpio = chip.info().map_err(Error::GpiodFailed)?.num_lines() as u16;
// Can't set a vector to all None easily
let mut state: Vec<RwLock<PhysLineState>> = Vec::new();
let mut state: Vec<Mutex<PhysLineState>> = Vec::new();
state.resize_with(ngpio as usize, || {
RwLock::new(PhysLineState {
Mutex::new(PhysLineState {
request: None,
buffer: None,
})
});
Ok(PhysDevice { chip, ngpio, state })
Ok(PhysDevice {
chip: Mutex::new(chip),
ngpio,
state,
})
}
fn num_gpios(&self) -> Result<u16> {
@ -131,6 +128,8 @@ impl GpioDevice for PhysDevice {
fn gpio_name(&self, gpio: u16) -> Result<String> {
let line_info = self
.chip
.lock()
.unwrap()
.line_info(gpio.into())
.map_err(Error::GpiodFailed)?;
@ -140,6 +139,8 @@ impl GpioDevice for PhysDevice {
fn direction(&self, gpio: u16) -> Result<u8> {
let line_info = self
.chip
.lock()
.unwrap()
.line_info(gpio.into())
.map_err(Error::GpiodFailed)?;
@ -152,7 +153,7 @@ impl GpioDevice for PhysDevice {
fn set_direction(&self, gpio: u16, dir: u8, value: u32) -> Result<()> {
let mut lsettings = line::Settings::new().map_err(Error::GpiodFailed)?;
let state = &mut self.state[gpio as usize].write().unwrap();
let state = &mut self.state[gpio as usize].lock().unwrap();
match dir {
VIRTIO_GPIO_DIRECTION_NONE => {
@ -195,29 +196,20 @@ impl GpioDevice for PhysDevice {
.set_consumer("vhu-gpio")
.map_err(Error::GpiodFailed)?;
// This is causing a warning since libgpiod's request_config is
// not `Send`.
// We, however, unsafely claim that it is by marking PhysDevice as
// `Send`. This is wrong, but until we figure out what to do, we
// just silence the clippy warning here.
//
// https://github.com/rust-vmm/vhost-device/issues/442 tracks
// finding a solution to this.
#[allow(clippy::arc_with_non_send_sync)]
{
state.request = Some(Arc::new(Mutex::new(
self.chip
.request_lines(Some(&rconfig), &lconfig)
.map_err(Error::GpiodFailed)?,
)));
}
state.request = Some(Arc::new(Mutex::new(
self.chip
.lock()
.unwrap()
.request_lines(Some(&rconfig), &lconfig)
.map_err(Error::GpiodFailed)?,
)));
}
Ok(())
}
fn value(&self, gpio: u16) -> Result<u8> {
let state = &self.state[gpio as usize].read().unwrap();
let state = self.state[gpio as usize].lock().unwrap();
if let Some(request) = &state.request {
Ok(request
@ -233,11 +225,11 @@ impl GpioDevice for PhysDevice {
}
fn set_value(&self, gpio: u16, value: u32) -> Result<()> {
let state = &self.state[gpio as usize].read().unwrap();
let mut state = self.state[gpio as usize].lock().unwrap();
// Direction change can follow value change, don't fail here for invalid
// direction.
if let Some(request) = &state.request {
if let Some(request) = &mut state.request {
let value = line::Value::new(value as i32).map_err(Error::GpiodFailed)?;
request
.lock()
@ -250,7 +242,7 @@ impl GpioDevice for PhysDevice {
}
fn set_irq_type(&self, gpio: u16, value: u16) -> Result<()> {
let state = &mut self.state[gpio as usize].write().unwrap();
let mut state = self.state[gpio as usize].lock().unwrap();
let edge = match value {
VIRTIO_GPIO_IRQ_TYPE_EDGE_RISING => line::Edge::Rising,
@ -289,7 +281,7 @@ impl GpioDevice for PhysDevice {
state
.request
.as_ref()
.as_mut()
.unwrap()
.lock()
.unwrap()
@ -326,18 +318,21 @@ impl GpioDevice for PhysDevice {
// This design also allows `wait_for_interrupt()` to not take a lock for the entire
// duration, which can potentially also starve the other thread trying to disable the
// interrupt.
let request = {
let state = &self.state[gpio as usize].write().unwrap();
match &state.request {
Some(x) => x.clone(),
None => return Err(Error::GpioIrqNotEnabled),
}
// Take the state lock, get the request and release the state lock again
let request = {
let mut state = self.state[gpio as usize].lock().unwrap();
state
.request
.as_mut()
.ok_or(Error::GpioIrqNotEnabled)?
.clone()
};
// Only take the request lock now
let request = request.lock().unwrap();
// Wait for the interrupt for a second.
// Wait for the interrupt for a second while only taking the request lock
if !request
.wait_edge_events(Some(Duration::new(1, 0)))
.map_err(Error::GpiodFailed)?
@ -345,8 +340,8 @@ impl GpioDevice for PhysDevice {
return Ok(false);
}
// The interrupt has already occurred, we can lock now just fine.
let state = &mut self.state[gpio as usize].write().unwrap();
// The interrupt has already occurred, we can lock the state again.
let mut state = self.state[gpio as usize].lock().unwrap();
if let Some(buffer) = &mut state.buffer {
request
.read_edge_events(buffer)

View file

@ -0,0 +1 @@
../LICENSE-APACHE

View file

@ -0,0 +1 @@
../LICENSE-BSD-3-Clause

View file

@ -0,0 +1 @@
../LICENSE-APACHE

View file

@ -0,0 +1 @@
../LICENSE-BSD-3-Clause

View file

@ -0,0 +1 @@
../LICENSE-APACHE

View file

@ -0,0 +1 @@
../LICENSE-BSD-3-Clause

View file

@ -0,0 +1 @@
../LICENSE-APACHE

View file

@ -0,0 +1 @@
../LICENSE-BSD-3-Clause

View file

@ -0,0 +1 @@
../LICENSE-APACHE

View file

@ -0,0 +1 @@
../LICENSE-BSD-3-Clause

Some files were not shown because too many files have changed in this diff Show more