From nobody Thu Oct 31 16:00:01 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 4XfTGT5vltz5bwcK; Thu, 31 Oct 2024 16:00:01 +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 4XfTGT2RYxz4Nm7; Thu, 31 Oct 2024 16:00:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730390401; 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=UGPP6ihVnZIecRZnWTqWXziWVXi98QQ2fqYySgRhzcA=; b=KLw22/7A6DietQ5O1g1jNZnM2Tb++cNmPGXmz/554kSlbA6SHYgXBnHoRbmVPfIGAnYO3W iKA2SyiV63PUcU2JteLjeAUbMXY5DZ+ewnyahvg5hI9SxPbXj64hmBo2gbf1BvG5PS9dk0 y68D11Zg4E8wDEKN+HG5nJEDgg1+HQTiZgUzlcBV+O06hx0e4aGHZo3FZX81frwCyxQ9vi 21R24fXIrRnYRhKmG+/ljuqFYZLTDtAe4RaFMixjClDrcVgnj/5OtDEnkpAt1/8zZgNxsW yTiAB2OsRBir48GXAxmSUSiHCS5KBdN3oqpKwEXnDk+U04Tk58wg4j7Tn9xNiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1730390401; 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=UGPP6ihVnZIecRZnWTqWXziWVXi98QQ2fqYySgRhzcA=; b=AiNcLyopLRfU2nhA6AhrJrhqWIZ/Lkf1ZFxhOXL9SbAxrk3rXY1GlQ5+JvcPBL4I9iAHYV Dakv+UI+SCcXIF73xcaAlxLsDzl/yrgqEg1YJNlc9opEmEOGi/z91qW3MDlPwsPAYogCMq gdcoLgjWQ350i4LMVNIhHhSIKv2Glxvpzqkezpagm2Ee4GyQ5fi+qaOcjATUz2xntiZDq6 s9XAV8W7Z4ixwDR/cxfqMpEE4ylX49XEF1CjiEOdqalJycJj4Ov3PuOmtYC5PRfR1/MOBJ +b8X2o/2pQbIWzGjIJE/iPIjJlhfMveUtTKHexZX+XlVOE6tQm+//OU+2gDEPg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1730390401; a=rsa-sha256; cv=none; b=iItayS2C8MjD9XjQQ5LMvvLEKuE1ywYbjSpxipE8QQ982mkCSX15lY2oZC7S07kKlRASUM BnY6qYObpRFzTZYib7GsOQsK94t4c/kRY96vd1aeAzW/jIbSYdh2nP1eJLIIqfz9p+dW0m MDIXe5GS5+p2G9Hults7DvV3MiXpkz1Cs+gQbUHOKT/v6hnbx0MnO6mNZeT2TEHidt3fzT cCNeXc3ut1t0D14Jf3N+YMLxCaTDV0G5mbPnNbk5sKPvwbavHKeMzmrGimJPuB92B6bRdl 6TL/6WrDc1ygQWQAUz0qQLSIswBl1miXl9lB1VZDQdB94iZuZwfXsLLJOs9uXQ== 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 4XfTGT1YZJzj5D; Thu, 31 Oct 2024 16:00:01 +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 49VG01e6058855; Thu, 31 Oct 2024 16:00:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49VG01HN058845; Thu, 31 Oct 2024 16:00:01 GMT (envelope-from git) Date: Thu, 31 Oct 2024 16:00:01 GMT Message-Id: <202410311600.49VG01HN058845@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: a5b6e4509b4f - stable/13 - 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/13 X-Git-Reftype: branch X-Git-Commit: a5b6e4509b4f21069e94227080ff423194bb5672 Auto-Submitted: auto-generated The branch stable/13 has been updated by osamaabb: URL: https://cgit.FreeBSD.org/src/commit/?id=a5b6e4509b4f21069e94227080ff423194bb5672 commit a5b6e4509b4f21069e94227080ff423194bb5672 Author: Osama Abboud AuthorDate: 2024-08-07 06:24:19 +0000 Commit: Osama Abboud CommitDate: 2024-10-31 14:55:19 +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 3f938fe8f619..32c93de821a3 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 2f3bc72d8760..e85d29d7f278 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 0d0b7b6a1cf2..fb2c5cb21e6d 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");