Virtio: Add fence(Acquire) after avail_index read

Driver use virtio_wmb() before avail_index updating, here fence() is
compared with it, this guarantee that the descriptor_index is read after
avail_index.

BUG=none
TEST=run fio_read and fio_write in guest

Change-Id: I6a5e1bc7c915effd433b05aca246302c5a3e313c
Signed-off-by: Xiong Zhang <xiong.y.zhang@intel.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2035079
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Xiong Zhang 2020-02-03 10:03:17 +08:00 committed by Commit Bot
parent bc7728f69b
commit 5c51e05282

View file

@ -317,6 +317,8 @@ impl Queue {
let queue_size = self.actual_size();
let avail_index_addr = mem.checked_offset(self.avail_ring, 2).unwrap();
let avail_index: u16 = mem.read_obj_from_addr(avail_index_addr).unwrap();
// make sure desc_index read doesn't bypass avail_index read
fence(Ordering::Acquire);
let avail_len = Wrapping(avail_index) - self.next_avail;
if avail_len.0 > queue_size || self.next_avail == Wrapping(avail_index) {