Skip to content

Commit

Permalink
Fixed Error handling: Panic in hypercall handler caused remaining thr…
Browse files Browse the repository at this point in the history
…eads never to finish
  • Loading branch information
jounathaen committed Feb 19, 2024
1 parent 63de7c6 commit 711242f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
13 changes: 12 additions & 1 deletion src/hypercall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,20 @@ pub fn write(mem: &MmapMemory, syswrite: &WriteParams) -> io::Result<()> {
let mut bytes_written: usize = 0;
while bytes_written != syswrite.len {
unsafe {
use std::io::{Error, ErrorKind};

use crate::mem::MemoryError;
let step = libc::write(
syswrite.fd,
mem.host_address(syswrite.buf + bytes_written).unwrap() as *const libc::c_void,
mem.host_address(syswrite.buf + bytes_written)
.map_err(|e| match e {
MemoryError::BoundsViolation => {
unreachable!("Bounds violation after host_address function")
}
MemoryError::WrongMemoryError => {
Error::new(ErrorKind::AddrNotAvailable, e.to_string())
}
})? as *const libc::c_void,
syswrite.len - bytes_written,
);
if step >= 0 {
Expand Down
14 changes: 7 additions & 7 deletions src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ impl UhyveVm<KvmCpu> {
}
Err(err) => {
error!("CPU {} crashed with {:?}", cpu_id, err);
None
barrier.wait();
Some(err.errno())
}
}
})
Expand All @@ -142,12 +143,11 @@ impl UhyveVm<KvmCpu> {
.into_iter()
.filter_map(|thread| thread.join().unwrap())
.collect::<Vec<_>>();
assert_eq!(
1,
code.len(),
"more than one thread finished with an exit code"
);
code[0]
match code.len() {
0 => panic!("No return code from any CPU? Maybe all have been kicked?"),
1 => code[0],
_ => panic!("more than one thread finished with an exit code (codes: {code:?})"),
}
}

fn run_gdb(self, cpu_affinity: Option<Vec<CoreId>>) -> i32 {
Expand Down
5 changes: 3 additions & 2 deletions src/linux/x86_64/kvm_cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
vcpu::{VcpuStopReason, VirtualCPU},
virtio::*,
vm::UhyveVm,
HypervisorResult,
HypervisorError, HypervisorResult,
};

const CPUID_EXT_HYPERVISOR: u32 = 1 << 31;
Expand Down Expand Up @@ -425,7 +425,8 @@ impl VirtualCPU for KvmCpu {
hypercall::read(&self.parent_vm.mem, sysread)
}
Hypercall::FileWrite(syswrite) => {
hypercall::write(&self.parent_vm.mem, syswrite)?
hypercall::write(&self.parent_vm.mem, syswrite)
.map_err(|_e| HypervisorError::new(libc::EFAULT))?
}
Hypercall::FileUnlink(sysunlink) => {
hypercall::unlink(&self.parent_vm.mem, sysunlink)
Expand Down

0 comments on commit 711242f

Please sign in to comment.