public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 0/3] vdpa/mlx5: Fix MAC address update via vdpa-tool
@ 2026-01-19  5:53 Cindy Lu
  2026-01-19  5:53 ` [PATCH v3 1/3] vdpa/mlx5: update mlx_features with driver state check Cindy Lu
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Cindy Lu @ 2026-01-19  5:53 UTC (permalink / raw)
  To: lulu, dtatulea, mst, jasowang, netdev, virtualization,
	linux-kernel, kvm

This series hardens the mlx5 vDPA MAC plumbing by ensuring new addresses replace old
entries cleanly, reusing shared update logic to keep flow tables consistent, and only
advertising the MAC feature when the device is not yet DRIVER_OK

Changes in v2
 Factor out the MAC address update logic and reuse it from handle_ctrl_mac().
 Address review comments.
Changes in v3
 rename mlx5_vdpa_change_new_mac to mlx5_vdpa_change_mac
 Address review comments.

Cindy Lu (3):
  vdpa/mlx5: update mlx_features with driver state check
  vdpa/mlx5: reuse common function for MAC address updates
  vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()

 drivers/vdpa/mlx5/net/mlx5_vnet.c | 149 +++++++++++++++++-------------
 1 file changed, 83 insertions(+), 66 deletions(-)

-- 
2.51.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 1/3] vdpa/mlx5: update mlx_features with driver state check
  2026-01-19  5:53 [PATCH v3 0/3] vdpa/mlx5: Fix MAC address update via vdpa-tool Cindy Lu
@ 2026-01-19  5:53 ` Cindy Lu
  2026-01-19  5:53 ` [PATCH v3 2/3] vdpa/mlx5: reuse common function for MAC address updates Cindy Lu
  2026-01-19  5:53 ` [PATCH v3 3/3] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu
  2 siblings, 0 replies; 6+ messages in thread
From: Cindy Lu @ 2026-01-19  5:53 UTC (permalink / raw)
  To: lulu, dtatulea, mst, jasowang, netdev, virtualization,
	linux-kernel, kvm

Add logic in mlx5_vdpa_set_attr() to ensure the VIRTIO_NET_F_MAC
feature bit is properly set only when the device is not yet in
the DRIVER_OK (running) state.

This makes the MAC address visible in the output of:

 vdpa dev config show -jp

when the device is created without an initial MAC address.

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

Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index ddaa1366704b..6e42bae7c9a1 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -4049,7 +4049,7 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
 	struct mlx5_vdpa_dev *mvdev;
 	struct mlx5_vdpa_net *ndev;
 	struct mlx5_core_dev *mdev;
-	int err = -EOPNOTSUPP;
+	int err = 0;
 
 	mvdev = to_mvdev(dev);
 	ndev = to_mlx5_vdpa_ndev(mvdev);
@@ -4057,13 +4057,22 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
 	config = &ndev->config;
 
 	down_write(&ndev->reslock);
-	if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
+
+	if (add_config->mask & BIT_ULL(VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
+		if (!(ndev->mvdev.status & VIRTIO_CONFIG_S_DRIVER_OK)) {
+			ndev->mvdev.mlx_features |= BIT_ULL(VIRTIO_NET_F_MAC);
+		} else {
+			mlx5_vdpa_warn(mvdev, "device running, skip updating MAC\n");
+			err = -EBUSY;
+			goto out;
+		}
 		pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
 		err = mlx5_mpfs_add_mac(pfmdev, config->mac);
 		if (!err)
 			ether_addr_copy(config->mac, add_config->net.mac);
 	}
 
+out:
 	up_write(&ndev->reslock);
 	return err;
 }
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 2/3] vdpa/mlx5: reuse common function for MAC address updates
  2026-01-19  5:53 [PATCH v3 0/3] vdpa/mlx5: Fix MAC address update via vdpa-tool Cindy Lu
  2026-01-19  5:53 ` [PATCH v3 1/3] vdpa/mlx5: update mlx_features with driver state check Cindy Lu
@ 2026-01-19  5:53 ` Cindy Lu
  2026-01-19  6:05   ` Hariprasad Kelam
  2026-01-19  5:53 ` [PATCH v3 3/3] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu
  2 siblings, 1 reply; 6+ messages in thread
From: Cindy Lu @ 2026-01-19  5:53 UTC (permalink / raw)
  To: lulu, dtatulea, mst, jasowang, netdev, virtualization,
	linux-kernel, kvm

Factor out MAC address update logic and reuse it from handle_ctrl_mac().

