8475 Commits

Author SHA1 Message Date
Nikolay Edigaryev
27fda753e1 virtio-devices: iommu: allow limiting maximum address width in bits
Currently, Cloud Hypervisor does not set a VIRTIO_IOMMU_F_INPUT_RANGE
feature bit for the VirtIO IOMMU device, which, according to spec[1],
means that the guest may use the whole 64-bit address space is for
IOMMU purposes:

>If the feature is not offered, virtual mappings span over the whole
>64-bit address space (start = 0, end = 0xffffffff ffffffff)

As far as I am aware, there are currently no host platforms on
the market capable of addressing the whole 64-bit address space.

For example, I am currently working with a host platform that reports
39-bit address space for IOMMU purposes:

>DMAR: Host address width 39

When running a VFIO pass-through guest on such a platform, NVIDIA
driver in guest gets DMA mapping failures when working with large data,
and this results in Cloud Hypervisor exiting with the following error:

>cloud-hypervisor: 1501.220535s: <__iommu>
>ERROR:virtio-devices/src/thread_helper.rs:53 -- Error running worker:
>HandleEvent(Failed to process request queue : ExternalMapping(Custom
>{ kind: Other, error: "failed to map memory for VFIO container, iova
>0x7fff00000000, gpa 0x24ce25000, size 0x1000: IommuDmaMap(Error(22))"
>}))

Passing "--platform iommu_address_width=39" to Cloud Hypervisor built
with this change fixes this.

[1]: https://docs.oasis-open.org/virtio/virtio/v1.3/csd01/
virtio-v1.3-csd01.html#x1-5420006

Signed-off-by: Nikolay Edigaryev <edigaryev@gmail.com>
2025-01-14 21:31:47 +00:00
Nikolay Edigaryev
74ca38f7a9 vmm: introduce platform option to limit maximum IOMMU address width
Signed-off-by: Nikolay Edigaryev <edigaryev@gmail.com>
2025-01-14 21:31:47 +00:00
Rob Bradford
fa686fdfc7 tests: Bump OVMF version
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-14 17:53:43 +00:00
Wei Liu
c827a1c009 fuzz: build x86emul by default
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-14 17:37:57 +00:00
dependabot[bot]
eefd7fcaaf build: Bump linux-raw-sys from 0.4.14 to 0.4.15
Bumps [linux-raw-sys](https://github.com/sunfishcode/linux-raw-sys) from 0.4.14 to 0.4.15.
- [Commits](https://github.com/sunfishcode/linux-raw-sys/compare/v0.4.14...v0.4.15)

---
updated-dependencies:
- dependency-name: linux-raw-sys
  dependency-type: indirect
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-14 16:01:22 +00:00
Rob Bradford
62303d8c33 arch: x86_64: Log the cpuid per vCPU
This will aid debugging issues related to CPUID.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-14 12:52:55 +00:00
Rob Bradford
293cf90e3d hypervisor: Implement fmt::Display for CpuIdEntry
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-14 12:52:55 +00:00
Bo Chen
8f98fabd0b vmm: Cleanup VM being created when VM restore fails
When VM restore fails, the VMM state is left with some side-effects,
such as a VM being created. It would prevent the VMM from creating and
booting a new VM or restoring from a VM snapshot.

To fix this issue, this patch explicitly handles the side effects to the
VMM state when VM restore fails, e.g. clear the VmConfig and shutdown
the VM being created.

Fixes: #6869

Signed-off-by: Bo Chen <bo.arvin.chen@gmail.com>
2025-01-14 00:45:03 +00:00
Bo Chen
07821c08c0 vmm: Always re-generate the 'console_info' with VM restore
With VM restore, the VMM is always re-creating a VM based on the
restored `VmConfig`. We should always re-generate the 'console_info'
from the `Vmm` struct to stay consistent with the new VM being created.

Signed-off-by: Bo Chen <bo.arvin.chen@gmail.com>
2025-01-14 00:45:03 +00:00
Wei Liu
0cb2c86ff4 fuzz: introduce a virtio vsock fuzzer
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-14 00:26:01 +00:00
Wei Liu
d359c8cdce virtio-devices: vsock: allow fuzzer to use TestBackend
Instead of reinventing this mock infrastructure in the upcoming fuzzer,
reuse the one that is already available.

However this change makes Clippy complain that TestBackend and
TestContext don't implement Default. This is just test code, we can
suppress Clippy in this case.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-14 00:26:01 +00:00
Rob Bradford
c801929fd1 tests: Update interrupt group name on ARM
This has changed with kernel 6.12.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-13 21:46:23 +00:00
Rob Bradford
66da3b9970 scripts: Temporarily build kernel as part of CI
Updating the kernel to v6.12 has shown up a flaw in the workflow for our
binary kernel releases. The CI job that builds the binary kernel in the
cloud-hypervisor/linux repository fetches the config from the main
branch of the cloud-hypervisor/cloud-hypervisor repository. However the
CI job to update the kernel version to use is in the cloud-hypervisor
repository.

As a workaround - update the kernel config and version in the
cloud-hypervisor repository to point to v6.12 and use the ability to
build the kernel during the CI run. Once merged to main a new release
can be made in the linux respository which will build a binary asset
using the new config. After that release the CI jobs on the
cloud-hypervisor repository can changed back to using the binary kernel
assets.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-13 21:46:23 +00:00
Rob Bradford
6ddbd60d9d build: Update kernel to v6.12
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-13 21:46:23 +00:00
Rob Bradford
2fc4de6c65 virtio-devices: iommu: Use hex formatting in log messages
This means that the the addresses are more easily readable.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-13 21:46:23 +00:00
Rob Bradford
03eeb36b74 virtio-devices: iommu: Search full range for GVA conversion
Remove an erroneous optimisation that used the page size mask to reduce
the range to iterate through on the set of mappings. This doesn't work
as the virtio-iommu ranges are larger than a single page. This may have
worked in the past when the mappings were limited to a single page.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-13 21:46:23 +00:00
Rob Bradford
2fe7f54ece build: Bump version number of Docker image
No change to the Dockerfile but I observed that the 20251022-0 image was
not available in the repository.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-11 15:03:01 +00:00
Rob Bradford
1cc540c880 build: Update github artifact action version
The v3 version is now deprecated. Tested by creating a dummy tag and
validating the results.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-09 22:25:35 +00:00
Wei Liu
a1af4238ae virtio-devices: make ioeventfds() return an iterator
MSHV's SEV-SNP implementation calls ioeventfds whenever there is an
event.

This change removes the need frequent allocation and deallocation of a
vector, while at the same time makes sure other call sites are
unaffected.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 21:28:46 +00:00
Wei Liu
d2e798944a virtio-devices: rename two variables
They are used. No need to start their names with an underscore.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 21:28:46 +00:00
Wei Liu
d99f294281 pci: rename as_any to as_any_mut
That trait function returns a mutable reference. Rename it to follow
Rust's convention.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 21:28:46 +00:00
dependabot[bot]
44c9ce598d build: Bump anstyle-wincon from 3.0.4 to 3.0.6
Bumps [anstyle-wincon](https://github.com/rust-cli/anstyle) from 3.0.4 to 3.0.6.
- [Commits](https://github.com/rust-cli/anstyle/compare/anstyle-wincon-v3.0.4...anstyle-wincon-v3.0.6)

---
updated-dependencies:
- dependency-name: anstyle-wincon
  dependency-type: indirect
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-09 13:57:10 +00:00
Wei Liu
5b42aa0bcf hypervisor: kvm: fix an operator precedence clippy warning
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 13:51:42 +00:00
Wei Liu
703e0cab04 vmm: use C ABI-qualification for packed structures
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 13:51:42 +00:00
Wei Liu
abb88cf47f arch: tdx: use proper repr qualifications
They should be packed and use C ABI.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 13:51:42 +00:00
Wei Liu
2e22b8bc3a pci: use C ABI-qualification for a packed structure
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 13:51:42 +00:00
Wei Liu
778c05d678 virtio-devices: use C ABI-qualification for packed structures
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 13:51:42 +00:00
Wei Liu
5b29eba636 block: vhdx: use C ABI-qualification for packed structures
This fixes the following issue from beta Clippy:

error: item uses `packed` representation without ABI-qualification
Error:    --> block/src/vhdx/vhdx_header.rs:333:1
    |
331 |   #[repr(packed)]
    |          ------ `packed` representation set here
332 |   #[derive(Clone, Copy, Debug)]
333 | / pub struct RegionTableEntry {
334 | |     pub guid: Uuid,
335 | |     pub file_offset: u64,
336 | |     pub length: u32,
337 | |     pub required: u32,
338 | | }
    | |_^
    |
    = warning: unqualified `#[repr(packed)]` defaults to `#[repr(Rust, packed)]`, which has no stable ABI
    = help: qualify the desired ABI explicity via `#[repr(C, packed)]` or `#[repr(Rust, packed)]`
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#repr_packed_without_abi

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-09 13:51:42 +00:00
Wei Liu
e6e78e5986 block: vhdx: reject zero size virtual disk
Some calculation down the road depends on that value not being zero.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-08 22:45:58 +00:00
Wei Liu
a2df4d7660 fuzz: explicitly keep or reject input for vhdx fuzzer
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-08 22:45:58 +00:00
Wei Liu
bc4a1fd16c block: vhdx: use checked_add in read and write functions
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-08 22:45:58 +00:00
Wei Liu
463c9b8e56 block: vhdx: hoist a check out of IO loops
This reduces one indentation level in the IO loops in the read and write
functions.

No functional change.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-08 22:45:58 +00:00
dependabot[bot]
835847bea5 build: Bump async-trait from 0.1.83 to 0.1.85
Bumps [async-trait](https://github.com/dtolnay/async-trait) from 0.1.83 to 0.1.85.
- [Release notes](https://github.com/dtolnay/async-trait/releases)
- [Commits](https://github.com/dtolnay/async-trait/compare/0.1.83...0.1.85)

---
updated-dependencies:
- dependency-name: async-trait
  dependency-type: indirect
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-08 15:17:36 +00:00
Rob Bradford
3e4ed5621e vmm: Automatically fix operator precedence clippy warning
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-07 17:44:41 +00:00
Rob Bradford
2624f17ffe virtio-devices: Automatically fix operator precedence clippy warning
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-07 17:44:41 +00:00
Rob Bradford
21f05ebb4f vhost_user_block: Automatically fix operator precedence clippy warning
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-07 17:44:41 +00:00
Rob Bradford
1485e17268 vhost_user_net: Automatically fix operator precedence clippy warning
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-07 17:44:41 +00:00
Rob Bradford
b57cc3d79f pci: Automatically fix operator precedence clippy warning
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-07 17:44:41 +00:00
Rob Bradford
a322e2d6f4 hypervisor: Automatically fix operator precedence clippy warning
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-07 17:44:41 +00:00
Rob Bradford
dd0b95ba5c devices: Automatically fix operator precedence clippy warning
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-07 17:44:41 +00:00
Rob Bradford
b6667f948e arch: Fix operator precedence clippy warning
With manual (to ensure comment preservation) and automatic fixes.

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-07 17:44:41 +00:00
dependabot[bot]
4f22f67307 build: Bump proc-macro2 from 1.0.86 to 1.0.92
Bumps [proc-macro2](https://github.com/dtolnay/proc-macro2) from 1.0.86 to 1.0.92.
- [Release notes](https://github.com/dtolnay/proc-macro2/releases)
- [Commits](https://github.com/dtolnay/proc-macro2/compare/1.0.86...1.0.92)

---
updated-dependencies:
- dependency-name: proc-macro2
  dependency-type: indirect
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-07 00:15:47 +00:00
Rob Bradford
eeae63b459 build: Bump thiserror version
Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-06 17:39:45 +00:00
Rob Bradford
abf5748f64 block: qcow: Use constant in error message
This avoids ambiguity of parameters:

error: ambiguous reference to positional arguments by number in a tuple variant; change this to a named argument
  --> block/src/qcow/mod.rs:48:48
   |
48 |     #[error("File larger than max of {}: {0}", MAX_QCOW_FILE_SIZE)]
   |                                                ^^^^^^^^^^^^^^^^^^

Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
2025-01-06 17:39:45 +00:00
dependabot[bot]
23b5f7b1c5 build: Bump futures from 0.3.30 to 0.3.31
Bumps [futures](https://github.com/rust-lang/futures-rs) from 0.3.30 to 0.3.31.
- [Release notes](https://github.com/rust-lang/futures-rs/releases)
- [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.30...0.3.31)

---
updated-dependencies:
- dependency-name: futures
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-01-06 15:05:55 +00:00
Wei Liu
a66fef407c block: vhdx: properly account for bytes read and written
The counter value in vhdx_io::{read,write} should've been accumulated
over the loop.

Fixes: #6897
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-03 10:25:53 +00:00
Wei Liu
7c39f37855 fuzz: introduce an x86 instruction emulator fuzzer
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-02 22:43:59 +00:00
Wei Liu
fe24a7a24f hypervisor: introduce an mshv_emulator feature
This will become useful when we build the fuzzing target for the
instruction emulator, because there is no need to pull in the rest of
the hypervisor crate in that situation.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-02 22:43:59 +00:00
Wei Liu
73e1451a12 hypervisor: emulator: use wrapping arithmetic
Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-02 22:43:59 +00:00
Wei Liu
1180f757b3 hypervisor: emulator: adjust iced-x86 feature flags
The fastfmt feature and VEX support use techniques that appear to leak
memory in the eye of LLVM's address sanitizer.

While at it, disable a bunch of instruction set decoding support we
never intend to support.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
2025-01-02 22:43:59 +00:00