Skip to content

Commit 9120f3a

Browse files
committed
refactor(queue): remove set_used_ring_avail_event method
Instead use `used_ring_avail_event_set()` Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent f0a95a8 commit 9120f3a

File tree

1 file changed

+7
-48
lines changed

1 file changed

+7
-48
lines changed

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

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,10 @@ use std::num::Wrapping;
1010
use std::sync::atomic::{fence, Ordering};
1111

1212
use utils::usize_to_u64;
13-
use vm_memory::bitmap::Bitmap;
1413

1514
use crate::logger::error;
1615
use crate::vstate::memory::{
17-
Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryMmap,
16+
Address, Bitmap, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryMmap,
1817
};
1918

2019
pub const VIRTQ_DESC_F_NEXT: u16 = 0x1;
@@ -659,29 +658,6 @@ impl Queue {
659658
Ok(())
660659
}
661660

662-
/// Helper method that writes to the `avail_event` field of the used ring.
663-
#[inline(always)]
664-
fn set_used_ring_avail_event<M: GuestMemory>(&mut self, avail_event: u16, mem: &M) {
665-
debug_assert!(self.is_valid(mem));
666-
667-
// Used ring has layout:
668-
// struct UsedRing {
669-
// flags: u16,
670-
// idx: u16,
671-
// ring: [UsedElement; <queue size>],
672-
// avail_event: u16,
673-
// }
674-
// We calculate offset into `avail_event` field.
675-
let avail_event_offset = std::mem::size_of::<u16>()
676-
+ std::mem::size_of::<u16>()
677-
+ std::mem::size_of::<UsedElement>() * usize::from(self.actual_size());
678-
let avail_event_addr = self
679-
.used_ring_address
680-
.unchecked_add(usize_to_u64(avail_event_offset));
681-
682-
mem.write_obj(avail_event, avail_event_addr).unwrap();
683-
}
684-
685661
/// Try to enable notification events from the guest driver. Returns true if notifications were
686662
/// successfully enabled. Otherwise it means that one or more descriptors can still be consumed
687663
/// from the available ring and we can't guarantee that there will be a notification. In this
@@ -714,9 +690,9 @@ impl Queue {
714690
}
715691

716692
// Set the next expected avail_idx as avail_event.
717-
self.set_used_ring_avail_event(self.next_avail.0, mem);
693+
self.used_ring_avail_event_set(self.next_avail.0);
718694

719-
// Make sure all subsequent reads are performed after `set_used_ring_avail_event`.
695+
// Make sure all subsequent reads are performed after we set avail_event.
720696
fence(Ordering::SeqCst);
721697

722698
// If the actual avail_idx is different than next_avail one or more descriptors can still
@@ -1021,22 +997,6 @@ mod verification {
1021997
}
1022998
}
1023999

1024-
mod stubs {
1025-
use super::*;
1026-
1027-
// Calls to set_used_ring_address_avail_event tend to cause memory to grow unboundedly
1028-
// during verification. The function writes to the `avail_event` of the virtio
1029-
// queue, which is not read from by the device. It is only intended to be used by
1030-
// guest. Therefore, it does not affect any device functionality (e.g. its only call
1031-
// site, try_enable_notification, will behave independently of what value was
1032-
// written here). Thus we can stub it out with a no-op. Note that we have a separate
1033-
// harness for set_used_ring_address_avail_event, to ensure the function itself is
1034-
// sound.
1035-
fn set_used_ring_avail_event<M: GuestMemory>(_self: &mut Queue, _val: u16, _mem: &M) {
1036-
// do nothing
1037-
}
1038-
}
1039-
10401000
#[kani::proof]
10411001
#[kani::unwind(0)] // There are no loops anywhere, but kani really enjoys getting stuck in std::ptr::drop_in_place.
10421002
// This is a compiler intrinsic that has a "dummy" implementation in stdlib that just
@@ -1168,9 +1128,9 @@ mod verification {
11681128
#[kani::proof]
11691129
#[kani::unwind(0)]
11701130
fn verify_set_used_ring_avail_event() {
1171-
let ProofContext(mut queue, mem) = ProofContext::bounded_queue();
1131+
let ProofContext(mut queue, _) = ProofContext::bounded_queue();
11721132

1173-
queue.set_used_ring_avail_event(kani::any(), &mem);
1133+
queue.used_ring_avail_event_set(kani::any());
11741134
}
11751135

11761136
#[kani::proof]
@@ -1216,7 +1176,6 @@ mod verification {
12161176

12171177
#[kani::proof]
12181178
#[kani::unwind(0)]
1219-
#[kani::stub(Queue::set_used_ring_avail_event, stubs::set_used_ring_avail_event)]
12201179
fn verify_try_enable_notification() {
12211180
let ProofContext(mut queue, mem) = ProofContext::bounded_queue();
12221181

@@ -1606,10 +1565,10 @@ mod tests {
16061565
let mut q = vq.create_queue();
16071566
assert_eq!(vq.used.event.get(), 0);
16081567

1609-
q.set_used_ring_avail_event(10, m);
1568+
q.used_ring_avail_event_set(10);
16101569
assert_eq!(vq.used.event.get(), 10);
16111570

1612-
q.set_used_ring_avail_event(u16::MAX, m);
1571+
q.used_ring_avail_event_set(u16::MAX);
16131572
assert_eq!(vq.used.event.get(), u16::MAX);
16141573
}
16151574

0 commit comments

Comments
 (0)