rust-vmm / mshv

Crates for Microsoft Hypervisor ioctls and bindings
Apache License 2.0
29 stars 12 forks source link

ioctls: Add new MshvError type derived from thiserror::Error #138

Closed NunoDasNeves closed 5 months ago

NunoDasNeves commented 5 months ago

MshvError allows different kinds of errors to be returned from the library. One intended use is to return details about a failed hypercall from the MSHV_ROOT_HVCALL ioctl, so useful error messages can be printed.

Implement from_hvcall for future use with MSHV_ROOT_HVCALL, along with tests.

Use into() to convert uses of errno::Error to MshvError.

Summary of the PR

This is a precursor patch to https://github.com/rust-vmm/mshv/pull/128.

The only way to debug hypercall failures that result from the IOCTL calls in mshv-ioctls today, is to use dmesg and rely on debug printing in the kernel itself.

The MshvError type is the first step to solving thism this by allowing mshv-ioctls to return either an errno::Error or details about a hypercall-related error (hypercall code and status code).

This will help users/developers of VMMs identify the root cause of issues more reliably.

This PR introduces a couple of dependencies:

Since this PR changes the Result type used by mshv-ioctls, it may cause API breakages with other crates. From testing with Cloud Hypervisor, I have only found one, in the vfio-ioctls crate. It is fixed in a backward-compatible manner here: https://github.com/rust-vmm/vfio/pull/44

Requirements

Before submitting your PR, please make sure you addressed the following requirements:

NunoDasNeves commented 5 months ago

NOTE: All the changes are in the 2nd commit. The first is just cargo fmt replacing all the newlines in hvdef.rs.