Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp3796910imm; Fri, 25 May 2018 11:48:48 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo2Ovoz7frRU9WNtL4PX+O7XUFidRrdZgSHVswTiDtI/59zpfvxm30ZxiiiiiYr0fVHAn2L X-Received: by 2002:a63:9a02:: with SMTP id o2-v6mr2865757pge.439.1527274128662; Fri, 25 May 2018 11:48:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527274128; cv=none; d=google.com; s=arc-20160816; b=i458gylzbkzw3M1XX8FOEmi+8VJu0ptJmT7ZluTe7wbSZXT6RTU3pniC51sVgq6CH3 CtYkkzyZxUApH/yoYMxFGTXLF9+qaR1YqntyOayWTlfm4q4T2VNUUtUMx8geuCcPEzFp XiNLdagNvM6pHl9EFWM3j6JJ7GcIgLMxClofQ9GAX7IXGh21DA3vwa9+EO/XYG6Rgfbb dJH7dYQr8DqCse1+YiXW8xFSkIeI7Br/fX7JZ0CodL6MzugoVw2uuYXC6PC0nqAaxv1z PBPak+QmE4yI6521bqXk057jz/ofpBSLnyfTP9yY0Dsy/eHNErwlw+Ycxag4jY5/IzPb AdLw== 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=RkIJFJfs4jZVYbV0LpA1As+SfboaDavS1JHha53TQqA=; b=nXML85uOuw7+VmS2gdVWYRr/8ydxEM03Tn+51BTd9r1Qjtdu6c9FPNMfU7xFTE+Q1/ q8Ua9coB2pBN7LtZjsqVr0ImRBW4StcqAOcyElaBDL8v9fXayJ8E0ERiFRJlmGY2XXii pQO89sW88Cw6A0/WXl0jIdsWPp5Djzj4TV52Q2U+5ek4z0r369AjULSTQRm/LFa1NXlj UnNVFEAdHaX3vzB4oiy8LbzyAjvxxChHcWSH1kNpTpeAcxYYblNYD+Tyr5PsWIsrilDf P/M54u3RtTnOVwLLb+jlTMOM/b0ggKSFkfl7WuWyIF7aNMpaeu0nqzrfOXyGbiMXLJFW GOXg== 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 n13-v6si19113891pgt.564.2018.05.25.11.48.33; Fri, 25 May 2018 11:48:48 -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 S967926AbeEYSot (ORCPT + 99 others); Fri, 25 May 2018 14:44:49 -0400 Received: from szxga07-in.huawei.com ([45.249.212.35]:60872 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S967824AbeEYSop (ORCPT ); Fri, 25 May 2018 14:44:45 -0400 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 9335AEF4F6BF5; Sat, 26 May 2018 02:44:41 +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; Sat, 26 May 2018 02:44:36 +0800 From: Salil Mehta To: CC: , , , , , , , Xi Wang Subject: [PATCH net-next 05/12] net: hns3: Fix for PF mailbox receving unknown message Date: Fri, 25 May 2018 19:43:00 +0100 Message-ID: <20180525184307.36288-6-salil.mehta@huawei.com> X-Mailer: git-send-email 2.8.3 In-Reply-To: <20180525184307.36288-1-salil.mehta@huawei.com> References: <20180525184307.36288-1-salil.mehta@huawei.com> MIME-Version: 1.0 Content-Type: text/plain 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 PF 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 not empty before reading the message. Fixes: c1a81619d73a ("net: hns3: Add mailbox interrupt handling to PF driver") Signed-off-by: Xi Wang Signed-off-by: Peng Li Signed-off-by: Salil Mehta --- .../net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c | 23 +++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c index b6ae26b..31f3d9a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_mbx.c @@ -382,6 +382,13 @@ static void hclge_reset_vf(struct hclge_vport *vport, hclge_func_reset_cmd(hdev, mbx_req->mbx_src_vfid); } +static bool hclge_cmd_crq_empty(struct hclge_hw *hw) +{ + u32 tail = hclge_read_dev(hw, HCLGE_NIC_CRQ_TAIL_REG); + + return tail == hw->cmq.crq.next_to_use; +} + void hclge_mbx_handler(struct hclge_dev *hdev) { struct hclge_cmq_ring *crq = &hdev->hw.cmq.crq; @@ -390,12 +397,23 @@ void hclge_mbx_handler(struct hclge_dev *hdev) struct hclge_desc *desc; int ret, flag; - flag = le16_to_cpu(crq->desc[crq->next_to_use].flag); /* handle all the mailbox requests in the queue */ - while (hnae_get_bit(flag, HCLGE_CMDQ_RX_OUTVLD_B)) { + while (!hclge_cmd_crq_empty(&hdev->hw)) { desc = &crq->desc[crq->next_to_use]; req = (struct hclge_mbx_vf_to_pf_cmd *)desc->data; + flag = le16_to_cpu(crq->desc[crq->next_to_use].flag); + if (unlikely(!hnae_get_bit(flag, HCLGE_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; + } + vport = &hdev->vport[req->mbx_src_vfid]; switch (req->msg[0]) { @@ -470,7 +488,6 @@ void hclge_mbx_handler(struct hclge_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 */ -- 2.7.4