app/testpmd: fix quit testpmd with vfs and pf
cover app/testpmd: fix quit testpmd with vfs and pf
From: wenxuan wu <[email protected]>
Apply our reverse iterator macro into testpmd to avoid testpmd startups with pf and vfs quit without error heap-free-before-use
wenxuan wu (2):
app/testpmd: fix quit testpmd with vfs and pf
lib/ethdev: add reverse macro to quit testpmd
app/test-pmd/testpmd.c | 4 ++-- lib/ethdev/rte_ethdev.h | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/2 app/testpmd: fix quit testpmd with vfs and pf
From: wenxuan wu <[email protected]>
When testpmd startups with pf and vfs,this error occurs when quitting, results in pf is released before vfs ,so the vf would access an freed heap memory.
The solution is that release our allocated ports in reverse order,add two macros RTE_ETH_FOREACH_DEV_REVERSE_OWNED_BY and RTE_ETH_FOREACH_DEV_REVERSE,which would be used in quit procedure of testpmd, error is fixed.
--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-pmd/testpmd.c +2 -2
@@ -3384,12 +3384,12 @@ pmd_test_exit(void)#endif if (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);fflush (stdout);close_port (pt_id);
Signature · 1 line
2.25.1
Hi Wenxuan,
Quoted 11 lines
-----Original Message-----
From: Wu, WenxuanX <[email protected]>
Sent: Thursday, February 17, 2022 6:14 PM
To: Yang, Qiming <[email protected]>; Zhang, Qi Z <[email protected]>; Li, Xiaoyun <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>
Cc: [email protected]
Subject: [PATCH 1/2] app/testpmd: fix quit testpmd with vfs and pfFrom: wenxuan wu <[email protected]>
Quoted 8 lines
When testpmd startups with pf and vfs,this error occurs when quitting, results in pf is released before vfs ,so the vf would access an freed heap memory.
The solution is that release our allocated ports in reverse order,add two macros
RTE_ETH_FOREACH_DEV_REVERSE_OWNED_BYand RTE_ETH_FOREACH_DEV_REVERSE,which would be used in quit procedure of testpmd, error is fixed.
Please correct grammatical errors and refine your commit log.
Quoted 28 lines
Fixes d3a274ce9dee ("app/testpmd: handle SIGINT and SIGTERM")Signed-off-by wenxuan wu <[email protected]>--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0
-0
e1da961311..698b6d8cc4100644app/test-pmd/testpmd.c +2
-3@@ -3384,12 +3384,12 @@ pmd_test_exit(void) #endifif (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);fflush (stdout);close_port (pt_id); --2.25.1
Quoted 24 lines · On 2/17/2022 10:14 AM, [email protected] wrote:
From: wenxuan wu <[email protected]>
When testpmd startups with pf and vfs,this error occurs when quitting, results in pf is released before vfs ,so the vf would access an freed heap memory.
The solution is that release our allocated ports in reverse order,add two macros
RTE_ETH_FOREACH_DEV_REVERSE_OWNED_BYand RTE_ETH_FOREACH_DEV_REVERSE,which would be used in quit procedure of testpmd, error is fixed.Fixes d3a274ce9dee ("app/testpmd: handle SIGINT and SIGTERM")Signed-off-by wenxuan wu <[email protected]>--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/test-pmd/testpmd.c +0
-0
app/test-pmd/testpmd.c pmd_test_exit(void) · line 3387
Quoted 5 lines
app/test-pmd/testpmd.c +1
-1@@ -3384,12 +3384,12 @@ pmd_test_exit(void)#endif if (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {
This fix assumes PF is always probed before VFs (so PF has smaller port id than VF).
I am not sure if this is guaranteed, ports ported based on scan in the sysfs folder.
Instead, what do you think PF port stop/close fail when there are still VFs probed? I think PF driver can know if there are VFs ported.
Quoted 9 lines
app/test-pmd/testpmd.c +1
-1printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);fflush (stdout);close_port (pt_id);
PATCH 2/2 lib/ethdev: add reverse macro to quit testpmd
In reply to [email protected]From: wenxuan wu <[email protected]>
There is a heap-free-after-use bug when quit testpmd with pf and vfs, stop and close ports in reverse order is a more reasonable approach.
--- lib/ethdev/rte_ethdev.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.h +13 -1
@@ -2185,9 +2185,13 @@ struct rte_eth_dev_owner {* @return * Next valid port ID owned by owner_id, RTE_MAX_ETHPORTS if there is none. */ -uint64_t rte_eth_find_next_owned_by (uint16_t port_id, +uint64_t +rte_eth_find_next_owned_by (uint16_t port_id,const uint64_t owner_id); +uint64_t +rte_eth_find_prev_owned_by (uint16_t port_id,const uint64_t owner_id); +/** * Macro to iterate over all enabled ethdev ports owned by a specific owner. */
@@ -2212,6 +2216,14 @@ uint16_t rte_eth_find_next(uint16_t port_id);#define RTE_ETH_FOREACH_DEV (p) \ RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER) +/** +* Macro to iterate over all enabled and ownerless ethdev ports in reverse order, for quit purpose. +*/ +#define RTE_ETH_FOREACH_DEV_REVERSE (p) \ + for (p = (rte_eth_dev_count_total() - 1 >= 0) ? (rte_eth_dev_count_total() - 1) : 0; \ + p < rte_eth_dev_count_total(); \ + p--) +/** * Iterates over ethdev ports of a specified device. *
Signature · 1 line
2.25.1
RE: [PATCH 2/2] lib/ethdev: add reverse macro to quit testpmd
Hi Wenxuan,
Quoted 9 lines
-----Original Message-----
From: Wu, WenxuanX <[email protected]>
Sent: Thursday, February 17, 2022 6:14 PM
To: Yang, Qiming <[email protected]>; Zhang, Qi Z <[email protected]>; Li, Xiaoyun <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>
Cc: [email protected]
Subject: [PATCH 2/2] lib/ethdev: add reverse macro to quit testpmd
Quoted 4 lines
From: wenxuan wu <[email protected]>
There is a heap-free-after-use bug when quit testpmd with pf and vfs, stop and close ports in reverse order is a more reasonable approach.
Please explain the issue and your fix in detail. Since your patch is a fix, you need a fix line here.
Quoted 13 lines
Signed-off-by wenxuan wu <[email protected]>--- lib/ethdev/rte_ethdev.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0
-0
2660e4f374..e080840b06100644lib/ethdev/rte_ethdev.h +0
-0@@ -2185,9 +2185,13 @@ struct rte_eth_dev_owner {* @return
lib/ethdev/rte_ethdev.h struct rte_eth_dev_owner { · line 2194
Quoted 10 lines
lib/ethdev/rte_ethdev.h +5
-1* Next valid port ID owned by owner_id, RTE_MAX_ETHPORTS if there is none. */ -uint64_t rte_eth_find_next_owned_by (uint16_t port_id, +uint64_t +rte_eth_find_next_owned_by (uint16_t port_id,const uint64_t owner_id); +uint64_t +rte_eth_find_prev_owned_by (uint16_t port_id,const uint64_t owner_id); +
Please keep consistency of code style of similar declaration.
Quoted 14 lines
lib/ethdev/rte_ethdev.h +2
-0/** * Macro to iterate over all enabled ethdev ports owned by a specific owner. */ @@ -2212,6 +2216,14 @@ uint16_t rte_eth_find_next(uint16_t port_id);#define RTE_ETH_FOREACH_DEV (p) \ RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER) +/** +* Macro to iterate over all enabled and ownerless ethdev ports in reverse order, for quit purpose.
+ */lib/ethdev/rte_ethdev.h +2
-0+#define RTE_ETH_FOREACH_DEV_REVERSE (p) \ + for (p = (rte_eth_dev_count_total() - 1 >= 0) ?(
rte_eth_dev_count_total()- 1) : 0; \
lib/ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 2225
Quoted 2 lines
lib/ethdev/rte_ethdev.h +2
-0+ p <rte_eth_dev_count_total (); \ + p--)
Use rte_eth_dev_count_total() function can only get the number of valid port instead of port id separately. You should can refer to the logic of RTE_ETH_FOREACH_DEV(p).
Quoted 6 lines
+
/**
* Iterates over ethdev ports of a specified device. *
--
2.25.1
Re: [PATCH 2/2] lib/ethdev: add reverse macro to quit testpmd
In reply to [email protected]Quoted 11 lines · On 2/17/2022 10:14 AM, [email protected] wrote:
From: wenxuan wu <[email protected]>
There is a heap-free-after-use bug when quit testpmd with pf and vfs, stop and close ports in reverse order is a more reasonable approach.
Signed-off-by wenxuan wu <[email protected]>--- lib/ethdev/rte_ethdev.h | 14 +++++++++++++-
This patch should come before testpmd patch, because testpmd is using macro defined here.
Quoted 8 lines
1 file changed, 13 insertions(+), 1 deletion(-)lib/ethdev/rte_ethdev.h +0
-0@@ -2185,9 +2185,13 @@ struct rte_eth_dev_owner {* @return
lib/ethdev/rte_ethdev.h struct rte_eth_dev_owner { · line 2194
Quoted 10 lines
lib/ethdev/rte_ethdev.h +5
-1* Next valid port ID owned by owner_id, RTE_MAX_ETHPORTS if there is none. */ -uint64_t rte_eth_find_next_owned_by (uint16_t port_id, +uint64_t +rte_eth_find_next_owned_by (uint16_t port_id,const uint64_t owner_id); +uint64_t +rte_eth_find_prev_owned_by (uint16_t port_id,const uint64_t owner_id); +
This function declared but not implemented, can remove above.
lib/ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 2220
Quoted 9 lines
lib/ethdev/rte_ethdev.h +2
-0/** * Macro to iterate over all enabled ethdev ports owned by a specific owner. */ @@ -2212,6 +2216,14 @@ uint16_t rte_eth_find_next(uint16_t port_id);#define RTE_ETH_FOREACH_DEV (p) \ RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER) +/** +* Macro to iterate over all enabled and ownerless ethdev ports in reverse order, for quit purpose.
No need to add comment related to "quit purpose", macro can be used for different reasons.
lib/ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 2223
Quoted 3 lines
lib/ethdev/rte_ethdev.h +3
-0+*/ +#define RTE_ETH_FOREACH_DEV_REVERSE (p) \ + for (p = (rte_eth_dev_count_total() - 1 >= 0) ? (rte_eth_dev_count_total() - 1) : 0; \
Below check already relies on 'p' is unsigned, also 'rte_eth_dev_count_total()' returns unsigned, if so above check is unnecessary, it can just have:
"p = rte_eth_dev_count_total() - 1"
Quoted 6 lines
lib/ethdev/rte_ethdev.h +3
-0+ p <rte_eth_dev_count_total (); \ + p--) +/** * Iterates over ethdev ports of a specified device. *
cover app/testpmd: fix testpmd quit with pf and vfs
From: wenxuan wu <[email protected]>
Apply our reverse iterator macro into testpmd to avoid testpmd startups with pf and vfs quit without error heap-free-before-use
wenxuan wu (2):
lib/ethdev: add reverse macro to quit testpmd app/testpmd:fix testpmd quit failure
app/test-pmd/testpmd.c | 4 ++-- lib/ethdev/rte_ethdev.h | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-)
Signature · 1 line
2.25.1
PATCH v2 1/2 lib/ethdev: add reverse macro to quit testpmd
From: wenxuan wu <[email protected]>
There is a heap-free-after-use bug when quit testpmd with pf and vfs, stop and close ports in reverse order is a more reasonable approach.
--- lib/ethdev/rte_ethdev.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
lib/ethdev/rte_ethdev.h +10 -1
@@ -2185,7 +2185,8 @@ struct rte_eth_dev_owner {* @return * Next valid port ID owned by owner_id, RTE_MAX_ETHPORTS if there is none. */ -uint64_t rte_eth_find_next_owned_by (uint16_t port_id, +uint64_t +rte_eth_find_next_owned_by (uint16_t port_id,const uint64_t owner_id);/**
@@ -2212,6 +2213,14 @@ uint16_t rte_eth_find_next(uint16_t port_id);#define RTE_ETH_FOREACH_DEV (p) \ RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER) +/** +* Macro to iterate over all enabled and ownerless ethdev ports in reverse order. +*/ +#define RTE_ETH_FOREACH_DEV_REVERSE (p) \ + for (p = rte_eth_dev_count_total() - 1; \ + p < rte_eth_dev_count_total(); \ + p--) +/** * Iterates over ethdev ports of a specified device. *
Signature · 1 line
2.25.1
PATCH v2 2/2 app/testpmd:fix testpmd quit failure
In reply to [email protected]From: wenxuan wu <[email protected]>
When testpmd start ed with 1 pf and 2 vfs, testpmd quited while vfs were still alive would result in failure. Root cause is that pf had been released already but vfs were still accessing by func rte_eth_dev_info_get, which would result in heap-free-after-use error.
By quitting our ports in reverse order to avoid this.And the order is guaranteed that vf are created after pfs.
--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
app/test-pmd/testpmd.c +2 -2
@@ -3384,12 +3384,12 @@ pmd_test_exit(void)#endif if (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);fflush (stdout);close_port (pt_id);
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] app/testpmd:fix testpmd quit failure
Quoted 23 lines · On 2/23/2022 11:32 AM, [email protected] wrote:
From: wenxuan wu <[email protected]>
When testpmd start ed with 1 pf and 2 vfs, testpmd quited while vfs were still alive would result in failure. Root cause is that pf had been released already but vfs were still accessing by func
rte_eth_dev_info_get, which would result in heap-free-after-use error.By quitting our ports in reverse order to avoid this.And the order is guaranteed that vf are created after pfs.
Fixes d3a274ce9dee ("app/testpmd: handle SIGINT and SIGTERM")Signed-off-by wenxuan wu <[email protected]>--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/test-pmd/testpmd.c +0
-0
app/test-pmd/testpmd.c pmd_test_exit(void) · line 3387
Quoted 5 lines
app/test-pmd/testpmd.c +1
-1@@ -3384,12 +3384,12 @@ pmd_test_exit(void)#endif if (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {
The main problem with this patch was this logic,
can you please check comment on previous version?
Quoted 9 lines
app/test-pmd/testpmd.c +1
-1printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);fflush (stdout);close_port (pt_id);
RE: [PATCH v2 2/2] app/testpmd:fix testpmd quit failure
In reply to [email protected]I found this meaning in DPDK testplan.
Note that currently hot-plugging of representor ports is not supported so all the required representors must be specified on the creation of the PF or the trusted VF.
When testpmd is started with pf and vf representors, the order of representor is determined on creation. So it is guaranteed that ,pf is beneath the vf representors, we implemented in a reverse way is acceptable just at present, depends on when the hot-plugging of representor is supported.
Quoted 46 lines
-----Original Message-----
From: Wu, WenxuanX <[email protected]>
Sent: 2022年2月23日 19:33
To: Li, Xiaoyun <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Cc: Wu, WenxuanX <[email protected]>; [email protected]
Subject: [PATCH v2 2/2] app/testpmd:fix testpmd quit failureFrom: wenxuan wu <[email protected]>
When testpmd start ed with 1 pf and 2 vfs, testpmd quited while vfs were still alive would result in failure. Root cause is that pf had been released already but vfs were still accessing by func
rte_eth_dev_info_get, which would result in heap-free-after-use error.By quitting our ports in reverse order to avoid this.And the order is guaranteed that vf are created after pfs.
Fixes d3a274ce9dee ("app/testpmd: handle SIGINT and SIGTERM")Signed-off-by wenxuan wu <[email protected]>--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0
-0
e1da961311..698b6d8cc4100644app/test-pmd/testpmd.c +2
-3@@ -3384,12 +3384,12 @@ pmd_test_exit(void) #endifif (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);fflush (stdout);close_port (pt_id); --2.25.1
Re: [PATCH v2 2/2] app/testpmd:fix testpmd quit failure
On 3/3/2022 1:22 PM, Wu, WenxuanX wrote:
moved down, please don't top post
Quoted 43 lines
Quoted 43 lines
-----Original Message-----
From: Wu, WenxuanX <[email protected]>
Sent: 2022年2月23日 19:33
To: Li, Xiaoyun <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Cc: Wu, WenxuanX <[email protected]>; [email protected]
Subject: [PATCH v2 2/2] app/testpmd:fix testpmd quit failureFrom: wenxuan wu <[email protected]>
When testpmd start ed with 1 pf and 2 vfs, testpmd quited while vfs were still alive would result in failure. Root cause is that pf had been released already but vfs were still accessing by func
rte_eth_dev_info_get, which would result in heap-free-after-use error.By quitting our ports in reverse order to avoid this.And the order is guaranteed that vf are created after pfs.
Fixes d3a274ce9dee ("app/testpmd: handle SIGINT and SIGTERM")Signed-off-by wenxuan wu <[email protected]>--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0
-0
e1da961311..698b6d8cc4100644app/test-pmd/testpmd.c +2
-2@@ -3384,12 +3384,12 @@ pmd_test_exit(void) #endifif (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);fflush (stdout);
Quoted 9 lines
Quoted 3 lines
app/test-pmd/testpmd.c +0
-1close_port (pt_id); --2.25.1
I found this meaning in DPDK testplan.
Note that currently hot-plugging of representor ports is not supported so all the required representors must be specified on the creation of the PF or the trusted VF.
When testpmd is started with pf and vf representors, the order of representor is determined on creation. So it is guaranteed that ,pf is beneath the vf representors, we implemented in a reverse way is acceptable just at present, depends on when the hot-plugging of representor is supported.
The patch mentions from PF and VFs, and now you are referring to port representor.
Is the problem related to VF or port representor.
For both, VF and port reporesentor should be closed before PF, that part is OK. My comment is if reversing port id traverse will fix the issue or do we need more complex solution.
Like have APIs to get VF and representor ports from a given port id, and free them first.
RE: [PATCH v2 2/2] app/testpmd:fix testpmd quit failure
Quoted 76 lines
-----Original Message-----
From: Yigit, Ferruh <[email protected]>
Sent: 2022年3月5日 0:16
To: Wu, WenxuanX <[email protected]>; Li, Xiaoyun <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: [PATCH v2 2/2] app/testpmd:fix testpmd quit failureOn 3/3/2022 1:22 PM, Wu, WenxuanX wrote:
moved down, please don't top post
Quoted 42 lines
Quoted 42 lines
-----Original Message-----
From: Wu, WenxuanX <[email protected]>
Sent: 2022年2月23日 19:33
To: Li, Xiaoyun <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Cc: Wu, WenxuanX <[email protected]>; [email protected]
Subject: [PATCH v2 2/2] app/testpmd:fix testpmd quit failureFrom: wenxuan wu <[email protected]>
When testpmd start ed with 1 pf and 2 vfs, testpmd quited while vfs were still alive would result in failure. Root cause is that pf had been released already but vfs were still accessing by func
rte_eth_dev_info_get, which would result in heap-free-after-use error.By quitting our ports in reverse order to avoid this.And the order is guaranteed that vf are created after pfs.
Fixes d3a274ce9dee ("app/testpmd: handle SIGINT and SIGTERM")Signed-off-by wenxuan wu <[email protected]>--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0
-0
e1da961311..698b6d8cc4100644app/test-pmd/testpmd.c +2
-2@@ -3384,12 +3384,12 @@ pmd_test_exit(void) #endifif (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);Quoted 8 lines
Quoted 4 lines
app/test-pmd/testpmd.c +0
-1fflush (stdout);close_port (pt_id); --2.25.1
I found this meaning in DPDK testplan.
Note that currently hot-plugging of representor ports is not supported so allthe required representors must be specified on the creation of the PF or the trusted VF.
Quoted 1 line
When testpmd is started with pf and vf representors, the order of
representor is determined on creation. So it is guaranteed that ,pf is beneath the vf representors, we implemented in a reverse way is acceptable just at present, depends on when the hot-plugging of representor is supported.
Quoted 1 line
The patch mentions from PF and VFs, and now you are referring to port representor.
Is the problem related to VF or port representor.
Quoted 5 lines
For both, VF and port reporesentor should be closed before PF, that part is OK. My comment is if reversing port id traverse will fix the issue or do we need more complex solution.
Like have APIs to get VF and representor ports from a given port id, and free them first.
This patch did fix the issue ,and was verified.But it was rejected.
RE: [PATCH v2 2/2] app/testpmd:fix testpmd quit failure
Quoted 75 lines
-----Original Message-----
From: Wu, WenxuanX
Sent: 2022年3月9日 11:07
To: Yigit, Ferruh <[email protected]>; Li, Xiaoyun <[email protected]>; [email protected]
Cc: [email protected]
Subject: RE: [PATCH v2 2/2] app/testpmd:fix testpmd quit failureQuoted 63 lines
-----Original Message-----
From: Yigit, Ferruh <[email protected]>
Sent: 2022年3月5日 0:16
To: Wu, WenxuanX <[email protected]>; Li, Xiaoyun <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: [PATCH v2 2/2] app/testpmd:fix testpmd quit failureOn 3/3/2022 1:22 PM, Wu, WenxuanX wrote:
moved down, please don't top post
Quoted 51 lines
Quoted 45 lines
-----Original Message-----
From: Wu, WenxuanX <[email protected]>
Sent: 2022年2月23日 19:33
To: Li, Xiaoyun <[email protected]>; Yigit, Ferruh <[email protected]>; [email protected]
Cc: Wu, WenxuanX <[email protected]>; [email protected]
Subject: [PATCH v2 2/2] app/testpmd:fix testpmd quit failureFrom: wenxuan wu <[email protected]>
When testpmd start ed with 1 pf and 2 vfs, testpmd quited while vfs were still alive would result in failure. Root cause is that pf had been released already but vfs were still accessing by func
rte_eth_dev_info_get, which would result in heap-free-after-use error.By quitting our ports in reverse order to avoid this.And the order is guaranteed that vf are created after pfs.
Fixes d3a274ce9dee ("app/testpmd: handle SIGINT and SIGTERM")Signed-off-by wenxuan wu <[email protected]>--- app/test-pmd/testpmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)app/test-pmd/testpmd.c index renamed from app/test-pmd/testpmd.c +0
-0
e1da961311..698b6d8cc4100644app/test-pmd/testpmd.c +2
-3@@ -3384,12 +3384,12 @@ pmd_test_exit(void) #endifif (ports !=NULL ) { no_link_check =1 ; -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nStopping port %d...\n" , pt_id);fflush (stdout);stop_port (pt_id); } -RTE_ETH_FOREACH_DEV (pt_id) { +RTE_ETH_FOREACH_DEV_REVERSE (pt_id) {printf ("\nShutting down port %d...\n" , pt_id);fflush (stdout);close_port (pt_id); --Quoted 1 line
2.25.1
I found this meaning in DPDK testplan.
Note that currently hot-plugging of representor ports is not supported so all
Quoted 18 lines
Quoted 6 lines
the required representors must be specified on the creation of the PF or the trusted VF.
Quoted 1 line
When testpmd is started with pf and vf representors, the order of
representor is determined on creation. So it is guaranteed that ,pf is beneath the vf representors, we implemented in a reverse way is acceptable just at present, depends on when the hot-plugging of
representor is supported.
Quoted 11 lines
Quoted 1 line
The patch mentions from PF and VFs, and now you are referring to port representor.
Is the problem related to VF or port representor.For both, VF and port reporesentor should be closed before PF, that part is OK. My comment is if reversing port id traverse will fix the issue or do we need more complex solution.
Like have APIs to get VF and representor ports from a given port id, and free them first.
The problem is that when I attempted to use a func like get_representor_info(pid,info); I didn't found this func implemented by driver , so I can not get the type of port(VF or PF ) directly by get_representor_info(pid,info),especially when the connected driver is i40e, representor_info_get occurred below.
./drivers/net/mlx5/mlx5.c: .representor_info_get = mlx5_representor_info_get, ./drivers/net/mlx5/mlx5.c: .representor_info_get = mlx5_representor_info_get, ./drivers/net/mlx5/mlx5.c: .representor_info_get = mlx5_representor_info_get,
./drivers/net/mlx5/mlx5.h:int mlx5_representor_info_get(struct rte_eth_dev *dev, ./drivers/net/mlx5/mlx5_ethdev.c:mlx5_representor_info_get(struct rte_eth_dev *dev, ./drivers/net/sfc/sfc_ethdev.c:sfc_representor_info_get(struct rte_eth_dev *dev,./drivers/net/sfc/sfc_ethdev.c: .representor_info_get = sfc_representor_info_get,
./app/test-pmd/cmdline.c: ret = rte_eth_representor_info_get(res->cmd_pid, NULL); ./app/test-pmd/cmdline.c: ret = rte_eth_representor_info_get(res->cmd_pid, info); ./app/test-pmd/testpmd.c: ret = rte_eth_representor_info_get(pi,&info); ./lib/ethdev/version.map: rte_eth_representor_info_get;
./lib/ethdev/rte_ethdev.h:int rte_eth_representor_info_get(uint16_t port_id, ./lib/ethdev/ethdev_driver.h:typedef int (*eth_representor_info_get_t)(struct rte_eth_dev *dev,./lib/ethdev/ethdev_driver.h: eth_representor_info_get_t representor_info_get;./lib/ethdev/ethdev_driver.h: * The mapping is retrieved from rte_eth_representor_info_get()../lib/ethdev/rte_ethdev.c: ret = rte_eth_representor_info_get(port_id, NULL);./lib/ethdev/rte_ethdev.c: ret = rte_eth_representor_info_get(port_id, info);
./lib/ethdev/rte_ethdev.c:rte_eth_representor_info_get(uint16_t port_id,./lib/ethdev/rte_ethdev.c: RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->representor_info_get, -ENOTSUP);./lib/ethdev/rte_ethdev.c: return eth_err(port_id, (*dev->dev_ops->representor_info_get)(dev, info));
We should focus on changing the logic of is_bonding_slave to avoid this bug ,right ? The procedure of port_close is like this :FOR_EACH_DEV(pi):
If Is_bonding_slave(pi) Continue; .... Etc.
In is_bonding_slave(pi):
This func get_dev_info(pid,dev_info) would be called to get dev.dev_flag &SLAVE ,this would be result in error ,when port sequence is like port 0 PF ,port 1 VF_REPR, port 2 VF_REPR, there is no obstacles in closing port 0 ,then pid iterate to port 1.
But port 1 is a VF_REPR which based on port 0 ,when in func is_bonding_slave(port 1), it would
call get_dev_info(1,dev_info) ,error occurred. Because we use get_dev_info(especially when PF is released )
not ports[1] which had been pre allocated . would result in this error.
Two solutions :
1. Reverse order to close like I mentioned before (PF and VF_repr order is determined at creation time with no representor hot_plug). 2.change func get_dev_info(pid,info) to ports[pid) to get dev_flag
Both can resolve this bug ,which one do you prefer?
RE: [PATCH 2/2] lib/ethdev: add reverse macro to quit testpmd
In reply to Ferruh YigitQuoted 53 lines
-----Original Message-----
From: Yigit, Ferruh <[email protected]>
Sent: 2022年2月19日 1:05
To: Wu, WenxuanX <[email protected]>; Yang, Qiming <[email protected]>; Zhang, Qi Z <[email protected]>; Li, Xiaoyun <[email protected]>; Singh, Aman Deep <[email protected]>; Zhang, Yuying <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH 2/2] lib/ethdev: add reverse macro to quit testpmdQuoted 10 lines · On 2/17/2022 10:14 AM, [email protected] wrote:
From: wenxuan wu <[email protected]>
There is a heap-free-after-use bug when quit testpmd with pf and vfs, stop and close ports in reverse order is a more reasonable approach.
Signed-off-by wenxuan wu <[email protected]>--- lib/ethdev/rte_ethdev.h | 14 +++++++++++++-This patch should come before testpmd patch, because testpmd is using macro defined here.
lib/ethdev/rte_ethdev.h struct rte_eth_dev_owner { · line 2186
Quoted 9 lines
1 file changed, 13 insertions(+), 1 deletion(-)lib/ethdev/rte_ethdev.h index renamed from lib/ethdev/rte_ethdev.h +0
-0
2660e4f374..e080840b06100644lib/ethdev/rte_ethdev.h +0
-0@@ -2185,9 +2185,13 @@ struct rte_eth_dev_owner {* @return * Next valid port ID owned by owner_id, RTE_MAX_ETHPORTS if there is none.
lib/ethdev/rte_ethdev.h struct rte_eth_dev_owner { · line 2194
Quoted 10 lines
lib/ethdev/rte_ethdev.h +6
-1*/ -uint64_t rte_eth_find_next_owned_by (uint16_t port_id, +uint64_t +rte_eth_find_next_owned_by (uint16_t port_id,const uint64_t owner_id); +uint64_t +rte_eth_find_prev_owned_by (uint16_t port_id,const uint64_t +owner_id); +This function declared but not implemented, can remove above.
lib/ethdev/rte_ethdev.h struct rte_eth_dev_owner { · line 2197
Quoted 2 lines
lib/ethdev/rte_ethdev.h +0
-0/** * Macro to iterate over all enabled ethdev ports owned by a specific owner.
Quoted 8 lines
lib/ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id); · line 2220
Quoted 7 lines
lib/ethdev/rte_ethdev.h +2
-0*/ @@ -2212,6 +2216,14 @@ uint16_t rte_eth_find_next(uint16_t port_id);#define RTE_ETH_FOREACH_DEV (p) \ RTE_ETH_FOREACH_DEV_OWNED_BY(p, RTE_ETH_DEV_NO_OWNER) +/** +* Macro to iterate over all enabled and ownerless ethdev ports in reverse order, for quit purpose.
Hi,
My next plan is like this:
Rough one:
---
For each dev:
If( dev is a pf)
Continue
Close(dev)
For each dev :
Close(dev)
Future version:
----
This will be a quick fix before 22.07,but if time is accepted, I will try a more appropriate way ,like u mentioned . For each dev:
If (dev has pf)://new api
for each vf of this dev: //new api
close(vf)
close(dev)
Quoted 20 lines
No need to add comment related to "quit purpose", macro can be used for different reasons.
lib/ethdev/rte_ethdev.h uint16_t rte_eth_find_next(uint16_t port_id);
Quoted 4 lines
lib/ethdev/rte_ethdev.h +4
-0+*/ +#define RTE_ETH_FOREACH_DEV_REVERSE (p) \ + for (p = (rte_eth_dev_count_total() - 1 >= 0) ? +(rte_eth_dev_count_total() - 1) : 0; \Below check already relies on 'p' is unsigned, also '
rte_eth_dev_count_total()' returns unsigned, if so above check is unnecessary, it can just have:
"p =rte_eth_dev_count_total()- 1"Quoted 6 lines
lib/ethdev/rte_ethdev.h +3
-0+ p <rte_eth_dev_count_total (); \ + p--) +/** * Iterates over ethdev ports of a specified device. *