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 7E431A0540; Fri, 8 Jul 2022 11:28:28 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 70C654280C; Fri, 8 Jul 2022 11:28:28 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by mails.dpdk.org (Postfix) with ESMTP id 674894021E; Fri, 8 Jul 2022 11:28:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657272506; x=1688808506; h=message-id:date:subject:to:cc:references:from: in-reply-to:content-transfer-encoding:mime-version; bh=rTn+5RWiVYJaX7GYnfRh7zkw9Xu74uHqzM9a664mNFY=; b=L4L/PtwLd2BYk1slJsfNsQYAlt1GMqGgFKKPxAtbSrpodMfSA2kMrrp/ Wg9/8QcxupOyLQud3nytV2WulPqnQIgaE1l3L558KZVrJXMGlGnfwuMEr mWD0m+8of9k2E7VHAIT1gJP+QfngKjW12IAb5KTwpwbbvgDdQpQGzErc3 FN/UQ9KWD3jcU9kgO+m7fiw+wP3cFDbnjdkNvUuCQULA8sdBlGdmglSzH Bjgi/3IF9UXURi/hB2EjCJnMopt7MQIAgJUPvGV5UhgktrlSGNZnj3GJI OtGGMU5ywjJ1gmDC1Zss6va2fjuokZpN/68ClLDdYChdNFPcpokV+K6Ld Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10401"; a="285369190" X-IronPort-AV: E=Sophos;i="5.92,255,1650956400"; d="scan'208";a="285369190" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Jul 2022 02:28:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,255,1650956400"; d="scan'208";a="598320812" Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by fmsmga007.fm.intel.com with ESMTP; 08 Jul 2022 02:28:25 -0700 Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 8 Jul 2022 02:28:24 -0700 Received: from fmsmsx609.amr.corp.intel.com (10.18.126.89) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27; Fri, 8 Jul 2022 02:28:24 -0700 Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx609.amr.corp.intel.com (10.18.126.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.27 via Frontend Transport; Fri, 8 Jul 2022 02:28:24 -0700 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (104.47.73.173) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2308.27; Fri, 8 Jul 2022 02:28:23 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BIT+qVPzwdLM8hcqmJjOBH02puo2fcIfpM3IT52zcRvxNIaWrPfgRvLCIb0Be/uyzLZ9Bh/n2mfw3pfNYL1MKprGnr5vE79ON6i2OdEB06p2AQeV7l3ZTf7+P/oybVStNkVK4a6Thx6Bj3y9yBrwW95OEUQTczBwiu4cNlehlPvgACt1qHKda7NGNPVn3bc3p14yYNdwPMG93okiVTRPw7xdbEUINMmlHGQUU+e1B+9yiF15FBhrTfV/xt11wLIPHYD7gbOKQrI6tGo9qiP5JpenZtkIHF7XapR7w9/xBfZLUWaavx8Vt3PTli2MRLbjAoRWS9ZF7SBRyk3WsN6oNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=yAtWx2ihlw0SpiiqLT6J9krCkg3Zw5OrJsMk/+jcj3w=; b=cOM3HehPiGyu67XZc4A/w2/BJKjftjXEvJNpu+GoVleromQS6axGZsO63ojLCh2Pxn/274N8i6q2KEJmexzYToIe7eUT+Nb+629GOD66havWrlwN4xgrw+VHThiwMcK/L2/3nmsirNR8z3hvAaEgNDUmoiKhrrITEDihB15LISyt3Q774Q5FJtpHy6USD54dOsbXBNkUxJLcqZJMI0T0ICZp76hEZADA1Wvbo+1ox40O0Pm3IVVe5IaSkqVkz2AOlDKrsMwL49TdxuFyBcT2KEHATlqcRu/UP7edzNa45bwM1wMcCR4//dLuc3AevkFSQwaJvEVp2mGfxGy9b6uU4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from BYAPR11MB3799.namprd11.prod.outlook.com (2603:10b6:a03:fb::19) by BYAPR11MB3800.namprd11.prod.outlook.com (2603:10b6:a03:f5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5417.20; Fri, 8 Jul 2022 09:28:22 +0000 Received: from BYAPR11MB3799.namprd11.prod.outlook.com ([fe80::1c02:23cc:c50f:aa92]) by BYAPR11MB3799.namprd11.prod.outlook.com ([fe80::1c02:23cc:c50f:aa92%4]) with mapi id 15.20.5395.014; Fri, 8 Jul 2022 09:28:22 +0000 Message-ID: <478cac62-6c6f-68b1-b424-14f3139089d8@intel.com> Date: Fri, 8 Jul 2022 10:28:17 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v3] examples/vm_power_manager: use safe version of list iterator Content-Language: en-US To: Hamza Khan , CC: , References: <20220601105455.166505-1-hamza.khan@intel.com> <20220708085141.925246-1-hamza.khan@intel.com> From: "Hunt, David" In-Reply-To: <20220708085141.925246-1-hamza.khan@intel.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: LO4P265CA0214.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:33a::9) To BYAPR11MB3799.namprd11.prod.outlook.com (2603:10b6:a03:fb::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2b2c1e02-d87c-40d3-9c08-08da60c4338f X-MS-TrafficTypeDiagnostic: BYAPR11MB3800:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hsXXSM+VJo76jY22deiquqLEaM7h1dMUiawjd/uc91IT27Dq7lCGIsVLcvJexm0UjJ7qPYqYDYe/aXLrlegd0EmEJC41dvqwpT+sFSmQsoxIUw7VdrBQ364K6UL+TbjxzTahA1+HjZZZ8G9/KAZNAhlQ+jBiEHJQFc0M8br7Uc0E8SEhDIxUF8ubtYeR7OdT8VwuNW73/mi7OlcRd6NPVB6JodMnbN0exiDG+/pIla1CV5xACYJsa9GtrxHywDKzQhGtOI3dkIELM6ULrrxyuhX4RYe6v8pPSghX/MxofrqILibUb5lRDVFSG/iURU704kDNpEUE2i9athLC2PCN4bOCE98LUiJzOz5bdqDvLZCnml2Gf4D5zD6Edd1EMOzsIrfceIbPjh4PZezve920c3qDCDzeZAP8Xzz2sIsFHeaEUMSSV5JbAgWN4aDo0AmmNsbRl1lwTWkutwdjEWc0pVdqpYFI3+HA2zV4bSzyCYzPiS1aUKTc/3Xrd94zxJdc1w8eiui5DZeZvP6S3I2kLUK+cdzoCtBDf6kIjk6sZlINty9pMUnA0lcn5a0zm6AAOSPWHRjCUU/PfaOJUASGi4EMqkBZ17b5ZR/jpzzG2guAS0x+7QfdQb96Ut2opL2a2Lg5A17HRT9yi/96E+tzZqmTlvhXU0QtOYbsr2ckm68hKAeALMhZ3K0u1jqr7LeTwOoFt3V/6J04TGaXHQg/mTwYmmzSM7e30nxgTy0T5y92AJ+ycjaGExoh1Rqf9Hnpbd3hs9HANrfNKzZoEM6b6tVLMz+eiQ9FGiy/yxbdUmCR6D32u6DaZtUKG6LQmlBKGXJ1FYKa2bsUNO4HN7l/HghNt62ySQ5/3vsvxbU3QMQ= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR11MB3799.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(366004)(39860400002)(346002)(136003)(376002)(396003)(66476007)(450100002)(66946007)(8676002)(66556008)(4326008)(82960400001)(53546011)(31696002)(6512007)(26005)(6486002)(6666004)(6506007)(41300700001)(86362001)(186003)(2616005)(316002)(38100700002)(2906002)(31686004)(478600001)(36756003)(5660300002)(83380400001)(8936002)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?RFR3UUN3Y3IwOTF1TVdqMlZDWXpRYlR0amk1a2dhNE4xSkZHSWo0cWowK09o?= =?utf-8?B?WDNFaHB5TnJqZ1dicmZRbTdkLzYrZ2dEaEVZdTdkVE9uTDc3aTFtY3NrN0c1?= =?utf-8?B?Rko5OUdqV1FqVkJPbk5ESTl2dzdiWmJqVDMyQnZQNlV4Vm05NDh1RDZwS0tt?= =?utf-8?B?WTBUK3RzK0lIVW5VMkVrcH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ENyRVVocGNpdXhxdWxS?= =?utf-8?B?OURydDlBMlhGcS9Ibk1RMDdHbHJhaVlOWmRsb1l0c2FoREVEUWtBZFZVZzYx?= =?utf-8?B?cVhWZkxHVk1uaWRpVmd6aXJrUFQxL3VYMEJFaSs3Umphc0RPNVdHRDZPMSsw?= =?utf-8?B?VDU2NllEbTRwVjBvL3N2RmZsbHlncUEwUHYxdjRhZ3RHcHZzdzE2Q21RVTU3?= =?utf-8?B?NEE9PQ==?= X-MS-Exchange-CrossTenant-Network-Message-Id: 2b2c1e02-d87c-40d3-9c08-08da60c4338f X-MS-Exchange-CrossTenant-AuthSource: BYAPR11MB3799.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Jul 2022 09:28:22.3596 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: la3v51ZhtuIrUw4HMWIhvLEUo3/QIM3uy1DUCUIrclRP2osqGvUU8/LOvwyZ2ok35R/Ehg00LzJYsVLcrzRfDg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR11MB3800 X-OriginatorOrg: intel.com 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 On 08/07/2022 09:51, Hamza Khan wrote: > 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. > > * The change is small and doesn’t affect other code > * Testing was performed on the patch > > 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 > > --- > V3: Update commit message > V2: Use RTE_TAILQ_* marcos > --- > 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); > } > Acked-by: David Hunt