Skip to content

hypervisor: ivshmem support compatible with arm - #1307

Draft
lisongqian wants to merge 3 commits into
TencentCloud:masterfrom
lisongqian:sync-ivshmem
Draft

hypervisor: ivshmem support compatible with arm#1307
lisongqian wants to merge 3 commits into
TencentCloud:masterfrom
lisongqian:sync-ivshmem

Conversation

@lisongqian

Copy link
Copy Markdown
Collaborator

Cherry-pick the upstream cloud-hypervisor ivshmem series, adapt it to
cube-sandbox APIs, and make ivshmem work on both x86_64 and aarch64 by
default.

@lisongqian lisongqian self-assigned this Aug 7, 2026
Comment thread hypervisor/devices/src/ivshmem.rs
Comment thread hypervisor/vmm/src/device_manager.rs
Comment thread hypervisor/scripts/run_integration_tests_x86_64.sh Outdated
Comment thread hypervisor/test_infra/src/lib.rs
@lkml-likexu lkml-likexu self-assigned this Aug 7, 2026
@lisongqian
lisongqian force-pushed the sync-ivshmem branch 4 times, most recently from fa62ca8 to 78be756 Compare August 7, 2026 08:26
@lkml-likexu

Copy link
Copy Markdown
Collaborator

@lisongqian Pls add some e2e tests for tests/e2e/sdk_compat so that we can verify this feature on both x86 and arm.

@lisongqian
lisongqian marked this pull request as draft August 10, 2026 08:20
@lisongqian

Copy link
Copy Markdown
Collaborator Author

Reopen after #1302 has been merged.

@lisongqian

Copy link
Copy Markdown
Collaborator Author

@lisongqian Pls add some e2e tests for tests/e2e/sdk_compat so that we can verify this feature on both x86 and arm.

There are integration tests for the hypervisor, and they're enough since this PR only modifies hypervisor. I will supplement the test results for both ARM and x86.

BTW, we will add e2e tests for ivshmem on metric/log features in the future. @lkml-likexu

@lisongqian
lisongqian force-pushed the sync-ivshmem branch 2 times, most recently from a1be3e8 to 201d6a2 Compare August 11, 2026 14:02
Cherry-pick the upstream cloud-hypervisor ivshmem series, adapt it to
cube-sandbox APIs, and make ivshmem work on both x86_64 and aarch64 by
default.

* hypervisor: remove pre-existing legacy ivshmem implementation
  Drop the locally-forked ivshmem device plus all of its
  vmm/config/CLI/main wiring so that we can cleanly cherry-pick the
  upstream cloud-hypervisor ivshmem series on top.

* devices: introduce ivshmem device
  Introduce the inter-vm shared memory (ivshmem) device to share a
  memory region between multiple processes running different guests
  and the host. Supports the basic ivshmem functions like
  ivshmem-plain in QEMU
  (https://www.qemu.org/docs/master/specs/ivshmem-spec.html).

* vmm: ivshmem device support.

* docs: add ivshmem device introduction.

* fuzz: add ivshmem device config.

* tests: add ivshmem integration test case.

* hypervisor: adapt upstream ivshmem to cube-sandbox APIs
  The freshly cherry-picked upstream ivshmem series targets newer
  pci/vm-migration/vm-device APIs than cube-sandbox currently exposes.
  Adjust the ported sources so that they compile against cube-sandbox's
  existing trait surface:
  - devices/ivshmem.rs: drop the upstream-only PCI_CONFIGURATION_ID /
    UserspaceMapping / EventFd dependencies; use the 10-arg
    PciConfiguration::new; switch allocate_bars/free_bars to the local
    4-/3-arg signatures (BAR0 via the SystemAllocator mmio hole, BAR2
    via the AddressAllocator); split write_config_register and
    detect_bar_reprogramming to match the local PciDevice trait;
    rename as_any_mut to as_any; align Snapshot/Snapshottable usage
    with the local API.
  - vmm/config.rs: feature-gate the std::fs import so the default
    build no longer warns, and add fmt::Display arms for the new
    ValidationError::InvalidIvshmem* variants.

* hypervisor: enable ivshmem unconditionally
  Drop the ivshmem cargo feature so that ivshmem support is built and
  shipped as part of the default cube-hypervisor binary.
  - Remove the 'ivshmem' feature declaration from hypervisor/Cargo.toml
    (workspace), vmm/Cargo.toml, devices/Cargo.toml and
    fuzz/Cargo.toml.
  - Strip every '#[cfg(feature = "ivshmem")]' attribute (37
    occurrences across 6 files) so the ivshmem types, CLI flag,
    ValidationError variants, VmConfig field, DeviceManager wiring,
    fuzz target wiring and src/main.rs hook-up are always compiled.
  - Update integration test scripts to drop '--features ivshmem' (the
    feature no longer exists).
  - Promote tests/integration.rs::snapshot_and_check_events to
    pub(crate) and call it via crate:: from the ivshmem live-migration
    test, since ivshmem-related integration tests are now always
    compiled.

Signed-off-by: Songqian Li <sionli@tencent.com>
When the guest reprograms BAR2 of the ivshmem device to a new GPA,
we must tear down the host-side userspace mapping at the old address
and create a new mapping at the new address; otherwise guest accesses
via the new BAR address would not hit the host backing memory.

Introduce an IvshmemOps trait so the device can ask the VMM to
(re)map and unmap RAM regions, plus an IvshmemUserspaceMapping struct
kept inside the devices crate to avoid a cyclic dependency on
virtio-devices. The vmm crate now provides an IvshmemHandler that
implements IvshmemOps on top of MemoryManager.
Adapted from upstream commit 5128ee9b. The path layout and a few
API signatures (Snapshot::to_state, PciConfiguration::new,
MemoryManager::create_ram_region) differ in this tree, so this is a
manual port rather than a straight cherry-pick.

Signed-off-by: Songqian Li <sionli@tencent.com>
Add test_live_migration_ivshmem and test_live_migration_ivshmem_local
to exercise live-migration of a guest that has an ivshmem device
attached. Both tests share the existing _test_ivshmem helper to
validate host<->guest data exchange before and after the migration.
To reuse the live_migration helpers (start_live_migration and
print_and_panic) from the new ivshmem tests, those helpers are
promoted to pub fn.

Adapted from upstream commit 9011ff21; the binary path is changed
from cloud-hypervisor to cube-hypervisor and Duration::new is
replaced with std::time::Duration::new to match the local style.

Signed-off-by: Songqian Li <sionli@tencent.com>
@lkml-likexu

Copy link
Copy Markdown
Collaborator

@lisongqian Any status update for this PR ?

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.

2 participants