[RFC PATCH 4/5] nvme-vfio: check if the hardware supports live migration
Lei Rao
lei.rao at intel.com
Mon Dec 5 21:58:15 PST 2022
NVMe device can extend the vendor-specific field in the identify
controller data structure to indicate whether live migration
is supported. This patch checks if the NVMe device supports
live migration.
Signed-off-by: Lei Rao <lei.rao at intel.com>
Signed-off-by: Yadong Li <yadong.li at intel.com>
Signed-off-by: Chaitanya Kulkarni <kch at nvidia.com>
Reviewed-by: Eddie Dong <eddie.dong at intel.com>
Reviewed-by: Hang Yuan <hang.yuan at intel.com>
---
drivers/vfio/pci/nvme/nvme.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/vfio/pci/nvme/nvme.c b/drivers/vfio/pci/nvme/nvme.c
index 698e470a4e53..2ffc90ad556d 100644
--- a/drivers/vfio/pci/nvme/nvme.c
+++ b/drivers/vfio/pci/nvme/nvme.c
@@ -473,6 +473,36 @@ static void nvmevf_pci_close_device(struct vfio_device *core_vdev)
vfio_pci_core_close_device(core_vdev);
}
+static bool nvmevf_check_migration(struct pci_dev *pdev)
+{
+ struct nvme_command c = { };
+ struct nvme_id_ctrl *id;
+ u8 live_mig_support;
+ int ret;
+
+ c.identify.opcode = nvme_admin_identify;
+ c.identify.cns = NVME_ID_CNS_CTRL;
+
+ id = kmalloc(sizeof(struct nvme_id_ctrl), GFP_KERNEL);
+ if (!id)
+ return false;
+
+ ret = nvme_submit_vf_cmd(pdev, &c, NULL, id, sizeof(struct nvme_id_ctrl));
+ if (ret) {
+ dev_warn(&pdev->dev, "Get identify ctrl failed (ret=0x%x)\n", ret);
+ goto out;
+ }
+
+ live_mig_support = id->vs[0];
+ if (live_mig_support) {
+ kfree(id);
+ return true;
+ }
+out:
+ kfree(id);
+ return false;
+}
+
static const struct vfio_migration_ops nvmevf_pci_mig_ops = {
.migration_set_state = nvmevf_pci_set_device_state,
.migration_get_state = nvmevf_pci_get_device_state,
@@ -489,6 +519,10 @@ static int nvmevf_migration_init_dev(struct vfio_device *core_vdev)
if (!pdev->is_virtfn)
return ret;
+ /* Get the identify controller data structure to check the live migration support */
+ if (!nvmevf_check_migration(pdev))
+ return ret;
+
nvmevf_dev->migrate_cap = 1;
vf_id = pci_iov_vf_id(pdev);
--
2.34.1
More information about the Linux-nvme
mailing list