Skip to content

Commit

Permalink
net: hns3: fix kernel crash when devlink reload during initialization
Browse files Browse the repository at this point in the history
The devlink reload process will access the hardware resources,
but the register operation is done before the hardware is initialized.
So, processing the devlink reload during initialization may lead to kernel
crash.

This patch fixes this by registering the devlink after
hardware initialization.

Fixes: cd62429 ("net: hns3: add support for registering devlink for VF")
Fixes: 93305b7 ("net: hns3: fix kernel crash when devlink reload during pf initialization")
Signed-off-by: Yonglong Liu <liuyonglong@huawei.com>
Signed-off-by: Jijie Shao <shaojijie@huawei.com>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
  • Loading branch information
Yonglong Liu authored and Paolo Abeni committed May 9, 2024
1 parent f5db7a3 commit 35d92ab
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 18 deletions.
17 changes: 5 additions & 12 deletions drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -11631,16 +11631,10 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
if (ret)
goto out;

ret = hclge_devlink_init(hdev);
if (ret)
goto err_pci_uninit;

devl_lock(hdev->devlink);

/* Firmware command queue initialize */
ret = hclge_comm_cmd_queue_init(hdev->pdev, &hdev->hw.hw);
if (ret)
goto err_devlink_uninit;
goto err_pci_uninit;

/* Firmware command initialize */
ret = hclge_comm_cmd_init(hdev->ae_dev, &hdev->hw.hw, &hdev->fw_version,
Expand Down Expand Up @@ -11808,15 +11802,17 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
dev_warn(&pdev->dev,
"failed to wake on lan init, ret = %d\n", ret);

ret = hclge_devlink_init(hdev);
if (ret)
goto err_ptp_uninit;

hclge_state_init(hdev);
hdev->last_reset_time = jiffies;

dev_info(&hdev->pdev->dev, "%s driver initialization finished.\n",
HCLGE_DRIVER_NAME);

hclge_task_schedule(hdev, round_jiffies_relative(HZ));

devl_unlock(hdev->devlink);
return 0;

err_ptp_uninit:
Expand All @@ -11830,9 +11826,6 @@ static int hclge_init_ae_dev(struct hnae3_ae_dev *ae_dev)
pci_free_irq_vectors(pdev);
err_cmd_uninit:
hclge_comm_cmd_uninit(hdev->ae_dev, &hdev->hw.hw);
err_devlink_uninit:
devl_unlock(hdev->devlink);
hclge_devlink_uninit(hdev);
err_pci_uninit:
pcim_iounmap(pdev, hdev->hw.hw.io_base);
pci_release_regions(pdev);
Expand Down
10 changes: 4 additions & 6 deletions drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2845,10 +2845,6 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
if (ret)
return ret;

ret = hclgevf_devlink_init(hdev);
if (ret)
goto err_devlink_init;

ret = hclge_comm_cmd_queue_init(hdev->pdev, &hdev->hw.hw);
if (ret)
goto err_cmd_queue_init;
Expand Down Expand Up @@ -2941,6 +2937,10 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)

hclgevf_init_rxd_adv_layout(hdev);

ret = hclgevf_devlink_init(hdev);
if (ret)
goto err_config;

set_bit(HCLGEVF_STATE_SERVICE_INITED, &hdev->state);

hdev->last_reset_time = jiffies;
Expand All @@ -2960,8 +2960,6 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev)
err_cmd_init:
hclge_comm_cmd_uninit(hdev->ae_dev, &hdev->hw.hw);
err_cmd_queue_init:
hclgevf_devlink_uninit(hdev);
err_devlink_init:
hclgevf_pci_uninit(hdev);
clear_bit(HCLGEVF_STATE_IRQ_INITED, &hdev->state);
return ret;
Expand Down

0 comments on commit 35d92ab

Please sign in to comment.