* [PATCH] virtio: add num_vf callback to virtio_bus
@ 2026-03-09 2:33 Yui Washizu
2026-03-09 3:33 ` Jason Wang
0 siblings, 1 reply; 5+ messages in thread
From: Yui Washizu @ 2026-03-09 2:33 UTC (permalink / raw)
To: mst, jasowang, xuanzhuo, eperezma; +Cc: Yui Washizu, virtualization
Recent QEMU versions added support for virtio SR-IOV emulation,
allowing virtio devices to expose SR-IOV VFs to the guest.
However, virtio_bus does not implement the num_vf callback of bus_type,
causing dev_num_vf() to return 0 for virtio devices even when
SR-IOV VFs are active.
net/core/rtnetlink.c calls dev_num_vf(dev->dev.parent) to populate
IFLA_NUM_VF and IFLA_VFINFO_LIST in RTM_GETLINK responses. For a
virtio-net device, dev.parent points to the virtio_device, whose bus
is virtio_bus. Without num_vf, SR-IOV VF information is silently
omitted from tools that rely on rtnetlink, such as 'ip link show'.
Add a num_vf callback that delegates to dev_num_vf(dev->parent),
which in turn reaches the underlying transport (pci_bus_type for
virtio-pci) where the actual VF count is tracked. Non-PCI transports
are unaffected as dev_num_vf() returns 0 when no num_vf callback is
present.
Signed-off-by: Yui Washizu <yui.washidu@gmail.com>
---
drivers/virtio/virtio.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
index 5bdc6b82b30b..299fa83be1d5 100644
--- a/drivers/virtio/virtio.c
+++ b/drivers/virtio/virtio.c
@@ -435,6 +435,14 @@ static void virtio_dev_shutdown(struct device *_d)
dev->config->reset(dev);
}
+static int virtio_dev_num_vf(struct device *dev)
+{
+ struct virtio_device *vdev = dev_to_virtio(dev);
+
+ return dev_num_vf(vdev->dev.parent);
+}
+
+
static const struct bus_type virtio_bus = {
.name = "virtio",
.match = virtio_dev_match,
@@ -444,6 +452,7 @@ static const struct bus_type virtio_bus = {
.remove = virtio_dev_remove,
.irq_get_affinity = virtio_irq_get_affinity,
.shutdown = virtio_dev_shutdown,
+ .num_vf = virtio_dev_num_vf,
};
int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio: add num_vf callback to virtio_bus
2026-03-09 2:33 [PATCH] virtio: add num_vf callback to virtio_bus Yui Washizu
@ 2026-03-09 3:33 ` Jason Wang
2026-03-09 6:19 ` Yui Washizu
0 siblings, 1 reply; 5+ messages in thread
From: Jason Wang @ 2026-03-09 3:33 UTC (permalink / raw)
To: Yui Washizu; +Cc: mst, xuanzhuo, eperezma, virtualization
On Mon, Mar 9, 2026 at 10:37 AM Yui Washizu <yui.washidu@gmail.com> wrote:
>
> Recent QEMU versions added support for virtio SR-IOV emulation,
> allowing virtio devices to expose SR-IOV VFs to the guest.
> However, virtio_bus does not implement the num_vf callback of bus_type,
> causing dev_num_vf() to return 0 for virtio devices even when
> SR-IOV VFs are active.
>
> net/core/rtnetlink.c calls dev_num_vf(dev->dev.parent) to populate
> IFLA_NUM_VF and IFLA_VFINFO_LIST
Patch looks good but,
If I understand correctly, ndo_get_vf_config is needed for
IFLA_VFINFO_LIST but not implemeted in this patch?
> in RTM_GETLINK responses. For a
> virtio-net device, dev.parent points to the virtio_device, whose bus
> is virtio_bus. Without num_vf, SR-IOV VF information is silently
> omitted from tools that rely on rtnetlink, such as 'ip link show'.
>
> Add a num_vf callback that delegates to dev_num_vf(dev->parent),
> which in turn reaches the underlying transport (pci_bus_type for
> virtio-pci) where the actual VF count is tracked. Non-PCI transports
> are unaffected as dev_num_vf() returns 0 when no num_vf callback is
> present.
>
> Signed-off-by: Yui Washizu <yui.washidu@gmail.com>
> ---
> drivers/virtio/virtio.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index 5bdc6b82b30b..299fa83be1d5 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -435,6 +435,14 @@ static void virtio_dev_shutdown(struct device *_d)
> dev->config->reset(dev);
> }
>
> +static int virtio_dev_num_vf(struct device *dev)
> +{
> + struct virtio_device *vdev = dev_to_virtio(dev);
> +
> + return dev_num_vf(vdev->dev.parent);
> +}
> +
> +
> static const struct bus_type virtio_bus = {
> .name = "virtio",
> .match = virtio_dev_match,
> @@ -444,6 +452,7 @@ static const struct bus_type virtio_bus = {
> .remove = virtio_dev_remove,
> .irq_get_affinity = virtio_irq_get_affinity,
> .shutdown = virtio_dev_shutdown,
> + .num_vf = virtio_dev_num_vf,
> };
>
> int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
> --
> 2.47.3
>
Thanks
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio: add num_vf callback to virtio_bus
2026-03-09 3:33 ` Jason Wang
@ 2026-03-09 6:19 ` Yui Washizu
2026-03-10 3:02 ` Jason Wang
0 siblings, 1 reply; 5+ messages in thread
From: Yui Washizu @ 2026-03-09 6:19 UTC (permalink / raw)
To: Jason Wang; +Cc: mst, xuanzhuo, eperezma, virtualization
On 3/9/2026 12:33 PM, Jason Wang wrote:
> On Mon, Mar 9, 2026 at 10:37 AM Yui Washizu <yui.washidu@gmail.com> wrote:
>> Recent QEMU versions added support for virtio SR-IOV emulation,
>> allowing virtio devices to expose SR-IOV VFs to the guest.
>> However, virtio_bus does not implement the num_vf callback of bus_type,
>> causing dev_num_vf() to return 0 for virtio devices even when
>> SR-IOV VFs are active.
>>
>> net/core/rtnetlink.c calls dev_num_vf(dev->dev.parent) to populate
>> IFLA_NUM_VF and IFLA_VFINFO_LIST
> Patch looks good but,
>
> If I understand correctly, ndo_get_vf_config is needed for
> IFLA_VFINFO_LIST but not implemeted in this patch?
Thank you for your comment.
I submitted this patch because I confirmed
that "ip link show" returns the correct VF IDs with this implementation.
In the current implementation,
I believe there is no information that would need to be referenced
through IFLA_VFINFO_LIST.
Therefore, I did not include ndo_get_vf_config in this patch,
as it did not seem essential at this stage.
Would it be better to implement IFLA_VFINFO_LIST support together with this?
Regards,
>> in RTM_GETLINK responses. For a
>> virtio-net device, dev.parent points to the virtio_device, whose bus
>> is virtio_bus. Without num_vf, SR-IOV VF information is silently
>> omitted from tools that rely on rtnetlink, such as 'ip link show'.
>>
>> Add a num_vf callback that delegates to dev_num_vf(dev->parent),
>> which in turn reaches the underlying transport (pci_bus_type for
>> virtio-pci) where the actual VF count is tracked. Non-PCI transports
>> are unaffected as dev_num_vf() returns 0 when no num_vf callback is
>> present.
>>
>> Signed-off-by: Yui Washizu <yui.washidu@gmail.com>
>> ---
>> drivers/virtio/virtio.c | 9 +++++++++
>> 1 file changed, 9 insertions(+)
>>
>> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
>> index 5bdc6b82b30b..299fa83be1d5 100644
>> --- a/drivers/virtio/virtio.c
>> +++ b/drivers/virtio/virtio.c
>> @@ -435,6 +435,14 @@ static void virtio_dev_shutdown(struct device *_d)
>> dev->config->reset(dev);
>> }
>>
>> +static int virtio_dev_num_vf(struct device *dev)
>> +{
>> + struct virtio_device *vdev = dev_to_virtio(dev);
>> +
>> + return dev_num_vf(vdev->dev.parent);
>> +}
>> +
>> +
>> static const struct bus_type virtio_bus = {
>> .name = "virtio",
>> .match = virtio_dev_match,
>> @@ -444,6 +452,7 @@ static const struct bus_type virtio_bus = {
>> .remove = virtio_dev_remove,
>> .irq_get_affinity = virtio_irq_get_affinity,
>> .shutdown = virtio_dev_shutdown,
>> + .num_vf = virtio_dev_num_vf,
>> };
>>
>> int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
>> --
>> 2.47.3
>>
> Thanks
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio: add num_vf callback to virtio_bus
2026-03-09 6:19 ` Yui Washizu
@ 2026-03-10 3:02 ` Jason Wang
2026-03-10 5:34 ` Washizu Yui
0 siblings, 1 reply; 5+ messages in thread
From: Jason Wang @ 2026-03-10 3:02 UTC (permalink / raw)
To: Yui Washizu; +Cc: mst, xuanzhuo, eperezma, virtualization
On Mon, Mar 9, 2026 at 2:19 PM Yui Washizu <yui.washidu@gmail.com> wrote:
>
>
> On 3/9/2026 12:33 PM, Jason Wang wrote:
> > On Mon, Mar 9, 2026 at 10:37 AM Yui Washizu <yui.washidu@gmail.com> wrote:
> >> Recent QEMU versions added support for virtio SR-IOV emulation,
> >> allowing virtio devices to expose SR-IOV VFs to the guest.
> >> However, virtio_bus does not implement the num_vf callback of bus_type,
> >> causing dev_num_vf() to return 0 for virtio devices even when
> >> SR-IOV VFs are active.
> >>
> >> net/core/rtnetlink.c calls dev_num_vf(dev->dev.parent) to populate
> >> IFLA_NUM_VF and IFLA_VFINFO_LIST
> > Patch looks good but,
> >
> > If I understand correctly, ndo_get_vf_config is needed for
> > IFLA_VFINFO_LIST but not implemeted in this patch?
>
> Thank you for your comment.
>
> I submitted this patch because I confirmed
> that "ip link show" returns the correct VF IDs with this implementation.
>
> In the current implementation,
> I believe there is no information that would need to be referenced
> through IFLA_VFINFO_LIST.
> Therefore, I did not include ndo_get_vf_config in this patch,
> as it did not seem essential at this stage.
>
> Would it be better to implement IFLA_VFINFO_LIST support together with this?
Then it's not, I think it's better to not mention IFLA_VFINFO_LIST in
the commit log as it may confuse people.
Thanks
>
> Regards,
>
>
> >> in RTM_GETLINK responses. For a
> >> virtio-net device, dev.parent points to the virtio_device, whose bus
> >> is virtio_bus. Without num_vf, SR-IOV VF information is silently
> >> omitted from tools that rely on rtnetlink, such as 'ip link show'.
> >>
> >> Add a num_vf callback that delegates to dev_num_vf(dev->parent),
> >> which in turn reaches the underlying transport (pci_bus_type for
> >> virtio-pci) where the actual VF count is tracked. Non-PCI transports
> >> are unaffected as dev_num_vf() returns 0 when no num_vf callback is
> >> present.
> >>
> >> Signed-off-by: Yui Washizu <yui.washidu@gmail.com>
> >> ---
> >> drivers/virtio/virtio.c | 9 +++++++++
> >> 1 file changed, 9 insertions(+)
> >>
> >> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> >> index 5bdc6b82b30b..299fa83be1d5 100644
> >> --- a/drivers/virtio/virtio.c
> >> +++ b/drivers/virtio/virtio.c
> >> @@ -435,6 +435,14 @@ static void virtio_dev_shutdown(struct device *_d)
> >> dev->config->reset(dev);
> >> }
> >>
> >> +static int virtio_dev_num_vf(struct device *dev)
> >> +{
> >> + struct virtio_device *vdev = dev_to_virtio(dev);
> >> +
> >> + return dev_num_vf(vdev->dev.parent);
> >> +}
> >> +
> >> +
> >> static const struct bus_type virtio_bus = {
> >> .name = "virtio",
> >> .match = virtio_dev_match,
> >> @@ -444,6 +452,7 @@ static const struct bus_type virtio_bus = {
> >> .remove = virtio_dev_remove,
> >> .irq_get_affinity = virtio_irq_get_affinity,
> >> .shutdown = virtio_dev_shutdown,
> >> + .num_vf = virtio_dev_num_vf,
> >> };
> >>
> >> int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
> >> --
> >> 2.47.3
> >>
> > Thanks
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] virtio: add num_vf callback to virtio_bus
2026-03-10 3:02 ` Jason Wang
@ 2026-03-10 5:34 ` Washizu Yui
0 siblings, 0 replies; 5+ messages in thread
From: Washizu Yui @ 2026-03-10 5:34 UTC (permalink / raw)
To: Jason Wang; +Cc: mst, xuanzhuo, eperezma, virtualization
2026年3月10日(火) 12:02 Jason Wang <jasowang@redhat.com>:
>
> On Mon, Mar 9, 2026 at 2:19 PM Yui Washizu <yui.washidu@gmail.com> wrote:
> >
> >
> > On 3/9/2026 12:33 PM, Jason Wang wrote:
> > > On Mon, Mar 9, 2026 at 10:37 AM Yui Washizu <yui.washidu@gmail.com> wrote:
> > >> Recent QEMU versions added support for virtio SR-IOV emulation,
> > >> allowing virtio devices to expose SR-IOV VFs to the guest.
> > >> However, virtio_bus does not implement the num_vf callback of bus_type,
> > >> causing dev_num_vf() to return 0 for virtio devices even when
> > >> SR-IOV VFs are active.
> > >>
> > >> net/core/rtnetlink.c calls dev_num_vf(dev->dev.parent) to populate
> > >> IFLA_NUM_VF and IFLA_VFINFO_LIST
> > > Patch looks good but,
> > >
> > > If I understand correctly, ndo_get_vf_config is needed for
> > > IFLA_VFINFO_LIST but not implemeted in this patch?
> >
> > Thank you for your comment.
> >
> > I submitted this patch because I confirmed
> > that "ip link show" returns the correct VF IDs with this implementation.
> >
> > In the current implementation,
> > I believe there is no information that would need to be referenced
> > through IFLA_VFINFO_LIST.
> > Therefore, I did not include ndo_get_vf_config in this patch,
> > as it did not seem essential at this stage.
> >
> > Would it be better to implement IFLA_VFINFO_LIST support together with this?
>
> Then it's not, I think it's better to not mention IFLA_VFINFO_LIST in
> the commit log as it may confuse people.
>
> Thanks
>
Thank you.
I'll update the commit message to remove the reference to IFLA_VFINFO_LIST
and send a v2.
Regards,
>
> >
> > Regards,
> >
> >
> > >> in RTM_GETLINK responses. For a
> > >> virtio-net device, dev.parent points to the virtio_device, whose bus
> > >> is virtio_bus. Without num_vf, SR-IOV VF information is silently
> > >> omitted from tools that rely on rtnetlink, such as 'ip link show'.
> > >>
> > >> Add a num_vf callback that delegates to dev_num_vf(dev->parent),
> > >> which in turn reaches the underlying transport (pci_bus_type for
> > >> virtio-pci) where the actual VF count is tracked. Non-PCI transports
> > >> are unaffected as dev_num_vf() returns 0 when no num_vf callback is
> > >> present.
> > >>
> > >> Signed-off-by: Yui Washizu <yui.washidu@gmail.com>
> > >> ---
> > >> drivers/virtio/virtio.c | 9 +++++++++
> > >> 1 file changed, 9 insertions(+)
> > >>
> > >> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> > >> index 5bdc6b82b30b..299fa83be1d5 100644
> > >> --- a/drivers/virtio/virtio.c
> > >> +++ b/drivers/virtio/virtio.c
> > >> @@ -435,6 +435,14 @@ static void virtio_dev_shutdown(struct device *_d)
> > >> dev->config->reset(dev);
> > >> }
> > >>
> > >> +static int virtio_dev_num_vf(struct device *dev)
> > >> +{
> > >> + struct virtio_device *vdev = dev_to_virtio(dev);
> > >> +
> > >> + return dev_num_vf(vdev->dev.parent);
> > >> +}
> > >> +
> > >> +
> > >> static const struct bus_type virtio_bus = {
> > >> .name = "virtio",
> > >> .match = virtio_dev_match,
> > >> @@ -444,6 +452,7 @@ static const struct bus_type virtio_bus = {
> > >> .remove = virtio_dev_remove,
> > >> .irq_get_affinity = virtio_irq_get_affinity,
> > >> .shutdown = virtio_dev_shutdown,
> > >> + .num_vf = virtio_dev_num_vf,
> > >> };
> > >>
> > >> int __register_virtio_driver(struct virtio_driver *driver, struct module *owner)
> > >> --
> > >> 2.47.3
> > >>
> > > Thanks
> > >
> >
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-03-10 5:34 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 2:33 [PATCH] virtio: add num_vf callback to virtio_bus Yui Washizu
2026-03-09 3:33 ` Jason Wang
2026-03-09 6:19 ` Yui Washizu
2026-03-10 3:02 ` Jason Wang
2026-03-10 5:34 ` Washizu Yui
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox