DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH]librte_eal:add heap lock in malloc_heap_get_stats
@ 2017-09-21  3:19 liucheng (J)
  2017-10-06 20:19 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: liucheng (J) @ 2017-09-21  3:19 UTC (permalink / raw)
  To: dev

There is no lock in function malloc_heap_get_stats. When we call this function, the elem may free by other thread.

the call stack:
Core was generated by `ovs-vswitchd unix:/usr/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:info'.
Program terminated with signal 11, Segmentation fault.
#0  malloc_heap_get_stats (heap=0x7f3abf08ee1c, socket_stats=socket_stats@entry=0x7ffce811ffc0) at /usr/src/debug/dpdk-16.04/lib/librte_eal/common/malloc_heap.c:198
198                              socket_stats->heap_freesz_bytes += elem->size;
(gdb) bt
#0  malloc_heap_get_stats (heap=0x7f3abf08ee1c, socket_stats=socket_stats@entry=0x7ffce811ffc0) at /usr/src/debug/dpdk-16.04/lib/librte_eal/common/malloc_heap.c:198
#1  0x00007f3abd6d6299 in rte_malloc_get_socket_stats (socket=socket@entry=0, socket_stats=socket_stats@entry=0x7ffce811ffc0) at /usr/src/debug/dpdk-16.04/lib/librte_eal/common/rte_malloc.c:214
......



lib/librte_eal/common/malloc_heap.c | 3 +++
lib/librte_eal/common/malloc_heap.h | 2 +-
2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/malloc_heap.c b/lib/librte_eal/common/malloc_heap.c
index 267a4c6..1952ddd 100644
--- a/lib/librte_eal/common/malloc_heap.c
+++ b/lib/librte_eal/common/malloc_heap.c
@@ -189,6 +189,7 @@ malloc_heap_get_stats(const struct malloc_heap *heap,
       socket_stats->heap_freesz_bytes = 0;
       socket_stats->greatest_free_size = 0;
+       rte_spinlock_lock(&heap->lock);
       /* Iterate through free list */
       for (idx = 0; idx < RTE_HEAP_NUM_FREELISTS; idx++) {
                for (elem = LIST_FIRST(&heap->free_head[idx]);
@@ -200,6 +201,8 @@ malloc_heap_get_stats(const struct malloc_heap *heap,
                                   socket_stats->greatest_free_size = elem->size;
                }
       }
+       rte_spinlock_unlock(&heap->lock);
+
       /* Get stats on overall heap and allocated memory on this heap */
       socket_stats->heap_totalsz_bytes = heap->total_size;
       socket_stats->heap_allocsz_bytes = (socket_stats->heap_totalsz_bytes -
diff --git a/lib/librte_eal/common/malloc_heap.h b/lib/librte_eal/common/malloc_heap.h
index 3ccbef0..3b1166f 100644
--- a/lib/librte_eal/common/malloc_heap.h
+++ b/lib/librte_eal/common/malloc_heap.h
@@ -57,7 +57,7 @@ malloc_heap_alloc(struct malloc_heap *heap,  const char *type, size_t size,
                unsigned flags, size_t align, size_t bound);
 int
-malloc_heap_get_stats(const struct malloc_heap *heap,
+malloc_heap_get_stats(struct malloc_heap *heap,
                struct rte_malloc_socket_stats *socket_stats);
 int

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [dpdk-dev] [PATCH]librte_eal:add heap lock in malloc_heap_get_stats
  2017-09-21  3:19 [dpdk-dev] [PATCH]librte_eal:add heap lock in malloc_heap_get_stats liucheng (J)
@ 2017-10-06 20:19 ` Thomas Monjalon
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Monjalon @ 2017-10-06 20:19 UTC (permalink / raw)
  To: liucheng (J); +Cc: dev, sergio.gonzalez.monroy

Hi,
We need a Signed-off-by to process your contribution.
Thank you

+Cc sergio.gonzalez.monroy@intel.com


21/09/2017 05:19, liucheng (J):
> There is no lock in function malloc_heap_get_stats. When we call this function, the elem may free by other thread.
> 
> the call stack:
> Core was generated by `ovs-vswitchd unix:/usr/var/run/openvswitch/db.sock -vconsole:emer -vsyslog:info'.
> Program terminated with signal 11, Segmentation fault.
> #0  malloc_heap_get_stats (heap=0x7f3abf08ee1c, socket_stats=socket_stats@entry=0x7ffce811ffc0) at /usr/src/debug/dpdk-16.04/lib/librte_eal/common/malloc_heap.c:198
> 198                              socket_stats->heap_freesz_bytes += elem->size;
> (gdb) bt
> #0  malloc_heap_get_stats (heap=0x7f3abf08ee1c, socket_stats=socket_stats@entry=0x7ffce811ffc0) at /usr/src/debug/dpdk-16.04/lib/librte_eal/common/malloc_heap.c:198
> #1  0x00007f3abd6d6299 in rte_malloc_get_socket_stats (socket=socket@entry=0, socket_stats=socket_stats@entry=0x7ffce811ffc0) at /usr/src/debug/dpdk-16.04/lib/librte_eal/common/rte_malloc.c:214
> ......
> 
> lib/librte_eal/common/malloc_heap.c | 3 +++
> lib/librte_eal/common/malloc_heap.h | 2 +-
> 2 files changed, 4 insertions(+), 1 deletion(-)

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-06 20:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-21  3:19 [dpdk-dev] [PATCH]librte_eal:add heap lock in malloc_heap_get_stats liucheng (J)
2017-10-06 20:19 ` Thomas Monjalon

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).