From 3957d1ee272c2c2e8967b7c7da2d0bf09b0d3188 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Tue, 10 Mar 2020 05:43:13 -0400 Subject: [PATCH] vhost_user_backend: call get_used_event from needs_notification This change, combined with the compiler hint to inline get_used_event, shortens the window between the memory read and the actual check by calling get_used_event from needs_notification. Without it, when putting enough pressure on the vring, it's possible that a notification is wrongly omitted, causing the queue to stall. Signed-off-by: Sergio Lopez --- src/bin/vhost_user_fs.rs | 3 +-- vhost_user_backend/src/lib.rs | 8 ++------ vhost_user_block/src/lib.rs | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/bin/vhost_user_fs.rs b/src/bin/vhost_user_fs.rs index 01bcaaa25..5b666805f 100644 --- a/src/bin/vhost_user_fs.rs +++ b/src/bin/vhost_user_fs.rs @@ -126,8 +126,7 @@ impl VhostUserFsBackend { .map_err(Error::ProcessQueue)?; if self.event_idx { if let Some(used_idx) = vring.mut_queue().add_used(mem, head_index, 0) { - let used_event = vring.mut_queue().get_used_event(mem); - if vring.needs_notification(Wrapping(used_idx), used_event) { + if vring.needs_notification(&mem, Wrapping(used_idx)) { vring.signal_used_queue().map_err(Error::SignalQueue)?; } used_any = true; diff --git a/vhost_user_backend/src/lib.rs b/vhost_user_backend/src/lib.rs index 6256e066f..10184a175 100644 --- a/vhost_user_backend/src/lib.rs +++ b/vhost_user_backend/src/lib.rs @@ -235,11 +235,7 @@ impl Vring { self.event_idx = enabled; } - pub fn needs_notification( - &mut self, - used_idx: Wrapping, - used_event: Option>, - ) -> bool { + pub fn needs_notification(&mut self, mem: &GuestMemoryMmap, used_idx: Wrapping) -> bool { if !self.event_idx { return true; } @@ -247,7 +243,7 @@ impl Vring { let mut notify = true; if let Some(old_idx) = self.signalled_used { - if let Some(used_event) = used_event { + if let Some(used_event) = self.mut_queue().get_used_event(&mem) { if (used_idx - used_event - Wrapping(1u16)) >= (used_idx - old_idx) { notify = false; } diff --git a/vhost_user_block/src/lib.rs b/vhost_user_block/src/lib.rs index c9671186b..395df9f44 100644 --- a/vhost_user_block/src/lib.rs +++ b/vhost_user_block/src/lib.rs @@ -197,8 +197,7 @@ impl VhostUserBlkBackend { if self.event_idx { if let Some(used_idx) = vring.mut_queue().add_used(mem, head.index, len) { - let used_event = vring.mut_queue().get_used_event(mem); - if vring.needs_notification(Wrapping(used_idx), used_event) { + if vring.needs_notification(&mem, Wrapping(used_idx)) { debug!("signalling queue"); vring.signal_used_queue().unwrap(); } else {