From patchwork Mon Apr 22 13:43:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jijie Shao X-Patchwork-Id: 13638545 X-Patchwork-Delegate: kuba@kernel.org Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E12B21514E2; Mon, 22 Apr 2024 13:50:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.188 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713793802; cv=none; b=tCYjc/e1oDSIVwGEoU1msrXCWLb4x5p72aeeFkGmbTFuGRbAc7MeqR6aQ8xuU0dV3YZKAFzUjfOpnd6OIsUsY3E/QYrT1M9A2CHNl+k/H5gL5qeZi4EL9naYQjDKXI6pqw+UevFBSlDaTPfrbZRtWRXDVxv75JDZLv4Yep3IM4w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713793802; c=relaxed/simple; bh=5yvgi9mrQAF3qOurmIWeU5dX0slS7fJ6ldV2mGba9Lc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JzU4BxWJr2Xsk/4KtjelO975nY3TXsDDD5hk82jQb39wwckjmIsbGqJiASlemakL/KbLfm40RL0Hw+rDQfg/UXbwcxHTMeK/cKCXVLimvDzVtET6rTMy8eCfuQgK+sjOmQkQl1pj94EK977IIcP8MrT01gbVrJatluJLjNns5NA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4VNRNy5vlqzXmCw; Mon, 22 Apr 2024 21:46:26 +0800 (CST) Received: from kwepemm600007.china.huawei.com (unknown [7.193.23.208]) by mail.maildlp.com (Postfix) with ESMTPS id 6D5F318007D; Mon, 22 Apr 2024 21:49:53 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemm600007.china.huawei.com (7.193.23.208) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Mon, 22 Apr 2024 21:49:52 +0800 From: Jijie Shao To: , , , , , CC: , , , , , , Subject: [PATCH net 7/7] net: hns3: fix kernel crash when devlink reload during vf initialization Date: Mon, 22 Apr 2024 21:43:27 +0800 Message-ID: <20240422134327.3160587-8-shaojijie@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240422134327.3160587-1-shaojijie@huawei.com> References: <20240422134327.3160587-1-shaojijie@huawei.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemm600007.china.huawei.com (7.193.23.208) X-Patchwork-Delegate: kuba@kernel.org From: Yonglong Liu 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 taking devl_lock during initialization. Fixes: cd6242991d2e ("net: hns3: add support for registering devlink for VF") Signed-off-by: Yonglong Liu Signed-off-by: Jijie Shao --- drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c index 08db8e84be4e..3ee41943d15f 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_main.c @@ -2849,6 +2849,8 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev) if (ret) goto err_devlink_init; + devl_lock(hdev->devlink); + ret = hclge_comm_cmd_queue_init(hdev->pdev, &hdev->hw.hw); if (ret) goto err_cmd_queue_init; @@ -2950,6 +2952,7 @@ static int hclgevf_init_hdev(struct hclgevf_dev *hdev) hclgevf_task_schedule(hdev, round_jiffies_relative(HZ)); timer_setup(&hdev->reset_timer, hclgevf_reset_timer, 0); + devl_unlock(hdev->devlink); return 0; err_config: @@ -2960,6 +2963,7 @@ 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: + devl_unlock(hdev->devlink); hclgevf_devlink_uninit(hdev); err_devlink_init: hclgevf_pci_uninit(hdev);