From nobody Fri Dec 19 03:17:26 2025 Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190]) (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 5E9241FCF74; Thu, 13 Mar 2025 07:22:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.190 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741850575; cv=none; b=JVczzna1k4b7Z2Zj9xP45Jf0/exa04w4AYNSuz325yrqVb4OsLi5EtfcuVLBE0UKsnvNbgoQyrmRjFunLRx1/3wRuEe+XNuJhSo9dU/EhG1HFySX42OnXrxsqZQ+SsL5caJ7SRJaq2et+FOr3Y8Gq1SJghwXvchcQ38qFqxAj/g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1741850575; c=relaxed/simple; bh=MdOGDK+6pHLRWCUrvTLmjR3vj8SHXrPceHACVI50xXs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fMBsgPGOoQnjFnjmsU2xESCv2+IQFyWPMORPer3zGAk3n4GglU7E0CcGwFA2GVo4Tq0x3H+vNGVJ2kphHJNTyPiLHYduE88lPJv2puBc7i4x+5haMOmRlBlMvEyUptGnhfQgyBPoG1+pr0YQ3Z67D9sfJKtW7Te3xMEGSjg7rfo= 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.190 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.88.163]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4ZCzPG1hFKz2RTXC; Thu, 13 Mar 2025 15:18:26 +0800 (CST) Received: from kwepemg500006.china.huawei.com (unknown [7.202.181.43]) by mail.maildlp.com (Postfix) with ESMTPS id E1341180069; Thu, 13 Mar 2025 15:22:48 +0800 (CST) Received: from huawei.com (10.50.165.33) by kwepemg500006.china.huawei.com (7.202.181.43) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 13 Mar 2025 15:22:48 +0800 From: Longfang Liu To: , , , CC: , , , Subject: [PATCH v5 5/5] hisi_acc_vfio_pci: bugfix live migration function without VF device driver Date: Thu, 13 Mar 2025 15:20:10 +0800 Message-ID: <20250313072010.57199-6-liulongfang@huawei.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20250313072010.57199-1-liulongfang@huawei.com> References: <20250313072010.57199-1-liulongfang@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemg500006.china.huawei.com (7.202.181.43) Content-Type: text/plain; charset="utf-8" If the VF device driver is not loaded in the Guest OS and we attempt to perform device data migration, the address of the migrated data will be NULL. The live migration recovery operation on the destination side will access a null address value, which will cause access errors. Therefore, live migration of VMs without added VF device drivers does not require device data migration. In addition, when the queue address data obtained by the destination is empty, device queue recovery processing will not be performed. Fixes: b0eed085903e ("hisi_acc_vfio_pci: Add support for VFIO live migratio= n") Signed-off-by: Longfang Liu Reviewed-by: Shameer Kolothum --- .../vfio/pci/hisilicon/hisi_acc_vfio_pci.c | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c b/drivers/vfio/= pci/hisilicon/hisi_acc_vfio_pci.c index cadc82419dca..44fa2d16bbcc 100644 --- a/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c +++ b/drivers/vfio/pci/hisilicon/hisi_acc_vfio_pci.c @@ -426,13 +426,6 @@ static int vf_qm_check_match(struct hisi_acc_vf_core_d= evice *hisi_acc_vdev, return -EINVAL; } =20 - ret =3D qm_write_regs(vf_qm, QM_VF_STATE, &vf_data->vf_qm_state, 1); - if (ret) { - dev_err(dev, "failed to write QM_VF_STATE\n"); - return ret; - } - - hisi_acc_vdev->vf_qm_state =3D vf_data->vf_qm_state; hisi_acc_vdev->match_done =3D true; return 0; } @@ -498,6 +491,13 @@ static int vf_qm_load_data(struct hisi_acc_vf_core_dev= ice *hisi_acc_vdev, if (migf->total_length < sizeof(struct acc_vf_data)) return -EINVAL; =20 + ret =3D qm_write_regs(qm, QM_VF_STATE, &vf_data->vf_qm_state, 1); + if (ret) { + dev_err(dev, "failed to write QM_VF_STATE\n"); + return -EINVAL; + } + hisi_acc_vdev->vf_qm_state =3D vf_data->vf_qm_state; + qm->eqe_dma =3D vf_data->eqe_dma; qm->aeqe_dma =3D vf_data->aeqe_dma; qm->sqc_dma =3D vf_data->sqc_dma; @@ -506,6 +506,12 @@ static int vf_qm_load_data(struct hisi_acc_vf_core_dev= ice *hisi_acc_vdev, qm->qp_base =3D vf_data->qp_base; qm->qp_num =3D vf_data->qp_num; =20 + if (!vf_data->eqe_dma || !vf_data->aeqe_dma || + !vf_data->sqc_dma || !vf_data->cqc_dma) { + dev_err(dev, "resume dma addr is NULL!\n"); + return -EINVAL; + } + ret =3D qm_set_regs(qm, vf_data); if (ret) { dev_err(dev, "set VF regs failed\n"); @@ -726,8 +732,12 @@ static int hisi_acc_vf_load_state(struct hisi_acc_vf_c= ore_device *hisi_acc_vdev) { struct device *dev =3D &hisi_acc_vdev->vf_dev->dev; struct hisi_acc_vf_migration_file *migf =3D hisi_acc_vdev->resuming_migf; + struct acc_vf_data *vf_data =3D &migf->vf_data; int ret; =20 + if (vf_data->vf_qm_state !=3D QM_READY) + return 0; + /* Recover data to VF */ ret =3D vf_qm_load_data(hisi_acc_vdev, migf); if (ret) { @@ -1531,6 +1541,7 @@ static int hisi_acc_vfio_pci_migrn_init_dev(struct vf= io_device *core_vdev) hisi_acc_vdev->vf_id =3D pci_iov_vf_id(pdev) + 1; hisi_acc_vdev->pf_qm =3D pf_qm; hisi_acc_vdev->vf_dev =3D pdev; + hisi_acc_vdev->vf_qm_state =3D QM_NOT_READY; mutex_init(&hisi_acc_vdev->state_mutex); mutex_init(&hisi_acc_vdev->open_mutex); =20 --=20 2.24.0