Skip to content

Support for iommu in vhost-user-backened #312

Description

@zqianyi792-max

My rust's dependencies and dev-dependencies are as follows

[dependencies]
clap = { version = "4.5",  features = ["derive"] }
env_logger = "0.11"
libc = "0.2"
log = "0.4"
thiserror = "2.0"
vhost = { version = "0.13", features = ["vhost-user-backend"] }
vhost-user-backend = "0.17"
virtio-bindings = "0.2.5"
virtio-queue = "0.14"
vm-memory = "0.16.1"
vmm-sys-util = "0.12"


[dev-dependencies]
assert_matches = "1.5"
virtio-queue = { version = "0.14", features = ["test-utils"] }
vm-memory = { version = "0.16.1", features = ["backend-mmap", "backend-atomic"] }

I use these crates to create a vhost-user-backened to monitor a unix domain socket to communicate with the qemu virtual machine, and my qemu boot orders are like this

./qemu-system-x86_64 \
-m 4G \
-smp 4 \
-machine q35,accel=kvm,mem-merge=off,kernel-irqchip=split,memory-backend=mem \
-object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \
-device intel-iommu,intremap=on,caching-mode=on \
-drive file=/secondDisk/zyy/qemu_images/ubuntu22-desktop2-60G.row,format=raw,if=virtio,bus=0,unit=0 \
-nographic \
-netdev user,id=net0,hostfwd=tcp::2226-:22 \
-device virtio-net-pci,netdev=net0 \
-chardev socket,id=char0,path=/secondDisk/zyy/vhost-user-cuda.sock \
-device vhost-user-device-pci,chardev=char0,vq_size=64,num_vqs=1,virtio-id=42,iommu_platform=on

the negotiate features with the front qemu are as follows

    fn features(&self) -> u64 {
        // this matches the current libvhost defaults except VHOST_F_LOG_ALL
        1 << VIRTIO_F_VERSION_1
            | 1 << VIRTIO_F_NOTIFY_ON_EMPTY
            | 1 << VIRTIO_RING_F_INDIRECT_DESC
            | 1 << VIRTIO_RING_F_EVENT_IDX
            | 1 << VIRTIO_F_IOMMU_PLATFORM

            // Protocol features are optional and must not be defined unless required and must be
            // accompanied by the supporting PROTOCOL_FEATURES bits in features.
            | VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits()
       
    }

fn protocol_features(&self) -> VhostUserProtocolFeatures {
    VhostUserProtocolFeatures::from_bits_truncate(
        VhostUserProtocolFeatures::MQ.bits()
        | VhostUserProtocolFeatures::REPLY_ACK.bits()
        | VhostUserProtocolFeatures::BACKEND_REQ.bits()
        | VHOST_USER_PROTOCOL_F_IOTLB,
    )
    }

It raises issue when I try to insert my own kernel model by the command of insmod my_ownmodle.ko, the qemu returns with the results as the picture shows

Image

Moreover, the rust backened alter me that

Fatal error: failed to handle request: handler failed to handle request: Missing memory mapping

How do I fix this?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions