diff mbox series

[2/3] virtio_net: Add the check for vdpa mac address

Message ID 20240806005814.51651-2-lulu@redhat.com (mailing list archive)
State New, archived
Headers show
Series [1/3] virtio_net: Add the check for vdpa's mac address | expand

Commit Message

Cindy Lu Aug. 6, 2024, 12:58 a.m. UTC
When using a VDPA device, this is another acceptable situations
The hardware MAC address is not 0, and the MAC address in the QEMU command line is 0.
This is also acceptable

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

Comments

Jason Wang Aug. 6, 2024, 3:08 a.m. UTC | #1
On Tue, Aug 6, 2024 at 8:58 AM Cindy Lu <lulu@redhat.com> wrote:
>
> When using a VDPA device, this is another acceptable situations
> The hardware MAC address is not 0, and the MAC address in the QEMU command line is 0.
> This is also acceptable
>
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
>  hw/net/virtio-net.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
> index 7f51bd0dd3..c144ae2e78 100644
> --- a/hw/net/virtio-net.c
> +++ b/hw/net/virtio-net.c
> @@ -3592,11 +3592,22 @@ static bool virtio_net_check_vdpa_mac(NetClientState *nc, VirtIONet *n, MACAddr
>       * 1.The hardware MAC address is the same as the QEMU command line MAC
>       *   address, and both of them are not 0.
>       */
> -
> +       /*
> +     * 2.The hardware MAC address is not 0,
> +     *  and the MAC address in the QEMU command line is 0.
> +     *  In this situation, the hardware MAC address will overwrite
> +     *  the QEMU command line address.

This seems to break libvirt assumption?

Adding Jonathon.

> +     */
>         if (memcmp(&hwcfg.mac, &zero, sizeof(MACAddr)) != 0) {
>                 if ((memcmp(&hwcfg.mac, cmdline_mac, sizeof(MACAddr)) == 0)) {
>                         return true;
>                 }
> +               if (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0) {
> +                       /* overwrite the mac address with hardware address*/
> +                       memcpy(&n->mac[0], &hwcfg.mac, sizeof(n->mac));
> +                       memcpy(&n->nic_conf.macaddr, &hwcfg.mac, sizeof(n->mac));
> +                       return true;
> +               }
>         }
>         error_setg(errp, "vDPA device's mac != the mac address from qemu cmdline"
>                          "Please check the the vdpa device's setting.");
> --
> 2.45.0
>

Thanks
diff mbox series

Patch

diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c
index 7f51bd0dd3..c144ae2e78 100644
--- a/hw/net/virtio-net.c
+++ b/hw/net/virtio-net.c
@@ -3592,11 +3592,22 @@  static bool virtio_net_check_vdpa_mac(NetClientState *nc, VirtIONet *n, MACAddr
      * 1.The hardware MAC address is the same as the QEMU command line MAC
      *   address, and both of them are not 0.
      */
-
+	/*
+     * 2.The hardware MAC address is not 0,
+     *  and the MAC address in the QEMU command line is 0.
+     *  In this situation, the hardware MAC address will overwrite
+     *  the QEMU command line address.
+     */
 	if (memcmp(&hwcfg.mac, &zero, sizeof(MACAddr)) != 0) {
 		if ((memcmp(&hwcfg.mac, cmdline_mac, sizeof(MACAddr)) == 0)) {
 			return true;
 		}
+		if (memcmp(cmdline_mac, &zero, sizeof(MACAddr)) == 0) {
+			/* overwrite the mac address with hardware address*/
+			memcpy(&n->mac[0], &hwcfg.mac, sizeof(n->mac));
+			memcpy(&n->nic_conf.macaddr, &hwcfg.mac, sizeof(n->mac));
+			return true;
+		}
 	}
 	error_setg(errp, "vDPA device's mac != the mac address from qemu cmdline"
 			 "Please check the the vdpa device's setting.");