From nobody Thu Jan 13 06:10:02 2022 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 243A81944842; Thu, 13 Jan 2022 06:10:03 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4JZDYQ62Rjz3hFM; Thu, 13 Jan 2022 06:10:02 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 ABFF11B519; Thu, 13 Jan 2022 06:10:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20D6A2wB003691; Thu, 13 Jan 2022 06:10:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20D6A2lK003688; Thu, 13 Jan 2022 06:10:02 GMT (envelope-from git) Date: Thu, 13 Jan 2022 06:10:02 GMT Message-Id: <202201130610.20D6A2lK003688@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Wei Hu Subject: git: 623918a198f9 - main - mana: Improve the HWC error handling 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: whu X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 623918a198f9231621d60c9294ac1db469fe1565 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642054202; 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=NJVX3vJ/XvlEDh4tpRrmLSDTJbza89qeAI+6mF0dv0w=; b=WPVFi7G6kev5z+cHELLR/haIX5Qd5C32VLKpURUC2VaSibOwF3jHkw3QCPp2ueavFABV7Z HLEp9jVrpjkHzLvTdzGjxc5aQ/FFrOUEDrHGYikD3lDs57gok2PsOqnPr6xLIZ8R2Z1VBB bYiAypnDm9EwN2hA4VwmJOI+2vXzNRFyHbECwY89tvmyW+mjM3etQJvQqEoLWy/xOu0Xzd hZHGkdgI/PpURaYCY4Azf7kiHrIz4I+ZLwamp61Jj3vW3Hf0BbChhz48gUUOmXZG7KN4vv PEiw6ndYMjTWTcBXtTKVUjM0ATkyUJTl/Z/jYUAwc/9twaB0hISXASLcllUG8A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642054202; a=rsa-sha256; cv=none; b=n83jPLc9ej7hBl+ZA0dtcMyZuNjdMXxg/uM/sCzt1uxdr1DieCak5R1MuFd7qj9D+3NG+0 s+1C0zKpILalMPlRdIIUENSpNpI+JJAKPh7dz3AsqrKSog7ZdvrkdutgFgnHOe43NPSGju nGA1I1wytm3oqhlN7fSVhp2Rb1oct/kIPihkskzPshR4ckDnbCe2QkvggU6GavsGsbr6bt UBGOnO93t6TnjiXvKcFiBUzAYwSCyA/MwrwBsxf3sU2lkSsbhvC9l3kTrDcjCOsr1riLZP goTam45DRALGHv1Wdl+E9EG6x/LptT4dnVr286WpylsP+eooEjnyfX+rQUPDiA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by whu: URL: https://cgit.FreeBSD.org/src/commit/?id=623918a198f9231621d60c9294ac1db469fe1565 commit 623918a198f9231621d60c9294ac1db469fe1565 Author: Wei Hu AuthorDate: 2022-01-12 14:33:54 +0000 Commit: Wei Hu CommitDate: 2022-01-13 06:08:43 +0000 mana: Improve the HWC error handling Currently when the HWC creation fails, the error handling is flawed, e.g. if mana_hwc_create_channel() -> mana_hwc_establish_channel() fails, the resources acquired in mana_hwc_init_queues() is not released. Enhance mana_hwc_destroy_channel() to do the proper cleanup work and call it accordingly. MFC after: 2 weeks Sponsored by: Microsoft --- sys/dev/mana/gdma_main.c | 5 ---- sys/dev/mana/hw_channel.c | 73 +++++++++++++++++++++-------------------------- 2 files changed, 33 insertions(+), 45 deletions(-) diff --git a/sys/dev/mana/gdma_main.c b/sys/dev/mana/gdma_main.c index 49af54f4be5d..b879695825b1 100644 --- a/sys/dev/mana/gdma_main.c +++ b/sys/dev/mana/gdma_main.c @@ -1808,9 +1808,6 @@ mana_gd_attach(device_t dev) err_clean_up_gdma: mana_hwc_destroy_channel(gc); - if (gc->cq_table) - free(gc->cq_table, M_DEVBUF); - gc->cq_table = NULL; err_remove_irq: mana_gd_remove_irqs(dev); err_free_pci_res: @@ -1836,8 +1833,6 @@ mana_gd_detach(device_t dev) mana_remove(&gc->mana); mana_hwc_destroy_channel(gc); - free(gc->cq_table, M_DEVBUF); - gc->cq_table = NULL; mana_gd_remove_irqs(dev); diff --git a/sys/dev/mana/hw_channel.c b/sys/dev/mana/hw_channel.c index c24e62970f69..16b644d6c6b7 100644 --- a/sys/dev/mana/hw_channel.c +++ b/sys/dev/mana/hw_channel.c @@ -383,9 +383,6 @@ mana_hwc_comp_event(void *ctx, struct gdma_queue *q_self) static void mana_hwc_destroy_cq(struct gdma_context *gc, struct hwc_cq *hwc_cq) { - if (!hwc_cq) - return; - if (hwc_cq->comp_buf) free(hwc_cq->comp_buf, M_DEVBUF); @@ -531,9 +528,6 @@ static void mana_hwc_destroy_wq(struct hw_channel_context *hwc, struct hwc_wq *hwc_wq) { - if (!hwc_wq) - return; - mana_hwc_dealloc_dma_buf(hwc, hwc_wq->msg_buf); if (hwc_wq->gdma_wq) @@ -718,6 +712,7 @@ mana_hwc_establish_channel(struct gdma_context *gc, uint16_t *q_depth, *max_req_msg_size = hwc->hwc_init_max_req_msg_size; *max_resp_msg_size = hwc->hwc_init_max_resp_msg_size; + /* Both were set in mana_hwc_init_event_handler(). */ if (cq->id >= gc->max_num_cqs) { mana_warn(NULL, "invalid cq id %u > %u\n", cq->id, gc->max_num_cqs); @@ -738,9 +733,6 @@ static int mana_hwc_init_queues(struct hw_channel_context *hwc, uint16_t q_depth, uint32_t max_req_msg_size, uint32_t max_resp_msg_size) { - struct hwc_wq *hwc_rxq = NULL; - struct hwc_wq *hwc_txq = NULL; - struct hwc_cq *hwc_cq = NULL; int err; err = mana_hwc_init_inflight_msg(hwc, q_depth); @@ -753,44 +745,32 @@ mana_hwc_init_queues(struct hw_channel_context *hwc, uint16_t q_depth, err = mana_hwc_create_cq(hwc, q_depth * 2, mana_hwc_init_event_handler, hwc, mana_hwc_rx_event_handler, hwc, - mana_hwc_tx_event_handler, hwc, &hwc_cq); + mana_hwc_tx_event_handler, hwc, &hwc->cq); if (err) { device_printf(hwc->dev, "Failed to create HWC CQ: %d\n", err); goto out; } - hwc->cq = hwc_cq; err = mana_hwc_create_wq(hwc, GDMA_RQ, q_depth, max_req_msg_size, - hwc_cq, &hwc_rxq); + hwc->cq, &hwc->rxq); if (err) { device_printf(hwc->dev, "Failed to create HWC RQ: %d\n", err); goto out; } - hwc->rxq = hwc_rxq; err = mana_hwc_create_wq(hwc, GDMA_SQ, q_depth, max_resp_msg_size, - hwc_cq, &hwc_txq); + hwc->cq, &hwc->txq); if (err) { device_printf(hwc->dev, "Failed to create HWC SQ: %d\n", err); goto out; } - hwc->txq = hwc_txq; hwc->num_inflight_msg = q_depth; hwc->max_req_msg_size = max_req_msg_size; return 0; out: - if (hwc_txq) - mana_hwc_destroy_wq(hwc, hwc_txq); - - if (hwc_rxq) - mana_hwc_destroy_wq(hwc, hwc_rxq); - - if (hwc_cq) - mana_hwc_destroy_cq(hwc->gdma_dev->gdma_context, hwc_cq); - - mana_gd_free_res_map(&hwc->inflight_msg_res); + /* mana_hwc_create_channel() will do the cleanup.*/ return err; } @@ -819,6 +799,10 @@ mana_hwc_create_channel(struct gdma_context *gc) gd->pdid = INVALID_PDID; gd->doorbell = INVALID_DOORBELL; + /* + * mana_hwc_init_queues() only creates the required data structures, + * and doesn't touch the HWC device. + */ err = mana_hwc_init_queues(hwc, HW_CHANNEL_VF_BOOTSTRAP_QUEUE_DEPTH, HW_CHANNEL_MAX_REQUEST_SIZE, HW_CHANNEL_MAX_RESPONSE_SIZE); @@ -846,7 +830,7 @@ mana_hwc_create_channel(struct gdma_context *gc) return 0; out: - free(hwc, M_DEVBUF); + mana_hwc_destroy_channel(gc); return (err); } @@ -854,35 +838,44 @@ void mana_hwc_destroy_channel(struct gdma_context *gc) { struct hw_channel_context *hwc = gc->hwc.driver_data; - struct hwc_caller_ctx *ctx; - mana_smc_teardown_hwc(&gc->shm_channel, false); + if (!hwc) + return; + + /* + * gc->max_num_cqs is set in mana_hwc_init_event_handler(). If it's + * non-zero, the HWC worked and we should tear down the HWC here. + */ + if (gc->max_num_cqs > 0) { + mana_smc_teardown_hwc(&gc->shm_channel, false); + gc->max_num_cqs = 0; + } - ctx = hwc->caller_ctx; - free(ctx, M_DEVBUF); + free(hwc->caller_ctx, M_DEVBUF); hwc->caller_ctx = NULL; - mana_hwc_destroy_wq(hwc, hwc->txq); - hwc->txq = NULL; + if (hwc->txq) + mana_hwc_destroy_wq(hwc, hwc->txq); - mana_hwc_destroy_wq(hwc, hwc->rxq); - hwc->rxq = NULL; + if (hwc->rxq) + mana_hwc_destroy_wq(hwc, hwc->rxq); - mana_hwc_destroy_cq(hwc->gdma_dev->gdma_context, hwc->cq); - hwc->cq = NULL; + if (hwc->cq) + mana_hwc_destroy_cq(hwc->gdma_dev->gdma_context, hwc->cq); mana_gd_free_res_map(&hwc->inflight_msg_res); hwc->num_inflight_msg = 0; - if (hwc->gdma_dev->pdid != INVALID_PDID) { - hwc->gdma_dev->doorbell = INVALID_DOORBELL; - hwc->gdma_dev->pdid = INVALID_PDID; - } + hwc->gdma_dev->doorbell = INVALID_DOORBELL; + hwc->gdma_dev->pdid = INVALID_PDID; free(hwc, M_DEVBUF); gc->hwc.driver_data = NULL; gc->hwc.gdma_context = NULL; + + free(gc->cq_table, M_DEVBUF); + gc->cq_table = NULL; } int