From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086250; cv=none; d=zohomail.com; s=zohoarc; b=NJtTBv/CFA6P/RL7dOqC5L3z6gxUyj+diIFaDuoruivjQMsgABETo4lmhLcr2nbxifjD7ztxmuX+cCZckLzzEv8Tg4FP3i7yQmr7huwvUGHfJpfA0ET1Oiqa22gUZMqPqGmGxUk8kSJtvpTjZYwQl4/gSCIiCXfDOkglLsXk9SU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086250; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c3Rwhkunyga+sbGbUgiT6GLjdLh9EeLpvB5+CxEaL8k=; b=DIR8omhSjwDmSn6h7Lrp8BKF+SdEGYrKZRImcjbS1wERTrU2azz9RtP2jJ0yqLZ2tE08aCnY/oeMfeBXzUEP7pay4M9bAJ0knJkb+Sno4FGBxmHtHa2fXbWoG5+xioidL78QLl6TBIpWbe+J4KSQ4qV1juvbeGId3VG43ag3k2I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086250437866.4873972736098; Tue, 24 Mar 2020 14:44:10 -0700 (PDT) Received: from localhost ([::1]:55452 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrLE-0006oI-Tm for importer@patchew.org; Tue, 24 Mar 2020 17:44:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38672) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrK1-0005Fy-FE for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:42:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrJy-0004UE-QD for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:42:53 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6083) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrJy-0004U2-I7 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:42:50 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:42:35 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:42:49 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:42:48 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:42:42 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:42:49 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 01/16] vfio: KABI for migration interface - Kernel header placeholder Date: Wed, 25 Mar 2020 02:38:59 +0530 Message-ID: <1585084154-29461-2-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086156; bh=c3Rwhkunyga+sbGbUgiT6GLjdLh9EeLpvB5+CxEaL8k=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=L2xxkFx+OFlVY99Y+hm85OyTWhc3JSIVU57a8kiXGvb2dKkwAPoIs7c6B3DMqu1mH ZbD18NPaqh3x2Nc4wrXapJWrJJxeCoAIxRiewU9cY/q4sy4D6vUjzNesW2I1Lhzfoo RE2ws/5e4E0BZF1XWd2KXH5gM5rrZh5vtGxgA9l1nLX6XmmRWEnUotqyYq3ZVN6Dbs 1RfDjMGwl44xk8/O2aJxaa84hOigq9O8NzB+s5ZjJej8aq24SyE8++EGBxJb8jLjx2 63sCWmfszo7U5h/YHlOEgE26q6R7hyPyuE+CFmKnonSgEfzs9Qpqefo3Q9Zj/R6TU0 hyBQ4dhufKYrg== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Kernel header patches are being reviewed along with kernel side changes. This patch is only for place holder. Link to Kernel patch set: https://lists.gnu.org/archive/html/qemu-devel/2020-03/msg07429.html This patch include all changes in vfio.h from above patch set Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- linux-headers/linux/vfio.h | 297 +++++++++++++++++++++++++++++++++++++++++= +++- 1 file changed, 295 insertions(+), 2 deletions(-) diff --git a/linux-headers/linux/vfio.h b/linux-headers/linux/vfio.h index fb10370d2928..78cadee85ac6 100644 --- a/linux-headers/linux/vfio.h +++ b/linux-headers/linux/vfio.h @@ -305,6 +305,7 @@ struct vfio_region_info_cap_type { #define VFIO_REGION_TYPE_PCI_VENDOR_MASK (0xffff) #define VFIO_REGION_TYPE_GFX (1) #define VFIO_REGION_TYPE_CCW (2) +#define VFIO_REGION_TYPE_MIGRATION (3) =20 /* sub-types for VFIO_REGION_TYPE_PCI_* */ =20 @@ -379,6 +380,232 @@ struct vfio_region_gfx_edid { /* sub-types for VFIO_REGION_TYPE_CCW */ #define VFIO_REGION_SUBTYPE_CCW_ASYNC_CMD (1) =20 +/* sub-types for VFIO_REGION_TYPE_MIGRATION */ +#define VFIO_REGION_SUBTYPE_MIGRATION (1) + +/* + * The structure vfio_device_migration_info is placed at the 0th offset of + * the VFIO_REGION_SUBTYPE_MIGRATION region to get and set VFIO device rel= ated + * migration information. Field accesses from this structure are only supp= orted + * at their native width and alignment. Otherwise, the result is undefined= and + * vendor drivers should return an error. + * + * device_state: (read/write) + * - The user application writes to this field to inform the vendor d= river + * about the device state to be transitioned to. + * - The vendor driver should take the necessary actions to change the + * device state. After successful transition to a given state, the + * vendor driver should return success on write(device_state, state) + * system call. If the device state transition fails, the vendor dr= iver + * should return an appropriate -errno for the fault condition. + * - On the user application side, if the device state transition fai= ls, + * that is, if write(device_state, state) returns an error, read + * device_state again to determine the current state of the device from + * the vendor driver. + * - The vendor driver should return previous state of the device unl= ess + * the vendor driver has encountered an internal error, in which ca= se + * the vendor driver may report the device_state VFIO_DEVICE_STATE_= ERROR. + * - The user application must use the device reset ioctl to recover = the + * device from VFIO_DEVICE_STATE_ERROR state. If the device is + * indicated to be in a valid device state by reading device_state,= the + * user application may attempt to transition the device to any val= id + * state reachable from the current state or terminate itself. + * + * device_state consists of 3 bits: + * - If bit 0 is set, it indicates the _RUNNING state. If bit 0 is cl= ear, + * it indicates the _STOP state. When the device state is changed to + * _STOP, driver should stop the device before write() returns. + * - If bit 1 is set, it indicates the _SAVING state, which means tha= t the + * driver should start gathering device state information that will= be + * provided to the VFIO user application to save the device's state. + * - If bit 2 is set, it indicates the _RESUMING state, which means t= hat + * the driver should prepare to resume the device. Data provided th= rough + * the migration region should be used to resume the device. + * Bits 3 - 31 are reserved for future use. To preserve them, the user + * application should perform a read-modify-write operation on this + * field when modifying the specified bits. + * + * +------- _RESUMING + * |+------ _SAVING + * ||+----- _RUNNING + * ||| + * 000b =3D> Device Stopped, not saving or resuming + * 001b =3D> Device running, which is the default state + * 010b =3D> Stop the device & save the device state, stop-and-copy state + * 011b =3D> Device running and save the device state, pre-copy state + * 100b =3D> Device stopped and the device state is resuming + * 101b =3D> Invalid state + * 110b =3D> Error state + * 111b =3D> Invalid state + * + * State transitions: + * + * _RESUMING _RUNNING Pre-copy Stop-and-copy _STOP + * (100b) (001b) (011b) (010b) (000b) + * 0. Running or default state + * | + * + * 1. Normal Shutdown (optional) + * |------------------------------------->| + * + * 2. Save the state or suspend + * |------------------------->|---------->| + * + * 3. Save the state during live migration + * |----------->|------------>|---------->| + * + * 4. Resuming + * |<---------| + * + * 5. Resumed + * |--------->| + * + * 0. Default state of VFIO device is _RUNNNG when the user application st= arts. + * 1. During normal shutdown of the user application, the user application= may + * optionally change the VFIO device state from _RUNNING to _STOP. This + * transition is optional. The vendor driver must support this transiti= on but + * must not require it. + * 2. When the user application saves state or suspends the application, t= he + * device state transitions from _RUNNING to stop-and-copy and then to = _STOP. + * On state transition from _RUNNING to stop-and-copy, driver must stop= the + * device, save the device state and send it to the application through= the + * migration region. The sequence to be followed for such transition is= given + * below. + * 3. In live migration of user application, the state transitions from _R= UNNING + * to pre-copy, to stop-and-copy, and to _STOP. + * On state transition from _RUNNING to pre-copy, the driver should sta= rt + * gathering the device state while the application is still running an= d send + * the device state data to application through the migration region. + * On state transition from pre-copy to stop-and-copy, the driver must = stop + * the device, save the device state and send it to the user application + * through the migration region. + * Vendor drivers must support the pre-copy state even for implementati= ons + * where no data is provided to the user before the stop-and-copy state= . The + * user must not be required to consume all migration data before the d= evice + * transitions to a new state, including the stop-and-copy state. + * The sequence to be followed for above two transitions is given below. + * 4. To start the resuming phase, the device state should be transitioned= from + * the _RUNNING to the _RESUMING state. + * In the _RESUMING state, the driver should use the device state data + * received through the migration region to resume the device. + * 5. After providing saved device data to the driver, the application sho= uld + * change the state from _RESUMING to _RUNNING. + * + * reserved: + * Reads on this field return zero and writes are ignored. + * + * pending_bytes: (read only) + * The number of pending bytes still to be migrated from the vendor d= river. + * + * data_offset: (read only) + * The user application should read data_offset in the migration regi= on + * from where the user application should read the device data during= the + * _SAVING state or write the device data during the _RESUMING state.= See + * below for details of sequence to be followed. + * + * data_size: (read/write) + * The user application should read data_size to get the size in byte= s of + * the data copied in the migration region during the _SAVING state a= nd + * write the size in bytes of the data copied in the migration region + * during the _RESUMING state. + * + * The format of the migration region is as follows: + * ------------------------------------------------------------------ + * |vfio_device_migration_info| data section | + * | | /////////////////////////////// | + * ------------------------------------------------------------------ + * ^ ^ + * offset 0-trapped part data_offset + * + * The structure vfio_device_migration_info is always followed by the data + * section in the region, so data_offset will always be nonzero. The offset + * from where the data is copied is decided by the kernel driver. The data + * section can be trapped, mapped, or partitioned, depending on how the ke= rnel + * driver defines the data section. The data section partition can be defi= ned + * as mapped by the sparse mmap capability. If mmapped, data_offset should= be + * page aligned, whereas initial section which contains the + * vfio_device_migration_info structure, might not end at the offset, whic= h is + * page aligned. The user is not required to access through mmap regardless + * of the capabilities of the region mmap. + * The vendor driver should determine whether and how to partition the data + * section. The vendor driver should return data_offset accordingly. + * + * The sequence to be followed for the _SAVING|_RUNNING device state or + * pre-copy phase and for the _SAVING device state or stop-and-copy phase = is as + * follows: + * a. Read pending_bytes, indicating the start of a new iteration to get d= evice + * data. Repeated read on pending_bytes at this stage should have no si= de + * effects. + * If pending_bytes =3D=3D 0, the user application should not iterate t= o get data + * for that device. + * If pending_bytes > 0, perform the following steps. + * b. Read data_offset, indicating that the vendor driver should make data + * available through the data section. The vendor driver should return = this + * read operation only after data is available from (region + data_offs= et) + * to (region + data_offset + data_size). + * c. Read data_size, which is the amount of data in bytes available throu= gh + * the migration region. + * Read on data_offset and data_size should return the offset and size = of + * the current buffer if the user application reads data_offset and + * data_size more than once here. + * d. Read data_size bytes of data from (region + data_offset) from the + * migration region. + * e. Process the data. + * f. Read pending_bytes, which indicates that the data from the previous + * iteration has been read. If pending_bytes > 0, go to step b. + * + * If an error occurs during the above sequence, the vendor driver can ret= urn + * an error code for next read() or write() operation, which will terminat= e the + * loop. The user application should then take the next necessary action, = for + * example, failing migration or terminating the user application. + * + * The user application can transition from the _SAVING|_RUNNING + * (pre-copy state) to the _SAVING (stop-and-copy) state regardless of the + * number of pending bytes. The user application should iterate in _SAVING + * (stop-and-copy) until pending_bytes is 0. + * + * The sequence to be followed while _RESUMING device state is as follows: + * While data for this device is available, repeat the following steps: + * a. Read data_offset from where the user application should write data. + * b. Write migration data starting at the migration region + data_offset = for + * the length determined by data_size from the migration source. + * c. Write data_size, which indicates to the vendor driver that data is + * written in the migration region. Vendor driver should apply the + * user-provided migration region data to the device resume state. + * + * For the user application, data is opaque. The user application should w= rite + * data in the same order as the data is received and the data should be of + * same transaction size at the source. + */ + +struct vfio_device_migration_info { + __u32 device_state; /* VFIO device state */ +#define VFIO_DEVICE_STATE_STOP (0) +#define VFIO_DEVICE_STATE_RUNNING (1 << 0) +#define VFIO_DEVICE_STATE_SAVING (1 << 1) +#define VFIO_DEVICE_STATE_RESUMING (1 << 2) +#define VFIO_DEVICE_STATE_MASK (VFIO_DEVICE_STATE_RUNNING | \ + VFIO_DEVICE_STATE_SAVING | \ + VFIO_DEVICE_STATE_RESUMING) + +#define VFIO_DEVICE_STATE_VALID(state) \ + (state & VFIO_DEVICE_STATE_RESUMING ? \ + (state & VFIO_DEVICE_STATE_MASK) =3D=3D VFIO_DEVICE_STATE_RESUMING : 1) + +#define VFIO_DEVICE_STATE_IS_ERROR(state) \ + ((state & VFIO_DEVICE_STATE_MASK) =3D=3D (VFIO_DEVICE_STATE_SAVING | \ + VFIO_DEVICE_STATE_RESUMING)) + +#define VFIO_DEVICE_STATE_SET_ERROR(state) \ + ((state & ~VFIO_DEVICE_STATE_MASK) | VFIO_DEVICE_SATE_SAVING | \ + VFIO_DEVICE_STATE_RESUMING) + + __u32 reserved; + __u64 pending_bytes; + __u64 data_offset; + __u64 data_size; +} __attribute__((packed)); + /* * The MSIX mappable capability informs that MSIX data of a BAR can be mma= pped * which allows direct access to non-MSIX registers which happened to be w= ithin @@ -720,8 +947,9 @@ struct vfio_device_ioeventfd { struct vfio_iommu_type1_info { __u32 argsz; __u32 flags; -#define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */ -#define VFIO_IOMMU_INFO_CAPS (1 << 1) /* Info supports caps */ +#define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */ +#define VFIO_IOMMU_INFO_CAPS (1 << 1) /* Info supports caps */ +#define VFIO_IOMMU_INFO_DIRTY_PGS (1 << 2) /* supports dirty page tracking= */ __u64 iova_pgsizes; /* Bitmap of supported page sizes */ __u32 cap_offset; /* Offset within info struct of first cap */ }; @@ -768,6 +996,12 @@ struct vfio_iommu_type1_dma_map { =20 #define VFIO_IOMMU_MAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 13) =20 +struct vfio_bitmap { + __u64 pgsize; /* page size for bitmap */ + __u64 size; /* in bytes */ + __u64 *data; /* one bit per page */ +}; + /** * VFIO_IOMMU_UNMAP_DMA - _IOWR(VFIO_TYPE, VFIO_BASE + 14, * struct vfio_dma_unmap) @@ -777,12 +1011,23 @@ struct vfio_iommu_type1_dma_map { * field. No guarantee is made to the user that arbitrary unmaps of iova * or size different from those used in the original mapping call will * succeed. + * VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP should be set to get dirty bitmap + * before unmapping IO virtual addresses. When this flag is set, user must + * provide data[] as structure vfio_bitmap. User must allocate memory to g= et + * bitmap, clear the bitmap memory by setting zero and must set size of + * allocated memory in vfio_bitmap.size field. One bit in bitmap + * represents per page, page of user provided page size in 'pgsize', + * consecutively starting from iova offset. Bit set indicates page at that + * offset from iova is dirty. Bitmap of pages in the range of unmapped siz= e is + * returned in vfio_bitmap.data */ struct vfio_iommu_type1_dma_unmap { __u32 argsz; __u32 flags; +#define VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP (1 << 0) __u64 iova; /* IO virtual address */ __u64 size; /* Size of mapping (bytes) */ + __u8 data[]; }; =20 #define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14) @@ -794,6 +1039,54 @@ struct vfio_iommu_type1_dma_unmap { #define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15) #define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16) =20 +/** + * VFIO_IOMMU_DIRTY_PAGES - _IOWR(VFIO_TYPE, VFIO_BASE + 17, + * struct vfio_iommu_type1_dirty_bitma= p) + * IOCTL is used for dirty pages tracking. Caller sets argsz, which is siz= e of + * struct vfio_iommu_type1_dirty_bitmap. Caller set flag depend on which + * operation to perform, details as below: + * + * When IOCTL is called with VFIO_IOMMU_DIRTY_PAGES_FLAG_START set, indica= tes + * migration is active and IOMMU module should track pages which are pinne= d and + * could be dirtied by device. + * Dirty pages are tracked until tracking is stopped by user application by + * setting VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP flag. + * + * When IOCTL is called with VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP set, indicat= es + * IOMMU should stop tracking pinned pages. + * + * When IOCTL is called with VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP flag s= et, + * IOCTL returns dirty pages bitmap for IOMMU container during migration f= or + * given IOVA range. User must provide data[] as the structure + * vfio_iommu_type1_dirty_bitmap_get through which user provides IOVA rang= e and + * pgsize. This interface supports to get bitmap of smallest supported pgs= ize + * only and can be modified in future to get bitmap of specified pgsize. + * User must allocate memory for bitmap, zero the bitmap memory and set si= ze + * of allocated memory in bitmap_size field. One bit is used to represent = one + * page consecutively starting from iova offset. User should provide page = size + * in 'pgsize'. Bit set in bitmap indicates page at that offset from iova = is + * dirty. Caller must set argsz including size of structure + * vfio_iommu_type1_dirty_bitmap_get. + * + * Only one flag should be set at a time. + */ +struct vfio_iommu_type1_dirty_bitmap { + __u32 argsz; + __u32 flags; +#define VFIO_IOMMU_DIRTY_PAGES_FLAG_START (1 << 0) +#define VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP (1 << 1) +#define VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP (1 << 2) + __u8 data[]; +}; + +struct vfio_iommu_type1_dirty_bitmap_get { + __u64 iova; /* IO virtual address */ + __u64 size; /* Size of iova range */ + struct vfio_bitmap bitmap; +}; + +#define VFIO_IOMMU_DIRTY_PAGES _IO(VFIO_TYPE, VFIO_BASE + 17) + /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ =20 /* --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086252; cv=none; d=zohomail.com; s=zohoarc; b=mU6Q+gue7IB4/cVXMktt03RGZMm5OZ2ERENkU5EBcYeu6ZPAfymGlJCis0JSYBsLpw4TiYYe1VrObejYNbxi1KmLA+3n0LnYYJWKeTkfO+KSTgwJ13uQ6d5AaxvIIaf+UlbpeGDBaw172u0d0pg9yrdBVUxo4u1vg2aJzZ6wFuA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086252; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6OJdnDk2YoR/jMg1CiBocQhG0AxgzBkRxbI9Iez1jK8=; b=NciaGTQJbj7+fpzptefw4HaiMWv5wcyfUv7J6UsY3FpTPkj93K0riXCPAWevV/y9Xc6eBTlXOjvMBMmdEHzMGcoE3+FE6/p5zVpjFY9ry1Z14LojQ2vK6I6L8mBFBMtZ1y3etNZ6isGeFIwXtIHJCHBRW9a8rjni9/iuT/XlMyc= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086252861221.90002571226944; Tue, 24 Mar 2020 14:44:12 -0700 (PDT) Received: from localhost ([::1]:55458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrLH-0006xj-FX for importer@patchew.org; Tue, 24 Mar 2020 17:44:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38697) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrK6-0005MC-AP for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:42:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrK5-0004a1-6A for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:42:58 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:6534) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrK5-0004Zh-0i for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:42:57 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:41:24 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:42:55 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:42:54 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:42:49 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 24 Mar 2020 14:42:55 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 02/16] vfio: Add function to unmap VFIO region Date: Wed, 25 Mar 2020 02:39:00 +0530 Message-ID: <1585084154-29461-3-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086085; bh=6OJdnDk2YoR/jMg1CiBocQhG0AxgzBkRxbI9Iez1jK8=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=XVhWBM6NstyZrKn0vQQ4Y/K5HmOv6oPagQvVRvouwiBY8EHtSBJOaCzgQTi44Rgvr dkOXVjhYxza9q6jaUQd2NGblKP2D4YOy7wEpiBtJTQH0g1aSgC7wzOwhjFAihdg972 82o9wor1jeCeVZOe4cXFTjAKBe8EX980tsW0SO5gOvKWeV1n36DAKhlaHcYu/JLVEa yMO7LwqAIn8DrS7MHYGSSPuyqSXllJwlBOgXJANWkqZNJtbZkXiWhxw7ZcijIMKIsM s3L4Ic2Nqul36HlPxQLXlshY6gkM16FmyNElef0bwuoenUZ0JVdejFgElMWsOAMg1E Abt7mwvy5112w== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.143 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This function will be used for migration region. Migration region is mmaped when migration starts and will be unmapped when migration is complete. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Reviewed-by: Cornelia Huck --- hw/vfio/common.c | 20 ++++++++++++++++++++ hw/vfio/trace-events | 1 + include/hw/vfio/vfio-common.h | 1 + 3 files changed, 22 insertions(+) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 0b3593b3c0c4..4a2f0d6a2233 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -983,6 +983,26 @@ int vfio_region_mmap(VFIORegion *region) return 0; } =20 +void vfio_region_unmap(VFIORegion *region) +{ + int i; + + if (!region->mem) { + return; + } + + for (i =3D 0; i < region->nr_mmaps; i++) { + trace_vfio_region_unmap(memory_region_name(®ion->mmaps[i].mem), + region->mmaps[i].offset, + region->mmaps[i].offset + + region->mmaps[i].size - 1); + memory_region_del_subregion(region->mem, ®ion->mmaps[i].mem); + munmap(region->mmaps[i].mmap, region->mmaps[i].size); + object_unparent(OBJECT(®ion->mmaps[i].mem)); + region->mmaps[i].mmap =3D NULL; + } +} + void vfio_region_exit(VFIORegion *region) { int i; diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index b1ef55a33ffd..8cdc27946cb8 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -111,6 +111,7 @@ vfio_region_mmap(const char *name, unsigned long offset= , unsigned long end) "Reg vfio_region_exit(const char *name, int index) "Device %s, region %d" vfio_region_finalize(const char *name, int index) "Device %s, region %d" vfio_region_mmaps_set_enabled(const char *name, bool enabled) "Region %s m= maps enabled: %d" +vfio_region_unmap(const char *name, unsigned long offset, unsigned long en= d) "Region %s unmap [0x%lx - 0x%lx]" vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) = "Device %s region %d: %d sparse mmap entries" vfio_region_sparse_mmap_entry(int i, unsigned long start, unsigned long en= d) "sparse entry %d [0x%lx - 0x%lx]" vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t s= ubtype) "%s index %d, %08x/%0x8" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index fd564209ac71..8d7a0fbb1046 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -171,6 +171,7 @@ int vfio_region_setup(Object *obj, VFIODevice *vbasedev= , VFIORegion *region, int index, const char *name); int vfio_region_mmap(VFIORegion *region); void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled); +void vfio_region_unmap(VFIORegion *region); void vfio_region_exit(VFIORegion *region); void vfio_region_finalize(VFIORegion *region); void vfio_reset_handler(void *opaque); --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086260; cv=none; d=zohomail.com; s=zohoarc; b=G9uyg12EWqeMWpXoXfyf50jge2Qebu6cHTnxd0rB7z3OPqmI+lHcL/Ovb3gytULozhT4B5hr98xXB2rytVm6O+PB11MjOi8orVBlvi2yIITGN4idjaChD9Gv/61qIg/oCkVwn222Wx/s+FSoarW2dIvmx8NQ2JZjAOVQPoHiHuc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086260; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RQyD3Vak9+vtQi5zZdaNzLlTlIKg3CpA3v/dVe1gFhQ=; b=VTTSvEIT3XCff1TgaTlyIoW4bRIbvqc6wAL8k9vrRNFyJGB2g33p33sBPEmyvUndddwWlMKXa74NzsFGbPwnHunja9X5Cw9SSlWKj/7szLuttphJqqBcKzCjr8+UlhYpgsORhFGBv11OWzlHW5t8asJ8iQiG7OLYOMnYqY3yxq0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086260585809.581271465696; Tue, 24 Mar 2020 14:44:20 -0700 (PDT) Received: from localhost ([::1]:55470 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrLP-0007E8-BC for importer@patchew.org; Tue, 24 Mar 2020 17:44:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38721) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrKD-0005XB-3H for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrKB-0004dL-Vh for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:04 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6098) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrKB-0004bF-Pb for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:03 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:42:48 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:01 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:01 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:42:55 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:43:01 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 03/16] vfio: Add vfio_get_object callback to VFIODeviceOps Date: Wed, 25 Mar 2020 02:39:01 +0530 Message-ID: <1585084154-29461-4-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086168; bh=RQyD3Vak9+vtQi5zZdaNzLlTlIKg3CpA3v/dVe1gFhQ=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=SuN7n6oO4WfiZApwVtLBT/TFOxMRa0Hjharrys+k5dwey/T6MWpb/XDG9VgAmBSYp LKAXo7O093wTnmYwvQ+eYhPfvxlC+GX6scrP1ejlgr9IzTtx8vh0cmMPQw1hoNfSdB Qly6rJG1eUUc9qm8wfTivFSylZG4NZ8pmaZTH+n6JGLiZgUzVjo029mCsFK6ygprbn NtshqGOq3SCmvG4k04VHn0yRoKpEH+H5kGbS1N2MpvxDrjILB1rPanuZoBCD7S0mA9 fqMcVg+FJfQ867b5raMnyMKSMulpz462OXS+GrGUgZjVOeCLpfqwYLQvIYEJ3om6R6 DXcKYzC0eRKQw== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Hook vfio_get_object callback for PCI devices. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia Suggested-by: Cornelia Huck Reviewed-by: Cornelia Huck --- hw/vfio/pci.c | 8 ++++++++ include/hw/vfio/vfio-common.h | 1 + 2 files changed, 9 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 5e75a95129ac..6c77c12e44b9 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2407,10 +2407,18 @@ static void vfio_pci_compute_needs_reset(VFIODevice= *vbasedev) } } =20 +static Object *vfio_pci_get_object(VFIODevice *vbasedev) +{ + VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + + return OBJECT(vdev); +} + static VFIODeviceOps vfio_pci_ops =3D { .vfio_compute_needs_reset =3D vfio_pci_compute_needs_reset, .vfio_hot_reset_multi =3D vfio_pci_hot_reset_multi, .vfio_eoi =3D vfio_intx_eoi, + .vfio_get_object =3D vfio_pci_get_object, }; =20 int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 8d7a0fbb1046..74261feaeac9 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -119,6 +119,7 @@ struct VFIODeviceOps { void (*vfio_compute_needs_reset)(VFIODevice *vdev); int (*vfio_hot_reset_multi)(VFIODevice *vdev); void (*vfio_eoi)(VFIODevice *vdev); + Object *(*vfio_get_object)(VFIODevice *vdev); }; =20 typedef struct VFIOGroup { --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086358; cv=none; d=zohomail.com; s=zohoarc; b=cWzKEwHCFI1RYDI+7sfQfPRsHVrk2P4RPT7bNsRuDIQdtQLzX0tDCBMvZ9HxdFz675bD3Nu/2KDVL6O0oi8J7WBSV8aVTJHmWhNRPmOI/e1fr+PDK/LB8qFkcuMu0u+RSiI8H0UnDoQg8mf5v1fNRMbSmsGgTJUcZ/pCTaXDdo4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086358; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=8GNHHJN6bYqzJEgHS83v8xtDI+MVHcgFYs0/xRA0l8o=; b=Yzcq8bqm4rfyQnYqsFxptGkj82BSxdE6GDHbUd8aRg2aK4cy5v4A4oJfT5ulZtUq9T0whaKdOWQr2PQfp7GxtFma6HmQLYuKrDOGW7+QxoVxSY2dB6KNdRvKhqLqpnjn9c0WRGWG04EK4yNByVLwyqJOQRrK7GbHrqA9uWT+/0Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086358158604.475863657257; Tue, 24 Mar 2020 14:45:58 -0700 (PDT) Received: from localhost ([::1]:55562 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrMy-0001PH-Ow for importer@patchew.org; Tue, 24 Mar 2020 17:45:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38740) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrKL-0005oe-Nr for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:15 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrKI-0004fD-Fn for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:12 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:6555) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrKI-0004f4-9E for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:10 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:41:38 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:08 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:08 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:01 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:43:08 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 04/16] vfio: Add save and load functions for VFIO PCI devices Date: Wed, 25 Mar 2020 02:39:02 +0530 Message-ID: <1585084154-29461-5-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086098; bh=8GNHHJN6bYqzJEgHS83v8xtDI+MVHcgFYs0/xRA0l8o=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=EQaPvxk5//5lnY9Sn1I4xuNfwPUUd+nWL4Gh8oLe1uN8tY2n3joHIBYb/ZPXSRNvr xIjUTeFBiz6D+g/MCtqs4dNpGwlOq0NOW0e3at1ZkMgJgBYKfEYO6UZMuyqfQWtHet HFNPz1tEa8y/AiQnWZMmnF3bReoKh/8eMX3N3nzn7gjKyOrxmhnkzD0HzuYoIDuxol eG6ovb6Yb1l3C/1uOcnBPsxmXV+9TI08D9igGXedd0MBPtbUeXDtvMf6auSWd+Zd8A BL86jY983yb9XwV5tli51eSZEXQrMGJqUeLIrkOfUXSTdQtIQSv5xggSuYMqhb1pIh 0Io7cyJEhV+Vw== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.143 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" These functions save and restore PCI device specific data - config space of PCI device. Tested save and restore with MSI and MSIX type. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/pci.c | 163 ++++++++++++++++++++++++++++++++++++++= ++++ include/hw/vfio/vfio-common.h | 2 + 2 files changed, 165 insertions(+) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 6c77c12e44b9..8deb11e87ef7 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -41,6 +41,7 @@ #include "trace.h" #include "qapi/error.h" #include "migration/blocker.h" +#include "migration/qemu-file.h" =20 #define TYPE_VFIO_PCI "vfio-pci" #define PCI_VFIO(obj) OBJECT_CHECK(VFIOPCIDevice, obj, TYPE_VFIO_PCI) @@ -1632,6 +1633,50 @@ static void vfio_bars_prepare(VFIOPCIDevice *vdev) } } =20 +static int vfio_bar_validate(VFIOPCIDevice *vdev, int nr) +{ + PCIDevice *pdev =3D &vdev->pdev; + VFIOBAR *bar =3D &vdev->bars[nr]; + uint64_t addr; + uint32_t addr_lo, addr_hi =3D 0; + + /* Skip unimplemented BARs and the upper half of 64bit BARS. */ + if (!bar->size) { + return 0; + } + + addr_lo =3D pci_default_read_config(pdev, PCI_BASE_ADDRESS_0 + nr * 4,= 4); + + addr_lo =3D addr_lo & (bar->ioport ? PCI_BASE_ADDRESS_IO_MASK : + PCI_BASE_ADDRESS_MEM_MASK); + if (bar->type =3D=3D PCI_BASE_ADDRESS_MEM_TYPE_64) { + addr_hi =3D pci_default_read_config(pdev, + PCI_BASE_ADDRESS_0 + (nr + 1) * 4= , 4); + } + + addr =3D ((uint64_t)addr_hi << 32) | addr_lo; + + if (!QEMU_IS_ALIGNED(addr, bar->size)) { + return -EINVAL; + } + + return 0; +} + +static int vfio_bars_validate(VFIOPCIDevice *vdev) +{ + int i, ret; + + for (i =3D 0; i < PCI_ROM_SLOT; i++) { + ret =3D vfio_bar_validate(vdev, i); + if (ret) { + error_report("vfio: BAR address %d validation failed", i); + return ret; + } + } + return 0; +} + static void vfio_bar_register(VFIOPCIDevice *vdev, int nr) { VFIOBAR *bar =3D &vdev->bars[nr]; @@ -2414,11 +2459,129 @@ static Object *vfio_pci_get_object(VFIODevice *vba= sedev) return OBJECT(vdev); } =20 +static void vfio_pci_save_config(VFIODevice *vbasedev, QEMUFile *f) +{ + VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + PCIDevice *pdev =3D &vdev->pdev; + uint16_t pci_cmd; + int i; + + for (i =3D 0; i < PCI_ROM_SLOT; i++) { + uint32_t bar; + + bar =3D pci_default_read_config(pdev, PCI_BASE_ADDRESS_0 + i * 4, = 4); + qemu_put_be32(f, bar); + } + + qemu_put_be32(f, vdev->interrupt); + if (vdev->interrupt =3D=3D VFIO_INT_MSI) { + uint32_t msi_flags, msi_addr_lo, msi_addr_hi =3D 0, msi_data; + bool msi_64bit; + + msi_flags =3D pci_default_read_config(pdev, pdev->msi_cap + PCI_MS= I_FLAGS, + 2); + msi_64bit =3D (msi_flags & PCI_MSI_FLAGS_64BIT); + + msi_addr_lo =3D pci_default_read_config(pdev, + pdev->msi_cap + PCI_MSI_ADDRESS_L= O, 4); + qemu_put_be32(f, msi_addr_lo); + + if (msi_64bit) { + msi_addr_hi =3D pci_default_read_config(pdev, + pdev->msi_cap + PCI_MSI_ADDRE= SS_HI, + 4); + } + qemu_put_be32(f, msi_addr_hi); + + msi_data =3D pci_default_read_config(pdev, + pdev->msi_cap + (msi_64bit ? PCI_MSI_DATA_64 : PCI_MSI_DAT= A_32), + 2); + qemu_put_be32(f, msi_data); + } else if (vdev->interrupt =3D=3D VFIO_INT_MSIX) { + uint16_t offset; + + /* save enable bit and maskall bit */ + offset =3D pci_default_read_config(pdev, + pdev->msix_cap + PCI_MSIX_FLAGS + 1= , 2); + qemu_put_be16(f, offset); + msix_save(pdev, f); + } + pci_cmd =3D pci_default_read_config(pdev, PCI_COMMAND, 2); + qemu_put_be16(f, pci_cmd); +} + +static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) +{ + VFIOPCIDevice *vdev =3D container_of(vbasedev, VFIOPCIDevice, vbasedev= ); + PCIDevice *pdev =3D &vdev->pdev; + uint32_t interrupt_type; + uint32_t msi_flags, msi_addr_lo, msi_addr_hi =3D 0, msi_data; + uint16_t pci_cmd; + bool msi_64bit; + int i, ret; + + /* retore pci bar configuration */ + pci_cmd =3D pci_default_read_config(pdev, PCI_COMMAND, 2); + vfio_pci_write_config(pdev, PCI_COMMAND, + pci_cmd & (!(PCI_COMMAND_IO | PCI_COMMAND_MEMORY))= , 2); + for (i =3D 0; i < PCI_ROM_SLOT; i++) { + uint32_t bar =3D qemu_get_be32(f); + + vfio_pci_write_config(pdev, PCI_BASE_ADDRESS_0 + i * 4, bar, 4); + } + + ret =3D vfio_bars_validate(vdev); + if (ret) { + return ret; + } + + interrupt_type =3D qemu_get_be32(f); + + if (interrupt_type =3D=3D VFIO_INT_MSI) { + /* restore msi configuration */ + msi_flags =3D pci_default_read_config(pdev, + pdev->msi_cap + PCI_MSI_FLAGS,= 2); + msi_64bit =3D (msi_flags & PCI_MSI_FLAGS_64BIT); + + vfio_pci_write_config(pdev, pdev->msi_cap + PCI_MSI_FLAGS, + msi_flags & (!PCI_MSI_FLAGS_ENABLE), 2); + + msi_addr_lo =3D qemu_get_be32(f); + vfio_pci_write_config(pdev, pdev->msi_cap + PCI_MSI_ADDRESS_LO, + msi_addr_lo, 4); + + msi_addr_hi =3D qemu_get_be32(f); + if (msi_64bit) { + vfio_pci_write_config(pdev, pdev->msi_cap + PCI_MSI_ADDRESS_HI, + msi_addr_hi, 4); + } + msi_data =3D qemu_get_be32(f); + vfio_pci_write_config(pdev, + pdev->msi_cap + (msi_64bit ? PCI_MSI_DATA_64 : PCI_MSI_DAT= A_32), + msi_data, 2); + + vfio_pci_write_config(pdev, pdev->msi_cap + PCI_MSI_FLAGS, + msi_flags | PCI_MSI_FLAGS_ENABLE, 2); + } else if (interrupt_type =3D=3D VFIO_INT_MSIX) { + uint16_t offset =3D qemu_get_be16(f); + + /* load enable bit and maskall bit */ + vfio_pci_write_config(pdev, pdev->msix_cap + PCI_MSIX_FLAGS + 1, + offset, 2); + msix_load(pdev, f); + } + pci_cmd =3D qemu_get_be16(f); + vfio_pci_write_config(pdev, PCI_COMMAND, pci_cmd, 2); + return 0; +} + static VFIODeviceOps vfio_pci_ops =3D { .vfio_compute_needs_reset =3D vfio_pci_compute_needs_reset, .vfio_hot_reset_multi =3D vfio_pci_hot_reset_multi, .vfio_eoi =3D vfio_intx_eoi, .vfio_get_object =3D vfio_pci_get_object, + .vfio_save_config =3D vfio_pci_save_config, + .vfio_load_config =3D vfio_pci_load_config, }; =20 int vfio_populate_vga(VFIOPCIDevice *vdev, Error **errp) diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 74261feaeac9..d69a7f3ae31e 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -120,6 +120,8 @@ struct VFIODeviceOps { int (*vfio_hot_reset_multi)(VFIODevice *vdev); void (*vfio_eoi)(VFIODevice *vdev); Object *(*vfio_get_object)(VFIODevice *vdev); + void (*vfio_save_config)(VFIODevice *vdev, QEMUFile *f); + int (*vfio_load_config)(VFIODevice *vdev, QEMUFile *f); }; =20 typedef struct VFIOGroup { --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086414; cv=none; d=zohomail.com; s=zohoarc; b=Uw6NudEWJkHL2ez7q5pgrpaaZ1p0tlEblfFa4yAOK7CsEhpogRmrg/BJftEn8iJwMt1fSTmti1rGdJ6fklIm2+uvip/yByE42ZPHSH6lk7ocsD5vSVKDEAR4K9jr/z2fmniknjxjphyUbuMp1WiHz4yJ2QAH/1XZ2Cb0UoSB3x4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086414; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6/kXae8jnO/HUeHim09m+t6UCx3moooGb24rwJ+hKnM=; b=gsCM96/IQYbzQJO9Ib4LS5NgVEWYectKNozQ0scIon30uwm8XRpYlymwLjzp9d5WNVewc6/9X+1JcGWxCZXPTNwJqLwzMbXCiuTWo+mm3mD/uQjAJjX5zvCihgKyszJa+nIjvXuZpnpk3mthnkWJQOzC9q4VK7FALHJfl5aXfwA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086414026556.6204265208014; Tue, 24 Mar 2020 14:46:54 -0700 (PDT) Received: from localhost ([::1]:55574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrNs-0002J7-L5 for importer@patchew.org; Tue, 24 Mar 2020 17:46:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38758) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrKR-0005us-FB for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrKP-0004gv-VV for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:19 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8821) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrKO-0004gL-Ju for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:17 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:42:30 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:15 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:15 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:08 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 24 Mar 2020 14:43:15 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 05/16] vfio: Add migration region initialization and finalize function Date: Wed, 25 Mar 2020 02:39:03 +0530 Message-ID: <1585084154-29461-6-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086150; bh=6/kXae8jnO/HUeHim09m+t6UCx3moooGb24rwJ+hKnM=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=WCNS+L6UEMEF0jfQhqfd8EJLURk5QunE1i0gLph8AZN/kiW944dmpC+EeayrScLKW 5jiz/gLB+ntsA8bHy47l/c0ZyG6x9Im+l0AqkHn5EKZtIxZpH7a4vcY1JoYaOecZI+ bPv/vuvSbYKt8WqLloeav83AegytYAJdPVPWsorlq+rI5FzQvpRoqpqH5hA+6LMutm I3i71aI/3xoZkYKwuc21fCYZwQ7RaOhM/9yIlJxRbI2YxspgfYLXJOqQQcpVD/ILLX 77SdpZfoiMefE1kv+S5g/bu87+DzDG4yhFTulQEx1xa2G/oeGn7iq8ipw3v8Kgxqgw Ie4xDgnu3tCbg== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" - Migration functions are implemented for VFIO_DEVICE_TYPE_PCI device in th= is 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 Reviewed-by: Neo Jia --- 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 +=3D common.o spapr.o +obj-y +=3D common.o spapr.o migration.o obj-$(CONFIG_VFIO_PCI) +=3D pci.o pci-quirks.o display.o obj-$(CONFIG_VFIO_CCW) +=3D ccw.o obj-$(CONFIG_VFIO_PLATFORM) +=3D 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 + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include + +#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 =3D 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 =3D vbasedev->migration; + Object *obj =3D NULL; + int ret =3D -EINVAL; + + if (!vbasedev->ops->vfio_get_object) { + return ret; + } + + obj =3D vbasedev->ops->vfio_get_object(vbasedev); + if (!obj) { + return ret; + } + + ret =3D 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 =3D -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 =3D g_new0(VFIOMigration, 1); + + ret =3D 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 =3D NULL; + return ret; + } + + return 0; +} + +/* ---------------------------------------------------------------------- = */ + +int vfio_migration_probe(VFIODevice *vbasedev, Error **errp) +{ + struct vfio_region_info *info; + Error *local_err =3D NULL; + int ret; + + ret =3D vfio_get_dev_region_info(vbasedev, VFIO_REGION_TYPE_MIGRATION, + VFIO_REGION_SUBTYPE_MIGRATION, &info); + if (ret) { + goto add_blocker; + } + + ret =3D 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 =3D 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; =20 +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; =20 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); =20 +int vfio_migration_probe(VFIODevice *vbasedev, Error **errp); +void vfio_migration_finalize(VFIODevice *vbasedev); + #endif /* HW_VFIO_VFIO_COMMON_H */ --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086543; cv=none; d=zohomail.com; s=zohoarc; b=ApV1tfTO3dkZ+pwRHwtz5q/4Pt8XUZ4eyEfrDyYA00vZKb2YdKL+YEMHFsc9rm5dVaIDByDJBTHKKeK7chFGel2su2+PD/veeo5IFMOoFR5YdpMgoGqRSOJ5AVWCyspNjFMb+MXivTfUeBO3GG7LnMqvDVJ7P3pUbFwgB8gwm0g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086543; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1lsXdrVK1pa0ObOWyoEz9Lbsi26OX8yNYFCguvsRpJU=; b=aC5JcSqfBZcNxQFtccBjq8y8BbqT0BVvT+OZJPbnWXAuaV7CcxAUQ/bhxbVK/9VjPAs6P9kEeXhCDEXAs7LceM13kg1JBJCtbc1JUtgpzYle3jwO243Fsdgyw57c04w0qTuclEYIrBKA2n6WVmytXbpf+YGE3ZSG/ymhvNxKtSo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086543694899.2448715059862; Tue, 24 Mar 2020 14:49:03 -0700 (PDT) Received: from localhost ([::1]:55628 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrPy-0005jG-BF for importer@patchew.org; Tue, 24 Mar 2020 17:49:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38778) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrKW-0005xZ-Et for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrKV-0004jj-5P for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:24 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8834) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrKV-0004jT-0B for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:23 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:42:37 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:21 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:21 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:15 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:43:21 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 06/16] vfio: Add VM state change handler to know state of VM Date: Wed, 25 Mar 2020 02:39:04 +0530 Message-ID: <1585084154-29461-7-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086157; bh=1lsXdrVK1pa0ObOWyoEz9Lbsi26OX8yNYFCguvsRpJU=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=G3hOsrI0DMte0VnVEbN1SilFt4T+xl7Pw+5N9pW2qn0SQ+owqx5harUsjvlh6OYPf hx1AYnOsgmZAakPZ67GVibteYf306uA5/Xv00H4mitTsR/Z/F2fjThPqSypGNuPN+/ nENRVj0HWZG+enD5PbqNgFKiISd14fhS7OcRDNgDcTJ89qNVtGMv2OWQaVy7+VAX7s yNXhZAgR3GFNjtkuXgjiDRjOARKlhxlvmVTZYhhBQHo7DtnoTUK/orZb8WjeKUZg+0 McINrLKEh+d+Tckw6XHWdbJez0gr1D71VH/r1xRq1z3qGWV+muOvlqXUlElgWhI/Zb uJB4MdxZl8Btg== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" VM state change handler gets called on change in VM's state. This is used t= o set VFIO device state to _RUNNING. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/migration.c | 87 +++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 2 + include/hw/vfio/vfio-common.h | 4 ++ 3 files changed, 93 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index a078dcf1dd8f..af9443c275fb 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include =20 +#include "sysemu/runstate.h" #include "hw/vfio/vfio-common.h" #include "cpu.h" #include "migration/migration.h" @@ -74,6 +75,85 @@ err: return ret; } =20 +static int vfio_migration_set_state(VFIODevice *vbasedev, uint32_t mask, + uint32_t value) +{ + VFIOMigration *migration =3D vbasedev->migration; + VFIORegion *region =3D &migration->region; + uint32_t device_state; + int ret; + + ret =3D pread(vbasedev->fd, &device_state, sizeof(device_state), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + device_state)); + if (ret < 0) { + error_report("%s: Failed to read device state %d %s", + vbasedev->name, ret, strerror(errno)); + return ret; + } + + device_state =3D (device_state & mask) | value; + + if (!VFIO_DEVICE_STATE_VALID(device_state)) { + return -EINVAL; + } + + ret =3D pwrite(vbasedev->fd, &device_state, sizeof(device_state), + region->fd_offset + offsetof(struct vfio_device_migration= _info, + device_state)); + if (ret < 0) { + error_report("%s: Failed to set device state %d %s", + vbasedev->name, ret, strerror(errno)); + + ret =3D pread(vbasedev->fd, &device_state, sizeof(device_state), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + device_state)); + if (ret < 0) { + error_report("%s: On failure, failed to read device state %d %= s", + vbasedev->name, ret, strerror(errno)); + return ret; + } + + if (VFIO_DEVICE_STATE_IS_ERROR(device_state)) { + error_report("%s: Device is in error state 0x%x", + vbasedev->name, device_state); + return -EFAULT; + } + } + + vbasedev->device_state =3D device_state; + trace_vfio_migration_set_state(vbasedev->name, device_state); + return 0; +} + +static void vfio_vmstate_change(void *opaque, int running, RunState state) +{ + VFIODevice *vbasedev =3D opaque; + + if ((vbasedev->vm_running !=3D running)) { + int ret; + uint32_t value =3D 0, mask =3D 0; + + if (running) { + value =3D VFIO_DEVICE_STATE_RUNNING; + if (vbasedev->device_state & VFIO_DEVICE_STATE_RESUMING) { + mask =3D ~VFIO_DEVICE_STATE_RESUMING; + } + } else { + mask =3D ~VFIO_DEVICE_STATE_RUNNING; + } + + ret =3D vfio_migration_set_state(vbasedev, mask, value); + if (ret) { + error_report("%s: Failed to set device state 0x%x", + vbasedev->name, value & mask); + } + vbasedev->vm_running =3D running; + trace_vfio_vmstate_change(vbasedev->name, running, RunState_str(st= ate), + value & mask); + } +} + static int vfio_migration_init(VFIODevice *vbasedev, struct vfio_region_info *info) { @@ -90,6 +170,9 @@ static int vfio_migration_init(VFIODevice *vbasedev, return ret; } =20 + vbasedev->vm_state =3D qemu_add_vm_change_state_handler(vfio_vmstate_c= hange, + vbasedev); + return 0; } =20 @@ -128,6 +211,10 @@ add_blocker: =20 void vfio_migration_finalize(VFIODevice *vbasedev) { + if (vbasedev->vm_state) { + qemu_del_vm_change_state_handler(vbasedev->vm_state); + } + if (vbasedev->migration_blocker) { migrate_del_blocker(vbasedev->migration_blocker); error_free(vbasedev->migration_blocker); diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 191a726a1312..3d15bacd031a 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -146,3 +146,5 @@ vfio_display_edid_write_error(void) "" =20 # migration.c vfio_migration_probe(char *name, uint32_t index) " (%s) Region %d" +vfio_migration_set_state(char *name, uint32_t state) " (%s) state %d" +vfio_vmstate_change(char *name, int running, const char *reason, uint32_t = dev_state) " (%s) running %d reason %s device state %d" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index d4b268641173..3d18eb146b33 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -29,6 +29,7 @@ #ifdef CONFIG_LINUX #include #endif +#include "sysemu/sysemu.h" =20 #define VFIO_MSG_PREFIX "vfio %s: " =20 @@ -119,6 +120,9 @@ typedef struct VFIODevice { unsigned int flags; VFIOMigration *migration; Error *migration_blocker; + VMChangeStateEntry *vm_state; + uint32_t device_state; + int vm_running; } VFIODevice; =20 struct VFIODeviceOps { --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086654; cv=none; d=zohomail.com; s=zohoarc; b=Y5aO5yClODo3+a8yZ/28sSF2n7amySYV9bJEnbKQTiyQQBykUCkoD5OakKy3/YBUOGz9nF6lvy5h1kM0efHQ8Z98RtjWOVFF/+cUnMAIe0ZYP6iP9Xmuxd5COOjEqJ5S07MSF82W0yegAO6WRt06ihNXX1/HmzvrDYSSk9j9cLM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086654; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RYCcc4+O5nHCMKaMsAlhqi/eDwYsgZSiczCP8XirvXU=; b=AsvE/QKViNyPLvlKLd2uxh09GMlCgPbCEMCKY+5V2uF9dgRk6Ihw/nAG7IIumSXxpZc1Y4YxR1ug5L2/bxT/yCeeyrVPn9CRm7fOvizk7894LSAiQ/Icwq1OT36DR38iSftVS4LWovFdYxdk0sH8dG+XUOeMgB6FKPOzbQVHrlM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 15850866542191022.8320934288539; Tue, 24 Mar 2020 14:50:54 -0700 (PDT) Received: from localhost ([::1]:55686 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrRl-0000D4-2M for importer@patchew.org; Tue, 24 Mar 2020 17:50:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38796) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrKd-00069Q-0F for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrKb-0004lK-Ny for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:30 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8846) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrKb-0004l8-Hn for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:29 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:42:43 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:28 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:28 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:21 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:43:28 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 07/16] vfio: Add migration state change notifier Date: Wed, 25 Mar 2020 02:39:05 +0530 Message-ID: <1585084154-29461-8-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086163; bh=RYCcc4+O5nHCMKaMsAlhqi/eDwYsgZSiczCP8XirvXU=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=J1gaOvw+UvrQP0Hnj0c6WOD50MfhqcQqiqgu4xN0DQhEeibkON7Vh+q8eCx76gci5 xIwV8QxItKNwbjk90EFvI+m4Lcy9gs6VV6G8SF+7+wpSsgCUBZcuutlkcrG8leN4Xw HI2GSdWEfdUp4B0v8eet4MzMonC5Rp8QhFkHVid02sP7s+1tt3RfhLGgmTTLIH0OUb 3rPh4jqTM2XendcHjaQwqcHGke8HBX1Qxbp5luqGWx/R1EI/DsTxeSNqy4aDviY03q 5qO5EPkXqCfEJgQ3HNYr4msguRTzJ4ZZw6wPwf5s7sqQcPq3qToeaQH3Cba4fPVFMP qXrBH1vB3yHRQ== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Added migration state change notifier to get notification on migration state change. These states are translated to VFIO device state and conveyed to ve= ndor driver. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/migration.c | 29 +++++++++++++++++++++++++++++ hw/vfio/trace-events | 1 + include/hw/vfio/vfio-common.h | 1 + 3 files changed, 31 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index af9443c275fb..22ded9d28cf3 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -154,6 +154,27 @@ static void vfio_vmstate_change(void *opaque, int runn= ing, RunState state) } } =20 +static void vfio_migration_state_notifier(Notifier *notifier, void *data) +{ + MigrationState *s =3D data; + VFIODevice *vbasedev =3D container_of(notifier, VFIODevice, migration_= state); + int ret; + + trace_vfio_migration_state_notifier(vbasedev->name, s->state); + + switch (s->state) { + case MIGRATION_STATUS_CANCELLING: + case MIGRATION_STATUS_CANCELLED: + case MIGRATION_STATUS_FAILED: + ret =3D vfio_migration_set_state(vbasedev, + ~(VFIO_DEVICE_STATE_SAVING | VFIO_DEVICE_STATE_RESUM= ING), + VFIO_DEVICE_STATE_RUNNING); + if (ret) { + error_report("%s: Failed to set state RUNNING", vbasedev->name= ); + } + } +} + static int vfio_migration_init(VFIODevice *vbasedev, struct vfio_region_info *info) { @@ -173,6 +194,9 @@ static int vfio_migration_init(VFIODevice *vbasedev, vbasedev->vm_state =3D qemu_add_vm_change_state_handler(vfio_vmstate_c= hange, vbasedev); =20 + vbasedev->migration_state.notify =3D vfio_migration_state_notifier; + add_migration_state_change_notifier(&vbasedev->migration_state); + return 0; } =20 @@ -211,6 +235,11 @@ add_blocker: =20 void vfio_migration_finalize(VFIODevice *vbasedev) { + + if (vbasedev->migration_state.notify) { + remove_migration_state_change_notifier(&vbasedev->migration_state); + } + if (vbasedev->vm_state) { qemu_del_vm_change_state_handler(vbasedev->vm_state); } diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 3d15bacd031a..69503228f20e 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -148,3 +148,4 @@ vfio_display_edid_write_error(void) "" vfio_migration_probe(char *name, uint32_t index) " (%s) Region %d" vfio_migration_set_state(char *name, uint32_t state) " (%s) state %d" vfio_vmstate_change(char *name, int running, const char *reason, uint32_t = dev_state) " (%s) running %d reason %s device state %d" +vfio_migration_state_notifier(char *name, int state) " (%s) state %d" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 3d18eb146b33..28f55f66d019 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -123,6 +123,7 @@ typedef struct VFIODevice { VMChangeStateEntry *vm_state; uint32_t device_state; int vm_running; + Notifier migration_state; } VFIODevice; =20 struct VFIODeviceOps { --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086735; cv=none; d=zohomail.com; s=zohoarc; b=C2CH0yFGn0TUkXH5KwMPRTTtQIjqwCKO7xisNjJv/WORmr6fAvl08SXy4aGXsf2/zEU8985+kDdG12ulaiEhGMPl/X1oNYOB75GXRXdTLGuEgqLMhyCpdiad5Kpj9M6AlNm6JnJBniU0gX/YhYCpGolUFx0vkOWejFRrRL66LIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086735; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cdLHWobDze0sjUOm2rMtYvFS47xMNkY3ST4WBMYGhbs=; b=efT64SdLYA/AlY62tAx2gZzJGWx33kCVOqIWLaUei8CvcwdGp7iQa7uzZuaVWMYDwrOTHg0OPSuoyUVR10kzuqefmLMlXfsXoaSmtjMizUQ/gYjFLteo0cHDtdYztS81vvQhofx1pXn/jeRr4OSNR4Ff3r+B3k0J4F3p3zAsj14= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086735777909.8754186519955; Tue, 24 Mar 2020 14:52:15 -0700 (PDT) Received: from localhost ([::1]:55710 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrT4-000210-J8 for importer@patchew.org; Tue, 24 Mar 2020 17:52:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38815) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrKj-0006QN-FT for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrKi-0004n5-6G for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:37 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8861) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrKi-0004mp-0W for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:36 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:42:50 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:35 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:34 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:28 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:43:35 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 08/16] vfio: Register SaveVMHandlers for VFIO device Date: Wed, 25 Mar 2020 02:39:06 +0530 Message-ID: <1585084154-29461-9-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086170; bh=cdLHWobDze0sjUOm2rMtYvFS47xMNkY3ST4WBMYGhbs=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=i88Q+YUskR97fgrhiqONmSyIRKMaav0sQDgeIN+HCE5yd0TKaXv3heEd6BMNgG5yk Zx5+rsiRKACD8/T1IAaIjO+jma0P2i24ekzPIoIc+EAtnxVRSzwh2LC4L5TCsmFSOf 7hRfQXbEMhLYLijhj9Yk5rxPw5h25VpMnSEZpv57JydUo7MXErji1R5JPx2bFCHTM9 i9DWraRc/SO2DxsAA9lUKbRNnBKaCPWSsUhxCM8dCQPJDtCgSnaA2eua35gVNBpPh8 Y0qZG4OC5gKXidSxkbQDDCEmGMlMrm9rEtLAKjWohHq6FkJfLM0gtrX3S9KJcmYlLD DVoyFz2UE3oBA== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Define flags to be used as delimeter in migration file stream. Added .save_setup and .save_cleanup functions. Mapped & unmapped migration region from these functions at source during saving or pre-copy phase. Set VFIO device state depending on VM's state. During live migration, VM is running when .save_setup is called, _SAVING | _RUNNING state is set for VFIO device. During save-restore, VM is paused, _SAVING state is set for VFIO de= vice. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/migration.c | 76 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 2 ++ 2 files changed, 78 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 22ded9d28cf3..033f76526e49 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -8,6 +8,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include =20 #include "sysemu/runstate.h" @@ -24,6 +25,17 @@ #include "pci.h" #include "trace.h" =20 +/* + * Flags used as delimiter: + * 0xffffffff =3D> MSB 32-bit all 1s + * 0xef10 =3D> emulated (virtual) function IO + * 0x0000 =3D> 16-bits reserved for flags + */ +#define VFIO_MIG_FLAG_END_OF_STATE (0xffffffffef100001ULL) +#define VFIO_MIG_FLAG_DEV_CONFIG_STATE (0xffffffffef100002ULL) +#define VFIO_MIG_FLAG_DEV_SETUP_STATE (0xffffffffef100003ULL) +#define VFIO_MIG_FLAG_DEV_DATA_STATE (0xffffffffef100004ULL) + static void vfio_migration_region_exit(VFIODevice *vbasedev) { VFIOMigration *migration =3D vbasedev->migration; @@ -126,6 +138,69 @@ static int vfio_migration_set_state(VFIODevice *vbased= ev, uint32_t mask, return 0; } =20 +/* ---------------------------------------------------------------------- = */ + +static int vfio_save_setup(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret; + + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_SETUP_STATE); + + if (migration->region.mmaps) { + qemu_mutex_lock_iothread(); + ret =3D vfio_region_mmap(&migration->region); + qemu_mutex_unlock_iothread(); + if (ret) { + error_report("%s: Failed to mmap VFIO migration region %d: %s", + vbasedev->name, migration->region.index, + strerror(-ret)); + return ret; + } + } + + ret =3D vfio_migration_set_state(vbasedev, ~0, VFIO_DEVICE_STATE_SAVIN= G); + if (ret) { + error_report("%s: Failed to set state SAVING", vbasedev->name); + return ret; + } + + /* + * Save migration region size. This is used to verify migration region= size + * is greater than or equal to migration region size at destination + */ + qemu_put_be64(f, migration->region.size); + + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + + trace_vfio_save_setup(vbasedev->name); + return 0; +} + +static void vfio_save_cleanup(void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + + if (migration->region.mmaps) { + vfio_region_unmap(&migration->region); + } + trace_vfio_save_cleanup(vbasedev->name); +} + +static SaveVMHandlers savevm_vfio_handlers =3D { + .save_setup =3D vfio_save_setup, + .save_cleanup =3D vfio_save_cleanup, +}; + +/* ---------------------------------------------------------------------- = */ + static void vfio_vmstate_change(void *opaque, int running, RunState state) { VFIODevice *vbasedev =3D opaque; @@ -191,6 +266,7 @@ static int vfio_migration_init(VFIODevice *vbasedev, return ret; } =20 + register_savevm_live("vfio", -1, 1, &savevm_vfio_handlers, vbasedev); vbasedev->vm_state =3D qemu_add_vm_change_state_handler(vfio_vmstate_c= hange, vbasedev); =20 diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 69503228f20e..4bb43f18f315 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -149,3 +149,5 @@ vfio_migration_probe(char *name, uint32_t index) " (%s)= Region %d" vfio_migration_set_state(char *name, uint32_t state) " (%s) state %d" vfio_vmstate_change(char *name, int running, const char *reason, uint32_t = dev_state) " (%s) running %d reason %s device state %d" vfio_migration_state_notifier(char *name, int state) " (%s) state %d" +vfio_save_setup(char *name) " (%s)" +vfio_save_cleanup(char *name) " (%s)" --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086401; cv=none; d=zohomail.com; s=zohoarc; b=jRI1RctaXqxlcuc7cQFrYiGrpIo6NLnLrHhU5LOgkwngayKlu2rFM5wu8WD9xkq+8Cgu3OM5eQxooDfaqA2XYCRZfitYtYYG2WMAIAg6ddUuLWrlZcK4jeddTOw4vQVEkiN0pr7mtsBmP3GAZiKU/azKCZoSKsmlXlYYAzE0QN4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086401; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=WX+IDzpXbpZW5h3DOnUfE6k8Ct0YzZaGL0Np8BubK8A=; b=O4QczFlcDZR4xQY2/oHfGJRbXhZsrUs+I4hpXZY7VsKXDQjrAplQjMhw7IeFCmVOHsNxc1H59kuzdtpMIbdVLYDOw9fsXIGBN5g8TU2nDFG7Chi/8vhlOYpsia3TOxYFS20wxg7lKaroJnLYeD0xYh/NBDRnSC5riikSjr0duFM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086401546578.5533748855369; Tue, 24 Mar 2020 14:46:41 -0700 (PDT) Received: from localhost ([::1]:55570 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrNg-00026j-2V for importer@patchew.org; Tue, 24 Mar 2020 17:46:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38831) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrKs-0006n4-BA for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrKq-0004pU-Cm for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:46 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6152) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrKq-0004p3-70 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:44 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:43:29 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:43 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:42 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:34 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 24 Mar 2020 14:43:43 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 09/16] vfio: Add save state functions to SaveVMHandlers Date: Wed, 25 Mar 2020 02:39:07 +0530 Message-ID: <1585084154-29461-10-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086209; bh=WX+IDzpXbpZW5h3DOnUfE6k8Ct0YzZaGL0Np8BubK8A=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=CQuFhgJg63tMQyZ/PsZsEkL5rFV6LBA3WK+faHgZl3U236seMW05i4no3+etDWOwS KPfsiE6bF1+lCfjFlXrLDfOLbETglb+TC5aOrT5tE8fSn0BOCH42zrJtL8O0S2T3zy a6NAkZ18jDbjFyhmRuBd3ipdi/CAGgL11grvXSN6LTIedHCkO//5H7NU+GruA+NqYS 0eyYeMwkBgILvFjqtp4gbz8O0/KEk4x4ujg+svPIXGLGn8YIMaR9UvpGSzNvob6TXP UeEtENcmwI1RivyJAjOW9WDzD7PG2GG2DcTHRKTQ4xAdO9JA1CqqVQxcyVHXdYinC8 hvTFLA00ajfng== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Added .save_live_pending, .save_live_iterate and .save_live_complete_precopy functions. These functions handles pre-copy and stop-and-copy phase. In _SAVING|_RUNNING device state or pre-copy phase: - read pending_bytes. If pending_bytes > 0, go through below steps. - read data_offset - indicates kernel driver to write data to staging buffer. - read data_size - amount of data in bytes written by vendor driver in migration region. - read data_size bytes of data from data_offset in the migration region. - Write data packet to file stream as below: {VFIO_MIG_FLAG_DEV_DATA_STATE, data_size, actual data, VFIO_MIG_FLAG_END_OF_STATE } In _SAVING device state or stop-and-copy phase a. read config space of device and save to migration file stream. This doesn't need to be from vendor driver. Any other special config state from driver can be saved as data in following iteration. b. read pending_bytes. If pending_bytes > 0, go through below steps. c. read data_offset - indicates kernel driver to write data to staging buffer. d. read data_size - amount of data in bytes written by vendor driver in migration region. e. read data_size bytes of data from data_offset in the migration region. f. Write data packet as below: {VFIO_MIG_FLAG_DEV_DATA_STATE, data_size, actual data} g. iterate through steps b to f while (pending_bytes > 0) h. Write {VFIO_MIG_FLAG_END_OF_STATE} When data region is mapped, its user's responsibility to read data from data_offset of data_size before moving to next steps. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/migration.c | 245 ++++++++++++++++++++++++++++++++++++++= +++- hw/vfio/trace-events | 6 ++ include/hw/vfio/vfio-common.h | 1 + 3 files changed, 251 insertions(+), 1 deletion(-) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 033f76526e49..ecbeed5182c2 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -138,6 +138,137 @@ static int vfio_migration_set_state(VFIODevice *vbase= dev, uint32_t mask, return 0; } =20 +static void *find_data_region(VFIORegion *region, + uint64_t data_offset, + uint64_t data_size) +{ + void *ptr =3D NULL; + int i; + + for (i =3D 0; i < region->nr_mmaps; i++) { + if ((data_offset >=3D region->mmaps[i].offset) && + (data_offset < region->mmaps[i].offset + region->mmaps[i].size= ) && + (data_size <=3D region->mmaps[i].size)) { + ptr =3D region->mmaps[i].mmap + (data_offset - + region->mmaps[i].offset); + break; + } + } + return ptr; +} + +static int vfio_save_buffer(QEMUFile *f, VFIODevice *vbasedev) +{ + VFIOMigration *migration =3D vbasedev->migration; + VFIORegion *region =3D &migration->region; + uint64_t data_offset =3D 0, data_size =3D 0; + int ret; + + ret =3D pread(vbasedev->fd, &data_offset, sizeof(data_offset), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + data_offset)); + if (ret !=3D sizeof(data_offset)) { + error_report("%s: Failed to get migration buffer data offset %d", + vbasedev->name, ret); + return -EINVAL; + } + + ret =3D pread(vbasedev->fd, &data_size, sizeof(data_size), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + data_size)); + if (ret !=3D sizeof(data_size)) { + error_report("%s: Failed to get migration buffer data size %d", + vbasedev->name, ret); + return -EINVAL; + } + + if (data_size > 0) { + void *buf =3D NULL; + bool buffer_mmaped; + + if (region->mmaps) { + buf =3D find_data_region(region, data_offset, data_size); + } + + buffer_mmaped =3D (buf !=3D NULL) ? true : false; + + if (!buffer_mmaped) { + buf =3D g_try_malloc0(data_size); + if (!buf) { + error_report("%s: Error allocating buffer ", __func__); + return -ENOMEM; + } + + ret =3D pread(vbasedev->fd, buf, data_size, + region->fd_offset + data_offset); + if (ret !=3D data_size) { + error_report("%s: Failed to get migration data %d", + vbasedev->name, ret); + g_free(buf); + return -EINVAL; + } + } + + qemu_put_be64(f, data_size); + qemu_put_buffer(f, buf, data_size); + + if (!buffer_mmaped) { + g_free(buf); + } + } else { + qemu_put_be64(f, data_size); + } + + trace_vfio_save_buffer(vbasedev->name, data_offset, data_size, + migration->pending_bytes); + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + + return data_size; +} + +static int vfio_update_pending(VFIODevice *vbasedev) +{ + VFIOMigration *migration =3D vbasedev->migration; + VFIORegion *region =3D &migration->region; + uint64_t pending_bytes =3D 0; + int ret; + + ret =3D pread(vbasedev->fd, &pending_bytes, sizeof(pending_bytes), + region->fd_offset + offsetof(struct vfio_device_migration_= info, + pending_bytes)); + if ((ret < 0) || (ret !=3D sizeof(pending_bytes))) { + error_report("%s: Failed to get pending bytes %d", + vbasedev->name, ret); + migration->pending_bytes =3D 0; + return (ret < 0) ? ret : -EINVAL; + } + + migration->pending_bytes =3D pending_bytes; + trace_vfio_update_pending(vbasedev->name, pending_bytes); + return 0; +} + +static int vfio_save_device_config_state(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_CONFIG_STATE); + + if (vbasedev->ops && vbasedev->ops->vfio_save_config) { + vbasedev->ops->vfio_save_config(vbasedev, f); + } + + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); + + trace_vfio_save_device_config_state(vbasedev->name); + + return qemu_file_get_error(f); +} + /* ---------------------------------------------------------------------- = */ =20 static int vfio_save_setup(QEMUFile *f, void *opaque) @@ -154,7 +285,7 @@ static int vfio_save_setup(QEMUFile *f, void *opaque) qemu_mutex_unlock_iothread(); if (ret) { error_report("%s: Failed to mmap VFIO migration region %d: %s", - vbasedev->name, migration->region.index, + vbasedev->name, migration->region.nr, strerror(-ret)); return ret; } @@ -194,9 +325,121 @@ static void vfio_save_cleanup(void *opaque) trace_vfio_save_cleanup(vbasedev->name); } =20 +static void vfio_save_pending(QEMUFile *f, void *opaque, + uint64_t threshold_size, + uint64_t *res_precopy_only, + uint64_t *res_compatible, + uint64_t *res_postcopy_only) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret; + + ret =3D vfio_update_pending(vbasedev); + if (ret) { + return; + } + + *res_precopy_only +=3D migration->pending_bytes; + + trace_vfio_save_pending(vbasedev->name, *res_precopy_only, + *res_postcopy_only, *res_compatible); +} + +static int vfio_save_iterate(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + int ret, data_size; + + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE); + + data_size =3D vfio_save_buffer(f, vbasedev); + + if (data_size < 0) { + error_report("%s: vfio_save_buffer failed %s", vbasedev->name, + strerror(errno)); + return data_size; + } + + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + + trace_vfio_save_iterate(vbasedev->name, data_size); + if (data_size =3D=3D 0) { + /* indicates data finished, goto complete phase */ + return 1; + } + + return 0; +} + +static int vfio_save_complete_precopy(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret; + + ret =3D vfio_migration_set_state(vbasedev, ~VFIO_DEVICE_STATE_RUNNING, + VFIO_DEVICE_STATE_SAVING); + if (ret) { + error_report("%s: Failed to set state STOP and SAVING", + vbasedev->name); + return ret; + } + + ret =3D vfio_save_device_config_state(f, opaque); + if (ret) { + return ret; + } + + ret =3D vfio_update_pending(vbasedev); + if (ret) { + return ret; + } + + while (migration->pending_bytes > 0) { + qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE); + ret =3D vfio_save_buffer(f, vbasedev); + if (ret < 0) { + error_report("%s: Failed to save buffer", vbasedev->name); + return ret; + } else if (ret =3D=3D 0) { + break; + } + + ret =3D vfio_update_pending(vbasedev); + if (ret) { + return ret; + } + } + + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + + ret =3D vfio_migration_set_state(vbasedev, ~VFIO_DEVICE_STATE_SAVING, = 0); + if (ret) { + error_report("%s: Failed to set state STOPPED", vbasedev->name); + return ret; + } + + trace_vfio_save_complete_precopy(vbasedev->name); + return ret; +} + static SaveVMHandlers savevm_vfio_handlers =3D { .save_setup =3D vfio_save_setup, .save_cleanup =3D vfio_save_cleanup, + .save_live_pending =3D vfio_save_pending, + .save_live_iterate =3D vfio_save_iterate, + .save_live_complete_precopy =3D vfio_save_complete_precopy, }; =20 /* ---------------------------------------------------------------------- = */ diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 4bb43f18f315..bdf40ba368c7 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -151,3 +151,9 @@ vfio_vmstate_change(char *name, int running, const char= *reason, uint32_t dev_st vfio_migration_state_notifier(char *name, int state) " (%s) state %d" vfio_save_setup(char *name) " (%s)" vfio_save_cleanup(char *name) " (%s)" +vfio_save_buffer(char *name, uint64_t data_offset, uint64_t data_size, uin= t64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 +vfio_update_pending(char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 +vfio_save_device_config_state(char *name) " (%s)" +vfio_save_pending(char *name, uint64_t precopy, uint64_t postcopy, uint64_= t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x= %"PRIx64 +vfio_save_iterate(char *name, int data_size) " (%s) data_size %d" +vfio_save_complete_precopy(char *name) " (%s)" diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index 28f55f66d019..c78033e4149d 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -60,6 +60,7 @@ typedef struct VFIORegion { =20 typedef struct VFIOMigration { VFIORegion region; + uint64_t pending_bytes; } VFIOMigration; =20 typedef struct VFIOAddressSpace { --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086516; cv=none; d=zohomail.com; s=zohoarc; b=Ga5YE3DwhiBWZmc18s9BJtxisvLrsi3KdBLzpN3x/IuGi85AOq2pQb4JJFHcH8ucCQ5C8QcoTOUaC7McoepA/KMm4PzwLh6tP99dKOL6Z2jCW2TPW/zirWaL4q1vbooUDxDmCbKS75kCsL1K5mwg3ubrRce7gRDzaR51ImN9ZS0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086516; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=NTmAM2GFSQjwnNXNGskV1u0RqowuPVQaq9tEMQqrqlk=; b=lvCsgmXtW5n9xjiBXiS5fCjnYs9lrCc9R24Y0/26EdmzLw4W6Afxo9qF8w/6ipA8Dr7laqvMt3lyDGCtfbGiftr+I/bZ3uNGCpppoQRKJqojhEsOloiYvDIoQiXqlVqh+bCJswWfb0Qc30Gy1PilV4DSyYN72pGq2S/RIC5K4UM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158508651666031.206528263165524; Tue, 24 Mar 2020 14:48:36 -0700 (PDT) Received: from localhost ([::1]:55612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrPX-0004oF-CF for importer@patchew.org; Tue, 24 Mar 2020 17:48:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38875) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrKy-00071c-La for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrKx-0004s7-4H for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:52 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8879) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrKw-0004rq-UM for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:51 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:43:04 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:49 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:49 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:42 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:43:49 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 10/16] vfio: Add load state functions to SaveVMHandlers Date: Wed, 25 Mar 2020 02:39:08 +0530 Message-ID: <1585084154-29461-11-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086185; bh=NTmAM2GFSQjwnNXNGskV1u0RqowuPVQaq9tEMQqrqlk=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=KvyoWvoYmYR1xtRcijHOLuKjw6W9M1ZUi+oF+k+WHcqq8mo4WoyCZ0ADp1za+gqsD /viXs/zA028F0MVlTWcG0CJSZb1kwuc4RaY70nzAQyTX/FWROYI0NHyJhSf6Z97CSc 2QkTm+99Sf4eiNNfTWQZrySvSSQA/KYJW20LzJ9h7nvTGYZjKHqhw0h+XYfvFSvtUS 1vMATpkRvuypucnPkOmOrvTmXZ0sCfcNLBm6oNHfbEP/qiOeS6iKsu8bxR0syKuRoU ryO5b4gczocmed5oID31I2lHgvZ6u6lkcienKAF+j+jT4FVy9t+L7BZ4tSf4UFSMRI 4RRVPx3igT0lA== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Sequence during _RESUMING device state: While data for this device is available, repeat below steps: a. read data_offset from where user application should write data. b. write data of data_size to migration region from data_offset. c. write data_size which indicates vendor driver that data is written in staging buffer. For user, data is opaque. User should write data in the same order as received. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/migration.c | 179 +++++++++++++++++++++++++++++++++++++++++++++++= ++++ hw/vfio/trace-events | 3 + 2 files changed, 182 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index ecbeed5182c2..ab295d25620e 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -269,6 +269,33 @@ static int vfio_save_device_config_state(QEMUFile *f, = void *opaque) return qemu_file_get_error(f); } =20 +static int vfio_load_device_config_state(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + uint64_t data; + + if (vbasedev->ops && vbasedev->ops->vfio_load_config) { + int ret; + + ret =3D vbasedev->ops->vfio_load_config(vbasedev, f); + if (ret) { + error_report("%s: Failed to load device config space", + vbasedev->name); + return ret; + } + } + + data =3D qemu_get_be64(f); + if (data !=3D VFIO_MIG_FLAG_END_OF_STATE) { + error_report("%s: Failed loading device config space, " + "end flag incorrect 0x%"PRIx64, vbasedev->name, data); + return -EINVAL; + } + + trace_vfio_load_device_config_state(vbasedev->name); + return qemu_file_get_error(f); +} + /* ---------------------------------------------------------------------- = */ =20 static int vfio_save_setup(QEMUFile *f, void *opaque) @@ -434,12 +461,164 @@ static int vfio_save_complete_precopy(QEMUFile *f, v= oid *opaque) return ret; } =20 +static int vfio_load_setup(QEMUFile *f, void *opaque) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret =3D 0; + + if (migration->region.mmaps) { + ret =3D vfio_region_mmap(&migration->region); + if (ret) { + error_report("%s: Failed to mmap VFIO migration region %d: %s", + vbasedev->name, migration->region.nr, + strerror(-ret)); + return ret; + } + } + + ret =3D vfio_migration_set_state(vbasedev, ~0, VFIO_DEVICE_STATE_RESUM= ING); + if (ret) { + error_report("%s: Failed to set state RESUMING", vbasedev->name); + } + return ret; +} + +static int vfio_load_cleanup(void *opaque) +{ + vfio_save_cleanup(opaque); + return 0; +} + +static int vfio_load_state(QEMUFile *f, void *opaque, int version_id) +{ + VFIODevice *vbasedev =3D opaque; + VFIOMigration *migration =3D vbasedev->migration; + int ret =3D 0; + uint64_t data, data_size; + + data =3D qemu_get_be64(f); + while (data !=3D VFIO_MIG_FLAG_END_OF_STATE) { + + trace_vfio_load_state(vbasedev->name, data); + + switch (data) { + case VFIO_MIG_FLAG_DEV_CONFIG_STATE: + { + ret =3D vfio_load_device_config_state(f, opaque); + if (ret) { + return ret; + } + break; + } + case VFIO_MIG_FLAG_DEV_SETUP_STATE: + { + uint64_t region_size =3D qemu_get_be64(f); + + if (migration->region.size < region_size) { + error_report("%s: SETUP STATE: migration region too small,= " + "0x%"PRIx64 " < 0x%"PRIx64, vbasedev->name, + migration->region.size, region_size); + return -EINVAL; + } + + data =3D qemu_get_be64(f); + if (data =3D=3D VFIO_MIG_FLAG_END_OF_STATE) { + return ret; + } else { + error_report("%s: SETUP STATE: EOS not found 0x%"PRIx64, + vbasedev->name, data); + return -EINVAL; + } + break; + } + case VFIO_MIG_FLAG_DEV_DATA_STATE: + { + VFIORegion *region =3D &migration->region; + void *buf =3D NULL; + bool buffer_mmaped =3D false; + uint64_t data_offset =3D 0; + + data_size =3D qemu_get_be64(f); + if (data_size =3D=3D 0) { + break; + } + + ret =3D pread(vbasedev->fd, &data_offset, sizeof(data_offset), + region->fd_offset + + offsetof(struct vfio_device_migration_info, + data_offset)); + if (ret !=3D sizeof(data_offset)) { + error_report("%s:Failed to get migration buffer data offse= t %d", + vbasedev->name, ret); + return -EINVAL; + } + + if (region->mmaps) { + buf =3D find_data_region(region, data_offset, data_size); + } + + buffer_mmaped =3D (buf !=3D NULL) ? true : false; + + if (!buffer_mmaped) { + buf =3D g_try_malloc0(data_size); + if (!buf) { + error_report("%s: Error allocating buffer ", __func__); + return -ENOMEM; + } + } + + qemu_get_buffer(f, buf, data_size); + + if (!buffer_mmaped) { + ret =3D pwrite(vbasedev->fd, buf, data_size, + region->fd_offset + data_offset); + g_free(buf); + + if (ret !=3D data_size) { + error_report("%s: Failed to set migration buffer %d", + vbasedev->name, ret); + return -EINVAL; + } + } + + ret =3D pwrite(vbasedev->fd, &data_size, sizeof(data_size), + region->fd_offset + + offsetof(struct vfio_device_migration_info, data_si= ze)); + if (ret !=3D sizeof(data_size)) { + error_report("%s: Failed to set migration buffer data size= %d", + vbasedev->name, ret); + if (!buffer_mmaped) { + g_free(buf); + } + return -EINVAL; + } + + trace_vfio_load_state_device_data(vbasedev->name, data_offset, + data_size); + break; + } + } + + ret =3D qemu_file_get_error(f); + if (ret) { + return ret; + } + data =3D qemu_get_be64(f); + } + + return ret; +} + static SaveVMHandlers savevm_vfio_handlers =3D { .save_setup =3D vfio_save_setup, .save_cleanup =3D vfio_save_cleanup, .save_live_pending =3D vfio_save_pending, .save_live_iterate =3D vfio_save_iterate, .save_live_complete_precopy =3D vfio_save_complete_precopy, + .load_setup =3D vfio_load_setup, + .load_cleanup =3D vfio_load_cleanup, + .load_state =3D vfio_load_state, }; =20 /* ---------------------------------------------------------------------- = */ diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index bdf40ba368c7..ac065b559f4e 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -157,3 +157,6 @@ vfio_save_device_config_state(char *name) " (%s)" vfio_save_pending(char *name, uint64_t precopy, uint64_t postcopy, uint64_= t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x= %"PRIx64 vfio_save_iterate(char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(char *name) " (%s)" +vfio_load_device_config_state(char *name) " (%s)" +vfio_load_state(char *name, uint64_t data) " (%s) data 0x%"PRIx64 +vfio_load_state_device_data(char *name, uint64_t data_offset, uint64_t dat= a_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086593; cv=none; d=zohomail.com; s=zohoarc; b=EkTusPGWHAbv2vsvphfvQ5dHgURMlU1x7GW9qGa281lZpJrHodnLQncHV/e1deQcrvYiH8VA0XdhasPPPDnxSD4GvLM4zGVylINfL81r1nh8IcwxDDmgiDj07IAd+rWUuYfol6CDDYKRn/DDsWkTHXWAKjwQmW7Qk7Br1GdamUk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086593; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=SGokuzyK15XQbSaJXhwUASXV/zbDfGbkpeQEfjLqKAI=; b=URWNaxFDskG5filqEPAFn8O2puiy0uRGWTiznTDwp8OvZQUOeTDzFV503+afn0JG65TKPVqhma8MbJiuWaPMd3fNc0/f5TIfDOyX9qAxVXgYF0WTkb5PrSJJMtRzMUFbzKI4KJP5NHn6DKDuAfjxjHtQr3XZDUIoqiCb2LU1U6Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158508659333523.49623597195898; Tue, 24 Mar 2020 14:49:53 -0700 (PDT) Received: from localhost ([::1]:55648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrQm-0006v6-4J for importer@patchew.org; Tue, 24 Mar 2020 17:49:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38904) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrL4-000786-PN for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrL3-0004uL-Ft for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:58 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6168) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrL3-0004tz-A2 for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:43:57 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:43:42 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:43:56 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:43:55 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:49 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:43:56 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 11/16] iommu: add callback to get address limit IOMMU supports Date: Wed, 25 Mar 2020 02:39:09 +0530 Message-ID: <1585084154-29461-12-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086222; bh=SGokuzyK15XQbSaJXhwUASXV/zbDfGbkpeQEfjLqKAI=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=MCicwBYxJjtyhMDu6Y2/LnJEGNLTAVz6iSt0fSxqGMSIZCgsaatBP8wiIHoexxdvX rWZR3J46x33I+6rK1Sxb97LrpUPwTVM+kNUQdsd6JYIqIH6FZc2cGfVv6jEYo5LBcr pV89nvD/tFIglV7wNgS8g5bZQysqqyO4Sgcs2kkr6uSsZ6oAe5zi5ULvcYQO7QQQqh vjFBkgrYlOx08aNUuf5gX87P/HXXmg3i10xwF9HeCQGZXJ/9lvFEJ8MVns9pJEPmSF QI3SpvemY9BnwckOKobF/3I/i/6GzO4/TzbSySdMLhdPODYiuXXAdPQ7wjKvUadrzz hYaufXVeALMRA== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add optional method to get address limit IOMMU supports Signed-off-by: Kirti Wankhede --- hw/i386/intel_iommu.c | 9 +++++++++ include/exec/memory.h | 19 +++++++++++++++++++ memory.c | 11 +++++++++++ 3 files changed, 39 insertions(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index df7ad254ac15..d0b88c20c31e 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3577,6 +3577,14 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iomm= u_mr, IOMMUNotifier *n) return; } =20 +static hwaddr vtd_iommu_get_address_limit(IOMMUMemoryRegion *iommu_mr) +{ + VTDAddressSpace *vtd_as =3D container_of(iommu_mr, VTDAddressSpace, io= mmu); + IntelIOMMUState *s =3D vtd_as->iommu_state; + + return VTD_ADDRESS_SIZE(s->aw_bits) - 1; +} + /* Do the initialization. It will also be called when reset, so pay * attention when adding new initialization stuff. */ @@ -3878,6 +3886,7 @@ static void vtd_iommu_memory_region_class_init(Object= Class *klass, imrc->translate =3D vtd_iommu_translate; imrc->notify_flag_changed =3D vtd_iommu_notify_flag_changed; imrc->replay =3D vtd_iommu_replay; + imrc->get_address_limit =3D vtd_iommu_get_address_limit; } =20 static const TypeInfo vtd_iommu_memory_region_info =3D { diff --git a/include/exec/memory.h b/include/exec/memory.h index 1614d9a02c0c..f7d92bf6e6a9 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -355,6 +355,17 @@ typedef struct IOMMUMemoryRegionClass { * @iommu: the IOMMUMemoryRegion */ int (*num_indexes)(IOMMUMemoryRegion *iommu); + + /* + * Return address limit this IOMMU supports. + * + * Optional method: if this method is not provided, then + * memory_region_iommu_address_limit() will return the limit which inp= ut + * argument to this function. + * + * @iommu: the IOMMUMemoryRegion + */ + hwaddr (*get_address_limit)(IOMMUMemoryRegion *iommu); } IOMMUMemoryRegionClass; =20 typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -1364,6 +1375,14 @@ int memory_region_iommu_attrs_to_index(IOMMUMemoryRe= gion *iommu_mr, int memory_region_iommu_num_indexes(IOMMUMemoryRegion *iommu_mr); =20 /** + * memory_region_iommu_get_address_limit : return the maximum address limit + * that this IOMMU supports. + * + * @iommu_mr: the memory region + */ +hwaddr memory_region_iommu_get_address_limit(IOMMUMemoryRegion *iommu_mr, + hwaddr limit); +/** * memory_region_name: get a memory region's name * * Returns the string that was used to initialize the memory region. diff --git a/memory.c b/memory.c index 601b74990620..acb7546971c3 100644 --- a/memory.c +++ b/memory.c @@ -1887,6 +1887,17 @@ void memory_region_iommu_replay(IOMMUMemoryRegion *i= ommu_mr, IOMMUNotifier *n) } } =20 +hwaddr memory_region_iommu_get_address_limit(IOMMUMemoryRegion *iommu_mr, + hwaddr limit) +{ + IOMMUMemoryRegionClass *imrc =3D IOMMU_MEMORY_REGION_GET_CLASS(iommu_m= r); + + if (imrc->get_address_limit) { + return imrc->get_address_limit(iommu_mr); + } + return limit; +} + void memory_region_unregister_iommu_notifier(MemoryRegion *mr, IOMMUNotifier *n) { --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086394; cv=none; d=zohomail.com; s=zohoarc; b=IVtlrkT5ZXg8YTU2g+HzcAj++zN3uJJ4qeooartq9s5hM+jsf2kJ4sc/vsogUWqDzciuD2ba0fSjlBQp2SxZVdMTLoaXSUSrf5vC4KfxVwAyR6z/8JSyC9zRo7igxXrBVERaZdE7Rdi3IiP7crdKprb9T+1YADXQh/odSbgDfSU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086394; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5enwOLQUs3mOZ9vXJXPKczJKjLtl0ueXpgpQhr+I2rU=; b=MTchmFpjn34jnjzEtL3W3TfvES/cjHJXJ/lAEH8Ws6KI3yfm9jgvkSUbTLrVi5oMZzLaezKbQGV33avQ6YWyxDRIPYZ6+qCQLKiru62FgVtQTNtRd8jN8j0U24BvFjHcCvOg0ZPbE8+yTMrPtyPfKqEvTBryAg+yTEN96QhYzkg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086394834777.6803005447729; Tue, 24 Mar 2020 14:46:34 -0700 (PDT) Received: from localhost ([::1]:55566 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrNZ-0001sI-Gz for importer@patchew.org; Tue, 24 Mar 2020 17:46:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38917) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrLA-0007NZ-Ln for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:05 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrL9-0004vn-MZ for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:04 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6178) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrL9-0004vX-Gb for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:03 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:43:49 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:44:02 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:44:02 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:43:56 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 24 Mar 2020 14:44:02 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 12/16] memory: Set DIRTY_MEMORY_MIGRATION when IOMMU is enabled Date: Wed, 25 Mar 2020 02:39:10 +0530 Message-ID: <1585084154-29461-13-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086229; bh=5enwOLQUs3mOZ9vXJXPKczJKjLtl0ueXpgpQhr+I2rU=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=Q7b+HjzhcpRn3ZLnwp8cVvRgG/GXdobIfntleZocZhcuQnN736DZIa9BviBpkQjoy HVsC9R37OE6aHaLrFUNk0p87xF5BsCE5uvZqAiGkUtmZpVFU88IPmq4XPQagYteYdX DphOTDdqaq0qqx7iZgirV27xB663bD/Q4kw4/gw8hbgMYX1ocAauImG0GHDc4KP0Ca SnMYSMK1PXnSCncNyef5zUjmvEWvi0MD6kQh5qRPDHksYZSq8npG3CEQPXnhKHhoB+ ejiBF/7CiFnwGEhRyr5aeFwF0rt4DWyrcLTKTbBWh07aSXum57Rm8Hnm+E23dFxQLc 7+HGKYnsNqflw== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Kirti Wankhede --- memory.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memory.c b/memory.c index acb7546971c3..285ca2ed6dd9 100644 --- a/memory.c +++ b/memory.c @@ -1788,7 +1788,7 @@ bool memory_region_is_ram_device(MemoryRegion *mr) uint8_t memory_region_get_dirty_log_mask(MemoryRegion *mr) { uint8_t mask =3D mr->dirty_log_mask; - if (global_dirty_log && mr->ram_block) { + if (global_dirty_log && (mr->ram_block || memory_region_is_iommu(mr)))= { mask |=3D (1 << DIRTY_MEMORY_MIGRATION); } return mask; --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086634; cv=none; d=zohomail.com; s=zohoarc; b=l7fZhcG6npfrW44eieoWcy3KJ88KkTAT9ObDHOCmWTh/orOfIj29uO9MXcVJ7rxBMYM9DXKP/a9opdTj2IuMPdrplcKasE45GnJ8UWVthm/3L9h1OvQYk9YfJLb7JaTBMvL3G7e/HevsXFmn6H6Fp0k59AxJV0yaRCqGjf9UwOs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086634; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wjRihxROOTpvB/Z5jHeyJNR8v5ig3rWfHPf4/d4XhVk=; b=Ezh45Px0BSV3wz/GudwOA9k1zLiPirno5cbpvAc00CPHgW7ZDJ7A73R2FCoZWtHdmcuDJFo9vQXdGeIDWYTArap7VBKMWcS4ftEPcnt+FuHO5I26MGCNUNfxDKep8eeH5RVF9IrovvJTjvJqFdhuAmbE5Hp68LMMKPfeBbl3SMY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086634891337.3528148565673; Tue, 24 Mar 2020 14:50:34 -0700 (PDT) Received: from localhost ([::1]:55662 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrRR-0007ym-Gf for importer@patchew.org; Tue, 24 Mar 2020 17:50:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38936) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrLH-0007fV-CN for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrLG-0004zW-8N for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:11 -0400 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:6595) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrLG-0004yx-2q for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:10 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:42:38 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:44:08 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:44:08 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:44:02 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:44:08 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 13/16] vfio: Add function to start and stop dirty pages tracking Date: Wed, 25 Mar 2020 02:39:11 +0530 Message-ID: <1585084154-29461-14-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086158; bh=wjRihxROOTpvB/Z5jHeyJNR8v5ig3rWfHPf4/d4XhVk=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=Kg299gkiwT+BIKB+b9cqWQpbSk70NaNgFoO7dlD+NJBP5MI5mO/mhPf6PEtC2qX/N 5NMenMVPCsrFD91RfJbu6fb2LeK8OfXsGmdB7qUkwRsS9zUziThTZgkofkfKR8l9Of nxYhLdCaVmBF1W6RKrMdWd52VIKNQLTwraLZkOW47BX4KT3eadFjnits7A/3qPZA9s uVphztZLx+i18ZLeOfGhXk8YmR3V21/26RFHE0wEeBx+umAYxFWAf2vaQ/a6F+hgxL qeYRsqB8ZAcjwOJw7SDnb1DTHWrmZGzQAFPsMDIL4x6QPtzSQd00D8Ka/mGDYkQBzz 3b7uEr6wnpoaA== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.143 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Call VFIO_IOMMU_DIRTY_PAGES ioctl to start and stop dirty pages tracking for VFIO devices. Signed-off-by: Kirti Wankhede --- hw/vfio/migration.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index ab295d25620e..1827b7cfb316 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -9,6 +9,7 @@ =20 #include "qemu/osdep.h" #include "qemu/main-loop.h" +#include #include =20 #include "sysemu/runstate.h" @@ -296,6 +297,32 @@ static int vfio_load_device_config_state(QEMUFile *f, = void *opaque) return qemu_file_get_error(f); } =20 +static int vfio_start_dirty_page_tracking(VFIODevice *vbasedev, bool start) +{ + int ret; + VFIOContainer *container =3D vbasedev->group->container; + struct vfio_iommu_type1_dirty_bitmap dirty =3D { + .argsz =3D sizeof(dirty), + }; + + if (start) { + if (vbasedev->device_state & VFIO_DEVICE_STATE_SAVING) { + dirty.flags =3D VFIO_IOMMU_DIRTY_PAGES_FLAG_START; + } else { + return 0; + } + } else { + dirty.flags =3D VFIO_IOMMU_DIRTY_PAGES_FLAG_STOP; + } + + ret =3D ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, &dirty); + if (ret) { + error_report("Failed to set dirty tracking flag 0x%x errno: %d", + dirty.flags, errno); + } + return ret; +} + /* ---------------------------------------------------------------------- = */ =20 static int vfio_save_setup(QEMUFile *f, void *opaque) @@ -330,6 +357,11 @@ static int vfio_save_setup(QEMUFile *f, void *opaque) */ qemu_put_be64(f, migration->region.size); =20 + ret =3D vfio_start_dirty_page_tracking(vbasedev, true); + if (ret) { + return ret; + } + qemu_put_be64(f, VFIO_MIG_FLAG_END_OF_STATE); =20 ret =3D qemu_file_get_error(f); @@ -346,6 +378,8 @@ static void vfio_save_cleanup(void *opaque) VFIODevice *vbasedev =3D opaque; VFIOMigration *migration =3D vbasedev->migration; =20 + vfio_start_dirty_page_tracking(vbasedev, false); + if (migration->region.mmaps) { vfio_region_unmap(&migration->region); } @@ -669,6 +703,8 @@ static void vfio_migration_state_notifier(Notifier *not= ifier, void *data) if (ret) { error_report("%s: Failed to set state RUNNING", vbasedev->name= ); } + + vfio_start_dirty_page_tracking(vbasedev, false); } } =20 --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086717; cv=none; d=zohomail.com; s=zohoarc; b=cCf8tXOJuwQSzFc5tFJPTZQz5TUQROKPVdzID2+/NLiKpO9YjKVnglAsN0JMRR5fXe121bWizVry6qzOjRqmVryPGUQw7DEV2Yfm8JgE7t2umsvB+EXMRmJQh3CkQeFexOFIpqaZ8khuk7oY9jjiBOgwobeZ3QNfhdKmakflsrw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086717; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=p0KOGL805FbEk/o7TaSs5/jMZEpVN73/mLs5xwyth/4=; b=Ea6uL5syptut/fhOWYs5azqcfo32e/wTOjkI2XhnC/uURfuym9sG5wrQ0TXLYYZr1iV/rdhWA1wJ5EH+D2FtfJKvU94oQiJAydWHcfCvu7U/DwXJY1UrMlPjg1EuIWGBkxqw3sGmvUozrK3TxhsmQoOihICy4eP/exCbC/ND3ro= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086717958346.5336740485801; Tue, 24 Mar 2020 14:51:57 -0700 (PDT) Received: from localhost ([::1]:55706 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrSl-0001Z5-Ex for importer@patchew.org; Tue, 24 Mar 2020 17:51:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38949) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrLO-0007xI-Ju for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrLN-00051F-1Z for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:18 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6191) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrLM-000511-RZ for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:16 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:44:02 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:44:15 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:44:15 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:44:08 +0000 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 24 Mar 2020 14:44:15 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 14/16] vfio: Add vfio_listener_log_sync to mark dirty pages Date: Wed, 25 Mar 2020 02:39:12 +0530 Message-ID: <1585084154-29461-15-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086242; bh=p0KOGL805FbEk/o7TaSs5/jMZEpVN73/mLs5xwyth/4=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=e46DUAQI0/JK1qb80hEyrzhABXccixyCaT1wwCUNCMSYTOhfbrBuqmZPLg9sE5Hls L79p3sBqZEI8dJ8YJIADOq4hI1RjzikMsUHN0G0CwwhPwBvE+9eBQGimgBcCK3YmQJ 86m9vajG124Oo++gB1Gb7FIZIA34BE4o7J6dptpnirihDeZWOFp4HTX2lP9K/8qIWZ ljDKJ6aVARtvzXbGYXv7tHJIdLf7fU8IxzDB1ebv57NYUG6j8vgvPwasY84zwPMEYb 7ZNtCGGcNjAV0z/9FP8+kMwqmRUlX4c+ZUJ9ReBcm7MylGqUiefBHkONaio761E5LZ QBePu3328NHZA== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" vfio_listener_log_sync gets list of dirty pages from container using VFIO_IOMMU_GET_DIRTY_BITMAP ioctl and mark those pages dirty when all devices are stopped and saving state. Return early for the RAM block section of mapped MMIO region. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/common.c | 200 +++++++++++++++++++++++++++++++++++++++++++++++= ++-- hw/vfio/trace-events | 1 + 2 files changed, 196 insertions(+), 5 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 4a2f0d6a2233..6d41e1ac5c2f 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -29,6 +29,7 @@ #include "hw/vfio/vfio.h" #include "exec/address-spaces.h" #include "exec/memory.h" +#include "exec/ram_addr.h" #include "hw/hw.h" #include "qemu/error-report.h" #include "qemu/main-loop.h" @@ -38,6 +39,7 @@ #include "sysemu/reset.h" #include "trace.h" #include "qapi/error.h" +#include "migration/migration.h" =20 VFIOGroupList vfio_group_list =3D QLIST_HEAD_INITIALIZER(vfio_group_list); @@ -288,6 +290,28 @@ const MemoryRegionOps vfio_region_ops =3D { }; =20 /* + * Device state interfaces + */ + +static bool vfio_devices_are_stopped_and_saving(void) +{ + VFIOGroup *group; + VFIODevice *vbasedev; + + QLIST_FOREACH(group, &vfio_group_list, next) { + QLIST_FOREACH(vbasedev, &group->device_list, next) { + if ((vbasedev->device_state & VFIO_DEVICE_STATE_SAVING) && + !(vbasedev->device_state & VFIO_DEVICE_STATE_RUNNING)) { + continue; + } else { + return false; + } + } + } + return true; +} + +/* * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86 */ static int vfio_dma_unmap(VFIOContainer *container, @@ -408,8 +432,8 @@ static bool vfio_listener_skipped_section(MemoryRegionS= ection *section) } =20 /* Called with rcu_read_lock held. */ -static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void **vaddr, - bool *read_only) +static bool vfio_get_xlat_addr(IOMMUTLBEntry *iotlb, void **vaddr, + ram_addr_t *ram_addr, bool *read_only) { MemoryRegion *mr; hwaddr xlat; @@ -440,9 +464,17 @@ static bool vfio_get_vaddr(IOMMUTLBEntry *iotlb, void = **vaddr, return false; } =20 - *vaddr =3D memory_region_get_ram_ptr(mr) + xlat; - *read_only =3D !writable || mr->readonly; + if (vaddr) { + *vaddr =3D memory_region_get_ram_ptr(mr) + xlat; + } =20 + if (ram_addr) { + *ram_addr =3D memory_region_get_ram_addr(mr) + xlat; + } + + if (read_only) { + *read_only =3D !writable || mr->readonly; + } return true; } =20 @@ -467,7 +499,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOM= MUTLBEntry *iotlb) rcu_read_lock(); =20 if ((iotlb->perm & IOMMU_RW) !=3D IOMMU_NONE) { - if (!vfio_get_vaddr(iotlb, &vaddr, &read_only)) { + if (!vfio_get_xlat_addr(iotlb, &vaddr, NULL, &read_only)) { goto out; } /* @@ -813,9 +845,167 @@ static void vfio_listener_region_del(MemoryListener *= listener, } } =20 +static int vfio_get_dirty_bitmap(MemoryListener *listener, + MemoryRegionSection *section) +{ + VFIOContainer *container =3D container_of(listener, VFIOContainer, lis= tener); + VFIOGuestIOMMU *giommu; + IOMMUTLBEntry iotlb; + hwaddr granularity, address_limit, iova; + int ret; + + if (memory_region_is_iommu(section->mr)) { + QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) { + if (MEMORY_REGION(giommu->iommu) =3D=3D section->mr && + giommu->n.start =3D=3D section->offset_within_region) { + break; + } + } + + if (!giommu) { + return -EINVAL; + } + } + + if (memory_region_is_iommu(section->mr)) { + granularity =3D memory_region_iommu_get_min_page_size(giommu->iomm= u); + + address_limit =3D MIN(int128_get64(section->size), + memory_region_iommu_get_address_limit(giommu->= iommu, + int128_get64(section->siz= e))); + } else { + granularity =3D memory_region_size(section->mr); + address_limit =3D int128_get64(section->size); + } + + iova =3D TARGET_PAGE_ALIGN(section->offset_within_address_space); + + RCU_READ_LOCK_GUARD(); + + while (iova < address_limit) { + struct vfio_iommu_type1_dirty_bitmap *dbitmap; + struct vfio_iommu_type1_dirty_bitmap_get *range; + ram_addr_t start, pages; + uint64_t iova_xlat, size; + + if (memory_region_is_iommu(section->mr)) { + iotlb =3D address_space_get_iotlb_entry(container->space->as, = iova, + true, MEMTXATTRS_UNSPECIF= IED); + if ((iotlb.target_as =3D=3D NULL) || (iotlb.addr_mask =3D=3D 0= )) { + if ((iova + granularity) < iova) { + break; + } + iova +=3D granularity; + continue; + } + iova_xlat =3D iotlb.iova + giommu->iommu_offset; + size =3D iotlb.addr_mask + 1; + } else { + iova_xlat =3D iova; + size =3D address_limit; + } + + dbitmap =3D g_malloc0(sizeof(*dbitmap) + sizeof(*range)); + if (!dbitmap) { + return -ENOMEM; + } + + dbitmap->argsz =3D sizeof(*dbitmap) + sizeof(*range); + dbitmap->flags =3D VFIO_IOMMU_DIRTY_PAGES_FLAG_GET_BITMAP; + range =3D (struct vfio_iommu_type1_dirty_bitmap_get *)&dbitmap->da= ta; + range->iova =3D iova_xlat; + range->size =3D size; + + /* + * cpu_physical_memory_set_dirty_lebitmap() expects pages in bitma= p of + * TARGET_PAGE_SIZE to mark those dirty. Hence set bitmap's pgsize= to + * TARGET_PAGE_SIZE. + */ + range->bitmap.pgsize =3D TARGET_PAGE_SIZE; + + /* + * Comment from kvm_physical_sync_dirty_bitmap() since same applie= s here + * XXX bad kernel interface alert + * For dirty bitmap, kernel allocates array of size aligned to + * bits-per-long. But for case when the kernel is 64bits and + * the userspace is 32bits, userspace can't align to the same + * bits-per-long, since sizeof(long) is different between kernel + * and user space. This way, userspace will provide buffer which + * may be 4 bytes less than the kernel will use, resulting in + * userspace memory corruption (which is not detectable by valgrind + * too, in most cases). + * So for now, let's align to 64 instead of HOST_LONG_BITS here, in + * a hope that sizeof(long) won't become >8 any time soon. + */ + + pages =3D TARGET_PAGE_ALIGN(range->size) >> TARGET_PAGE_BITS; + range->bitmap.size =3D ROUND_UP(pages, 64) / 8; + range->bitmap.data =3D g_malloc0(range->bitmap.size); + if (range->bitmap.data =3D=3D NULL) { + error_report("Error allocating bitmap of size 0x%llx", + range->bitmap.size); + ret =3D -ENOMEM; + goto err_out; + } + + ret =3D ioctl(container->fd, VFIO_IOMMU_DIRTY_PAGES, dbitmap); + if (ret) { + error_report("Failed to get dirty bitmap for iova: 0x%llx " + "size: 0x%llx err: %d", + range->iova, range->size, errno); + goto err_out; + } + + if (memory_region_is_iommu(section->mr)) { + if (!vfio_get_xlat_addr(&iotlb, NULL, &start, NULL)) { + ret =3D -EINVAL; + goto err_out; + } + } else { + start =3D memory_region_get_ram_addr(section->mr) + + section->offset_within_region + iova - + TARGET_PAGE_ALIGN(section->offset_within_address_space= ); + } + + cpu_physical_memory_set_dirty_lebitmap((uint64_t *)range->bitmap.d= ata, + start, pages); + + trace_vfio_get_dirty_bitmap(container->fd, range->iova, range->siz= e, + range->bitmap.size, start); +err_out: + g_free(range->bitmap.data); + g_free(dbitmap); + + if (ret) { + return ret; + } + + if ((iova + size) < iova) { + break; + } + + iova +=3D size; + } + + return 0; +} + +static void vfio_listerner_log_sync(MemoryListener *listener, + MemoryRegionSection *section) +{ + if (vfio_listener_skipped_section(section)) { + return; + } + + if (vfio_devices_are_stopped_and_saving()) { + vfio_get_dirty_bitmap(listener, section); + } +} + static const MemoryListener vfio_memory_listener =3D { .region_add =3D vfio_listener_region_add, .region_del =3D vfio_listener_region_del, + .log_sync =3D vfio_listerner_log_sync, }; =20 static void vfio_listener_release(VFIOContainer *container) diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index ac065b559f4e..bc8f35ee9356 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -160,3 +160,4 @@ vfio_save_complete_precopy(char *name) " (%s)" vfio_load_device_config_state(char *name) " (%s)" vfio_load_state(char *name, uint64_t data) " (%s) data 0x%"PRIx64 vfio_load_state_device_data(char *name, uint64_t data_offset, uint64_t dat= a_size) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64 +vfio_get_dirty_bitmap(int fd, uint64_t iova, uint64_t size, uint64_t bitma= p_size, uint64_t start) "container fd=3D%d, iova=3D0x%"PRIx64" size=3D 0x%"= PRIx64" bitmap_size=3D0x%"PRIx64" start=3D0x%"PRIx64 --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086532; cv=none; d=zohomail.com; s=zohoarc; b=Bt5F49Isjo9zMvOZl+c3ZpscV/6J+VdC6UmHrtDmYL51+qIRftJvdmdz+BxJNiVQW/ZkL9a+4YPtFgsRO8Sydnkhacr+fEPY+rGCWsE+h94zFrmn4/G/uHDFFXBQz5PGW1qkK2XRInejXONw00ZPg9S+xbmNIlwv9BT1JZsYZKg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086532; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=PEXMFuuI8fsiubSZvHl6Ada//eIsqIwjXaMF8FZO2m4=; b=gSCtR5mVnBQ9b11hPW7VLtrvFchOAtzN7XXpha0yzXfDke3Nwgqbu42QBWNg7JqqQJuFrxISz0nqIe79vU8UEGEb/QMYhFqy5S76H5bLJm7jjVihEXCCLfVuEP65nfQlLFmK1sOLQE4SExkz4Y8PnVPffhRVbaggr7Dj52Zu1yI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 158508653276542.9131847801915; Tue, 24 Mar 2020 14:48:52 -0700 (PDT) Received: from localhost ([::1]:55616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrPn-0005H3-Dj for importer@patchew.org; Tue, 24 Mar 2020 17:48:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38963) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrLV-0008Bv-9f for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrLT-00054B-TD for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:25 -0400 Received: from hqnvemgate26.nvidia.com ([216.228.121.65]:6205) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrLT-00053q-Ky for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:23 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate26.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:44:09 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:44:22 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:44:22 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:44:15 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 24 Mar 2020 14:44:22 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 15/16] vfio: Add ioctl to get dirty pages bitmap during dma unmap. Date: Wed, 25 Mar 2020 02:39:13 +0530 Message-ID: <1585084154-29461-16-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086249; bh=PEXMFuuI8fsiubSZvHl6Ada//eIsqIwjXaMF8FZO2m4=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=L9HL+1NQe/kklj0BUiQlsF8CcC7PmZtbSTAvksrdOvygKbuUhdkRcYdrCqlFuq4+Z 3dq3OAk49jsj0X6JMiChc9Da7Djhnj6H95FJ6GVXWQT0U5a3Gnpayf4lbhpvpcUF4p ewQpETD4gqHAUT6PVXM/COnupf764PbQsV6gvqisdgblqhuNK8p6LRSMgsQ7R2abvR 1hs/l53bFxoviPT6Q/X3Wf+KHJOUe3HWrbA0ZAKXpgfiuTNe0C2xLZ8bRgJpDsM+m6 WfaKL03x2+MtfUB8o74O8oSrEVr76L4kVYYikeo4Ve8jUzsUOqZRX/fpgTTEWvBJvG Sng71ybHAlVtQ== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.65 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" With vIOMMU, IO virtual address range can get unmapped while in pre-copy ph= ase of migration. In that case, unmap ioctl should return pages pinned in that = range and QEMU should find its correcponding guest physical addresses and report those dirty. Note: This patch is not yet tested. I'm trying to see how I can test this c= ode path. Suggested-by: Alex Williamson Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/common.c | 83 +++++++++++++++++++++++++++++++++++++++= +--- include/hw/vfio/vfio-common.h | 1 + 2 files changed, 80 insertions(+), 4 deletions(-) diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 6d41e1ac5c2f..e0f91841bc82 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -311,11 +311,77 @@ static bool vfio_devices_are_stopped_and_saving(void) return true; } =20 +static bool vfio_devices_are_running_and_saving(void) +{ + VFIOGroup *group; + VFIODevice *vbasedev; + + QLIST_FOREACH(group, &vfio_group_list, next) { + QLIST_FOREACH(vbasedev, &group->device_list, next) { + if ((vbasedev->device_state & VFIO_DEVICE_STATE_SAVING) && + (vbasedev->device_state & VFIO_DEVICE_STATE_RUNNING)) { + continue; + } else { + return false; + } + } + } + return true; +} + +static int vfio_dma_unmap_bitmap(VFIOContainer *container, + hwaddr iova, ram_addr_t size, + IOMMUTLBEntry *iotlb) +{ + struct vfio_iommu_type1_dma_unmap *unmap; + struct vfio_bitmap *bitmap; + uint64_t pages =3D TARGET_PAGE_ALIGN(size) >> TARGET_PAGE_BITS; + int ret; + + unmap =3D g_malloc0(sizeof(*unmap) + sizeof(*bitmap)); + if (!unmap) { + return -ENOMEM; + } + + unmap->argsz =3D sizeof(*unmap) + sizeof(*bitmap); + unmap->flags |=3D VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP; + bitmap =3D (struct vfio_bitmap *)&unmap->data; + + /* + * cpu_physical_memory_set_dirty_lebitmap() expects pages in bitmap of + * TARGET_PAGE_SIZE to mark those dirty. Hence set bitmap_pgsize to + * TARGET_PAGE_SIZE. + */ + + bitmap->pgsize =3D TARGET_PAGE_SIZE; + bitmap->size =3D ROUND_UP(pages, 64) / 8; + bitmap->data =3D g_malloc0(bitmap->size); + if (!bitmap->data) { + error_report("UNMAP: Error allocating bitmap of size 0x%llx", + bitmap->size); + g_free(unmap); + return -ENOMEM; + } + + ret =3D ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, unmap); + if (!ret) { + cpu_physical_memory_set_dirty_lebitmap((uint64_t *)bitmap->data, + iotlb->translated_addr, pages); + } else { + error_report("VFIO_UNMAP_DMA with DIRTY_BITMAP : %d", -errno); + } + + g_free(bitmap->data); + g_free(unmap); + return ret; +} + /* * DMA - Mapping and unmapping for the "type1" IOMMU interface used on x86 */ static int vfio_dma_unmap(VFIOContainer *container, - hwaddr iova, ram_addr_t size) + hwaddr iova, ram_addr_t size, + IOMMUTLBEntry *iotlb) { struct vfio_iommu_type1_dma_unmap unmap =3D { .argsz =3D sizeof(unmap), @@ -324,6 +390,11 @@ static int vfio_dma_unmap(VFIOContainer *container, .size =3D size, }; =20 + if (iotlb && container->dirty_pages_supported && + vfio_devices_are_running_and_saving()) { + return vfio_dma_unmap_bitmap(container, iova, size, iotlb); + } + while (ioctl(container->fd, VFIO_IOMMU_UNMAP_DMA, &unmap)) { /* * The type1 backend has an off-by-one bug in the kernel (71a7d3d7= 8e3c @@ -371,7 +442,7 @@ static int vfio_dma_map(VFIOContainer *container, hwadd= r iova, * the VGA ROM space. */ if (ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) =3D=3D 0 || - (errno =3D=3D EBUSY && vfio_dma_unmap(container, iova, size) =3D= =3D 0 && + (errno =3D=3D EBUSY && vfio_dma_unmap(container, iova, size, NULL)= =3D=3D 0 && ioctl(container->fd, VFIO_IOMMU_MAP_DMA, &map) =3D=3D 0)) { return 0; } @@ -519,7 +590,7 @@ static void vfio_iommu_map_notify(IOMMUNotifier *n, IOM= MUTLBEntry *iotlb) iotlb->addr_mask + 1, vaddr, ret); } } else { - ret =3D vfio_dma_unmap(container, iova, iotlb->addr_mask + 1); + ret =3D vfio_dma_unmap(container, iova, iotlb->addr_mask + 1, iotl= b); if (ret) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " "0x%"HWADDR_PRIx") =3D %d (%m)", @@ -822,7 +893,7 @@ static void vfio_listener_region_del(MemoryListener *li= stener, } =20 if (try_unmap) { - ret =3D vfio_dma_unmap(container, iova, int128_get64(llsize)); + ret =3D vfio_dma_unmap(container, iova, int128_get64(llsize), NULL= ); if (ret) { error_report("vfio_dma_unmap(%p, 0x%"HWADDR_PRIx", " "0x%"HWADDR_PRIx") =3D %d (%m)", @@ -1479,6 +1550,7 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, container->space =3D space; container->fd =3D fd; container->error =3D NULL; + container->dirty_pages_supported =3D false; QLIST_INIT(&container->giommu_list); QLIST_INIT(&container->hostwin_list); =20 @@ -1509,6 +1581,9 @@ static int vfio_connect_container(VFIOGroup *group, A= ddressSpace *as, } vfio_host_win_add(container, 0, (hwaddr)-1, info.iova_pgsizes); container->pgsizes =3D info.iova_pgsizes; + if (info.flags & VFIO_IOMMU_INFO_DIRTY_PGS) { + container->dirty_pages_supported =3D true; + } break; } case VFIO_SPAPR_TCE_v2_IOMMU: diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h index c78033e4149d..8ab741463d50 100644 --- a/include/hw/vfio/vfio-common.h +++ b/include/hw/vfio/vfio-common.h @@ -79,6 +79,7 @@ typedef struct VFIOContainer { unsigned iommu_type; Error *error; bool initialized; + bool dirty_pages_supported; unsigned long pgsizes; QLIST_HEAD(, VFIOGuestIOMMU) giommu_list; QLIST_HEAD(, VFIOHostDMAWindow) hostwin_list; --=20 2.7.0 From nobody Fri Apr 26 22:40:48 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=nvidia.com ARC-Seal: i=1; a=rsa-sha256; t=1585086799; cv=none; d=zohomail.com; s=zohoarc; b=AAe1CAYZlHeDcQDGwWnzsacHgseHraJJ5LgpCOV1XCp2CccMatOdFViey5TlBoyY4uuH2zcYrQW5iFZJ/OvxmGhFAht+kTpS6E0MxCR8rl+nYOpBJ+TqLZhNCLB5D23cAXmDSormyQ9rp+hWLBm1d2mF8BShIRF890L1U4ELulY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585086799; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=hDf/HIPA6TG0mzp9mQMoERUyUraLSc/fd3dkuNF7XRs=; b=D0uEcbFhUf7SN+SRPjPuNSp48Ctpm0fsSfkm7zxyjj+U+0ha0i7hcGe99fN3BlOz0h8pW16wYVk9ISQ4tS3ZmYt+/gyj8t4Bd30dc55BPYdyy1FhxHgWswjaag7xzyi7bYFgUm5u57jnHZMdd3JWizQietlXprEhCDOouk/jc30= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1585086799460171.26962160225992; Tue, 24 Mar 2020 14:53:19 -0700 (PDT) Received: from localhost ([::1]:55746 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrU6-0003Pi-6t for importer@patchew.org; Tue, 24 Mar 2020 17:53:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38976) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jGrLb-0008Rz-DF for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jGrLa-00055W-4U for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:31 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:8935) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jGrLZ-000559-Um for qemu-devel@nongnu.org; Tue, 24 Mar 2020 17:44:30 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 24 Mar 2020 14:43:43 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 24 Mar 2020 14:44:28 -0700 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 24 Mar 2020 21:44:28 +0000 Received: from kwankhede-dev.nvidia.com (10.124.1.5) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Tue, 24 Mar 2020 21:44:22 +0000 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 24 Mar 2020 14:44:28 -0700 From: Kirti Wankhede To: , Subject: [PATCH v16 QEMU 16/16] vfio: Make vfio-pci device migration capable Date: Wed, 25 Mar 2020 02:39:14 +0530 Message-ID: <1585084154-29461-17-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> References: <1585084154-29461-1-git-send-email-kwankhede@nvidia.com> X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1585086224; bh=hDf/HIPA6TG0mzp9mQMoERUyUraLSc/fd3dkuNF7XRs=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:X-NVConfidentiality:MIME-Version: Content-Type; b=k4k8erALNwHT0/c9Gyo0yfjgq2D2wQugQwuJhYxwD8QHojVp6qRuWJp4rgvBbmvMu 8PW5BIXd4JUZsh3u+AAWnl9CYGvmHBBwABz3FKtKvqFguFiiAxrNXHRq4s8n0Eqmg5 /nT5CYB1A44dCZFf5weop9hMXjt84X9dSReKtdBdHDxnDgJP+Q7ndKEgEnB1R4w6Ea mAjSGe1vsdBF8Spf68VqcfH3W65USrmLLCvIomUUkU2JtcdQOeomhXZ9uW5K69Vwz3 zBRZnmajf+ME3l3T0LnN8d2sWGy6bEqpCE8mmmmjZjMCjyyHyACWhcYm/6MY5aqAix 1nwv2s0G0BS9Q== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 216.228.121.64 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Zhengxiao.zx@Alibaba-inc.com, kevin.tian@intel.com, yi.l.liu@intel.com, yan.y.zhao@intel.com, eskultet@redhat.com, ziye.yang@intel.com, qemu-devel@nongnu.org, cohuck@redhat.com, shuangtai.tst@alibaba-inc.com, dgilbert@redhat.com, zhi.a.wang@intel.com, mlevitsk@redhat.com, pasic@linux.ibm.com, aik@ozlabs.ru, Kirti Wankhede , eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" If device is not failover primary device call vfio_migration_probe() and vfio_migration_finalize() functions for vfio-pci device to enable migration for vfio PCI device which support migration. Removed vfio_pci_vmstate structure. Removed migration blocker from VFIO PCI device specific structure and use migration blocker from generic structure of VFIO device. Signed-off-by: Kirti Wankhede Reviewed-by: Neo Jia --- hw/vfio/pci.c | 32 +++++++++++--------------------- hw/vfio/pci.h | 1 - 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 8deb11e87ef7..c70f153d431a 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -2916,22 +2916,11 @@ static void vfio_realize(PCIDevice *pdev, Error **e= rrp) return; } =20 - if (!pdev->failover_pair_id) { - error_setg(&vdev->migration_blocker, - "VFIO device doesn't support migration"); - ret =3D migrate_add_blocker(vdev->migration_blocker, &err); - if (ret) { - error_propagate(errp, err); - error_free(vdev->migration_blocker); - vdev->migration_blocker =3D NULL; - return; - } - } - vdev->vbasedev.name =3D g_path_get_basename(vdev->vbasedev.sysfsdev); vdev->vbasedev.ops =3D &vfio_pci_ops; vdev->vbasedev.type =3D VFIO_DEVICE_TYPE_PCI; vdev->vbasedev.dev =3D DEVICE(vdev); + vdev->vbasedev.device_state =3D 0; =20 tmp =3D g_strdup_printf("%s/iommu_group", vdev->vbasedev.sysfsdev); len =3D readlink(tmp, group_path, sizeof(group_path)); @@ -3195,6 +3184,14 @@ static void vfio_realize(PCIDevice *pdev, Error **er= rp) } } =20 + if (!pdev->failover_pair_id) { + ret =3D vfio_migration_probe(&vdev->vbasedev, errp); + if (ret) { + error_report("%s: Failed to setup for migration", + vdev->vbasedev.name); + } + } + vfio_register_err_notifier(vdev); vfio_register_req_notifier(vdev); vfio_setup_resetfn_quirk(vdev); @@ -3209,11 +3206,6 @@ out_teardown: vfio_bars_exit(vdev); error: error_prepend(errp, VFIO_MSG_PREFIX, vdev->vbasedev.name); - if (vdev->migration_blocker) { - migrate_del_blocker(vdev->migration_blocker); - error_free(vdev->migration_blocker); - vdev->migration_blocker =3D NULL; - } } =20 static void vfio_instance_finalize(Object *obj) @@ -3225,10 +3217,7 @@ static void vfio_instance_finalize(Object *obj) vfio_bars_finalize(vdev); g_free(vdev->emulated_config_bits); g_free(vdev->rom); - if (vdev->migration_blocker) { - migrate_del_blocker(vdev->migration_blocker); - error_free(vdev->migration_blocker); - } + /* * XXX Leaking igd_opregion is not an oversight, we can't remove the * fw_cfg entry therefore leaking this allocation seems like the safest @@ -3256,6 +3245,7 @@ static void vfio_exitfn(PCIDevice *pdev) } vfio_teardown_msi(vdev); vfio_bars_exit(vdev); + vfio_migration_finalize(&vdev->vbasedev); } =20 static void vfio_pci_reset(DeviceState *dev) diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h index 0da7a20a7ec2..b148c937ef72 100644 --- a/hw/vfio/pci.h +++ b/hw/vfio/pci.h @@ -168,7 +168,6 @@ typedef struct VFIOPCIDevice { bool no_vfio_ioeventfd; bool enable_ramfb; VFIODisplay *dpy; - Error *migration_blocker; Notifier irqchip_change_notifier; } VFIOPCIDevice; =20 --=20 2.7.0