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, Thread::VirtioBalloon,
&mut epoll_threads, &mut epoll_threads,
&self.exit_evt, &self.exit_evt,
move || { move || handler.run(paused, paused_sync.unwrap()),
if let Err(e) = handler.run(paused, paused_sync.unwrap()) {
error!("Error running worker: {:?}", e);
}
},
)?; )?;
self.common.epoll_threads = Some(epoll_threads); self.common.epoll_threads = Some(epoll_threads);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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