vdpa/mlx5: update mlx_features with driver state check
Subsystems (4)
PATCH 1/2 vdpa/mlx5: update mlx_features with driver state check
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.
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++ 1 file changed, 6 insertions(+)
drivers/vdpa/mlx5/net/mlx5_vnet.c +6 -0
@@ -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 )) {
Signature · 1 line
2.45.0
PATCH 2/2 vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
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
--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
drivers/vdpa/mlx5/net/mlx5_vnet.c +18 -2
@@ -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;
Signature · 1 line
2.45.0
Dragos Tatulea
maintainerRe: [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
Quoted 5 lines · Cindy Lu
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.
Quoted 7 lines
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?
Quoted 21 lines
Signed-off-by Cindy Lu <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +6
-2@@ -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); + } + }
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4085
Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +9
-0+ 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();
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4090
Quoted 5 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +3
-0} +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
Re: [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
Quoted 11 lines · Dragos Tatulea
Quoted 9 lines · Cindy Lu
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.
Quoted 6 lines
Quoted 3 lines
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
Quoted 41 lines
Quoted 21 lines
Signed-off-by Cindy Lu <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +6
-2@@ -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); + } + }drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4085
Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +9
-0+ 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();
Quoted 10 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4090
Quoted 5 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +3
-0} +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.
Quoted 3 lines
Thanks,
Dragos
Re: [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
In reply to Cindy LuQuoted 23 lines · Cindy Lu
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 <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4073
Quoted 9 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +4
-2@@ -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?
Quoted 20 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +14
-1+ } + } + 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; --
Quoted 2 lines
2.45.0
Thanks
Re: [PATCH 2/2] vdpa/mlx5: update MAC address handling in mlx5_vdpa_set_attr()
Quoted 20 lines · Jason Wang
Quoted 18 lines · Cindy Lu
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 <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-)
Quoted 17 lines
Quoted 5 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4073
Quoted 9 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +4
-2@@ -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
Quoted 25 lines
Quoted 20 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +14
-1+ } + } + 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; --Quoted 2 lines
2.45.0
Thanks
Dragos Tatulea
maintainerThanks for your patches!
Quoted 10 lines · Cindy Lu
Add logic in
mlx5_vdpa_set_attr()to ensure theVIRTIO_NET_F_MACfeature bit is properly set only when the device is not yet in theDRIVER_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.
Quoted 11 lines
Signed-off-by Cindy Lu <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4065
Quoted 9 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0@@ -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?
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4066
Quoted 2 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-0+ }
Why is this block not under the reslock?
Thanks,
Dragos
whie
Quoted 8 lines · Dragos Tatulea
Thanks for your patches!
Quoted 4 lines · Cindy Lu
Add logic in
mlx5_vdpa_set_attr()to ensure theVIRTIO_NET_F_MACfeature bit is properly set only when the device is not yet in theDRIVER_OK(running) state.
Quoted 9 lines
Quoted 6 lines
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.
Quoted 15 lines
Quoted 14 lines
Signed-off-by Cindy Lu <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0@@ -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;
Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4064
Quoted 5 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +5
-0+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
Quoted 5 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4066
Quoted 3 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +1
-0+ }Why is this block not under the reslock?
will fix this
Quoted 3 lines
Thanks,
Dragos
Quoted 21 lines · Cindy Lu
Add logic in
mlx5_vdpa_set_attr()to ensure theVIRTIO_NET_F_MACfeature bit is properly set only when the device is not yet in theDRIVER_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 <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0
drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4065
Quoted 9 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +6
-0@@ -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
Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-1down_write (&ndev->reslock);if (add_config->mask & (1 <<VDPA_ATTR_DEV_NET_CFG_MACADDR )) { --2.45.0
there
Quoted 36 lines · Jason Wang
Quoted 21 lines · Cindy Lu
Add logic in
mlx5_vdpa_set_attr()to ensure theVIRTIO_NET_F_MACfeature bit is properly set only when the device is not yet in theDRIVER_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 <[email protected]>--- drivers/vdpa/mlx5/net/mlx5_vnet.c | 6 ++++++ 1 file changed, 6 insertions(+)drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-0drivers/vdpa/mlx5/net/mlx5_vnet.c static int mlx5_vdpa_set_attr(struct vdpa_mgmt_dev *v_mdev, struct vdpa_device * · line 4065
Quoted 9 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +6
-0@@ -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?
Quoted 2 lines
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
Quoted 7 lines
Quoted 6 lines
drivers/vdpa/mlx5/net/mlx5_vnet.c +0
-1down_write (&ndev->reslock);if (add_config->mask & (1 <<VDPA_ATTR_DEV_NET_CFG_MACADDR )) { --2.45.0