Discussion:
[Qemu-discuss] virtio device instances identification by guest
Artem Pisarenko
2018-11-08 08:18:02 UTC
Permalink
Hi everyone,

Is there are any way to make guest system able to identify specific
instances of virtio devices as specified by qemu user (on command line or
via qmp command)?
More specifically, I'm interested in virtio-net devices.
I know it's possible for some other devices:
- virtserialport/virtconsole have 'name=<name>' property and guest
application accesses serial device via "/dev/virtio-ports/<name>"
- virtio-9p-pci/virtfs have 'mount_tag=<mount_tag>' and guest
application mounts filesystem with "mount -t 9p -o trans=virtio <mount_tag>
..."
But I cannot find any way to associate '-device virtio-net-pci' instances
with eth<X> network interfaces in guest.

Thanks in advance,
Artem
Artem Pisarenko
2018-11-08 08:56:21 UTC
Permalink
Forgot to clarify that identification needs to be unique only to machine
scope. 'virtio-net-pci' has 'mac' property, but if user wants to
instantiate multiple such machines and connect them in one network, then
'mac' value also needs to be unique per this network. Thus, user have to
generate 'mac' from some <network host id> and <NIC id> parts and guest
should find network interface by mac address masked with <NIC id> part.
Itsn't as elegant as in examples above. Although, it's better than
nothing...
Post by Artem Pisarenko
Hi everyone,
Is there are any way to make guest system able to identify specific
instances of virtio devices as specified by qemu user (on command line or
via qmp command)?
More specifically, I'm interested in virtio-net devices.
- virtserialport/virtconsole have 'name=<name>' property and guest
application accesses serial device via "/dev/virtio-ports/<name>"
- virtio-9p-pci/virtfs have 'mount_tag=<mount_tag>' and guest
application mounts filesystem with "mount -t 9p -o trans=virtio <mount_tag>
..."
But I cannot find any way to associate '-device virtio-net-pci' instances
with eth<X> network interfaces in guest.
Thanks in advance,
Artem
Artem Pisarenko
2018-11-08 11:20:53 UTC
Permalink
Ok, I found a way better, but it still not elegant, because depends on
machine hardware configuration. One may use 'addr' property to assign
address on PCI bus (and, if there are multiple PCI buses, identify bus
somehow, but I didn't looked at).
In my case on x86_64 target with default machine and given '-device
virtio-net-pci,addr=<hex_8bit_id>.0,...' on command line guest application
can get network interface name with:
`ls /sys/devices/pci0000\:00/0000\:00\:<hex_8bit_id>.0/virtio*/net/`
Post by Artem Pisarenko
Forgot to clarify that identification needs to be unique only to machine
scope. 'virtio-net-pci' has 'mac' property, but if user wants to
instantiate multiple such machines and connect them in one network, then
'mac' value also needs to be unique per this network. Thus, user have to
generate 'mac' from some <network host id> and <NIC id> parts and guest
should find network interface by mac address masked with <NIC id> part.
Itsn't as elegant as in examples above. Although, it's better than
nothing...
Post by Artem Pisarenko
Hi everyone,
Is there are any way to make guest system able to identify specific
instances of virtio devices as specified by qemu user (on command line or
via qmp command)?
More specifically, I'm interested in virtio-net devices.
- virtserialport/virtconsole have 'name=<name>' property and guest
application accesses serial device via "/dev/virtio-ports/<name>"
- virtio-9p-pci/virtfs have 'mount_tag=<mount_tag>' and guest
application mounts filesystem with "mount -t 9p -o trans=virtio <mount_tag>
..."
But I cannot find any way to associate '-device virtio-net-pci' instances
with eth<X> network interfaces in guest.
Thanks in advance,
Artem
Michael S. Tsirkin
2018-11-08 14:08:03 UTC
Permalink
Ok, I found a way better, but it still not elegant, because depends on machine
hardware configuration. One may use 'addr' property to assign address on PCI
bus (and, if there are multiple PCI buses, identify bus somehow, but I didn't
looked at).
In my case on x86_64 target with default machine and given '-device
virtio-net-pci,addr=<hex_8bit_id>.0,...' on command line guest application can
`ls /sys/devices/pci0000\:00/0000\:00\:<hex_8bit_id>.0/virtio*/net/`
I'm not sure I understand the requirements.
If you are after arbitrary strings, one way would be to add support
to vpd capability to devices... Want to try coding it up?
Forgot to clarify that identification needs to be unique only to machine
scope. 'virtio-net-pci' has 'mac' property, but if user wants to
instantiate multiple such machines and connect them in one network, then
'mac' value also needs to be unique per this network. Thus, user have to
generate 'mac' from some <network host id> and <NIC id> parts and guest
should find network interface by mac address masked with <NIC id> part.
You need to create unique MACs anyway. If you don't it isn't guaranteed networking
will work.
Itsn't as elegant as in examples above. Although, it's better than
nothing...
Hi everyone,
Is there are any way to make guest system able to identify specific
instances of virtio devices as specified by qemu user (on command line
or via qmp command)?
More specifically, I'm interested in virtio-net devices.
- virtserialport/virtconsole have 'name=<name>' property and guest
application accesses serial device via "/dev/virtio-ports/<name>"
- virtio-9p-pci/virtfs have 'mount_tag=<mount_tag>' and guest
application mounts filesystem with "mount -t 9p -o trans=virtio
<mount_tag> ..."
But I cannot find any way to associate '-device virtio-net-pci'
instances with eth<X> network interfaces in guest.
Thanks in advance,
Artem
Artem Pisarenko
2018-11-09 06:19:37 UTC
Permalink
Post by Michael S. Tsirkin
I'm not sure I understand the requirements.
No requirements. That was just a question and some notes about cons of
solutions I found (compared to an ideal way it implemented for specific
virtio devices I listed above).
Post by Michael S. Tsirkin
Post by Artem Pisarenko
Forgot to clarify that identification needs to be unique only to machine
scope. 'virtio-net-pci' has 'mac' property, but if user wants to
instantiate multiple such machines and connect them in one network, then
'mac' value also needs to be unique per this network. Thus, user have to
generate 'mac' from some <network host id> and <NIC id> parts and guest
should find network interface by mac address masked with <NIC id> part.
You need to create unique MACs anyway. If you don't it isn't guaranteed networking
will work.
Not always. It depends on network backend and use case. I've just meant,
that NIC identification by guest and MAC uniqueness are completely separate
issues, and mixing them in one single value of configuration decreases
flexibility of QEMU usage.
Post by Michael S. Tsirkin
If you are after arbitrary strings, one way would be to add support
to vpd capability to devices... Want to try coding it up?
If I wouldn't found solutions above I would have to try, but now it seems
to be an overkill (even if it doesn't involves most scare part -
modification of linux guest driver).
Maybe in some future. But now I'm happy with solutions above, and most
users, who searched and found them here, probably, too.
Post by Michael S. Tsirkin
Post by Artem Pisarenko
Ok, I found a way better, but it still not elegant, because depends on
machine
Post by Artem Pisarenko
hardware configuration. One may use 'addr' property to assign address on
PCI
Post by Artem Pisarenko
bus (and, if there are multiple PCI buses, identify bus somehow, but I
didn't
Post by Artem Pisarenko
looked at).
In my case on x86_64 target with default machine and given '-device
virtio-net-pci,addr=<hex_8bit_id>.0,...' on command line guest
application can
Post by Artem Pisarenko
`ls /sys/devices/pci0000\:00/0000\:00\:<hex_8bit_id>.0/virtio*/net/`
I'm not sure I understand the requirements.
If you are after arbitrary strings, one way would be to add support
to vpd capability to devices... Want to try coding it up?
Post by Artem Pisarenko
чт, 8 нояб. 2018 г. в 14:56, Artem Pisarenko <
Forgot to clarify that identification needs to be unique only to
machine
Post by Artem Pisarenko
scope. 'virtio-net-pci' has 'mac' property, but if user wants to
instantiate multiple such machines and connect them in one network,
then
Post by Artem Pisarenko
'mac' value also needs to be unique per this network. Thus, user
have to
Post by Artem Pisarenko
generate 'mac' from some <network host id> and <NIC id> parts and
guest
Post by Artem Pisarenko
should find network interface by mac address masked with <NIC id>
part.
You need to create unique MACs anyway. If you don't it isn't guaranteed networking
will work.
Post by Artem Pisarenko
Itsn't as elegant as in examples above. Although, it's better than
nothing...
чт, 8 нояб. 2018 г. в 14:18, Artem Pisarenko <
Hi everyone,
Is there are any way to make guest system able to identify
specific
Post by Artem Pisarenko
instances of virtio devices as specified by qemu user (on
command line
Post by Artem Pisarenko
or via qmp command)?
More specifically, I'm interested in virtio-net devices.
- virtserialport/virtconsole have 'name=<name>' property and
guest
Post by Artem Pisarenko
application accesses serial device via "/dev/virtio-ports/<name>"
- virtio-9p-pci/virtfs have 'mount_tag=<mount_tag>' and guest
application mounts filesystem with "mount -t 9p -o trans=virtio
<mount_tag> ..."
But I cannot find any way to associate '-device virtio-net-pci'
instances with eth<X> network interfaces in guest.
Thanks in advance,
Artem
Loading...