Skip to content

Commit ac06b7e

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 <[email protected]>
1 parent 7b15eab commit ac06b7e

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() {
@@ -365,7 +367,7 @@ impl<'b, M: GuestAddressSpace> Iterator for AvailIter<'b, M> {
365367
let addr = self.avail_ring.unchecked_add(offset);
366368
let head_index: u16 = self
367369
.mem
368-
.read_obj(addr)
370+
.load(addr, Ordering::Acquire)
369371
.map_err(|_| error!("Failed to read from memory {:x}", addr.raw_value()))
370372
.ok()?;
371373

0 commit comments

Comments
 (0)