kni: fix unit test segfault
PATCH 1/1 kni: fix unit test segfault
To clean alloc_q, which has physicall addresses of the mbufs, kni lib free the pkt_mempool, but this leads a crash in kni unit test.
KNI library shouldn't free the pkt_mempool.
Implementation updated to find the mbufs in the alloc_q and return them back to mempool.
--- lib/librte_kni/rte_kni.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
lib/librte_kni/rte_kni.c +22 -12
@@ -451,17 +451,35 @@ kni_free_fifo(struct rte_kni_fifo *fifo) }while (ret); } +static void * +va2pa (struct rte_mbuf *m) +{ +return (void *)((unsigned long )m - + ((unsigned long )m->buf_addr - + (unsigned long )m->buf_physaddr)); +} +static void -kni_free_fifo_phy (struct rte_mempool *pktmbuf_pool,struct rte_kni_fifo *fifo) +obj_free(struct rte_mempool *mp __rte_unused, void *opaque, void *obj, +unsigned obj_idx __rte_unused) +{ +struct rte_mbuf *m = obj; +void *mbuf_phys = opaque; + +if (va2pa (m) == mbuf_phys) +rte_pktmbuf_free (m); +} + +static void +kni_free_fifo_phy (struct rte_mempool *mp,struct rte_kni_fifo *fifo) {void *mbuf_phys;int ret; -rte_mempool_free (pktmbuf_pool); - -/* All mbufs alredy freed with rte_mempoll_free, just free the fifo */ do { ret =kni_fifo_get (fifo, &mbuf_phys,1 ); +if (ret) +rte_mempool_obj_iter (mp, obj_free, mbuf_phys); }while (ret); }
@@ -557,14 +575,6 @@ rte_kni_handle_request(struct rte_kni *kni)return 0 ; } -static void * -va2pa (struct rte_mbuf *m) -{ -return (void *)((unsigned long )m - - ((unsigned long )m->buf_addr - - (unsigned long )m->buf_physaddr)); -} -unsigned rte_kni_tx_burst (struct rte_kni *kni,struct rte_mbuf **mbufs,unsigned num) {
Signature · 1 line
2.9.3
Hi Ferruh,
Even w/o this patch, I mostly find mbufs returned by rte_kni_rx_burst() always 0 (or sometimes 1) where as more than 32000 mbufs approx created in ingress side for this test.
dpdk/test/test $ ./test -l 0,1,2 --socket-mem 1024
Am I missing something required for this unit test ?.
Thanks,
Gowrishankar
Quoted 74 lines · Ferruh Yigit
To clean
alloc_q, which has physicall addresses of the mbufs, kni lib free thepkt_mempool, but this leads a crash in kni unit test.KNI library shouldn't free the
pkt_mempool.Implementation updated to find the mbufs in the
alloc_qand return them back to mempool.Fixes 8eba5ebd1811 ("kni: fix possible memory leak")Signed-off-by Ferruh Yigit <[email protected]>--- lib/librte_kni/rte_kni.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)lib/librte_kni/rte_kni.c +22
-12@@ -451,17 +451,35 @@ kni_free_fifo(struct rte_kni_fifo *fifo) }while (ret); } +static void * +va2pa (struct rte_mbuf *m) +{ +return (void *)((unsigned long )m - + ((unsigned long )m->buf_addr - + (unsigned long )m->buf_physaddr)); +} +static void -kni_free_fifo_phy (struct rte_mempool *pktmbuf_pool,struct rte_kni_fifo *fifo) +obj_free(struct rte_mempool *mp __rte_unused, void *opaque, void *obj, +unsigned obj_idx __rte_unused) +{ +struct rte_mbuf *m = obj; +void *mbuf_phys = opaque; + +if (va2pa (m) == mbuf_phys) +rte_pktmbuf_free (m); +} + +static void +kni_free_fifo_phy (struct rte_mempool *mp,struct rte_kni_fifo *fifo) {void *mbuf_phys;int ret; -rte_mempool_free (pktmbuf_pool); - -/* All mbufs alredy freed with rte_mempoll_free, just free the fifo */ do { ret =kni_fifo_get (fifo, &mbuf_phys,1 ); +if (ret) +rte_mempool_obj_iter (mp, obj_free, mbuf_phys); }while (ret); }@@ -557,14 +575,6 @@ rte_kni_handle_request(struct rte_kni *kni)return 0 ; } -static void * -va2pa (struct rte_mbuf *m) -{ -return (void *)((unsigned long )m - - ((unsigned long )m->buf_addr - - (unsigned long )m->buf_physaddr)); -} -unsigned rte_kni_tx_burst (struct rte_kni *kni,struct rte_mbuf **mbufs,unsigned num) {
Quoted 10 lines · gowrishankar muthukrishnan
Hi Ferruh,
Even w/o this patch, I mostly find mbufs returned byrte_kni_rx_burst()always 0
(or sometimes 1) where as more than 32000 mbufs approx created in ingress side
for this test.dpdk/test/test $ ./test -l 0,1,2 --socket-mem 1024Am I missing something required for this unit test ?.
Hi Gowrishankar,
KNI module should be inserted with one of the loopback options [1] for the unit test.
[1]
There are two loopback options supported, both loopbacks Rx/Tx path in kernel side, this is easy way to test KNI.
options are: lo_mode_fifo and lo_mode_fifo_skb
usage:
insmod build/kmod/rte_kni.ko lo_mode=lo_mode_fifo or
insmod build/kmod/rte_kni.ko lo_mode=lo_mode_fifo_skb
Regards,
ferruh
Quoted 81 lines
Thanks,
GowrishankarQuoted 74 lines · Ferruh Yigit
To clean
alloc_q, which has physicall addresses of the mbufs, kni lib free thepkt_mempool, but this leads a crash in kni unit test.KNI library shouldn't free the
pkt_mempool.Implementation updated to find the mbufs in the
alloc_qand return them back to mempool.Fixes 8eba5ebd1811 ("kni: fix possible memory leak")Signed-off-by Ferruh Yigit <[email protected]>--- lib/librte_kni/rte_kni.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)lib/librte_kni/rte_kni.c +22
-12@@ -451,17 +451,35 @@ kni_free_fifo(struct rte_kni_fifo *fifo) }while (ret); } +static void * +va2pa (struct rte_mbuf *m) +{ +return (void *)((unsigned long )m - + ((unsigned long )m->buf_addr - + (unsigned long )m->buf_physaddr)); +} +static void -kni_free_fifo_phy (struct rte_mempool *pktmbuf_pool,struct rte_kni_fifo *fifo) +obj_free(struct rte_mempool *mp __rte_unused, void *opaque, void *obj, +unsigned obj_idx __rte_unused) +{ +struct rte_mbuf *m = obj; +void *mbuf_phys = opaque; + +if (va2pa (m) == mbuf_phys) +rte_pktmbuf_free (m); +} + +static void +kni_free_fifo_phy (struct rte_mempool *mp,struct rte_kni_fifo *fifo) {void *mbuf_phys;int ret; -rte_mempool_free (pktmbuf_pool); - -/* All mbufs alredy freed with rte_mempoll_free, just free the fifo */ do { ret =kni_fifo_get (fifo, &mbuf_phys,1 ); +if (ret) +rte_mempool_obj_iter (mp, obj_free, mbuf_phys); }while (ret); }@@ -557,14 +575,6 @@ rte_kni_handle_request(struct rte_kni *kni)return 0 ; } -static void * -va2pa (struct rte_mbuf *m) -{ -return (void *)((unsigned long )m - - ((unsigned long )m->buf_addr - - (unsigned long )m->buf_physaddr)); -} -unsigned rte_kni_tx_burst (struct rte_kni *kni,struct rte_mbuf **mbufs,unsigned num) {
Thomas Monjalon
Applied03/05/2017 18:10, Ferruh Yigit:
Quoted 11 lines
To clean
alloc_q, which has physicall addresses of the mbufs, kni lib free thepkt_mempool, but this leads a crash in kni unit test.KNI library shouldn't free the
pkt_mempool.Implementation updated to find the mbufs in the
alloc_qand return them back to mempool.Fixes 8eba5ebd1811 ("kni: fix possible memory leak")Signed-off-by Ferruh Yigit <[email protected]>
Applied, thanks