QEMU-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Kirti Wankhede <kwankhede@nvidia.com>
Cc: Zhengxiao.zx@alibaba-inc.com, kevin.tian@intel.com,
	yi.l.liu@intel.com, cjia@nvidia.com, eskultet@redhat.com,
	ziye.yang@intel.com, cohuck@redhat.com,
	shuangtai.tst@alibaba-inc.com, qemu-devel@nongnu.org,
	zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com,
	aik@ozlabs.ru, alex.williamson@redhat.com, eauger@redhat.com,
	felipe@nutanix.com, jonathan.davies@nutanix.com,
	yan.y.zhao@intel.com, changpeng.liu@intel.com, Ken.Xue@amd.com
Subject: Re: [PATCH v16 QEMU 05/16] vfio: Add migration region initialization and finalize function
Date: Tue, 19 May 2020 20:32:35 +0100
Message-ID: <20200519193235.GA20699@work-vm> (raw)
In-Reply-To: <d0347049-59d9-87d5-acb1-e56b56acc6b9@nvidia.com>

* Kirti Wankhede (kwankhede@nvidia.com) wrote:
> 
> 
> On 3/26/2020 11:22 PM, Dr. David Alan Gilbert wrote:
> > * Kirti Wankhede (kwankhede@nvidia.com) wrote:
> > > - Migration functions are implemented for VFIO_DEVICE_TYPE_PCI device in this
> > >    patch series.
> > > - VFIO device supports migration or not is decided based of migration region
> > >    query. If migration region query is successful and migration region
> > >    initialization is successful then migration is supported else migration is
> > >    blocked.
> > > 
> > > Signed-off-by: Kirti Wankhede <kwankhede@nvidia.com>
> > > Reviewed-by: Neo Jia <cjia@nvidia.com>
> > > ---
> > >   hw/vfio/Makefile.objs         |   2 +-
> > >   hw/vfio/migration.c           | 138 ++++++++++++++++++++++++++++++++++++++++++
> > >   hw/vfio/trace-events          |   3 +
> > >   include/hw/vfio/vfio-common.h |   9 +++
> > >   4 files changed, 151 insertions(+), 1 deletion(-)
> > >   create mode 100644 hw/vfio/migration.c
> > > 
> > > diff --git a/hw/vfio/Makefile.objs b/hw/vfio/Makefile.objs
> > > index 9bb1c09e8477..8b296c889ed9 100644
> > > --- a/hw/vfio/Makefile.objs
> > > +++ b/hw/vfio/Makefile.objs
> > > @@ -1,4 +1,4 @@
> > > -obj-y += common.o spapr.o
> > > +obj-y += common.o spapr.o migration.o
> > >   obj-$(CONFIG_VFIO_PCI) += pci.o pci-quirks.o display.o
> > >   obj-$(CONFIG_VFIO_CCW) += ccw.o
> > >   obj-$(CONFIG_VFIO_PLATFORM) += platform.o
> > > diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c
> > > new file mode 100644
> > > index 000000000000..a078dcf1dd8f
> > > --- /dev/null
> > > +++ b/hw/vfio/migration.c
> > > @@ -0,0 +1,138 @@
> > > +/*
> > > + * Migration support for VFIO devices
> > > + *
> > > + * Copyright NVIDIA, Inc. 2019
> > 
> > Time flies by...
> > 
> > > + *
> > > + * This work is licensed under the terms of the GNU GPL, version 2. See
> > > + * the COPYING file in the top-level directory.
> > 
> > Are you sure you want this to be V2 only? Most code added to qemu now is
> > v2 or later.
> > 
> 
> I kept it same as in files vfio-pci and hw/vfio/common.c
> 
> Should it be different? Can you give some reference what it should be?

It's OK to be v2; there's a statement in LICENSE saying hw/vfio is
acceptable for that; most other new code we try and make
'version 2 or later' - if you want it as 2 that is fine though.

Dave

> Thanks,
> Kirti
> 
> > > + */
> > > +
> > > +#include "qemu/osdep.h"
> > > +#include <linux/vfio.h>
> > > +
> > > +#include "hw/vfio/vfio-common.h"
> > > +#include "cpu.h"
> > > +#include "migration/migration.h"
> > > +#include "migration/qemu-file.h"
> > > +#include "migration/register.h"
> > > +#include "migration/blocker.h"
> > > +#include "migration/misc.h"
> > > +#include "qapi/error.h"
> > > +#include "exec/ramlist.h"
> > > +#include "exec/ram_addr.h"
> > > +#include "pci.h"
> > > +#include "trace.h"
> > > +
> > > +static void vfio_migration_region_exit(VFIODevice *vbasedev)
> > > +{
> > > +    VFIOMigration *migration = vbasedev->migration;
> > > +
> > > +    if (!migration) {
> > > +        return;
> > > +    }
> > > +
> > > +    if (migration->region.size) {
> > > +        vfio_region_exit(&migration->region);
> > > +        vfio_region_finalize(&migration->region);
> > > +    }
> > > +}
> > > +
> > > +static int vfio_migration_region_init(VFIODevice *vbasedev, int index)
> > > +{
> > > +    VFIOMigration *migration = vbasedev->migration;
> > > +    Object *obj = NULL;
> > > +    int ret = -EINVAL;
> > > +
> > > +    if (!vbasedev->ops->vfio_get_object) {
> > > +        return ret;
> > > +    }
> > > +
> > > +    obj = vbasedev->ops->vfio_get_object(vbasedev);
> > > +    if (!obj) {
> > > +        return ret;
> > > +    }
> > > +
> > > +    ret = vfio_region_setup(obj, vbasedev, &migration->region, index,
> > > +                            "migration");
> > > +    if (ret) {
> > > +        error_report("%s: Failed to setup VFIO migration region %d: %s",
> > > +                     vbasedev->name, index, strerror(-ret));
> > > +        goto err;
> > > +    }
> > > +
> > > +    if (!migration->region.size) {
> > > +        ret = -EINVAL;
> > > +        error_report("%s: Invalid region size of VFIO migration region %d: %s",
> > > +                     vbasedev->name, index, strerror(-ret));
> > > +        goto err;
> > > +    }
> > > +
> > > +    return 0;
> > > +
> > > +err:
> > > +    vfio_migration_region_exit(vbasedev);
> > > +    return ret;
> > > +}
> > > +
> > > +static int vfio_migration_init(VFIODevice *vbasedev,
> > > +                               struct vfio_region_info *info)
> > > +{
> > > +    int ret;
> > > +
> > > +    vbasedev->migration = g_new0(VFIOMigration, 1);
> > > +
> > > +    ret = vfio_migration_region_init(vbasedev, info->index);
> > > +    if (ret) {
> > > +        error_report("%s: Failed to initialise migration region",
> > > +                     vbasedev->name);
> > > +        g_free(vbasedev->migration);
> > > +        vbasedev->migration = NULL;
> > > +        return ret;
> > > +    }
> > > +
> > > +    return 0;
> > > +}
> > > +
> > > +/* ---------------------------------------------------------------------- */
> > > +
> > > +int vfio_migration_probe(VFIODevice *vbasedev, Error **errp)
> > > +{
> > > +    struct vfio_region_info *info;
> > > +    Error *local_err = NULL;
> > > +    int ret;
> > > +
> > > +    ret = vfio_get_dev_region_info(vbasedev, VFIO_REGION_TYPE_MIGRATION,
> > > +                                   VFIO_REGION_SUBTYPE_MIGRATION, &info);
> > > +    if (ret) {
> > > +        goto add_blocker;
> > > +    }
> > > +
> > > +    ret = vfio_migration_init(vbasedev, info);
> > > +    if (ret) {
> > > +        goto add_blocker;
> > > +    }
> > > +
> > > +    trace_vfio_migration_probe(vbasedev->name, info->index);
> > > +    return 0;
> > > +
> > > +add_blocker:
> > > +    error_setg(&vbasedev->migration_blocker,
> > > +               "VFIO device doesn't support migration");
> > > +    ret = migrate_add_blocker(vbasedev->migration_blocker, &local_err);
> > > +    if (local_err) {
> > > +        error_propagate(errp, local_err);
> > > +        error_free(vbasedev->migration_blocker);
> > > +    }
> > > +    return ret;
> > > +}
> > > +
> > > +void vfio_migration_finalize(VFIODevice *vbasedev)
> > > +{
> > > +    if (vbasedev->migration_blocker) {
> > > +        migrate_del_blocker(vbasedev->migration_blocker);
> > > +        error_free(vbasedev->migration_blocker);
> > > +    }
> > > +
> > > +    vfio_migration_region_exit(vbasedev);
> > > +    g_free(vbasedev->migration);
> > > +}
> > > diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
> > > index 8cdc27946cb8..191a726a1312 100644
> > > --- a/hw/vfio/trace-events
> > > +++ b/hw/vfio/trace-events
> > > @@ -143,3 +143,6 @@ vfio_display_edid_link_up(void) ""
> > >   vfio_display_edid_link_down(void) ""
> > >   vfio_display_edid_update(uint32_t prefx, uint32_t prefy) "%ux%u"
> > >   vfio_display_edid_write_error(void) ""
> > > +
> > > +# migration.c
> > > +vfio_migration_probe(char *name, uint32_t index) " (%s) Region %d"
> > > diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
> > > index d69a7f3ae31e..d4b268641173 100644
> > > --- a/include/hw/vfio/vfio-common.h
> > > +++ b/include/hw/vfio/vfio-common.h
> > > @@ -57,6 +57,10 @@ typedef struct VFIORegion {
> > >       uint8_t nr; /* cache the region number for debug */
> > >   } VFIORegion;
> > > +typedef struct VFIOMigration {
> > > +    VFIORegion region;
> > > +} VFIOMigration;
> > > +
> > >   typedef struct VFIOAddressSpace {
> > >       AddressSpace *as;
> > >       QLIST_HEAD(, VFIOContainer) containers;
> > > @@ -113,6 +117,8 @@ typedef struct VFIODevice {
> > >       unsigned int num_irqs;
> > >       unsigned int num_regions;
> > >       unsigned int flags;
> > > +    VFIOMigration *migration;
> > > +    Error *migration_blocker;
> > >   } VFIODevice;
> > >   struct VFIODeviceOps {
> > > @@ -204,4 +210,7 @@ int vfio_spapr_create_window(VFIOContainer *container,
> > >   int vfio_spapr_remove_window(VFIOContainer *container,
> > >                                hwaddr offset_within_address_space);
> > > +int vfio_migration_probe(VFIODevice *vbasedev, Error **errp);
> > > +void vfio_migration_finalize(VFIODevice *vbasedev);
> > > +
> > >   #endif /* HW_VFIO_VFIO_COMMON_H */
> > > -- 
> > > 2.7.0
> > > 
> > --
> > Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
> > 
> 
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply index

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-24 21:08 [PATCH v16 QEMU 00/16] Add migration support for VFIO devices Kirti Wankhede
2020-03-24 21:08 ` [PATCH v16 QEMU 01/16] vfio: KABI for migration interface - Kernel header placeholder Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 02/16] vfio: Add function to unmap VFIO region Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 03/16] vfio: Add vfio_get_object callback to VFIODeviceOps Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 04/16] vfio: Add save and load functions for VFIO PCI devices Kirti Wankhede
2020-03-25 19:56   ` Alex Williamson
2020-03-26 17:29     ` Dr. David Alan Gilbert
2020-03-26 17:38       ` Alex Williamson
2020-05-04 23:18     ` Kirti Wankhede
2020-05-05  4:37       ` Alex Williamson
2020-05-06  6:11         ` Yan Zhao
2020-05-06 19:48           ` Kirti Wankhede
2020-05-06 20:03             ` Alex Williamson
2020-05-07  5:40               ` Kirti Wankhede
2020-05-07 18:14                 ` Alex Williamson
2020-03-26 17:46   ` Dr. David Alan Gilbert
2020-05-04 23:19     ` Kirti Wankhede
2020-04-07  4:10   ` Longpeng (Mike, Cloud Infrastructure Service Product Dept.)
2020-05-04 23:21     ` Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 05/16] vfio: Add migration region initialization and finalize function Kirti Wankhede
2020-03-26 17:52   ` Dr. David Alan Gilbert
2020-05-04 23:19     ` Kirti Wankhede
2020-05-19 19:32       ` Dr. David Alan Gilbert [this message]
2020-03-24 21:09 ` [PATCH v16 QEMU 06/16] vfio: Add VM state change handler to know state of VM Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 07/16] vfio: Add migration state change notifier Kirti Wankhede
2020-04-01 11:27   ` Dr. David Alan Gilbert
2020-05-04 23:20     ` Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 08/16] vfio: Register SaveVMHandlers for VFIO device Kirti Wankhede
2020-03-25 21:02   ` Alex Williamson
2020-05-04 23:19     ` Kirti Wankhede
2020-05-05  4:37       ` Alex Williamson
2020-05-06  6:38         ` Yan Zhao
2020-05-06  9:58           ` Cornelia Huck
2020-05-06 16:53             ` Dr. David Alan Gilbert
2020-05-06 19:30               ` Kirti Wankhede
2020-05-07  6:37                 ` Cornelia Huck
2020-05-07 20:29                 ` Alex Williamson
2020-04-01 17:36   ` Dr. David Alan Gilbert
2020-05-04 23:20     ` Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 09/16] vfio: Add save state functions to SaveVMHandlers Kirti Wankhede
2020-03-25 22:03   ` Alex Williamson
2020-05-04 23:18     ` Kirti Wankhede
2020-05-05  4:37       ` Alex Williamson
2020-05-11  9:53         ` Kirti Wankhede
2020-05-11 15:59           ` Alex Williamson
2020-05-12  2:06           ` Yan Zhao
2020-05-09  5:31   ` Yan Zhao
2020-05-11 10:22     ` Kirti Wankhede
2020-05-12  0:50       ` Yan Zhao
2020-03-24 21:09 ` [PATCH v16 QEMU 10/16] vfio: Add load " Kirti Wankhede
2020-03-25 22:36   ` Alex Williamson
2020-04-01 18:58   ` Dr. David Alan Gilbert
2020-05-04 23:20     ` Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 11/16] iommu: add callback to get address limit IOMMU supports Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 12/16] memory: Set DIRTY_MEMORY_MIGRATION when IOMMU is enabled Kirti Wankhede
2020-04-01 19:00   ` Dr. David Alan Gilbert
2020-04-01 19:42     ` Alex Williamson
2020-03-24 21:09 ` [PATCH v16 QEMU 13/16] vfio: Add function to start and stop dirty pages tracking Kirti Wankhede
2020-03-26 19:10   ` Alex Williamson
2020-05-04 23:20     ` Kirti Wankhede
2020-04-01 19:03   ` Dr. David Alan Gilbert
2020-05-04 23:21     ` Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 14/16] vfio: Add vfio_listener_log_sync to mark dirty pages Kirti Wankhede
2020-03-25  2:19   ` Yan Zhao
2020-03-26 19:46   ` Alex Williamson
2020-04-01 19:08     ` Dr. David Alan Gilbert
2020-04-01  5:50   ` Yan Zhao
2020-04-03 20:11     ` Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 15/16] vfio: Add ioctl to get dirty pages bitmap during dma unmap Kirti Wankhede
2020-03-24 21:09 ` [PATCH v16 QEMU 16/16] vfio: Make vfio-pci device migration capable Kirti Wankhede
2020-03-24 23:36 ` [PATCH v16 QEMU 00/16] Add migration support for VFIO devices no-reply
2020-03-31 18:34 ` Alex Williamson
2020-04-01  6:41   ` Yan Zhao
2020-04-01 18:34     ` Alex Williamson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200519193235.GA20699@work-vm \
    --to=dgilbert@redhat.com \
    --cc=Ken.Xue@amd.com \
    --cc=Zhengxiao.zx@alibaba-inc.com \
    --cc=aik@ozlabs.ru \
    --cc=alex.williamson@redhat.com \
    --cc=changpeng.liu@intel.com \
    --cc=cjia@nvidia.com \
    --cc=cohuck@redhat.com \
    --cc=eauger@redhat.com \
    --cc=eskultet@redhat.com \
    --cc=felipe@nutanix.com \
    --cc=jonathan.davies@nutanix.com \
    --cc=kevin.tian@intel.com \
    --cc=kwankhede@nvidia.com \
    --cc=mlevitsk@redhat.com \
    --cc=pasic@linux.ibm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=shuangtai.tst@alibaba-inc.com \
    --cc=yan.y.zhao@intel.com \
    --cc=yi.l.liu@intel.com \
    --cc=zhi.a.wang@intel.com \
    --cc=ziye.yang@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

QEMU-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/qemu-devel/0 qemu-devel/git/0.git
	git clone --mirror https://lore.kernel.org/qemu-devel/1 qemu-devel/git/1.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 qemu-devel qemu-devel/ https://lore.kernel.org/qemu-devel \
		qemu-devel@nongnu.org
	public-inbox-index qemu-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.nongnu.qemu-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git