Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 8, 2024

Conversation

NunoDasNeves
Copy link
Collaborator

@NunoDasNeves NunoDasNeves commented Apr 3, 2024

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 #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:

  • https://crates.io/crates/thiserror is used in many places in rust-vmm to create error enums with automatically generated From and Display traits. Similarly, here it is used to define MshvError.
  • https://crates.io/crates/num_enum is the defacto way to convert integers to enums by implementing the TryFromPrimitive trait. It is used to convert u16 to enum HvError. If there is a better way to do this please let me know!

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: rust-vmm/vfio#44

Requirements

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

  • All commits in this PR have Signed-Off-By trailers (with
    git commit -s), and the commit message has max 60 characters for the
    summary and max 75 characters for each description line.
  • All added/changed functionality has a corresponding unit/integration
    test.
  • All added/changed public-facing functionality has entries in the "Upcoming
    Release" section of CHANGELOG.md (if no such section exists, please create one).
  • Any newly added unsafe code is properly documented.

Signed-off-by: Nuno Das Neves <[email protected]>
@NunoDasNeves NunoDasNeves force-pushed the nudasnev/mshv-error-result-type branch 4 times, most recently from 0e0258d to 9179ab5 Compare April 3, 2024 23:02
@NunoDasNeves
Copy link
Collaborator Author

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

@NunoDasNeves NunoDasNeves force-pushed the nudasnev/mshv-error-result-type branch 2 times, most recently from 2201b51 to a8468de Compare April 4, 2024 23:31
@NunoDasNeves NunoDasNeves force-pushed the nudasnev/mshv-error-result-type branch from a8468de to 5788a8b Compare April 5, 2024 19:03
mshv-bindings/Cargo.toml Outdated Show resolved Hide resolved
mshv-ioctls/Cargo.toml Show resolved Hide resolved
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.

Signed-off-by: Nuno Das Neves <[email protected]>
@NunoDasNeves NunoDasNeves force-pushed the nudasnev/mshv-error-result-type branch from 5788a8b to ec3c268 Compare April 5, 2024 22:51
@russell-islam russell-islam enabled auto-merge (rebase) April 6, 2024 00:39
@russell-islam russell-islam merged commit a2695a5 into main Apr 8, 2024
2 checks passed
@russell-islam russell-islam deleted the nudasnev/mshv-error-result-type branch April 8, 2024 06:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants