* [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check
@ 2025-11-05 8:01 Cindy Lu
2025-11-05 8:01 ` [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: Cindy Lu @ 2025-11-05 8:01 UTC (permalink / raw)
To: lulu, dtatulea, mst, jasowang, netdev, virtualization,
linux-kernel
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>
---
drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index 82034efb74fc..e38aa3a335fc 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -4057,6 +4057,12 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
ndev = to_mlx5_vdpa_ndev(mvdev);
mdev = mvdev->mdev;
config = &ndev->config;
+ 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");
+ return err;
+ }
down_write(&ndev->reslock);
if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
--
2.45.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
2025-11-05 8:01 [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check Cindy Lu
@ 2025-11-05 8:01 ` Cindy Lu
2025-11-05 10:12 ` Dragos Tatulea
2025-11-06 4:10 ` Jason Wang
2025-11-05 10:02 ` [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check Dragos Tatulea
2025-11-06 4:07 ` Jason Wang
2 siblings, 2 replies; 10+ messages in thread
From: Cindy Lu @ 2025-11-05 8:01 UTC (permalink / raw)
To: lulu, dtatulea, mst, jasowang, netdev, virtualization,
linux-kernel
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.
Warnings are issued if deleting or adding a MAC entry fails, but
the function continues to execute in order to keep the configuration
as consistent as possible with the hardware state.
This change fixes an issue where the updated MAC address would not
take effect until the qemu was rebooted
Signed-off-by: Cindy Lu <lulu@redhat.com>
---
drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++--
1 file changed, 18 insertions(+), 2 deletions(-)
diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
index e38aa3a335fc..4bc39cb76268 100644
--- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
+++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
@@ -4067,10 +4067,26 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
down_write(&ndev->reslock);
if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
- err = mlx5_mpfs_add_mac(pfmdev, config->mac);
- if (!err)
+ 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);
+ }
+ }
+ err = mlx5_mpfs_add_mac(pfmdev, (u8 *)add_config->net.mac);
+ if (!err) {
+ mac_vlan_del(ndev, config->mac, 0, false);
ether_addr_copy(config->mac, add_config->net.mac);
+ } else {
+ mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to MPFS table\n",
+ (u8 *)add_config->net.mac);
+ up_write(&ndev->reslock);
+ return err;
+ }
}
+ if (mac_vlan_add(ndev, ndev->config.mac, 0, false))
+ mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to vlan table\n",
+ (u8 *)add_config->net.mac);
up_write(&ndev->reslock);
return err;
--
2.45.0
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check
2025-11-05 8:01 [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check Cindy Lu
2025-11-05 8:01 ` [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu
@ 2025-11-05 10:02 ` Dragos Tatulea
2025-11-06 7:32 ` Cindy Lu
2025-11-06 4:07 ` Jason Wang
2 siblings, 1 reply; 10+ messages in thread
From: Dragos Tatulea @ 2025-11-05 10:02 UTC (permalink / raw)
To: Cindy Lu, mst, jasowang, netdev, virtualization, linux-kernel
Thanks for your patches!
On Wed, Nov 05, 2025 at 04:01:41PM +0800, Cindy Lu wrote:
> 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.
>
So when the random MAC address is assigned it is not currently shown?
I don't fully understand the motivation.
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 82034efb74fc..e38aa3a335fc 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -4057,6 +4057,12 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
> ndev = to_mlx5_vdpa_ndev(mvdev);
> mdev = mvdev->mdev;
> config = &ndev->config;
> + 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");
> + return err;
The err is EOPNOTSUPP. Is this the right error?
> + }
>
Why is this block not under the reslock?
Thanks,
Dragos
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
2025-11-05 8:01 ` [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu
@ 2025-11-05 10:12 ` Dragos Tatulea
2025-11-06 7:47 ` Cindy Lu
2025-11-06 4:10 ` Jason Wang
1 sibling, 1 reply; 10+ messages in thread
From: Dragos Tatulea @ 2025-11-05 10:12 UTC (permalink / raw)
To: Cindy Lu, mst, jasowang, netdev, virtualization, linux-kernel
On Wed, Nov 05, 2025 at 04:01:42PM +0800, Cindy Lu wrote:
> 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.
>
> Warnings are issued if deleting or adding a MAC entry fails, but
> the function continues to execute in order to keep the configuration
> as consistent as possible with the hardware state.
>
> This change fixes an issue where the updated MAC address would not
> take effect until the qemu was rebooted
>
Can you remind me how you provision the MAC address throug .set_attr()
instead ofa the CVQ route?
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index e38aa3a335fc..4bc39cb76268 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -4067,10 +4067,26 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
> down_write(&ndev->reslock);
> if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
> - err = mlx5_mpfs_add_mac(pfmdev, config->mac);
> - if (!err)
> + 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);
> + }
> + }
> + err = mlx5_mpfs_add_mac(pfmdev, (u8 *)add_config->net.mac);
> + if (!err) {
> + mac_vlan_del(ndev, config->mac, 0, false);
> ether_addr_copy(config->mac, add_config->net.mac);
> + } else {
> + mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to MPFS table\n",
> + (u8 *)add_config->net.mac);
> + up_write(&ndev->reslock);
> + return err;
> + }
Code reorg suggestion for this block:
err = mlx5_mpfs_add_mac();
if (err) {
warn();
return err;
}
mac_vlan_del();
ether_addr_copy();
> }
> + if (mac_vlan_add(ndev, ndev->config.mac, 0, false))
> + mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to vlan table\n",
> + (u8 *)add_config->net.mac);
>
Have you considered factoring out the MAC changing code from
hanle_ctrl_mac() into a function and using it here? Most of the
operations are the same.
Thanks,
Dragos
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check
2025-11-05 8:01 [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check Cindy Lu
2025-11-05 8:01 ` [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu
2025-11-05 10:02 ` [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check Dragos Tatulea
@ 2025-11-06 4:07 ` Jason Wang
2025-11-06 7:44 ` Cindy Lu
2 siblings, 1 reply; 10+ messages in thread
From: Jason Wang @ 2025-11-06 4:07 UTC (permalink / raw)
To: Cindy Lu; +Cc: dtatulea, mst, netdev, virtualization, linux-kernel
On Wed, Nov 5, 2025 at 4:02 PM Cindy Lu <lulu@redhat.com> wrote:
>
> 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>
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index 82034efb74fc..e38aa3a335fc 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -4057,6 +4057,12 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
> ndev = to_mlx5_vdpa_ndev(mvdev);
> mdev = mvdev->mdev;
> config = &ndev->config;
> + 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");
> + return err;
> + }
I don't get the logic here, mgmt risk themselve for such races or what
would happen if we don't do this?
Thanks
>
> down_write(&ndev->reslock);
> if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> --
> 2.45.0
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
2025-11-05 8:01 ` [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu
2025-11-05 10:12 ` Dragos Tatulea
@ 2025-11-06 4:10 ` Jason Wang
2025-11-06 7:58 ` Cindy Lu
1 sibling, 1 reply; 10+ messages in thread
From: Jason Wang @ 2025-11-06 4:10 UTC (permalink / raw)
To: Cindy Lu; +Cc: dtatulea, mst, netdev, virtualization, linux-kernel
On Wed, Nov 5, 2025 at 4:02 PM Cindy Lu <lulu@redhat.com> wrote:
>
> 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.
>
> Warnings are issued if deleting or adding a MAC entry fails, but
> the function continues to execute in order to keep the configuration
> as consistent as possible with the hardware state.
>
> This change fixes an issue where the updated MAC address would not
> take effect until the qemu was rebooted
>
> Signed-off-by: Cindy Lu <lulu@redhat.com>
> ---
> drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++--
> 1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> index e38aa3a335fc..4bc39cb76268 100644
> --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> @@ -4067,10 +4067,26 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
> down_write(&ndev->reslock);
> if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
> - err = mlx5_mpfs_add_mac(pfmdev, config->mac);
> - if (!err)
> + 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);
Any reason we need to keep trying when we fail here?
> + }
> + }
> + err = mlx5_mpfs_add_mac(pfmdev, (u8 *)add_config->net.mac);
> + if (!err) {
> + mac_vlan_del(ndev, config->mac, 0, false);
> ether_addr_copy(config->mac, add_config->net.mac);
> + } else {
> + mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to MPFS table\n",
> + (u8 *)add_config->net.mac);
> + up_write(&ndev->reslock);
> + return err;
> + }
> }
> + if (mac_vlan_add(ndev, ndev->config.mac, 0, false))
> + mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to vlan table\n",
> + (u8 *)add_config->net.mac);
>
> up_write(&ndev->reslock);
> return err;
> --
> 2.45.0
>
Thanks
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check
2025-11-05 10:02 ` [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check Dragos Tatulea
@ 2025-11-06 7:32 ` Cindy Lu
0 siblings, 0 replies; 10+ messages in thread
From: Cindy Lu @ 2025-11-06 7:32 UTC (permalink / raw)
To: Dragos Tatulea; +Cc: mst, jasowang, netdev, virtualization, linux-kernel
whie
On Wed, Nov 5, 2025 at 6:03 PM Dragos Tatulea <dtatulea@nvidia.com> wrote:
>
> Thanks for your patches!
>
> On Wed, Nov 05, 2025 at 04:01:41PM +0800, Cindy Lu wrote:
> > 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.
> >
> So when the random MAC address is assigned it is not currently shown?
> I don't fully understand the motivation.
>
Yes, when the device was created without a MAC address, the
VIRTIO_NET_F_MAC bit wasn’t set during dev_add, so it wasn’t
displayed. At this time the mac address is 0. I think we can remove
the VIRTIO_NET_F_MAC bit check when showing it.
> > Signed-off-by: Cindy Lu <lulu@redhat.com>
>
> > ---
> > drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index 82034efb74fc..e38aa3a335fc 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -4057,6 +4057,12 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
> > ndev = to_mlx5_vdpa_ndev(mvdev);
> > mdev = mvdev->mdev;
> > config = &ndev->config;
>
> > + 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");
> > + return err;
> The err is EOPNOTSUPP. Is this the right error?
will fix this
>
> > + }
> >
> Why is this block not under the reslock?
>
will fix this
> Thanks,
> Dragos
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check
2025-11-06 4:07 ` Jason Wang
@ 2025-11-06 7:44 ` Cindy Lu
0 siblings, 0 replies; 10+ messages in thread
From: Cindy Lu @ 2025-11-06 7:44 UTC (permalink / raw)
To: Jason Wang; +Cc: dtatulea, mst, netdev, virtualization, linux-kernel
there
On Thu, Nov 6, 2025 at 12:08 PM Jason Wang <jasowang@redhat.com> wrote:
>
> On Wed, Nov 5, 2025 at 4:02 PM Cindy Lu <lulu@redhat.com> wrote:
> >
> > 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>
> > ---
> > drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++
> > 1 file changed, 6 insertions(+)
> >
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index 82034efb74fc..e38aa3a335fc 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -4057,6 +4057,12 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
> > ndev = to_mlx5_vdpa_ndev(mvdev);
> > mdev = mvdev->mdev;
> > config = &ndev->config;
> > + 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");
> > + return err;
> > + }
>
> I don't get the logic here, mgmt risk themselve for such races or what
> would happen if we don't do this?
>
> Thanks
>
sure I can move this to the reslock.
I added the VIRTIO_NET_F_MAC bit because when the device is created
without a MAC address, this bit is missing in dev_add. Since we now
configure the MAC address, we need to also add this bit. I now coding
in QEMU to use this bit to identify if the mac address provided by
host.
there is no vdpa_config_ops for device to change the device_features,
So I add it here
Thanks
cindy
> >
> > down_write(&ndev->reslock);
> > if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> > --
> > 2.45.0
> >
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
2025-11-05 10:12 ` Dragos Tatulea
@ 2025-11-06 7:47 ` Cindy Lu
0 siblings, 0 replies; 10+ messages in thread
From: Cindy Lu @ 2025-11-06 7:47 UTC (permalink / raw)
To: Dragos Tatulea; +Cc: mst, jasowang, netdev, virtualization, linux-kernel
On Wed, Nov 5, 2025 at 6:13 PM Dragos Tatulea <dtatulea@nvidia.com> wrote:
>
> On Wed, Nov 05, 2025 at 04:01:42PM +0800, Cindy Lu wrote:
> > 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.
> >
> > Warnings are issued if deleting or adding a MAC entry fails, but
> > the function continues to execute in order to keep the configuration
> > as consistent as possible with the hardware state.
> >
> > This change fixes an issue where the updated MAC address would not
> > take effect until the qemu was rebooted
> >
> Can you remind me how you provision the MAC address throug .set_attr()
> instead ofa the CVQ route?
>
this mac address is set from vdpa tool,such as
vdpa dev set name vdpa0 mac 00:11:22:33:44:01
> > Signed-off-by: Cindy Lu <lulu@redhat.com>
> > ---
> > drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++--
> > 1 file changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index e38aa3a335fc..4bc39cb76268 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -4067,10 +4067,26 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
> > down_write(&ndev->reslock);
> > if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> > pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
> > - err = mlx5_mpfs_add_mac(pfmdev, config->mac);
> > - if (!err)
> > + 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);
> > + }
> > + }
> > + err = mlx5_mpfs_add_mac(pfmdev, (u8 *)add_config->net.mac);
> > + if (!err) {
> > + mac_vlan_del(ndev, config->mac, 0, false);
> > ether_addr_copy(config->mac, add_config->net.mac);
> > + } else {
> > + mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to MPFS table\n",
> > + (u8 *)add_config->net.mac);
> > + up_write(&ndev->reslock);
> > + return err;
> > + }
> Code reorg suggestion for this block:
> err = mlx5_mpfs_add_mac();
> if (err) {
> warn();
> return err;
> }
>
> mac_vlan_del();
> ether_addr_copy();
>
> > }
> > + if (mac_vlan_add(ndev, ndev->config.mac, 0, false))
> > + mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to vlan table\n",
> > + (u8 *)add_config->net.mac);
> >
> Have you considered factoring out the MAC changing code from
> hanle_ctrl_mac() into a function and using it here? Most of the
> operations are the same.
>
>
Thanks, that’s a good point. I’ll update the code.
> Thanks,
> Dragos
>
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
2025-11-06 4:10 ` Jason Wang
@ 2025-11-06 7:58 ` Cindy Lu
0 siblings, 0 replies; 10+ messages in thread
From: Cindy Lu @ 2025-11-06 7:58 UTC (permalink / raw)
To: Jason Wang; +Cc: dtatulea, mst, netdev, virtualization, linux-kernel
On Thu, Nov 6, 2025 at 12:11 PM Jason Wang <jasowang@redhat.com> wrote:
>
> On Wed, Nov 5, 2025 at 4:02 PM Cindy Lu <lulu@redhat.com> wrote:
> >
> > 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.
> >
> > Warnings are issued if deleting or adding a MAC entry fails, but
> > the function continues to execute in order to keep the configuration
> > as consistent as possible with the hardware state.
> >
> > This change fixes an issue where the updated MAC address would not
> > take effect until the qemu was rebooted
> >
> > Signed-off-by: Cindy Lu <lulu@redhat.com>
> > ---
> > drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++--
> > 1 file changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/vdpa/mlx5/net/mlx5_vnet.c b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > index e38aa3a335fc..4bc39cb76268 100644
> > --- a/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > +++ b/drivers/vdpa/mlx5/net/mlx5_vnet.c
> > @@ -4067,10 +4067,26 @@ static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device *
> > down_write(&ndev->reslock);
> > if (add_config->mask & (1 << VDPA_ATTR_DEV_NET_CFG_MACADDR)) {
> > pfmdev = pci_get_drvdata(pci_physfn(mdev->pdev));
> > - err = mlx5_mpfs_add_mac(pfmdev, config->mac);
> > - if (!err)
> > + 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);
>
> Any reason we need to keep trying when we fail here?
>
sure will change this. i will reuse the code in hanle_ctrl_mac
> > + }
> > + }
> > + err = mlx5_mpfs_add_mac(pfmdev, (u8 *)add_config->net.mac);
> > + if (!err) {
> > + mac_vlan_del(ndev, config->mac, 0, false);
> > ether_addr_copy(config->mac, add_config->net.mac);
> > + } else {
> > + mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to MPFS table\n",
> > + (u8 *)add_config->net.mac);
> > + up_write(&ndev->reslock);
> > + return err;
> > + }
> > }
> > + if (mac_vlan_add(ndev, ndev->config.mac, 0, false))
> > + mlx5_vdpa_warn(mvdev,"failed to add new MAC %pM to vlan table\n",
> > + (u8 *)add_config->net.mac);
> >
> > up_write(&ndev->reslock);
> > return err;
> > --
> > 2.45.0
> >
>
> Thanks
>
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2025-11-06 7:59 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-05 8:01 [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check Cindy Lu
2025-11-05 8:01 ` [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr() Cindy Lu
2025-11-05 10:12 ` Dragos Tatulea
2025-11-06 7:47 ` Cindy Lu
2025-11-06 4:10 ` Jason Wang
2025-11-06 7:58 ` Cindy Lu
2025-11-05 10:02 ` [PATCH 1/2] vdpa/mlx5: update mlx_features with driver state check Dragos Tatulea
2025-11-06 7:32 ` Cindy Lu
2025-11-06 4:07 ` Jason Wang
2025-11-06 7:44 ` Cindy Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).