From b2fa8d91ddc99a020169424d2b516c6230c8fb30 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Thu, 18 May 2023 11:03:30 +0200 Subject: [PATCH] vsock: deal with process_tx error gracefully It's possible to receive backend events before the VMM contacts us to activate the vrings. Trying to call process_tx in this state will trigger a NoMemoryConfigured error which will end crashing the worker thread. As NoMemoryConfigured is a transitory error, deal with it gracefully printing a warning but continuing the normal execution. Signed-off-by: Sergio Lopez --- crates/vsock/src/vhu_vsock.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/vsock/src/vhu_vsock.rs b/crates/vsock/src/vhu_vsock.rs index e9b12a3..8e0863e 100644 --- a/crates/vsock/src/vhu_vsock.rs +++ b/crates/vsock/src/vhu_vsock.rs @@ -6,6 +6,7 @@ use std::{ u16, u32, u64, u8, }; +use log::warn; use thiserror::Error as ThisError; use vhost::vhost_user::message::{VhostUserProtocolFeatures, VhostUserVirtioFeatures}; use vhost_user_backend::{VhostUserBackend, VringRwLock}; @@ -289,7 +290,14 @@ impl VhostUserBackend for VhostUserVsockBackend { EVT_QUEUE_EVENT => {} BACKEND_EVENT => { thread.process_backend_evt(evset); - thread.process_tx(vring_tx, evt_idx)?; + if let Err(e) = thread.process_tx(vring_tx, evt_idx) { + match e { + Error::NoMemoryConfigured => { + warn!("Received a backend event before vring initialization") + } + _ => return Err(e.into()), + } + } } _ => { return Err(Error::HandleUnknownEvent.into());