Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Feb 2022 13:04:26 GMT
From:      Marcin Wojtas <mw@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: ecafc181ed0a - stable/12 - ena: rework tx req_id validation logic
Message-ID:  <202202241304.21OD4Q8R044146@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch stable/12 has been updated by mw:

URL: https://cgit.FreeBSD.org/src/commit/?id=ecafc181ed0ada77844e2c8b090f964e6e6540df

commit ecafc181ed0ada77844e2c8b090f964e6e6540df
Author:     Artur Rojek <ar@semihalf.com>
AuthorDate: 2022-01-03 13:50:06 +0000
Commit:     Marcin Wojtas <mw@FreeBSD.org>
CommitDate: 2022-02-24 13:04:04 +0000

    ena: rework tx req_id validation logic
    
    Since `ena_com_tx_comp_req_id_get` already checks for `req_id` validity,
    the logic was exiting early, never giving `validate_tx_req_id` a chance
    to trigger device reset.
    Rewrite the logic so that device reset is called based on return value
    of `ena_com_tx_comp_req_id_get` instead.
    
    Submitted by: Artur Rojek <ar@semihalf.com>
    Obtained from: Semihalf
    MFC after: 2 weeks
    Sponsored by: Amazon, Inc.
    
    (cherry picked from commit b168d0c850f34e8178d815ba3a87de2657a02ca9)
---
 sys/dev/ena/ena_datapath.c | 35 ++++++++++++++++++-----------------
 1 file changed, 18 insertions(+), 17 deletions(-)

diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c
index 023a0d54693e..bf305944ab22 100644
--- a/sys/dev/ena/ena_datapath.c
+++ b/sys/dev/ena/ena_datapath.c
@@ -49,7 +49,8 @@ __FBSDID("$FreeBSD$");
 
 static int	ena_tx_cleanup(struct ena_ring *);
 static int	ena_rx_cleanup(struct ena_ring *);
-static inline int validate_tx_req_id(struct ena_ring *, uint16_t);
+static inline int ena_get_tx_req_id(struct ena_ring *tx_ring,
+    struct ena_com_io_cq *io_cq, uint16_t *req_id);
 static void	ena_rx_hash_mbuf(struct ena_ring *, struct ena_com_rx_ctx *,
     struct mbuf *);
 static struct mbuf* ena_rx_mbuf(struct ena_ring *, struct ena_com_rx_buf_info *,
@@ -201,23 +202,27 @@ ena_qflush(if_t ifp)
  *********************************************************************/
 
 static inline int
-validate_tx_req_id(struct ena_ring *tx_ring, uint16_t req_id)
+ena_get_tx_req_id(struct ena_ring *tx_ring, struct ena_com_io_cq *io_cq,
+    uint16_t *req_id)
 {
 	struct ena_adapter *adapter = tx_ring->adapter;
-	struct ena_tx_buffer *tx_info = NULL;
+	int rc;
 
-	if (likely(req_id < tx_ring->ring_size)) {
-		tx_info = &tx_ring->tx_buffer_info[req_id];
-		if (tx_info->mbuf != NULL)
-			return (0);
-		ena_log(adapter->pdev, ERR,
-		    "tx_info doesn't have valid mbuf\n");
+	rc = ena_com_tx_comp_req_id_get(io_cq, req_id);
+	if (rc == ENA_COM_TRY_AGAIN)
+		return (EAGAIN);
+
+	if (unlikely(rc != 0)) {
+		ena_log(adapter->pdev, ERR, "Invalid req_id: %hu\n", *req_id);
+		counter_u64_add(tx_ring->tx_stats.bad_req_id, 1);
+		goto err;
 	}
 
-	ena_log(adapter->pdev, ERR, "Invalid req_id: %hu\n", req_id);
-	counter_u64_add(tx_ring->tx_stats.bad_req_id, 1);
+	if (tx_ring->tx_buffer_info[*req_id].mbuf != NULL)
+		return (0);
 
-	/* Trigger device reset */
+	ena_log(adapter->pdev, ERR, "tx_info doesn't have valid mbuf\n");
+err:
 	ena_trigger_reset(adapter, ENA_REGS_RESET_INV_TX_REQ_ID);
 
 	return (EFAULT);
@@ -263,11 +268,7 @@ ena_tx_cleanup(struct ena_ring *tx_ring)
 		struct ena_tx_buffer *tx_info;
 		struct mbuf *mbuf;
 
-		rc = ena_com_tx_comp_req_id_get(io_cq, &req_id);
-		if (unlikely(rc != 0))
-			break;
-
-		rc = validate_tx_req_id(tx_ring, req_id);
+		rc = ena_get_tx_req_id(tx_ring, io_cq, &req_id);
 		if (unlikely(rc != 0))
 			break;
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202202241304.21OD4Q8R044146>