File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
src/vmm/src/devices/virtio Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -469,6 +469,28 @@ impl Queue {
469469 }
470470
471471 fn write_used_ring < M : GuestMemory > (
472+ /// Read used element from a used ring at specified index.
473+ #[ inline( always) ]
474+ pub fn read_used_ring < M : GuestMemory > ( & self , mem : & M , index : u16 ) -> UsedElement {
475+ // Used ring has layout:
476+ // struct UsedRing {
477+ // flags: u16,
478+ // idx: u16,
479+ // ring: [UsedElement; <queue size>],
480+ // avail_event: u16,
481+ // }
482+ // We calculate offset into `ring` field.
483+ let used_ring_offset = std:: mem:: size_of :: < u16 > ( )
484+ + std:: mem:: size_of :: < u16 > ( )
485+ + std:: mem:: size_of :: < UsedElement > ( ) * usize:: from ( index % self . actual_size ( ) ) ;
486+ let used_element_address = self . used_ring . unchecked_add ( usize_to_u64 ( used_ring_offset) ) ;
487+
488+ // SAFETY:
489+ // `used_element_address` param is bounded by size of the queue as `index` is
490+ // modded by `actual_size()`.
491+ mem. read_obj ( used_element_address) . unwrap ( )
492+ }
493+
472494 & self ,
473495 mem: & M ,
474496 index: u16 ,
You can’t perform that action at this time.
0 commit comments