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 <slp@redhat.com>
This commit is contained in:
Sergio Lopez
2020-03-10 05:43:13 -04:00
committed by Rob Bradford
parent 536323d9fb
commit 3957d1ee27
3 changed files with 4 additions and 10 deletions

View File

@@ -235,11 +235,7 @@ impl Vring {
self.event_idx = enabled;
}
pub fn needs_notification(
&mut self,
used_idx: Wrapping<u16>,
used_event: Option<Wrapping<u16>>,
) -> bool {
pub fn needs_notification(&mut self, mem: &GuestMemoryMmap, used_idx: Wrapping<u16>) -> 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;
}