From patchwork Sun Aug 29 07:35:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12463771 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,MIME_HEADER_CTYPE_ONLY, SPF_HELO_NONE,SPF_PASS,T_TVD_MIME_NO_HEADERS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3BAAC43214 for ; Sun, 29 Aug 2021 07:35:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D673760C3E for ; Sun, 29 Aug 2021 07:35:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234876AbhH2Hg0 (ORCPT ); Sun, 29 Aug 2021 03:36:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234835AbhH2HgX (ORCPT ); Sun, 29 Aug 2021 03:36:23 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41757C0613D9 for ; Sun, 29 Aug 2021 00:35:31 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id me10so23704998ejb.11 for ; Sun, 29 Aug 2021 00:35:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Kq3EpLJ7qVZq3JDoVpaaZSalTxMZVLyqofXbeEna7FU=; b=DzBhDY7kqkeM6e0Wq3t7iKC+PazPADkw7pICIXncvNHo2oQzHaNlMInmd15NzplfLv +xmt/M6m+khPXMG89QfZr9xlXdzyjw6obujVY8PfmtXCrzyfQ14MHLA6yj8YEiqTZLVj B+JojZaDohUh6k44vjBn7pEsPCOr9VT5w2Mqc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Kq3EpLJ7qVZq3JDoVpaaZSalTxMZVLyqofXbeEna7FU=; b=tKTil/2gfs4twlnQ0V6PhwWmXWaZOmowqs9gEHRvnPSaTj6+2tc5WBtQ/qaP3qFWj5 sm2tEnFV20s+//EGWwgct4WH72yU7W3SQnw1rRjOxevOO77X/yRUos9UTL9DKVpxTlWP ZmBxleJoafXjCOYI77ejqks7ObJ7ctFXcitx/eouSlAYC0x3Nf1pFHG0AWuT31s5SV1p ClziNgKV2q7i3JOCZjeRQD55yY9L5XdzG/7TdYf9yXQEY4z+cWCRRIr+M/svMisJJg8W LC9HmFmmVTwOVwR3sI4dsgJFpd1F2BYLaFdAtnrxRtWzUsefN2KogbhEtc525rRhMK8Q 1tcA== X-Gm-Message-State: AOAM533IOplpDKzwWIYOztkiJ8F8OHcVZU90zjA0xmuo1lG89tzX+OHQ fUhwreRPdXCb6qazYY+0wv8WODrQJtex/w== X-Google-Smtp-Source: ABdhPJxIQS4YC+/o+19qO62AbsP/2LDR3ajMzPS/K6I/kqR6kS5S/cOqRZTAjnPocGhqBs1X3hXxfA== X-Received: by 2002:a17:906:16c4:: with SMTP id t4mr11706181ejd.302.1630222529590; Sun, 29 Aug 2021 00:35:29 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id dy7sm984007edb.38.2021.08.29.00.35.27 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 29 Aug 2021 00:35:29 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, kuba@kernel.org, edwin.peer@broadcom.com, gospo@broadcom.com Subject: [PATCH net-next v2 05/11] bnxt_en: discard out of sequence HWRM responses Date: Sun, 29 Aug 2021 03:35:00 -0400 Message-Id: <1630222506-19532-6-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630222506-19532-1-git-send-email-michael.chan@broadcom.com> References: <1630222506-19532-1-git-send-email-michael.chan@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Edwin Peer During firmware crash recovery, it is possible for firmware to respond to stale HWRM commands that have already timed out. Because response buffers may be reused, any out of sequence responses need to be ignored and only the matching seq_id should be accepted. Also, READ_ONCE should be used for the reads from the DMA buffer to ensure that the necessary loads are scheduled. Reviewed-by: Scott Branden Signed-off-by: Edwin Peer Signed-off-by: Michael Chan --- .../net/ethernet/broadcom/bnxt/bnxt_hwrm.c | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c index a45f2a619086..621daf687a00 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_hwrm.c @@ -399,9 +399,10 @@ static int __hwrm_send(struct bnxt *bp, struct bnxt_hwrm_ctx *ctx) le16_to_cpu(ctx->req->req_type)); goto exit; } - len = le16_to_cpu(ctx->resp->resp_len); + len = le16_to_cpu(READ_ONCE(ctx->resp->resp_len)); valid = ((u8 *)ctx->resp) + len - 1; } else { + __le16 seen_out_of_seq = ctx->req->seq_id; /* will never see */ int j; /* Check if response len is updated */ @@ -411,9 +412,21 @@ static int __hwrm_send(struct bnxt *bp, struct bnxt_hwrm_ctx *ctx) */ if (test_bit(BNXT_STATE_FW_FATAL_COND, &bp->state)) goto exit; - len = le16_to_cpu(ctx->resp->resp_len); - if (len) - break; + len = le16_to_cpu(READ_ONCE(ctx->resp->resp_len)); + if (len) { + __le16 resp_seq = READ_ONCE(ctx->resp->seq_id); + + if (resp_seq == ctx->req->seq_id) + break; + if (resp_seq != seen_out_of_seq) { + netdev_warn(bp->dev, "Discarding out of seq response: 0x%x for msg {0x%x 0x%x}\n", + le16_to_cpu(resp_seq), + le16_to_cpu(ctx->req->req_type), + le16_to_cpu(ctx->req->seq_id)); + seen_out_of_seq = resp_seq; + } + } + /* on first few passes, just barely sleep */ if (i < HWRM_SHORT_TIMEOUT_COUNTER) { usleep_range(HWRM_SHORT_MIN_TIMEOUT,