[PATCH V3 net 2/3] net: hns3: fix kernel crash when devlink reload during pf initialization

From: Jijie Shao
Date: Mon Mar 18 2024 - 09:53:56 EST


From: Yonglong Liu <liuyonglong@xxxxxxxxxx>

The devlink reload process will access the hardware resources,
but the register operation is done before the hardware is initialized.
so, if process the devlink reload during initialization, may lead to kernel
crash. This patch fixes this by checking whether the NIC is initialized.

Fixes: b741269b2759 ("net: hns3: add support for registering devlink for PF")
Signed-off-by: Yonglong Liu <liuyonglong@xxxxxxxxxx>
Signed-off-by: Jijie Shao <shaojijie@xxxxxxxxxx>
---
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
index 9a939c0b217f..80db4f7b05f6 100644
--- a/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
+++ b/drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_devlink.c
@@ -40,8 +40,9 @@ static int hclge_devlink_reload_down(struct devlink *devlink, bool netns_change,
struct pci_dev *pdev = hdev->pdev;
int ret;

- if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state)) {
- dev_err(&pdev->dev, "reset is handling\n");
+ if (test_bit(HCLGE_STATE_RST_HANDLING, &hdev->state) ||
+ !test_bit(HCLGE_STATE_NIC_REGISTERED, &hdev->state)) {
+ dev_err(&pdev->dev, "reset is handling or driver removed\n");
return -EBUSY;
}

--
2.30.0