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 2071745BF5; Sun, 27 Oct 2024 18:12:05 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 08B224065E; Sun, 27 Oct 2024 18:11:52 +0100 (CET) Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) by mails.dpdk.org (Postfix) with ESMTP id 54F5F4064C for ; Sun, 27 Oct 2024 18:11:48 +0100 (CET) Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-71e74900866so2642894b3a.1 for ; Sun, 27 Oct 2024 10:11:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1730049107; x=1730653907; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+mUGrys51rrrGRcEsltsl7C5BlGSp1s3k7WzJGhOVLE=; b=Erlx9tpywkDUDy84162iJHD1p6USfwyQvzXPdjFz2xvAxTbHSSoBWgUqQVy0ucykiN RxQG6lPRXFrVvMD4rRkfJqHYOe0WuhlwSPzv0D5eBXXWlvT/8ywwR9AYhh3CmEAIHoNZ pxt6HFaBTOFc+pEjKI9fQtkoSuHwKYDyDnYis= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730049107; x=1730653907; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+mUGrys51rrrGRcEsltsl7C5BlGSp1s3k7WzJGhOVLE=; b=H/w9g9ArgRSulUAsFzNUCEubOpd2UJJ1hOrnrC/7mYSbPw2iEIs0s/DajdfikbJ/W+ Bh9+oWyHHyxS/6OnNXtYahQ+VhPz1cjB+liHny203CK+TPmnB+5DaMHNDkAKxw1bC8M1 dW8FAn8hOtrJT4kWSWZv7flh8VqV3XR8o+aUa0dZI+4Ay7N4HV4urpglwbsEi3ZaAgQi 6pe55Y4kQW74AKt+Nn4W6ZsC32/FXnfrleHZdNpJSmB7+nsB0UQIm1nrpjeH1Ly+hrU0 /Bksn/S/GduBMexgrC88A58A5IpCwDI4iYkmpbtPTkbunHywD2HEOjDb+CkRaSGQOoVB km/g== X-Gm-Message-State: AOJu0YyODOsHoQqIFBK1PpRZvz35SuVOTVbkj86L0iR4UqNKL+ngcal0 9HveFDKvLlOLSyCb4PPTn3mh/nSYKfb6TBcPSu/z0QHTHD8s1Oo/gxk0vmpyPbguoAIKe608qcd 6/AL0lUjHUEN0DowLtHsOtkrrbmXtnEHOz2iMacEHMC9aqZGUg1Y543aJBmjmwPbbtixD8sz9hs 1yPErYPWkpLfgXkj5frE5EvGSWQmM57PA= X-Google-Smtp-Source: AGHT+IHVI/4fRmZbY20x4LiLqAMRwQ+I+4rHoL44HjJNMdWi6meUKiGKGVnk2PX0XW5vlbhbn9/Ecg== X-Received: by 2002:a05:6a00:3d0d:b0:71d:ee1b:c851 with SMTP id d2e1a72fcca58-72062f13bd9mr9713899b3a.7.1730049107043; Sun, 27 Oct 2024 10:11:47 -0700 (PDT) Received: from localhost.localdomain ([136.52.21.78]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057a21ccesm4269158b3a.167.2024.10.27.10.11.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 27 Oct 2024 10:11:45 -0700 (PDT) From: Ajit Khaparde To: dev@dpdk.org Cc: Somnath Kotur Subject: [PATCH v2 04/13] net/bnxt: add check for number of segs Date: Sun, 27 Oct 2024 10:11:19 -0700 Message-Id: <20241027171128.50221-5-ajit.khaparde@broadcom.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20241027171128.50221-1-ajit.khaparde@broadcom.com> References: <20241027171128.50221-1-ajit.khaparde@broadcom.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Somnath Kotur If the application passes incorrect number of segs for a Tx pkt i.e. sets it to 5 while actually sending down only a single mbuf, this could escape all the existing driver checks and driver could end up sending down garbage TX BDs to the HW. This in turn could lead to a Tx pipeline stall. Fix it by validating the number of segs passed for the Tx pkt against what is actually set by the application to prevent this. Signed-off-by: Somnath Kotur Reviewed-by: Ajit Khaparde --- drivers/net/bnxt/bnxt_txr.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/net/bnxt/bnxt_txr.c b/drivers/net/bnxt/bnxt_txr.c index 6d7e9962ce..51d3689e9c 100644 --- a/drivers/net/bnxt/bnxt_txr.c +++ b/drivers/net/bnxt/bnxt_txr.c @@ -194,6 +194,21 @@ bnxt_check_pkt_needs_ts(struct rte_mbuf *m) return false; } +static bool +bnxt_invalid_nb_segs(struct rte_mbuf *tx_pkt) +{ + uint16_t nb_segs = 1; + struct rte_mbuf *m_seg; + + m_seg = tx_pkt->next; + while (m_seg) { + nb_segs++; + m_seg = m_seg->next; + } + + return (nb_segs != tx_pkt->nb_segs); +} + static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt, struct bnxt_tx_queue *txq, uint16_t *coal_pkts, @@ -221,6 +236,9 @@ static uint16_t bnxt_start_xmit(struct rte_mbuf *tx_pkt, if (unlikely(is_bnxt_in_error(txq->bp))) return -EIO; + if (unlikely(bnxt_invalid_nb_segs(tx_pkt))) + return -EINVAL; + long_bd = bnxt_xmit_need_long_bd(tx_pkt, txq); nr_bds = long_bd + tx_pkt->nb_segs; -- 2.39.5 (Apple Git-154)