File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
src/vmm/src/devices/virtio Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -522,9 +522,20 @@ impl Queue {
522522 fn set_avail_event < M : GuestMemory > ( & mut self , val : u16 , mem : & M ) {
523523 debug_assert ! ( self . is_layout_valid( mem) ) ;
524524
525+ // Used ring has layout:
526+ // struct UsedRing {
527+ // flags: u16,
528+ // idx: u16,
529+ // ring: [UsedElement; <queue size>],
530+ // avail_event: u16,
531+ // }
532+ // We calculate offset into `avail_event` field.
533+ let avail_event_offset = std:: mem:: size_of :: < u16 > ( )
534+ + std:: mem:: size_of :: < u16 > ( )
535+ + std:: mem:: size_of :: < UsedElement > ( ) * usize:: from ( self . actual_size ( ) ) ;
525536 let avail_event_addr = self
526537 . used_ring
527- . unchecked_add ( u64 :: from ( 4 + 8 * self . actual_size ( ) ) ) ;
538+ . unchecked_add ( usize_to_u64 ( avail_event_offset ) ) ;
528539
529540 mem. write_obj ( val, avail_event_addr) . unwrap ( ) ;
530541 }
You can’t perform that action at this time.
0 commit comments