From patchwork Tue Oct 4 22:09:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pattan, Reshma" X-Patchwork-Id: 117344 X-Patchwork-Delegate: thomas@monjalon.net 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 21F1AA0542; Wed, 5 Oct 2022 00:09:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 0738E40A7D; Wed, 5 Oct 2022 00:09:11 +0200 (CEST) Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mails.dpdk.org (Postfix) with ESMTP id 852D640041; Wed, 5 Oct 2022 00:09:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664921349; x=1696457349; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OM51cagxd/CwiQrJOMeuSqBN4ZTQaankT1pxn9FJGjo=; b=eNiavQ4lxh+gQn4XnSXDp6LLlTcAc477yO0bUokVeuwCyuuNIjwrVo8w wjqoJVCOruoTXm5cOz9AgtgFvDauWc8nN3dvDB2hBlcRx4Sia92taVRlT Wb53d7gAm4iTtNJLrG2jpYYkEVUDPxakFigxoX0YlLrdmrQ1+O9Q8USXH 8rKyk39ybH/cj9hV9Dhc7e2ObYEDzzg41hzWIsI/jVm+EP4ePXzEjDyjQ U3IC+l0rTDIGqs3/e5MRNUGEcnUEQzD7//1iOztXMrE+Wlbtf3/93gC0S C4xJi5HV3t/olSCyyGF3OHPyxXEZn3Ck+QAzxxzlrWeh5m5LCSk5p7adI w==; X-IronPort-AV: E=McAfee;i="6500,9779,10490"; a="286250912" X-IronPort-AV: E=Sophos;i="5.95,158,1661842800"; d="scan'208";a="286250912" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Oct 2022 15:09:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10490"; a="728425247" X-IronPort-AV: E=Sophos;i="5.95,158,1661842800"; d="scan'208";a="728425247" Received: from silpixa00401314.ir.intel.com ([10.243.23.141]) by fmsmga002.fm.intel.com with ESMTP; 04 Oct 2022 15:09:06 -0700 From: Reshma Pattan To: dev@dpdk.org Cc: Hamza Khan , alan.carew@intel.com, stable@dpdk.org, Reshma Pattan , David Hunt Subject: [PATCH v5] examples/vm_power_manager: use safe version of list iterator Date: Tue, 4 Oct 2022 23:09:04 +0100 Message-Id: <20221004220904.474852-1-reshma.pattan@intel.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220822105855.6180-1-reshma.pattan@intel.com> References: <20220822105855.6180-1-reshma.pattan@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: Hamza Khan 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 Signed-off-by: Reshma Pattan Acked-by: David Hunt --- 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..cb872ad2d5 100644 --- a/examples/vm_power_manager/channel_manager.c +++ b/examples/vm_power_manager/channel_manager.c @@ -22,6 +22,7 @@ #include #include #include +#include #include @@ -30,6 +31,7 @@ #include "power_manager.h" + #define RTE_LOGTYPE_CHANNEL_MANAGER RTE_LOGTYPE_USER1 struct libvirt_vm_info lvm_info[MAX_CLIENTS]; @@ -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); }