[5/8] trace: fix race in debug dump

Message ID 20220921120359.2201131-6-david.marchand@redhat.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series Trace subsystem fixes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand Sept. 21, 2022, 12:03 p.m. UTC
  trace->nb_trace_mem_list access must be under trace->lock to avoid
races with threads allocating/freeing their trace buffers.

Fixes: f6b2d65dcd5d ("trace: implement debug dump")
Cc: stable@dpdk.org

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/eal/common/eal_common_trace.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Comments

Jerin Jacob Oct. 11, 2022, 2:37 p.m. UTC | #1
On Wed, Sep 21, 2022 at 5:35 PM David Marchand
<david.marchand@redhat.com> wrote:
>
> trace->nb_trace_mem_list access must be under trace->lock to avoid
> races with threads allocating/freeing their trace buffers.
>
> Fixes: f6b2d65dcd5d ("trace: implement debug dump")
> Cc: stable@dpdk.org
>
> Signed-off-by: David Marchand <david.marchand@redhat.com>

Acked-by: Jerin Jacob <jerinj@marvell.com>


> ---
>  lib/eal/common/eal_common_trace.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
> index afc4c6dbe5..5280aa7d62 100644
> --- a/lib/eal/common/eal_common_trace.c
> +++ b/lib/eal/common/eal_common_trace.c
> @@ -255,10 +255,9 @@ trace_lcore_mem_dump(FILE *f)
>         struct __rte_trace_header *header;
>         uint32_t count;
>
> -       if (trace->nb_trace_mem_list == 0)
> -               return;
> -
>         rte_spinlock_lock(&trace->lock);
> +       if (trace->nb_trace_mem_list == 0)
> +               goto out;
>         fprintf(f, "nb_trace_mem_list = %d\n", trace->nb_trace_mem_list);
>         fprintf(f, "\nTrace mem info\n--------------\n");
>         for (count = 0; count < trace->nb_trace_mem_list; count++) {
> @@ -269,6 +268,7 @@ trace_lcore_mem_dump(FILE *f)
>                 header->stream_header.lcore_id,
>                 header->stream_header.thread_name);
>         }
> +out:
>         rte_spinlock_unlock(&trace->lock);
>  }
>
> --
> 2.37.3
>
  

Patch

diff --git a/lib/eal/common/eal_common_trace.c b/lib/eal/common/eal_common_trace.c
index afc4c6dbe5..5280aa7d62 100644
--- a/lib/eal/common/eal_common_trace.c
+++ b/lib/eal/common/eal_common_trace.c
@@ -255,10 +255,9 @@  trace_lcore_mem_dump(FILE *f)
 	struct __rte_trace_header *header;
 	uint32_t count;
 
-	if (trace->nb_trace_mem_list == 0)
-		return;
-
 	rte_spinlock_lock(&trace->lock);
+	if (trace->nb_trace_mem_list == 0)
+		goto out;
 	fprintf(f, "nb_trace_mem_list = %d\n", trace->nb_trace_mem_list);
 	fprintf(f, "\nTrace mem info\n--------------\n");
 	for (count = 0; count < trace->nb_trace_mem_list; count++) {
@@ -269,6 +268,7 @@  trace_lcore_mem_dump(FILE *f)
 		header->stream_header.lcore_id,
 		header->stream_header.thread_name);
 	}
+out:
 	rte_spinlock_unlock(&trace->lock);
 }