From patchwork Wed Jun 7 07:54:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Chan X-Patchwork-Id: 13270122 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D418A8BE7 for ; Wed, 7 Jun 2023 07:54:51 +0000 (UTC) Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54BDEAA for ; Wed, 7 Jun 2023 00:54:50 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-6261367d2f1so51746836d6.3 for ; Wed, 07 Jun 2023 00:54:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1686124489; x=1688716489; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=fg/Qb98GLEbdpBWb9kRatcISpRG+6EjwC/InVO03vSE=; b=NYAxV6zKT6i8XVq5pk+baLevmSJ0NGvsuSGubst37AzxTM7ID6M9NQRaqNPYRDez4q XMGK2AzptW9Idn+ZWiON3b96Rr2lGZ/4EW52FbT2TiDI7+z0fy5qUJ4eTY2RzRybkG5w 9RwWncqsc6vxIxCZHm+vl55Hha5fHR/aeygA0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686124489; x=1688716489; h=mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fg/Qb98GLEbdpBWb9kRatcISpRG+6EjwC/InVO03vSE=; b=fBl94VhSdESWc/SAUMU3FElBDfeE0uS0mg+RcgRvHbhdNwUZnxLwwG7CDeDEGc8/kd YJnQl0mHiWO3VHMZN1xCxWTEF1y7POc+PutHhtzrBdCXd0JuHqQ6efN7/bxet/ZAeftD l3fY+0fH6cguDCSsq0J01rKcUccRcMwJUz8IyE3FHPYa4j0vVbEzYfeQK5SMJniurh8e Dtd274rWFMj4sXmXRD0ydu2v3O0ZsXBZi7WyhWBo7/Txa3CaLmYKNN4uJsYj5lzeIayZ c1M91E2EaoSMiFURt3SKMzkS+DuhxD5/bb2LbiKlaKs5yYPLCzRJs2qtkaH6bjY3/OVQ 2Nig== X-Gm-Message-State: AC+VfDxIF3GPgkg3L4yEOiOlk+moKAqP3X0QttYWMksjCRcCL/mFjElU GbWtSZv9xVclw9T96yt+4IIVqg== X-Google-Smtp-Source: ACHHUZ508WKWfuuRS25FtvLLsk0E4B/aD/qOthTS5tME8mcUd5Edjx2mGzokWxHZN43lU19tyueWXg== X-Received: by 2002:ad4:5f8d:0:b0:621:4669:c806 with SMTP id jp13-20020ad45f8d000000b006214669c806mr2449642qvb.37.1686124489235; Wed, 07 Jun 2023 00:54:49 -0700 (PDT) Received: from lvnvda5233.lvn.broadcom.net ([192.19.161.250]) by smtp.gmail.com with ESMTPSA id cs12-20020ad44c4c000000b00626362f1bf1sm5850817qvb.63.2023.06.07.00.54.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jun 2023 00:54:48 -0700 (PDT) From: Michael Chan To: davem@davemloft.net Cc: netdev@vger.kernel.org, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, gospo@broadcom.com, Pavan Chebbi Subject: [PATCH net 5/6] bnxt_en: Prevent kernel panic when receiving unexpected PHC_UPDATE event Date: Wed, 7 Jun 2023 00:54:08 -0700 Message-Id: <20230607075409.228450-6-michael.chan@broadcom.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20230607075409.228450-1-michael.chan@broadcom.com> References: <20230607075409.228450-1-michael.chan@broadcom.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Pavan Chebbi The firmware can send PHC_RTC_UPDATE async event on a PF that may not have PTP registered. In such a case, there will be a null pointer deference for bp->ptp_cfg when we try to handle the event. Fix it by not registering for this event with the firmware if !bp->ptp_cfg. Also, check that bp->ptp_cfg is valid before proceeding when we receive the event. Fixes: 8bcf6f04d4a5 ("bnxt_en: Handle async event when the PHC is updated in RTC mode") Signed-off-by: Pavan Chebbi Signed-off-by: Michael Chan --- drivers/net/ethernet/broadcom/bnxt/bnxt.c | 6 ++++++ drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c | 1 + 2 files changed, 7 insertions(+) diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt.c b/drivers/net/ethernet/broadcom/bnxt/bnxt.c index 5c8d409d7af8..c0b0423de338 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt.c @@ -2365,6 +2365,9 @@ static int bnxt_async_event_process(struct bnxt *bp, struct bnxt_ptp_cfg *ptp = bp->ptp_cfg; u64 ns; + if (!ptp) + goto async_event_process_exit; + spin_lock_bh(&ptp->ptp_lock); bnxt_ptp_update_current_time(bp); ns = (((u64)BNXT_EVENT_PHC_RTC_UPDATE(data1) << @@ -4763,6 +4766,9 @@ int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp, unsigned long *bmap, int bmap_size, if (event_id == ASYNC_EVENT_CMPL_EVENT_ID_ERROR_RECOVERY && !(bp->fw_cap & BNXT_FW_CAP_ERROR_RECOVERY)) continue; + if (event_id == ASYNC_EVENT_CMPL_EVENT_ID_PHC_UPDATE && + !bp->ptp_cfg) + continue; __set_bit(bnxt_async_events_arr[i], async_events_bmap); } if (bmap && bmap_size) { diff --git a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c index e46689128e32..f3886710e778 100644 --- a/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c +++ b/drivers/net/ethernet/broadcom/bnxt/bnxt_ptp.c @@ -952,6 +952,7 @@ int bnxt_ptp_init(struct bnxt *bp, bool phc_cfg) bnxt_ptp_timecounter_init(bp, true); bnxt_ptp_adjfine_rtc(bp, 0); } + bnxt_hwrm_func_drv_rgtr(bp, NULL, 0, true); ptp->ptp_info = bnxt_ptp_caps; if ((bp->fw_cap & BNXT_FW_CAP_PTP_PPS)) {