LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Salil Mehta <salil.mehta@huawei.com>
To: <davem@davemloft.net>
Cc: <salil.mehta@huawei.com>, <yisen.zhuang@huawei.com>,
	<lipeng321@huawei.com>, <mehta.salil.lnk@gmail.com>,
	<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<linuxarm@huawei.com>, Huazhong Tan <tanhuazhong@huawei.com>
Subject: [PATCH net-next 7/9] net: hns3: fix a dead loop in hclge_cmd_csq_clean
Date: Tue, 1 May 2018 19:56:03 +0100	[thread overview]
Message-ID: <20180501185605.9584-8-salil.mehta@huawei.com> (raw)
In-Reply-To: <20180501185605.9584-1-salil.mehta@huawei.com>

From: Huazhong Tan <tanhuazhong@huawei.com>

If head has invlid value then a dead loop can be triggered in
hclge_cmd_csq_clean. This patch adds sanity check for this case.

Fixes: 68c0a5c70614 ("net: hns3: Add HNS3 IMP(Integrated Mgmt Proc) Cmd
Interface Support")
Signed-off-by: Huazhong Tan <tanhuazhong@huawei.com>
Signed-off-by: Peng Li <lipeng321@huawei.com>
Signed-off-by: Salil Mehta <salil.mehta@huawei.com>
---
 .../net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
index ff13d18..fab7068 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_cmd.c
@@ -31,6 +31,17 @@ static int hclge_ring_space(struct hclge_cmq_ring *ring)
 	return ring->desc_num - used - 1;
 }
 
+static int is_valid_csq_clean_head(struct hclge_cmq_ring *ring, int h)
+{
+	int u = ring->next_to_use;
+	int c = ring->next_to_clean;
+
+	if (unlikely(h >= ring->desc_num))
+		return 0;
+
+	return u > c ? (h > c && h <= u) : (h > c || h <= u);
+}
+
 static int hclge_alloc_cmd_desc(struct hclge_cmq_ring *ring)
 {
 	int size  = ring->desc_num * sizeof(struct hclge_desc);
@@ -141,6 +152,7 @@ static void hclge_cmd_init_regs(struct hclge_hw *hw)
 
 static int hclge_cmd_csq_clean(struct hclge_hw *hw)
 {
+	struct hclge_dev *hdev = (struct hclge_dev *)hw->back;
 	struct hclge_cmq_ring *csq = &hw->cmq.csq;
 	u16 ntc = csq->next_to_clean;
 	struct hclge_desc *desc;
@@ -149,6 +161,13 @@ static int hclge_cmd_csq_clean(struct hclge_hw *hw)
 
 	desc = &csq->desc[ntc];
 	head = hclge_read_dev(hw, HCLGE_NIC_CSQ_HEAD_REG);
+	rmb(); /* Make sure head is ready before touch any data */
+
+	if (!is_valid_csq_clean_head(csq, head)) {
+		dev_warn(&hdev->pdev->dev, "wrong head (%d, %d-%d)\n", head,
+			   csq->next_to_use, csq->next_to_clean);
+		return 0;
+	}
 
 	while (head != ntc) {
 		memset(desc, 0, sizeof(*desc));
-- 
2.7.4

  parent reply	other threads:[~2018-05-01 18:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-05-01 18:55 [PATCH net-next 0/9] Misc bug fixes for HNS3 Ethernet driver Salil Mehta
2018-05-01 18:55 ` [PATCH net-next 1/9] net: hns3: Remove error log when getting pfc stats fails Salil Mehta
2018-05-01 18:55 ` [PATCH net-next 2/9] net: hns3: fix to correctly fetch l4 protocol outer header Salil Mehta
2018-05-01 18:55 ` [PATCH net-next 3/9] net: hns3: Fixes the out of bounds access in hclge_map_tqp Salil Mehta
2018-05-01 18:56 ` [PATCH net-next 4/9] net: hns3: Fixes the error legs in hclge_init_ae_dev function Salil Mehta
2018-05-01 18:56 ` [PATCH net-next 5/9] net: hns3: fix for phy_addr error in hclge_mac_mdio_config Salil Mehta
2018-05-01 18:56 ` [PATCH net-next 6/9] net: hns3: Fix to support autoneg only for port attached with phy Salil Mehta
2018-05-01 18:56 ` Salil Mehta [this message]
2018-05-01 18:56 ` [PATCH net-next 8/9] net: hns3: Fix for packet loss due wrong filter config in VLAN tbls Salil Mehta
2018-05-01 18:56 ` [PATCH net-next 9/9] net: hns3: Remove packet statistics in the range of 8192~12287 Salil Mehta
2018-05-01 19:08 ` [PATCH net-next 0/9] Misc bug fixes for HNS3 Ethernet driver David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180501185605.9584-8-salil.mehta@huawei.com \
    --to=salil.mehta@huawei.com \
    --cc=davem@davemloft.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxarm@huawei.com \
    --cc=lipeng321@huawei.com \
    --cc=mehta.salil.lnk@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=tanhuazhong@huawei.com \
    --cc=yisen.zhuang@huawei.com \
    --subject='Re: [PATCH net-next 7/9] net: hns3: fix a dead loop in hclge_cmd_csq_clean' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).