Skip to content

Commit ec61408

Browse files
committed
Revert "iovec: fix kani proof for write_volatile_at"
This reverts commit bc0ba43. Signed-off-by: Babis Chalios <[email protected]>
1 parent 6bfe235 commit ec61408

File tree

2 files changed

+5
-69
lines changed

2 files changed

+5
-69
lines changed

src/vmm/src/devices/virtio/iov_deque.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ pub enum IovDequeError {
7171
// so making a slice out of them does not require any copies.
7272
#[derive(Debug)]
7373
pub struct IovDeque {
74-
pub iov: *mut libc::iovec,
75-
pub start: u16,
76-
pub len: u16,
74+
iov: *mut libc::iovec,
75+
start: u16,
76+
len: u16,
7777
}
7878

7979
// SAFETY: This is `Send`. We hold sole ownership of the underlying buffer.
@@ -215,7 +215,7 @@ impl IovDeque {
215215

216216
/// Returns `true` if the [`IovDeque`] is full, `false` otherwise
217217
#[inline(always)]
218-
pub fn is_full(&self) -> bool {
218+
fn is_full(&self) -> bool {
219219
self.len() == FIRECRACKER_MAX_QUEUE_SIZE
220220
}
221221

src/vmm/src/devices/virtio/iovec.rs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ mod tests {
795795
}
796796

797797
#[cfg(kani)]
798-
#[allow(dead_code)] // Avoid warning when using stubs
799798
mod verification {
800799
use std::mem::ManuallyDrop;
801800

@@ -804,9 +803,7 @@ mod verification {
804803
use vm_memory::VolatileSlice;
805804

806805
use super::{IoVecBuffer, IoVecBufferMut, IoVecVec};
807-
use crate::arch::PAGE_SIZE;
808806
use crate::devices::virtio::iov_deque::IovDeque;
809-
use crate::devices::virtio::queue::FIRECRACKER_MAX_QUEUE_SIZE;
810807

811808
// Maximum memory size to use for our buffers. For the time being 1KB.
812809
const GUEST_MEMORY_SIZE: usize = 1 << 10;
@@ -818,50 +815,6 @@ mod verification {
818815
// >= 1.
819816
const MAX_DESC_LENGTH: usize = 4;
820817

821-
mod stubs {
822-
use super::*;
823-
824-
/// This is a stub for the `IovDeque::push_back` method.
825-
///
826-
/// `IovDeque` relies on a special allocation of two pages of virtual memory, where both of
827-
/// these point to the same underlying physical page. This way, the contents of the first
828-
/// page of virtual memory are automatically mirrored in the second virtual page. We do
829-
/// that in order to always have the elements that are currently in the ring buffer in
830-
/// consecutive (virtual) memory.
831-
///
832-
/// To build this particular memory layout we create a new `memfd` object, allocate memory
833-
/// with `mmap` and call `mmap` again to make sure both pages point to the page allocated
834-
/// via the `memfd` object. These ffi calls make kani complain, so here we mock the
835-
/// `IovDeque` object memory with a normal memory allocation of two pages worth of data.
836-
///
837-
/// This stub helps imitate the effect of mirroring without all the elaborate memory
838-
/// allocation trick.
839-
pub fn push_back(deque: &mut IovDeque, iov: iovec) {
840-
// This should NEVER happen, since our ring buffer is as big as the maximum queue size.
841-
// We also check for the sanity of the VirtIO queues, in queue.rs, which means that if
842-
// we ever try to add something in a full ring buffer, there is an internal
843-
// bug in the device emulation logic. Panic here because the device is
844-
// hopelessly broken.
845-
assert!(
846-
!deque.is_full(),
847-
"The number of `iovec` objects is bigger than the available space"
848-
);
849-
850-
let offset = (deque.start + deque.len) as usize;
851-
let mirror = if offset >= FIRECRACKER_MAX_QUEUE_SIZE as usize {
852-
offset - FIRECRACKER_MAX_QUEUE_SIZE as usize
853-
} else {
854-
offset + FIRECRACKER_MAX_QUEUE_SIZE as usize
855-
};
856-
857-
// SAFETY: self.iov is a valid pointer and `self.start + self.len` is within range (we
858-
// asserted before that the buffer is not full).
859-
unsafe { deque.iov.add(offset).write_volatile(iov) };
860-
unsafe { deque.iov.add(mirror).write_volatile(iov) };
861-
deque.len += 1;
862-
}
863-
}
864-
865818
fn create_iovecs(mem: *mut u8, size: usize, nr_descs: usize) -> (IoVecVec, u32) {
866819
let mut vecs: Vec<iovec> = Vec::with_capacity(nr_descs);
867820
let mut len = 0u32;
@@ -892,23 +845,8 @@ mod verification {
892845
}
893846
}
894847

895-
fn create_iov_deque() -> IovDeque {
896-
// SAFETY: safe because the layout has non-zero size
897-
let mem = unsafe {
898-
std::alloc::alloc(std::alloc::Layout::from_size_align_unchecked(
899-
2 * PAGE_SIZE,
900-
PAGE_SIZE,
901-
))
902-
};
903-
IovDeque {
904-
iov: mem.cast(),
905-
start: kani::any_where(|&start| start < FIRECRACKER_MAX_QUEUE_SIZE),
906-
len: 0,
907-
}
908-
}
909-
910848
fn create_iovecs_mut(mem: *mut u8, size: usize, nr_descs: usize) -> (IovDeque, u32) {
911-
let mut vecs = create_iov_deque();
849+
let mut vecs = IovDeque::new().unwrap();
912850
let mut len = 0u32;
913851
for _ in 0..nr_descs {
914852
// The `IoVecBufferMut` constructors ensure that the memory region described by every
@@ -1017,7 +955,6 @@ mod verification {
1017955
#[kani::proof]
1018956
#[kani::unwind(5)]
1019957
#[kani::solver(cadical)]
1020-
#[kani::stub(IovDeque::push_back, stubs::push_back)]
1021958
fn verify_write_to_iovec() {
1022959
for nr_descs in 0..MAX_DESC_LENGTH {
1023960
let mut iov_mut = IoVecBufferMut::any_of_length(nr_descs);
@@ -1042,7 +979,6 @@ mod verification {
1042979
.unwrap(),
1043980
buf.len().min(iov_mut.len().saturating_sub(offset) as usize)
1044981
);
1045-
std::mem::forget(iov_mut.vecs);
1046982
}
1047983
}
1048984
}

0 commit comments

Comments
 (0)