Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22048

segmentation fault when using a non NULL pointer

$
0
0

there is a weird problem as title when using dpdk,

When I use rte_pktmbuf_alloc(struct rte_mempool *) and already verify the return value of rte_pktmbuf_pool_create() is not NULL, the process receive segmentation fault.

Follow

ing message is output of gdb in dpdk source code:Thread 1 "osw" received signal SIGSEGV, Segmentation fault.0x00000000005e9f41 in __mempool_generic_get (cache=0x1a7dfc000000000, n=1, obj_table=0x7fffffffdec8, mp=0x101a7df00)at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:14491449            if (unlikely(cache == NULL || n >= cache->size))(gdb) p cache$1 = (struct rte_mempool_cache *) 0x1a7dfc000000000(gdb) bt0  0x00000000005e9f41 in __mempool_generic_get (cache=0x1a7dfc000000000, n=1, obj_table=0x7fffffffdeb8, mp=0x101a7df00)   at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:14491  rte_mempool_generic_get (cache=0x1a7dfc000000000, n=1, obj_table=0x7fffffffdeb8, mp=0x101a7df00)   at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:15172  rte_mempool_get_bulk (n=1, obj_table=0x7fffffffdeb8, mp=0x101a7df00)   at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:15523  rte_mempool_get (obj_p=0x7fffffffdeb8, mp=0x101a7df00) at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:15784  rte_mbuf_raw_alloc (mp=0x101a7df00) at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mbuf.h:5865  rte_pktmbuf_alloc (mp=0x101a7df00) at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mbuf.h:896

And I dig into rte_mempool.h:

and change line 1449-1450

1449  if (unlikely(cache == NULL || n >= cache->size))1450         goto ring_dequeue;

to

1449  if (unlikely(cache == NULL))1450          goto ring_dequeue;1451  if (unlikely(n >= cache->size))1452          goto ring_dequeue;

and it also fail at line 1451

the gdb output message after changing:

Thread 1 "osw" received signal SIGSEGV, Segmentation fault.__mempool_generic_get (cache=0x1a7dfc000000000, n=1, obj_table=0x7fffffffdeb8, mp=0x101a7df00)   at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:14511451            if (unlikely(n >= cache->size))(gdb) p cache$1 = (struct rte_mempool_cache *) 0x1a7dfc000000000(gdb) bt0  __mempool_generic_get (cache=0x1a7dfc000000000, n=1, obj_table=0x7fffffffdeb8, mp=0x101a7df00)   at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:14511  rte_mempool_generic_get (cache=0x1a7dfc000000000, n=1, obj_table=0x7fffffffdeb8, mp=0x101a7df00)   at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:15192  rte_mempool_get_bulk (n=1, obj_table=0x7fffffffdeb8, mp=0x101a7df00)   at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:15543  rte_mempool_get (obj_p=0x7fffffffdeb8, mp=0x101a7df00) at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mempool.h:15804  rte_mbuf_raw_alloc (mp=0x101a7df00) at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mbuf.h:5865  rte_pktmbuf_alloc (mp=0x101a7df00) at /root/dpdk-20.05/x86_64-native-linuxapp-gcc/include/rte_mbuf.h:8966  main (argc=<optimized out>, argv=<optimized out>) at ofpd.c:150(gdb) p cache->sizeCannot access memory at address 0x1a7dfc000000000

It looks like the memory address “cache” pointer stored is not NULL but it actually is a NULL pointer.

I have no idea that why does the "cache" pointer address be non zero at prefix 4 bytes and zero at postfix 4 bytes.

The DPDK version is 20.05, I also tried 18.11 and 19.11.

OS is CentOS 8.1 kernel is 4.18.0-147.el8.x86_64.

CPU is AMD EPYC 7401P.

#define                 RING_SIZE       16384#define                 NUM_MBUFS       8191#define                 MBUF_CACHE_SIZE 512int main(int argc, char **argv){    int             ret;    uint16_t        portid;    unsigned        cpu_id = 1;    struct rte_mempool  *tmp;    int arg = rte_eal_init(argc, argv);    if (arg < 0)         rte_exit(EXIT_FAILURE, "Cannot init EAL: %s\n", rte_strerror(rte_errno));    if (rte_lcore_count() < 10)        rte_exit(EXIT_FAILURE, "We need at least 10 cores.\n");    argc -= arg;    argv += arg;    /* Creates a new mempool in memory to hold the mbufs. */    tmp = rte_pktmbuf_pool_create("TMP", NUM_MBUFS, MBUF_CACHE_SIZE, 0, RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());    if (tmp == NULL)        rte_exit(EXIT_FAILURE, "Cannot create mbuf pool, %s\n", rte_strerror(rte_errno));    printf("tmp addr = %x\n", tmp);    struct rte_mbuf *test = rte_pktmbuf_alloc(tmp);    rte_exit(EXIT_FAILURE, "end\n");}

I have ever faced same problem when using the return pointer of getifaddrs(), it also got segmentation fault, I had to shift the pointer address like

ifa->ifa_addr = (struct sockaddr *)((uintptr_t)(ifa->ifa_addr) >> 32);

and then it can work normally.

Thereforer, I think this is not dpdk specific issue.

Does anyone know this issue?

Thanks.


Viewing all articles
Browse latest Browse all 22048

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>