diff mbox series

[v2] virtio-net: Add check for mac address while peer is vdpa

Message ID 20201023091559.4858-1-lulu@redhat.com
State Superseded
Headers show
Series [v2] virtio-net: Add check for mac address while peer is vdpa | expand

Commit Message

Cindy Lu Oct. 23, 2020, 9:15 a.m. UTC
Sometime vdpa get an all 0 mac address 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

Signed-off-by: Cindy Lu <lulu@redhat.com>
---
 hw/net/virtio-net.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Jason Wang Oct. 26, 2020, 2:43 a.m. UTC | #1
On 2020/10/23 下午5:15, Cindy Lu wrote:
> Sometime vdpa get an all 0 mac address 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

>

> Signed-off-by: Cindy Lu <lulu@redhat.com>

> ---

>   hw/net/virtio-net.c | 7 ++++++-

>   1 file changed, 6 insertions(+), 1 deletion(-)

>

> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c

> index 9179013ac4..f1648fc47d 100644

> --- a/hw/net/virtio-net.c

> +++ b/hw/net/virtio-net.c

> @@ -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");

> +            }

>           }

>       }

>   }



Applied.

Thanks
Jason Wang Oct. 26, 2020, 3:19 a.m. UTC | #2
On 2020/10/26 上午10:43, Jason Wang wrote:
>

> On 2020/10/23 下午5:15, Cindy Lu wrote:

>> Sometime vdpa get an all 0 mac address 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

>>

>> Signed-off-by: Cindy Lu <lulu@redhat.com>

>> ---

>>   hw/net/virtio-net.c | 7 ++++++-

>>   1 file changed, 6 insertions(+), 1 deletion(-)

>>

>> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c

>> index 9179013ac4..f1648fc47d 100644

>> --- a/hw/net/virtio-net.c

>> +++ b/hw/net/virtio-net.c

>> @@ -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");

>> +            }

>>           }

>>       }

>>   }

>

>

> Applied.

>

> Thanks

>

>


Speak too fast. Some questions:

1) Any reason that you do such check or get_config() instead of doing it 
once in device initalization
2) the indentation looks wrong
3) There's no need for an error here since we can workaround it

Thanks
Cindy Lu Oct. 26, 2020, 4:41 a.m. UTC | #3
Hi jason


On Mon, Oct 26, 2020 at 11:20 AM Jason Wang <jasowang@redhat.com> wrote:

>

> On 2020/10/26 上午10:43, Jason Wang wrote:

> >

> > On 2020/10/23 下午5:15, Cindy Lu wrote:

> >> Sometime vdpa get an all 0 mac address 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

> >>

> >> Signed-off-by: Cindy Lu <lulu@redhat.com>

> >> ---

> >>   hw/net/virtio-net.c | 7 ++++++-

> >>   1 file changed, 6 insertions(+), 1 deletion(-)

> >>

> >> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c

> >> index 9179013ac4..f1648fc47d 100644

> >> --- a/hw/net/virtio-net.c

> >> +++ b/hw/net/virtio-net.c

> >> @@ -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");

> >> +            }

> >>           }

> >>       }

> >>   }

> >

> >

> > Applied.

> >

> > Thanks

> >

> >

>

> Speak too fast. Some questions:

>

> 1) Any reason that you do such check or get_config() instead of doing it

> once in device initalization

>

get_config()  was called before the device realized.  If we check in the
device initalization, the mac address is already overwritten to 0 and
we lost the default mac address
Also for my understanding. the mac address read from hardware should never
been 0, so we need to check it every time we got it, Just in case it will
change to 0 and overwrite the mac address while the qemu running or some
other case

> 2) the indentation looks wrong

>

sure will fix this

> 3) There's no need for an error here since we can workaround it


sure, I will change it to log

>

>



> Thanks

>

>
<div dir="ltr"><div dir="ltr">Hi jason <div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Oct 26, 2020 at 11:20 AM Jason Wang &lt;<a href="mailto:jasowang@redhat.com">jasowang@redhat.com</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On 2020/10/26 上午10:43, Jason Wang wrote:<br>
&gt;<br>
&gt; On 2020/10/23 下午5:15, Cindy Lu wrote:<br>
&gt;&gt; Sometime vdpa get an all 0 mac address from the hardware, this will <br>
&gt;&gt; cause the traffic down<br>
&gt;&gt; So we add the check for this part.<br>
&gt;&gt; if we get an 0 mac address we will use the default mac address instead<br>
&gt;&gt;<br>
&gt;&gt; Signed-off-by: Cindy Lu &lt;<a href="mailto:lulu@redhat.com" target="_blank">lulu@redhat.com</a>&gt;<br>
&gt;&gt; ---<br>
&gt;&gt;   hw/net/virtio-net.c | 7 ++++++-<br>
&gt;&gt;   1 file changed, 6 insertions(+), 1 deletion(-)<br>
&gt;&gt;<br>
&gt;&gt; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c<br>
&gt;&gt; index 9179013ac4..f1648fc47d 100644<br>
&gt;&gt; --- a/hw/net/virtio-net.c<br>
&gt;&gt; +++ b/hw/net/virtio-net.c<br>
&gt;&gt; @@ -126,6 +126,7 @@ static void virtio_net_get_config(VirtIODevice <br>
&gt;&gt; *vdev, uint8_t *config)<br>
&gt;&gt;       VirtIONet *n = VIRTIO_NET(vdev);<br>
&gt;&gt;       struct virtio_net_config netcfg;<br>
&gt;&gt;       NetClientState *nc = qemu_get_queue(n-&gt;nic);<br>
&gt;&gt; +    static const MACAddr zero = { .a = { 0, 0, 0, 0, 0, 0 } };<br>
&gt;&gt;         int ret = 0;<br>
&gt;&gt;       memset(&amp;netcfg, 0 , sizeof(struct virtio_net_config));<br>
&gt;&gt; @@ -151,7 +152,11 @@ static void virtio_net_get_config(VirtIODevice <br>
&gt;&gt; *vdev, uint8_t *config)<br>
&gt;&gt;           ret = vhost_net_get_config(get_vhost_net(nc-&gt;peer), <br>
&gt;&gt; (uint8_t *)&amp;netcfg,<br>
&gt;&gt;                                      n-&gt;config_size);<br>
&gt;&gt;           if (ret != -1) {<br>
&gt;&gt; -            memcpy(config, &amp;netcfg, n-&gt;config_size);<br>
&gt;&gt; +            if (memcmp(&amp;netcfg.mac, &amp;zero, sizeof(zero)) != 0) {<br>
&gt;&gt; +                memcpy(config, &amp;netcfg, n-&gt;config_size);<br>
&gt;&gt; +        } else {<br>
&gt;&gt; +                error_report(&quot;Get an all zero mac address from <br>
&gt;&gt; hardware&quot;);<br>
&gt;&gt; +            }<br>
&gt;&gt;           }<br>
&gt;&gt;       }<br>
&gt;&gt;   }<br>
&gt;<br>
&gt;<br>
&gt; Applied.<br>
&gt;<br>
&gt; Thanks<br>
&gt;<br>
&gt;<br>
<br>
Speak too fast. Some questions:<br>
<br>
1) Any reason that you do such check or get_config() instead of doing it <br>
once in device initalization<br></blockquote><div>get_config()  was called before the device realized.  If we check in the  device initalization, the mac address is already overwritten to 0 and we lost the default mac address</div><div>Also for my understanding. the mac address read from hardware should never been 0, so we need to check it every time we got it, Just in case it will change to 0 and overwrite the mac address while the qemu running or some other case  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
2) the indentation looks wrong<br></blockquote><div>sure will fix this  </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
3) There&#39;s no need for an error here since we can workaround it</blockquote><div>sure, I will change it to log</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> <br></blockquote><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Thanks<br>
<br>
</blockquote></div></div>
Jason Wang Oct. 27, 2020, 2:42 a.m. UTC | #4
----- Original Message -----
> Hi jason
> 
> 
> On Mon, Oct 26, 2020 at 11:20 AM Jason Wang <jasowang@redhat.com> wrote:
> 
> >
> > On 2020/10/26 上午10:43, Jason Wang wrote:
> > >
> > > On 2020/10/23 下午5:15, Cindy Lu wrote:
> > >> Sometime vdpa get an all 0 mac address 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
> > >>
> > >> Signed-off-by: Cindy Lu <lulu@redhat.com>
> > >> ---
> > >>   hw/net/virtio-net.c | 7 ++++++-
> > >>   1 file changed, 6 insertions(+), 1 deletion(-)
> > >>
> > >> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > >> index 9179013ac4..f1648fc47d 100644
> > >> --- a/hw/net/virtio-net.c
> > >> +++ b/hw/net/virtio-net.c
> > >> @@ -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");
> > >> +            }
> > >>           }
> > >>       }
> > >>   }
> > >
> > >
> > > Applied.
> > >
> > > Thanks
> > >
> > >
> >
> > Speak too fast. Some questions:
> >
> > 1) Any reason that you do such check or get_config() instead of doing it
> > once in device initalization
> >
> get_config()  was called before the device realized.

Intersting, any reason that we need call get_config() even before
device is realized?

> If we check in the
> device initalization, the mac address is already overwritten to 0 and
> we lost the default mac address
> Also for my understanding. the mac address read from hardware should never
> been 0, so we need to check it every time we got it,

This sounds self-contradict.

> Just in case it will
> change to 0 and overwrite the mac address while the qemu running or some
> other case

This looks like a bug in the device or driver.

Even if this is true, you can only detect it via get_config(). And I
don't think we need to workaround a buggy device.

Thanks

> 
> > 2) the indentation looks wrong
> >
> sure will fix this
> 
> > 3) There's no need for an error here since we can workaround it
> 
> sure, I will change it to log
> 
> >
> >
> 
> 
> > Thanks
> >
> >
>
diff mbox series

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 9179013ac4..f1648fc47d 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -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");
+            }
         }
     }
 }