From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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. * -- 2.25.1