This ensures that old MAC entries are removed from the MPFS table
before adding a new one and that the forwarding rules are updated
accordingly. If updating the flow table fails, the original MAC and
rules are restored as much as possible to keep the software and
hardware state consistent.

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

Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 131 ++++++++++++++++--------------
 1 file changed, 71 insertions(+), 60 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 6e42bae7c9a1..7a39843de243 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -2125,86 +2125,97 @@ static void teardown_steering(struct mlx5_vdpa_net *ndev)
 	mlx5_destroy_flow_table(ndev->rxft);
 }
 
-static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
+static int mlx5_vdpa_change_mac(struct mlx5_vdpa_net *ndev,
+				struct mlx5_core_dev *pfmdev,
+				const u8 *new_mac)
 {
-	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
-	struct mlx5_control_vq *cvq = &mvdev->cvq;
-	virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
-	struct mlx5_core_dev *pfmdev;
-	size_t read;
-	u8 mac[ETH_ALEN], mac_back[ETH_ALEN];
+	struct mlx5_vdpa_dev *mvdev = &ndev->mvdev;
+	u8 old_mac[ETH_ALEN];
 
-	pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
-	switch (cmd) {
-	case VIRTIO_NET_CTRL_MAC_ADDR_SET:
-		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, (void *)mac, ETH_ALEN);
-		if (read != ETH_ALEN)
-			break;
+	if (is_zero_ether_addr(new_mac))
+		return -EINVAL;
 
-		if (!memcmp(ndev->config.mac, mac, 6)) {
-			status = VIRTIO_NET_OK;
-			break;
+	if (!is_zero_ether_addr(ndev->config.mac)) {
+		if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
+			mlx5_vdpa_warn(mvdev, "failed to delete old MAC %pM from MPFS table\n",
+				       ndev->config.mac);
+			return -EIO;
 		}
+	}
 
-		if (is_zero_ether_addr(mac))
-			break;
+	if (mlx5_mpfs_add_mac(pfmdev, (u8 *)new_mac)) {
+		mlx5_vdpa_warn(mvdev, "failed to insert new MAC %pM into MPFS table\n",
+			       new_mac);
+		return -EIO;
+	}
 
-		if (!is_zero_ether_addr(ndev->config.mac)) {
-			if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
-				mlx5_vdpa_warn(mvdev, "failed to delete old MAC %pM from MPFS table\n",
-					       ndev->config.mac);
-				break;
-			}
-		}
+	/* backup the original mac address so that if failed to add the forward rules
+	 * we could restore it
+	 */
+	memcpy(old_mac, ndev->config.mac, ETH_ALEN);
 
-		if (mlx5_mpfs_add_mac(pfmdev, mac)) {
-			mlx5_vdpa_warn(mvdev, "failed to insert new MAC %pM into MPFS table\n",
-				       mac);
-			break;
-		}
+	memcpy(ndev->config.mac, new_mac, ETH_ALEN);
 
-		/* backup the original mac address so that if failed to add the forward rules
-		 * we could restore it
-		 */
-		memcpy(mac_back, ndev->config.mac, ETH_ALEN);
+	/* Need recreate the flow table entry, so that the packet could forward back
+	 */
+	mac_vlan_del(ndev, old_mac, 0, false);
 
-		memcpy(ndev->config.mac, mac, ETH_ALEN);
+	if (mac_vlan_add(ndev, ndev->config.mac, 0, false)) {
+		mlx5_vdpa_warn(mvdev, "failed to insert forward rules, try to restore\n");
 
-		/* Need recreate the flow table entry, so that the packet could forward back
+		/* Although it hardly run here, we still need double check */
+		if (is_zero_ether_addr(old_mac)) {
+			mlx5_vdpa_warn(mvdev, "restore mac failed: Original MAC is zero\n");
+			return -EIO;
+		}
+
+		/* Try to restore original mac address to MFPS table, and try to restore
+		 * the forward rule entry.
 		 */
-		mac_vlan_del(ndev, mac_back, 0, false);
+		if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
+			mlx5_vdpa_warn(mvdev, "restore mac failed: delete MAC %pM from MPFS table failed\n",
+				       ndev->config.mac);
+		}
 
