virtio-net: Set mac address to hardware if the peer is vdpa
PATCH 1/3 virtio-net: Set mac address to hardware if the peer is vdpa
If the peer's type is vdpa,set the mac address to NIC in virtio_net_device_realize, Also sometime vdpa get an all 0 macaddress from the hardware, this will cause the traffic down So we add the check for this part.
if we get an 0 mac address we will use the default mac address instead
--- hw/net/virtio-net.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +11 -1
@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)VirtIONet *n =VIRTIO_NET (vdev);struct virtio_net_config netcfg;NetClientState *nc =qemu_get_queue (n->nic); +static const MACAddr zero = { .a = {0 ,0 ,0 ,0 ,0 ,0 } };int ret =0 ;memset (&netcfg,0 ,sizeof (struct virtio_net_config ));
@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) ret =vhost_net_get_config (get_vhost_net (nc->peer), (uint8_t *)&netcfg, n->config_size);if (ret !=-1 ) { -memcpy (config, &netcfg, n->config_size); +if (memcmp (&netcfg.mac, &zero,sizeof (zero)) !=0 ) { +memcpy (config, &netcfg, n->config_size); + }else { +error_report ("Get an all zero mac address from hardware" ); + } } } }
@@ -3399,6 +3404,11 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc =qemu_get_queue (n->nic); nc->rxfilter_notify_enabled =1 ; +if (nc->peer && nc->peer->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +struct virtio_net_config netcfg = {}; +memcpy (&netcfg.mac, &n->nic_conf.macaddr,ETH_ALEN ); +virtio_net_set_config (vdev, (uint8_t *)&netcfg); + }QTAILQ_INIT (&n->rsc_chains); n->qdev = dev;
Signature · 1 line
2.21.3
PATCH 2/3 vhost-vdpa: Add qemu_close in vhost_vdpa_cleanup
fix the bug that fd will still open after the cleanup
--- net/vhost-vdpa.c | 4 ++++ 1 file changed, 4 insertions(+)
net/vhost-vdpa.c +4 -0
@@ -144,6 +144,10 @@ static void vhost_vdpa_cleanup(NetClientState *nc)g_free (s->vhost_net); s->vhost_net =NULL ; } +if (s->vhost_vdpa.device_fd >=0 ) { +qemu_close (s->vhost_vdpa.device_fd); + s->vhost_vdpa.device_fd =-1 ; + } }static bool vhost_vdpa_has_vnet_hdr (NetClientState *nc)
Signature · 1 line
2.21.3
Re: [PATCH 2/3] vhost-vdpa: Add qemu_close in vhost_vdpa_cleanup
Quoted 3 lines · Cindy Lu
fix the bug that fd will still open after the cleanup
Signed-off-by Cindy Lu <[email protected]>
Quoted 19 lines
--- net/vhost-vdpa.c | 4 ++++ 1 file changed, 4 insertions(+)net/vhost-vdpa.c +4
-0@@ -144,6 +144,10 @@ static void vhost_vdpa_cleanup(NetClientState *nc)g_free (s->vhost_net); s->vhost_net =NULL ; } +if (s->vhost_vdpa.device_fd >=0 ) { +qemu_close (s->vhost_vdpa.device_fd); + s->vhost_vdpa.device_fd =-1 ; + } }static bool vhost_vdpa_has_vnet_hdr (NetClientState *nc)
PATCH 3/3 net: Add vhost-vdpa in show_netdevs()
In reply to Cindy LuFix the bug that while Check qemu supported netdev, there is no vhost-vdpa
--- net/net.c | 3 +++ 1 file changed, 3 insertions(+)
net/net.c +3 -0
@@ -1049,6 +1049,9 @@ static void show_netdevs(void)#endif #ifdef CONFIG_POSIX "vhost-user", +#endif +#ifdef CONFIG_VHOST_VDPA + "vhost-vdpa",#endif };
Signature · 1 line
2.21.3
Re: [PATCH 3/3] net: Add vhost-vdpa in show_netdevs()
Quoted 4 lines · Cindy Lu
Fix the bug that while Check qemu supported netdev, there is no vhost-vdpa
Signed-off-by Cindy Lu <[email protected]>
Quoted 18 lines
--- net/net.c | 3 +++ 1 file changed, 3 insertions(+)net/net.c +3
-0@@ -1049,6 +1049,9 @@ static void show_netdevs(void)#endif #ifdef CONFIG_POSIX "vhost-user", +#endif +#ifdef CONFIG_VHOST_VDPA + "vhost-vdpa",#endif };
Quoted 23 lines · Cindy Lu
If the peer's type is vdpa,set the mac address to NIC in
virtio_net_device_realize, Also sometime vdpa get an all 0 macaddress from the hardware, this will cause the traffic down So we add the check for this part.
if we get an 0 mac address we will use the default mac address insteadSigned-off-by Cindy Lu <[email protected]>--- hw/net/virtio-net.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)VirtIONet *n =VIRTIO_NET (vdev);struct virtio_net_config netcfg;NetClientState *nc =qemu_get_queue (n->nic); +static const MACAddr zero = { .a = {0 ,0 ,0 ,0 ,0 ,0 } };int ret =0 ;memset (&netcfg,0 ,sizeof (struct virtio_net_config ));
hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 158
Quoted 8 lines
hw/net/virtio-net.c +4
-1@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) ret =vhost_net_get_config (get_vhost_net (nc->peer), (uint8_t *)&netcfg, n->config_size);if (ret !=-1 ) { -memcpy (config, &netcfg, n->config_size); +if (memcmp (&netcfg.mac, &zero,sizeof (zero)) !=0 ) { +memcpy (config, &netcfg, n->config_size); + }else { +error_report ("Get an all zero mac address from hardware" );
This is probably a hint that MAC is not properly provisioned.
So I guess we can leave this as is, or simply warn until the management interface is finalized.
hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 3410
Quoted 12 lines
hw/net/virtio-net.c +5
-0+ } } } }@@ -3399,6 +3404,11 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc =qemu_get_queue (n->nic); nc->rxfilter_notify_enabled =1 ; +if (nc->peer && nc->peer->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +struct virtio_net_config netcfg = {}; +memcpy (&netcfg.mac, &n->nic_conf.macaddr,ETH_ALEN ); +virtio_net_set_config (vdev, (uint8_t *)&netcfg);
Won't this overwrite all other fields in the netcfg? I think we should only touch mac part.
Thanks
Quoted 4 lines
hw/net/virtio-net.c +1
-0+ }QTAILQ_INIT (&n->rsc_chains); n->qdev = dev;
Quoted 38 lines · Jason Wang
Quoted 23 lines · Cindy Lu
If the peer's type is vdpa,set the mac address to NIC in
virtio_net_device_realize, Also sometime vdpa get an all 0 macaddress from the hardware, this will cause the traffic down So we add the check for this part.
if we get an 0 mac address we will use the default mac address insteadSigned-off-by Cindy Lu <[email protected]>--- hw/net/virtio-net.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)VirtIONet *n =VIRTIO_NET (vdev);struct virtio_net_config netcfg;NetClientState *nc =qemu_get_queue (n->nic); +static const MACAddr zero = { .a = {0 ,0 ,0 ,0 ,0 ,0 } };int ret =0 ;memset (&netcfg,0 ,sizeof (struct virtio_net_config ));hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 158
Quoted 8 lines
hw/net/virtio-net.c +4
-1@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) ret =vhost_net_get_config (get_vhost_net (nc->peer), (uint8_t *)&netcfg, n->config_size);if (ret !=-1 ) { -memcpy (config, &netcfg, n->config_size); +if (memcmp (&netcfg.mac, &zero,sizeof (zero)) !=0 ) { +memcpy (config, &netcfg, n->config_size); + }else { +error_report ("Get an all zero mac address from hardware" );This is probably a hint that MAC is not properly provisioned.
Quoted 3 lines
So I guess we can leave this as is, or simply warn until the management interface is finalized.
Hi Jason, For sure this is NIC card's problem, They cannot provide an correct MAC address,
But if we continue use this 0 mac address will cause this traffic down, maybe will cost a lot of effort in debugging
So I think maybe Just an warn is not enough, We can use the default mac address and let the traffic working
Quoted 18 lines
hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 3410
Quoted 13 lines
hw/net/virtio-net.c +5
-0+ } } } }@@ -3399,6 +3404,11 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc =qemu_get_queue (n->nic); nc->rxfilter_notify_enabled =1 ; +if (nc->peer && nc->peer->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +struct virtio_net_config netcfg = {}; +memcpy (&netcfg.mac, &n->nic_conf.macaddr,ETH_ALEN ); +virtio_net_set_config (vdev, (uint8_t *)&netcfg);Won't this overwrite all other fields in the netcfg? I think we should only touch mac part.
Quoted 3 lines
Thanks
Sure, will fix this
Quoted 5 lines
Quoted 4 lines
hw/net/virtio-net.c +1
-0+ }QTAILQ_INIT (&n->rsc_chains); n->qdev = dev;
Quoted 40 lines · Cindy Lu
Quoted 36 lines · Jason Wang
Quoted 23 lines · Cindy Lu
If the peer's type is vdpa,set the mac address to NIC in
virtio_net_device_realize, Also sometime vdpa get an all 0 macaddress from the hardware, this will cause the traffic down So we add the check for this part.
if we get an 0 mac address we will use the default mac address insteadSigned-off-by Cindy Lu <[email protected]>--- hw/net/virtio-net.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)VirtIONet *n =VIRTIO_NET (vdev);struct virtio_net_config netcfg;NetClientState *nc =qemu_get_queue (n->nic); +static const MACAddr zero = { .a = {0 ,0 ,0 ,0 ,0 ,0 } };int ret =0 ;memset (&netcfg,0 ,sizeof (struct virtio_net_config ));hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 158
Quoted 8 lines
hw/net/virtio-net.c +4
-1@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) ret =vhost_net_get_config (get_vhost_net (nc->peer), (uint8_t *)&netcfg, n->config_size);if (ret !=-1 ) { -memcpy (config, &netcfg, n->config_size); +if (memcmp (&netcfg.mac, &zero,sizeof (zero)) !=0 ) { +memcpy (config, &netcfg, n->config_size); + }else { +error_report ("Get an all zero mac address from hardware" );This is probably a hint that MAC is not properly provisioned.
Quoted 3 lines
So I guess we can leave this as is, or simply warn until the management interface is finalized.
Quoted 6 lines
Hi Jason, For sure this is NIC card's problem, They cannot provide an correct MAC address,
But if we continue use this 0 mac address will cause this traffic down, maybe will cost a lot of effort in debugging
So I think maybe Just an warn is not enough, We can use the default mac address and let the traffic working
Yes, and it's done by the following code.
But the question is there's no much value for the error here consider you've already had a solution.
Thanks
Quoted 25 lines
Quoted 16 lines
hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 3410
Quoted 12 lines
hw/net/virtio-net.c +5
-0+ } } } }@@ -3399,6 +3404,11 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc =qemu_get_queue (n->nic); nc->rxfilter_notify_enabled =1 ; +if (nc->peer && nc->peer->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +struct virtio_net_config netcfg = {}; +memcpy (&netcfg.mac, &n->nic_conf.macaddr,ETH_ALEN ); +virtio_net_set_config (vdev, (uint8_t *)&netcfg);Won't this overwrite all other fields in the netcfg? I think we should only touch mac part.
Quoted 3 lines
Thanks
Sure, will fix this
Quoted 4 lines
Quoted 4 lines
hw/net/virtio-net.c +1
-0+ }QTAILQ_INIT (&n->rsc_chains); n->qdev = dev;
Quoted 51 lines · Jason Wang
Quoted 40 lines · Cindy Lu
Quoted 36 lines · Jason Wang
Quoted 23 lines · Cindy Lu
If the peer's type is vdpa,set the mac address to NIC in
virtio_net_device_realize, Also sometime vdpa get an all 0 macaddress from the hardware, this will cause the traffic down So we add the check for this part.
if we get an 0 mac address we will use the default mac address insteadSigned-off-by Cindy Lu <[email protected]>--- hw/net/virtio-net.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)hw/net/virtio-net.c +1
-0@@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)VirtIONet *n =VIRTIO_NET (vdev);struct virtio_net_config netcfg;NetClientState *nc =qemu_get_queue (n->nic); +static const MACAddr zero = { .a = {0 ,0 ,0 ,0 ,0 ,0 } };int ret =0 ;memset (&netcfg,0 ,sizeof (struct virtio_net_config ));hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 158
Quoted 8 lines
hw/net/virtio-net.c +4
-1@@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) ret =vhost_net_get_config (get_vhost_net (nc->peer), (uint8_t *)&netcfg, n->config_size);if (ret !=-1 ) { -memcpy (config, &netcfg, n->config_size); +if (memcmp (&netcfg.mac, &zero,sizeof (zero)) !=0 ) { +memcpy (config, &netcfg, n->config_size); + }else { +error_report ("Get an all zero mac address from hardware" );This is probably a hint that MAC is not properly provisioned.
Quoted 3 lines
So I guess we can leave this as is, or simply warn until the management interface is finalized.
Quoted 6 lines
Hi Jason, For sure this is NIC card's problem, They cannot provide an correct MAC address,
But if we continue use this 0 mac address will cause this traffic down, maybe will cost a lot of effort in debugging
So I think maybe Just an warn is not enough, We can use the default mac address and let the traffic working
Quoted 7 lines
Yes, and it's done by the following code.
But the question is there's no much value for the error here consider you've already had a solution.
Thanks
Sure, Thanks Jason I will remove this
Quoted 27 lines
Quoted 26 lines
Quoted 17 lines
hw/net/virtio-net.c static void virtio_net_device_realize(DeviceState *dev, Error **errp) · line 3410
Quoted 13 lines
hw/net/virtio-net.c +5
-0+ } } } }@@ -3399,6 +3404,11 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp) nc =qemu_get_queue (n->nic); nc->rxfilter_notify_enabled =1 ; +if (nc->peer && nc->peer->info->type ==NET_CLIENT_DRIVER_VHOST_VDPA ) { +struct virtio_net_config netcfg = {}; +memcpy (&netcfg.mac, &n->nic_conf.macaddr,ETH_ALEN ); +virtio_net_set_config (vdev, (uint8_t *)&netcfg);Won't this overwrite all other fields in the netcfg? I think we should only touch mac part.
Quoted 3 lines
Thanks
Sure, will fix this
Quoted 4 lines
Quoted 4 lines
hw/net/virtio-net.c +1
-0+ }QTAILQ_INIT (&n->rsc_chains); n->qdev = dev;