From nobody Thu Oct 31 16:01:26 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XfTJ72Cvdz5bwgq; Thu, 31 Oct 2024 16:01:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XfTJ673dWz4Swk; Thu, 31 Oct 2024 16:01:26 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730390487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=itL/qKcmfzSAn9ktw6G5C0hCW9/q2kCNHZACUZ+C5v8=; b=QGVB8JATPvPu4Y45t4LEoSA7fElzl5cu9Ngcfv4JPPSPJam68vRhG4kioc481wbVY/61qj 9fwNmkjJXpQtK/TNHPrGAsNiL8tP47Gp9lzCEEKClg844mx1zeMLlOYKHWL0WNeOoO3uon raxct+1jwEvUHPdZsT2K+YQxuNNUxK0p6FD4gBy39bFES2aEp5gb59Ck5+sUiJTODOlfY5 ag5bevRqDZSbvoKt/M86oaVlzavo0Os/9w8YHe2gdZZDJxRsdZCaqONQQGqC/v/QZuHEN9 OjkyewkOGfUOXA1tdkkLbNXC1Hihj800CU+75vydqa9A7alLAPdWQ7RlQve5Sw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730390487; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=itL/qKcmfzSAn9ktw6G5C0hCW9/q2kCNHZACUZ+C5v8=; b=f9bTrvWSlLKCDB5VfqtOWq683VggOykYy5d3bAh0lLjS5rVj4iKv9nCz//aS8GRxHdFv53 GeBF+ziXCUBwe0yefcJAgLPQDNQrM044NOwoWTzxix3W9ibUUcVqESKVWyOgZNvgCZNkgh c7P6YXo7Z9CHgXH98KloGBFtQB1eNXSbpwHRQ+DutJUKrMZC/uZhTZd0oIj7jRFM0SEPAK pOchEIxwME7z3+QS78eb4r4nqjV1mzcX9zplAZMDcZFq60qKifIEMx5HGpC8O68e0Qhq3q saz+sLY+b4RxmgW1Hit/dSK7VObCrV8U/lZaxFUq9u9pbCpAT4v/z/ZQOni6Zg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730390487; a=rsa-sha256; cv=none; b=xGgYQ/ogbwHeWAJ499q9cwLyywSaa/rLhaquomy52iHHl10/qixn69MBGLjMhevHzlCyrZ bFp2odLLcV3L/Txkq6RCWikgXmcfTNzIs0+p93kbthzmiSUl+87IKRJVB5vw+hfbIJies3 WBuM6xSLn4pZ7vb3axU7on5a3+Z6bv+iZ2U2fg2xnBeC4PGNkkKDQr3adaIE8ctswkvbMK f8LU69Qd/jDR7cqKfj/FLTLa9fRlReuMiQDzB1P9TQJQaXrkwdY69vHFSGYiBCfubOEpNK GfxcEXBpUrA2SwSOwHW8qu1/JbYhhOAERkdd3HWTmnYnhGZ5AgsZSkbYIoqnVg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XfTJ66YVwzjXJ; Thu, 31 Oct 2024 16:01:26 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49VG1Q8A070106; Thu, 31 Oct 2024 16:01:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49VG1QoR070103; Thu, 31 Oct 2024 16:01:26 GMT (envelope-from git) Date: Thu, 31 Oct 2024 16:01:26 GMT Message-Id: <202410311601.49VG1QoR070103@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Osama Abboud Subject: git: 189bc23fd0e4 - stable/14 - ena: Add reset reason for corrupted TX cdescs List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: osamaabb X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 189bc23fd0e4ddc0485dd52b2925728d321ab8ec Auto-Submitted: auto-generated The branch stable/14 has been updated by osamaabb: URL: https://cgit.FreeBSD.org/src/commit/?id=189bc23fd0e4ddc0485dd52b2925728d321ab8ec commit 189bc23fd0e4ddc0485dd52b2925728d321ab8ec Author: Osama Abboud AuthorDate: 2024-08-07 06:24:19 +0000 Commit: Osama Abboud CommitDate: 2024-10-31 14:54:10 +0000 ena: Add reset reason for corrupted TX cdescs TX completion descriptors may sometimes contain errors due to corruption. Upon identifying such a case, the driver will trigger a reset with an explicit reset reason ENA_REGS_RESET_TX_DESCRIPTOR_MALFORMED. Approved by: cperciva (mentor) Sponsored by: Amazon, Inc. (cherry picked from commit 38727218460008a500fbc18f08c90082ed678895) --- sys/dev/ena/ena.c | 26 ++++++++++++++++++++++++++ sys/dev/ena/ena.h | 3 +++ sys/dev/ena/ena_datapath.c | 27 ++++++++++----------------- sys/dev/ena/ena_netmap.c | 38 ++++++++++++++------------------------ sys/dev/ena/ena_sysctl.c | 2 ++ 5 files changed, 55 insertions(+), 41 deletions(-) diff --git a/sys/dev/ena/ena.c b/sys/dev/ena/ena.c index 7c86c0594daf..3f3a4946ccca 100644 --- a/sys/dev/ena/ena.c +++ b/sys/dev/ena/ena.c @@ -560,6 +560,32 @@ ena_free_rx_dma_tag(struct ena_adapter *adapter) return (ret); } +int +validate_tx_req_id(struct ena_ring *tx_ring, uint16_t req_id, int tx_req_id_rc) +{ + struct ena_adapter *adapter = tx_ring->adapter; + enum ena_regs_reset_reason_types reset_reason = ENA_REGS_RESET_INV_TX_REQ_ID; + + if (unlikely(tx_req_id_rc != 0)) { + if (tx_req_id_rc == ENA_COM_FAULT) { + reset_reason = ENA_REGS_RESET_TX_DESCRIPTOR_MALFORMED; + ena_log(adapter->pdev, ERR, + "TX descriptor malformed. req_id %hu qid %hu\n", + req_id, tx_ring->qid); + } else if (tx_req_id_rc == ENA_COM_INVAL) { + ena_log_nm(adapter->pdev, WARN, + "Invalid req_id %hu in qid %hu\n", + req_id, tx_ring->qid); + counter_u64_add(tx_ring->tx_stats.bad_req_id, 1); + } + + ena_trigger_reset(adapter, reset_reason); + return (EFAULT); + } + + return (0); +} + static void ena_release_all_tx_dmamap(struct ena_ring *tx_ring) { diff --git a/sys/dev/ena/ena.h b/sys/dev/ena/ena.h index 4ac79edd0016..22c42a9346f7 100644 --- a/sys/dev/ena/ena.h +++ b/sys/dev/ena/ena.h @@ -389,6 +389,7 @@ struct ena_stats_dev { counter_u64_t bad_rx_desc_num; counter_u64_t invalid_state; counter_u64_t missing_intr; + counter_u64_t tx_desc_malformed; }; struct ena_hw_stats { @@ -548,6 +549,7 @@ static const struct ena_reset_stats_offset resets_to_stats_offset_map[ENA_REGS_R ENA_RESET_STATS_ENTRY(ENA_REGS_RESET_TOO_MANY_RX_DESCS, bad_rx_desc_num), ENA_RESET_STATS_ENTRY(ENA_REGS_RESET_DRIVER_INVALID_STATE, invalid_state), ENA_RESET_STATS_ENTRY(ENA_REGS_RESET_MISS_INTERRUPT, missing_intr), + ENA_RESET_STATS_ENTRY(ENA_REGS_RESET_TX_DESCRIPTOR_MALFORMED, tx_desc_malformed), }; int ena_up(struct ena_adapter *adapter); @@ -562,6 +564,7 @@ int ena_update_queue_size(struct ena_adapter *adapter, uint32_t new_tx_size, int ena_update_io_queue_nb(struct ena_adapter *adapter, uint32_t new_num); int ena_update_base_cpu(struct ena_adapter *adapter, int new_num); int ena_update_cpu_stride(struct ena_adapter *adapter, uint32_t new_num); +int validate_tx_req_id(struct ena_ring *tx_ring, uint16_t req_id, int tx_req_id_rc); static inline int ena_mbuf_count(struct mbuf *mbuf) { diff --git a/sys/dev/ena/ena_datapath.c b/sys/dev/ena/ena_datapath.c index 0691444f5357..c63a8914f9c2 100644 --- a/sys/dev/ena/ena_datapath.c +++ b/sys/dev/ena/ena_datapath.c @@ -200,29 +200,22 @@ 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; - int rc; + int rc = ena_com_tx_comp_req_id_get(io_cq, req_id); - rc = ena_com_tx_comp_req_id_get(io_cq, req_id); - if (rc == ENA_COM_TRY_AGAIN) + if (unlikely(rc == ENA_COM_TRY_AGAIN)) return (EAGAIN); - if (unlikely(rc != 0)) { - ena_log(adapter->pdev, ERR, "Invalid req_id %hu in qid %hu\n", + rc = validate_tx_req_id(tx_ring, *req_id, rc); + + if (unlikely(tx_ring->tx_buffer_info[*req_id].mbuf == NULL)) { + ena_log(adapter->pdev, ERR, + "tx_info doesn't have valid mbuf. req_id %hu qid %hu\n", *req_id, tx_ring->qid); - counter_u64_add(tx_ring->tx_stats.bad_req_id, 1); - goto err; + ena_trigger_reset(adapter, ENA_REGS_RESET_INV_TX_REQ_ID); + rc = EFAULT; } - if (tx_ring->tx_buffer_info[*req_id].mbuf != NULL) - return (0); - - ena_log(adapter->pdev, ERR, - "tx_info doesn't have valid mbuf. req_id %hu qid %hu\n", - *req_id, tx_ring->qid); -err: - ena_trigger_reset(adapter, ENA_REGS_RESET_INV_TX_REQ_ID); - - return (EFAULT); + return (rc); } /** diff --git a/sys/dev/ena/ena_netmap.c b/sys/dev/ena/ena_netmap.c index ae2140d1217c..618d25a07f67 100644 --- a/sys/dev/ena/ena_netmap.c +++ b/sys/dev/ena/ena_netmap.c @@ -71,7 +71,6 @@ static void ena_netmap_unmap_last_socket_chain(struct ena_netmap_ctx *, struct ena_tx_buffer *); static void ena_netmap_tx_cleanup(struct ena_netmap_ctx *); static uint16_t ena_netmap_tx_clean_one(struct ena_netmap_ctx *, uint16_t); -static inline int validate_tx_req_id(struct ena_ring *, uint16_t); static int ena_netmap_rx_frames(struct ena_netmap_ctx *); static int ena_netmap_rx_frame(struct ena_netmap_ctx *); static int ena_netmap_rx_load_desc(struct ena_netmap_ctx *, uint16_t, int *); @@ -795,25 +794,33 @@ ena_netmap_unmap_last_socket_chain(struct ena_netmap_ctx *ctx, static void ena_netmap_tx_cleanup(struct ena_netmap_ctx *ctx) { + struct ena_ring *tx_ring = ctx->ring; + int rc; uint16_t req_id; uint16_t total_tx_descs = 0; ctx->nm_i = ctx->kring->nr_hwtail; - ctx->nt = ctx->ring->next_to_clean; + ctx->nt = tx_ring->next_to_clean; /* Reclaim buffers for completed transmissions */ - while (ena_com_tx_comp_req_id_get(ctx->io_cq, &req_id) >= 0) { - if (validate_tx_req_id(ctx->ring, req_id) != 0) + do { + rc = ena_com_tx_comp_req_id_get(ctx->io_cq, &req_id); + if(unlikely(rc == ENA_COM_TRY_AGAIN)) break; + + rc = validate_tx_req_id(tx_ring, req_id, rc); + if(unlikely(rc != 0)) + break; + total_tx_descs += ena_netmap_tx_clean_one(ctx, req_id); - } + } while (1); ctx->kring->nr_hwtail = ctx->nm_i; if (total_tx_descs > 0) { /* acknowledge completion of sent packets */ - ctx->ring->next_to_clean = ctx->nt; - ena_com_comp_ack(ctx->ring->ena_com_io_sq, total_tx_descs); + tx_ring->next_to_clean = ctx->nt; + ena_com_comp_ack(tx_ring->ena_com_io_sq, total_tx_descs); } } @@ -856,23 +863,6 @@ ena_netmap_tx_clean_one(struct ena_netmap_ctx *ctx, uint16_t req_id) return tx_info->tx_descs; } -static inline int -validate_tx_req_id(struct ena_ring *tx_ring, uint16_t req_id) -{ - struct ena_adapter *adapter = tx_ring->adapter; - - if (likely(req_id < tx_ring->ring_size)) - return (0); - - ena_log_nm(adapter->pdev, WARN, "Invalid req_id %hu in qid %hu\n", - req_id, tx_ring->qid); - counter_u64_add(tx_ring->tx_stats.bad_req_id, 1); - - ena_trigger_reset(adapter, ENA_REGS_RESET_INV_TX_REQ_ID); - - return (EFAULT); -} - static int ena_netmap_rxsync(struct netmap_kring *kring, int flags) { diff --git a/sys/dev/ena/ena_sysctl.c b/sys/dev/ena/ena_sysctl.c index 6eafe2a8c052..71c25dd5e443 100644 --- a/sys/dev/ena/ena_sysctl.c +++ b/sys/dev/ena/ena_sysctl.c @@ -294,6 +294,8 @@ ena_sysctl_add_stats(struct ena_adapter *adapter) &dev_stats->invalid_state, "Driver invalid state count"); SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "missing_intr", CTLFLAG_RD, &dev_stats->missing_intr, "Missing interrupt count"); + SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "tx_desc_malformed", CTLFLAG_RD, + &dev_stats->tx_desc_malformed, "TX descriptors malformed count"); SYSCTL_ADD_COUNTER_U64(ctx, child, OID_AUTO, "total_resets", CTLFLAG_RD, &dev_stats->total_resets, "Total resets count");