From patchwork Tue Jan 25 15:29:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1584132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=vHyON5oy; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JjrPt0zbPz9t6h for ; Wed, 26 Jan 2022 02:29:52 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nCNlQ-0000ex-Dm; Tue, 25 Jan 2022 15:29:44 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nCNlO-0000eU-2D for kernel-team@lists.ubuntu.com; Tue, 25 Jan 2022 15:29:42 +0000 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 210553F1A4 for ; Tue, 25 Jan 2022 15:29:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1643124581; bh=ND8iOlM2f+fp8hjECVHGzOoBYHONI+YiEslenjxHJ7A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=vHyON5oyK/OwhwMvtDcNITw9IJ+KFHdqdjXE0TSbpZKXrnrxUNQAhnj2XHbDZxTmb S9AmCC6fXIqNNP1456ZhuA+0/xq2xdXmCpXTFlyXGTItvsWCyB48WLWxw8aG/ftth4 Vg3BW0LAj9wF6xo2FINNNd/GiXvaJWEuDh+xlnHfyqJ+kz0jR+SCERJskbyJk+WSvS 0w22lM36s2Z2xksctduPPKTHrediiChZb0tMIS8x7yaH2gd7lI94gUffrvVOd5rlD+ QasJrQetYtaECdvwHDaf/iOwf6M0GDfWMUe86GpxdESm98dALSxICJcMh/Fk2cHjy0 9TMOG91MDlJKg== Received: by mail-pg1-f198.google.com with SMTP id r9-20020a6560c9000000b00343fa9529e5so11907876pgv.18 for ; Tue, 25 Jan 2022 07:29:41 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ND8iOlM2f+fp8hjECVHGzOoBYHONI+YiEslenjxHJ7A=; b=aOTGkS9h14gtHOKU9F/iwdl4fIwFdsw/C/1gyKRaRKrMFpogfDkT6CZkD2dorCMYn7 cXK1JSEoXPWemIppRuo04Q/xDbiFKKt8r0AQjthxFmu931fsljupeL5CYmDJdPHJycdv 9vabABAQkxMzAjDyyj/EYppWXDzuUj/0dJaNzTa3yZr4IfpsuDE3ZBK23xPwADoemBjc Mmh22rl4N+f0t2pEKdyKmCE95LK9rzepnvSNjBagmrBq/gyDsCtpj9/Y2GMLny0bJy7X hPdUT1hHcHtw63TWjwIVMLoX4kBoQujiT5RNaAVsJoArGoA6ULrmKNc0MWshxIsHj21L bLWQ== X-Gm-Message-State: AOAM531FQ3OirsG58pQ62B5gkZ7wVogWPDKEO8otaFX7ijfI5LByyLHO uJ55/sxCKDo7Z4Rau+qn9P70pLyL4VoaTR0CBxbjQe9fCXwGEDnSM1X94kGLf/C1dJCiNr5utic +QdcVI35h72xJfL9IX2yVCTWxhKMxUUzbbVgwaivF0g== X-Received: by 2002:a17:90a:ab8d:: with SMTP id n13mr3957939pjq.133.1643124579377; Tue, 25 Jan 2022 07:29:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJz7TF90B0wIJxDgi2z2zxb7ZAwAvvuXiQEwLhC7VPKziG5Edd8zdDctKsk3g6k3TSZQauXSQg== X-Received: by 2002:a17:90a:ab8d:: with SMTP id n13mr3957921pjq.133.1643124579077; Tue, 25 Jan 2022 07:29:39 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id s6sm15321071pgk.44.2022.01.25.07.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 07:29:38 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 1/2] net: mana: Add RX fencing Date: Tue, 25 Jan 2022 08:29:20 -0700 Message-Id: <20220125152921.16937-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220125152921.16937-1-tim.gardner@canonical.com> References: <20220125152921.16937-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Dexuan Cui BugLink: https://bugs.launchpad.net/bugs/1959012 RX fencing allows the driver to know that any prior change to the RQs has finished, e.g. when the RQs are disabled/enabled or the hashkey/indirection table are changed, RX fencing is required. Remove the previous workaround "ssleep(1)" and add the real support for RX fencing as the PF driver supports the MANA_FENCE_RQ request now (any old PF driver not supporting the request won't be used in production). Signed-off-by: Dexuan Cui Reviewed-by: Haiyang Zhang Link: https://lore.kernel.org/r/20211216001748.8751-1-decui@microsoft.com Signed-off-by: Jakub Kicinski (cherry picked from commit 6cc74443a7732d7e93bee3d0c3704a22cc7274d9) Signed-off-by: Tim Gardner --- drivers/net/ethernet/microsoft/mana/mana.h | 2 + drivers/net/ethernet/microsoft/mana/mana_en.c | 69 +++++++++++++++++-- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/mana.h b/drivers/net/ethernet/microsoft/mana/mana.h index 0c5553887b75..9a12607fb511 100644 --- a/drivers/net/ethernet/microsoft/mana/mana.h +++ b/drivers/net/ethernet/microsoft/mana/mana.h @@ -289,6 +289,8 @@ struct mana_rxq { struct mana_cq rx_cq; + struct completion fence_event; + struct net_device *ndev; /* Total number of receive buffers to be allocated */ diff --git a/drivers/net/ethernet/microsoft/mana/mana_en.c b/drivers/net/ethernet/microsoft/mana/mana_en.c index bcbc82364597..b6642241735b 100644 --- a/drivers/net/ethernet/microsoft/mana/mana_en.c +++ b/drivers/net/ethernet/microsoft/mana/mana_en.c @@ -750,6 +750,61 @@ static int mana_create_eq(struct mana_context *ac) return err; } +static int mana_fence_rq(struct mana_port_context *apc, struct mana_rxq *rxq) +{ + struct mana_fence_rq_resp resp = {}; + struct mana_fence_rq_req req = {}; + int err; + + init_completion(&rxq->fence_event); + + mana_gd_init_req_hdr(&req.hdr, MANA_FENCE_RQ, + sizeof(req), sizeof(resp)); + req.wq_obj_handle = rxq->rxobj; + + err = mana_send_request(apc->ac, &req, sizeof(req), &resp, + sizeof(resp)); + if (err) { + netdev_err(apc->ndev, "Failed to fence RQ %u: %d\n", + rxq->rxq_idx, err); + return err; + } + + err = mana_verify_resp_hdr(&resp.hdr, MANA_FENCE_RQ, sizeof(resp)); + if (err || resp.hdr.status) { + netdev_err(apc->ndev, "Failed to fence RQ %u: %d, 0x%x\n", + rxq->rxq_idx, err, resp.hdr.status); + if (!err) + err = -EPROTO; + + return err; + } + + if (wait_for_completion_timeout(&rxq->fence_event, 10 * HZ) == 0) { + netdev_err(apc->ndev, "Failed to fence RQ %u: timed out\n", + rxq->rxq_idx); + return -ETIMEDOUT; + } + + return 0; +} + +static void mana_fence_rqs(struct mana_port_context *apc) +{ + unsigned int rxq_idx; + struct mana_rxq *rxq; + int err; + + for (rxq_idx = 0; rxq_idx < apc->num_queues; rxq_idx++) { + rxq = apc->rxqs[rxq_idx]; + err = mana_fence_rq(apc, rxq); + + /* In case of any error, use sleep instead. */ + if (err) + msleep(100); + } +} + static int mana_move_wq_tail(struct gdma_queue *wq, u32 num_units) { u32 used_space_old; @@ -1023,7 +1078,7 @@ static void mana_process_rx_cqe(struct mana_rxq *rxq, struct mana_cq *cq, return; case CQE_RX_OBJECT_FENCE: - netdev_err(ndev, "RX Fencing is unsupported\n"); + complete(&rxq->fence_event); return; default: @@ -1617,6 +1672,7 @@ int mana_config_rss(struct mana_port_context *apc, enum TRI_STATE rx, bool update_hash, bool update_tab) { u32 queue_idx; + int err; int i; if (update_tab) { @@ -1626,7 +1682,13 @@ int mana_config_rss(struct mana_port_context *apc, enum TRI_STATE rx, } } - return mana_cfg_vport_steering(apc, rx, true, update_hash, update_tab); + err = mana_cfg_vport_steering(apc, rx, true, update_hash, update_tab); + if (err) + return err; + + mana_fence_rqs(apc); + + return 0; } static int mana_init_port(struct net_device *ndev) @@ -1773,9 +1835,6 @@ static int mana_dealloc_queues(struct net_device *ndev) return err; } - /* TODO: Implement RX fencing */ - ssleep(1); - mana_destroy_vport(apc); return 0; From patchwork Tue Jan 25 15:29:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1584133 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=FVVs8gpw; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JjrPt0x3yz9t6g for ; Wed, 26 Jan 2022 02:29:52 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1nCNlR-0000fF-Is; Tue, 25 Jan 2022 15:29:45 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1nCNlP-0000em-Dk for kernel-team@lists.ubuntu.com; Tue, 25 Jan 2022 15:29:43 +0000 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 7BE383F1B4 for ; Tue, 25 Jan 2022 15:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1643124582; bh=CgMQ7AjmI+aC0A+QcY6Y3D1dP3KtpUV9CtFv1C3qapw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=FVVs8gpwClEXBPsbhfsX5g9Rmq+nL6ju7s3bG8JOoZKVOu0xvDCZh4Wv8PvOVpost l0YTfuKZFlqUvMPyuYLBp+6yYwk4P8NhRmvt4YzNtgPP9o+gIPTWCBwDUNA8iV64s/ UT8lvMS2rIO8iICVCbno4qvMMdgUKawB+ITSp4c4E/dJtmj68HrpKc3UXmZjI0sd9N ljqHKkrAzlmZUTW1Ze+aLlt+5ys1IfLFxYRpBsTiKS5kjKoucTR6yGi2Q631cswZYW O6COG8KtIQVicRJh55vLIJ0B+UIFxx14U4haaWAAPitq0bAxw7nxT7/r8jvm9tzyDs XFbavCk6qUhEQ== Received: by mail-pl1-f198.google.com with SMTP id cp2-20020a170902e78200b0014a9f3e3c1fso5249465plb.5 for ; Tue, 25 Jan 2022 07:29:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CgMQ7AjmI+aC0A+QcY6Y3D1dP3KtpUV9CtFv1C3qapw=; b=GXkDAea3cITMZYfaaPSogBzeFF80SO4KrqQ1vOuVywtBMN+5rg8mDIYX3r02K7TbQ+ MHJ4vhaKg4A3RkJ6e2ZuiFFGQPMuTB1vevc9qpt19VEcnkukGE6Rj56mk/RFywcjznl2 Tm+LYHS6cq146PeMA551LuZr8u6uvxRvSuMRi16AG9+A9Ismd6Tdlil2StaKttr4EyAs CgktTZpUIiM9A9+zJNzUFabw1Rw5rUMLBQo33e8XPYU+nLEwCk2spzbkJtRgVd31hjey 0IlKjcqjwi1VxhxFVT0qmqqH3plmTj57qeeWuv5155rbrBr9qMoAkVnhKpfpouGQ2Hc/ hz9w== X-Gm-Message-State: AOAM532uTNAd78d4KJKriOiVXGrLuK5+l1mqikJ5IhM0FjhLp8c2oz/9 irWzMPYWLPwZxtuhAyZXNU0/oaMdER2zDkYTNmtLysbMB9/9LZ7dnprg6FBX6Qz4oxK1j4WMt0u jZ6g+cazrOZnxIMTMelewHe6Hgq0aLt4j5HkWWOW9qA== X-Received: by 2002:a65:464e:: with SMTP id k14mr15542346pgr.225.1643124580694; Tue, 25 Jan 2022 07:29:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyI19qzN9cMKixI3Pm6Oeou9AaFBNK9yGOg+rPBqfDk4OTwczFPx7877PH0oa2rUvCLidyAAg== X-Received: by 2002:a65:464e:: with SMTP id k14mr15542336pgr.225.1643124580384; Tue, 25 Jan 2022 07:29:40 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id s6sm15321071pgk.44.2022.01.25.07.29.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 07:29:39 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH 2/2] net: mana: Fix memory leak in mana_hwc_create_wq Date: Tue, 25 Jan 2022 08:29:21 -0700 Message-Id: <20220125152921.16937-3-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220125152921.16937-1-tim.gardner@canonical.com> References: <20220125152921.16937-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: José Expósito BugLink: https://bugs.launchpad.net/bugs/1959012 If allocating the DMA buffer fails, mana_hwc_destroy_wq was called without previously storing the pointer to the queue. In order to avoid leaking the pointer to the queue, store it as soon as it is allocated. Addresses-Coverity-ID: 1484720 ("Resource leak") Signed-off-by: José Expósito Reviewed-by: Dexuan Cui Link: https://lore.kernel.org/r/20211208223723.18520-1-jose.exposito89@gmail.com Signed-off-by: Jakub Kicinski (cherry picked from commit 9acfc57fa2b8944ed079cedbf846823ea32b8a31) Signed-off-by: Tim Gardner --- drivers/net/ethernet/microsoft/mana/hw_channel.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/microsoft/mana/hw_channel.c b/drivers/net/ethernet/microsoft/mana/hw_channel.c index 34b971ff8ef8..078d6a5a0768 100644 --- a/drivers/net/ethernet/microsoft/mana/hw_channel.c +++ b/drivers/net/ethernet/microsoft/mana/hw_channel.c @@ -480,16 +480,16 @@ static int mana_hwc_create_wq(struct hw_channel_context *hwc, if (err) goto out; - err = mana_hwc_alloc_dma_buf(hwc, q_depth, max_msg_size, - &hwc_wq->msg_buf); - if (err) - goto out; - hwc_wq->hwc = hwc; hwc_wq->gdma_wq = queue; hwc_wq->queue_depth = q_depth; hwc_wq->hwc_cq = hwc_cq; + err = mana_hwc_alloc_dma_buf(hwc, q_depth, max_msg_size, + &hwc_wq->msg_buf); + if (err) + goto out; + *hwc_wq_ptr = hwc_wq; return 0; out: