From patchwork Tue Feb 19 21:23:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kirti Wankhede X-Patchwork-Id: 1044902 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=209.51.188.17; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=nvidia.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=nvidia.com header.i=@nvidia.com header.b="TWjxxu6D"; dkim-atps=neutral Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 443vC51wGPz9s1l for ; Wed, 20 Feb 2019 08:34:36 +1100 (AEDT) Received: from localhost ([127.0.0.1]:55251 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwD2A-0008RP-L3 for incoming@patchwork.ozlabs.org; Tue, 19 Feb 2019 16:34:34 -0500 Received: from eggs.gnu.org ([209.51.188.92]:33484) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gwCyQ-0006A2-Er for qemu-devel@nongnu.org; Tue, 19 Feb 2019 16:30:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gwCyP-0005j5-1w for qemu-devel@nongnu.org; Tue, 19 Feb 2019 16:30:42 -0500 Received: from hqemgate14.nvidia.com ([216.228.121.143]:16942) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gwCyO-0005Ue-Iy for qemu-devel@nongnu.org; Tue, 19 Feb 2019 16:30:40 -0500 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 19 Feb 2019 13:25:25 -0800 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 19 Feb 2019 13:25:17 -0800 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 19 Feb 2019 13:25:17 -0800 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.1395.4; Tue, 19 Feb 2019 21:25:17 +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.1395.4 via Frontend Transport; Tue, 19 Feb 2019 21:25:10 +0000 From: Kirti Wankhede To: , Date: Wed, 20 Feb 2019 02:53:15 +0530 Message-ID: <1550611400-13703-1-git-send-email-kwankhede@nvidia.com> X-Mailer: git-send-email 2.7.0 X-NVConfidentiality: public MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1550611525; bh=0Dp6Guo9jqdFvqZ3IDADQ3GA+/i/yFQ0AEo1T7ygmNs=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: X-NVConfidentiality:MIME-Version:Content-Type; b=TWjxxu6DOme43gHC7KdNzrmrVCpRsDxXvklzu5ROADRNayOMYIQOr8z8ZyAZXah6i I0nn1civ4wEqEqY4z95Q/W2KTFjkkIjsEqANEvfFsXgMWzyk8gbaCB7Wc0EbVsMovk S5tguYeuoke1myuCGwa/WT7u+4XNGVJ8f1Z9faxCPYVk+vVmUABO60bq/xCdXeKM4w 1p584AqwtMk7+uiJr5/kXA3x1xZb0bUXx1+qb3G4KALnLdAEeYAtxzYDt8bBOfBNCE leZhiJaFaJ8lURZqYF1acgnUnPiEDNCq/V1jqANr68XvLw9+qYq3dcyfC+uryb7zOC zw95LqY4hUoMg== X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 X-Received-From: 216.228.121.143 Subject: [Qemu-devel] [PATCH v3 0/5] Add migration support for VFIO device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kirti Wankhede , 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, yulei.zhang@intel.com, eauger@redhat.com, felipe@nutanix.com, jonathan.davies@nutanix.com, changpeng.liu@intel.com, Ken.Xue@amd.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add migration support for VFIO device This Patch set include patches as below: - Define KABI for VFIO device for migration support. - Added save and restore functions for PCI configuration space - Generic migration functionality for VFIO device. * This patch set adds functionality only for PCI devices, but can be extended to other VFIO devices. * Added all the basic functions required for pre-copy, stop-and-copy and resume phases of migration. * Added state change notifier and from that notifier function, VFIO device's state changed is conveyed to VFIO device driver. * During save setup phase and resume/load setup phase, migration region is queried and is used to read/write VFIO device data. * .save_live_pending and .save_live_iterate are implemented to use QEMU's functionality of iteration during pre-copy phase. * In .save_live_complete_precopy, that is in stop-and-copy phase, iteration to read data from VFIO device driver is implemented till pending bytes returned by driver are not zero. * Added function to get dirty pages bitmap for the pages which are used by driver. - Add vfio_listerner_log_sync to mark dirty pages. - Make VFIO PCI device migration capable. If migration region is not provided by driver, migration is blocked. Below is the flow of state change for live migration where states in brackets represent VM state, migration state and VFIO device state as: (VM state, MIGRATION_STATUS, VFIO_DEVICE_STATE) Live migration save path: QEMU normal running state (RUNNING, _NONE, _RUNNING) | migrate_init spawns migration_thread. (RUNNING, _SETUP, _RUNNING|_SAVING) Migration thread then calls each device's .save_setup() | (RUNNING, _ACTIVE, _RUNNING|_SAVING) If device is active, get pending bytes by .save_live_pending() if pending bytes >= threshold_size, call save_live_iterate() Data of VFIO device for pre-copy phase is copied. Iterate till pending bytes converge and are less than threshold | migration_completion() stops vCPUs and calls .save_live_complete_precopy for each active device. VFIO device is then transitioned in _SAVING state. (FINISH_MIGRATE, _DEVICE, _SAVING) For VFIO device, iterate in .save_live_complete_precopy until pending data is 0. (FINISH_MIGRATE, _DEVICE, 0) | (FINISH_MIGRATE, _COMPLETED, 0) Migraton thread schedule cleanup bottom half and exit Live migration resume path: Incomming migration calls .load_setup for each device (RESTORE_VM, _ACTIVE, 0) | For each device, .load_state is called for that device section data | At the end, called .load_cleanup for each device and vCPUs are started. (RUNNING, _NONE, _RUNNING) Note that: - Migration post copy is not supported. - VFIO device driver version compatibility is not taken care in this series. v2 -> v3: - Removed enum of VFIO device states. Defined VFIO device state with 2 bits. - Re-structured vfio_device_migration_info to keep it minimal and defined action on read and write access on its members. v1 -> v2: - Defined MIGRATION region type and sub-type which should be used with region type capability. - Re-structured vfio_device_migration_info. This structure will be placed at 0th offset of migration region. - Replaced ioctl with read/write for trapped part of migration region. - Added both type of access support, trapped or mmapped, for data section of the region. - Moved PCI device functions to pci file. - Added iteration to get dirty page bitmap until bitmap for all requested pages are copied. Thanks, Kirti Kirti Wankhede (5): VFIO KABI for migration interface Add save and load functions for VFIO PCI devices Add migration functions for VFIO devices Add vfio_listerner_log_sync to mark dirty pages Make vfio-pci device migration capable. hw/vfio/Makefile.objs | 2 +- hw/vfio/common.c | 31 ++ hw/vfio/migration.c | 714 ++++++++++++++++++++++++++++++++++++++++++ hw/vfio/pci.c | 117 ++++++- hw/vfio/pci.h | 29 ++ include/hw/vfio/vfio-common.h | 20 ++ linux-headers/linux/vfio.h | 65 ++++ 7 files changed, 971 insertions(+), 7 deletions(-) create mode 100644 hw/vfio/migration.c