patches for DPDK stable branches
 help / color / mirror / Atom feed
* [PATCH v3] app/testpmd: fix heap-free-before-use when quit
@ 2022-03-02  7:08 wenxuanx.wu
  0 siblings, 0 replies; 5+ messages in thread
From: wenxuanx.wu @ 2022-03-02  7:08 UTC (permalink / raw)
  To: build_sh; +Cc: wenxuan wu, stable

From: wenxuan wu <wenxuanx.wu@intel.com>

Change func logic is_bonding_slave and set_port_slave_flag to avoid this
error.Port->slave_flag with dev_flag check to ensure slave_flag is securely
set.

Remove eth_dev_info_get in func is_bonding_slave, which would lead to
a heap-free-before-use error the reason is that vf was still accessing a
freed pf resource.

Fixes: 0a0821bcf312 ("app/testpmd: remove most uses of internal ethdev array")
Cc: stable@dpdk.org

Signed-off-by: Wenxuan Wu <wenxuanx.wu@intel.com>
---
 app/test-pmd/testpmd.c | 33 ++++++++++++++++-----------------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index e1da961311..dcba11f7a6 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -3805,15 +3805,23 @@ init_port_config(void)
 	}
 }
 
-void set_port_slave_flag(portid_t slave_pid)
+void
+set_port_slave_flag(portid_t slave_pid)
 {
 	struct rte_port *port;
-
+	struct rte_eth_dev_info dev_info;
+	int ret;
 	port = &ports[slave_pid];
-	port->slave_flag = 1;
+	ret = eth_dev_info_get_print_err(slave_pid, &dev_info);
+	if (ret != 0)
+		return;
+
+	if (*dev_info.dev_flags & RTE_ETH_DEV_BONDED_SLAVE)
+		port->slave_flag = 1;
 }
 
-void clear_port_slave_flag(portid_t slave_pid)
+void
+clear_port_slave_flag(portid_t slave_pid)
 {
 	struct rte_port *port;
 
@@ -3821,26 +3829,17 @@ void clear_port_slave_flag(portid_t slave_pid)
 	port->slave_flag = 0;
 }
 
-uint8_t port_is_bonding_slave(portid_t slave_pid)
+uint8_t
+port_is_bonding_slave(portid_t slave_pid)
 {
 	struct rte_port *port;
-	struct rte_eth_dev_info dev_info;
-	int ret;
-
 	port = &ports[slave_pid];
-	ret = eth_dev_info_get_print_err(slave_pid, &dev_info);
-	if (ret != 0) {
-		TESTPMD_LOG(ERR,
-			"Failed to get device info for port id %d,"
-			"cannot determine if the port is a bonded slave",
-			slave_pid);
-		return 0;
-	}
-	if ((*dev_info.dev_flags & RTE_ETH_DEV_BONDED_SLAVE) || (port->slave_flag == 1))
+	if (port->slave_flag == 1)
 		return 1;
 	return 0;
 }
 
+
 const uint16_t vlan_tags[] = {
 		0,  1,  2,  3,  4,  5,  6,  7,
 		8,  9, 10, 11,  12, 13, 14, 15,
-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread
* [PATCH v2 2/2] app/testpmd:fix testpmd quit failure
@ 2022-02-23 11:32 wenxuanx.wu
  2022-03-01  7:28 ` [PATCH v3] app/testpmd: fix heap-free-before-use when quit wenxuanx.wu
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: wenxuanx.wu @ 2022-02-23 11:32 UTC (permalink / raw)
  To: xiaoyun.li, ferruh.yigit, dev; +Cc: wenxuan wu, stable

From: wenxuan wu <wenxuanx.wu@intel.com>

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")
Cc: stable@dpdk.org

Signed-off-by: wenxuan wu <wenxuanx.wu@intel.com>
---
 app/test-pmd/testpmd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c
index e1da961311..698b6d8cc4 100644
--- a/app/test-pmd/testpmd.c
+++ b/app/test-pmd/testpmd.c
@@ -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);
-- 
2.25.1


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

end of thread, other threads:[~2022-03-02  8:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-02  7:08 [PATCH v3] app/testpmd: fix heap-free-before-use when quit wenxuanx.wu
  -- strict thread matches above, loose matches on Subject: below --
2022-02-23 11:32 [PATCH v2 2/2] app/testpmd:fix testpmd quit failure wenxuanx.wu
2022-03-01  7:28 ` [PATCH v3] app/testpmd: fix heap-free-before-use when quit wenxuanx.wu
2022-03-02  7:20 ` wenxuanx.wu
2022-03-02  8:06 ` wenxuanx.wu
2022-03-02  8:34 ` wenxuanx.wu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).