From nobody Tue Feb 10 05:10:40 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1498467660895621.2623482397767; Mon, 26 Jun 2017 02:01:00 -0700 (PDT) Received: from localhost ([::1]:45376 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPPtD-00038y-9Q for importer@patchew.org; Mon, 26 Jun 2017 05:00:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPPrU-0001wJ-W5 for qemu-devel@nongnu.org; Mon, 26 Jun 2017 04:59:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPPrU-0004Rz-1J for qemu-devel@nongnu.org; Mon, 26 Jun 2017 04:59:13 -0400 Received: from mga11.intel.com ([192.55.52.93]:44436) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dPPrT-0004PL-Ps for qemu-devel@nongnu.org; Mon, 26 Jun 2017 04:59:11 -0400 Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 26 Jun 2017 01:59:11 -0700 Received: from yzhang13-kvm.sh.intel.com ([10.239.36.121]) by fmsmga006.fm.intel.com with ESMTP; 26 Jun 2017 01:59:07 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,394,1493708400"; d="scan'208";a="119263378" From: Yulei Zhang To: qemu-devel@nongnu.org Date: Tue, 4 Apr 2017 18:32:56 +0800 Message-Id: <1491301977-24481-9-git-send-email-yulei.zhang@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491301977-24481-1-git-send-email-yulei.zhang@intel.com> References: <1491301977-24481-1-git-send-email-yulei.zhang@intel.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 192.55.52.93 Subject: [Qemu-devel] [Intel-gfx][RFC 8/9] drm/i915/gvt: Introduce new VFIO ioctl for mdev device dirty page sync 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: kevin.tian@intel.com, joonas.lahtinen@linux.intel.com, zhenyuw@linux.intel.com, Yulei Zhang , xiao.zheng@intel.com, zhi.a.wang@intel.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add new vfio ioctl VFIO_DEVICE_PCI_GET_DIRTY_BITMAP to fetch the dirty page bitmap from mdev device driver for data sync during live migration. Signed-off-by: Yulei Zhang --- drivers/gpu/drm/i915/gvt/kvmgt.c | 33 +++++++++++++++++++++++++++++++++ include/uapi/linux/vfio.h | 14 ++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/drivers/gpu/drm/i915/gvt/kvmgt.c b/drivers/gpu/drm/i915/gvt/kv= mgt.c index ac327f7..e9f11a9 100644 --- a/drivers/gpu/drm/i915/gvt/kvmgt.c +++ b/drivers/gpu/drm/i915/gvt/kvmgt.c @@ -919,6 +919,24 @@ static int intel_vgpu_set_irqs(struct intel_vgpu *vgpu= , uint32_t flags, return func(vgpu, index, start, count, flags, data); } =20 +static void intel_vgpu_update_dirty_bitmap(struct intel_vgpu *vgpu, u64 st= art_addr, + u64 page_nr, void *bitmap) +{ + u64 gfn =3D start_addr >> GTT_PAGE_SHIFT; + struct intel_vgpu_guest_page *p; + int i; + + for (i =3D 0; i < page_nr; i++) { + hash_for_each_possible(vgpu->gtt.guest_page_hash_table, + p, node, gfn) { + if (p->gfn =3D=3D gfn) + set_bit(i, bitmap); + } + gfn++; + } + +} + static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd, unsigned long arg) { @@ -1156,6 +1174,21 @@ static long intel_vgpu_ioctl(struct mdev_device *mde= v, unsigned int cmd, intel_gvt_ops->vgpu_deactivate(vgpu); else intel_gvt_ops->vgpu_activate(vgpu); + } else if (cmd =3D=3D VFIO_DEVICE_PCI_GET_DIRTY_BITMAP) { + struct vfio_pci_get_dirty_bitmap d; + unsigned long bitmap_sz; + unsigned *bitmap; + minsz =3D offsetofend(struct vfio_pci_get_dirty_bitmap, page_nr); + if (copy_from_user(&d, (void __user *)arg, minsz)) + return -EFAULT; + bitmap_sz =3D (BITS_TO_LONGS(d.page_nr) + 1) * sizeof(unsigned long); + bitmap =3D vzalloc(bitmap_sz); + intel_vgpu_update_dirty_bitmap(vgpu, d.start_addr, d.page_nr, bitmap); + if (copy_to_user((void __user*)arg + minsz, bitmap, bitmap_sz)) { + vfree(bitmap); + return -EFAULT; + } + vfree(bitmap); } =20 return 0; diff --git a/include/uapi/linux/vfio.h b/include/uapi/linux/vfio.h index 4bb057d..544cf93 100644 --- a/include/uapi/linux/vfio.h +++ b/include/uapi/linux/vfio.h @@ -518,6 +518,20 @@ struct vfio_pci_status_set{ =20 #define VFIO_DEVICE_PCI_STATUS_SET _IO(VFIO_TYPE, VFIO_BASE + 14) =20 +/** + * VFIO_DEVICE_PCI_GET_DIRTY_BITMAP - _IOW(VFIO_TYPE, VFIO_BASE + 15, + * struct vfio_pci_get_dirty_bitmap) + * + * Return: 0 on success, -errno on failure. + */ +struct vfio_pci_get_dirty_bitmap{ + __u64 start_addr; + __u64 page_nr; + __u8 dirty_bitmap[]; +}; + +#define VFIO_DEVICE_PCI_GET_DIRTY_BITMAP _IO(VFIO_TYPE, VFIO_BASE + 15) + /* -------- API for Type1 VFIO IOMMU -------- */ =20 /** --=20 2.7.4