[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221206055816.292304-5-lei.rao@intel.com>
Date: Tue, 6 Dec 2022 13:58:15 +0800
From: Lei Rao <lei.rao@...el.com>
To: kbusch@...nel.org, axboe@...com, kch@...dia.com, hch@....de,
sagi@...mberg.me, alex.williamson@...hat.com, cohuck@...hat.com,
jgg@...pe.ca, yishaih@...dia.com,
shameerali.kolothum.thodi@...wei.com, kevin.tian@...el.com,
mjrosato@...ux.ibm.com, linux-kernel@...r.kernel.org,
linux-nvme@...ts.infradead.org, kvm@...r.kernel.org
Cc: eddie.dong@...el.com, yadong.li@...el.com, yi.l.liu@...el.com,
Konrad.wilk@...cle.com, stephen@...eticom.com, hang.yuan@...el.com,
Lei Rao <lei.rao@...el.com>
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 <lei.rao@...el.com>
Signed-off-by: Yadong Li <yadong.li@...el.com>
Signed-off-by: Chaitanya Kulkarni <kch@...dia.com>
Reviewed-by: Eddie Dong <eddie.dong@...el.com>
Reviewed-by: Hang Yuan <hang.yuan@...el.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
Powered by blists - more mailing lists