From patchwork Sat Aug 28 21:58:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 12463645 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.4 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,URIBL_BLOCKED,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 86A71C432BE for ; Sat, 28 Aug 2021 21:59:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F5E860462 for ; Sat, 28 Aug 2021 21:59:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233797AbhH1V7y (ORCPT ); Sat, 28 Aug 2021 17:59:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232609AbhH1V7t (ORCPT ); Sat, 28 Aug 2021 17:59:49 -0400 Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98C2EC061756 for ; Sat, 28 Aug 2021 14:58:58 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id q3so15430242edt.5 for ; Sat, 28 Aug 2021 14:58:58 -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=Ia5muHIo9iuUXZID9UkO1+fdS6rwyNsmxsu9KHZ7iBs=; b=O/Ldp82tNFZl1cayNwz+ZbqGqDPXXCgW0cPDIYJ3y5NEtXBuc1OeCzgxodVmzV33hw FK0FzmXneD94UBwMNIXULdwogj+Ct1gKrOv7c7NQEVgUGnCyOchxO5aCDqRwPgOqRqyX WO4p/lk34hftYrk3qovM8lExDKaFjurmpomyM= 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=Ia5muHIo9iuUXZID9UkO1+fdS6rwyNsmxsu9KHZ7iBs=; b=P6s5U9F5ByHJ28JWb7gzb6p+sD0WoQBF9oYbbv5laqdewbl8C5+2jdafCqQIrpFn4m dicFAbXhcA4G+2dX2M/LPocjemCTwxrlKot2CPNQdbFdYyfQ4jxeLlOy9uUtVK97XiFO S8CdLKhcFp/tqFNke2Vj20WaZ6Jb0xlzGqJjuM4c5K3TTlT0BHyd6krDI260KgA2ISru RmLcS4QbeSqv7tE2OKSDdVPcxNhbndrvrE/hogEOX2A/WhWyShR2ulHYdkP1555AEF0A 5j7HVOI6CPsHHzDOZvWlTycQwgwHgNoBGScjpWoBAHTxmOy8XTq5YHZeBorUxhcjGmCC V6aw== X-Gm-Message-State: AOAM530Bf/khl7KaFPQzZ5L/GocTBaEpdG/FQuEtDBZztAaJsTbcwtiI esiD+94rukrf9OMtIDNm181/fLwtd7V9fw== X-Google-Smtp-Source: ABdhPJyF3FCrZy4NC9cTlXungHGl0oxq5JWG8hApZEPPwiMopHjhu0q5pCPC/dBxAj2zGTWiuAK5IQ== X-Received: by 2002:a05:6402:5188:: with SMTP id q8mr17087374edd.138.1630187936933; Sat, 28 Aug 2021 14:58:56 -0700 (PDT) Received: from localhost.swdvt.lab.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id cf11sm5361239edb.65.2021.08.28.14.58.55 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 28 Aug 2021 14:58:56 -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 05/11] bnxt_en: discard out of sequence HWRM responses Date: Sat, 28 Aug 2021 17:58:24 -0400 Message-Id: <1630187910-22252-6-git-send-email-michael.chan@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630187910-22252-1-git-send-email-michael.chan@broadcom.com> References: <1630187910-22252-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 91c4d3aac0b6..917d617afa87 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,