diff mbox series

[v2] kni: fix wrong mbuf alloc count in kni_allocate_mbufs

Message ID 4aebf99afe5bae2b25f2e5445a32243ffd6f7e97.1624359204.git.wangyunjian@huawei.com (mailing list archive)
State Superseded, archived
Headers show
Series [v2] kni: fix wrong mbuf alloc count in kni_allocate_mbufs | expand

Checks

Context Check Description
ci/iol-mellanox-Functional fail Functional Testing issues
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-intel-Functional fail Functional Testing issues
ci/intel-Testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/github-robot success github build: passed
ci/Intel-compilation success Compilation OK
ci/checkpatch warning coding style issues

Commit Message

Yunjian Wang June 22, 2021, 10:57 a.m. UTC
From: Yunjian Wang <wangyunjian@huawei.com>

In kni_allocate_mbufs(), we alloc mbuf for alloc_q as this code.
allocq_free = (kni->alloc_q->read - kni->alloc_q->write - 1) \
		& (MAX_MBUF_BURST_NUM - 1);
The value of allocq_free maybe zero, for example :
The ring size is 1024. After init, write = read = 0. Then we fill
kni->alloc_q to full. At this time, write = 1023, read = 0.

Then the kernel send 32 packets to userspace. At this time, write
= 1023, read = 32. And then the userspace receive this 32 packets.
Then fill the kni->alloc_q, (32 - 1023 - 1) & 31 = 0, fill nothing.
...
Then the kernel send 32 packets to userspace. At this time, write
= 1023, read = 992. And then the userspace receive this 32 packets.
Then fill the kni->alloc_q, (992 - 1023 - 1) & 31 = 0, fill nothing.

Then the kernel send 32 packets to userspace. The kni->alloc_q only
has 31 mbufs and will drop one packet.

Absolutely, this is a special scene. Normally, it will fill some
mbufs everytime, but may not enough for the kernel to use.

In this patch, we always keep the kni->alloc_q to full for the kernel
to use.

Fixes: 49da4e82cf94 ("kni: allocate no more mbuf than empty slots in queue")
Cc: stable@dpdk.org

Signed-off-by: Cheng Liu <liucheng11@huawei.com>
Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
   add fixes tag and update commit log
---
 lib/kni/rte_kni.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Ferruh Yigit June 22, 2021, 12:27 p.m. UTC | #1
On 6/22/2021 11:57 AM, wangyunjian wrote:
> From: Yunjian Wang <wangyunjian@huawei.com>
> 
> In kni_allocate_mbufs(), we alloc mbuf for alloc_q as this code.
> allocq_free = (kni->alloc_q->read - kni->alloc_q->write - 1) \
> 		& (MAX_MBUF_BURST_NUM - 1);
> The value of allocq_free maybe zero, for example :
> The ring size is 1024. After init, write = read = 0. Then we fill
> kni->alloc_q to full. At this time, write = 1023, read = 0.
> 
> Then the kernel send 32 packets to userspace. At this time, write
> = 1023, read = 32. And then the userspace receive this 32 packets.
> Then fill the kni->alloc_q, (32 - 1023 - 1) & 31 = 0, fill nothing.
> ...
> Then the kernel send 32 packets to userspace. At this time, write
> = 1023, read = 992. And then the userspace receive this 32 packets.
> Then fill the kni->alloc_q, (992 - 1023 - 1) & 31 = 0, fill nothing.
> 
> Then the kernel send 32 packets to userspace. The kni->alloc_q only
> has 31 mbufs and will drop one packet.
> 
> Absolutely, this is a special scene. Normally, it will fill some
> mbufs everytime, but may not enough for the kernel to use.
> 
> In this patch, we always keep the kni->alloc_q to full for the kernel
> to use.
> 
> Fixes: 49da4e82cf94 ("kni: allocate no more mbuf than empty slots in queue")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Cheng Liu <liucheng11@huawei.com>
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>

Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>

What do you think to change patch title to something like:
kni: fix mbuf allocation for alloc FIFO
Yunjian Wang June 22, 2021, 12:32 p.m. UTC | #2
> -----Original Message-----
> From: Ferruh Yigit [mailto:ferruh.yigit@intel.com]
> Sent: Tuesday, June 22, 2021 8:28 PM
> To: wangyunjian <wangyunjian@huawei.com>; dev@dpdk.org
> Cc: thomas@monjalon.net; gowrishankar.m@linux.vnet.ibm.com;
> dingxiaoxiong <dingxiaoxiong@huawei.com>; stable@dpdk.org; liucheng (J)
> <liucheng11@huawei.com>
> Subject: Re: [PATCH v2] kni: fix wrong mbuf alloc count in kni_allocate_mbufs
> 
> On 6/22/2021 11:57 AM, wangyunjian wrote:
> > From: Yunjian Wang <wangyunjian@huawei.com>
> >
> > In kni_allocate_mbufs(), we alloc mbuf for alloc_q as this code.
> > allocq_free = (kni->alloc_q->read - kni->alloc_q->write - 1) \
> > 		& (MAX_MBUF_BURST_NUM - 1);
> > The value of allocq_free maybe zero, for example :
> > The ring size is 1024. After init, write = read = 0. Then we fill
> > kni->alloc_q to full. At this time, write = 1023, read = 0.
> >
> > Then the kernel send 32 packets to userspace. At this time, write =
> > 1023, read = 32. And then the userspace receive this 32 packets.
> > Then fill the kni->alloc_q, (32 - 1023 - 1) & 31 = 0, fill nothing.
> > ...
> > Then the kernel send 32 packets to userspace. At this time, write =
> > 1023, read = 992. And then the userspace receive this 32 packets.
> > Then fill the kni->alloc_q, (992 - 1023 - 1) & 31 = 0, fill nothing.
> >
> > Then the kernel send 32 packets to userspace. The kni->alloc_q only
> > has 31 mbufs and will drop one packet.
> >
> > Absolutely, this is a special scene. Normally, it will fill some mbufs
> > everytime, but may not enough for the kernel to use.
> >
> > In this patch, we always keep the kni->alloc_q to full for the kernel
> > to use.
> >
> > Fixes: 49da4e82cf94 ("kni: allocate no more mbuf than empty slots in
> > queue")
> > Cc: stable@dpdk.org
> >
> > Signed-off-by: Cheng Liu <liucheng11@huawei.com>
> > Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> 
> Acked-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> What do you think to change patch title to something like:
> kni: fix mbuf allocation for alloc FIFO

OK, I will change patch title later.

Thanks
diff mbox series

Patch

diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c
index 9dae6a8d7c..eb24b0d0ae 100644
--- a/lib/kni/rte_kni.c
+++ b/lib/kni/rte_kni.c
@@ -677,8 +677,9 @@  kni_allocate_mbufs(struct rte_kni *kni)
 		return;
 	}
 
-	allocq_free = (kni->alloc_q->read - kni->alloc_q->write - 1)
-			& (MAX_MBUF_BURST_NUM - 1);
+	allocq_free = kni_fifo_free_count(kni->alloc_q);
+	allocq_free = (allocq_free > MAX_MBUF_BURST_NUM) ?
+		MAX_MBUF_BURST_NUM : allocq_free;
 	for (i = 0; i < allocq_free; i++) {
 		pkts[i] = rte_pktmbuf_alloc(kni->pktmbuf_pool);
 		if (unlikely(pkts[i] == NULL)) {