Skip to content

Commit 77d825c

Browse files
committed
GuestMemory: Add lifetimes to try_access()
With virtual memory, seemingly consecutive I/O virtual memory regions may actually be fragmented across multiple pages in our userspace mapping. Existing `descriptor_utils::Reader::new()` (and `Writer`) implementations (e.g. in virtiofsd or vm-virtio/virtio-queue) use `GuestMemory::get_slice()` to turn guest memory address ranges into valid slices in our address space; but with this fragmentation, it is easily possible that a range no longer corresponds to a single slice. To fix this, we can instead use `try_access()` to collect all slices, but to do so, its region argument needs to have the correct lifetime so we can collect the slices into a `Vec<_>` outside of the closure. Signed-off-by: Hanna Czenczek <[email protected]>
1 parent b2eaf98 commit 77d825c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/guest_memory.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,9 @@ pub trait GuestMemory {
501501
/// - the error code returned by the callback 'f'
502502
/// - the size of the already handled data when encountering the first hole
503503
/// - the size of the already handled data when the whole range has been handled
504-
fn try_access<F>(&self, count: usize, addr: GuestAddress, mut f: F) -> Result<usize>
504+
fn try_access<'a, F>(&'a self, count: usize, addr: GuestAddress, mut f: F) -> Result<usize>
505505
where
506-
F: FnMut(usize, usize, MemoryRegionAddress, &Self::R) -> Result<usize>,
506+
F: FnMut(usize, usize, MemoryRegionAddress, &'a Self::R) -> Result<usize>,
507507
{
508508
let mut cur = addr;
509509
let mut total = 0;

0 commit comments

Comments
 (0)