[PATCH v5 4/4] virtio_net: Add third acceptable configuration for MAC setup.

Cindy Lu posted 4 patches 10 months, 2 weeks ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>
There is a newer version of this series
[PATCH v5 4/4] virtio_net: Add third acceptable configuration for MAC setup.
Posted by Cindy Lu 10 months, 2 weeks ago
For VDPA devices, Allow configurations where both the hardware MAC address
and QEMU command line MAC address are zero.

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

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 1fd0403d5d..d1f44850d5 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3782,6 +3782,19 @@ static bool virtio_net_check_vdpa_mac(NetClientState *nc, VirtIONet *n,
             return true;
         }
     }
+    /*
+     * 3.The hardware MAC address is 0,
+     *  and the MAC address in the QEMU command line is also 0.
+     *  In this situation, qemu will generate a random mac address
+     *  QEMU will try to use CVQ/set_config to set this address to
+     *  device
+     */
+    if ((memcmp(&hwcfg.mac, &zero, sizeof(MACAddr)) == 0) &&
+        (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0)) {
+        memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
+
+        return true;
+    }
 
     error_setg(errp,
                "vDPA device's mac %02x:%02x:%02x:%02x:%02x:%02x"
-- 
2.45.0
Re: [PATCH v5 4/4] virtio_net: Add third acceptable configuration for MAC setup.
Posted by Michael S. Tsirkin 10 months, 1 week ago
On Wed, Mar 26, 2025 at 09:19:33PM +0800, Cindy Lu wrote:
> For VDPA devices, Allow configurations where both the hardware MAC address
> and QEMU command line MAC address are zero.
> 
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
>  hw/net/virtio-net.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 1fd0403d5d..d1f44850d5 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -3782,6 +3782,19 @@ static bool virtio_net_check_vdpa_mac(NetClientState *nc, VirtIONet *n,
>              return true;
>          }
>      }
> +    /*
> +     * 3.The hardware MAC address is 0,
> +     *  and the MAC address in the QEMU command line is also 0.
> +     *  In this situation, qemu will generate a random mac address
> +     *  QEMU will try to use CVQ/set_config to set this address to
> +     *  device

same comments. end sentences with a period.

> +     */
> +    if ((memcmp(&hwcfg.mac, &zero, sizeof(MACAddr)) == 0) &&
> +        (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0)) {
> +        memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
> +
> +        return true;
> +    }
>  
>      error_setg(errp,
>                 "vDPA device's mac %02x:%02x:%02x:%02x:%02x:%02x"
> -- 
> 2.45.0
Re: [PATCH v5 4/4] virtio_net: Add third acceptable configuration for MAC setup.
Posted by Cindy Lu 10 months, 1 week ago
On Thu, Apr 3, 2025 at 12:36 AM Michael S. Tsirkin <mst@redhat.com> wrote:
>
> On Wed, Mar 26, 2025 at 09:19:33PM +0800, Cindy Lu wrote:
> > For VDPA devices, Allow configurations where both the hardware MAC address
> > and QEMU command line MAC address are zero.
> >
> > Signed-off-by: Cindy Lu <lulu@redhat.com>
> > ---
> >  hw/net/virtio-net.c | 13 +++++++++++++
> >  1 file changed, 13 insertions(+)
> >
> > diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> > index 1fd0403d5d..d1f44850d5 100644
> > --- a/hw/net/virtio-net.c
> > +++ b/hw/net/virtio-net.c
> > @@ -3782,6 +3782,19 @@ static bool virtio_net_check_vdpa_mac(NetClientState *nc, VirtIONet *n,
> >              return true;
> >          }
> >      }
> > +    /*
> > +     * 3.The hardware MAC address is 0,
> > +     *  and the MAC address in the QEMU command line is also 0.
> > +     *  In this situation, qemu will generate a random mac address
> > +     *  QEMU will try to use CVQ/set_config to set this address to
> > +     *  device
>
> same comments. end sentences with a period.
>
sure. will fix this
Thanks
cindy
> > +     */
> > +    if ((memcmp(&hwcfg.mac, &zero, sizeof(MACAddr)) == 0) &&
> > +        (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0)) {
> > +        memcpy(&n->mac[0], &n->nic_conf.macaddr, sizeof(n->mac));
> > +
> > +        return true;
> > +    }
> >
> >      error_setg(errp,
> >                 "vDPA device's mac %02x:%02x:%02x:%02x:%02x:%02x"
> > --
> > 2.45.0
>