From patchwork Wed Jun 6 13:07:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Salil Mehta X-Patchwork-Id: 137830 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp782261lji; Wed, 6 Jun 2018 06:09:03 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLsXqfl16Pbdr2hQwbSjVeSNRhtLom5WEeZFz4e0LVShqM/63Ock3R++y7hM2WRjTCGyVnp X-Received: by 2002:a63:7a07:: with SMTP id v7-v6mr2514019pgc.444.1528290543407; Wed, 06 Jun 2018 06:09:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528290543; cv=none; d=google.com; s=arc-20160816; b=T1h08hSG4WqqpsxJ+4rwO+PwHsC4F+CFpbibYh5Kfc/apS5q3gWQeWCTDCHAeIoueS P3F1kwx4USmWbtXq6sDL2+hORFFLN6CMHFzw+Vwth+ehpqPL+z/6Fw25Y6mddT1/CkTK BVsMBIDnBgjaqLUkpi3T7A99oA24UiauvVfW37LnVh9qGx1Yu2ZEE1GQIVD3whPm/bPq nOe5p76WM9pxd5laEV34Xf3qZjFy7D0Q7L+oNP3IxXbLablD+kNdAthlzJ14YGIsh7hf fcAM314UNHUo6zZSmn2iO6/Qi76sL/IjwlYXyhMcUS1xc6A2RpU7rpc3cRkd1IRJwMmx aInw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=nvrdJDXREFF5RpcyFg/kYpQawlqsK+zxPAnStwsT50g=; b=B8YMbpeZDUPOhnNoLOB6p4vLhRHNDWOpEot7RZKERl1cdywoYFOiCuI1Sn/keTxO69 Kx3HQcUgWR2UXp0/2dSyw74SohusCnfztuLy9j8Oxa/AMMQWHttP9iGxnOKcpoSdOyfs zax6wN2UiGsQA1wGxncCg4X6lXJa0i/jKuCcBAYuND6z1SGuStYgn/iW9hTO0n+Jr16G XvLRW4GJkuASFL4vUavJZgNvQtU54e+dyOtQmMGDtA86Vmgv4JXbnKSjFCkFlw280YDA CWmlG6HR8BpWLtdkEHgjHNsbe3WhcLujiEqLv4fHZSSITSKwyzmpi74cK3S0SE0EZENc l7Pg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l12-v6si2822010pgp.683.2018.06.06.06.09.03; Wed, 06 Jun 2018 06:09:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752262AbeFFNJB (ORCPT + 30 others); Wed, 6 Jun 2018 09:09:01 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:8700 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751914AbeFFNI5 (ORCPT ); Wed, 6 Jun 2018 09:08:57 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id C17A29C55C857; Wed, 6 Jun 2018 21:08:42 +0800 (CST) Received: from S00293818-DELL1.china.huawei.com (10.202.227.234) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.382.0; Wed, 6 Jun 2018 21:08:37 +0800 From: Salil Mehta To: CC: , , , , , , , Xi Wang Subject: [PATCH V2 net-next 2/3] net: hns3: Fix for VF mailbox receiving unknown message Date: Wed, 6 Jun 2018 14:07:52 +0100 Message-ID: <20180606130753.54428-3-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20180606130753.54428-1-salil.mehta@huawei.com> References: <20180606130753.54428-1-salil.mehta@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.202.227.234] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Xi Wang Before the firmware updates the crq's tail pointer, if the VF driver reads the data in the crq, the data may be incomplete at this time, which will lead to the driver read an unknown message. This patch fixes it by checking if crq is empty before reading the message. Fixes: b11a0bb231f3 ("net: hns3: Add mailbox support to VF driver") Signed-off-by: Xi Wang Signed-off-by: Peng Li Signed-off-by: Salil Mehta --- Patch V2: Fixes the compilation break reported David Miller & Kbuild Link: https://lkml.org/lkml/2018/6/5/866 https://lkml.org/lkml/2018/6/6/147 Patch V1: Initial Submit --- .../ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) -- 2.7.4 diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c index a286184..b598c06 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c @@ -126,6 +126,13 @@ int hclgevf_send_mbx_msg(struct hclgevf_dev *hdev, u16 code, u16 subcode, return status; } +static bool hclgevf_cmd_crq_empty(struct hclgevf_hw *hw) +{ + u32 tail = hclgevf_read_dev(hw, HCLGEVF_NIC_CRQ_TAIL_REG); + + return tail == hw->cmq.crq.next_to_use; +} + void hclgevf_mbx_handler(struct hclgevf_dev *hdev) { struct hclgevf_mbx_resp_status *resp; @@ -140,11 +147,22 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev) resp = &hdev->mbx_resp; crq = &hdev->hw.cmq.crq; - flag = le16_to_cpu(crq->desc[crq->next_to_use].flag); - while (hnae_get_bit(flag, HCLGEVF_CMDQ_RX_OUTVLD_B)) { + while (!hclgevf_cmd_crq_empty(&hdev->hw)) { desc = &crq->desc[crq->next_to_use]; req = (struct hclge_mbx_pf_to_vf_cmd *)desc->data; + flag = le16_to_cpu(crq->desc[crq->next_to_use].flag); + if (unlikely(!hnae_get_bit(flag, HCLGEVF_CMDQ_RX_OUTVLD_B))) { + dev_warn(&hdev->pdev->dev, + "dropped invalid mailbox message, code = %d\n", + req->msg[0]); + + /* dropping/not processing this invalid message */ + crq->desc[crq->next_to_use].flag = 0; + hclge_mbx_ring_ptr_move_crq(crq); + continue; + } + /* synchronous messages are time critical and need preferential * treatment. Therefore, we need to acknowledge all the sync * responses as quickly as possible so that waiting tasks do not @@ -205,7 +223,6 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev) } crq->desc[crq->next_to_use].flag = 0; hclge_mbx_ring_ptr_move_crq(crq); - flag = le16_to_cpu(crq->desc[crq->next_to_use].flag); } /* Write back CMDQ_RQ header pointer, M7 need this pointer */