qemuqemu-devicevirtio

Who will configure virtio,mmio device register in qemu?


I want to enable virtio_net on qemu, virtio_net driver should return an error if the device id is zero (read from https://docs.oasis-open.org/virtio/virtio/v1.1/virtio-v1.1.html).

In qemu, 0x0A000000 address is used for virtio,mmio region. when I print the memory dump of 0x0A000000, I am getting only the magic number, vendor id, and mmio version which is set by qemu. But my driver expects device id and other values like device features, max queue size, etc.. but gets those values to zero.

So my question is who will write the config data in virtio,mmio device register(in my case mmio region is 0x0A000000) if qemu then which command is used? (I am using my custom kdi)

Qemu command:

qemu-system-aarch64 -M virt-7.1,virtualization=on -cpu cortex-a72 -m 512 -smp 1 -display none -serial mon:stdio -device loader,addr=0x50004000,cpu-num=0,file=/tftp/sd.kdi -device loader,addr=0x50004020,cpu-num=0 **-netdev tap,id=mynet0,ifname=tap0,script=no,downscript=no -device e1000,netdev=mynet0,mac=52:55:00:d1:55:01**

Memory dump of 0x0A000000:

(gdb) x/64x 0x0a000000
0xa000000: 0x74726976 0x00000001 0x00000000 0x554d4551
0xa000010: 0x00000000 0x00000000 0x00000000 0x00000000
0xa000020: 0x00000000 0x00000000 0x00000000 0x00000000
0xa000030: 0x00000000 0x00000000 0x00000000 0x00000000
0xa000040: 0x00000000 0x00000000 0x00000000 0x00000000
0xa000050: 0x00000000 0x00000000 0x00000000 0x00000000
0xa000060: 0x00000000 0x00000000 0x00000000 0x00000000
0xa000070: 0x00000000 0x00000000 0x00000000 0x00000000
0xa000080: 0x00000000 0x00000000 0x00000000 0x00000000
0xa000090: 0x00000000 0x00000000 0x00000000 0x00000000
0xa0000a0: 0x00000000 0x00000000 0x00000000 0x00000000
0xa0000b0: 0x00000000 0x00000000 0x00000000 0x00000000
0xa0000c0: 0x00000000 0x00000000 0x00000000 0x00000000
0xa0000d0: 0x00000000 0x00000000 0x00000000 0x00000000
0xa0000e0: 0x00000000 0x00000000 0x00000000 0x00000000
0xa0000f0: 0x00000000 0x00000000 0x00000000 0x00000000

I tried qemu command to configure virtio_net, but unable to install driver due to config data not available at virtio,mmio region.


Solution

  • As an initial note, the virtio-mmio devices are generally not recommended for use. We provide them for compatibility because there was a time when that was the only kind of virtio the virt board supported, but these days it's generally better to use the PCI virtio devices: they're more flexible, you can create more of them, and they're better tested. That said, here's what's up with the virtio-mmio behaviour you're seeing:

    The virtio MMIO devices created by the virt board are 'transports', which is to say they don't by default have any backends plugged into them. They're useless unless your command line creates virtio backends to plug into the transport, and your command line doesn't do that. What you see is what you should expect for "transport with nothing plugged into it".

    Try creating a backend on the command line, eg -with -device virtio-blk-device, -device virtio-net-device, etc. (These likely need extra sub-options to configure them, eg connecting a virtio-blk-device to its drive.)