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 <dverkamp@chromium.org>
Reviewed-by: Chirantan Ekbote <chirantan@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Tested-by: Dylan Reid <dgreid@chromium.org>
Commit-Queue: Dylan Reid <dgreid@chromium.org>
This commit is contained in:
Dylan Reid 2020-06-25 16:38:25 -07:00 committed by Commit Bot
parent e254389b63
commit 0cbf9d3fb5

View file

@ -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)
}
}