virtio-devices: Shutdown VMM upon worker thread errors

Fixes: #4462

Signed-off-by: Bo Chen <chen.bo@intel.com>
This commit is contained in:
Bo Chen 2022-08-11 17:16:27 -07:00 committed by Rob Bradford
parent 8c38992143
commit df5b803a63
14 changed files with 28 additions and 81 deletions

View File

@ -603,11 +603,7 @@ impl VirtioDevice for Balloon {
Thread::VirtioBalloon,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.common.epoll_threads = Some(epoll_threads);

View File

@ -647,11 +647,7 @@ impl VirtioDevice for Block {
Thread::VirtioBlock,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
}

View File

@ -559,11 +559,7 @@ impl VirtioDevice for Console {
Thread::VirtioConsole,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.common.epoll_threads = Some(epoll_threads);

View File

@ -1097,11 +1097,7 @@ impl VirtioDevice for Iommu {
Thread::VirtioIommu,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.common.epoll_threads = Some(epoll_threads);

View File

@ -1063,11 +1063,7 @@ impl VirtioDevice for Mem {
Thread::VirtioMem,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.common.epoll_threads = Some(epoll_threads);

View File

@ -655,11 +655,7 @@ impl VirtioDevice for Net {
Thread::VirtioNetCtl,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = ctrl_handler.run_ctrl(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || ctrl_handler.run_ctrl(paused, paused_sync.unwrap()),
)?;
self.ctrl_queue_epoll_thread = Some(epoll_threads.remove(0));
}
@ -736,11 +732,7 @@ impl VirtioDevice for Net {
Thread::VirtioNet,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
}

View File

@ -421,11 +421,7 @@ impl VirtioDevice for Pmem {
Thread::VirtioPmem,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.common.epoll_threads = Some(epoll_threads);

View File

@ -260,11 +260,7 @@ impl VirtioDevice for Rng {
Thread::VirtioRng,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.common.epoll_threads = Some(epoll_threads);

View File

@ -4,6 +4,7 @@
//
use crate::{
epoll_helper::EpollHelperError,
seccomp_filters::{get_seccomp_filter, Thread},
ActivateError,
};
@ -23,7 +24,7 @@ pub(crate) fn spawn_virtio_thread<F>(
f: F,
) -> Result<(), ActivateError>
where
F: FnOnce(),
F: FnOnce() -> std::result::Result<(), EpollHelperError>,
F: Send + 'static,
{
let seccomp_filter = get_seccomp_filter(seccomp_action, thread_type)
@ -44,12 +45,18 @@ where
return;
}
}
std::panic::catch_unwind(AssertUnwindSafe(f))
.or_else(|_| {
match std::panic::catch_unwind(AssertUnwindSafe(f)) {
Err(_) => {
error!("{} thread panicked", thread_name);
thread_exit_evt.write(1)
})
.ok();
thread_exit_evt.write(1).ok();
}
Ok(r) => {
if let Err(e) = r {
error!("Error running worker: {:?}", e);
thread_exit_evt.write(1).ok();
}
}
};
})
.map(|thread| epoll_threads.push(thread))
.map_err(|e| {

View File

@ -324,11 +324,7 @@ impl VirtioDevice for Blk {
Thread::VirtioVhostBlock,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.epoll_thread = Some(epoll_threads.remove(0));

View File

@ -563,11 +563,7 @@ impl VirtioDevice for Fs {
Thread::VirtioVhostFs,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.epoll_thread = Some(epoll_threads.remove(0));

View File

@ -313,11 +313,7 @@ impl VirtioDevice for Net {
Thread::VirtioVhostNetCtl,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = ctrl_handler.run_ctrl(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || ctrl_handler.run_ctrl(paused, paused_sync.unwrap()),
)?;
self.ctrl_queue_epoll_thread = Some(epoll_threads.remove(0));
}
@ -352,11 +348,7 @@ impl VirtioDevice for Net {
Thread::VirtioVhostNet,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.epoll_thread = Some(epoll_threads.remove(0));

View File

@ -467,11 +467,7 @@ where
Thread::VirtioVsock,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.common.epoll_threads = Some(epoll_threads);

View File

@ -341,11 +341,7 @@ impl VirtioDevice for Watchdog {
Thread::VirtioWatchdog,
&mut epoll_threads,
&self.exit_evt,
move || {
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
move || handler.run(paused, paused_sync.unwrap()),
)?;
self.common.epoll_threads = Some(epoll_threads);