Skip to content

Commit 4856224

Browse files
authored
ufd: fix memleak detected by mt_asan_check (#906)
Fix below fail: MTL: 2024-06-15 00:45:30, mt_asan_check, leak of 1624 byte(s) at 0x7fc17ff3b900 MTL: 2024-06-15 00:45:30, mt_asan_check, backtrace info: MTL: 2024-06-15 00:45:30, mt_asan_check, /lib/x86_64-linux-gnu/libasan.so.5(+0x6cd40) [0x7fc9823fdd40] MTL: 2024-06-15 00:45:30, mt_asan_check, /usr/local/lib/x86_64-linux-gnu/libmtl.so(mt_rte_zmalloc_socket+0x18a) [0x7fc981d07c69] MTL: 2024-06-15 00:45:30, mt_asan_check, /usr/local/lib/x86_64-linux-gnu/libmtl.so(+0x6ecbfe) [0x7fc982200bfe] MTL: 2024-06-15 00:45:30, mt_asan_check, /usr/local/lib/x86_64-linux-gnu/libmtl.so(+0x6ed322) [0x7fc982201322] MTL: 2024-06-15 00:45:30, mt_asan_check, /usr/local/lib/x86_64-linux-gnu/libmtl.so(mufd_socket_port+0x132) [0x7fc982201b26] MTL: 2024-06-15 00:45:30, mt_asan_check, /usr/local/lib/x86_64-linux-gnu/libmtl.so(mufd_socket+0x55) [0x7fc982202d20] MTL: 2024-06-15 00:45:30, mt_asan_check, ./build/app/UfdServerSample(+0x81f0) [0x559cc2cc11f0] MTL: 2024-06-15 00:45:30, mt_asan_check, /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3) [0x7fc981923083] MTL: 2024-06-15 00:45:30, mt_asan_check, ./build/app/UfdServerSample(+0x588e) [0x559cc2cbe88e] Signed-off-by: Frank Du <[email protected]> (cherry picked from commit b087f1f)
1 parent 46cdf81 commit 4856224

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

lib/src/mt_cni.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ static void* cni_traffic_thread(void* arg) {
393393
info("%s, start\n", __func__);
394394
while (rte_atomic32_read(&cni->stop_thread) == 0) {
395395
cni_traffic(impl);
396-
mt_sleep_ms(1);
396+
mt_sleep_ms(cni->thread_sleep_ms);
397397
}
398398
info("%s, stop\n", __func__);
399399

@@ -563,6 +563,7 @@ int mt_cni_init(struct mtl_main_impl* impl) {
563563

564564
cni_impl->lcore_tasklet = (p->flags & MTL_FLAG_CNI_THREAD) ? false : true;
565565
rte_atomic32_set(&cni_impl->stop_thread, 0);
566+
cni_impl->thread_sleep_ms = 1;
566567

567568
for (int i = 0; i < num_ports; i++) {
568569
struct mt_cni_entry* cni = cni_get_entry(impl, i);
@@ -719,6 +720,9 @@ struct mt_csq_entry* mt_csq_get(struct mtl_main_impl* impl, enum mtl_port port,
719720
cni->csq_idx++;
720721
csq_unlock(cni);
721722

723+
/* csq enabled, disable the sleep */
724+
mt_get_cni(impl)->thread_sleep_ms = 0;
725+
722726
uint8_t* ip = flow->dip_addr;
723727
info("%s(%d), ip %u.%u.%u.%u port %u on %d\n", __func__, port, ip[0], ip[1], ip[2],
724728
ip[3], flow->dst_port, idx);

lib/src/mt_main.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ struct mt_cni_impl {
389389
rte_atomic32_t stop_thread;
390390
bool lcore_tasklet;
391391
struct mt_sch_tasklet_impl* tasklet;
392+
int thread_sleep_ms;
392393

393394
struct mt_cni_entry entries[MTL_PORT_MAX];
394395

lib/src/udp/udp_rxq.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ static struct mur_queue* urq_get(struct mudp_rxq_mgr* mgr,
231231
if (q) {
232232
if (!q->reuse_port || !create->reuse_port) {
233233
err("%s(%d,%u), already used\n", __func__, port, dst_port);
234+
q = NULL;
234235
goto out_unlock_fail;
235236
}
236237

@@ -257,6 +258,7 @@ static struct mur_queue* urq_get(struct mudp_rxq_mgr* mgr,
257258
q->rx_burst_pkts = 128;
258259
MT_TAILQ_INIT(&q->client_head);
259260
mt_pthread_mutex_init(&q->mutex, NULL);
261+
rte_atomic32_inc(&q->refcnt);
260262

261263
/* create flow */
262264
struct mt_rxq_flow flow;
@@ -265,28 +267,37 @@ static struct mur_queue* urq_get(struct mudp_rxq_mgr* mgr,
265267
flow.dst_port = dst_port;
266268
q->rxq = mt_rxq_get(impl, port, &flow);
267269
if (!q->rxq) {
268-
err("%s(%d,%u), get rxq fail\n", __func__, port, dst_port);
269-
urq_put(q);
270-
goto out_unlock_fail;
270+
/* wa for e810 pf mode since it doesn't support MT_RXQ_FLOW_F_NO_IP */
271+
warn("%s(%d,%u), get rxq fail with no ip flow, try cni queue\n", __func__, port,
272+
dst_port);
273+
flow.flags |= MT_RXQ_FLOW_F_FORCE_CNI;
274+
q->rxq = mt_rxq_get(impl, port, &flow);
275+
if (!q->rxq) {
276+
err("%s(%d,%u), get rxq fail with CNI also\n", __func__, port, dst_port);
277+
goto out_unlock_fail;
278+
}
279+
/* start mtl sch with CNI tasklet mode */
280+
if (!mt_started(impl)) {
281+
mtl_start(impl);
282+
}
271283
}
272284
q->rxq_id = mt_rxq_queue_id(q->rxq);
273285

274286
ret = urq_mgr_add(mgr, q);
275287
if (ret < 0) {
276288
err("%s(%d,%u), urq mgr add fail %d\n", __func__, port, dst_port, ret);
277-
urq_put(q);
278289
goto out_unlock_fail;
279290
}
280291

281292
*idx = 0;
282-
rte_atomic32_inc(&q->refcnt);
283293
urq_mgr_unlock(mgr);
284294

285295
info("%s(%d,%u), new q %p\n", __func__, port, dst_port, q);
286296
return q;
287297

288298
out_unlock_fail:
289299
urq_mgr_unlock(mgr);
300+
if (q) urq_put(q);
290301
return NULL;
291302
}
292303

lib/src/udp/ufd_main.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ static int ufd_free_slot(struct ufd_mt_ctx* ctx, struct ufd_slot* slot) {
5959
}
6060

6161
static int ufd_free_mt_ctx(struct ufd_mt_ctx* ctx) {
62+
struct mtl_main_impl* mt = ctx->mt;
63+
6264
if (ctx->slots) {
6365
for (int i = 0; i < ufd_max_slot(ctx); i++) {
6466
/* check if any not free slot */
@@ -69,15 +71,18 @@ static int ufd_free_mt_ctx(struct ufd_mt_ctx* ctx) {
6971
mt_rte_free(ctx->slots);
7072
ctx->slots = NULL;
7173
}
72-
if (ctx->mt) {
73-
mtl_uninit(ctx->mt);
74-
ctx->mt = NULL;
75-
}
7674
mt_pthread_mutex_destroy(&ctx->slots_lock);
7775
if (ctx->alloc_with_rte)
7876
mt_rte_free(ctx);
7977
else
8078
mt_free(ctx);
79+
80+
/* always mtl_uninit at the last */
81+
if (mt) {
82+
mtl_uninit(mt);
83+
mt = NULL;
84+
}
85+
8186
return 0;
8287
}
8388

0 commit comments

Comments
 (0)