Skip to content

Introduce a separate KVM error variant of HyperlightError. #771

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

Merged
merged 1 commit into from
Aug 8, 2025

Conversation

ludfjig
Copy link
Contributor

@ludfjig ludfjig commented Aug 7, 2025

Fixes a common build error which occurs when the version of vmm-sys-util crate does not match between mshv/kvm.

VmmSysError variant is now solely used for our signal registration, and is not used by mshv nor kvm code.

Kvm functions like Kvm::new()? will ue the new variant automatically.

Certain Mshv functions from mshv_bindings used to use our vmm-sys-util error, which are changed in this commit.

This error only manifests when a separate crate depends on hyperlight-host, but not when we build hyperlight-host ourselves, since we check in our cargo.lock, and dependency resolution could make crates have different versions.

The error either happened in kvm code (as seen below), or in mshv code, depending on which version of vmm-sys-util hyperlight uses

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:335:29
    |
335 |         let kvm = Kvm::new()?;
    |                   ----------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |                   |
    |                   this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<KVMDriver, HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:337:47
    |
337 |         let vm_fd = kvm.create_vm_with_type(0)?;
    |                         ----------------------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |                         |
    |                         this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<KVMDriver, HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:343:11
    |
339 |           mem_regions.iter().enumerate().try_for_each(|(i, region)| {
    |  ________________________________________-
340 | |             let mut kvm_region: kvm_userspace_memory_region = region.clone().into();
341 | |             kvm_region.slot = i as u32;
342 | |             unsafe { vm_fd.set_user_memory_region(kvm_region) }
343 | |         })?;
    | |          -^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    | |__________|
    |            this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<KVMDriver, HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:345:47
    |
345 |         let mut vcpu_fd = vm_fd.create_vcpu(0)?;
    |                                 --------------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |                                 |
    |                                 this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<KVMDriver, HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:423:44
    |
423 |         let mut sregs = vcpu_fd.get_sregs()?;
    |                                 -----------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |                                 |
    |                                 this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<(), HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:436:34
    |
436 |         vcpu_fd.set_sregs(&sregs)?;
    |                 -----------------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |                 |
    |                 this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<(), HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:505:37
    |
505 |         self.vcpu_fd.set_regs(&regs)?;
    |                      ---------------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |                      |
    |                      this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<(), HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:543:65
    |
543 |         unsafe { self.vm_fd.set_user_memory_region(kvm_region) }?;
    |         --------------------------------------------------------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |         |
    |         this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<(), HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:558:69
    |
558 |             unsafe { self.vm_fd.set_user_memory_region(kvm_region) }?;
    |             --------------------------------------------------------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |             |
    |             this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<(), HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:585:37
    |
585 |         self.vcpu_fd.set_regs(&regs)?;
    |                      ---------------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |                      |
    |                      this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<(), HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

error[E0277]: `?` couldn't convert the error to `HyperlightError`
   --> /home/ludde/hyperlight-new/src/hyperlight_host/src/hypervisor/kvm.rs:594:35
    |
594 |         self.vcpu_fd.set_fpu(&fpu)?;
    |                      -------------^ the trait `From<kvm_ioctls::Error>` is not implemented for `HyperlightError`
    |                      |
    |                      this can't be annotated with `?` because it has type `Result<_, kvm_ioctls::Error>`
    |
    = note: the question mark operation (`?`) implicitly performs a conversion on the error value using the `From` trait
    = help: the following other types implement trait `From<T>`:
              `HyperlightError` implements `From<&str>`
              `HyperlightError` implements `From<BackendError>`
              `HyperlightError` implements `From<BorrowError>`
              `HyperlightError` implements `From<BorrowMutError>`
              `HyperlightError` implements `From<FromUtf8Error>`
              `HyperlightError` implements `From<Infallible>`
              `HyperlightError` implements `From<InvalidFlatbuffer>`
              `HyperlightError` implements `From<MshvError>`
            and 11 others
    = note: required for `std::result::Result<(), HyperlightError>` to implement `FromResidual<std::result::Result<Infallible, kvm_ioctls::Error>>`

@ludfjig ludfjig force-pushed the fix_vmm_sys_util_mismatch branch from 3a0b3ad to c706fa5 Compare August 7, 2025 22:10
@ludfjig ludfjig changed the title Introduces a separate KVM error variant of HyperlightError. Introduce a separate KVM error variant of HyperlightError. Aug 7, 2025
@ludfjig ludfjig force-pushed the fix_vmm_sys_util_mismatch branch from c706fa5 to e0bf767 Compare August 7, 2025 22:36
Fixes a common build error which occurs when the version of vmm-sys-util
crate does not match between mshv/kvm.

VmmSysError variant is now solely used for our signal
registration, and is not used by mshv nor kvm code.

Signed-off-by: Ludvig Liljenberg <[email protected]>
@ludfjig ludfjig force-pushed the fix_vmm_sys_util_mismatch branch from e0bf767 to d97967e Compare August 7, 2025 22:37
Copy link
Contributor

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jprendes jprendes merged commit 65217f3 into hyperlight-dev:main Aug 8, 2025
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bugfix For PRs that fix bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants