From patchwork Thu Feb 17 10:14:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, WenxuanX" X-Patchwork-Id: 107717 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id A1255A00BE; Thu, 17 Feb 2022 11:34:56 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 024D54114E; Thu, 17 Feb 2022 11:34:53 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id 3854140DDD for ; Thu, 17 Feb 2022 11:34:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645094091; x=1676630091; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZsjXsbhx2Gs+bw9YsKG42P57qwcr5pQ/MkuCdGma64Q=; b=df9RbXHMmfOBbDQOslk9vrNSWjvAwEC5sDNq3DprK1tr13S87iuxqUGZ zv1TWokskqSwS1elqTOq6TQSfFX3CUaDom42lvwikt3kSEfauj7xBbdxr EkDzUrEBT+4WSa2eQtybSyI84XtLqD9Nq0mHNZjeRJ4JYvW1KAlSJ6Nde gTa9rKIFZ7vmFGqUA89/tbKHN9qA+SamuMuiRncOsCwVgk8BOcj+RV/D3 pk+M38983FLC9/H9Yq8rc+qTFq856sG0n/X4szNJyy6SMRoHrbpkHloC4 m6q+Iipr+F9dYuO33NtzdnLv8SK3cYn4x0EinWrauTtV1yJTzALLPTLX7 Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10260"; a="314114273" X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="314114273" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 02:34:48 -0800 X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="545514017" Received: from unknown (HELO localhost.localdomain) ([10.239.251.3]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 02:34:44 -0800 From: wenxuanx.wu@intel.com To: qiming.yang@intel.com, qi.z.zhang@intel.com, xiaoyun.li@intel.com, aman.deep.singh@intel.com, yuying.zhang@intel.com Cc: dev@dpdk.org Subject: [PATCH 1/2] app/testpmd: fix quit testpmd with vfs and pf Date: Thu, 17 Feb 2022 18:14:27 +0800 Message-Id: <20220217101428.385751-2-wenxuanx.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220217101428.385751-1-wenxuanx.wu@intel.com> References: <20220217101428.385751-1-wenxuanx.wu@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: wenxuan wu 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. Fixes: d3a274ce9dee ("app/testpmd: handle SIGINT and SIGTERM") Cc: stable@dpdk.org Signed-off-by: wenxuan wu --- 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); From patchwork Thu Feb 17 10:14:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, WenxuanX" X-Patchwork-Id: 107718 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3583EA00BE; Thu, 17 Feb 2022 11:35:01 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id DE7CC41153; Thu, 17 Feb 2022 11:34:53 +0100 (CET) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by mails.dpdk.org (Postfix) with ESMTP id CFA5E410FF for ; Thu, 17 Feb 2022 11:34:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1645094092; x=1676630092; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=i3fmAMc1Ci38fWSS/LchdwQLywgvLjTYYa33tqq5tMM=; b=FUi6w4ccLSCBFNhidp8nq/o3OQswU6lX/PpkqQi+Jo7YYPkkT76rTz8H CrRbQHAwZ1YLrXOX9QxdQPjDMv1WI3FHoGcaYi0Cyzubyir+V0mVAydNh xkixVAKlOZHgocKSneG3LgRvNXPedHXaN1rrs8hEj8+iqlVnnjIxfJwO3 5U+u08Ed+2FWHZPSOxvlWwzoZIAHD/n/hgi377pavc/orcILBDrY3L691 eEiE1aaDdLGeJMeYClqV0t1BuZIlS7ZMeCIfolkVTx6G7U5sFh1LF5tgO kx9tXBvlL9ESfSF1fobFRGRJIe/0MJ981d7j0B3Ge9Ok0YN5yR5niP6vU Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10260"; a="314114277" X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="314114277" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 02:34:49 -0800 X-IronPort-AV: E=Sophos;i="5.88,375,1635231600"; d="scan'208";a="545514043" Received: from unknown (HELO localhost.localdomain) ([10.239.251.3]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Feb 2022 02:34:46 -0800 From: wenxuanx.wu@intel.com To: qiming.yang@intel.com, qi.z.zhang@intel.com, xiaoyun.li@intel.com, aman.deep.singh@intel.com, yuying.zhang@intel.com Cc: dev@dpdk.org Subject: [PATCH 2/2] lib/ethdev: add reverse macro to quit testpmd Date: Thu, 17 Feb 2022 18:14:28 +0800 Message-Id: <20220217101428.385751-3-wenxuanx.wu@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220217101428.385751-1-wenxuanx.wu@intel.com> References: <20220217101428.385751-1-wenxuanx.wu@intel.com> MIME-Version: 1.0 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: wenxuan wu 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. Cc: stable@dpdk.org Signed-off-by: wenxuan wu --- lib/ethdev/rte_ethdev.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/ethdev/rte_ethdev.h b/lib/ethdev/rte_ethdev.h index 2660e4f374..e080840b06 100644 --- a/lib/ethdev/rte_ethdev.h +++ b/lib/ethdev/rte_ethdev.h @@ -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. *