rust-vmm / rust-vmm/vhost-device

Problem with interrupt support for vhost-device-gpio and QEMU 8.1.1

Open
#613 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
137
Forks
92
Avg merge
2d 12h
Merged PRs (30d)
9

Description

I tried to test connecting simulated GPIO peripherals to QEMU using vhost-device-gpio.
I have successfully built the vhost-device-gpio (with cargo build --features "mock_gpio") and tried to connect it to the Linux running on a qemu-aarch64-virt machine, built with Buildroot version 2023.11.1.

Of course, I had to add CONFIG_GPIO_VIRTIO=m in the Linux kernel configuration.

In the virtual machine, I have loaded the driver with modprobe gpio-virtio. Then, I could access the simulated GPIO controlling the direction and values.
However, when I tried to test interrupt functionality with gpiomon 0 0, I got an error:

# gpiomon 0 0
gpiomon: error waiting for events: No such device

After some investigations, I have found the cause. The feature VIRTIO_GPIO_F_IRQ was not set for the created virtio gpio device.
Further investigation required compiling QEMU with debugging symbols and running it under gdb.

With that, I could find that the problem is caused by the fact that this flag is not set in the host_features in virtio-pci.c source in QEMU.
As a quick workaround, I have modified the function virtio_pci_pre_plugged, adding the lacking feature here:

static void virtio_pci_pre_plugged(DeviceState *d, Error **errp)
{
    VirtIOPCIProxy *proxy = VIRTIO_PCI(d);
    VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);

    if (virtio_pci_modern(proxy)) {
        virtio_add_feature(&vdev->host_features, 0); /* VIRTIO_GPIO_F_IRQ - added by WZab as a quick&dirty workaround */ 
        virtio_add_feature(&vdev->host_features, VIRTIO_F_VERSION_1);
    }

    virtio_add_feature(&vdev->host_features, VIRTIO_F_BAD_FEATURE);
}

With such a modified QEMU, I was able to activate emulation of IRQs with vhost-device-gpio.
That is a QEMU problem, but it is highly specific to vhost-device-gpio. Therefore, I've described it here.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the interrupt failure with vhost-device-gpio, QEMU 8.1.1, and the stated Buildroot configuration, then inspect QEMU's hw/virtio/virtio-pci.c at virtio_pci_pre_plugged. Verify how VIRTIO_GPIO_F_IRQ is advertised and determine whether the actionable fix belongs in QEMU or this repository; done means a confirmed fix or a clearly documented upstream issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, rust
Domain
backend, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.