From nobody Mon Oct 27 13:47:52 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; 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=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1761271846; cv=none; d=zohomail.com; s=zohoarc; b=mjGUsawCYkqR55LuTSb6tAAtQB1a/GixfacwbIuysa+6AMY/rQI3bOah6nCYlOf1VR0ucq/nbbuRtoi/m9SAfHeSD2Jzj+POXKaAts+XJMs07hTfxmLpA1wPeW2mDeGxjSrObPS5JMRzin2jXqo0p4iHbwiWokT6K9DVtQHKA1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761271846; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=nUwZWAhxW3Dn8LB2zizXxoe/8iS7BriP0Sup/ficeck=; b=YuDg7hreTMttfVMWfmDQq1+0yDq1lbtShGM7aHoImJXRQsgLRVi852TTTDmTBZDWe/TxmJWyxP/6vWcWNTmAIHyYSBh1bQhmCNu27LKOnLVbk4ZN78tQhIuZ4gxBTs6pOM5xm1Bn3YJWuTkud1e2kVhk8AWWEne+5EISIBwjW5U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; 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=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1761271846830692.6303204769299; Thu, 23 Oct 2025 19:10:46 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vC7Fx-0004jy-Pv; Thu, 23 Oct 2025 22:10:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vC7Fu-0004jF-6k for qemu-devel@nongnu.org; Thu, 23 Oct 2025 22:10:14 -0400 Received: from mgamail.intel.com ([192.198.163.18]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vC7Fs-0006Ox-GE for qemu-devel@nongnu.org; Thu, 23 Oct 2025 22:10:13 -0400 Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2025 19:10:11 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2025 19:10:08 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1761271812; x=1792807812; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TsGQjpSaiCigw06ThV1ReigSCAZXU2bwig3p/fdJvxs=; b=f322SeSTulOiWKYA2HOYiE8EylVw9EmXw50ozztmiHEQuCstN0MYtN+j V0XhwXkG9fAgmsk3/R5f89BruUW5MayeyyH5MS0Y1Dg4a3B3sFy5yYEI7 s2yO85tnWk3mkjUEBJa3DlRTfI4AzOS7U0EQ29inrTX+7qnf+VcSylU6j UD/ysoUb27Atr4HT+MSXyvxOr4M7q4/PwIo/O5FXHAt3nTKOn6jR+nCdG Fo4jyMUyEGAWu2Nrp+z+7OPjwvuZR/wBVBjgrVeEN+vFcJN+Ko0VaIhnI vYrWwsxdxu9tYd2oU0k3ntDqtGnPTkTtbNlNtauCAq5PvEOv+B4MdQBQC A==; X-CSE-ConnectionGUID: K9+uPv2mRYebLqpgo6y44g== X-CSE-MsgGUID: iv5m37B7RdKk/4Vis3lGXg== X-IronPort-AV: E=McAfee;i="6800,10657,11586"; a="62662161" X-IronPort-AV: E=Sophos;i="6.19,251,1754982000"; d="scan'208";a="62662161" X-CSE-ConnectionGUID: KaqTwZjoTvyPGItMogb8Mg== X-CSE-MsgGUID: jtCPdLRNQf+P6HEpaa1qUQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.19,251,1754982000"; d="scan'208";a="189440810" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, mst@redhat.com, jasowang@redhat.com, yi.l.liu@intel.com, clement.mathieu--drif@eviden.com, eric.auger@redhat.com, joao.m.martins@oracle.com, avihaih@nvidia.com, xudong.hao@intel.com, giovanni.cabiddu@intel.com, rohith.s.r@intel.com, mark.gross@intel.com, arjan.van.de.ven@intel.com, Zhenzhong Duan Subject: [PATCH v3 7/8] vfio/migration: Add migration blocker if VM memory is too large to cause unmap_bitmap failure Date: Thu, 23 Oct 2025 22:09:21 -0400 Message-ID: <20251024020922.13053-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20251024020922.13053-1-zhenzhong.duan@intel.com> References: <20251024020922.13053-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=192.198.163.18; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H2=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1761271853946158500 Content-Type: text/plain; charset="utf-8" With default config, kernel VFIO IOMMU type1 driver limits dirty bitmap to 256MB for unmap_bitmap ioctl so the maximum guest memory region is no more than 8TB size for the ioctl to succeed. Be conservative here to limit total guest memory to max value supported by unmap_bitmap ioctl or else add a migration blocker. IOMMUFD backend doesn't have such limit, one can use IOMMUFD backed device if there is a need to migration such large VM. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/vfio/iommufd.c | 5 +++++ hw/vfio/migration.c | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index ba5c6b6586..8de765c769 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -633,6 +633,11 @@ skip_ioas_alloc: QLIST_INIT(&container->hwpt_list); =20 bcontainer =3D VFIO_IOMMU(container); + + /* There is no limitation on dirty bitmap size in IOMMUFD */ + bcontainer->max_dirty_bitmap_size =3D UINT64_MAX; + bcontainer->dirty_pgsizes =3D qemu_real_host_page_size(); + vfio_address_space_insert(space, bcontainer); =20 if (!iommufd_cdev_attach_container(vbasedev, container, errp)) { diff --git a/hw/vfio/migration.c b/hw/vfio/migration.c index 4c06e3db93..44bab024b7 100644 --- a/hw/vfio/migration.c +++ b/hw/vfio/migration.c @@ -16,6 +16,7 @@ #include =20 #include "system/runstate.h" +#include "hw/boards.h" #include "hw/vfio/vfio-device.h" #include "hw/vfio/vfio-migration.h" #include "migration/misc.h" @@ -1152,6 +1153,31 @@ static bool vfio_viommu_preset(VFIODevice *vbasedev) return vbasedev->bcontainer->space->as !=3D &address_space_memory; } =20 +static bool vfio_dirty_tracking_exceed_limit(VFIODevice *vbasedev) +{ + VFIOContainer *bcontainer =3D vbasedev->bcontainer; + uint64_t max_size, page_size; + + if (!bcontainer->dirty_pages_supported) { + return true; + } + /* + * VFIO IOMMU type1 driver has limitation of bitmap size on unmap_bitm= ap + * ioctl(), calculate the limit and compare with guest memory size to + * catch dirty tracking failure early. + * + * This limit is 8TB with default kernel and QEMU config, we are a bit + * conservative here as VM memory layout may be nonconsecutive or VM + * can run with vIOMMU enabled so the limitation could be relaxed. One + * can also switch to use IOMMUFD backend if there is a need to migrate + * large VM. + */ + page_size =3D 1 << ctz64(bcontainer->dirty_pgsizes); + max_size =3D bcontainer->max_dirty_bitmap_size * BITS_PER_BYTE * page_= size; + + return current_machine->ram_size > max_size; +} + /* * Return true when either migration initialized or blocker registered. * Currently only return false when adding blocker fails which will @@ -1208,6 +1234,13 @@ bool vfio_migration_realize(VFIODevice *vbasedev, Er= ror **errp) goto add_blocker; } =20 + if (vfio_dirty_tracking_exceed_limit(vbasedev)) { + error_setg(&err, "%s: Migration is currently not supported with " + "large memory VM due to dirty tracking limitation in " + "VFIO type1 driver", vbasedev->name); + goto add_blocker; + } + trace_vfio_migration_realize(vbasedev->name); return true; =20 --=20 2.47.1