-		if (mac_vlan_add(ndev, ndev->config.mac, 0, false)) {
-			mlx5_vdpa_warn(mvdev, "failed to insert forward rules, try to restore\n");
+		if (mlx5_mpfs_add_mac(pfmdev, old_mac)) {
+			mlx5_vdpa_warn(mvdev, "restore mac failed: insert old MAC %pM into MPFS table failed\n",
+				       old_mac);
+		}
 
-			/* Although it hardly run here, we still need double check */
-			if (is_zero_ether_addr(mac_back)) {
-				mlx5_vdpa_warn(mvdev, "restore mac failed: Original MAC is zero\n");
-				break;
-			}
+		memcpy(ndev->config.mac, old_mac, ETH_ALEN);
 
-			/* Try to restore original mac address to MFPS table, and try to restore
-			 * the forward rule entry.
-			 */
-			if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
-				mlx5_vdpa_warn(mvdev, "restore mac failed: delete MAC %pM from MPFS table failed\n",
-					       ndev->config.mac);
-			}
+		if (mac_vlan_add(ndev, ndev->config.mac, 0, false))
+			mlx5_vdpa_warn(mvdev, "restore forward rules failed: insert forward rules failed\n");
 
-			if (mlx5_mpfs_add_mac(pfmdev, mac_back)) {
-				mlx5_vdpa_warn(mvdev, "restore mac failed: insert old MAC %pM into MPFS table failed\n",
-					       mac_back);
-			}
+		return -EIO;
+	}
 
-			memcpy(ndev->config.mac, mac_back, ETH_ALEN);
+	return 0;
+}
 
-			if (mac_vlan_add(ndev, ndev->config.mac, 0, false))
-				mlx5_vdpa_warn(mvdev, "restore forward rules failed: insert forward rules failed\n");
+static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
+{
+	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
+	struct mlx5_control_vq *cvq = &mvdev->cvq;
+	virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
+	struct mlx5_core_dev *pfmdev;
+	size_t read;
+	u8 mac[ETH_ALEN];
 
+	pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
+	switch (cmd) {
+	case VIRTIO_NET_CTRL_MAC_ADDR_SET:
+		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov,
+					     (void *)mac, ETH_ALEN);
+		if (read != ETH_ALEN)
 			break;
-		}
 
-		status = VIRTIO_NET_OK;
+		if (!memcmp(ndev->config.mac, mac, 6)) {
+			status = VIRTIO_NET_OK;
+			break;
+		}
+		status = mlx5_vdpa_change_mac(ndev, pfmdev, mac) ? VIRTIO_NET_ERR :
+								       VIRTIO_NET_OK;
 		break;
 
 	default:
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 3/3] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
  2026-01-19  5:53 [PATCH v3 0/3] vdpa/mlx5: Fix MAC address update via vdpa-tool Cindy Lu
  2026-01-19  5:53 ` [PATCH v3 1/3] vdpa/mlx5: update mlx_features with driver state check Cindy Lu
  2026-01-19  5:53 ` [PATCH v3 2/3] vdpa/mlx5: reuse common function for MAC address updates Cindy Lu
@ 2026-01-19  5:53 ` Cindy Lu
  2 siblings, 0 replies; 6+ messages in thread
From: Cindy Lu @ 2026-01-19  5:53 UTC (permalink / raw)
  To: lulu, dtatulea, mst, jasowang, netdev, virtualization,
	linux-kernel, kvm

Improve MAC address handling in mlx5_vdpa_set_attr() to ensure that
old MAC entries are properly removed from the MPFS table before
adding a new one. The new MAC address is then added to both the MPFS
and VLAN tables.

This change fixes an issue where the updated MAC address would not
take effect until QEMU was rebooted.

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

Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
---
 drivers/vdpa/mlx5/net/mlx5_vnet.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 7a39843de243..ed9aa0c2191a 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -4055,17 +4055,15 @@ static void mlx5_vdpa_dev_del(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
 static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *dev,
 			      const struct vdpa_dev_set_config *add_config)
 {
-	struct virtio_net_config *config;
 	struct mlx5_core_dev *pfmdev;
 	struct mlx5_vdpa_dev *mvdev;
 	struct mlx5_vdpa_net *ndev;
 	struct mlx5_core_dev *mdev;
-	int err = 0;
+	int err = -EOPNOTSUPP;
 
 	mvdev = to_mvdev(dev);
 	ndev = to_mlx5_vdpa_ndev(mvdev);
 	mdev = mvdev->mdev;
-	config = &ndev->config;
 
 	down_write(&ndev->reslock);
 
@@ -4078,9 +4076,8 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
 			goto out;
 		}
 		pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
-		err = mlx5_mpfs_add_mac(pfmdev, config->mac);
-		if (!err)
-			ether_addr_copy(config->mac, add_config->net.mac);
+		err = mlx5_vdpa_change_mac(ndev, pfmdev,
+					   (u8 *)add_config->net.mac);
 	}
 
 out:
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 2/3] vdpa/mlx5: reuse common function for MAC address updates
  2026-01-19  5:53 ` [PATCH v3 2/3] vdpa/mlx5: reuse common function for MAC address updates Cindy Lu
