From 0cbf9d3fb5c93c2fd5a83355b1e43fdc9b6562f9 Mon Sep 17 00:00:00 2001 From: Dylan Reid Date: Thu, 25 Jun 2020 16:38:25 -0700 Subject: [PATCH] io_uring: initialze sqes to zero Submission queue entries have whatever value is left from last time stored. Clear them to zero when they are pulled out prior to being filled. It's better to do this in a central location than making each user responsible for setting all the fields. Change-Id: I0436e24cd97fe4bbe808d7d0cc09fa81c1323d57 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2274995 Reviewed-by: Daniel Verkamp Reviewed-by: Chirantan Ekbote Tested-by: kokoro Tested-by: Dylan Reid Commit-Queue: Dylan Reid --- io_uring/src/uring.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/io_uring/src/uring.rs b/io_uring/src/uring.rs index 5042c32f6f..569d862f14 100644 --- a/io_uring/src/uring.rs +++ b/io_uring/src/uring.rs @@ -512,11 +512,14 @@ impl SubmitQueueEntries { if index >= self.len { return None; } - unsafe { + let mut_ref = unsafe { // Safe because the mut borrow of self resticts to one mutable reference at a time and // we trust that the kernel has returned enough memory in io_uring_setup and mmap. - Some(&mut *(self.mmap.as_ptr() as *mut io_uring_sqe).add(index)) - } + &mut *(self.mmap.as_ptr() as *mut io_uring_sqe).add(index) + }; + // Clear any state. + *mut_ref = io_uring_sqe::default(); + Some(mut_ref) } }