From: "Hunt, David" <david.hunt@intel.com>
To: Hamza Khan <hamza.khan@intel.com>, <dev@dpdk.org>
Cc: <alan.carew@intel.com>, <stable@dpdk.org>
Subject: Re: [PATCH v3] examples/vm_power_manager: use safe version of list iterator
Date: Fri, 8 Jul 2022 10:28:17 +0100 [thread overview]
Message-ID: <478cac62-6c6f-68b1-b424-14f3139089d8@intel.com> (raw)
In-Reply-To: <20220708085141.925246-1-hamza.khan@intel.com>
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 <hamza.khan@intel.com>
>
> ---
> 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 <david.hunt@intel.com>
next prev parent reply other threads:[~2022-07-08 9:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-01 10:54 [PATCH 1/2] common: add safe version of foreach-list to Linux Hamza Khan
2022-06-01 10:54 ` [PATCH 2/2] examples/vm_power_manager: use safe version of list iterator Hamza Khan
2022-07-04 12:31 ` Hunt, David
2022-07-05 2:38 ` Li, WeiyuanX
2022-07-04 13:45 ` [PATCH 1/2] common: add safe version of foreach-list to Linux Khan, Hamza
2022-07-05 16:16 ` Thomas Monjalon
2022-07-07 15:59 ` Khan, Hamza
2022-07-07 19:09 ` Thomas Monjalon
2022-07-08 8:56 ` Khan, Hamza
2022-07-08 9:25 ` Thomas Monjalon
2022-07-08 9:28 ` Khan, Hamza
2022-07-07 15:48 ` [PATCH v2] examples/vm_power_manager: use safe version of list iterator Hamza Khan
2022-07-08 8:51 ` [PATCH v3] " Hamza Khan
2022-07-08 9:28 ` Hunt, David [this message]
2022-07-19 18:25 ` Pattan, Reshma
2022-08-22 10:58 ` [PATCH v4] " Reshma Pattan
2022-08-22 11:29 ` Hunt, David
2022-10-04 22:09 ` [PATCH v5] " Reshma Pattan
2022-10-05 10:17 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=478cac62-6c6f-68b1-b424-14f3139089d8@intel.com \
--to=david.hunt@intel.com \
--cc=alan.carew@intel.com \
--cc=dev@dpdk.org \
--cc=hamza.khan@intel.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).