Skip to content

Commit 3ed55d3

Browse files
committed
feat(queue): add kani proofs for new methods
Add kani proofs for new methods for accessing queue objects. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent be3e924 commit 3ed55d3

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

src/vmm/src/devices/virtio/queue.rs

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl Queue {
396396
}
397397
}
398398

399-
#[cfg(test)]
399+
#[cfg(any(test, kani))]
400400
#[inline(always)]
401401
pub fn used_ring_avail_event_get(&mut self) -> u16 {
402402
// SAFETY: `avail_event` is 2 * u16 and self.len * UsedElement away from the start
@@ -685,9 +685,7 @@ mod verification {
685685
use vm_memory::guest_memory::GuestMemoryIterator;
686686
use vm_memory::{GuestMemoryRegion, MemoryRegionAddress};
687687

688-
use crate::devices::virtio::queue::{
689-
Descriptor, DescriptorChain, Queue, FIRECRACKER_MAX_QUEUE_SIZE, VIRTQ_DESC_F_NEXT,
690-
};
688+
use super::*;
691689
use crate::vstate::memory::{Bytes, FileOffset, GuestAddress, GuestMemory, MmapRegion};
692690

693691
/// A made-for-kani version of `vm_memory::GuestMemoryMmap`. Unlike the real
@@ -1070,10 +1068,52 @@ mod verification {
10701068

10711069
#[kani::proof]
10721070
#[kani::unwind(0)]
1073-
fn verify_set_used_ring_avail_event() {
1074-
let ProofContext(mut queue, _) = ProofContext::bounded_queue();
1071+
fn verify_avail_ring_idx_get() {
1072+
let ProofContext(queue, _) = kani::any();
1073+
_ = queue.avail_ring_idx_get();
1074+
}
1075+
1076+
#[kani::proof]
1077+
#[kani::unwind(0)]
1078+
fn verify_avail_ring_ring_get() {
1079+
let ProofContext(queue, _) = kani::any();
1080+
let x: usize = kani::any_where(|x| *x < usize::from(queue.size));
1081+
unsafe { _ = queue.avail_ring_ring_get(x) };
1082+
}
1083+
1084+
#[kani::proof]
1085+
#[kani::unwind(0)]
1086+
fn verify_avail_ring_used_event_get() {
1087+
let ProofContext(queue, _) = kani::any();
1088+
_ = queue.avail_ring_used_event_get();
1089+
}
10751090

1076-
queue.used_ring_avail_event_set(kani::any());
1091+
#[kani::proof]
1092+
#[kani::unwind(0)]
1093+
fn verify_used_ring_idx_set() {
1094+
let ProofContext(mut queue, _) = kani::any();
1095+
queue.used_ring_idx_set(kani::any());
1096+
}
1097+
1098+
#[kani::proof]
1099+
#[kani::unwind(0)]
1100+
fn verify_used_ring_ring_set() {
1101+
let ProofContext(mut queue, _) = kani::any();
1102+
let x: usize = kani::any_where(|x| *x < usize::from(queue.size));
1103+
let used_element = UsedElement {
1104+
id: kani::any(),
1105+
len: kani::any(),
1106+
};
1107+
unsafe { queue.used_ring_ring_set(x, used_element) };
1108+
}
1109+
1110+
#[kani::proof]
1111+
#[kani::unwind(0)]
1112+
fn verify_used_ring_avail_event() {
1113+
let ProofContext(mut queue, _) = kani::any();
1114+
let x = kani::any();
1115+
queue.used_ring_avail_event_set(x);
1116+
assert_eq!(x, queue.used_ring_avail_event_get());
10771117
}
10781118

10791119
#[kani::proof]

0 commit comments

Comments
 (0)