Skip to content

Commit c8193d9

Browse files
Erik Schillingepilys
Erik Schilling
authored andcommitted
Update to vm-memory 0.13.1
Mostly this introduces the traits WriteVolatile and ReadVolatile. Since these can deal more efficiently deal with the volatile semantics, some old methods got deprecated. Mostly that means replacing Read/Write with {Read,Write}Volatile. Some code still requires Read/Write in order to do calls like .flush() - which is not part of the {Read,Write}Volatile contract. Signed-off-by: Erik Schilling <[email protected]>
1 parent 9a1bbfb commit c8193d9

File tree

10 files changed

+33
-26
lines changed

10 files changed

+33
-26
lines changed

crates/devices/virtio-blk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ edition = "2021"
1313
backend-stdio = []
1414

1515
[dependencies]
16-
vm-memory = "0.12.0"
16+
vm-memory = "0.13.1"
1717
vmm-sys-util = "0.11.0"
1818
log = "0.4.17"
1919
virtio-queue = { path = "../../virtio-queue" }
2020
virtio-device = { path = "../../virtio-device" }
2121
virtio-bindings = { path = "../../virtio-bindings", version = "0.2.1" }
2222

2323
[dev-dependencies]
24-
vm-memory = { version = "0.12.0", features = ["backend-mmap", "backend-atomic"] }
24+
vm-memory = { version = "0.13.1", features = ["backend-mmap", "backend-atomic"] }
2525
virtio-queue = { path = "../../virtio-queue", features = ["test-utils"] }

crates/devices/virtio-blk/src/stdio_executor.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,21 @@
1717
//! request via [`StdIoBackend::execute`](struct.StdIoBackend.html#method.execute) method.
1818
//! The `StdIoBackend` is wrapping the block device backend and keeps the number of sectors of the
1919
//! backing file and its negotiated features too. This backend has to be, at least for now,
20-
//! `io::Read` and `io::Write`. In the future, we might add some abstraction for the file access
21-
//! operations.
20+
//! `vm_memory::ReadVolatile` and `vm_memory::WriteVolatile`.
21+
//! In the future, we might add some abstraction for the file access operations.
2222
//!
2323
//! For more complex executors, that need asynchronous dispatch of requests for example, we can
2424
//! add separate modules for those abstractions as well.
2525
2626
use std::fmt::{self, Display};
27-
use std::io::{Read, Seek, SeekFrom, Write};
27+
use std::io::{Seek, SeekFrom};
2828
use std::{io, mem, result};
2929

3030
use log::{error, warn};
3131

32-
use vm_memory::{Address, ByteValued, Bytes, GuestMemory, GuestMemoryError};
32+
use vm_memory::{
33+
Address, ByteValued, Bytes, GuestMemory, GuestMemoryError, ReadVolatile, WriteVolatile,
34+
};
3335
use vmm_sys_util::file_traits::FileSync;
3436
use vmm_sys_util::write_zeroes::{PunchHole, WriteZeroesAt};
3537

