From patchwork Wed Jun 1 10:54:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Khan, Hamza" X-Patchwork-Id: 112329 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 A471EA00C2; Sun, 5 Jun 2022 09:51:57 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 97277427F2; Sun, 5 Jun 2022 09:51:49 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id B96504003F for ; Wed, 1 Jun 2022 12:55:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654080910; x=1685616910; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=BIXgCPnV1tbFTqYMbsKryt8htDoRRefEL/0uulYLFAU=; b=bcZ08wOVkLcM6bGdvdjfxrYJm7gyH78savI1ce5cQLi9t3BBzLuZVLGu SuxyOF+21YRNIFQtdEr4A+WjP3Vay4qYlPdjSKJsQnatcjIh+qmXmOOpg VSdJ/31yqH6O/q1fVXa5u7G7EwORu+6kzxy+H/UcqtGbSk6W+qMlkHs8w eAk+hd9g5xlLQf7kvRl/hb0erc9S+QcW+XLxIqZHY03ggHQdyRSie3DE5 mtJPOiI6YfuFJVR4zx1rh/Z7XHGl3twVUOBReAzFVgVe2Nih9gKu4gDpe qeS6IqAJ02ey1JnpsNcbN2hJ2dtK3R2KDF+Kqw5ZnzF2g7PkPMgENfjqp A==; X-IronPort-AV: E=McAfee;i="6400,9594,10364"; a="275557228" X-IronPort-AV: E=Sophos;i="5.91,268,1647327600"; d="scan'208";a="275557228" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2022 03:55:09 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,268,1647327600"; d="scan'208";a="755862778" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.52]) by orsmga005.jf.intel.com with ESMTP; 01 Jun 2022 03:55:09 -0700 From: Hamza Khan To: Cc: dev@dpdk.org, Hamza Khan Subject: [PATCH 1/2] common: add safe version of foreach-list to Linux Date: Wed, 1 Jun 2022 10:54:54 +0000 Message-Id: <20220601105455.166505-1-hamza.khan@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Mailman-Approved-At: Sun, 05 Jun 2022 09:51:46 +0200 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 Linux EAL does not have the LIST_FOREACH_SAFE version of the iterator macros. Add it. Signed-off-by: Hamza Khan Acked-by: David Hunt --- lib/eal/linux/include/rte_os.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/eal/linux/include/rte_os.h b/lib/eal/linux/include/rte_os.h index c72bf5b7e6..00d7714181 100644 --- a/lib/eal/linux/include/rte_os.h +++ b/lib/eal/linux/include/rte_os.h @@ -26,6 +26,13 @@ extern "C" { #define RTE_STAILQ_HEAD(name, type) STAILQ_HEAD(name, type) #define RTE_STAILQ_ENTRY(type) STAILQ_ENTRY(type) +#ifndef LIST_FOREACH_SAFE +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) +#endif + #ifdef CPU_SETSIZE /* may require _GNU_SOURCE */ typedef cpu_set_t rte_cpuset_t; #define RTE_HAS_CPUSET From patchwork Wed Jun 1 10:54:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Khan, Hamza" X-Patchwork-Id: 112330 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 A86C6A00C2; Sun, 5 Jun 2022 09:52:04 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9C9D740041; Sun, 5 Jun 2022 09:51:50 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 43C71410EA; Wed, 1 Jun 2022 12:55:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654080914; x=1685616914; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vE957rAt9OW00McYjIZBghY0LaPcu29mg/RAXgPaTuw=; b=Ey0cgJeIzIrcqdCPcLB87qfHccFC71+zM4OvtEkOHTBGXTq00w2lcFbp iTgUj3Rh7KPivkWzVIsv6dr8NQ8DbvnnczLGZERBraI214zSNN4rb8ECK /r8UbX/OVfTqx22GZJ6+7BfkyBs03SOSp9TESlXfBKysBm0lNvKIKFL1Y F1fIVgvzMFh5433HFcjUIKWCYiOdH1HQR2sijxK9nScWxeobZVslzsGor Lr6+8RPHm71gUw9yQmiwAfHtGAQKZDLcQumw1ap7GQeuRIhG56fjZEC+I 0f41Al2TfmcvYhj/8hXCorrQF6em9Y4oVekHBQrmZOKBzEo+RvjF8uDHw w==; X-IronPort-AV: E=McAfee;i="6400,9594,10364"; a="275557241" X-IronPort-AV: E=Sophos;i="5.91,268,1647327600"; d="scan'208";a="275557241" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jun 2022 03:55:13 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,268,1647327600"; d="scan'208";a="755862804" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.52]) by orsmga005.jf.intel.com with ESMTP; 01 Jun 2022 03:55:12 -0700 From: Hamza Khan To: David Hunt , Alan Carew , Pablo de Lara Cc: dev@dpdk.org, Hamza Khan , stable@dpdk.org Subject: [PATCH 2/2] examples/vm_power_manager: use safe version of list iterator Date: Wed, 1 Jun 2022 10:54:55 +0000 Message-Id: <20220601105455.166505-2-hamza.khan@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220601105455.166505-1-hamza.khan@intel.com> References: <20220601105455.166505-1-hamza.khan@intel.com> MIME-Version: 1.0 X-Mailman-Approved-At: Sun, 05 Jun 2022 09:51:46 +0200 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 Currently, when vm_power_manager exits, we are using a LIST_FOREACH macro to iterate over VM info structures while freeing them. This leads to use-after-free error. To address this, use the newly added LIST_FOREACH_SAFE macro. Fixes: e8ae9b662506 ("examples/vm_power: channel manager and monitor in host") Cc: alan.carew@intel.com Cc: stable@dpdk.org Signed-off-by: Hamza Khan Acked-by: David Hunt Tested-by: Weiyuan Li --- examples/vm_power_manager/channel_manager.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c index 838465ab4b..bc95cec8d6 100644 --- a/examples/vm_power_manager/channel_manager.c +++ b/examples/vm_power_manager/channel_manager.c @@ -1005,9 +1005,9 @@ channel_manager_exit(void) { unsigned i; char mask[RTE_MAX_LCORE]; - struct virtual_machine_info *vm_info; + struct virtual_machine_info *vm_info, *tmp; - LIST_FOREACH(vm_info, &vm_list_head, vms_info) { + LIST_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, tmp) { rte_spinlock_lock(&(vm_info->config_spinlock));