virtio-net: Add check for mac address while peer is vdpa
PATCH 1/1 virtio-net: Add check for mac address while peer is vdpa
Sometime vdpa get an all zero mac address from the hardware, this will cause the traffic down, So we add the check for in part.if we get an zero mac address we will use the default/cmdline mac address instead
--- hw/net/virtio-net.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
hw/net/virtio-net.c +6 -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" ); + } } } }
Signature · 1 line
2.21.3
Quoted 1 line
[PATCH] virtio-net: Add check for mac address while peer is vdpa
please do keep numbering patch versions.
Quoted 3 lines · Cindy Lu
Sometime vdpa get an all zero mac address from the hardware, this will cause the traffic down, So we add the check for in part.if we get an zero mac address we will use the default/cmdline mac address instead
How does this differ from v4 of same patch?
Lots of typos above. I guess I can just rewrite the whole log ...
Quoted 19 lines
Signed-off-by Cindy Lu <[email protected]>--- hw/net/virtio-net.c | 7 ++++++- 1 file changed, 6 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 154
Quoted 4 lines
hw/net/virtio-net.c +0
-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);
Below needs a huge code comment explaining what is going on.
E.g. if we get a valid mac from peer, use it.
If we get 0 instead
then we don't know the peer mac but since the
mac is 0 and that is not a legal value,
try to proceed assume something else (management, hardware) sets up the mac correctly and consistently with the qemu configuration.
hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 155
Quoted 1 line
hw/net/virtio-net.c +1
-0+if (memcmp (&netcfg.mac, &zero,sizeof (zero)) !=0 ) {
!= 0 is not necessary
hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 158
Quoted 4 lines
hw/net/virtio-net.c +3
-0+memcpy (config, &netcfg, n->config_size); + }else { +error_report ("Get an all zero mac address from hardware" );
So why are you skipping the copying of the whole config space? Why not just skip the mac? Seems quite risky e.g. looks like it will break things like reporting the link status, right?
Quoted 6 lines
hw/net/virtio-net.c +1
-0+ } } }}
Signature · 1 line
2.21.3
sure, Thanks michael, I will address, these comment and send a new version
Quoted 69 lines · Michael S. Tsirkin
Quoted 2 lines
[PATCH] virtio-net: Add check for mac address while peer is vdpa
please do keep numbering patch versions.
Quoted 3 lines · Cindy Lu
Sometime vdpa get an all zero mac address from the hardware, this will cause the traffic down, So we add the check for in part.if we get an zero mac address we will use the default/cmdline mac address instead
How does this differ from v4 of same patch?
Lots of typos above. I guess I can just rewrite the whole log ...
Quoted 19 lines
Signed-off-by Cindy Lu <[email protected]>--- hw/net/virtio-net.c | 7 ++++++- 1 file changed, 6 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 154
Quoted 4 lines
hw/net/virtio-net.c +0
-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);Below needs a huge code comment explaining what is going on.
E.g. if we get a valid mac from peer, use it.
If we get 0 instead
then we don't know the peer mac but since the
mac is 0 and that is not a legal value,
try to proceed assume something else (management, hardware) sets up the mac correctly and consistently with the qemu configuration.hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 155
Quoted 1 line
hw/net/virtio-net.c +1
-0+if (memcmp (&netcfg.mac, &zero,sizeof (zero)) !=0 ) {!= 0 is not necessary
hw/net/virtio-net.c static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config) · line 158
Quoted 4 lines
hw/net/virtio-net.c +3
-0+memcpy (config, &netcfg, n->config_size); + }else { +error_report ("Get an all zero mac address from hardware" );So why are you skipping the copying of the whole config space? Why not just skip the mac? Seems quite risky e.g. looks like it will break things like reporting the link status, right?
Quoted 6 lines
hw/net/virtio-net.c +1
-0+ } } }}
--
2.21.3