@@ -43,9 +45,12 @@ use virtio_bindings::bindings::virtio_blk::{
4345

4446
/// Trait that keeps as supertraits the ones that are necessary for the `StdIoBackend` abstraction
4547
/// used for the virtio block request execution.
46-
pub trait Backend: Read + Write + Seek + FileSync + PunchHole + WriteZeroesAt {}
48+
pub trait Backend:
49+
ReadVolatile + WriteVolatile + Seek + FileSync + PunchHole + WriteZeroesAt
50+
{
51+
}
4752

48-
impl<B: Read + Write + Seek + FileSync + PunchHole + WriteZeroesAt> Backend for B {}
53+
impl<B: ReadVolatile + WriteVolatile + Seek + FileSync + PunchHole + WriteZeroesAt> Backend for B {}
4954

5055
/// One or more `DiscardWriteZeroes` structs are used to describe the data for
5156
/// discard or write zeroes command.
@@ -326,7 +331,7 @@ impl<B: Backend> StdIoBackend<B> {
326331
return Err(Error::InvalidDataLength);
327332
}
328333
for (data_addr, data_len) in request.data() {
329-
mem.read_exact_from(*data_addr, &mut self.inner, *data_len as usize)
334+
mem.read_exact_volatile_from(*data_addr, &mut self.inner, *data_len as usize)
330335
.map_err(|e| {
331336
if let GuestMemoryError::PartialBuffer {
332337
completed,
@@ -347,7 +352,7 @@ impl<B: Backend> StdIoBackend<B> {
347352
RequestType::Out => {
348353
self.check_access(total_len / SECTOR_SIZE, request.sector())?;
349354
for (data_addr, data_len) in request.data() {
350-
mem.write_all_to(*data_addr, &mut self.inner, *data_len as usize)
355+
mem.write_all_volatile_to(*data_addr, &mut self.inner, *data_len as usize)
351356
.map_err(Error::Write)?;
352357
}
353358
}
@@ -364,7 +369,7 @@ impl<B: Backend> StdIoBackend<B> {
364369
for (data_addr, data_len) in request.data() {
365370
// The device_id accesses are safe because we checked that the total data length
366371
// is VIRTIO_BLK_ID_BYTES, which is the size of the id as well.
367-
mem.read_exact_from(
372+
mem.read_exact_volatile_from(
368373
*data_addr,
369374
&mut &device_id[bytes_to_mem as usize..(*data_len + bytes_to_mem) as usize],
370375
*data_len as usize,
@@ -475,6 +480,8 @@ impl<B: Backend> StdIoBackend<B> {
475480
mod tests {
476481
use super::*;
477482

483+
use std::io::{Read, Write};
484+
478485
use vm_memory::guest_memory::Error::{InvalidGuestAddress, PartialBuffer};
479486
use vm_memory::{GuestAddress, GuestMemoryMmap};
480487
use vmm_sys_util::tempfile::TempFile;

crates/devices/virtio-console/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ edition = "2021"
1414
[dependencies]
1515
virtio-bindings = { path = "../../virtio-bindings", version = "0.2.1" }
1616
virtio-queue = { path = "../../virtio-queue", version = "0.9.0" }
17-
vm-memory = "0.12.0"
17+
vm-memory = "0.13.1"
1818

1919
[dev-dependencies]
2020
virtio-queue = { path = "../../virtio-queue", version = "0.9.0", features = ["test-utils"] }
21-
vm-memory = { version = "0.12.0", features = ["backend-mmap"] }
21+
vm-memory = { version = "0.13.1", features = ["backend-mmap"] }

crates/devices/virtio-console/src/console.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::io::{stdout, Stdout, Write};
1717
use std::ops::Deref;
1818
use std::sync::{Arc, Mutex};
1919
use virtio_queue::DescriptorChain;
20-
use vm_memory::{Bytes, GuestMemory, GuestMemoryError};
20+
use vm_memory::{Bytes, GuestMemory, GuestMemoryError, WriteVolatile};
2121

2222
/// Console device errors.
2323
#[derive(Debug)]
@@ -81,7 +81,7 @@ impl Display for Error {
8181

8282
/// Console struct that implements the abstraction of virtio console descriptor chain handling.
8383
#[derive(Clone, Debug)]
84-
pub struct Console<T: Write> {
84+
pub struct Console<T: Write + WriteVolatile> {
8585
/// Buffer that stores data to be sent to the driver.
8686
input_buffer: Arc<Mutex<Vec<u8>>>,
8787
/// Capacity of the input buffer.
@@ -110,7 +110,7 @@ impl Default for Console<Stdout> {
110110

111111
impl<T> Console<T>
112112
where
113-
T: Write,
113+
T: Write + WriteVolatile,
114114
{
115115
/// Create new console object with the default `capacity`.
116116
///
@@ -206,7 +206,7 @@ where
206206
}
207207
desc_chain
208208
.memory()
209-
.write_to(desc.addr(), &mut self.output, desc.len() as usize)
209+
.write_volatile_to(desc.addr(), &mut self.output, desc.len() as usize)
210210
.map_err(Error::WriteToOutputFailed)?;
211211

212212
self.output.flush().map_err(Error::OutputSinkFlushFailed)?;

crates/devices/virtio-vsock/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ edition = "2021"
1313
# The `path` part gets stripped when publishing the crate.
1414
virtio-queue = { path = "../../virtio-queue", version = "0.9.0" }
1515
virtio-bindings = { path = "../../virtio-bindings", version = "0.2.1" }
16-
vm-memory = "0.12.0"
16+
vm-memory = "0.13.1"
1717

1818
[dev-dependencies]
1919
virtio-queue = { path = "../../virtio-queue", version = "0.9.0", features = ["test-utils"] }
20-
vm-memory = { version = "0.12.0", features = ["backend-mmap", "backend-atomic"] }
20+
vm-memory = { version = "0.13.1", features = ["backend-mmap", "backend-atomic"] }

crates/virtio-device/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ license = "Apache-2.0 OR MIT"
1010
edition = "2021"
1111

1212
[dependencies]
13-
vm-memory = "0.12.0"
13+
vm-memory = "0.13.1"
1414
log = "0.4.17"
1515
virtio-bindings = { path = "../virtio-bindings" }
1616
virtio-queue = { path = "../virtio-queue", version = "0.9.0"}
1717

1818
[dev-dependencies]
19-
vm-memory = { version = "0.12.0", features = ["backend-mmap", "backend-atomic"] }
19+
vm-memory = { version = "0.13.1", features = ["backend-mmap", "backend-atomic"] }

crates/virtio-queue-ser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ versionize_derive = "0.1.3"
1818
# and virtio-queue-ser releases. This is to prevent accidental changes
1919
# to the serializer output in a patch release of virtio-queue.
2020
virtio-queue = { path = "../../crates/virtio-queue", version = "=0.9.0" }
21-
vm-memory = "0.12.0"
21+
vm-memory = "0.13.1"
2222

2323
[dev-dependencies]
2424
virtio-queue = { path = "../../crates/virtio-queue", version = "=0.9.0", features = ["test-utils"] }

crates/virtio-queue/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ edition = "2021"
1313
test-utils = []
1414

1515
[dependencies]
16-
vm-memory = "0.12.0"
16+
vm-memory = "0.13.1"
1717
vmm-sys-util = "0.11.0"
1818
log = "0.4.17"
1919
virtio-bindings = { path="../virtio-bindings", version = "0.2.1" }
2020

2121
[dev-dependencies]
2222
criterion = "0.3.0"
23-
vm-memory = { version = "0.12.0", features = ["backend-mmap", "backend-atomic"] }
23+
vm-memory = { version = "0.13.1", features = ["backend-mmap", "backend-atomic"] }
2424
memoffset = "0.7.1"
2525

2626
[[bench]]

fuzz/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ serde = "1.0.63"
1919
virtio-queue = { path = "../crates/virtio-queue", features = ["test-utils"] }
2020
virtio-vsock = { path = "../crates/devices/virtio-vsock" }
2121
virtio-queue-ser = { path = "../crates/virtio-queue-ser" }
22-
vm-memory = { version = "0.12.0", features = ["backend-mmap", "backend-atomic"] }
22+
vm-memory = { version = "0.13.1", features = ["backend-mmap", "backend-atomic"] }
2323
common = { path = "common" }
2424

2525
[[bin]]

fuzz/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ virtio-bindings = { path = "../../crates/virtio-bindings" }
1212
virtio-queue = { path = "../../crates/virtio-queue", features = ["test-utils"] }
1313
virtio-vsock = { path = "../../crates/devices/virtio-vsock" }
1414
virtio-queue-ser = { path = "../../crates/virtio-queue-ser" }
15-
vm-memory = { version = "0.12.0", features = ["backend-mmap", "backend-atomic"] }
15+
vm-memory = { version = "0.13.1", features = ["backend-mmap", "backend-atomic"] }

0 commit comments

Comments
 (0)