@ 2026-01-19  6:05   ` Hariprasad Kelam
  2026-01-26  8:03     ` Cindy Lu
  0 siblings, 1 reply; 6+ messages in thread
From: Hariprasad Kelam @ 2026-01-19  6:05 UTC (permalink / raw)
  To: Cindy Lu; +Cc: dtatulea, mst, jasowang, netdev, virtualization, linux-kernel,
	kvm

On 2026-01-19 at 11:23:52, Cindy Lu (lulu@redhat.com) wrote:
> Factor out MAC address update logic and reuse it from handle_ctrl_mac().
> 
> This ensures that old MAC entries are removed from the MPFS table
> before adding a new one and that the forwarding rules are updated
> accordingly. If updating the flow table fails, the original MAC and
> rules are restored as much as possible to keep the software and
> hardware state consistent.
> 
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> 
> Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
> ---
>  drivers/vdpa/mlx5/net/mlx5_vnet.c | 131 ++++++++++++++++--------------
>  1 file changed, 71 insertions(+), 60 deletions(-)
> 
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 6e42bae7c9a1..7a39843de243 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -2125,86 +2125,97 @@ static void teardown_steering(struct mlx5_vdpa_net *ndev)
>  	mlx5_destroy_flow_table(ndev->rxft);
>  }
>  
> -static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
> +static int mlx5_vdpa_change_mac(struct mlx5_vdpa_net *ndev,
> +				struct mlx5_core_dev *pfmdev,
> +				const u8 *new_mac)
>  {
> -	struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
> -	struct mlx5_control_vq *cvq = &mvdev->cvq;
> -	virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
> -	struct mlx5_core_dev *pfmdev;
> -	size_t read;
> -	u8 mac[ETH_ALEN], mac_back[ETH_ALEN];
> +	struct mlx5_vdpa_dev *mvdev = &ndev->mvdev;
> +	u8 old_mac[ETH_ALEN];
>  
> -	pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
> -	switch (cmd) {
> -	case VIRTIO_NET_CTRL_MAC_ADDR_SET:
> -		read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, (void *)mac, ETH_ALEN);
> -		if (read != ETH_ALEN)
> -			break;
> +	if (is_zero_ether_addr(new_mac))
> +		return -EINVAL;
>  
> -		if (!memcmp(ndev->config.mac, mac, 6)) {
> -			status = VIRTIO_NET_OK;
> -			break;
> +	if (!is_zero_ether_addr(ndev->config.mac)) {
> +		if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
> +			mlx5_vdpa_warn(mvdev, "failed to delete old MAC %pM from MPFS table\n",
> +				       ndev->config.mac);
> +			return -EIO;
>  		}
> +	}
>  
> -		if (is_zero_ether_addr(mac))
> -			break;
> +	if (mlx5_mpfs_add_mac(pfmdev, (u8 *)new_mac)) {
> +		mlx5_vdpa_warn(mvdev, "failed to insert new MAC %pM into MPFS table\n",
> +			       new_mac);
> +		return -EIO;
> +	}
>  
> -		if (!is_zero_ether_addr(ndev->config.mac)) {
> -			if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
> -				mlx5_vdpa_warn(mvdev, "failed to delete old MAC %pM from MPFS table\n",
> -					       ndev->config.mac);
> -				break;
> -			}
> -		}
> +	/* backup the original mac address so that if failed to add the forward rules
> +	 * we could restore it
> +	 */
> +	memcpy(old_mac, ndev->config.mac, ETH_ALEN);
        can we use "ether_addr_copy" instead of memcpy?
Thanks,
Hariprasad k	

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 2/3] vdpa/mlx5: reuse common function for MAC address updates
  2026-01-19  6:05   ` Hariprasad Kelam
@ 2026-01-26  8:03     ` Cindy Lu
  0 siblings, 0 replies; 6+ messages in thread
From: Cindy Lu @ 2026-01-26  8:03 UTC (permalink / raw)
  To: Hariprasad Kelam
  Cc: dtatulea, mst, jasowang, netdev, virtualization, linux-kernel,
	kvm

