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 104FCA0543; Thu, 7 Jul 2022 21:09:18 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id A009A40A7B; Thu, 7 Jul 2022 21:09:17 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 3AAD44069D; Thu, 7 Jul 2022 17:48:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657208923; x=1688744923; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=RScuEE4++t383H9OhPnsrpF5No4Pz9xaFmtBYuEhHTo=; b=hHcVpPrlos8A6sjlXvqoOGqgsgUUdUSz5u3uRlETRkznffIH+INoA42d 8KL6Cg3ykIhuX8ktkk/iexE59Xpp3p61T3axH1wScL+suZ7+Upp8GuorR ruLQirufGhOE2eAMlWWTa6MY5wQGeu0y9PI7drQ8ByOg2P6/kLbszv77T 3LrI9ibrX/PG4pJQ13fMDcogJ1WMFf928tDhZ0k5O6MmHhf/QXhDy0uSm 7HI6DRDSAMqL+yXnulJNy/OEo4ynUXQA16NXIVVAYtv8pPqOVyAUkdTp5 PUb2oy7WKvPvtSx+hLfwOVGp2SfRjHBYRTgpNXBYdXiAhxNNla10IPhx1 A==; X-IronPort-AV: E=McAfee;i="6400,9594,10400"; a="285184127" X-IronPort-AV: E=Sophos;i="5.92,253,1650956400"; d="scan'208";a="285184127" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Jul 2022 08:48:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,253,1650956400"; d="scan'208";a="598070395" Received: from silpixa00399752.ir.intel.com (HELO silpixa00399752.ger.corp.intel.com) ([10.237.222.52]) by fmsmga007.fm.intel.com with ESMTP; 07 Jul 2022 08:48:36 -0700 From: Hamza Khan To: dev@dpdk.org Cc: david.hunt@intel.com, Hamza Khan , alan.carew@intel.com, stable@dpdk.org Subject: [PATCH v2] examples/vm_power_manager: use safe version of list iterator Date: Thu, 7 Jul 2022 15:48:29 +0000 Message-Id: <20220707154829.918694-1-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 Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Thu, 07 Jul 2022 21:09:16 +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, replace all usages of LIST_* with TAILQ_* macros, and use the RTE_TAILQ_FOREACH_SAFE macro to iterate and delete VM info structures. 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 --- examples/vm_power_manager/channel_manager.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/examples/vm_power_manager/channel_manager.c b/examples/vm_power_manager/channel_manager.c index 838465ab4b..e82c26ddca 100644 --- a/examples/vm_power_manager/channel_manager.c +++ b/examples/vm_power_manager/channel_manager.c @@ -29,6 +29,8 @@ #include "channel_monitor.h" #include "power_manager.h" +#include "rte_tailq.h" + #define RTE_LOGTYPE_CHANNEL_MANAGER RTE_LOGTYPE_USER1 @@ -58,16 +60,16 @@ struct virtual_machine_info { virDomainInfo info; rte_spinlock_t config_spinlock; int allow_query; - LIST_ENTRY(virtual_machine_info) vms_info; + RTE_TAILQ_ENTRY(virtual_machine_info) vms_info; }; -LIST_HEAD(, virtual_machine_info) vm_list_head; +RTE_TAILQ_HEAD(, virtual_machine_info) vm_list_head; static struct virtual_machine_info * find_domain_by_name(const char *name) { struct virtual_machine_info *info; - LIST_FOREACH(info, &vm_list_head, vms_info) { + RTE_TAILQ_FOREACH(info, &vm_list_head, vms_info) { if (!strncmp(info->name, name, CHANNEL_MGR_MAX_NAME_LEN-1)) return info; } @@ -878,7 +880,7 @@ add_vm(const char *vm_name) new_domain->allow_query = 0; rte_spinlock_init(&(new_domain->config_spinlock)); - LIST_INSERT_HEAD(&vm_list_head, new_domain, vms_info); + TAILQ_INSERT_HEAD(&vm_list_head, new_domain, vms_info); return 0; } @@ -900,7 +902,7 @@ remove_vm(const char *vm_name) rte_spinlock_unlock(&vm_info->config_spinlock); return -1; } - LIST_REMOVE(vm_info, vms_info); + TAILQ_REMOVE(&vm_list_head, vm_info, vms_info); rte_spinlock_unlock(&vm_info->config_spinlock); rte_free(vm_info); return 0; @@ -953,7 +955,7 @@ channel_manager_init(const char *path __rte_unused) { virNodeInfo info; - LIST_INIT(&vm_list_head); + TAILQ_INIT(&vm_list_head); if (connect_hypervisor(path) < 0) { global_n_host_cpus = 64; global_hypervisor_available = 0; @@ -1005,9 +1007,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) { + RTE_TAILQ_FOREACH_SAFE(vm_info, &vm_list_head, vms_info, tmp) { rte_spinlock_lock(&(vm_info->config_spinlock)); @@ -1022,7 +1024,7 @@ channel_manager_exit(void) } rte_spinlock_unlock(&(vm_info->config_spinlock)); - LIST_REMOVE(vm_info, vms_info); + TAILQ_REMOVE(&vm_list_head, vm_info, vms_info); rte_free(vm_info); } -- 2.25.1