ethdev: fix one MAC address occupies two index in mac addrs
PATCH 1/1 ethdev: fix one MAC address occupies two index in mac addrs
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1) mac_addr add 0 00:18:2D:00:00:90
2) mac_addr add 0 00:18:2D:00:00:91
3) mac_addr add 0 00:18:2D:00:00:92
4) mac_addr set 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 4
00:18:2D:00:00:91
00:18:2D:00:00:90
00:18:2D:00:00:91
00:18:2D:00:00:92
This is due to the reason that if the address has been added as a non-default MAC address by rte_eth_dev_mac_addr_add API, it doesn't remove from dev->data->mac_addrs[] when set default MAC address with the same address.
--- lib/ethdev/rte_ethdev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
lib/ethdev/rte_ethdev.c +15 -0
@@ -4360,6 +4360,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4381,6 +4382,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (ret <0 )return ret; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* remove address in NIC data structure */ +rte_ether_addr_copy (&null_mac_addr, + &dev->data->mac_addrs[index]); +/* reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } +/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);
Signature · 1 line
2.33.0
Quoted 52 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 4
00:18:2D:00:00:91
00:18:2D:00:00:90
00:18:2D:00:00:91
00:18:2D:00:00:92This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>--- lib/ethdev/rte_ethdev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +8
-0@@ -4360,6 +4360,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4381,6 +4382,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (ret <0 )return ret; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) {
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4401
Quoted 10 lines
lib/ethdev/rte_ethdev.c +7
-0+/* remove address in NIC data structure */ +rte_ether_addr_copy (&null_mac_addr, + &dev->data->mac_addrs[index]); +/* reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } +/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);
If I change default MAC to something else later, should the old default MAC be returned to some specific pools? I guess it is hard to do. If the change is accepted, the behaviour must be documented in rte_eth_dev_default_mac_addr_set() description.
Quoted 57 lines · Andrew Rybchenko
Quoted 56 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 4
00:18:2D:00:00:91
00:18:2D:00:00:90
00:18:2D:00:00:91
00:18:2D:00:00:92This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>--- lib/ethdev/rte_ethdev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +13
-0@@ -4360,6 +4360,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4381,6 +4382,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (ret <0 )return ret; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* remove address in NIC data structure */ +rte_ether_addr_copy (&null_mac_addr, + &dev->data->mac_addrs[index]); +/* reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ;
Quoted 8 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4401
Quoted 6 lines
lib/ethdev/rte_ethdev.c +2
-0+ } +/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);If I change default MAC to something else later, should the old default MAC be returned to some specific pools? I guess it is
Since the old default MAC address is invalid, which has been removed from hardware.
This MAC address does not need to be added to some specific pools, and occupies
one position in mac addrs.
Quoted 3 lines
hard to do. If the change is accepted, the behaviour must be documented in
rte_eth_dev_default_mac_addr_set()description. .
I think it's not necessary. Because old default MAC is no longer valid if we modify
default MAC with a new MAC address. This is a definition of rte_eth_dev_default_mac_addr_set().
The current modification does not change the definition of the interface.
Quoted 80 lines · Huisong Li
Quoted 57 lines · Andrew Rybchenko
Quoted 56 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 4 00:18:2D:00:00:91
00:18:2D:00:00:90
00:18:2D:00:00:91
00:18:2D:00:00:92This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove
from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +0
-0@@ -4360,6 +4360,7 @@ int
rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
{
structrte_eth_dev*dev;
+ int index;
int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);lib/ethdev/rte_ethdev.c +0
-0@@ -4381,6 +4382,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);
+ if (index > 0) {
+ /* remove address in NIC data structure */
+ rte_ether_addr_copy(&null_mac_addr,
+ &dev->data->mac_addrs[index]);
+ /* reset pool bitmap */Quoted 8 lines
Quoted 6 lines
+ dev->data->mac_pool_sel[index] = 0;
+ }
+
/* Update default address in NIC data structure */rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);If I change default MAC to something else later, should the old default MAC be returned to some specific pools? I guess it is
Since the old default MAC address is invalid, which has been removed from hardware.
This MAC address does not need to be added to some specific pools, and occupies
one position in mac addrs.
Quoted 3 lines
hard to do. If the change is accepted, the behaviour must be documented in
rte_eth_dev_default_mac_addr_set()description. .
Quoted 7 lines
I think it's not necessary. Because old default MAC is no longer valid if we modify
default MAC with a new MAC address. This is a definition of
rte_eth_dev_default_mac_addr_set().The current modification does not change the definition of the interface.
Not sure that I understand:
set default MAC-A
add MAC-B to pool 1
set default MAC-B
set default MAC-C
since I've not removed MAC-B from pool 1, I'd expect it to be there.
Quoted 87 lines · Andrew Rybchenko
Quoted 77 lines · Huisong Li
Quoted 57 lines · Andrew Rybchenko
Quoted 56 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 4
00:18:2D:00:00:91
00:18:2D:00:00:90
00:18:2D:00:00:91
00:18:2D:00:00:92This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove
from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>--- lib/ethdev/rte_ethdev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +11
-0@@ -4360,6 +4360,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4381,6 +4382,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret; + /* + * If the address has been added as a non-default MAC address by + * rte_eth_dev_mac_addr_add API, it should be removed from + * dev->data->mac_addrs[]. + */ + index = eth_dev_get_mac_addr_index(port_id, addr); + if (index > 0) { + /* remove address in NIC data structure */ + rte_ether_addr_copy(&null_mac_addr, + &dev->data->mac_addrs[index]); + /* reset pool bitmap */Quoted 8 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4400
Quoted 6 lines
lib/ethdev/rte_ethdev.c +3
-0+ dev->data->mac_pool_sel[index] = 0; + } + /* Update default address in NIC data structure */ rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);If I change default MAC to something else later, should the old default MAC be returned to some specific pools? I guess it is
Since the old default MAC address is invalid, which has been removed from hardware.
This MAC address does not need to be added to some specific pools, and occupies
one position in mac addrs.
Quoted 3 lines
hard to do. If the change is accepted, the behaviour must be documented in
rte_eth_dev_default_mac_addr_set()description. .Quoted 7 lines
I think it's not necessary. Because old default MAC is no longer valid if we modify
default MAC with a new MAC address. This is a definition of
rte_eth_dev_default_mac_addr_set().The current modification does not change the definition of the interface.
Not sure that I understand:
Quoted 8 lines
set default MAC-A
add MAC-B to pool 1
set default MAC-B
set default MAC-Csince I've not removed MAC-B from pool 1, I'd expect it to be there.
.
Yes. You are right.
But MAC-B is removed from hardware after executing "set default MAC-C" cmd, and
new default MAC-C takes effect.
View from interface rte_eth_dev_mac_addr_remove(), if one MAC address is removed,
the API removes the MAC from dev->data->mac_addrs[] and reset "mac_pool_sel"(that is,
all pools do not have the MAC address.).
This also means that above MAC-B should not exist in any of the pools and
in dev->data->mac_addrs[] after executing "set default MAC-C" cmd.
22/09/2021 05:36, Min Hu (Connor):
Quoted 13 lines
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 4
00:18:2D:00:00:91
00:18:2D:00:00:90
00:18:2D:00:00:91
00:18:2D:00:00:92
Please describe with words.
Reading similar MAC addresses is not a fun game.
Quoted 10 lines
This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>
Hi, Thomas,
Quoted 15 lines · Thomas Monjalon
22/09/2021 05:36, Min Hu (Connor):
Quoted 13 lines
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 4
00:18:2D:00:00:91
00:18:2D:00:00:90
00:18:2D:00:00:91
00:18:2D:00:00:92
Quoted 2 lines
Please describe with words.
Reading similar MAC addresses is not a fun game.
I do not catch you, could you please be
more detailed, thanks.
Quoted 16 lines
Quoted 11 lines
This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>.
08/10/2021 09:02, Min Hu (Connor):
Quoted 18 lines
Hi, Thomas,
Quoted 15 lines · Thomas Monjalon
22/09/2021 05:36, Min Hu (Connor):
Quoted 13 lines
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 4
00:18:2D:00:00:91
00:18:2D:00:00:90
00:18:2D:00:00:91
00:18:2D:00:00:92
Quoted 5 lines
Quoted 2 lines
Please describe with words.
Reading similar MAC addresses is not a fun game.I do not catch you, could you please be
more detailed, thanks.
Me too, I don't catch you.
Please explain the problem in the commit log
so we can understand without the example.
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>
Hi, Thomas,
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by rte_eth_dev_default_mac_addr_set() API. However, If the new default MAC address has been added as a non-default MAC address by rte_eth_dev_mac_addr_add() API, the rte_eth_dev_default_mac_addr_set() API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[]. This patch adds the logic of removing MAC addresses for this scenario.
Is that will be more clear? Hope for your reply
Quoted 44 lines · Thomas Monjalon
08/10/2021 09:02, Min Hu (Connor):
Quoted 18 lines
Hi, Thomas,
Quoted 15 lines · Thomas Monjalon
22/09/2021 05:36, Min Hu (Connor):
Quoted 13 lines
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 400:18:2D:00:00:91 00:18:2D:00:00:90 00:18:2D:00:00:91 00:18:2D:00:00:92Quoted 5 lines
Quoted 2 lines
Please describe with words.
Reading similar MAC addresses is not a fun game.I do not catch you, could you please be
more detailed, thanks.Me too, I don't catch you.
Please explain the problem in the commit log
so we can understand without the example.Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>.
09/10/2021 11:53, Min Hu (Connor):
Quoted 14 lines
Hi, Thomas,
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify
the default MAC address byrte_eth_dev_default_mac_addr_set()API. However, If the new default
MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[].
As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].
This patch adds the logic of removing MAC addresses for this scenario.
Quoted 1 line
Is that will be more clear? Hope for your reply
Yes, that's the explanation I was expecting. Thank you!
Quoted 40 lines · Thomas Monjalon
Quoted 39 lines
08/10/2021 09:02, Min Hu (Connor):
Quoted 18 lines
Hi, Thomas,
Quoted 15 lines · Thomas Monjalon
22/09/2021 05:36, Min Hu (Connor):
Quoted 13 lines
From: Huisong Li <[email protected]>
Use the testpmd to perform the following operations:
1)mac_addradd 0 00:18:2D:00:00:90
2)mac_addradd 0 00:18:2D:00:00:91
3)mac_addradd 0 00:18:2D:00:00:92
4)mac_addrset 0 00:18:2D:00:00:91
5) show port 0 macs
Number of MAC address added: 400:18:2D:00:00:91 00:18:2D:00:00:90 00:18:2D:00:00:91 00:18:2D:00:00:92Quoted 5 lines
Quoted 2 lines
Please describe with words.
Reading similar MAC addresses is not a fun game.I do not catch you, could you please be
more detailed, thanks.Me too, I don't catch you.
Please explain the problem in the commit log
so we can understand without the example.Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
This is due to the reason that if the address has been added as a non-default MAC address by
rte_eth_dev_mac_addr_addAPI, it doesn't remove from dev->data->mac_addrs[] when set default MAC address with the same address.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>
PATCH v2 1/1 ethdev: fix one MAC address occupies two index in mac addrs
In reply to Min Hu (Connor)From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by rte_eth_dev_default_mac_addr_set() API. However, If the new default MAC address has been added as a non-default MAC address by rte_eth_dev_mac_addr_add() API, the rte_eth_dev_default_mac_addr_set() API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].
This patch adds the logic of removing MAC addresses for this scenario.
---
v2:
* fixed commit log.
--- lib/ethdev/rte_ethdev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
lib/ethdev/rte_ethdev.c +15 -0
@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (ret <0 )return ret; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* remove address in NIC data structure */ +rte_ether_addr_copy (&null_mac_addr, + &dev->data->mac_addrs[index]); +/* reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } +/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);
Signature · 1 line
2.33.0
11/10/2021 11:28, Min Hu (Connor):
Quoted 18 lines
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4369
Quoted 5 lines
lib/ethdev/rte_ethdev.c +5
-0+/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/
This is the definition of mac_addrs:
struct rte_ether_addr *mac_addrs;
/**< Device Ethernet link address.
* @see rte_eth_dev_release_port()
*/I feel we need to explain there can be multiple addresses, the first one being the default.
Another comment,
If we remove the duplicate, we may have to copy to previous default one to avoid completely deleting the previous default address. Not sure what should be the behaviour.
Quoted 26 lines · Thomas Monjalon
11/10/2021 11:28, Min Hu (Connor):
Quoted 18 lines
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4369
Quoted 5 lines
lib/ethdev/rte_ethdev.c +5
-0+/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ This is the definition of
mac_addrs:
Quoted 7 lines
struct rte_ether_addr *mac_addrs; /**< Device Ethernet link address. * @see rte_eth_dev_release_port() */I feel we need to explain there can be multiple addresses, the first one being the default.
Do you mean that the problem mentioned in this patch is not a problem?
Should we accept this scenario?
Quoted 4 lines
Another comment,
If we remove the duplicate, we may have to copy to previous default one to avoid completely deleting the previous default address.
That's not necessary.
Because the previous default address has been removed from hardware.
After the default MAC address is modified, the previous default one is invalid.
Quoted 4 lines
Not sure what should be the behaviour.
.
12/10/2021 04:58, lihuisong (C):
Quoted 32 lines · Thomas Monjalon
Quoted 31 lines
11/10/2021 11:28, Min Hu (Connor):
Quoted 18 lines
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4369
Quoted 5 lines
lib/ethdev/rte_ethdev.c +5
-0+/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ This is the definition of
mac_addrs:struct rte_ether_addr *mac_addrs; /**< Device Ethernet link address. * @see rte_eth_dev_release_port() */
Quoted 4 lines
Quoted 2 lines
I feel we need to explain there can be multiple addresses, the first one being the default.
Do you mean that the problem mentioned in this patch is not a problem?
It is not a problem if it is expected,
but nothing is defined.
Quoted 1 line
Should we accept this scenario?
We need to decide what is the correct behaviour.
I see pros and cons on both sides.
Quoted 10 lines
Quoted 3 lines
Another comment,
If we remove the duplicate, we may have to copy to previous default one to avoid completely deleting the previous default address.That's not necessary.
Because the previous default address has been removed from hardware.
After the default MAC address is modified, the previous default one is invalid.
No you don't get it.
With the current behaviour, the app could keep all the MAC addresses, and copy one as the default while keeping it in the rest of the list. You are suggesting a different behaviour where there is no duplicate.
Quoted 1 line
Quoted 1 line
Not sure what should be the behaviour.
Quoted 35 lines · Thomas Monjalon
12/10/2021 04:58, lihuisong (C):
Quoted 34 lines · Thomas Monjalon
Quoted 33 lines
11/10/2021 11:28, Min Hu (Connor):
Quoted 18 lines
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4369
Quoted 5 lines
lib/ethdev/rte_ethdev.c +5
-0+/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ This is the definition of
mac_addrs:struct rte_ether_addr *mac_addrs; /**< Device Ethernet link address. * @see rte_eth_dev_release_port() */I feel we need to explain there can be multiple addresses, the first one being the default.
Quoted 7 lines
Quoted 1 line
Do you mean that the problem mentioned in this patch is not a problem?
It is not a problem if it is expected,
but nothing is defined.Quoted 1 line
Should we accept this scenario?
We need to decide what is the correct behaviour.
I see pros and cons on both sides.
Where's the bright side of this behavior?
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Another comment,
If we remove the duplicate, we may have to copy to previous default one to avoid completely deleting the previous default address.That's not necessary.
Quoted 8 lines
Quoted 4 lines
Because the previous default address has been removed from hardware.
After the default MAC address is modified, the previous default one is invalid.
No you don't get it.
With the current behaviour, the app could keep all the MAC addresses, and copy one as the default while keeping it in the rest of the list. You are suggesting a different behaviour where there is no duplicate.
This behavior seems to be contrary to the rte_eth_dev_mac_addr_add() API.
If the pmd does not support the dev_ops->mac_addr_set, the rte_eth_dev_mac_addr_add()
is used to set default MAC in ethdev layer. Namely, the rte_eth_dev_mac_addr_add() can
be used to set default MAC in the special scenario and add MAC address.
But the API does not allow the rest of the list to be the same as the default MAC which
occupies idx 0.
If the app uses the MAC address in dev->data->mac_addrs[] to set the default MAC,
the PMD actually has only one entry. As far as I know, the dev->data->mac_addrs[] in
ethdev layer should be consistent with the hardware entry of the PMD.
So I think the behavior referred to in this patch is inappropriate.
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
Not sure what should be the behaviour.
.
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].
Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?
Quoted 34 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.--- lib/ethdev/rte_ethdev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +5
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (ret <0 )return ret; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[].
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4378
Quoted 10 lines
lib/ethdev/rte_ethdev.c +10
-0+*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* remove address in NIC data structure */ +rte_ether_addr_copy (&null_mac_addr, + &dev->data->mac_addrs[index]); +/* reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } +
Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
What about following logic to be sure HW configuration and 'dev->data->mac_addrs[]' is same:
index = eth_dev_get_mac_addr_index(port_id, addr);
if (index > 0)
rte_eth_dev_mac_addr_remove(port_id, addr);
(*dev->dev_ops->mac_addr_set)(dev, addr);Quoted 4 lines
lib/ethdev/rte_ethdev.c +0
-0/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?
I think it's just a waste of space.
Quoted 49 lines
Quoted 36 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ +rte_ether_addr_copy(&null_mac_addr, + &dev->data->mac_addrs[index]); + /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.
Quoted 8 lines
What about following logic to be sure HW configuration and 'dev->data->mac_addrs[]' is same:
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0)rte_eth_dev_mac_addr_remove(port_id, addr); (*dev->dev_ops->mac_addr_set)(dev, addr);
The logic above seems to be good. But if .mac_addr_set() failed to execute, the addr has been removed from HW and 'dev->data->mac_addrs[]'. It's not good.
Hope for your reply. Thanks.
Quoted 5 lines
Quoted 3 lines
/* Update default address in NIC data structure */
rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);.
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);
Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 48 lines
Quoted 48 lines
Quoted 35 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ +rte_ether_addr_copy(&null_mac_addr, + &dev->data->mac_addrs[index]); + /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Quoted 4 lines
Quoted 4 lines
What about following logic to be sure HW configuration and 'dev->data->mac_addrs[]' is same:
Quoted 8 lines
Quoted 4 lines
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0)rte_eth_dev_mac_addr_remove(port_id, addr); (*dev->dev_ops->mac_addr_set)(dev, addr);The logic above seems to be good. But if .mac_addr_set() failed to execute, the addr has been removed from HW and 'dev->data->mac_addrs[]'. It's not good.
Agree. So may need to get a copy of 'addr' and add it back on failure.
The concern I have to call 'rte_eth_dev_mac_addr_remove()' after 'dev_ops->mac_addr_set()' is, it may result different behavior on different PMDs.
For the PMDs that clean the redundant MAC address via 'dev_ops->mac_addr_set()' may try to remove (although it will fail) the new set default MAC address. That is why first remove the MAC and later add it back as default seems safer to me.
Quoted 6 lines
Hope for your reply. Thanks.
Quoted 5 lines
Quoted 3 lines
/* Update default address in NIC data structure */
rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);.
Quoted 93 lines · Ferruh Yigit
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 48 lines
Quoted 48 lines
Quoted 33 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.--- lib/ethdev/rte_ethdev.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +4
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret; + /* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4377
Quoted 10 lines
lib/ethdev/rte_ethdev.c +10
-0+*/ + index = eth_dev_get_mac_addr_index(port_id, addr); + if (index > 0) { + /* remove address in NIC data structure */ + rte_ether_addr_copy(&null_mac_addr, + &dev->data->mac_addrs[index]); + /* reset pool bitmap */ + dev->data->mac_pool_sel[index] = 0; + } +Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.
Quoted 7 lines
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Yes, the API view is more important than saving one entry in an array. From API perspective with this patch,
set_default(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)
default=MAC1, Filters=MAC2, MAC3, MAC4
set_default(MAC2)
default=MAC2, Filters= MAC3, MAC4
set_default(MAC3)
default=MAC3, Filters= MAC4
set_default(MAC4)
default=MAC4, Filters=
set_default(MAC5)
default=MAC5, Filters=
Did I get it right? If so, it seems wrong to silently remove the filters. In which case, it would be easier to just not remove them in the first place (current behaviour).
If they really need to be removed from the filter list when they are set_default(), then perhaps they should be restored to it when there is a new set_default().
Quoted 30 lines
Quoted 4 lines
Quoted 4 lines
What about following logic to be sure HW configuration and 'dev->data->mac_addrs[]' is same:
Quoted 8 lines
Quoted 4 lines
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0)rte_eth_dev_mac_addr_remove(port_id, addr);
(*dev->dev_ops->mac_addr_set)(dev, addr);The logic above seems to be good. But if .mac_addr_set() failed to execute, the addr has been removed from HW and 'dev->data->mac_addrs[]'. It's not good.
Agree. So may need to get a copy of 'addr' and add it back on failure.
The concern I have to call '
rte_eth_dev_mac_addr_remove()' after 'dev_ops->mac_addr_set()' is, it may result different behavior on different PMDs.
For the PMDs that clean the redundant MAC address via 'dev_ops->mac_addr_set()' may try to remove (although it will fail) the new set default MAC address. That is why first remove the MAC and later add it back as default seems safer to me.Quoted 6 lines
Hope for your reply. Thanks.
Quoted 5 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4381
Quoted 3 lines
lib/ethdev/rte_ethdev.c +0
-0/* Update default address in NIC data structure */ rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);.
Quoted 116 lines · Kevin Traynor
Quoted 93 lines · Ferruh Yigit
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 48 lines
Quoted 48 lines
Quoted 35 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ +rte_ether_addr_copy(&null_mac_addr, + &dev->data->mac_addrs[index]); + /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.Quoted 7 lines
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Yes, the API view is more important than saving one entry in an array. From API perspective with this patch,
set_default(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)
default=MAC1, Filters=MAC2, MAC3, MAC4
set_default(MAC2)
default=MAC2, Filters= MAC3, MAC4
set_default(MAC3)
default=MAC3, Filters= MAC4
Quoted 8 lines
set_default(MAC4)
default=MAC4, Filters=
set_default(MAC5)
default=MAC5, Filters=Did I get it right? If so, it seems wrong to silently remove the filters. In which case, it would be easier to just not remove them in the first place (current behaviour).
Yep, this is the updated behavior. And agree it looks wrong when you show like this. (btw, this is only ethdev record of MAC filters, what is updated in this patch, HW still may be keeping all filters.)
Quoted 2 lines
If they really need to be removed from the filter list when they are
set_default(), then perhaps they should be restored to it when there is a newset_default().
I am for keeping current behavior. Application always can explicitly remove a MAC filter before setting it default if required.
Quoted 31 lines
Quoted 30 lines
Quoted 4 lines
Quoted 4 lines
What about following logic to be sure HW configuration and 'dev->data->mac_addrs[]' is same:
Quoted 8 lines
Quoted 4 lines
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0)rte_eth_dev_mac_addr_remove(port_id, addr); (*dev->dev_ops->mac_addr_set)(dev, addr);The logic above seems to be good. But if .mac_addr_set() failed to execute, the addr has been removed from HW and 'dev->data->mac_addrs[]'. It's not good.
Agree. So may need to get a copy of 'addr' and add it back on failure.
The concern I have to call '
rte_eth_dev_mac_addr_remove()' after 'dev_ops->mac_addr_set()' is, it may result different behavior on different PMDs.
For the PMDs that clean the redundant MAC address via 'dev_ops->mac_addr_set()' may try to remove (although it will fail) the new set default MAC address. That is why first remove the MAC and later add it back as default seems safer to me.Quoted 6 lines
Hope for your reply. Thanks.
Quoted 5 lines
Quoted 3 lines
/* Update default address in NIC data structure */
rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);.
Quoted 125 lines · Ferruh Yigit
Quoted 124 lines · Kevin Traynor
Quoted 95 lines · Ferruh Yigit
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 50 lines
Quoted 50 lines
Quoted 37 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by
+ *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ + rte_ether_addr_copy(&null_mac_addr,
+ &dev->data->mac_addrs[index]);
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.Quoted 7 lines
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Yes, the API view is more important than saving one entry in an array. From API perspective with this patch,
set_default(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)
default=MAC1, Filters=MAC2, MAC3, MAC4
set_default(MAC2)
default=MAC2, Filters= MAC3, MAC4
set_default(MAC3)
default=MAC3, Filters= MAC4
set_default(MAC4)
default=MAC4, Filters=
set_default(MAC5)
default=MAC5, Filters=
Quoted 6 lines
Quoted 2 lines
Did I get it right? If so, it seems wrong to silently remove the filters. In which case, it would be easier to just not remove them in the first place (current behaviour).
Yep, this is the updated behavior. And agree it looks wrong when you show like this. (btw, this is only ethdev record of MAC filters, what is updated in this patch, HW still may be keeping all filters.)
Whether HW saves all filters depends on the implementation of the set_default()
in the driver. According to the implementation of this API of all PMDs, some drivers
will first remove the old default MAC in HW and then add the new one when calling
the set_default(). I am not sure if the HW that didn't do this would remove the old
default MAC. If not, we may need to standardize this API in the ethdev layer.
Quoted 6 lines
Quoted 3 lines
If they really need to be removed from the filter list when they are
set_default(), then perhaps they should be restored to it when there is a newset_default().I am for keeping current behavior. Application always can explicitly remove a MAC filter before setting it default if required.
But application can not remove the duplicate MAC if the MAC is the current default
MAC by rte_eth_dev_mac_addr_remove(). In this case, it will failed to remove.
Quoted 35 lines
Quoted 25 lines
Quoted 25 lines
Quoted 6 lines
Quoted 6 lines
What about following logic to be sure HW configuration and 'dev->data->mac_addrs[]' is same:
Quoted 8 lines
Quoted 4 lines
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0)rte_eth_dev_mac_addr_remove(port_id, addr); (*dev->dev_ops->mac_addr_set)(dev, addr);The logic above seems to be good. But if .mac_addr_set() failed to execute, the addr has been removed from HW and 'dev->data->mac_addrs[]'. It's not good.
Agree. So may need to get a copy of 'addr' and add it back on failure.
The concern I have to call '
rte_eth_dev_mac_addr_remove()' after 'dev_ops->mac_addr_set()' is, it may result different behavior on different PMDs.
For the PMDs that clean the redundant MAC address via 'dev_ops->mac_addr_set()' may try to remove (although it will fail) the new set default MAC address. That is why first remove the MAC and later add it back as default seems safer to me.Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Hope for your reply. Thanks.
Quoted 5 lines
Quoted 3 lines
/* Update default address in NIC data structure */
rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);.
.
Quoted 146 lines · lihuisong (C)
Quoted 123 lines · Ferruh Yigit
Quoted 122 lines · Kevin Traynor
Quoted 93 lines · Ferruh Yigit
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 48 lines
Quoted 48 lines
Quoted 35 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ + rte_ether_addr_copy(&null_mac_addr,
+ &dev->data->mac_addrs[index]);
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.Quoted 7 lines
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Yes, the API view is more important than saving one entry in an array. From API perspective with this patch,
set_default(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)
default=MAC1, Filters=MAC2, MAC3, MAC4
set_default(MAC2)
default=MAC2, Filters= MAC3, MAC4
set_default(MAC3)
default=MAC3, Filters= MAC4
set_default(MAC4)
default=MAC4, Filters=
set_default(MAC5)
default=MAC5, Filters=Quoted 6 lines
Quoted 2 lines
Did I get it right? If so, it seems wrong to silently remove the filters. In which case, it would be easier to just not remove them in the first place (current behaviour).
Yep, this is the updated behavior. And agree it looks wrong when you show like this. (btw, this is only ethdev record of MAC filters, what is updated in this patch, HW still may be keeping all filters.)
Whether HW saves all filters depends on the implementation of the
set_default()in the driver. According to the implementation of this API of all PMDs, some drivers
will first remove the old default MAC in HW and then add the new one when calling
the
set_default(). I am not sure if the HW that didn't do this would remove the olddefault MAC. If not, we may need to standardize this API in the ethdev layer.
Quoted 4 lines
Quoted 3 lines
If they really need to be removed from the filter list when they are
set_default(), then perhaps they should be restored to it when there is a newset_default().
Quoted 7 lines
Quoted 2 lines
I am for keeping current behavior. Application always can explicitly remove a MAC filter before setting it default if required.
But application can not remove the duplicate MAC if the MAC is the current default
MAC by
rte_eth_dev_mac_addr_remove(). In this case, it will failed to remove.
But can do other-way around, first remove (the non default one), later 'rte_eth_dev_default_mac_addr_set()'.
Quoted 35 lines
Quoted 35 lines
Quoted 25 lines
Quoted 25 lines
Quoted 6 lines
Quoted 6 lines
What about following logic to be sure HW configuration and 'dev->data->mac_addrs[]' is same:
Quoted 8 lines
Quoted 4 lines
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0)rte_eth_dev_mac_addr_remove(port_id, addr); (*dev->dev_ops->mac_addr_set)(dev, addr);The logic above seems to be good. But if .mac_addr_set() failed to execute, the addr has been removed from HW and 'dev->data->mac_addrs[]'. It's not good.
Agree. So may need to get a copy of 'addr' and add it back on failure.
The concern I have to call '
rte_eth_dev_mac_addr_remove()' after 'dev_ops->mac_addr_set()' is, it may result different behavior on different PMDs.
For the PMDs that clean the redundant MAC address via 'dev_ops->mac_addr_set()' may try to remove (although it will fail) the new set default MAC address. That is why first remove the MAC and later add it back as default seems safer to me.Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Hope for your reply. Thanks.
Quoted 5 lines
Quoted 3 lines
/* Update default address in NIC data structure */
rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);.
.
Quoted 152 lines · Ferruh Yigit
Quoted 151 lines · lihuisong (C)
Quoted 125 lines · Ferruh Yigit
Quoted 124 lines · Kevin Traynor
Quoted 95 lines · Ferruh Yigit
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 50 lines
Quoted 50 lines
Quoted 37 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by
+ *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ + rte_ether_addr_copy(&null_mac_addr,
+ &dev->data->mac_addrs[index]);
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.Quoted 7 lines
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Yes, the API view is more important than saving one entry in an array. From API perspective with this patch,
set_default(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)
default=MAC1, Filters=MAC2, MAC3, MAC4
set_default(MAC2)
default=MAC2, Filters= MAC3, MAC4
set_default(MAC3)
default=MAC3, Filters= MAC4
set_default(MAC4)
default=MAC4, Filters=
set_default(MAC5)
default=MAC5, Filters=Quoted 6 lines
Quoted 2 lines
Did I get it right? If so, it seems wrong to silently remove the filters. In which case, it would be easier to just not remove them in the first place (current behaviour).
Yep, this is the updated behavior. And agree it looks wrong when you show like this. (btw, this is only ethdev record of MAC filters, what is updated in this patch, HW still may be keeping all filters.)
Whether HW saves all filters depends on the implementation of the
set_default()in the driver. According to the implementation of this API of all PMDs, some drivers
will first remove the old default MAC in HW and then add the new one when calling
the
set_default(). I am not sure if the HW that didn't do this would remove the olddefault MAC. If not, we may need to standardize this API in the ethdev layer.
Quoted 6 lines
Quoted 3 lines
If they really need to be removed from the filter list when they are
set_default(), then perhaps they should be restored to it when there is a newset_default().I am for keeping current behavior. Application always can explicitly remove a MAC filter before setting it default if required.
Quoted 7 lines
Quoted 4 lines
But application can not remove the duplicate MAC if the MAC is the current default
MAC by
rte_eth_dev_mac_addr_remove(). In this case, it will failed to remove.But can do other-way around, first remove (the non default one), later '
rte_eth_dev_default_mac_addr_set()'.
This introduces a usage dependency on the user. We don't have a statement in some place
for the dependency. What's more, if the user does not follow this dependency, the user
will no longer be able to remove the MAC.
So it may be more appropriate to deal with problem in ethdev layer.
**Scheme A:**
The decision is left to the user, but there are usage dependency and irremovable possibility.** **
*Scheme B:*
index = eth_dev_get_mac_addr_index(port_id, addr); if (index > 0) {
mac_pool_sel_bk = dev->data->mac_pool_sel[index]; rte_eth_dev_mac_addr_remove(port_id, addr); }
ret = (*dev->dev_ops->mac_addr_set)(dev, addr); if (ret < 0) {
if (index > 0) { rte_eth_dev_mac_addr_add(port_id, addr, 0); dev->data->mac_pool_sel[index] = mac_pool_sel_bk; }
return ret;
}
* Scheme C:*
Use the method in this patch. It assumes that the driver has only one HW entry for a MAC.
What do you think we should do?
Quoted 38 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 7 lines
Quoted 7 lines
What about following logic to be sure HW configuration and 'dev->data->mac_addrs[]' is same:
Quoted 8 lines
Quoted 4 lines
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0)rte_eth_dev_mac_addr_remove(port_id, addr); (*dev->dev_ops->mac_addr_set)(dev, addr);The logic above seems to be good. But if .mac_addr_set() failed to execute, the addr has been removed from HW and 'dev->data->mac_addrs[]'. It's not good.
Agree. So may need to get a copy of 'addr' and add it back on failure.
The concern I have to call '
rte_eth_dev_mac_addr_remove()' after 'dev_ops->mac_addr_set()' is, it may result different behavior on different PMDs.
For the PMDs that clean the redundant MAC address via 'dev_ops->mac_addr_set()' may try to remove (although it will fail) the new set default MAC address. That is why first remove the MAC and later add it back as default seems safer to me.Quoted 5 lines
Hope for your reply. Thanks.
Quoted 4 lines
Quoted 3 lines
/* Update default address in NIC data structure */
rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
Quoted 2 lines
Quoted 1 line
Quoted 1 line
.
.
.
Quoted 188 lines · lihuisong (C)
Quoted 150 lines · Ferruh Yigit
Quoted 149 lines · lihuisong (C)
Quoted 123 lines · Ferruh Yigit
Quoted 122 lines · Kevin Traynor
Quoted 93 lines · Ferruh Yigit
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 48 lines
Quoted 48 lines
Quoted 35 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret; RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ + rte_ether_addr_copy(&null_mac_addr,
+ &dev->data->mac_addrs[index]);
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.Quoted 7 lines
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Yes, the API view is more important than saving one entry in an array. From API perspective with this patch,
set_default(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)
default=MAC1, Filters=MAC2, MAC3, MAC4
set_default(MAC2)
default=MAC2, Filters= MAC3, MAC4
set_default(MAC3)
default=MAC3, Filters= MAC4
set_default(MAC4)
default=MAC4, Filters=
set_default(MAC5)
default=MAC5, Filters=Quoted 6 lines
Quoted 2 lines
Did I get it right? If so, it seems wrong to silently remove the filters. In which case, it would be easier to just not remove them in the first place (current behaviour).
Yep, this is the updated behavior. And agree it looks wrong when you show like this. (btw, this is only ethdev record of MAC filters, what is updated in this patch, HW still may be keeping all filters.)
Whether HW saves all filters depends on the implementation of the
set_default()in the driver. According to the implementation of this API of all PMDs, some drivers
will first remove the old default MAC in HW and then add the new one when calling
the
set_default(). I am not sure if the HW that didn't do this would remove the olddefault MAC. If not, we may need to standardize this API in the ethdev layer.
Quoted 6 lines
Quoted 3 lines
If they really need to be removed from the filter list when they are
set_default(), then perhaps they should be restored to it when there is a newset_default().I am for keeping current behavior. Application always can explicitly remove a MAC filter before setting it default if required.
Quoted 7 lines
Quoted 4 lines
But application can not remove the duplicate MAC if the MAC is the current default
MAC by
rte_eth_dev_mac_addr_remove(). In this case, it will failed to remove.But can do other-way around, first remove (the non default one), later '
rte_eth_dev_default_mac_addr_set()'.This introduces a usage dependency on the user. We don't have a statement in some place
for the dependency. What's more, if the user does not follow this dependency, the user
will no longer be able to remove the MAC.
So it may be more appropriate to deal with problem in ethdev layer.
**Scheme A:**
The decision is left to the user, but there are usage dependency and irremovable possibility.** **
*Scheme B:*
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0) {
mac_pool_sel_bk = dev->data->mac_pool_sel[index];rte_eth_dev_mac_addr_remove(port_id, addr);
}
ret = (*dev->dev_ops->mac_addr_set)(dev, addr); if (ret < 0) {
if (index > 0) {rte_eth_dev_mac_addr_add(port_id, addr, 0); dev->data->mac_pool_sel[index] =mac_pool_sel_bk; }
Quoted 9 lines
return ret;
}* Scheme C:*
Use the method in this patch. It assumes that the driver has only one HW entry for a MAC.
What do you think we should do?
If the impact is only loosing one entry in the array without any functional effect, I am OK to keep behavior as it is.
If there is more motivation for fix, I would prefer option B to be sure all drivers behave same by explicit remove.
Quoted 201 lines · Ferruh Yigit
Quoted 190 lines · lihuisong (C)
Quoted 152 lines · Ferruh Yigit
Quoted 151 lines · lihuisong (C)
Quoted 125 lines · Ferruh Yigit
Quoted 124 lines · Kevin Traynor
Quoted 95 lines · Ferruh Yigit
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 50 lines
Quoted 50 lines
Quoted 37 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by
+ *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ + rte_ether_addr_copy(&null_mac_addr,
+ &dev->data->mac_addrs[index]);
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.Quoted 7 lines
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Yes, the API view is more important than saving one entry in an array. From API perspective with this patch,
set_default(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)
default=MAC1, Filters=MAC2, MAC3, MAC4
set_default(MAC2)
default=MAC2, Filters= MAC3, MAC4
set_default(MAC3)
default=MAC3, Filters= MAC4
set_default(MAC4)
default=MAC4, Filters=
set_default(MAC5)
default=MAC5, Filters=Quoted 6 lines
Quoted 2 lines
Did I get it right? If so, it seems wrong to silently remove the filters. In which case, it would be easier to just not remove them in the first place (current behaviour).
Yep, this is the updated behavior. And agree it looks wrong when you show like this. (btw, this is only ethdev record of MAC filters, what is updated in this patch, HW still may be keeping all filters.)
Whether HW saves all filters depends on the implementation of the
set_default()in the driver. According to the implementation of this API of all PMDs, some drivers
will first remove the old default MAC in HW and then add the new one when calling
the
set_default(). I am not sure if the HW that didn't do this would remove the olddefault MAC. If not, we may need to standardize this API in the ethdev layer.
Quoted 6 lines
Quoted 3 lines
If they really need to be removed from the filter list when they are
set_default(), then perhaps they should be restored to it when there is a newset_default().I am for keeping current behavior. Application always can explicitly remove a MAC filter before setting it default if required.
Quoted 7 lines
Quoted 4 lines
But application can not remove the duplicate MAC if the MAC is the current default
MAC by
rte_eth_dev_mac_addr_remove(). In this case, it will failed to remove.But can do other-way around, first remove (the non default one), later '
rte_eth_dev_default_mac_addr_set()'.This introduces a usage dependency on the user. We don't have a statement in some place
for the dependency. What's more, if the user does not follow this dependency, the user
will no longer be able to remove the MAC.
So it may be more appropriate to deal with problem in ethdev layer.
**Scheme A:**
The decision is left to the user, but there are usage dependency and irremovable possibility.** **
*Scheme B:*
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0) {
mac_pool_sel_bk = dev->data->mac_pool_sel[index];rte_eth_dev_mac_addr_remove(port_id, addr); }
ret = (*dev->dev_ops->mac_addr_set)(dev, addr); if (ret < 0) {
if (index > 0) {rte_eth_dev_mac_addr_add(port_id, addr, 0); dev->data->mac_pool_sel[index] =mac_pool_sel_bk; }Quoted 9 lines
return ret;
}* Scheme C:*
Use the method in this patch. It assumes that the driver has only one HW entry for a MAC.
What do you think we should do?
Quoted 6 lines
If the impact is only loosing one entry in the array without any functional effect, I am OK to keep behavior as it is.
If there is more motivation for fix, I would prefer option B to be sure all drivers behave same by explicit remove.
.
Hi, Ferruh
There may be a functional problem in one scenario if we don't fix this.
Testpmd does the following steps:
1) add MAC1/2/3
mac_addr add 0 MAC1
mac_addr add 0 MAC2
mac_addr add 0 MAC3
2) then set new default MAC3
mac_addr set 0 MAC3
3)show mac_addrs list
MAC3
MAC1
MAC2
MAC3
4)then set new default MAC4
mac_addr set 0 MAC4
5) now, the mac_addrs list is as follows:
MAC4
MAC1
MAC2
MAC3
As a result, the network engine cannot receive packets from MAC3.
But application can see the MAC3 in mac_addrs list.
Btw, rte_eth_dev_default_mac_addr_set() will replace the old default MAC with
the new one, and the old one will be deleted.
So, we should fix it. What do you think? Thanks.
Hi, Ferruh,
what do you think of this patch?
Quoted 271 lines · lihuisong (C)
Quoted 201 lines · Ferruh Yigit
Quoted 190 lines · lihuisong (C)
Quoted 152 lines · Ferruh Yigit
Quoted 151 lines · lihuisong (C)
Quoted 125 lines · Ferruh Yigit
Quoted 124 lines · Kevin Traynor
Quoted 95 lines · Ferruh Yigit
Quoted 25 lines · lihuisong (C)
Hi Ferruh
Quoted 22 lines · Ferruh Yigit
Quoted 10 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set()API. However, If the new default MAC address has been added as a non-default MAC address byrte_eth_dev_mac_addr_add()API, therte_eth_dev_default_mac_addr_set()API doesn't remove it from dev->data->mac_addrs[]. As a result, one MAC address occupies two index capacities in dev->data->mac_addrs[].Hi Connor,
I see the problem, but can you please clarify what is the impact to the end user?
If application does as following:
rte_eth_dev_mac_addr_add(MAC1);
rte_eth_dev_mac_addr_add(MAC2);
rte_eth_dev_mac_addr_add(MAC3);
rte_eth_dev_default_mac_addr_set(MAC2);Quoted 7 lines
Quoted 6 lines
The 'dev->data->mac_addrs[]' will have: "MAC2,MAC2,MAC3" which has 'MAC2' duplicated.
Will this cause any problem for the application to receive the packets with 'MAC2' address?
Or is the only problem one extra space used in 'dev->data->mac_addrs[]' without any other impact to the application?I think it's just a waste of space.
True, it is a waste. But if there is no other visible user impact, we can handle the issue with lower priority and clarifying the impact in commit log helps to others.
Quoted 50 lines
Quoted 50 lines
Quoted 37 lines
This patch adds the logic of removing MAC addresses for this scenario.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v2:
* fixed commit log.
---
lib/ethdev/rte_ethdev.c| 15 +++++++++++++++1 file changed, 15 insertions(+)lib/ethdev/rte_ethdev.c +1
-0@@ -4340,6 +4340,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; + int index; int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4361,6 +4362,20 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (ret < 0) return ret;+ /*
+ * If the address has been added as a non-default MAC address by
+ *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);Quoted 8 lines
+ if (index > 0) {
+ /* remove address in NIC data structure */ + rte_ether_addr_copy(&null_mac_addr,
+ &dev->data->mac_addrs[index]);
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0; + }
+Here only 'dev->data->mac_addrs[]' array is updated and it assumes driver removes similar duplication itself, but I am not sure if this is valid for all drivers.
Quoted 6 lines
Quoted 2 lines
If driver is not removing the duplicate in the HW configuration, the driver config and 'dev->data->mac_addrs[]' will diverge, which is not good.
The same MAC address does not occupy two HW entries, which is also a waste for HW. After all, HW entry resources are also limited. The PMD should also take this into account.
So, I think, we don't have to think about it here.Quoted 7 lines
I am not sure all PMD take this into account, I briefly checked the ixgbe code and I am not sure if it handles this.
Also it is possible to think that this responsibility is pushed to the application, like application should remove a MAC address before setting it as default MAC...
Yes, the API view is more important than saving one entry in an array. From API perspective with this patch,
set_default(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)
default=MAC1, Filters=MAC2, MAC3, MAC4
set_default(MAC2)
default=MAC2, Filters= MAC3, MAC4
set_default(MAC3)
default=MAC3, Filters= MAC4
set_default(MAC4)
default=MAC4, Filters=
set_default(MAC5)
default=MAC5, Filters=Quoted 6 lines
Quoted 2 lines
Did I get it right? If so, it seems wrong to silently remove the filters. In which case, it would be easier to just not remove them in the first place (current behaviour).
Yep, this is the updated behavior. And agree it looks wrong when you show like this. (btw, this is only ethdev record of MAC filters, what is updated in this patch, HW still may be keeping all filters.)
Whether HW saves all filters depends on the implementation of the
set_default()in the driver. According to the implementation of this API of all PMDs, some drivers
will first remove the old default MAC in HW and then add the new one when calling
the
set_default(). I am not sure if the HW that didn't do this would remove the olddefault MAC. If not, we may need to standardize this API in the ethdev layer.
Quoted 6 lines
Quoted 3 lines
If they really need to be removed from the filter list when they are
set_default(), then perhaps they should be restored to it when there is a newset_default().I am for keeping current behavior. Application always can explicitly remove a MAC filter before setting it default if required.
Quoted 7 lines
Quoted 4 lines
But application can not remove the duplicate MAC if the MAC is the current default
MAC by
rte_eth_dev_mac_addr_remove(). In this case, it will failed to remove.But can do other-way around, first remove (the non default one), later '
rte_eth_dev_default_mac_addr_set()'.This introduces a usage dependency on the user. We don't have a statement in some place
for the dependency. What's more, if the user does not follow this dependency, the user
will no longer be able to remove the MAC.
So it may be more appropriate to deal with problem in ethdev layer.
**Scheme A:**
The decision is left to the user, but there are usage dependency and irremovable possibility.** **
*Scheme B:*
index =
eth_dev_get_mac_addr_index(port_id, addr); if (index > 0) {
mac_pool_sel_bk = dev->data->mac_pool_sel[index];rte_eth_dev_mac_addr_remove(port_id, addr); }
ret = (*dev->dev_ops->mac_addr_set)(dev, addr); if (ret < 0) {
if (index > 0) {rte_eth_dev_mac_addr_add(port_id, addr, 0); dev->data->mac_pool_sel[index] =mac_pool_sel_bk; }Quoted 9 lines
return ret;
}* Scheme C:*
Use the method in this patch. It assumes that the driver has only one HW entry for a MAC.
What do you think we should do?
Quoted 6 lines
If the impact is only loosing one entry in the array without any functional effect, I am OK to keep behavior as it is.
If there is more motivation for fix, I would prefer option B to be sure all drivers behave same by explicit remove.
.Hi, Ferruh
There may be a functional problem in one scenario if we don't fix this.
Testpmd does the following steps:
1) add MAC1/2/3
mac_addradd 0 MAC1
mac_addradd 0 MAC2
mac_addradd 0 MAC32) then set new default MAC3
mac_addrset 0 MAC33)show
mac_addrslistMAC3
MAC1
MAC2
MAC3
4)then set new default MAC4
mac_addrset 0 MAC45) now, the
mac_addrslist is as follows:MAC4
MAC1
MAC2
MAC3
As a result, the network engine cannot receive packets from MAC3.
But application can see the MAC3 in
mac_addrslist.Btw,
rte_eth_dev_default_mac_addr_set()will replace the old default MAC withthe new one, and the old one will be deleted.
So, we should fix it. What do you think? Thanks.
.
PATCH v5 1/1 ethdev: fix one address occupies two indexes in MAC addrs
In reply to Min Hu (Connor)The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the mac_addrs list. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do set_default(MAC5), and the mac_addrs list is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
So this patch adds a remove operation in set default MAC API documents this behavior.
---
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
--- lib/ethdev/ethdev_driver.h | 7 ++++++- lib/ethdev/rte_ethdev.c | 41 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-)
lib/ethdev/ethdev_driver.h +6 -1
@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the +* index of the default address, and other indexes can't be the same +* as the address corresponding to index 0. +* @see rte_eth_dev_release_port() +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
lib/ethdev/rte_ethdev.c +39 -2
62 lines not on this page · raw message
Signature · 1 line
2.22.0
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
Kindly ping.
Quoted 132 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So this patch adds a remove operation in set default MAC API documents this behavior.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.v4:
- fix broken in the patchworkv3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC addressv2:
- fixed commit log.--- lib/ethdev/ethdev_driver.h | 7 ++++++- lib/ethdev/rte_ethdev.c | 41 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-)lib/ethdev/ethdev_driver.h +6
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the +* index of the default address, and other indexes can't be the same +* as the address corresponding to index 0. +* @see rte_eth_dev_release_port() +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];lib/ethdev/rte_ethdev.c +39
-2@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id); +return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) { +if (rte_eth_dev_mac_addr_add (port_id, addr, + pool) !=0 ) +RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
In reply to Huisong LiHi Andrew and PMD maintainers,
Can you have a look?
Quoted 132 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So this patch adds a remove operation in set default MAC API documents this behavior.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.v4:
- fix broken in the patchworkv3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC addressv2:
- fixed commit log.--- lib/ethdev/ethdev_driver.h | 7 ++++++- lib/ethdev/rte_ethdev.c | 41 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-)lib/ethdev/ethdev_driver.h +6
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the +* index of the default address, and other indexes can't be the same +* as the address corresponding to index 0. +* @see rte_eth_dev_release_port() +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];lib/ethdev/rte_ethdev.c +39
-2@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id); +return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) { +if (rte_eth_dev_mac_addr_add (port_id, addr, + pool) !=0 ) +RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
In reply to Huisong LiLGTM
Quoted 133 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So this patch adds a remove operation in set default MAC API documents this behavior.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu (Connor) <[email protected]>---
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.v4:
- fix broken in the patchworkv3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC addressv2:
- fixed commit log.--- lib/ethdev/ethdev_driver.h | 7 ++++++- lib/ethdev/rte_ethdev.c | 41 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 45 insertions(+), 3 deletions(-)lib/ethdev/ethdev_driver.h +6
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the +* index of the default address, and other indexes can't be the same +* as the address corresponding to index 0. +* @see rte_eth_dev_release_port() +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];lib/ethdev/rte_ethdev.c +39
-2@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id); +return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) { +if (rte_eth_dev_mac_addr_add (port_id, addr, + pool) !=0 ) +RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
In reply to Huisong Li20/10/2022 11:31, Huisong Li:
Quoted 11 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4
I agree it would be simpler to ensure that the addresses are uniques.
Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
If MAC3 is not removed with rte_eth_dev_mac_addr_remove() by the app, MAC3 packets should be received.
The MAC address should not be removed by the PMD.
Quoted 2 lines
So this patch adds a remove operation in set default MAC API documents this behavior.
Let's be clear here: only the new default address is removed from the rest of the list.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 120
Quoted 12 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")lib/ethdev/ethdev_driver.h +2
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the
It should be "addresses" as there can be multiple.
What means "as" above?
Can we say the first entry (index zero) is the default address?
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 121
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* index of the default address, and other indexes can't be the same
You can split the sentence in 2 instead of ", and". indexes -> entries
can't -> cannot
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 122
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* as the address corresponding to index 0.
simpler: as the default address.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 123
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* @see rte_eth_dev_release_port()
Why referencing this function here?
Quoted 16 lines
lib/ethdev/ethdev_driver.h +1
-0+*/ lib/ethdev/rte_ethdev.c +3
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4527
Quoted 8 lines
lib/ethdev/rte_ethdev.c +5
-0@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/
Make is simpler:
"Keep address unique in dev->data->mac_addrs[]."
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4535
Quoted 8 lines
lib/ethdev/rte_ethdev.c +8
-0+ index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id);
It is not clear with this log that it failed.
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4539
Quoted 4 lines
lib/ethdev/rte_ethdev.c +4
-0+return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ;
mac_pool_sel[index] is already reset in rte_eth_dev_mac_addr_remove().
Quoted 19 lines
lib/ethdev/rte_ethdev.c +9
-2+ } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; + do { + if (mac_pool_sel_bk & UINT64_C(1)) { + if (rte_eth_dev_mac_addr_add(port_id, addr, + pool) != 0)
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4566
Quoted 10 lines
lib/ethdev/rte_ethdev.c +10
-0+RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}
Can we avoid this rollback by removing the address after mac_addr_set() succeed?
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
18/01/2023 09:26, Thomas Monjalon:
Quoted 21 lines
20/10/2022 11:31, Huisong Li:
Quoted 11 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4I agree it may be simpler to ensure that the addresses are uniques.
Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
Quoted 3 lines
If MAC3 is not removed with
rte_eth_dev_mac_addr_remove()by the app, MAC3 packets should be received.
The MAC address should not be removed by the PMD.
Sorry for the confusion. I mean the opposite.
With the new behavior, if we want the old default address to be kept in the list, we need to add it explicitly with rte_eth_dev_mac_addr_add. This is a behavior change and must be highlighted in the release notes.
Quoted 114 lines
Quoted 2 lines
So this patch adds a remove operation in set default MAC API documents this behavior.
Let's be clear here: only the new default address is removed from the rest of the list.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 120
Quoted 12 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")lib/ethdev/ethdev_driver.h +2
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the It should be "addresses" as there can be multiple.
What means "as" above?
Can we say the first entry (index zero) is the default address?lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 121
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* index of the default address, and other indexes can't be the same You can split the sentence in 2 instead of ", and". indexes -> entries
can't -> cannotlib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 122
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* as the address corresponding to index 0. simpler: as the default address.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 123
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* @see rte_eth_dev_release_port() Why referencing this function here?
Quoted 16 lines
lib/ethdev/ethdev_driver.h +1
-0+*/ lib/ethdev/rte_ethdev.c +3
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4527
Quoted 8 lines
lib/ethdev/rte_ethdev.c +5
-0@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ Make is simpler:
"Keep address unique in dev->data->mac_addrs[]."lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4535
Quoted 8 lines
lib/ethdev/rte_ethdev.c +8
-0+ index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id);It is not clear with this log that it failed.
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4539
Quoted 4 lines
lib/ethdev/rte_ethdev.c +4
-0+return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ;mac_pool_sel[index] is already reset in
rte_eth_dev_mac_addr_remove().Quoted 19 lines
lib/ethdev/rte_ethdev.c +9
-2+ } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; + do { + if (mac_pool_sel_bk & UINT64_C(1)) { + if (rte_eth_dev_mac_addr_add(port_id, addr, + pool) != 0)lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4566
Quoted 10 lines
lib/ethdev/rte_ethdev.c +10
-0+RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}Can we avoid this rollback by removing the address after
mac_addr_set()succeed?
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
Quoted 20 lines · Thomas Monjalon
18/01/2023 09:26, Thomas Monjalon:
Quoted 19 lines
20/10/2022 11:31, Huisong Li:
Quoted 11 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4I agree it may be simpler to ensure that the addresses are uniques.
Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
Quoted 7 lines
Quoted 3 lines
If MAC3 is not removed with
rte_eth_dev_mac_addr_remove()by the app, MAC3 packets should be received.
The MAC address should not be removed by the PMD.Sorry for the confusion. I mean the opposite.
With the new behavior, if we want the old default address to be kept in the list, we need to add it explicitly withrte_eth_dev_mac_addr_add. This is a behavior change and must be highlighted in the release notes.
Hi Thomas,
Sorry for your confusion. Maybe my cmmmit log is misleading. Please ignore the second paragraph description in my commit.
It has nothing to do with the old defalut address.
The purpose of this patch is to solve the problem that one address occupies two entries in MAC list.
All network engines have this problem. If the new defalut address has been added as a non-default MAC address to the MAC list, this address will occupy two entries in MAC list.
It's still a problem for some network engines, like, hns3 and i40e. That's what I described in the second paragraph in my commit.
/Huisong
Quoted 106 lines
Quoted 95 lines
Quoted 2 lines
So this patch adds a remove operation in set default MAC API documents this behavior.
Let's be clear here: only the new default address is removed from the rest of the list.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 120
Quoted 11 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")lib/ethdev/ethdev_driver.h +2
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the It should be "addresses" as there can be multiple.
What means "as" above?
Can we say the first entry (index zero) is the default address?lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 121
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* index of the default address, and other indexes can't be the same You can split the sentence in 2 instead of ", and". indexes -> entries
can't -> cannotlib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 122
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* as the address corresponding to index 0. simpler: as the default address.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 123
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* @see rte_eth_dev_release_port() Why referencing this function here?
Quoted 15 lines
lib/ethdev/ethdev_driver.h +1
-0+*/ lib/ethdev/rte_ethdev.c +3
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4527
Quoted 8 lines
lib/ethdev/rte_ethdev.c +5
-0@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ Make is simpler:
"Keep address unique in dev->data->mac_addrs[]."lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4535
Quoted 8 lines
lib/ethdev/rte_ethdev.c +8
-0+ index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id);It is not clear with this log that it failed.
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4539
Quoted 4 lines
lib/ethdev/rte_ethdev.c +4
-0+return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ;mac_pool_sel[index] is already reset in
rte_eth_dev_mac_addr_remove().Quoted 22 lines
lib/ethdev/rte_ethdev.c +12
-2+ } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; + do { + if (mac_pool_sel_bk & UINT64_C(1)) { + if (rte_eth_dev_mac_addr_add(port_id, addr, + pool) != 0) + RTE_ETHDEV_LOG(ERR, "failed to restore MAC pool id(%u) in port %u.\n", + pool, port_id); + }Quoted 8 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4566
Quoted 7 lines
lib/ethdev/rte_ethdev.c +7
-0+ mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}Can we avoid this rollback by removing the address after
mac_addr_set()succeed?.
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
In reply to Thomas MonjalonQuoted 72 lines · Thomas Monjalon
20/10/2022 11:31, Huisong Li:
Quoted 11 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4I agree it would be simpler to ensure that the addresses are uniques.
Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.If MAC3 is not removed with
rte_eth_dev_mac_addr_remove()by the app, MAC3 packets should be received.
The MAC address should not be removed by the PMD.Quoted 2 lines
So this patch adds a remove operation in set default MAC API documents this behavior.
Let's be clear here: only the new default address is removed from the rest of the list.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 120
Quoted 11 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")lib/ethdev/ethdev_driver.h +2
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the It should be "addresses" as there can be multiple.
What means "as" above?
Can we say the first entry (index zero) is the default address?lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 121
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* index of the default address, and other indexes can't be the same You can split the sentence in 2 instead of ", and". indexes -> entries
can't -> cannotlib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 122
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* as the address corresponding to index 0. simpler: as the default address.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 123
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* @see rte_eth_dev_release_port() Why referencing this function here?
Quoted 18 lines
lib/ethdev/ethdev_driver.h +1
-0+*/ lib/ethdev/rte_ethdev.c +3
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ;
Quoted 7 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4527
Quoted 5 lines
lib/ethdev/rte_ethdev.c +5
-0+/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ Make is simpler:
"Keep address unique in dev->data->mac_addrs[]."
Ack
Quoted 10 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4535
Quoted 9 lines
lib/ethdev/rte_ethdev.c +8
-0+ index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id);It is not clear with this log that it failed.
Adjust as follows?
"Delete old address entry from the MAC list of ethdev port %u.\n"
Quoted 6 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4539
Quoted 5 lines
lib/ethdev/rte_ethdev.c +4
-0+return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ;mac_pool_sel[index] is already reset in
rte_eth_dev_mac_addr_remove().
Yes, this can be deleted.
Quoted 23 lines
Quoted 23 lines
lib/ethdev/rte_ethdev.c +12
-2+ } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; + do { + if (mac_pool_sel_bk & UINT64_C(1)) { + if (rte_eth_dev_mac_addr_add(port_id, addr, + pool) != 0) + RTE_ETHDEV_LOG(ERR, "failed to restore MAC pool id(%u) in port %u.\n", + pool, port_id); + }
Quoted 8 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4566
Quoted 7 lines
lib/ethdev/rte_ethdev.c +7
-0+ mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}Can we avoid this rollback by removing the address after
mac_addr_set()succeed?
No, the new default address will be removed if we do that.
we need to remove it first if the new default address has been added as a non-default MAC address to the MAC list.
Quoted 4 lines
.
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
Hi,
You missed some questions and comments below.
19/01/2023 10:57, lihuisong (C):
Quoted 131 lines · Thomas Monjalon
Quoted 72 lines
20/10/2022 11:31, Huisong Li:
Quoted 11 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4I agree it would be simpler to ensure that the addresses are uniques.
Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.If MAC3 is not removed with
rte_eth_dev_mac_addr_remove()by the app, MAC3 packets should be received.
The MAC address should not be removed by the PMD.Quoted 2 lines
So this patch adds a remove operation in set default MAC API documents this behavior.
Let's be clear here: only the new default address is removed from the rest of the list.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 120
Quoted 11 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")lib/ethdev/ethdev_driver.h +2
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the It should be "addresses" as there can be multiple.
What means "as" above?
Can we say the first entry (index zero) is the default address?lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 121
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* index of the default address, and other indexes can't be the same You can split the sentence in 2 instead of ", and". indexes -> entries
can't -> cannotlib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 122
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* as the address corresponding to index 0. simpler: as the default address.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 123
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* @see rte_eth_dev_release_port() Why referencing this function here?
Quoted 18 lines
lib/ethdev/ethdev_driver.h +1
-0+*/ lib/ethdev/rte_ethdev.c +3
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ;Quoted 7 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4527
Quoted 5 lines
lib/ethdev/rte_ethdev.c +5
-0+/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ Make is simpler:
"Keep address unique in dev->data->mac_addrs[]."Ack
Quoted 10 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4535
Quoted 9 lines
lib/ethdev/rte_ethdev.c +8
-0+ index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id);It is not clear with this log that it failed.
Adjust as follows?
"Delete old address entry from the MAC list of ethdev port %u.\n"Quoted 6 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4539
Quoted 5 lines
lib/ethdev/rte_ethdev.c +4
-0+return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ;mac_pool_sel[index] is already reset in
rte_eth_dev_mac_addr_remove().Yes, this can be deleted.
Quoted 23 lines
Quoted 23 lines
lib/ethdev/rte_ethdev.c +12
-2+ } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; + do { + if (mac_pool_sel_bk & UINT64_C(1)) { + if (rte_eth_dev_mac_addr_add(port_id, addr, + pool) != 0) + RTE_ETHDEV_LOG(ERR, "failed to restore MAC pool id(%u) in port %u.\n", + pool, port_id); + }Quoted 8 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4566
Quoted 7 lines
lib/ethdev/rte_ethdev.c +7
-0+ mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}Can we avoid this rollback by removing the address after
mac_addr_set()succeed?
Quoted 3 lines
No, the new default address will be removed if we do that.
we need to remove it first if the new default address has been added as a non-default MAC address to the MAC list.
OK yes.
Re: [PATCH V5] ethdev: fix one address occupies two indexes in MAC addrs
Quoted 3 lines · Thomas Monjalon
Hi,
You missed some questions and comments below.
Sorry for my later reply. I just got back from vacation. Please take a look again.
Quoted 25 lines
19/01/2023 10:57, lihuisong (C):
Quoted 23 lines · Thomas Monjalon
Quoted 22 lines
20/10/2022 11:31, Huisong Li:
Quoted 11 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4I agree it would be simpler to ensure that the addresses are uniques.
Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.If MAC3 is not removed with
rte_eth_dev_mac_addr_remove()by the app, MAC3 packets should be received.
The MAC address should not be removed by the PMD.
Please review another thread you pulled.
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
So this patch adds a remove operation in set default MAC API documents this behavior.
Let's be clear here: only the new default address is removed from the rest of the list.
ok. Your expression is more explicit.
Quoted 17 lines
Quoted 17 lines
Quoted 17 lines
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 120
Quoted 12 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")lib/ethdev/ethdev_driver.h +2
-1@@ -116,7 +116,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the It should be "addresses" as there can be multiple.
What means "as" above?
Can we say the first entry (index zero) is the default address?
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 121
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* index of the default address, and other indexes can't be the same You can split the sentence in 2 instead of ", and". indexes -> entries
can't -> cannotlib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 122
Quoted 1 line
lib/ethdev/ethdev_driver.h +1
-0+* as the address corresponding to index 0. simpler: as the default address.
Above all will be fixed. Thank you for your suggestion.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 123
Quoted 2 lines
lib/ethdev/ethdev_driver.h +1
-0+* @see rte_eth_dev_release_port() Why referencing this function here?
It was here before, and I didn't care too much, but I think it is redundant. I will remove it.
Quoted 81 lines
Quoted 74 lines
Quoted 19 lines
Quoted 19 lines
lib/ethdev/ethdev_driver.h +1
-0+*/ lib/ethdev/rte_ethdev.c +3
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4517,16 +4520,50 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ;Quoted 7 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4527
Quoted 5 lines
lib/ethdev/rte_ethdev.c +5
-0+/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ Make is simpler:
"Keep address unique in dev->data->mac_addrs[]."Ack
Quoted 9 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4535
Quoted 8 lines
lib/ethdev/rte_ethdev.c +8
-0+ index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id);It is not clear with this log that it failed.
Adjust as follows?
"Delete old address entry from the MAC list of ethdev port %u.\n"Quoted 5 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4539
Quoted 4 lines
lib/ethdev/rte_ethdev.c +4
-0+return ret; + } +/* Reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ;mac_pool_sel[index] is already reset in
rte_eth_dev_mac_addr_remove().Yes, this can be deleted.
Quoted 22 lines
Quoted 22 lines
lib/ethdev/rte_ethdev.c +12
-2+ } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; + do { + if (mac_pool_sel_bk & UINT64_C(1)) { + if (rte_eth_dev_mac_addr_add(port_id, addr, + pool) != 0) + RTE_ETHDEV_LOG(ERR, "failed to restore MAC pool id(%u) in port %u.\n", + pool, port_id); + }Quoted 8 lines
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4566
Quoted 7 lines
lib/ethdev/rte_ethdev.c +7
-0+ mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}Can we avoid this rollback by removing the address after
mac_addr_set()succeed?Quoted 3 lines
No, the new default address will be removed if we do that.
we need to remove it first if the new default address has been added as a non-default MAC address to the MAC list.OK yes.
.
PATCH v6 1/1 ethdev: fix one address occupies two entries in MAC addrs
In reply to Huisong LiThe dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the mac_addrs list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do set_default(MAC5), and the mac_addrs list is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
So need to ensure that the new default address is removed from the rest of the list.
---
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
--- lib/ethdev/ethdev_driver.h | 6 +++++- lib/ethdev/rte_ethdev.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-)
lib/ethdev/ethdev_driver.h +5 -1
@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. The first entry (index zero) is the +* default address. The rest of list cannot be the same as the default +* address. +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
lib/ethdev/rte_ethdev.c +33 -2
@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4517,16 +4520,44 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* Keep address unique in dev->data->mac_addrs[]. */ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Cannot remove the port %u address from the rest of list.\n" , + port_id); +return ret; + } + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) { +if (rte_eth_dev_mac_addr_add (port_id, addr, + pool) !=0 ) +RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
Signature · 1 line
2.22.0
Re: [PATCH V6] ethdev: fix one address occupies two entries in MAC addrs
31/01/2023 07:41, Huisong Li:
Quoted 25 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of the list.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")
Quoted 6 lines
Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>--- lib/ethdev/ethdev_driver.h | 6 +++++- lib/ethdev/rte_ethdev.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-)
This is a behavior change.
It must be noted in the release notes in the API section.
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 124
Quoted 6 lines
lib/ethdev/ethdev_driver.h +5
-1-/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. The first entry (index zero) is the +* default address. The rest of list cannot be the same as the default +* address. +*/
Please split the lines after a dot.
rest of "the" list
Maybe better for this field:
All entries are unique.
The first entry (index zero) is the default address.
Quoted 1 line
struct
rte_ether_addr*mac_addrs;
and for the function rte_eth_dev_default_mac_addr_set:
Set the default MAC address.
It replaces the address at index 0 of the address list. If the address was already in the MAC address list, it is removed from the rest of the list.
Re: [PATCH V6] ethdev: fix one address occupies two entries in MAC addrs
Quoted 26 lines · Thomas Monjalon
31/01/2023 07:41, Huisong Li:
Quoted 25 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of the list.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")
Quoted 8 lines
Quoted 6 lines
Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>--- lib/ethdev/ethdev_driver.h | 6 +++++- lib/ethdev/rte_ethdev.c | 35 +++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 3 deletions(-)This is a behavior change.
It must be noted in the release notes in the API section.
ok. I will add an announcement.
Quoted 8 lines
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 124
Quoted 6 lines
lib/ethdev/ethdev_driver.h +5
-1-/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. The first entry (index zero) is the +* default address. The rest of list cannot be the same as the default +* address. +*/ Please split the lines after a dot.
Quoted 5 lines
rest of "the" list
Maybe better for this field:
All entries are unique.
The first entry (index zero) is the default address.
It's more simpler. Thank you for your suggestion.
Quoted 6 lines
Quoted 1 line
struct
rte_ether_addr*mac_addrs;and for the function
rte_eth_dev_default_mac_addr_set:
Set the default MAC address.
It replaces the address at index 0 of the address list. If the address was already in the MAC address list, it is removed from the rest of the list.
Indeed, It's better to document it.
Quoted 4 lines
.
PATCH v7 1/1 ethdev: fix one address occupies two entries in MAC addrs
In reply to Huisong LiThe dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the mac_addrs list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do set_default(MAC5), and the mac_addrs list is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
---
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
--- doc/guides/rel_notes/release_23_03.rst | 6 +++++ lib/ethdev/ethdev_driver.h | 6 ++++- lib/ethdev/rte_ethdev.c | 35 ++++++++++++++++++++++++-- lib/ethdev/rte_ethdev.h | 3 +++ 4 files changed, 47 insertions(+), 3 deletions(-)
doc/guides/rel_notes/release_23_03.rst +6 -0
@@ -101,10 +101,16 @@ API Changes Use fixed width quotes for ``function_names`` or ``struct_names``. Use the past tense. + This section is a comment. Do not overwrite or remove it. Also, make sure to start the actual text at the margin. ======================================================= + * ethdev: ensured all entries in MAC address list is unique. + The function ``rte_eth_dev_default_mac_addr_set`` replaces the address + at index 0 of the address list. If the address was already in the + address list, it is removed from the rest of the list. + ABI Changes -----------
lib/ethdev/ethdev_driver.h +5 -1
@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. The first entry (index zero) is the +* default address. +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
lib/ethdev/rte_ethdev.c +33 -2
@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4517,16 +4520,44 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* Keep address unique in dev->data->mac_addrs[]. */ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Cannot remove the port %u address from the rest of list.\n" , + port_id); +return ret; + } + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) { +if (rte_eth_dev_mac_addr_add (port_id, addr, + pool) !=0 ) +RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
lib/ethdev/rte_ethdev.h +3 -0
@@ -4356,6 +4356,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, it is removed from +* the rest of the list. * * @param port_id * The port identifier of the Ethernet device.
Signature · 1 line
2.22.0
Re: [PATCH V7] ethdev: fix one address occupies two entries in MAC addrs
01/02/2023 14:15, Huisong Li:
Quoted 27 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>
[...]
doc/guides/rel_notes/release_23_03.rst API Changes · line 104
Quoted 7 lines
doc/guides/rel_notes/release_23_03.rst +1
-0@@ -101,10 +101,16 @@ API Changes Use fixed width quotes for ``function_names`` or ``struct_names``. Use the past tense. +
useless line?
doc/guides/rel_notes/release_23_03.rst API Changes · line 107
Quoted 3 lines
doc/guides/rel_notes/release_23_03.rst +0
-0This section is a comment. Do not overwrite or remove it. Also, make sure to start the actual text at the margin. =======================================================
Please check the comment: "make sure to start the actual text at the margin."
doc/guides/rel_notes/release_23_03.rst API Changes · line 109
Quoted 1 line
doc/guides/rel_notes/release_23_03.rst +1
-0+ * ethdev: ensured all entries in MAC address list is unique.
is -> are uniques
doc/guides/rel_notes/release_23_03.rst API Changes · line 112
Quoted 3 lines
doc/guides/rel_notes/release_23_03.rst +3
-0+ The function ``rte_eth_dev_default_mac_addr_set`` replaces the address + at index 0 of the address list. If the address was already in the + address list, it is removed from the rest of the list.
You need to highlight what changed:
When setting a default MAC address with the function ``rte_eth_dev_default_mac_addr_set``,
the address is now removed from the rest of the address list in order to ensure it is only at index 0 of the list.
[...]
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 124
Quoted 12 lines
lib/ethdev/ethdev_driver.h +5
-1@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. The first entry (index zero) is the +* default address. +*/
You remember I asked to split lines after the dot?
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data {
Quoted 5 lines
lib/ethdev/ethdev_driver.h +3
-0/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, it is removed from +* the rest of the list.
Here you can split after the comma.
Re: [PATCH V7] ethdev: fix one address occupies two entries in MAC addrs
Quoted 29 lines · Thomas Monjalon
01/02/2023 14:15, Huisong Li:
Quoted 27 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>[...]
Quoted 8 lines
doc/guides/rel_notes/release_23_03.rst API Changes · line 104
Quoted 7 lines
doc/guides/rel_notes/release_23_03.rst +1
-0@@ -101,10 +101,16 @@ API Changes Use fixed width quotes for ``function_names`` or ``struct_names``. Use the past tense. +useless line?
will remove.
Quoted 5 lines
doc/guides/rel_notes/release_23_03.rst API Changes · line 107
Quoted 4 lines
doc/guides/rel_notes/release_23_03.rst +0
-0This section is a comment. Do not overwrite or remove it. Also, make sure to start the actual text at the margin. =======================================================Please check the comment: "make sure to start the actual text at the margin."
It means to start the actual text at the beginning of the line, right?
Quoted 3 lines
doc/guides/rel_notes/release_23_03.rst API Changes · line 109
Quoted 2 lines
doc/guides/rel_notes/release_23_03.rst +1
-0+ * ethdev: ensured all entries in MAC address list is unique.is -> are uniques
All right.
Quoted 10 lines
doc/guides/rel_notes/release_23_03.rst API Changes · line 112
Quoted 4 lines
doc/guides/rel_notes/release_23_03.rst +3
-0+ The function ``rte_eth_dev_default_mac_addr_set`` replaces the address + at index 0 of the address list. If the address was already in the + address list, it is removed from the rest of the list.You need to highlight what changed:
When setting a default MAC address with the function ``rte_eth_dev_default_mac_addr_set``,
the address is now removed from the rest of the address list in order to ensure it is only at index 0 of the list.
ok, highlight it.
Quoted 8 lines
[...]
Quoted 6 lines
lib/ethdev/ethdev_driver.h +0
-0@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */
Quoted 7 lines
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 124
Quoted 6 lines
lib/ethdev/ethdev_driver.h +5
-1-/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. The first entry (index zero) is the +* default address. +*/ You remember I asked to split lines after the dot?
Sorry for my misunderstanding. Need to occupy one line for each sentence here? Do we generally use this style to make comments? or are we just trying to highlight it here?
Quoted 7 lines
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data {
Quoted 6 lines
lib/ethdev/ethdev_driver.h +3
-0/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, it is removed from +* the rest of the list. Here you can split after the comma.
Ack
Quoted 4 lines
.
Re: [PATCH V7] ethdev: fix one address occupies two entries in MAC addrs
02/02/2023 02:11, lihuisong (C):
Quoted 8 lines · Thomas Monjalon
Quoted 5 lines
01/02/2023 14:15, Huisong Li:
Quoted 3 lines
This section is a comment. Do not overwrite or remove it. Also, make sure to start the actual text at the margin.
=======================================================Please check the comment: "make sure to start the actual text at the margin."
It means to start the actual text at the beginning of the line, right?
It means no extra space at the beginning of the line.
Quoted 9 lines
Quoted 7 lines
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 124
Quoted 6 lines
lib/ethdev/ethdev_driver.h +5
-1-/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. The first entry (index zero) is the +* default address. +*/ You remember I asked to split lines after the dot?
Sorry for my misunderstanding. Need to occupy one line for each sentence here?
A sentence may be longer than one line,
but it is better split lines logically (after dots, commas, etc).
Quoted 2 lines
Do we generally use this style to make comments? or are we just trying to highlight it here?
That's a recommendation when writing text (comments and rst doc). Having lines split logically may help reading,
and will make simpler patches when updating in future, because in general we change a single sentence.
Re: [PATCH V7] ethdev: fix one address occupies two entries in MAC addrs
Quoted 22 lines · Thomas Monjalon
02/02/2023 02:11, lihuisong (C):
Quoted 7 lines · Thomas Monjalon
Quoted 5 lines
01/02/2023 14:15, Huisong Li:
Quoted 3 lines
This section is a comment. Do not overwrite or remove it. Also, make sure to start the actual text at the margin.
=======================================================Please check the comment: "make sure to start the actual text at the margin."
It means to start the actual text at the beginning of the line, right?
It means no extra space at the beginning of the line.
Quoted 9 lines
Quoted 7 lines
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 124
Quoted 6 lines
lib/ethdev/ethdev_driver.h +5
-1-/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. The first entry (index zero) is the +* default address. +*/ You remember I asked to split lines after the dot?
Sorry for my misunderstanding. Need to occupy one line for each sentence here?
A sentence may be longer than one line,
but it is better split lines logically (after dots, commas, etc).
Quoted 6 lines
Quoted 2 lines
Do we generally use this style to make comments? or are we just trying to highlight it here?
That's a recommendation when writing text (comments and rst doc). Having lines split logically may help reading,
and will make simpler patches when updating in future, because in general we change a single sentence.
All right, got it. The next version will be out soon.
Quoted 3 lines
.
PATCH v8 1/1 ethdev: fix one address occupies two entries in MAC addrs
In reply to Huisong LiThe dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the mac_addrs list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do set_default(MAC5), and the mac_addrs list is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
---
v8: fix some comments.
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
--- doc/guides/rel_notes/release_23_03.rst | 6 +++++ lib/ethdev/ethdev_driver.h | 6 ++++- lib/ethdev/rte_ethdev.c | 35 ++++++++++++++++++++++++-- lib/ethdev/rte_ethdev.h | 3 +++ 4 files changed, 47 insertions(+), 3 deletions(-)
doc/guides/rel_notes/release_23_03.rst +6 -0
@@ -105,6 +105,12 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: ensured all entries in MAC address list are uniques. + When setting a default MAC address with the function + ``rte_eth_dev_default_mac_addr_set``, + the address is now removed from the rest of the address list + in order to ensure it is only at index 0 of the list. + ABI Changes -----------
lib/ethdev/ethdev_driver.h +5 -1
@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. +* The first entry (index zero) is the default address. +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
lib/ethdev/rte_ethdev.c +33 -2
@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4517,16 +4520,44 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* Keep address unique in dev->data->mac_addrs[]. */ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Cannot remove the port %u address from the rest of list.\n" , + port_id); +return ret; + } + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) { +if (rte_eth_dev_mac_addr_add (port_id, addr, + pool) !=0 ) +RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
lib/ethdev/rte_ethdev.h +3 -0
@@ -4356,6 +4356,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* it is removed from the rest of the list. * * @param port_id * The port identifier of the Ethernet device.
Signature · 1 line
2.22.0
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
02/02/2023 13:36, Huisong Li:
Quoted 19 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
Quoted 8 lines
So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>
Thank you
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
In reply to Huisong LiQuoted 13 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.
Quoted 9 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
Same comment from past seems already valid, I am not looking to the set for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2
I am not exactly clear what is the intention with set(), if there is single MAC I guess intention is to replace it with new one, but if there are multiple MACs and one of them are already in the list intention may be just to change the default MAC.
If above assumption is correct, what about following:
set(MAC) {
if only_default_mac_exist
replace_default_mac
if MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}
This swap prevents removing MAC side affect, does it make sense?
Quoted 136 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>---
v8: fix some comments.
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.--- doc/guides/rel_notes/release_23_03.rst | 6 +++++ lib/ethdev/ethdev_driver.h | 6 ++++- lib/ethdev/rte_ethdev.c | 35 ++++++++++++++++++++++++-- lib/ethdev/rte_ethdev.h | 3 +++ 4 files changed, 47 insertions(+), 3 deletions(-)doc/guides/rel_notes/release_23_03.rst +6
-0@@ -105,6 +105,12 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: ensured all entries in MAC address list are uniques. + When setting a default MAC address with the function + ``rte_eth_dev_default_mac_addr_set``, + the address is now removed from the rest of the address list + in order to ensure it is only at index 0 of the list. + ABI Changes -----------lib/ethdev/ethdev_driver.h +5
-1@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. +* The first entry (index zero) is the default address. +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];lib/ethdev/rte_ethdev.c +33
-2@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4517,16 +4520,44 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* Keep address unique in dev->data->mac_addrs[]. */ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Cannot remove the port %u address from the rest of list.\n" , + port_id); +return ret; + } + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) { +if (rte_eth_dev_mac_addr_add (port_id, addr, + pool) !=0 ) +RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find lib/ethdev/rte_ethdev.h +3
-0@@ -4356,6 +4356,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* it is removed from the rest of the list. * * @param port_id * The port identifier of the Ethernet device.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
02/02/2023 19:09, Ferruh Yigit:
Quoted 37 lines · Huisong Li
Quoted 13 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.Quoted 9 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
Same comment from past seems already valid, I am not looking to the set for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2
Quoted 1 line
I am not exactly clear what is the intention with
set(),
That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Quoted 4 lines
if there is
single MAC I guess intention is to replace it with new one, but if there are multiple MACs and one of them are already in the list intention may be just to change the default MAC.
The assumption in this patch is that "Set" means "Replace", not "Swap". So this patch takes the approach 1/ Replace and keep Unique.
Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}
This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.
Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?
RE: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 88 lines
From: Thomas Monjalon [mailto:[email protected]]
Sent: Thursday, 2 February 2023 22.1102/02/2023 19:09, Ferruh Yigit:
Quoted 2 lines · Huisong Li
Quoted 1 line
The dev->data->mac_addrs[0] will be changed to a new MAC address
when
Quoted 1 line
Quoted 1 line
applications modify the default MAC address by .mac_addr_set().
However,
Quoted 1 line
Quoted 1 line
if the new default one has been added as a non-default MAC address
by
Quoted 1 line
Quoted 1 line
.mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrsQuoted 1 line
Quoted 1 line
list. As a result, one MAC address occupies two entries in the
list. Like:
Quoted 9 lines
Quoted 9 lines
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do
remove the
Quoted 2 lines
Quoted 2 lines
old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5,filters=(MAC1,
Quoted 1 line
Quoted 1 line
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the
list,
Quoted 3 lines
Quoted 3 lines
but packets with MAC3 aren't actually received by the PMD.
So need to ensure that the new default address is removed from the
rest of
Quoted 4 lines
Quoted 2 lines
the list if the address was already in the list.
Same comment from past seems already valid, I am not looking to the
set
Quoted 12 lines
for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2Quoted 1 line
I am not exactly clear what is the intention with
set(),That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Quoted 2 lines
if there is
single MAC I guess intention is to replace it with new one, but ifthere
Quoted 1 line
are multiple MACs and one of them are already in the list intention
may
Quoted 1 line
be just to change the default MAC.
The assumption in this patch is that "Set" means "Replace", not "Swap". So this patch takes the approach 1/ Replace and keep Unique.
Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
Quoted 5 lines
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?
If there is only one MAC, MAC1, I would certainly expect Set(MAC2) to replace MAC1 with MAC2.
If there is a list of MACs, I might expect Set() to select one in the list. And, if calling Set() with a MAC not in the list, we could either 1. return an error, or 2. implicitly add it to the list and then set it.
If we implicitly add it to the list (i.e. follow option 2 described above), it should not be implicitly be removed from the list if another MAC is Set(). This behavior seems weird, which speaks for returning an error if setting a MAC not in the list (i.e. option 1).
Disclaimer: I have no experience configuring NICs with multiple MACs - we promiscuous mode or one MAC address. So my input regarding multiple MACs is purely theoretical.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
In reply to Thomas MonjalonQuoted 37 lines · Thomas Monjalon
02/02/2023 19:09, Ferruh Yigit:
Quoted 36 lines · Huisong Li
Quoted 13 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.Quoted 9 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
Same comment from past seems already valid, I am not looking to the set for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2
Quoted 3 lines
Quoted 1 line
I am not exactly clear what is the intention with
set(),That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Indeed. But we can see the following information.
From the ethdev layer, this set() API always replaces the old default address (index 0) without adding the old one. From the PMD layer, set() interface of some PMDs, such as i40e, ice, hns3 and so on (as far as I know), also do remove the hardware entry of the old default address.
Quoted 28 lines
Quoted 5 lines
if there is
single MAC I guess intention is to replace it with new one, but if there are multiple MACs and one of them are already in the list intention may be just to change the default MAC.The assumption in this patch is that "Set" means "Replace", not "Swap". So this patch takes the approach 1/ Replace and keep Unique.
Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
Quoted 5 lines
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?
According to the implement of set() in ethdev and PMD layer, it always use "Replace", not "Swap". If we use "Swap" now, the behavior of this API will be changed.
I'm not sure if the application can accept this change or has other effects.
BTW, it seems that the ethernet port in kernel also replaces the old address if we modify the one. Use the test command: ifconfig eth0 hw ether new_mac
Quoted 3 lines
.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 47 lines · lihuisong (C)
Quoted 45 lines · Thomas Monjalon
02/02/2023 19:09, Ferruh Yigit:
Quoted 44 lines · Huisong Li
Quoted 25 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However,
if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from themac_addrs
list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the
old default MAC when set default MAC. If user continues to doset_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1,
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list,
but packets with MAC3 aren't actually received by the PMD.Quoted 4 lines
So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Same comment from past seems already valid, I am not looking to the set for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2I am not exactly clear what is the intention with
set(),
Quoted 8 lines
Quoted 2 lines
That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Indeed. But we can see the following information.
From the ethdev layer, thisset()API always replaces the old default address (index 0) without adding the old one.
From the PMD layer,set()interface of some PMDs, such as i40e, ice, hns3 and so on (as far as I know),
also do remove the hardware entry of the old default address.
If we define behavior clearly, I think we can adapt PMD implementation according it, unless there is HW limitation.
Quoted 31 lines
Quoted 31 lines
Quoted 5 lines
if there is
single MAC I guess intention is to replace it with new one, but if there are multiple MACs and one of them are already in the list intention may be just to change the default MAC.The assumption in this patch is that "Set" means "Replace", not "Swap". So this patch takes the approach 1/ Replace and keep Unique.
Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
Quoted 8 lines
Quoted 2 lines
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?According to the implement of
set()in ethdev and PMD layer, it always use "Replace", not "Swap".
If we use "Swap" now, the behavior of this API will be changed. I'm not sure if the application can accept this change or has other effects.
This patch is also changing behavior, because of implied remove address, same concern is valid with this patch.
As I checked again current implementation may have one more problem (this from reading code, I did not test this):
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
set(MAC2) -> MAC2, MAC2
del(MAC2) -> FAILS
This fails because rte_eth_dev_mac_addr_remove() can't remove default MAC, and it only tries to remove first address it finds, it can't find and remove second 'MAC2'.
I wasn't too much bothered with wasting one MAC address slot, so wasn't sure if a change is required at all, but if above analysis is correct I think this is more serious problem to justify the change.
I don't think always swap (option /3) is good idea, specially for single MAC address exists case, and current case has (option 0/) has mentioned problems.
Remaining ones are mix of swap and replace (option 2/) and this patch (option /1).
I think mix of swap and replace (option 2/ above) has some benefits:
- It always replaces default MAC
- Prevents duplication MAC address in the list
- Doesn't implicitly remove address from list
BUT, if the agreement is this patch (option 1/) I am OK with that too, I just want to make sure that it is discussed.
Quoted 3 lines
BTW, it seems that the ethernet port in kernel also replaces the old address if we modify the one.
Use the test command: ifconfig eth0 hw ethernew_mac
For default MAC address it is more clear that intention is to replace it, but question is about what to do with the list of MAC addresses.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 49 lines · Ferruh Yigit
Quoted 48 lines · lihuisong (C)
Quoted 47 lines · Thomas Monjalon
02/02/2023 19:09, Ferruh Yigit:
Quoted 43 lines · Huisong Li
Quoted 25 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However,
if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from themac_addrs
list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the
old default MAC when set default MAC. If user continues to doset_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1,
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list,
but packets with MAC3 aren't actually received by the PMD.Quoted 4 lines
So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Same comment from past seems already valid, I am not looking to the set for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2Quoted 1 line
I am not exactly clear what is the intention with
set(),That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Quoted 8 lines
Quoted 6 lines
Indeed. But we can see the following information.
From the ethdev layer, thisset()API always replaces the old default
address (index 0) without adding the old one.
From the PMD layer,set()interface of some PMDs, such as i40e, ice,
hns3 and so on (as far as I know),
also do remove the hardware entry of the old default address.If we define behavior clearly, I think we can adapt PMD implementation according it, unless there is HW limitation.
Right. I think this is another point (issue 2/) to be discussed.
Namely, whether the old default address should be removed when set new default one.
If we want to explicitly unify the behavior of all PMDs in ethdev layer as described above, there may be no problem if do the following:
1) In the ethdev layer, remove the old default address if the old one is exist.
2) For PMD i40e, ice and hns3, remvoe the code of deleting the old default address before adding the new one. For other PMDs, we probably don't need to do anything because they have supported remove_addr() API. (Without explicitly removing the old default address, I don't know if their hardware or firmware removes the old one when set a new address. But, we explicitly remove the old one in ethdev layer now, I'm not sure if this has an effect on these PMDs.)
Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 4 lines
if there is
single MAC I guess intention is to replace it with new one, but if there are multiple MACs and one of them are already in the list intention may be just to change the default MAC.The assumption in this patch is that "Set" means "Replace", not "Swap". So this patch takes the approach 1/ Replace and keep Unique.
Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?
Quoted 8 lines
Quoted 6 lines
According to the implement of
set()in ethdev and PMD layer, it always use "Replace", not "Swap".
If we use "Swap" now, the behavior of this API will be changed. I'm not sure if the application can accept this change or has other effects.This patch is also changing behavior, because of implied remove address, same concern is valid with this patch.
Indeed, it changes the behavior.
But this patch only resolves the problem (issue 1/) that the entries of the MAC address list possibly are not uniques. Fixing it may be little impact on the application.
Quoted 9 lines
As I checked again current implementation may have one more problem (this from reading code, I did not test this):
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
set(MAC2) -> MAC2, MAC2
del(MAC2) -> FAILS
Quoted 6 lines
This fails because
rte_eth_dev_mac_addr_remove()can't remove default MAC, and it only tries to remove first address it finds, it can't find and remove second 'MAC2'.
I wasn't too much bothered with wasting one MAC address slot, so wasn't sure if a change is required at all, but if above analysis is correct I think this is more serious problem to justify the change.
Your analysis is fully correct.
Quoted 5 lines
I don't think always swap (option /3) is good idea, specially for single MAC address exists case, and current case has (option 0/) has mentioned problems.
+1
Quoted 7 lines
Remaining ones are mix of swap and replace (option 2/) and this patch (option /1).
I think mix of swap and replace (option 2/ above) has some benefits:
- It always replaces default MAC
- Prevents duplication MAC address in the list
- Doesn't implicitly remove address from list
As far as I know, the first entry (index 0) always be the default address in all PMDs, but it's not documented. (So this patch did it, that's what was discussed earlier). The 'Swap' may be inappropriate. It may need to be discussed.
Quoted 10 lines
BUT, if the agreement is this patch (option 1/) I am OK with that too, I just want to make sure that it is discussed.
Quoted 3 lines
BTW, it seems that the ethernet port in kernel also replaces the old address if we modify the one.
Use the test command: ifconfig eth0 hw ethernew_macFor default MAC address it is more clear that intention is to replace it, but question is about what to do with the list of MAC addresses.
Hi Ferruh and Thomas,
As mentioned above, they are actually two problems (issue /1 and issue /2). Can we deal with them separately?
#1 For issue /1, it's really a problem. This patch is responsible for it. #2 For issue /2, I will send a RFC to discuss as described above. It may require the participation of all PMD maintainers.
What do you think?
/Huisong
Quoted 2 lines
.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 156 lines · lihuisong (C)
Quoted 49 lines · Ferruh Yigit
Quoted 48 lines · lihuisong (C)
Quoted 47 lines · Thomas Monjalon
02/02/2023 19:09, Ferruh Yigit:
Quoted 43 lines · Huisong Li
Quoted 25 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However,
if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from themac_addrs
list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the
old default MAC when set default MAC. If user continues to doset_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1,
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list,
but packets with MAC3 aren't actually received by the PMD.Quoted 4 lines
So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Same comment from past seems already valid, I am not looking to the set for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2Quoted 1 line
I am not exactly clear what is the intention with
set(),That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Quoted 8 lines
Quoted 6 lines
Indeed. But we can see the following information.
From the ethdev layer, thisset()API always replaces the old default address (index 0) without adding the old one.
From the PMD layer,set()interface of some PMDs, such as i40e, ice, hns3 and so on (as far as I know),
also do remove the hardware entry of the old default address.If we define behavior clearly, I think we can adapt PMD implementation according it, unless there is HW limitation.
Right. I think this is another point (issue 2/) to be discussed.
Namely, whether the old default address should be removed when set new default one.
If we want to explicitly unify the behavior of all PMDs in ethdev layer as described above, there may be no problem if do the following:
1) In the ethdev layer, remove the old default address if the old one is exist.
2) For PMD i40e, ice and hns3, remvoe the code of deleting the old default address before adding the new one. For other PMDs, we probably don't need to do anything because they have supportedremove_addr()API. (Without explicitly removing the old default address, I don't know if their hardware or firmware removes the old one when set a new address. But, we explicitly remove the old one in ethdev layer now, I'm not sure if this has an effect on these PMDs.)Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 4 lines
if there is
single MAC I guess intention is to replace it with new one, but if there are multiple MACs and one of them are already in the list intention may be just to change the default MAC.The assumption in this patch is that "Set" means "Replace", not "Swap". So this patch takes the approach 1/ Replace and keep Unique.
Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?Quoted 8 lines
Quoted 6 lines
According to the implement of
set()in ethdev and PMD layer, it always use "Replace", not "Swap".
If we use "Swap" now, the behavior of this API will be changed. I'm not sure if the application can accept this change or has other effects.This patch is also changing behavior, because of implied remove address, same concern is valid with this patch.
Indeed, it changes the behavior.
But this patch only resolves the problem (issue 1/) that the entries of the MAC address list possibly are not uniques. Fixing it may be little impact on the application.Quoted 9 lines
As I checked again current implementation may have one more problem (this from reading code, I did not test this):
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
set(MAC2) -> MAC2, MAC2
del(MAC2) -> FAILSQuoted 6 lines
This fails because
rte_eth_dev_mac_addr_remove()can't remove default MAC, and it only tries to remove first address it finds, it can't find and remove second 'MAC2'.
I wasn't too much bothered with wasting one MAC address slot, so wasn't sure if a change is required at all, but if above analysis is correct I think this is more serious problem to justify the change.Your analysis is fully correct.
Quoted 5 lines
I don't think always swap (option /3) is good idea, specially for single MAC address exists case, and current case has (option 0/) has mentioned problems.
+1
Quoted 7 lines
Remaining ones are mix of swap and replace (option 2/) and this patch (option /1).
I think mix of swap and replace (option 2/ above) has some benefits:
- It always replaces default MAC
- Prevents duplication MAC address in the list
- Doesn't implicitly remove address from listAs far as I know, the first entry (index 0) always be the default address in all PMDs, but it's not documented. (So this patch did it, that's what was discussed earlier). The 'Swap' may be inappropriate. It may need to be discussed.
Quoted 10 lines
BUT, if the agreement is this patch (option 1/) I am OK with that too, I just want to make sure that it is discussed.
Quoted 3 lines
BTW, it seems that the ethernet port in kernel also replaces the old address if we modify the one.
Use the test command: ifconfig eth0 hw ethernew_macFor default MAC address it is more clear that intention is to replace it, but question is about what to do with the list of MAC addresses.
Hi Ferruh and Thomas,
Quoted 9 lines
As mentioned above, they are actually two problems (issue /1 and issue /2). Can we deal with them separately?
#1 For issue /1, it's really a problem. This patch is responsible for it. #2 For issue /2, I will send a RFC to discuss as described above. It may require the participation of all PMD maintainers.What do you think?
Hi Ferruh and Thomas,
What do you think of the above proposal?
Looking forward to your reply.
/Huisong
Quoted 3 lines
Quoted 2 lines
.
.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
In reply to lihuisong (C)Quoted 152 lines · lihuisong (C)
Quoted 50 lines · Ferruh Yigit
Quoted 49 lines · lihuisong (C)
Quoted 48 lines · Thomas Monjalon
02/02/2023 19:09, Ferruh Yigit:
Quoted 44 lines · Huisong Li
Quoted 25 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However,
if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from themac_addrs
list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the
old default MAC when set default MAC. If user continues to doset_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1,
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list,
but packets with MAC3 aren't actually received by the PMD.Quoted 4 lines
So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Same comment from past seems already valid, I am not looking to the set
for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2Quoted 1 line
I am not exactly clear what is the intention with
set(),That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Quoted 8 lines
Quoted 6 lines
Indeed. But we can see the following information.
From the ethdev layer, thisset()API always replaces the old default address (index 0) without adding the old one.
From the PMD layer,set()interface of some PMDs, such as i40e, ice, hns3 and so on (as far as I know),
also do remove the hardware entry of the old default address.If we define behavior clearly, I think we can adapt PMD implementation according it, unless there is HW limitation.
Right. I think this is another point (issue 2/) to be discussed. Namely, whether the old default address should be removed when set new default one.
If we want to explicitly unify the behavior of all PMDs in ethdev layer as described above,
there may be no problem if do the following:
1) In the ethdev layer, remove the old default address if the old one is exist.
2) For PMD i40e, ice and hns3, remvoe the code of deleting the old default address before adding the new one.
For other PMDs, we probably don't need to do anything because they have supportedremove_addr()API.
(Without explicitly removing the old default address, I don't know if their hardware or firmware
removes the old one when set a new address. But, we explicitly remove the old one in ethdev layer now,
I'm not sure if this has an effect on these PMDs.)Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 6 lines
if there is
single MAC I guess intention is to replace it with new one, but if there
are multiple MACs and one of them are already in the list intention may
be just to change the default MAC.The assumption in this patch is that "Set" means "Replace", not "Swap". So this patch takes the approach 1/ Replace and keep Unique.
Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?Quoted 8 lines
Quoted 6 lines
According to the implement of
set()in ethdev and PMD layer, it always use "Replace", not "Swap".
If we use "Swap" now, the behavior of this API will be changed. I'm not sure if the application can accept this change or has other effects.This patch is also changing behavior, because of implied remove address, same concern is valid with this patch.
Indeed, it changes the behavior.
But this patch only resolves the problem (issue 1/) that the entries of the MAC address list possibly are not uniques.
Fixing it may be little impact on the application.Quoted 9 lines
As I checked again current implementation may have one more problem (this from reading code, I did not test this):
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
set(MAC2) -> MAC2, MAC2
del(MAC2) -> FAILSQuoted 6 lines
This fails because
rte_eth_dev_mac_addr_remove()can't remove default MAC, and it only tries to remove first address it finds, it can't find and remove second 'MAC2'.
I wasn't too much bothered with wasting one MAC address slot, so wasn't sure if a change is required at all, but if above analysis is correct I think this is more serious problem to justify the change.Your analysis is fully correct.
Quoted 5 lines
I don't think always swap (option /3) is good idea, specially for single MAC address exists case, and current case has (option 0/) has mentioned problems.
+1
Quoted 7 lines
Remaining ones are mix of swap and replace (option 2/) and this patch (option /1).
I think mix of swap and replace (option 2/ above) has some benefits:
- It always replaces default MAC
- Prevents duplication MAC address in the list
- Doesn't implicitly remove address from list
Quoted 5 lines
As far as I know, the first entry (index 0) always be the default address in all PMDs,
but it's not documented. (So this patch did it, that's what was discussed earlier).
The 'Swap' may be inappropriate. It may need to be discussed.
Yes, index 0 always holds the default MAC, +1 to document this.
In option /2, MAC swap is done only if the MAC address is already in the list.
Another option can be to store an enabled/disabled flag for each MAC address in the list.
In set(MAC), if MAC is already in the list, the existing one in the list can be disabled. Next time default MAC changed, disabled MAC can be enabled again. Like:
(d) => disabled
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC3(d), MAC4
set(MAC4) -> MAC4, MAC2, MAC3, MAC4(d)
set(MAC2) -> MAC2, MAC2(d), MAC3, MAC4
set(MAC5) -> MAC5, MAC2, MAC3, MAC4
The ones disabled in the ethdev layer can be explicitly removed in drivers, and the ones enabled in the ethdev layer can be explicitly added back in drives. This simplifies the driver implementation a lot.
Quoted 12 lines
Quoted 10 lines
BUT, if the agreement is this patch (option 1/) I am OK with that too, I just want to make sure that it is discussed.
Quoted 3 lines
BTW, it seems that the ethernet port in kernel also replaces the old address if we modify the one.
Use the test command: ifconfig eth0 hw ethernew_macFor default MAC address it is more clear that intention is to replace it, but question is about what to do with the list of MAC addresses.
Hi Ferruh and Thomas,
Quoted 8 lines
As mentioned above, they are actually two problems (issue /1 and issue /2). Can we deal with them separately?
#1 For issue /1, it's really a problem. This patch is responsible for it. #2 For issue /2, I will send a RFC to discuss as described above. It may require the participation of all PMD maintainers.What do you think?
Agree to separate fixing drivers (issue /2) and ethdev (issue /1), and drivers can be fixed after ethdev clarified.
Sorry that this patch is taking time because expected behavior is not clear, and we are not getting enough feedback for it. Also issue is not a major or a blocking issue.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 155 lines · Ferruh Yigit
Quoted 149 lines · lihuisong (C)
Quoted 50 lines · Ferruh Yigit
Quoted 49 lines · lihuisong (C)
Quoted 48 lines · Thomas Monjalon
02/02/2023 19:09, Ferruh Yigit:
Quoted 44 lines · Huisong Li
Quoted 25 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However,
if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from themac_addrs
list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the
old default MAC when set default MAC. If user continues to doset_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1,
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list,
but packets with MAC3 aren't actually received by the PMD.Quoted 4 lines
So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Same comment from past seems already valid, I am not looking to the set
for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2Quoted 1 line
I am not exactly clear what is the intention with
set(),That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Quoted 8 lines
Quoted 6 lines
Indeed. But we can see the following information.
From the ethdev layer, thisset()API always replaces the old default
address (index 0) without adding the old one.
From the PMD layer,set()interface of some PMDs, such as i40e, ice,
hns3 and so on (as far as I know),
also do remove the hardware entry of the old default address.If we define behavior clearly, I think we can adapt PMD implementation according it, unless there is HW limitation.
Right. I think this is another point (issue 2/) to be discussed. Namely, whether the old default address should be removed when set new default one.
If we want to explicitly unify the behavior of all PMDs in ethdev layer as described above,
there may be no problem if do the following:
1) In the ethdev layer, remove the old default address if the old one is exist.
2) For PMD i40e, ice and hns3, remvoe the code of deleting the old default address before adding the new one.
For other PMDs, we probably don't need to do anything because they
have supportedremove_addr()API.
(Without explicitly removing the old default address, I don't know if
their hardware or firmware
removes the old one when set a new address. But, we explicitly
remove the old one in ethdev layer now,
I'm not sure if this has an effect on these PMDs.)Quoted 34 lines
Quoted 34 lines
Quoted 34 lines
Quoted 6 lines
if there is
single MAC I guess intention is to replace it with new one, but if there
are multiple MACs and one of them are already in the list intention may
be just to change the default MAC.The assumption in this patch is that "Set" means "Replace", not "Swap". So this patch takes the approach 1/ Replace and keep Unique.
Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?Quoted 8 lines
Quoted 6 lines
According to the implement of
set()in ethdev and PMD layer, it always use "Replace", not "Swap".
If we use "Swap" now, the behavior of this API will be changed. I'm not sure if the application can accept this change or has other effects.This patch is also changing behavior, because of implied remove address, same concern is valid with this patch.
Indeed, it changes the behavior.
But this patch only resolves the problem (issue 1/) that the entries of the MAC address list possibly are not uniques.
Fixing it may be little impact on the application.Quoted 8 lines
As I checked again current implementation may have one more problem (this from reading code, I did not test this):
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
set(MAC2) -> MAC2, MAC2
del(MAC2) -> FAILSQuoted 6 lines
This fails because
rte_eth_dev_mac_addr_remove()can't remove default MAC, and it only tries to remove first address it finds, it can't find and remove second 'MAC2'.
I wasn't too much bothered with wasting one MAC address slot, so wasn't sure if a change is required at all, but if above analysis is correct I think this is more serious problem to justify the change.Your analysis is fully correct.
Quoted 4 lines
I don't think always swap (option /3) is good idea, specially for single MAC address exists case, and current case has (option 0/) has mentioned problems.
+1
Quoted 7 lines
Remaining ones are mix of swap and replace (option 2/) and this patch (option /1).
I think mix of swap and replace (option 2/ above) has some benefits:
- It always replaces default MAC
- Prevents duplication MAC address in the list
- Doesn't implicitly remove address from listQuoted 5 lines
As far as I know, the first entry (index 0) always be the default address in all PMDs,
but it's not documented. (So this patch did it, that's what was discussed earlier).
The 'Swap' may be inappropriate. It may need to be discussed.
Quoted 5 lines
Yes, index 0 always holds the default MAC, +1 to document this.
In option /2, MAC swap is done only if the MAC address is already in the list.
Whether the 'swap' is required in this case depends on the assumption that the old default address needs to be 'secondary' address when set new default one, right? It is still the same issue as issue /2 to be discussed.
Quoted 17 lines
Another option can be to store an enabled/disabled flag for each MAC address in the list.
In set(MAC), if MAC is already in the list, the existing one in the list can be disabled. Next time default MAC changed, disabled MAC can be enabled again. Like:(d) => disabled
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC3(d), MAC4
set(MAC4) -> MAC4, MAC2, MAC3, MAC4(d)
set(MAC2) -> MAC2, MAC2(d), MAC3, MAC4
set(MAC5) -> MAC5, MAC2, MAC3, MAC4
Quoted 4 lines
The ones disabled in the ethdev layer can be explicitly removed in drivers, and the ones enabled in the ethdev layer can be explicitly added back in drives. This simplifies the driver implementation a lot.
Good idea, but it's a little complicated.
If I understand correctly, all of the above are done under the condition that 'swap' is accepted.
Quoted 17 lines
Quoted 17 lines
Quoted 9 lines
BUT, if the agreement is this patch (option 1/) I am OK with that too, I just want to make sure that it is discussed.
Quoted 3 lines
BTW, it seems that the ethernet port in kernel also replaces the old address if we modify the one.
Use the test command: ifconfig eth0 hw ethernew_macFor default MAC address it is more clear that intention is to replace it, but question is about what to do with the list of MAC addresses.
Hi Ferruh and Thomas,
As mentioned above, they are actually two problems (issue /1 and issue /2). Can we deal with them separately?
#1 For issue /1, it's really a problem. This patch is responsible for it. #2 For issue /2, I will send a RFC to discuss as described above.
It may require the participation of all PMD maintainers.
Quoted 4 lines
Quoted 2 lines
What do you think?
Agree to separate fixing drivers (issue /2) and ethdev (issue /1), and drivers can be fixed after ethdev clarified.
Yeah, we are in the same boat.😁
Quoted 2 lines
Sorry that this patch is taking time because expected behavior is not
I cannot understand the behavior determined by this patch is not expected.
Wouldn't it be simpler and more reasonable to make sure that the entries in the MAC list are uniques?
Quoted 2 lines
clear, and we are not getting enough feedback for it. Also issue is not a major or a blocking issue.
IMO, the last point to be discussed and have enough feedback is the issue /2 instead of issue /1. Whether the old default address needs to be removed or swapped when set new one is the major or a blocking issue.
We can't go back and forth between them. we should break the cycle.
For issue /1 (duplicate entries), please forget what to do with the old default address. I'm sure you'll think it's ok. Let's take a new discussion for the old default address in set() API to get enough feedback.
what do you think, Ferruh and Thomas?
Quoted 2 lines
.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 169 lines · lihuisong (C)
Quoted 167 lines · Ferruh Yigit
Quoted 159 lines · lihuisong (C)
Quoted 61 lines · Ferruh Yigit
Quoted 53 lines · lihuisong (C)
Quoted 49 lines · Thomas Monjalon
02/02/2023 19:09, Ferruh Yigit:
Quoted 48 lines · Huisong Li
Quoted 29 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when
applications modify the default MAC address by .mac_addr_set(). However,
if the new default one has been added as a non-default MAC address by
.mac_addr_add(), the .mac_addr_set() doesn't remove it from themac_addrs
list. As a result, one MAC address occupies two entries in the list.
Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove
the
old default MAC when set default MAC. If user continues to doset_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1,
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list,
but packets with MAC3 aren't actually received by the PMD.Quoted 4 lines
So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Same comment from past seems already valid, I am not looking to the set
for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2Quoted 3 lines
Quoted 1 line
I am not exactly clear what is the intention with
set(),That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Quoted 7 lines
Indeed. But we can see the following information.
From the ethdev layer, thisset()API always replaces the old default
address (index 0) without adding the old one.
From the PMD layer,set()interface of some PMDs, such as i40e, ice, hns3 and so on (as far as I know),
also do remove the hardware entry of the old default address.Quoted 2 lines
If we define behavior clearly, I think we can adapt PMD implementation according it, unless there is HW limitation.
Right. I think this is another point (issue 2/) to be discussed. Namely, whether the old default address should be removed when set new default one.
If we want to explicitly unify the behavior of all PMDs in ethdev layer as described above,
there may be no problem if do the following:
1) In the ethdev layer, remove the old default address if the old one is exist.
2) For PMD i40e, ice and hns3, remvoe the code of deleting the old default address before adding the new one.
For other PMDs, we probably don't need to do anything because they have supportedremove_addr()API.
(Without explicitly removing the old default address, I don't know if
their hardware or firmware
removes the old one when set a new address. But, we explicitly remove the old one in ethdev layer now,
I'm not sure if this has an effect on these PMDs.)Quoted 42 lines
Quoted 34 lines
Quoted 34 lines
Quoted 6 lines
if there is
single MAC I guess intention is to replace it with new one, but if there
are multiple MACs and one of them are already in the list intention may
be just to change the default MAC.The assumption in this patch is that "Set" means "Replace", not "Swap".
So this patch takes the approach 1/ Replace and keep Unique.Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
Quoted 8 lines
Quoted 2 lines
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?According to the implement of
set()in ethdev and PMD layer, it always use "Replace", not "Swap".
If we use "Swap" now, the behavior of this API will be changed. I'm not sure if the application can accept this change or has other effects.Quoted 3 lines
This patch is also changing behavior, because of implied remove address,
same concern is valid with this patch.Indeed, it changes the behavior.
But this patch only resolves the problem (issue 1/) that the entries of the MAC address list possibly are not uniques.
Fixing it may be little impact on the application.Quoted 8 lines
As I checked again current implementation may have one more problem (this from reading code, I did not test this):
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
set(MAC2) -> MAC2, MAC2
del(MAC2) -> FAILSQuoted 6 lines
This fails because
rte_eth_dev_mac_addr_remove()can't remove default MAC, and it only tries to remove first address it finds, it can't find and remove second 'MAC2'.
I wasn't too much bothered with wasting one MAC address slot, so wasn't sure if a change is required at all, but if above analysis is correct I think this is more serious problem to justify the change.Your analysis is fully correct.
Quoted 5 lines
I don't think always swap (option /3) is good idea, specially for single
MAC address exists case, and current case has (option 0/) has mentioned problems.+1
Quoted 7 lines
Remaining ones are mix of swap and replace (option 2/) and this patch (option /1).
I think mix of swap and replace (option 2/ above) has some benefits:
- It always replaces default MAC
- Prevents duplication MAC address in the list
- Doesn't implicitly remove address from listQuoted 5 lines
As far as I know, the first entry (index 0) always be the default address in all PMDs,
but it's not documented. (So this patch did it, that's what was discussed earlier).
The 'Swap' may be inappropriate. It may need to be discussed.Yes, index 0 always holds the default MAC, +1 to document this.
Quoted 7 lines
Quoted 3 lines
In option /2, MAC swap is done only if the MAC address is already in the list.
Whether the 'swap' is required in this case depends on the assumption that the
old default address needs to be 'secondary' address when set new default one, right?
We don't know if default address needs to be 'secondary' address or not, swap is just a way to both keep list unique and don't implicit remove any MAC address.
Quoted 17 lines
It is still the same issue as issue /2 to be discussed.>> Another option can be to store an enabled/disabled flag for each MAC
Quoted 16 lines
address in the list.
In set(MAC), if MAC is already in the list, the existing one in the list can be disabled. Next time default MAC changed, disabled MAC can be enabled again. Like:(d) => disabled
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC3(d), MAC4
set(MAC4) -> MAC4, MAC2, MAC3, MAC4(d)
set(MAC2) -> MAC2, MAC2(d), MAC3, MAC4
set(MAC5) -> MAC5, MAC2, MAC3, MAC4
Quoted 7 lines
Quoted 4 lines
The ones disabled in the ethdev layer can be explicitly removed in drivers, and the ones enabled in the ethdev layer can be explicitly added back in drives. This simplifies the driver implementation a lot.
Good idea, but it's a little complicated.
If I understand correctly, all of the above are done under the condition that 'swap' is accepted.
Agree it is more complicated, and no this doesn't require swap.
Instead of implicitly removing duplicated MAC address it keeps in the ethdev list as disabled, and adds it back when default MAC is changed.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 10 lines
BUT, if the agreement is this patch (option 1/) I am OK with that too, I
just want to make sure that it is discussed.Quoted 3 lines
BTW, it seems that the ethernet port in kernel also replaces the old address if we modify the one.
Use the test command: ifconfig eth0 hw ethernew_macFor default MAC address it is more clear that intention is to replace it, but question is about what to do with the list of MAC addresses.
Hi Ferruh and Thomas,
As mentioned above, they are actually two problems (issue /1 and issue /2).
Can we deal with them separately?
#1 For issue /1, it's really a problem. This patch is responsible for it.
#2 For issue /2, I will send a RFC to discuss as described above. It may require the participation of all PMD maintainers.What do you think?
Quoted 8 lines
Quoted 2 lines
Agree to separate fixing drivers (issue /2) and ethdev (issue /1), and drivers can be fixed after ethdev clarified.
Yeah, we are in the same boat.😁
Quoted 2 lines
Sorry that this patch is taking time because expected behavior is not
I cannot understand the behavior determined by this patch is not expected. Wouldn't it be simpler and more reasonable to make sure that the entries in the MAC list are uniques?
Yes, above part is OK. Only problem is it may cause shrinking the MAC list by setting MAC address, that may not be the expected behavior.
Quoted 7 lines
Quoted 2 lines
clear, and we are not getting enough feedback for it. Also issue is not a major or a blocking issue.
IMO, the last point to be discussed and have enough feedback is the issue /2 instead of issue /1.
Whether the old default address needs to be removed or swapped when set new one is the major or a blocking issue.
Quoted 7 lines
We can't go back and forth between them. we should break the cycle. For issue /1 (duplicate entries), please forget what to do with the old default address. I'm sure you'll think it's ok.
Let's take a new discussion for the old default address inset()API to get enough feedback.what do you think, Ferruh and Thomas?
Does it work to present options to techboard, get a decision and proceed with it?
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 235 lines · Ferruh Yigit
Quoted 166 lines · lihuisong (C)
Quoted 165 lines · Ferruh Yigit
Quoted 157 lines · lihuisong (C)
Quoted 61 lines · Ferruh Yigit
Quoted 53 lines · lihuisong (C)
Quoted 49 lines · Thomas Monjalon
02/02/2023 19:09, Ferruh Yigit:
Quoted 48 lines · Huisong Li
Quoted 29 lines
The dev->data->mac_addrs[0] will be changed to a new MAC address when
applications modify the default MAC address by .mac_addr_set(). However,
if the new default one has been added as a non-default MAC address by
.mac_addr_add(), the .mac_addr_set() doesn't remove it from themac_addrs
list. As a result, one MAC address occupies two entries in the list.
Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove
the
old default MAC when set default MAC. If user continues to doset_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1,
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list,
but packets with MAC3 aren't actually received by the PMD.Quoted 4 lines
So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Same comment from past seems already valid, I am not looking to the set
for a while, sorry if this is already discussed and decided, if not, I am referring to the side effect that setting MAC addresses cause to remove MAC addresses, think following case:add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC4
set(MAC4) -> MAC4, MAC2
set(MAC2) -> MAC2Quoted 3 lines
Quoted 1 line
I am not exactly clear what is the intention with
set(),That's the problem, nobody is clear with the current behavior. The doc says "Set the default MAC address." and nothing else.
Quoted 7 lines
Indeed. But we can see the following information.
From the ethdev layer, thisset()API always replaces the old
default
address (index 0) without adding the old one.
From the PMD layer,set()interface of some PMDs, such as i40e, ice,
hns3 and so on (as far as I know),
also do remove the hardware entry of the old default address.Quoted 2 lines
If we define behavior clearly, I think we can adapt PMD implementation according it, unless there is HW limitation.
Right. I think this is another point (issue 2/) to be discussed. Namely, whether the old default address should be removed when set new default one.
If we want to explicitly unify the behavior of all PMDs in ethdev layer as described above,
there may be no problem if do the following:
1) In the ethdev layer, remove the old default address if the old one is exist.
2) For PMD i40e, ice and hns3, remvoe the code of deleting the old default address before adding the new one.
For other PMDs, we probably don't need to do anything because they
have supportedremove_addr()API.
(Without explicitly removing the old default address, I don't
know if
their hardware or firmware
removes the old one when set a new address. But, we explicitly
remove the old one in ethdev layer now,
I'm not sure if this has an effect on these PMDs.)Quoted 42 lines
Quoted 34 lines
Quoted 34 lines
Quoted 6 lines
if there is
single MAC I guess intention is to replace it with new one, but if there
are multiple MACs and one of them are already in the list intention may
be just to change the default MAC.The assumption in this patch is that "Set" means "Replace", not "Swap".
So this patch takes the approach 1/ Replace and keep Unique.Quoted 11 lines
If above assumption is correct, what about following:
set(MAC) {
ifonly_default_mac_exist
replace_default_macif MAC exists in list
swap MAC and list[0]
else
replace_default_mac
}This approach 2/ is a mix of Swap and Replace.
The old default MAC destiny depends on whether
we have added the new MAC as "secondary" before setting as new default.Quoted 1 line
This swap prevents removing MAC side affect, does it make sense?
Another approach would be 3/ to do an "Always Swap" even if the new MAC didn't exist before, you keep the old default MAC as a secondary MAC.
And the current approach 0/ is to Replace default MAC address without touching the secondary addresses at all.
Quoted 8 lines
Quoted 2 lines
So we have 4 choices.
We could vote, roll a dice, or find a strong argument?According to the implement of
set()in ethdev and PMD layer, it always use "Replace", not "Swap".
If we use "Swap" now, the behavior of this API will be changed. I'm not sure if the application can accept this change or has other effects.Quoted 3 lines
This patch is also changing behavior, because of implied remove address,
same concern is valid with this patch.Indeed, it changes the behavior.
But this patch only resolves the problem (issue 1/) that the entries of the MAC address list possibly are not uniques.
Fixing it may be little impact on the application.Quoted 7 lines
As I checked again current implementation may have one more problem (this from reading code, I did not test this):
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
set(MAC2) -> MAC2, MAC2
del(MAC2) -> FAILSQuoted 6 lines
This fails because
rte_eth_dev_mac_addr_remove()can't remove default MAC, and it only tries to remove first address it finds, it can't find and remove second 'MAC2'.
I wasn't too much bothered with wasting one MAC address slot, so wasn't sure if a change is required at all, but if above analysis is correct I think this is more serious problem to justify the change.Your analysis is fully correct.
Quoted 4 lines
I don't think always swap (option /3) is good idea, specially for single
MAC address exists case, and current case has (option 0/) has mentioned problems.+1
Quoted 7 lines
Remaining ones are mix of swap and replace (option 2/) and this patch (option /1).
I think mix of swap and replace (option 2/ above) has some benefits:
- It always replaces default MAC
- Prevents duplication MAC address in the list
- Doesn't implicitly remove address from listQuoted 5 lines
As far as I know, the first entry (index 0) always be the default address in all PMDs,
but it's not documented. (So this patch did it, that's what was discussed earlier).
The 'Swap' may be inappropriate. It may need to be discussed.Yes, index 0 always holds the default MAC, +1 to document this.
Quoted 7 lines
Quoted 3 lines
In option /2, MAC swap is done only if the MAC address is already in the list.
Whether the 'swap' is required in this case depends on the assumption that the
old default address needs to be 'secondary' address when set new default one, right?We don't know if default address needs to be 'secondary' address or not, swap is just a way to both keep list unique and don't implicit remove any MAC address.
Quoted 17 lines
It is still the same issue as issue /2 to be discussed.>> Another option can be to store an enabled/disabled flag for each MAC
Quoted 16 lines
address in the list.
In set(MAC), if MAC is already in the list, the existing one in the list can be disabled. Next time default MAC changed, disabled MAC can be enabled again. Like:(d) => disabled
add(MAC1) -> MAC1
add(MAC2) -> MAC1, MAC2
add(MAC3) -> MAC1, MAC2, MAC3
add(MAC4) -> MAC1, MAC2, MAC3, MAC4
set(MAC3) -> MAC3, MAC2, MAC3(d), MAC4
set(MAC4) -> MAC4, MAC2, MAC3, MAC4(d)
set(MAC2) -> MAC2, MAC2(d), MAC3, MAC4
set(MAC5) -> MAC5, MAC2, MAC3, MAC4Quoted 7 lines
Quoted 4 lines
The ones disabled in the ethdev layer can be explicitly removed in drivers, and the ones enabled in the ethdev layer can be explicitly added back in drives. This simplifies the driver implementation a lot.
Good idea, but it's a little complicated.
If I understand correctly, all of the above are done under the condition that 'swap' is accepted.Agree it is more complicated, and no this doesn't require swap.
Instead of implicitly removing duplicated MAC address it keeps in the ethdev list as disabled, and adds it back when default MAC is changed.
Quoted 24 lines
Quoted 24 lines
Quoted 20 lines
Quoted 10 lines
BUT, if the agreement is this patch (option 1/) I am OK with that too, I
just want to make sure that it is discussed.Quoted 3 lines
BTW, it seems that the ethernet port in kernel also replaces the old address if we modify the one.
Use the test command: ifconfig eth0 hw ethernew_macFor default MAC address it is more clear that intention is to replace it, but question is about what to do with the list of MAC addresses.
Hi Ferruh and Thomas,
As mentioned above, they are actually two problems (issue /1 and issue /2).
Can we deal with them separately?
#1 For issue /1, it's really a problem. This patch is responsible for it.
#2 For issue /2, I will send a RFC to discuss as described above.
It may require the participation of all PMD maintainers.Quoted 2 lines
What do you think?
Agree to separate fixing drivers (issue /2) and ethdev (issue /1), and drivers can be fixed after ethdev clarified.
Quoted 8 lines
Quoted 5 lines
Yeah, we are in the same boat.😁
Quoted 1 line
Sorry that this patch is taking time because expected behavior is not
I cannot understand the behavior determined by this patch is not expected. Wouldn't it be simpler and more reasonable to make sure that the entries in the MAC list are uniques?
Yes, above part is OK. Only problem is it may cause shrinking the MAC list by setting MAC address, that may not be the expected behavior.
The root cause of shrinking the MAC list is that the old default address is removed when set MAC address, rather than removing the address being already in the rest of the list.
Quoted 15 lines
Quoted 15 lines
Quoted 4 lines
clear, and we are not getting enough feedback for it. Also issue is not a major or a blocking issue.
IMO, the last point to be discussed and have enough feedback is the issue /2 instead of issue /1.
Whether the old default address needs to be removed or swapped when set new one is the major or a blocking issue.We can't go back and forth between them. we should break the cycle. For issue /1 (duplicate entries), please forget what to do with the old default address. I'm sure you'll think it's ok.
Let's take a new discussion for the old default address inset()API to get enough feedback.
Quoted 3 lines
Quoted 1 line
what do you think, Ferruh and Thomas?
Does it work to present options to techboard, get a decision and proceed with it?
Agreed. At least, there's a decision soon.
Quoted 1 line
.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
In reply to Huisong LiHi Ferruh,
There is no result on techboard.
How to deal with this problem next?
/Huisong
Quoted 158 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of the list if the address was already in the list.
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>---
v8: fix some comments.
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.--- doc/guides/rel_notes/release_23_03.rst | 6 +++++ lib/ethdev/ethdev_driver.h | 6 ++++- lib/ethdev/rte_ethdev.c | 35 ++++++++++++++++++++++++-- lib/ethdev/rte_ethdev.h | 3 +++ 4 files changed, 47 insertions(+), 3 deletions(-)doc/guides/rel_notes/release_23_03.rst +6
-0@@ -105,6 +105,12 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: ensured all entries in MAC address list are uniques. + When setting a default MAC address with the function + ``rte_eth_dev_default_mac_addr_set``, + the address is now removed from the rest of the address list + in order to ensure it is only at index 0 of the list. + ABI Changes -----------lib/ethdev/ethdev_driver.h +5
-1@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. +* The first entry (index zero) is the default address. +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];lib/ethdev/rte_ethdev.c +33
-2@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4517,16 +4520,44 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* Keep address unique in dev->data->mac_addrs[]. */ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR ,"Cannot remove the port %u address from the rest of list.\n" , + port_id); +return ret; + } + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto out;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +out: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) { +if (rte_eth_dev_mac_addr_add (port_id, addr, + pool) !=0 ) +RTE_ETHDEV_LOG (ERR ,"failed to restore MAC pool id(%u) in port %u.\n" , + pool, port_id); + } + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk !=0 ); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find lib/ethdev/rte_ethdev.h +3
-0@@ -4356,6 +4356,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* it is removed from the rest of the list. * * @param port_id * The port identifier of the Ethernet device.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 4 lines · lihuisong (C)
Hi Ferruh,
There is no result on techboard.
How to deal with this problem next?
+techboard for comment.
Btw, what was your positioning to Bruce's suggestion,
when a MAC address is in the list, fail to set it as default and enforce user do the corrective action (delete MAC explicitly etc...). If you are OK with it, that is good for me too, unless techboard objects we can proceed with that one.
Quoted 162 lines
/Huisong
Quoted 158 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>---
v8: fix some comments.
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
---
doc/guides/rel_notes/release_23_03.rst| 6 +++++ lib/ethdev/ethdev_driver.h | 6 ++++- lib/ethdev/rte_ethdev.c | 35 ++++++++++++++++++++++++-- lib/ethdev/rte_ethdev.h | 3 +++4 files changed, 47 insertions(+), 3 deletions(-)doc/guides/rel_notes/release_23_03.rst +0
-0@@ -105,6 +105,12 @@ API ChangesAlso, make sure to start the actual text at the margin.
=======================================================
+* ethdev: ensured all entries in MAC address list are uniques. + When setting a default MAC address with the function + ``rte_eth_dev_default_mac_addr_set``,
+ the address is now removed from the rest of the address list + in order to ensure it is only at index 0 of the list. +
ABI Changes
-----------lib/ethdev/ethdev_driver.h +0
-0@@ -117,7 +117,11 @@ struct rte_eth_dev_data {
uint64_trx_mbuf_alloc_failed; /**< Rx ring mbuf allocation failures */
- /** Device Ethernet link address. @seerte_eth_dev_release_port()*/
+ /**
+ * Device Ethernet link addresses.
+ * All entries are unique.
+ * The first entry (index zero) is the default address. + */
structrte_ether_addr*mac_addrs;
/** Bitmap associating MAC addresses to pools */uint64_tmac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR];lib/ethdev/rte_ethdev.c +0
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int
rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
{
+uint64_tmac_pool_sel_bk= 0;
structrte_eth_dev*dev;
+uint32_tpool;
+ int index;
int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);lib/ethdev/rte_ethdev.c +0
-0@@ -4517,16 +4520,44 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (*dev->dev_ops->mac_addr_set == NULL) return -ENOTSUP;+ /* Keep address unique in dev->data->mac_addrs[]. */ + index =
eth_dev_get_mac_addr_index(port_id, addr);
+ if (index > 0) {
+ /* Remove address in dev data structure */
+mac_pool_sel_bk= dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove(port_id, addr); + if (ret < 0) {
+ RTE_ETHDEV_LOG(ERR, "Cannot remove the port %u address from the rest of list.\n",
+port_id);
+ return ret;
+ }
+ }
ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
if (ret < 0)
- return ret;
+ goto out;
/* Update default address in NIC data structure */rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]); return 0;
-}
+out:
+ if (index > 0) {
+ pool = 0;
+ do {
+ if (mac_pool_sel_bk&UINT64_C(1)) {
+ if (rte_eth_dev_mac_addr_add(port_id, addr, + pool)!= 0)
+ RTE_ETHDEV_LOG(ERR, "failed to restore MAC pool id(%u) in port %u.\n",
+ pool,port_id);
+ }
+mac_pool_sel_bk>>= 1;
+ pool++;
+ } while (mac_pool_sel_bk!= 0);
+ }lib/ethdev/rte_ethdev.c +3
-0+ + return ret; +}/*
* Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to findlib/ethdev/rte_ethdev.h +3
-0@@ -4356,6 +4356,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id, /*** Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* it is removed from the rest of the list. * * @param port_id * The port identifier of the Ethernet device.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 11 lines · Ferruh Yigit
Quoted 4 lines · lihuisong (C)
Hi Ferruh,
There is no result on techboard.
How to deal with this problem next?+techboard for comment.
Btw, what was your positioning to Bruce's suggestion,
when a MAC address is in the list, fail to set it as default and enforce user do the corrective action (delete MAC explicitly etc...).
If a MAC address is in the list, rte_eth_dev_default_mac_addr_set returns failure?
Quoted 166 lines
If you are OK with it, that is good for me too, unless techboard objects we can proceed with that one.
Quoted 153 lines
/Huisong
Quoted 150 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from the
mac_addrslist. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>---
v8: fix some comments.
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.--- doc/guides/rel_notes/release_23_03.rst | 6 +++++ lib/ethdev/ethdev_driver.h | 6 ++++- lib/ethdev/rte_ethdev.c | 35 ++++++++++++++++++++++++-- lib/ethdev/rte_ethdev.h | 3 +++ 4 files changed, 47 insertions(+), 3 deletions(-)doc/guides/rel_notes/release_23_03.rst +5
-0@@ -105,6 +105,12 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= +* ethdev: ensured all entries in MAC address list are uniques. + When setting a default MAC address with the function + ``rte_eth_dev_default_mac_addr_set``, + the address is now removed from the rest of the address list + in order to ensure it is only at index 0 of the list. + ABI Changes -----------lib/ethdev/ethdev_driver.h +0
-0@@ -117,7 +117,11 @@ struct rte_eth_dev_data { uint64_t rx_mbuf_alloc_failed; /**< Rx ring mbuf allocationfailures */
- /** Device Ethernet link address. @seerte_eth_dev_release_port()*/
+ /**
+ * Device Ethernet link addresses.
+ * All entries are unique.
+ * The first entry (index zero) is the default address. + */
structrte_ether_addr*mac_addrs;
/** Bitmap associating MAC addresses to pools */uint64_tmac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR];lib/ethdev/rte_ethdev.c +3
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr) int rte_eth_dev_default_mac_addr_set(uint16_t port_id, structrte_ether_addr *addr) { + uint64_t mac_pool_sel_bk = 0; struct rte_eth_dev *dev; + uint32_t pool; + int index; int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);lib/ethdev/rte_ethdev.c +28
-2@@ -4517,16 +4520,44 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (*dev->dev_ops->mac_addr_set == NULL) return -ENOTSUP; + /* Keep address unique in dev->data->mac_addrs[]. */ + index = eth_dev_get_mac_addr_index(port_id, addr); + if (index > 0) { + /* Remove address in dev data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret = rte_eth_dev_mac_addr_remove(port_id, addr); + if (ret < 0) { + RTE_ETHDEV_LOG(ERR, "Cannot remove the port %u address from the rest of list.\n", + port_id); + return ret; + } + } ret = (*dev->dev_ops->mac_addr_set)(dev, addr); if (ret < 0) - return ret; + goto out; /* Update default address in NIC data structure */ rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]); return 0; -} +out: + if (index > 0) { + pool = 0; + do { + if (mac_pool_sel_bk & UINT64_C(1)) { + if (rte_eth_dev_mac_addr_add(port_id, addr, + pool) != 0) + RTE_ETHDEV_LOG(ERR, "failed to restore MAC pool id(%u) in port %u.\n", + pool, port_id); + } + mac_pool_sel_bk >>= 1; + pool++; + } while (mac_pool_sel_bk != 0); + } + + return ret; +} /** Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
lib/ethdev/rte_ethdev.h +0
-0@@ -4356,6 +4356,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,Quoted 8 lines
lib/ethdev/rte_ethdev.h int rte_eth_dev_mac_addr_remove(uint16_t port_id, · line 4364
Quoted 8 lines
lib/ethdev/rte_ethdev.h +3
-0/*** Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* it is removed from the rest of the list. * * @param port_id * The port identifier of the Ethernet device. .
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 7 lines · lihuisong (C)
Quoted 5 lines · Ferruh Yigit
Quoted 4 lines · lihuisong (C)
Hi Ferruh,
There is no result on techboard.
How to deal with this problem next?
Quoted 8 lines
Quoted 6 lines
+techboard for comment.
Btw, what was your positioning to Bruce's suggestion,
when a MAC address is in the list, fail to set it as default and enforce user do the corrective action (delete MAC explicitly etc...).If a MAC address is in the list,
rte_eth_dev_default_mac_addr_setreturns failure?
Yes.
In that case API can return EEXIST or similar. In this case user need to call 'rte_eth_dev_mac_addr_remove()' first and call 'rte_eth_dev_default_mac_addr_set()' again, if this is the intention.
Quoted 173 lines
Quoted 173 lines
If you are OK with it, that is good for me too, unless techboard objects we can proceed with that one.
Quoted 160 lines
/Huisong
Quoted 157 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However,
if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() doesn't remove it from themac_addrs
list. As a result, one MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the
old default MAC when set default MAC. If user continues to doset_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1,
MAC2, MAC3, MAC4). At this moment, user can still see MAC3 from the list,
but packets with MAC3 aren't actually received by the PMD.So need to ensure that the new default address is removed from the rest of
the list if the address was already in the list.Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>---
v8: fix some comments.
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
---
doc/guides/rel_notes/release_23_03.rst| 6 +++++ lib/ethdev/ethdev_driver.h | 6 ++++- lib/ethdev/rte_ethdev.c | 35
++++++++++++++++++++++++--
lib/ethdev/rte_ethdev.h | 3 +++4 files changed, 47 insertions(+), 3 deletions(-)doc/guides/rel_notes/release_23_03.rst +0
-0@@ -105,6 +105,12 @@ API ChangesAlso, make sure to start the actual text at the margin.
=======================================================
+* ethdev: ensured all entries in MAC address list are uniques. + When setting a default MAC address with the function + ``rte_eth_dev_default_mac_addr_set``,
+ the address is now removed from the rest of the address list + in order to ensure it is only at index 0 of the list. +
ABI Changes
-----------lib/ethdev/ethdev_driver.h +0
-0@@ -117,7 +117,11 @@ struct rte_eth_dev_data {
uint64_trx_mbuf_alloc_failed; /**< Rx ring mbuf allocation failures */
- /** Device Ethernet link address. @seerte_eth_dev_release_port()*/
+ /**
+ * Device Ethernet link addresses.
+ * All entries are unique.
+ * The first entry (index zero) is the default address. + */
structrte_ether_addr*mac_addrs;
/** Bitmap associating MAC addresses to pools */uint64_tmac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR];lib/ethdev/rte_ethdev.c +0
-0@@ -4498,7 +4498,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int
rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
{
+uint64_tmac_pool_sel_bk= 0;
structrte_eth_dev*dev;
+uint32_tpool;
+ int index;
int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);lib/ethdev/rte_ethdev.c +0
-0@@ -4517,16 +4520,44 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) if (*dev->dev_ops->mac_addr_set == NULL) return -ENOTSUP;+ /* Keep address unique in dev->data->mac_addrs[]. */ + index =
eth_dev_get_mac_addr_index(port_id, addr);
+ if (index > 0) {
+ /* Remove address in dev data structure */
+mac_pool_sel_bk= dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove(port_id, addr); + if (ret < 0) {
+ RTE_ETHDEV_LOG(ERR, "Cannot remove the port %u address from the rest of list.\n",
+port_id);
+ return ret;
+ }
+ }
ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
if (ret < 0)
- return ret;
+ goto out;
/* Update default address in NIC data structure */rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]); return 0;
-}
+out:
+ if (index > 0) {
+ pool = 0;
+ do {
+ if (mac_pool_sel_bk&UINT64_C(1)) {
+ if (rte_eth_dev_mac_addr_add(port_id, addr, + pool)!= 0)
+ RTE_ETHDEV_LOG(ERR, "failed to restore MAC pool id(%u) in port %u.\n",
+ pool,port_id);
+ }
+mac_pool_sel_bk>>= 1;
+ pool++;
+ } while (mac_pool_sel_bk!= 0);
+ }lib/ethdev/rte_ethdev.c +3
-0+ + return ret; +}/*
* Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to findlib/ethdev/rte_ethdev.h +0
-0@@ -4356,6 +4356,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,Quoted 8 lines
lib/ethdev/rte_ethdev.h int rte_eth_dev_mac_addr_remove(uint16_t port_id, · line 4364
Quoted 8 lines
lib/ethdev/rte_ethdev.h +3
-0/*** Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* it is removed from the rest of the list. * * @param port_id * The port identifier of the Ethernet device. .
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 13 lines · Ferruh Yigit
Quoted 12 lines · lihuisong (C)
Quoted 11 lines · Ferruh Yigit
Quoted 4 lines · lihuisong (C)
Hi Ferruh,
There is no result on techboard.
How to deal with this problem next?+techboard for comment.
Btw, what was your positioning to Bruce's suggestion,
when a MAC address is in the list, fail to set it as default and enforce user do the corrective action (delete MAC explicitly etc...).
Quoted 6 lines
Quoted 2 lines
If a MAC address is in the list,
rte_eth_dev_default_mac_addr_setreturns failure?Yes.
In that case API can return EEXIST or similar. In this case user need to call 'rte_eth_dev_mac_addr_remove()' first and call 'rte_eth_dev_default_mac_addr_set()' again, if this is the intention.
lgtm.
send V9 to do this?
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
If you are OK with it, that is good for me too, unless techboard objects we can proceed with that one.
Re: [PATCH V8] ethdev: fix one address occupies two entries in MAC addrs
Quoted 18 lines · lihuisong (C)
Quoted 16 lines · Ferruh Yigit
Quoted 15 lines · lihuisong (C)
Quoted 5 lines · Ferruh Yigit
Quoted 4 lines · lihuisong (C)
Hi Ferruh,
There is no result on techboard.
How to deal with this problem next?Quoted 7 lines
+techboard for comment.
Btw, what was your positioning to Bruce's suggestion, when a MAC address is in the list, fail to set it as default and enforce
user do the corrective action (delete MAC explicitly etc...).If a MAC address is in the list,
rte_eth_dev_default_mac_addr_setreturns failure?
Quoted 8 lines
Quoted 4 lines
Yes.
In that case API can return EEXIST or similar. In this case user need to call 'rte_eth_dev_mac_addr_remove()' first and call 'rte_eth_dev_default_mac_addr_set()' again, if this is the intention.lgtm.
send V9 to do this?
I am happy to proceed with a v9 unless there is no objection from techboard.
PATCH v9 1/1 ethdev: fix one address occupies two entries in MAC addrs
In reply to Huisong LiThe dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() didn't check this address. As a result, this MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.
But .mac_addr_set() cannot remove it implicitly in case of MAC address shrinking in the list.
So this patch adds a check on whether the new default address was already in the list and if so requires the user to remove it first.
In addition, this patch documents the position of the default MAC address and address unique in the list.
---
v9: request user to remove the address instead of doing it implicitly in
.mac_addr_set() API.
v8: fix some comments.
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
--- doc/guides/rel_notes/release_23_07.rst | 5 +++++ lib/ethdev/ethdev_driver.h | 6 +++++- lib/ethdev/rte_ethdev.c | 10 ++++++++++ lib/ethdev/rte_ethdev.h | 3 +++ 4 files changed, 23 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_23_07.rst +5 -0
@@ -96,6 +96,11 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= + * ethdev: ensured all entries in MAC address list are uniques. + When setting a default MAC address with the function + ``rte_eth_dev_default_mac_addr_set``, + the default one needs to be removed by user if it was already in + the list. ABI Changes -----------
lib/ethdev/ethdev_driver.h +5 -1
@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. +* The first entry (index zero) is the default address. +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
lib/ethdev/rte_ethdev.c +10 -0
@@ -4898,6 +4898,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4916,6 +4917,15 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* Keep address unique in dev->data->mac_addrs[]. */ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +RTE_ETHDEV_LOG (ERR , +"New default address for port %u was already in the address list. Please remove it first.\n" , + port_id); +return -EEXIST ; + } + ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 )return ret;
lib/ethdev/rte_ethdev.h +3 -0
@@ -4381,6 +4381,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* please remove it first. * * @param port_id * The port identifier of the Ethernet device.
Signature · 1 line
2.33.0
Re: [PATCH V9] ethdev: fix one address occupies two entries in MAC addrs
lib/ethdev/rte_ethdev.h int rte_eth_dev_mac_addr_remove(uint16_t port_id, · line 4386
Quoted 11 lines · Huisong Li
lib/ethdev/rte_ethdev.h +3
-0@@ -4381,6 +4381,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* please remove it first.
Can you please document last sentences under '@return' as (-EEXIST) error type?
Re: [PATCH V9] ethdev: fix one address occupies two entries in MAC addrs
Quoted 7 lines · Ferruh Yigit
Quoted 6 lines · Huisong Li
lib/ethdev/rte_ethdev.h +0
-0@@ -4381,6 +4381,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,
Quoted 8 lines
lib/ethdev/rte_ethdev.h int rte_eth_dev_mac_addr_remove(uint16_t port_id, · line 4386
Quoted 5 lines
lib/ethdev/rte_ethdev.h +3
-0/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* please remove it first. Can you please document last sentences under '@return' as (
-EEXIST) error type?
ok, v10 send later.
Quoted 1 line
.
PATCH v10 1/1 ethdev: fix one address occupies two entries in MAC addrs
In reply to Huisong LiThe dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() didn't check this address. As a result, this MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.
But .mac_addr_set() cannot remove it implicitly in case of MAC address shrinking in the list.
So this patch adds a check on whether the new default address was already in the list and if so requires the user to remove it first.
In addition, this patch documents the position of the default MAC address and address unique in the list.
---
v10: add '-EEXIST' error type case under @return.
v9: request user to remove the address instead of doing it implicitly in
.mac_addr_set() API.
v8: fix some comments.
v7: add announcement in the release notes and document this behavior.
v6: fix commit log and some code comments.
v5:
- merge the second patch into the first patch.
- add error log when rollback failed.
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
--- doc/guides/rel_notes/release_23_07.rst | 5 +++++ lib/ethdev/ethdev_driver.h | 6 +++++- lib/ethdev/rte_ethdev.c | 10 ++++++++++ lib/ethdev/rte_ethdev.h | 4 ++++ 4 files changed, 24 insertions(+), 1 deletion(-)
doc/guides/rel_notes/release_23_07.rst +5 -0
@@ -96,6 +96,11 @@ API Changes Also, make sure to start the actual text at the margin. ======================================================= + * ethdev: ensured all entries in MAC address list are uniques. + When setting a default MAC address with the function + ``rte_eth_dev_default_mac_addr_set``, + the default one needs to be removed by user if it was already in + the list. ABI Changes -----------
lib/ethdev/ethdev_driver.h +5 -1
@@ -117,7 +117,11 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link addresses. +* All entries are unique. +* The first entry (index zero) is the default address. +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
lib/ethdev/rte_ethdev.c +10 -0
@@ -4898,6 +4898,7 @@ int rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) { struct rte_eth_dev *dev; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4916,6 +4917,15 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)if (*dev->dev_ops->mac_addr_set ==NULL )return -ENOTSUP ; +/* Keep address unique in dev->data->mac_addrs[]. */ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +RTE_ETHDEV_LOG (ERR , +"New default address for port %u was already in the address list. Please remove it first.\n" , + port_id); +return -EEXIST ; + } + ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 )return ret;
lib/ethdev/rte_ethdev.h +4 -0
@@ -4381,6 +4381,9 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,/** * Set the default MAC address. +* It replaces the address at index 0 of the MAC address list. +* If the address was already in the MAC address list, +* please remove it first. * * @param port_id * The port identifier of the Ethernet device.
@@ -4391,6 +4394,7 @@ int rte_eth_dev_mac_addr_remove(uint16_t port_id,* - (-ENOTSUP) if hardware doesn't support. * - (-ENODEV) if *port* invalid. * - (-EINVAL) if MAC address is invalid. +* - (-EEXIST) if MAC address was already in the address list. */ int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *mac_addr);
Signature · 1 line
2.33.0
Re: [PATCH V10] ethdev: fix one address occupies two entries in MAC addrs
Quoted 18 lines · Huisong Li
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by .mac_addr_set(). However, if the new default one has been added as a non-default MAC address by .mac_addr_add(), the .mac_addr_set() didn't check this address. As a result, this MAC address occupies two entries in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, the rest of the list=MAC1, MAC2, MAC3, MAC4
Note: MAC3 occupies two entries.But .mac_addr_set() cannot remove it implicitly in case of MAC address shrinking in the list.
So this patch adds a check on whether the new default address was already in the list and if so requires the user to remove it first.
Quoted 6 lines
In addition, this patch documents the position of the default MAC address and address unique in the list.
Signed-off-by Huisong Li <[email protected]>Acked-by Chengwen Feng <[email protected]>Acked-by Thomas Monjalon <[email protected]>
Applied to dpdk-next-net/main, thanks.
v3 cover ethdev: fix MAC addrs list
In reply to Min Hu (Connor)From: Huisong Li <[email protected]>
The index zero of rte_eth_dev_data::mac_addrs array is as the default MAC index, and other indexes can't be the same as the address corresponding to index 0. If we break it, may cause following problems:
1) waste of MAC address spaces.
2) a fake MAC address in the MAC list, isn't in hardware MAC entries.
3) a MAC address is assigned to diffent pool.
Huisong Li (2):
ethdev: fix one address occupies two indexes in MAC addrs
ethdev: document default and non-default MAC address
---
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
lib/ethdev/ethdev_driver.h | 7 ++++++- lib/ethdev/rte_ethdev.c | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-)
Signature · 1 line
2.33.0
PATCH v3 1/2 ethdev: fix one address occupies two indexes in MAC addrs
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by rte_eth_dev_default_mac_addr_set(). However, if the new default one has been added as a non-default MAC address by rte_eth_dev_mac_addr_add(), the the rte_eth_dev_default_mac_addr_set() doesn't remove it from the mac_addrs list. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do set_default(MAC5), and the mac_addrs list is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still view MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
--- lib/ethdev/rte_ethdev.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c +37 -2
@@ -4248,7 +4248,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4266,16 +4269,48 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->mac_addr_set, -ENOTSUP ); +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* remove address in NIC data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR , +"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id); +return ret; + } +/* reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } + ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto back;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +back: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) +rte_eth_dev_mac_addr_add (port_id, addr, pool); + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
Signature · 1 line
2.33.0
PATCH v3 2/2 ethdev: document default and non-default MAC address
In reply to Min Hu (Connor)From: Huisong Li <[email protected]>
The rte_eth_dev_data::mac_addrs is a MAC address array. The index zero of this array is as the default address index, and other indexes can't be the same as the address corresponding to index 0. If we break it, may cause following problems:
1) waste of MAC address spaces.
2) a fake MAC address in the MAC list, isn't in hardware MAC entries.
3) a MAC address is assigned to diffent pool.
--- lib/ethdev/ethdev_driver.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/ethdev/ethdev_driver.h +6 -1
@@ -115,7 +115,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the +* index of the default address, and other indexes can't be the same +* as the address corresponding to index 0. +* @see rte_eth_dev_release_port() +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
Signature · 1 line
2.33.0
Re: [PATCH V3 0/2] ethdev: fix MAC addrs list
In reply to Min Hu (Connor)Quoted 8 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The index zero of
rte_eth_dev_data::mac_addrsarray is as the default MAC index, and other indexes can't be the same as the address corresponding to index 0. If we break it, may cause following problems:
1) waste of MAC address spaces.
2) a fake MAC address in the MAC list, isn't in hardware MAC entries.
3) a MAC address is assigned to diffent pool.
The series looks broken in the patchwork. As the result unit tests are run in a strange way. Please, format patches once again and send v4.
Re: [PATCH V3 0/2] ethdev: fix MAC addrs list
Hi, Andrew,
v4 has been sent. Thanks.
Quoted 14 lines · Andrew Rybchenko
Quoted 8 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The index zero of
rte_eth_dev_data::mac_addrsarray is as the default MAC index, and other indexes can't be the same as the address corresponding to index 0. If we break it, may cause following problems:
1) waste of MAC address spaces.
2) a fake MAC address in the MAC list, isn't in hardware MAC entries.
3) a MAC address is assigned to diffent pool.The series looks broken in the patchwork. As the result unit tests are run in a strange way. Please, format patches once again and send v4.
.
v4 cover ethdev: fix MAC addrs list
In reply to Min Hu (Connor)The index zero of rte_eth_dev_data::mac_addrs array is as the default MAC index, and other indexes can't be the same as the address corresponding to index 0. If we break it, may cause following problems:
1) waste of MAC address spaces.
2) a fake MAC address in the MAC list, isn't in hardware MAC entries.
3) a MAC address is assigned to diffent pool.
Huisong Li (2):
ethdev: fix one address occupies two indexes in MAC addrs
ethdev: document default and non-default MAC address
---
v4:
- fix broken in the patchwork
v3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
v2:
- fixed commit log.
lib/ethdev/ethdev_driver.h | 7 ++++++- lib/ethdev/rte_ethdev.c | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-)
Signature · 1 line
2.33.0
PATCH v4 1/2 ethdev: fix one address occupies two indexes in MAC addrs
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by rte_eth_dev_default_mac_addr_set(). However, if the new default one has been added as a non-default MAC address by rte_eth_dev_mac_addr_add(), the the rte_eth_dev_default_mac_addr_set() doesn't remove it from the mac_addrs list. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do set_default(MAC5), and the mac_addrs list is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still view MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
--- lib/ethdev/rte_ethdev.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-)
lib/ethdev/rte_ethdev.c +37 -2
@@ -4260,7 +4260,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );
@@ -4278,16 +4281,48 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->mac_addr_set, -ENOTSUP ); +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* remove address in NIC data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR , +"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id); +return ret; + } +/* reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } + ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto back;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);return 0 ; -} +back: +if (index >0 ) { + pool =0 ; +do { +if (mac_pool_sel_bk &UINT64_C (1 )) +rte_eth_dev_mac_addr_add (port_id, addr, pool); + mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk); + } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
Signature · 1 line
2.33.0
Re: [PATCH v4 1/2] ethdev: fix one address occupies two indexes in MAC addrs
Quoted 15 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set(). However, if the new default one has been added as a non-default MAC address byrte_eth_dev_mac_addr_add(), the therte_eth_dev_default_mac_addr_set()doesn't remove it from themac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4
Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still view MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.
IMHO, the main problem is inconsistency which exists right now. rte_eth_dev_mac_addr_add() checks for duplicate MAC addition including the default one (index zero) and extends the entry pool mask (including zero entry case).
However, the patch above does not extend zero entry pool mask. So, the result will depend on order which is bad:
A. Set default to A, add MAC A with pool 2 => pool mask has 2 B. Add MAC A with pool 2, set default to A => pool mask is empty
Am I missing something in the code?
What is the right/intended behaviour?
Quoted 56 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu <[email protected]>--- lib/ethdev/rte_ethdev.c | 39 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-)lib/ethdev/rte_ethdev.c +24
-1@@ -4260,7 +4260,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int rte_eth_dev_default_mac_addr_set (uint16_t port_id,struct rte_ether_addr *addr) { +uint64_t mac_pool_sel_bk =0 ;struct rte_eth_dev *dev; +uint32_t pool; +int index;int ret;RTE_ETH_VALID_PORTID_OR_ERR_RET (port_id, -ENODEV );@@ -4278,16 +4281,48 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->mac_addr_set, -ENOTSUP ); +/* +* If the address has been added as a non-default MAC address by +* rte_eth_dev_mac_addr_add API, it should be removed from +* dev->data->mac_addrs[]. +*/ + index =eth_dev_get_mac_addr_index (port_id, addr); +if (index >0 ) { +/* remove address in NIC data structure */ + mac_pool_sel_bk = dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove (port_id, addr); +if (ret <0 ) { +RTE_ETHDEV_LOG (ERR , +"Delete MAC address from the MAC list of ethdev port %u.\n" , + port_id); +return ret; + } +/* reset pool bitmap */ + dev->data->mac_pool_sel[index] =0 ; + } + ret = (*dev->dev_ops->mac_addr_set)(dev, addr);if (ret <0 ) -return ret; + goto back;/* Update default address in NIC data structure */ rte_ether_addr_copy (addr, &dev->data->mac_addrs[0 ]);
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4318
Quoted 10 lines
lib/ethdev/rte_ethdev.c +6
-1return 0 ; -} +back: +if (index >0 ) { + pool =0 ; + do { + if (mac_pool_sel_bk & UINT64_C(1)) + rte_eth_dev_mac_addr_add(port_id, addr, pool);
Don't we want to have at least error logs in the case of rollback failure here?
lib/ethdev/rte_ethdev.c rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) · line 4321
Quoted 3 lines
lib/ethdev/rte_ethdev.c +3
-0+ mac_pool_sel_bk >>=1 ; + pool++; + }while (mac_pool_sel_bk);
Please, compare vs 0 explicitly.
Quoted 7 lines
lib/ethdev/rte_ethdev.c +4
-0+ } + +return ret; +}/* * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
Re: [PATCH v4 1/2] ethdev: fix one address occupies two indexes in MAC addrs
Quoted 27 lines · Andrew Rybchenko
Quoted 15 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set(). However, if the new default one has been added as a non-default MAC address byrte_eth_dev_mac_addr_add(), the therte_eth_dev_default_mac_addr_set()doesn't remove it from themac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still view MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.IMHO, the main problem is inconsistency which exists right now.
rte_eth_dev_mac_addr_add()checks for duplicate MAC addition including the default one (index zero) and extends the entry pool mask (including zero entry case).
Quoted 5 lines
However, the patch above does not extend zero entry pool mask. So, the result will depend on order which is bad:
A. Set default to A, add MAC A with pool 2 => pool mask has 2 B. Add MAC A with pool 2, set default to A => pool mask is empty
I don't know how this MAC pool works in which driver.
However, the 'eth_dev_mac_restore' API show that 1) the default MAC has only pool zero if set it by the 'mac_addr_add', 2) the default one hasn't pool information if set it by 'default_mac_addr_set'.
Do you mean we should inherit its pool mask in this case?
Quoted 61 lines
Am I missing something in the code?
What is the right/intended behaviour?Quoted 58 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu <[email protected]>---
lib/ethdev/rte_ethdev.c| 39 +++++++++++++++++++++++++++++++++++++--1 file changed, 37 insertions(+), 2 deletions(-)lib/ethdev/rte_ethdev.c +0
-0@@ -4260,7 +4260,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int
rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr){
+uint64_tmac_pool_sel_bk= 0;
structrte_eth_dev*dev;
+uint32_tpool;
+ int index;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);lib/ethdev/rte_ethdev.c +0
-0@@ -4278,16 +4281,48 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->mac_addr_set, -ENOTSUP );+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);
+ if (index > 0) {
+ /* remove address in NIC data structure */
+mac_pool_sel_bk= dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove(port_id, addr); + if (ret < 0) {
+ RTE_ETHDEV_LOG(ERR,
+ "Delete MAC address from the MAC list of ethdev port %u.\n",
+port_id);
+ return ret;
+ }
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0;
+ }
+
ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
if (ret < 0)
- return ret;
+ goto back;
/* Update default address in NIC data structure */rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]); return 0;
-}
+back:
Quoted 8 lines
Quoted 5 lines
+ if (index > 0) {
+ pool = 0;
+ do {
+ if (mac_pool_sel_bk&UINT64_C(1))
+rte_eth_dev_mac_addr_add(port_id, addr, pool);Don't we want to have at least error logs in the case of rollback failure here?
It doesn't feel necessary. It may trigger the printing of a large number of error logs in abnormal scenarios.
Quoted 6 lines
Quoted 4 lines
+
mac_pool_sel_bk>>= 1;
+ pool++;
+ } while (mac_pool_sel_bk);Please, compare vs 0 explicitly.
Ack
Quoted 9 lines
Quoted 7 lines
+ }
lib/ethdev/rte_ethdev.c +3
-0+ + return ret; +}/*
* Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find.
Re: [PATCH v4 1/2] ethdev: fix one address occupies two indexes in MAC addrs
Cc more driver maintainers
Quoted 29 lines · lihuisong (C)
Quoted 27 lines · Andrew Rybchenko
Quoted 15 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set(). However, if the new default one has been added as a non-default MAC address byrte_eth_dev_mac_addr_add(), the therte_eth_dev_default_mac_addr_set()doesn't remove it from themac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still view MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.IMHO, the main problem is inconsistency which exists right now.
rte_eth_dev_mac_addr_add()checks for duplicate MAC addition including the default one (index zero) and extends the entry pool mask (including zero entry case).
Quoted 6 lines
Quoted 5 lines
However, the patch above does not extend zero entry pool mask. So, the result will depend on order which is bad:
A. Set default to A, add MAC A with pool 2 => pool mask has 2 B. Add MAC A with pool 2, set default to A => pool mask is emptyI don't know how this MAC pool works in which driver.
Me too
Quoted 5 lines
However, the '
eth_dev_mac_restore' API show that 1) the default MAC has only pool zero if set it by the 'mac_addr_add', 2) the default one hasn't pool information if set it by 'default_mac_addr_set'.Do you mean we should inherit its pool mask in this case?
I simply want to make it consistent
Quoted 69 lines
Quoted 61 lines
Am I missing something in the code?
What is the right/intended behaviour?Quoted 58 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu <[email protected]>---
lib/ethdev/rte_ethdev.c| 39 +++++++++++++++++++++++++++++++++++++--1 file changed, 37 insertions(+), 2 deletions(-)lib/ethdev/rte_ethdev.c +0
-0@@ -4260,7 +4260,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int
rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr){
+uint64_tmac_pool_sel_bk= 0;
structrte_eth_dev*dev;
+uint32_tpool;
+ int index;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);lib/ethdev/rte_ethdev.c +0
-0@@ -4278,16 +4281,48 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->mac_addr_set, -ENOTSUP );+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);
+ if (index > 0) {
+ /* remove address in NIC data structure */
+mac_pool_sel_bk= dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove(port_id, addr); + if (ret < 0) {
+ RTE_ETHDEV_LOG(ERR,
+ "Delete MAC address from the MAC list of ethdev port %u.\n",
+port_id);
+ return ret;
+ }
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0;
+ }
+
ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
if (ret < 0)
- return ret;
+ goto back;
/* Update default address in NIC data structure */rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]); return 0;
-}
+back:Quoted 8 lines
Quoted 5 lines
+ if (index > 0) {
+ pool = 0;
+ do {
+ if (mac_pool_sel_bk&UINT64_C(1))
+rte_eth_dev_mac_addr_add(port_id, addr, pool);Don't we want to have at least error logs in the case of rollback failure here?
Quoted 2 lines
It doesn't feel necessary. It may trigger the printing of a large number of error logs in abnormal scenarios.
Otherwise how will user know that rollback failed and configuration is inconsistent?
Quoted 16 lines
Quoted 6 lines
Quoted 4 lines
+
mac_pool_sel_bk>>= 1;
+ pool++;
+ } while (mac_pool_sel_bk);Please, compare vs 0 explicitly.
Ack
Quoted 9 lines
Quoted 7 lines
+ }
lib/ethdev/rte_ethdev.c +3
-0+ + return ret; +}/*
* Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find.
Re: [PATCH v4 1/2] ethdev: fix one address occupies two indexes in MAC addrs
Quoted 41 lines · Andrew Rybchenko
Cc more driver maintainers
Quoted 29 lines · lihuisong (C)
Quoted 27 lines · Andrew Rybchenko
Quoted 15 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The dev->data->mac_addrs[0] will be changed to a new MAC address when applications modify the default MAC address by
rte_eth_dev_default_mac_addr_set(). However, if the new default one has been added as a non-default MAC address byrte_eth_dev_mac_addr_add(), the therte_eth_dev_default_mac_addr_set()doesn't remove it from themac_addrslist. As a result, one MAC address occupies two indexes in the list. Like:
add(MAC1)
add(MAC2)
add(MAC3)
add(MAC4)set_default(MAC3)
default=MAC3, filters=MAC1, MAC2, MAC3, MAC4Quoted 5 lines
In addition, some PMDs, such as i40e, ice, hns3 and so on, do remove the old default MAC when set default MAC. If user continues to do
set_default(MAC5), and themac_addrslist is default=MAC5, filters=(MAC1, MAC2, MAC3, MAC4). At this moment, user can still view MAC3 from the list, but packets with MAC3 aren't actually received by the PMD.IMHO, the main problem is inconsistency which exists right now.
rte_eth_dev_mac_addr_add()checks for duplicate MAC addition including the default one (index zero) and extends the entry pool mask (including zero entry case).Quoted 6 lines
Quoted 5 lines
However, the patch above does not extend zero entry pool mask. So, the result will depend on order which is bad:
A. Set default to A, add MAC A with pool 2 => pool mask has 2 B. Add MAC A with pool 2, set default to A => pool mask is emptyI don't know how this MAC pool works in which driver.
Me too
Quoted 7 lines
Quoted 5 lines
However, the '
eth_dev_mac_restore' API show that 1) the default MAC has only pool zero if set it by the 'mac_addr_add', 2) the default one hasn't pool information if set it by 'default_mac_addr_set'.Do you mean we should inherit its pool mask in this case?
I simply want to make it consistent
I know what you mean. However, from the implementations mentioned above, it seems that drivers used pool mask don't care the pool mask of the default MAC.
Do we need to set pool mask for the default MAC?
Quoted 70 lines
Quoted 70 lines
Quoted 70 lines
Am I missing something in the code?
What is the right/intended behaviour?Quoted 55 lines
Fixes 854d8ad4ef68 ("ethdev: add default mac address modifier")Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu <[email protected]>---
lib/ethdev/rte_ethdev.c| 39 +++++++++++++++++++++++++++++++++++++--1 file changed, 37 insertions(+), 2 deletions(-)lib/ethdev/rte_ethdev.c +0
-0@@ -4260,7 +4260,10 @@ rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)int
rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr){
+uint64_tmac_pool_sel_bk= 0;
structrte_eth_dev*dev;
+uint32_tpool;
+ int index;
int ret;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);lib/ethdev/rte_ethdev.c +0
-0@@ -4278,16 +4281,48 @@ rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)RTE_FUNC_PTR_OR_ERR_RET (*dev->dev_ops->mac_addr_set, -ENOTSUP );+ /*
+ * If the address has been added as a non-default MAC address by + *rte_eth_dev_mac_addr_addAPI, it should be removed from + * dev->data->mac_addrs[].
+ */
+ index =eth_dev_get_mac_addr_index(port_id, addr);
+ if (index > 0) {
+ /* remove address in NIC data structure */
+mac_pool_sel_bk= dev->data->mac_pool_sel[index]; + ret =rte_eth_dev_mac_addr_remove(port_id, addr); + if (ret < 0) {
+ RTE_ETHDEV_LOG(ERR,
+ "Delete MAC address from the MAC list of ethdev port %u.\n",
+port_id);
+ return ret;
+ }
+ /* reset pool bitmap */
+ dev->data->mac_pool_sel[index] = 0;
+ }
+
ret = (*dev->dev_ops->mac_addr_set)(dev, addr);
if (ret < 0)
- return ret;
+ goto back;
/* Update default address in NIC data structure */rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);Quoted 8 lines
return 0;
-}
+back:
+ if (index > 0) {
+ pool = 0;
+ do {
+ if (mac_pool_sel_bk&UINT64_C(1))
+rte_eth_dev_mac_addr_add(port_id, addr, pool);Don't we want to have at least error logs in the case of rollback failure here?
Quoted 5 lines
Quoted 2 lines
It doesn't feel necessary. It may trigger the printing of a large number of error logs in abnormal scenarios.
Otherwise how will user know that rollback failed and configuration is inconsistent?
Ack.
Quoted 19 lines
Quoted 17 lines
Quoted 7 lines
Quoted 5 lines
+
mac_pool_sel_bk>>= 1;
+ pool++;
+ } while (mac_pool_sel_bk);Please, compare vs 0 explicitly.
Ack
Quoted 9 lines
Quoted 7 lines
+ }
lib/ethdev/rte_ethdev.c +3
-0+ + return ret; +}/*
* Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find.
.
PATCH v4 2/2 ethdev: document default and non-default MAC address
In reply to Min Hu (Connor)From: Huisong Li <[email protected]>
The rte_eth_dev_data::mac_addrs is a MAC address array. The index zero of this array is as the default address index, and other indexes can't be the same as the address corresponding to index 0. If we break it, may cause following problems:
1) waste of MAC address spaces.
2) a fake MAC address in the MAC list, isn't in hardware MAC entries.
3) a MAC address is assigned to diffent pool.
--- lib/ethdev/ethdev_driver.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
lib/ethdev/ethdev_driver.h +6 -1
@@ -115,7 +115,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */ -/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the +* index of the default address, and other indexes can't be the same +* as the address corresponding to index 0. +* @see rte_eth_dev_release_port() +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
Signature · 1 line
2.33.0
Re: [PATCH v4 2/2] ethdev: document default and non-default MAC address
Quoted 24 lines · Min Hu (Connor)
From: Huisong Li <[email protected]>
The
rte_eth_dev_data::mac_addrsis a MAC address array. The index zero of this array is as the default address index, and other indexes can't be the same as the address corresponding to index 0. If we break it, may cause following problems:
1) waste of MAC address spaces.
2) a fake MAC address in the MAC list, isn't in hardware MAC entries.
3) a MAC address is assigned to diffent pool.Signed-off-by Huisong Li <[email protected]>Signed-off-by Min Hu <[email protected]>--- lib/ethdev/ethdev_driver.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)lib/ethdev/ethdev_driver.h +0
-0@@ -115,7 +115,12 @@ struct rte_eth_dev_data {uint64_t rx_mbuf_alloc_failed;/**< Rx ring mbuf allocation failures */
lib/ethdev/ethdev_driver.h struct rte_eth_dev_data { · line 126
Quoted 10 lines
lib/ethdev/ethdev_driver.h +6
-1-/** Device Ethernet link address. @see rte_eth_dev_release_port() */ +/** +* Device Ethernet link address. The index zero of the array is as the +* index of the default address, and other indexes can't be the same +* as the address corresponding to index 0. +* @see rte_eth_dev_release_port() +*/ struct rte_ether_addr *mac_addrs;/** Bitmap associating MAC addresses to pools */ uint64_t mac_pool_sel[RTE_ETH_NUM_RECEIVE_MAC_ADDR ];
The patch itself does not make sense since it documents what happens in the first patch of the series. So, it should be a part of the first patch.
Re: [PATCH v4 0/2] ethdev: fix MAC addrs list
In reply to Min Hu (Connor)Quoted 18 lines · Min Hu (Connor)
The index zero of
rte_eth_dev_data::mac_addrsarray is as the default MAC index, and other indexes can't be the same as the address corresponding to index 0. If we break it, may cause following problems:
1) waste of MAC address spaces.
2) a fake MAC address in the MAC list, isn't in hardware MAC entries.
3) a MAC address is assigned to diffent pool.Huisong Li (2):
ethdev: fix one address occupies two indexes in MAC addrs
ethdev: document default and non-default MAC address
---
v4:
- fix broken in the patchworkv3:
- first explicitly remove the non-default MAC, then set default one.
- document default and non-default MAC address
Quoted 7 lines
v2:
- fixed commit log.lib/ethdev/ethdev_driver.h | 7 ++++++- lib/ethdev/rte_ethdev.c | 39 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-)
Please, don't forget to add maintainers in Cc when you send patches.
--cc-cmd ./devtools/get-maintainers.sh
or
--to-cmd ./devtools/get-maintainers.sh
(I'd prefer To and have [email protected] in Cc)
Don't worry about it right now. I'll add Thomas and Ferrh in my replies.