On Mon, Jan 19, 2026 at 2:05 PM Hariprasad Kelam <hkelam@marvell.com> wrote:
>
> On 2026-01-19 at 11:23:52, Cindy Lu (lulu@redhat.com) wrote:
> > Factor out MAC address update logic and reuse it from handle_ctrl_mac().
> >
> > This ensures that old MAC entries are removed from the MPFS table
> > before adding a new one and that the forwarding rules are updated
> > accordingly. If updating the flow table fails, the original MAC and
> > rules are restored as much as possible to keep the software and
> > hardware state consistent.
> >
> > Signed-off-by: Cindy Lu <lulu@redhat.com>
> >
> > Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
> > ---
> >  drivers/vdpa/mlx5/net/mlx5_vnet.c | 131 ++++++++++++++++--------------
> >  1 file changed, 71 insertions(+), 60 deletions(-)
> >
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index 6e42bae7c9a1..7a39843de243 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -2125,86 +2125,97 @@ static void teardown_steering(struct mlx5_vdpa_net *ndev)
> >       mlx5_destroy_flow_table(ndev->rxft);
> >  }
> >
> > -static virtio_net_ctrl_ack handle_ctrl_mac(struct mlx5_vdpa_dev *mvdev, u8 cmd)
> > +static int mlx5_vdpa_change_mac(struct mlx5_vdpa_net *ndev,
> > +                             struct mlx5_core_dev *pfmdev,
> > +                             const u8 *new_mac)
> >  {
> > -     struct mlx5_vdpa_net *ndev = to_mlx5_vdpa_ndev(mvdev);
> > -     struct mlx5_control_vq *cvq = &mvdev->cvq;
> > -     virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
> > -     struct mlx5_core_dev *pfmdev;
> > -     size_t read;
> > -     u8 mac[ETH_ALEN], mac_back[ETH_ALEN];
> > +     struct mlx5_vdpa_dev *mvdev = &ndev->mvdev;
> > +     u8 old_mac[ETH_ALEN];
> >
> > -     pfmdev = pci_get_drvdata(pci_physfn(mvdev->mdev->pdev));
> > -     switch (cmd) {
> > -     case VIRTIO_NET_CTRL_MAC_ADDR_SET:
> > -             read = vringh_iov_pull_iotlb(&cvq->vring, &cvq->riov, (void *)mac, ETH_ALEN);
> > -             if (read != ETH_ALEN)
> > -                     break;
> > +     if (is_zero_ether_addr(new_mac))
> > +             return -EINVAL;
> >
> > -             if (!memcmp(ndev->config.mac, mac, 6)) {
> > -                     status = VIRTIO_NET_OK;
> > -                     break;
> > +     if (!is_zero_ether_addr(ndev->config.mac)) {
> > +             if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
> > +                     mlx5_vdpa_warn(mvdev, "failed to delete old MAC %pM from MPFS table\n",
> > +                                    ndev->config.mac);
> > +                     return -EIO;
> >               }
> > +     }
> >
> > -             if (is_zero_ether_addr(mac))
> > -                     break;
> > +     if (mlx5_mpfs_add_mac(pfmdev, (u8 *)new_mac)) {
> > +             mlx5_vdpa_warn(mvdev, "failed to insert new MAC %pM into MPFS table\n",
> > +                            new_mac);
> > +             return -EIO;
> > +     }
> >
> > -             if (!is_zero_ether_addr(ndev->config.mac)) {
> > -                     if (mlx5_mpfs_del_mac(pfmdev, ndev->config.mac)) {
> > -                             mlx5_vdpa_warn(mvdev, "failed to delete old MAC %pM from MPFS table\n",
> > -                                            ndev->config.mac);
> > -                             break;
> > -                     }
> > -             }
> > +     /* backup the original mac address so that if failed to add the forward rules
> > +      * we could restore it
> > +      */
> > +     memcpy(old_mac, ndev->config.mac, ETH_ALEN);
>         can we use "ether_addr_copy" instead of memcpy?
> Thanks,
> Hariprasad k
>
Thanks  Hariprasad, will change this
Thanks
cindy


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-01-26  8:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-19  5:53 [PATCH v3 0/3] vdpa/mlx5: Fix MAC address update via vdpa-tool Cindy Lu
2026-01-19  5:53 ` [PATCH v3 1/3] vdpa/mlx5: update mlx_features with driver state check Cindy Lu
2026-01-19  5:53 ` [PATCH v3 2/3] vdpa/mlx5: reuse common function for MAC address updates Cindy Lu
2026-01-19  6:05   ` Hariprasad Kelam
2026-01-26  8:03     ` Cindy Lu
2026-01-19  5:53 ` [PATCH v3 3/3] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox