DPDK patches and discussions
 help / color / mirror / Atom feed
From: <shaibran@amazon.com>
To: <ferruh.yigit@amd.com>
Cc: <dev@dpdk.org>, Shai Brandes <shaibran@amazon.com>
Subject: [PATCH v4 12/31] net/ena/base: add completion descriptor corruption check
Date: Tue, 12 Mar 2024 20:06:57 +0200	[thread overview]
Message-ID: <20240312180716.8515-13-shaibran@amazon.com> (raw)
In-Reply-To: <20240312180716.8515-1-shaibran@amazon.com>

From: Shai Brandes <shaibran@amazon.com>

Adding a check of the MBZ (Must Be Zero) fields in the
incoming tx and rx completion descriptors in order to
identify corrupted descriptors.

Signed-off-by: Shai Brandes <shaibran@amazon.com>
Reviewed-by: Amit Bernstein <amitbern@amazon.com>
---
 drivers/net/ena/base/ena_eth_com.c | 13 +++++++++++--
 drivers/net/ena/base/ena_eth_com.h | 14 +++++++++++++-
 2 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ena/base/ena_eth_com.c b/drivers/net/ena/base/ena_eth_com.c
index 875d55b00d..58d1cc68d9 100644
--- a/drivers/net/ena/base/ena_eth_com.c
+++ b/drivers/net/ena/base/ena_eth_com.c
@@ -236,6 +236,7 @@ static int ena_com_cdesc_rx_pkt_get(struct ena_com_io_cq *io_cq,
 				    u16 *first_cdesc_idx,
 				    u16 *num_descs)
 {
+	struct ena_com_dev *dev = ena_com_io_cq_to_ena_dev(io_cq);
 	u16 count = io_cq->cur_rx_pkt_cdesc_count, head_masked;
 	struct ena_eth_io_rx_cdesc_base *cdesc;
 	u32 last = 0;
@@ -251,13 +252,21 @@ static int ena_com_cdesc_rx_pkt_get(struct ena_com_io_cq *io_cq,
 		ena_com_cq_inc_head(io_cq);
 		if (unlikely((status & ENA_ETH_IO_RX_CDESC_BASE_FIRST_MASK) >>
 		    ENA_ETH_IO_RX_CDESC_BASE_FIRST_SHIFT && count != 0)) {
-			struct ena_com_dev *dev = ena_com_io_cq_to_ena_dev(io_cq);
-
 			ena_trc_err(dev,
 				    "First bit is on in descriptor #%d on q_id: %d, req_id: %u\n",
 				    count, io_cq->qid, cdesc->req_id);
 			return ENA_COM_FAULT;
 		}
+
+		if (unlikely((status & (ENA_ETH_IO_RX_CDESC_BASE_MBZ7_MASK |
+					ENA_ETH_IO_RX_CDESC_BASE_MBZ17_MASK)) &&
+			      ena_com_get_cap(dev, ENA_ADMIN_CDESC_MBZ))) {
+			ena_trc_err(dev,
+				    "Corrupted RX descriptor #%d on q_id: %d, req_id: %u\n",
+				    count, io_cq->qid, cdesc->req_id);
+			return ENA_COM_FAULT;
+		}
+
 		count++;
 		last = (status & ENA_ETH_IO_RX_CDESC_BASE_LAST_MASK) >>
 			ENA_ETH_IO_RX_CDESC_BASE_LAST_SHIFT;
diff --git a/drivers/net/ena/base/ena_eth_com.h b/drivers/net/ena/base/ena_eth_com.h
index 6a7c17f84f..2fac10e678 100644
--- a/drivers/net/ena/base/ena_eth_com.h
+++ b/drivers/net/ena/base/ena_eth_com.h
@@ -204,9 +204,11 @@ static inline void ena_com_cq_inc_head(struct ena_com_io_cq *io_cq)
 static inline int ena_com_tx_comp_req_id_get(struct ena_com_io_cq *io_cq,
 					     u16 *req_id)
 {
+	struct ena_com_dev *dev = ena_com_io_cq_to_ena_dev(io_cq);
 	u8 expected_phase, cdesc_phase;
 	struct ena_eth_io_tx_cdesc *cdesc;
 	u16 masked_head;
+	u8 flags;
 
 	masked_head = io_cq->head & (io_cq->q_depth - 1);
 	expected_phase = io_cq->phase;
@@ -215,14 +217,24 @@ static inline int ena_com_tx_comp_req_id_get(struct ena_com_io_cq *io_cq,
 		((uintptr_t)io_cq->cdesc_addr.virt_addr +
 		(masked_head * io_cq->cdesc_entry_size_in_bytes));
 
+	flags = READ_ONCE8(cdesc->flags);
+
 	/* When the current completion descriptor phase isn't the same as the
 	 * expected, it mean that the device still didn't update
 	 * this completion.
 	 */
-	cdesc_phase = READ_ONCE8(cdesc->flags) & ENA_ETH_IO_TX_CDESC_PHASE_MASK;
+	cdesc_phase = flags & ENA_ETH_IO_TX_CDESC_PHASE_MASK;
 	if (cdesc_phase != expected_phase)
 		return ENA_COM_TRY_AGAIN;
 
+	if (unlikely((flags & ENA_ETH_IO_TX_CDESC_MBZ6_MASK) &&
+		      ena_com_get_cap(dev, ENA_ADMIN_CDESC_MBZ))) {
+		ena_trc_err(dev,
+			    "Corrupted TX descriptor on q_id: %d, req_id: %u\n",
+			    io_cq->qid, cdesc->req_id);
+		return ENA_COM_FAULT;
+	}
+
 	dma_rmb();
 
 	*req_id = READ_ONCE16(cdesc->req_id);
-- 
2.17.1


  parent reply	other threads:[~2024-03-12 18:08 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-12 18:06 [PATCH v4 00/31] net/ena: v2.9.0 driver release shaibran
2024-03-12 18:06 ` [PATCH v4 01/31] net/ena: rework the metrics multi-process functions shaibran
2024-03-12 18:06 ` [PATCH v4 02/31] net/ena: report new supported link speed capabilities shaibran
2024-03-12 18:06 ` [PATCH v4 03/31] net/ena: update imissed stat with Rx overruns shaibran
2024-03-13 15:59   ` Ferruh Yigit
2024-03-12 18:06 ` [PATCH v4 04/31] net/ena: sub-optimal configuration notifications support shaibran
2024-03-12 18:06 ` [PATCH v4 05/31] net/ena: fix fast mbuf free shaibran
2024-03-13 15:58   ` Ferruh Yigit
2024-03-12 18:06 ` [PATCH v4 06/31] net/ena: restructure the llq policy setting process shaibran
2024-03-12 18:06 ` [PATCH v4 07/31] net/ena/base: limit exponential backoff exp shaibran
2024-03-13 15:58   ` Ferruh Yigit
2024-03-12 18:06 ` [PATCH v4 08/31] net/ena/base: add a new csum offload bit shaibran
2024-03-13 15:58   ` Ferruh Yigit
2024-03-12 18:06 ` [PATCH v4 09/31] net/ena/base: optimize Rx ring submission queue shaibran
2024-03-12 18:06 ` [PATCH v4 10/31] net/ena/base: rename fields in completion descriptors shaibran
2024-03-12 18:06 ` [PATCH v4 11/31] net/ena/base: use correct read once on u8 field shaibran
2024-03-12 18:06 ` shaibran [this message]
2024-03-12 18:06 ` [PATCH v4 13/31] net/ena/base: malformed Tx descriptor error reason shaibran
2024-03-13 15:58   ` Ferruh Yigit
2024-03-12 18:06 ` [PATCH v4 14/31] net/ena/base: phc feature modifications shaibran
2024-03-12 18:07 ` [PATCH v4 15/31] net/ena/base: restructure interrupt handling shaibran
2024-03-13 15:58   ` Ferruh Yigit
2024-03-12 18:07 ` [PATCH v4 16/31] net/ena/base: add unlikely to error checks shaibran
2024-03-12 18:07 ` [PATCH v4 17/31] net/ena/base: missing admin interrupt reset reason shaibran
2024-03-12 18:07 ` [PATCH v4 18/31] net/ena/base: check for existing keep alive notification shaibran
2024-03-12 18:07 ` [PATCH v4 19/31] net/ena/base: modify memory barrier comment shaibran
2024-03-12 18:07 ` [PATCH v4 20/31] net/ena/base: rework Rx ring submission queue shaibran
2024-03-12 18:07 ` [PATCH v4 21/31] net/ena/base: remove operating system type enum shaibran
2024-03-12 18:07 ` [PATCH v4 22/31] net/ena/base: handle command abort shaibran
2024-03-12 18:07 ` [PATCH v4 23/31] net/ena/base: add support for device reset request shaibran
2024-03-12 18:07 ` [PATCH v4 24/31] net/ena: cosmetic changes shaibran
2024-03-13 15:58   ` Ferruh Yigit
2024-03-12 18:07 ` [PATCH v4 25/31] net/ena/base: modify customer metrics memory management shaibran
2024-03-12 18:07 ` [PATCH v4 26/31] net/ena/base: modify logs to use unsigned format specifier shaibran
2024-03-12 18:07 ` [PATCH v4 27/31] net/ena: update device-preferred size of rings shaibran
2024-03-12 18:07 ` [PATCH v4 28/31] net/ena: exhaust interrupt callbacks in device close shaibran
2024-03-12 18:07 ` [PATCH v4 29/31] net/ena: support max large llq depth from the device shaibran
2024-03-12 18:07 ` [PATCH v4 30/31] net/ena: control path pure polling mode shaibran
2024-03-12 18:07 ` [PATCH v4 31/31] net/ena: upgrade driver version to 2.9.0 shaibran
2024-03-13 16:00 ` [PATCH v4 00/31] net/ena: v2.9.0 driver release Ferruh Yigit
2024-03-13 17:07   ` Brandes, Shai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240312180716.8515-13-shaibran@amazon.com \
    --to=shaibran@amazon.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@amd.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).