Skip to content

Commit 3a17f36

Browse files
committed
queue: use atomic to access queue head field
Use atomic operation to access queue.head, to avoid reading inconsistent values. Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
1 parent e252a24 commit 3a17f36

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

crates/virtio-queue/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,8 @@ impl<M: GuestAddressSpace> Iterator for DescriptorChain<M> {
256256
.desc_table
257257
.unchecked_add(self.next_index as u64 * size_of::<Descriptor>() as u64);
258258

259+
// The guest device driver should not touch the descriptor once submitted, so it's safe
260+
// to use read_obj() here.
259261
let desc = self.mem.read_obj::<Descriptor>(desc_addr).ok()?;
260262

261263
if desc.is_indirect() {
@@ -361,7 +363,7 @@ impl<'b, M: GuestAddressSpace> Iterator for AvailIter<'b, M> {
361363
let addr = self.avail_ring.unchecked_add(offset);
362364
let head_index: u16 = self
363365
.mem
364-
.read_obj(addr)
366+
.load(addr, Ordering::Acquire)
365367
.map_err(|_| error!("Failed to read from memory {:x}", addr.raw_value()))
366368
.ok()?;
367369

0 commit comments

Comments
 (0)