2022-12-06 06:17:37

by Rao, Lei

[permalink] [raw]
Subject: [RFC PATCH 4/5] nvme-vfio: check if the hardware supports live migration

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 <[email protected]>
Signed-off-by: Yadong Li <[email protected]>
Signed-off-by: Chaitanya Kulkarni <[email protected]>
Reviewed-by: Eddie Dong <[email protected]>
Reviewed-by: Hang Yuan <[email protected]>
---
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


2022-12-06 14:24:26

by Keith Busch

[permalink] [raw]
Subject: Re: [RFC PATCH 4/5] nvme-vfio: check if the hardware supports live migration

On Tue, Dec 06, 2022 at 01:58:15PM +0800, Lei Rao wrote:
> +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];

Considering this is a vendor specific region, it seems rather presumptuous to
assume this byte means "live migration supported".