From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 478ABA00C2 for ; Wed, 9 Nov 2022 06:14:03 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3E81D410D7; Wed, 9 Nov 2022 06:14:03 +0100 (CET) Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mails.dpdk.org (Postfix) with ESMTP id A8127400D4; Wed, 9 Nov 2022 06:14:01 +0100 (CET) Received: by mail-pf1-f180.google.com with SMTP id y203so15706163pfb.4; Tue, 08 Nov 2022 21:14:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=O9jjNoH5fGImg8HXL85b3U8Yhg0h5jeeNv2ruremMjw=; b=QqPDmLeSS1aHTACTAfyCCHEjsQuTNaV3NYrgfHHX2yOCDILenq/4vQs0b8VYprxd3W 4XzddzQPMghXsigGbh2mKTqHDJWtXp8mO08A0G9a1ntm87G1skhOjBs+cQ+O6/8t9/HM GEN1T8NjvqO2CJjuM2gspaL5Du+yeJdjgp2Om8tKAj4npficZcF4yVUdab3n+59djsva AkUgsETuLBQ/exRItdmbUOuCgy1FDh/n6pna0eXuq1gnb/MPoc2heXEHHA3R/Ft11jH9 PeUnnpyVcNSJo8kuIBvH/2y/+SScQciE5jrhuFyPRO0+T1Zqr1NmJpGoeJB5hzHqrqj3 Oe+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=O9jjNoH5fGImg8HXL85b3U8Yhg0h5jeeNv2ruremMjw=; b=pekpxvq3qdgmxOK5w3lezliJUn0oFb1dw6ckKidM54nbHR7YOdeB+Is4rxskbpxRnM p90tpdT2L6ii5Dllwikn2nuHpLxM8md0XGNvTGcp/+B8pXaDiU918rRqsuffgGOlmCzw olW+pSYCFmdywBbsz/8+9UqHS3hb9PbByxgtkrpK68h7ALEOS0o5Wtl+/5xxMaSVDsPs Wle0AX836OoNieBY3z2Yt4XJH4e5E/TB9TmJM+ac+oTV91eKKRREI8HBp7x9sGo2GWiU Li1H2V6kmsuH0sqc61ikCVXV+7Pdti6CkY7uShD8OxuOW1YBvBkR6qWhCFIFj+mpdR3W Lhig== X-Gm-Message-State: ACrzQf3V5nweFmT3qEZqc2gKZUWFhq0Q0mw4wN/hgBe7djQMew3P0FE9 kRQ1YFJQVE1DPJuYXzcgyP0cFyJhhmHXZA== X-Google-Smtp-Source: AMsMyM70IlA8iG+i3g3zx8pZc3vALC8WqJMp06IA3FOOpPGvf802nVt3euhlGkIrH0fBlBJSQuTA6w== X-Received: by 2002:aa7:8293:0:b0:563:5852:e750 with SMTP id s19-20020aa78293000000b005635852e750mr59568319pfm.11.1667970840507; Tue, 08 Nov 2022 21:14:00 -0800 (PST) Received: from localhost.localdomain ([143.92.127.224]) by smtp.gmail.com with ESMTPSA id b123-20020a636781000000b0046ff6b380f8sm6553773pgc.68.2022.11.08.21.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Nov 2022 21:14:00 -0800 (PST) From: Yangchao Zhou To: dev@dpdk.org Cc: Hemant@freescale.com, stable@dpdk.org Subject: [PATCH] kni: fix possible alloc_q starvation when mbufs are exhausted Date: Wed, 9 Nov 2022 13:13:39 +0800 Message-Id: <20221109051339.1998037-1-zhouyates@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: stable-bounces@dpdk.org In some scenarios, mbufs returned by rte_kni_rx_burst are not freed immediately. So kni_allocate_mbufs may be failed, but we don't know. Even worse, when alloc_q is completely exhausted, kni_net_tx in rte_kni.ko will drop all tx packets. kni_allocate_mbufs is never called again, even if the mbufs are eventually freed. In this patch, we always try to allocate mbufs for alloc_q. Don't worry about alloc_q being allocated too many mbufs, in fact, the old logic will gradually fill up alloc_q. Also, the cost of more calls to kni_allocate_mbufs should be acceptable. Fixes: 3e12a98fe397 ("kni: optimize Rx burst") Cc: Hemant@freescale.com Cc: stable@dpdk.org Signed-off-by: Yangchao Zhou --- lib/kni/rte_kni.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c index 8ab6c47153..265c5262f7 100644 --- a/lib/kni/rte_kni.c +++ b/lib/kni/rte_kni.c @@ -634,9 +634,9 @@ rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs, unsigned int num) { unsigned int ret = kni_fifo_get(kni->tx_q, (void **)mbufs, num); - /* If buffers removed, allocate mbufs and then put them into alloc_q */ - if (ret) - kni_allocate_mbufs(kni); + /* Always try to allocate mbufs for alloc_q to avoid starvation when + * kni->pktmbuf_pool is exhausted. */ + kni_allocate_mbufs(kni); return ret; } -- 2.25.1