* [PATCH] hw/pci: Fix crash when running QEMU with "-nic model=rocker"
@ 2020-05-27 15:31 Thomas Huth
2020-05-27 15:35 ` Paolo Bonzini
2020-06-09 17:21 ` Laurent Vivier
0 siblings, 2 replies; 5+ messages in thread
From: Thomas Huth @ 2020-05-27 15:31 UTC (permalink / raw)
To: qemu-devel, Michael S. Tsirkin
Cc: qemu-trivial, Paolo Bonzini, Michael Tokarev
QEMU currently aborts when being started with "-nic model=rocker" or with
"-net nic,model=rocker". This happens because the "rocker" device is not
a normal NIC but a switch, which has different properties. Thus we should
only consider real NIC devices for "-nic" and "-net". These devices can
be identified by the "netdev" property, so check for this property before
adding the device to the list.
Reported-by: Michael Tokarev <mjt@tls.msk.ru>
Fixes: 52310c3fa7dc854d ("net: allow using any PCI NICs in -net or -nic")
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
hw/pci/pci.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 70c66965f5..46214f8287 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -1887,7 +1887,18 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
dc->user_creatable) {
const char *name = object_class_get_name(list->data);
- g_ptr_array_add(pci_nic_models, (gpointer)name);
+ /*
+ * A network device might also be something else than a NIC, see
+ * e.g. the "rocker" device. Thus we have to look for the "netdev"
+ * property, too. Unfortunately, some devices like virtio-net only
+ * create this property during instance_init, so we have to create
+ * a temporary instance here to be able to check it.
+ */
+ Object *obj = object_new_with_class(OBJECT_CLASS(dc));
+ if (object_property_find(obj, "netdev", NULL)) {
+ g_ptr_array_add(pci_nic_models, (gpointer)name);
+ }
+ object_unref(obj);
}
next = list->next;
g_slist_free_1(list);
--
2.18.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] hw/pci: Fix crash when running QEMU with "-nic model=rocker"
2020-05-27 15:31 [PATCH] hw/pci: Fix crash when running QEMU with "-nic model=rocker" Thomas Huth
@ 2020-05-27 15:35 ` Paolo Bonzini
2020-06-09 17:21 ` Laurent Vivier
1 sibling, 0 replies; 5+ messages in thread
From: Paolo Bonzini @ 2020-05-27 15:35 UTC (permalink / raw)
To: Thomas Huth, qemu-devel, Michael S. Tsirkin; +Cc: qemu-trivial, Michael Tokarev
On 27/05/20 17:31, Thomas Huth wrote:
> QEMU currently aborts when being started with "-nic model=rocker" or with
> "-net nic,model=rocker". This happens because the "rocker" device is not
> a normal NIC but a switch, which has different properties. Thus we should
> only consider real NIC devices for "-nic" and "-net". These devices can
> be identified by the "netdev" property, so check for this property before
> adding the device to the list.
>
> Reported-by: Michael Tokarev <mjt@tls.msk.ru>
> Fixes: 52310c3fa7dc854d ("net: allow using any PCI NICs in -net or -nic")
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> hw/pci/pci.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 70c66965f5..46214f8287 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1887,7 +1887,18 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
> if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
> dc->user_creatable) {
> const char *name = object_class_get_name(list->data);
> - g_ptr_array_add(pci_nic_models, (gpointer)name);
> + /*
> + * A network device might also be something else than a NIC, see
> + * e.g. the "rocker" device. Thus we have to look for the "netdev"
> + * property, too. Unfortunately, some devices like virtio-net only
> + * create this property during instance_init, so we have to create
> + * a temporary instance here to be able to check it.
> + */
> + Object *obj = object_new_with_class(OBJECT_CLASS(dc));
> + if (object_property_find(obj, "netdev", NULL)) {
> + g_ptr_array_add(pci_nic_models, (gpointer)name);
> + }
> + object_unref(obj);
> }
> next = list->next;
> g_slist_free_1(list);
>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hw/pci: Fix crash when running QEMU with "-nic model=rocker"
2020-05-27 15:31 [PATCH] hw/pci: Fix crash when running QEMU with "-nic model=rocker" Thomas Huth
2020-05-27 15:35 ` Paolo Bonzini
@ 2020-06-09 17:21 ` Laurent Vivier
2020-06-09 17:24 ` Paolo Bonzini
1 sibling, 1 reply; 5+ messages in thread
From: Laurent Vivier @ 2020-06-09 17:21 UTC (permalink / raw)
To: Thomas Huth, qemu-devel, Michael S. Tsirkin
Cc: qemu-trivial, Paolo Bonzini, Michael Tokarev
Le 27/05/2020 à 17:31, Thomas Huth a écrit :
> QEMU currently aborts when being started with "-nic model=rocker" or with
> "-net nic,model=rocker". This happens because the "rocker" device is not
> a normal NIC but a switch, which has different properties. Thus we should
> only consider real NIC devices for "-nic" and "-net". These devices can
> be identified by the "netdev" property, so check for this property before
> adding the device to the list.
>
> Reported-by: Michael Tokarev <mjt@tls.msk.ru>
> Fixes: 52310c3fa7dc854d ("net: allow using any PCI NICs in -net or -nic")
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
> hw/pci/pci.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index 70c66965f5..46214f8287 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1887,7 +1887,18 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
> if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
> dc->user_creatable) {
> const char *name = object_class_get_name(list->data);
> - g_ptr_array_add(pci_nic_models, (gpointer)name);
> + /*
> + * A network device might also be something else than a NIC, see
> + * e.g. the "rocker" device. Thus we have to look for the "netdev"
> + * property, too. Unfortunately, some devices like virtio-net only
> + * create this property during instance_init, so we have to create
> + * a temporary instance here to be able to check it.
> + */
> + Object *obj = object_new_with_class(OBJECT_CLASS(dc));
> + if (object_property_find(obj, "netdev", NULL)) {
> + g_ptr_array_add(pci_nic_models, (gpointer)name);
> + }
> + object_unref(obj);
> }
> next = list->next;
> g_slist_free_1(list);
>
Not really trivial, I will not pick up this patch via trivial-branch,
unless PCI maintainers request it.
Thanks,
Laurent
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hw/pci: Fix crash when running QEMU with "-nic model=rocker"
2020-06-09 17:21 ` Laurent Vivier
@ 2020-06-09 17:24 ` Paolo Bonzini
2020-06-09 17:41 ` Michael S. Tsirkin
0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2020-06-09 17:24 UTC (permalink / raw)
To: Laurent Vivier, Thomas Huth, qemu-devel, Michael S. Tsirkin
Cc: qemu-trivial, Michael Tokarev
On 09/06/20 19:21, Laurent Vivier wrote:
> Le 27/05/2020 à 17:31, Thomas Huth a écrit :
>> QEMU currently aborts when being started with "-nic model=rocker" or with
>> "-net nic,model=rocker". This happens because the "rocker" device is not
>> a normal NIC but a switch, which has different properties. Thus we should
>> only consider real NIC devices for "-nic" and "-net". These devices can
>> be identified by the "netdev" property, so check for this property before
>> adding the device to the list.
>>
>> Reported-by: Michael Tokarev <mjt@tls.msk.ru>
>> Fixes: 52310c3fa7dc854d ("net: allow using any PCI NICs in -net or -nic")
>> Signed-off-by: Thomas Huth <thuth@redhat.com>
>> ---
>> hw/pci/pci.c | 13 ++++++++++++-
>> 1 file changed, 12 insertions(+), 1 deletion(-)
>>
>> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
>> index 70c66965f5..46214f8287 100644
>> --- a/hw/pci/pci.c
>> +++ b/hw/pci/pci.c
>> @@ -1887,7 +1887,18 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
>> if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
>> dc->user_creatable) {
>> const char *name = object_class_get_name(list->data);
>> - g_ptr_array_add(pci_nic_models, (gpointer)name);
>> + /*
>> + * A network device might also be something else than a NIC, see
>> + * e.g. the "rocker" device. Thus we have to look for the "netdev"
>> + * property, too. Unfortunately, some devices like virtio-net only
>> + * create this property during instance_init, so we have to create
>> + * a temporary instance here to be able to check it.
>> + */
>> + Object *obj = object_new_with_class(OBJECT_CLASS(dc));
>> + if (object_property_find(obj, "netdev", NULL)) {
>> + g_ptr_array_add(pci_nic_models, (gpointer)name);
>> + }
>> + object_unref(obj);
>> }
>> next = list->next;
>> g_slist_free_1(list);
>>
>
> Not really trivial, I will not pick up this patch via trivial-branch,
> unless PCI maintainers request it.
>
> Thanks,
> Laurent
>
I'll pick it up then.
Paolo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] hw/pci: Fix crash when running QEMU with "-nic model=rocker"
2020-06-09 17:24 ` Paolo Bonzini
@ 2020-06-09 17:41 ` Michael S. Tsirkin
0 siblings, 0 replies; 5+ messages in thread
From: Michael S. Tsirkin @ 2020-06-09 17:41 UTC (permalink / raw)
To: Paolo Bonzini
Cc: Thomas Huth, qemu-trivial, Michael Tokarev, Laurent Vivier, qemu-devel
On Tue, Jun 09, 2020 at 07:24:24PM +0200, Paolo Bonzini wrote:
> On 09/06/20 19:21, Laurent Vivier wrote:
> > Le 27/05/2020 à 17:31, Thomas Huth a écrit :
> >> QEMU currently aborts when being started with "-nic model=rocker" or with
> >> "-net nic,model=rocker". This happens because the "rocker" device is not
> >> a normal NIC but a switch, which has different properties. Thus we should
> >> only consider real NIC devices for "-nic" and "-net". These devices can
> >> be identified by the "netdev" property, so check for this property before
> >> adding the device to the list.
> >>
> >> Reported-by: Michael Tokarev <mjt@tls.msk.ru>
> >> Fixes: 52310c3fa7dc854d ("net: allow using any PCI NICs in -net or -nic")
> >> Signed-off-by: Thomas Huth <thuth@redhat.com>
> >> ---
> >> hw/pci/pci.c | 13 ++++++++++++-
> >> 1 file changed, 12 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> >> index 70c66965f5..46214f8287 100644
> >> --- a/hw/pci/pci.c
> >> +++ b/hw/pci/pci.c
> >> @@ -1887,7 +1887,18 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus,
> >> if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) &&
> >> dc->user_creatable) {
> >> const char *name = object_class_get_name(list->data);
> >> - g_ptr_array_add(pci_nic_models, (gpointer)name);
> >> + /*
> >> + * A network device might also be something else than a NIC, see
> >> + * e.g. the "rocker" device. Thus we have to look for the "netdev"
> >> + * property, too. Unfortunately, some devices like virtio-net only
> >> + * create this property during instance_init, so we have to create
> >> + * a temporary instance here to be able to check it.
> >> + */
> >> + Object *obj = object_new_with_class(OBJECT_CLASS(dc));
> >> + if (object_property_find(obj, "netdev", NULL)) {
> >> + g_ptr_array_add(pci_nic_models, (gpointer)name);
> >> + }
> >> + object_unref(obj);
> >> }
> >> next = list->next;
> >> g_slist_free_1(list);
> >>
> >
> > Not really trivial, I will not pick up this patch via trivial-branch,
> > unless PCI maintainers request it.
> >
> > Thanks,
> > Laurent
> >
>
> I'll pick it up then.
>
> Paolo
I queued this already. Thanks!
--
MST
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-06-09 17:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-27 15:31 [PATCH] hw/pci: Fix crash when running QEMU with "-nic model=rocker" Thomas Huth
2020-05-27 15:35 ` Paolo Bonzini
2020-06-09 17:21 ` Laurent Vivier
2020-06-09 17:24 ` Paolo Bonzini
2020-06-09 17:41 ` Michael S. Tsirkin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).