{"id":2175437,"url":"http://patchwork.ozlabs.org/api/1.0/patches/2175437/?format=json","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.0/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20251218062643.624796-8-zhenzhong.duan@intel.com>","date":"2025-12-18T06:26:28","name":"[v6,7/9] vfio/listener: Add missing dirty tracking in region_del","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"f423bf2f3c442f7bc219533ec962258ea2c88d4c","submitter":{"id":81636,"url":"http://patchwork.ozlabs.org/api/1.0/people/81636/?format=json","name":"Duan, Zhenzhong","email":"zhenzhong.duan@intel.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20251218062643.624796-8-zhenzhong.duan@intel.com/mbox/","series":[{"id":485789,"url":"http://patchwork.ozlabs.org/api/1.0/series/485789/?format=json","date":"2025-12-18T06:26:21","name":"vfio: relax the vIOMMU check","version":6,"mbox":"http://patchwork.ozlabs.org/series/485789/mbox/"}],"check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2175437/checks/","tags":{},"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256\n header.s=Intel header.b=eDnsPpkN;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4dX13q1F2Gz1xty\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 18 Dec 2025 17:29:43 +1100 (AEDT)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1vW7UO-0003OX-6G; Thu, 18 Dec 2025 01:27:52 -0500","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <zhenzhong.duan@intel.com>)\n id 1vW7UJ-0003Ny-Am\n for qemu-devel@nongnu.org; Thu, 18 Dec 2025 01:27:47 -0500","from mgamail.intel.com ([198.175.65.18])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <zhenzhong.duan@intel.com>)\n id 1vW7UH-00019A-9R\n for qemu-devel@nongnu.org; Thu, 18 Dec 2025 01:27:47 -0500","from orviesa005.jf.intel.com ([10.64.159.145])\n by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 17 Dec 2025 22:27:43 -0800","from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229])\n by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 17 Dec 2025 22:27:40 -0800"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n t=1766039265; x=1797575265;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=F94eQF5etGZnbJvv+YltI5zknPfG77G/Rv34Fp6qScQ=;\n b=eDnsPpkNnWelfNp4SQ+7pNn39RafWsXloPP6cZCSWUk/warJy2ICM8B2\n 2edCQCqts+GVrurf6/nRxiBp+dYbnk1eHxHo1iCX/MrHSn3NQ9d+jWvqR\n M9GMc8H50V+7oRfJyMfkWSeEGyRr2A4X6GWxqWiAbJ7h78aQrRN09oUKq\n nOYe2/eNdq0o6TjNrqpHSe3rwOX/b6H3aVBZNF871C25j07P6oScRVSvK\n RjJskP5dWjIxFQGsPFeEgyUCp+0utkFAcu4QOAiPbvvtx/6Ej5GHBC32D\n 6kv8ubE3hbu5kzFl7VnPg8Li+sDE9M0b4JZ7cRS2qL2zccmSWROFKlZfk g==;","X-CSE-ConnectionGUID":["JLZklg7MTYyt+bt2wwUfUg==","K7FN/OOJTmWdLM5EN2wplw=="],"X-CSE-MsgGUID":["uq2ShDaqS7G31ZtZsP3vZQ==","LpbKp+Z8SAqmXx//Gw/3xg=="],"X-IronPort-AV":["E=McAfee;i=\"6800,10657,11645\"; a=\"68028564\"","E=Sophos;i=\"6.21,156,1763452800\"; d=\"scan'208\";a=\"68028564\"","E=Sophos;i=\"6.21,156,1763452800\"; d=\"scan'208\";a=\"203569902\""],"X-ExtLoop1":"1","From":"Zhenzhong Duan <zhenzhong.duan@intel.com>","To":"qemu-devel@nongnu.org","Cc":"alex@shazbot.org, clg@redhat.com, mst@redhat.com, jasowang@redhat.com,\n yi.l.liu@intel.com, clement.mathieu--drif@eviden.com,\n eric.auger@redhat.com, joao.m.martins@oracle.com, avihaih@nvidia.com,\n xudong.hao@intel.com, giovanni.cabiddu@intel.com, rohith.s.r@intel.com,\n mark.gross@intel.com, arjan.van.de.ven@intel.com,\n Zhenzhong Duan <zhenzhong.duan@intel.com>","Subject":"[PATCH v6 7/9] vfio/listener: Add missing dirty tracking in\n region_del","Date":"Thu, 18 Dec 2025 01:26:28 -0500","Message-ID":"<20251218062643.624796-8-zhenzhong.duan@intel.com>","X-Mailer":"git-send-email 2.47.1","In-Reply-To":"<20251218062643.624796-1-zhenzhong.duan@intel.com>","References":"<20251218062643.624796-1-zhenzhong.duan@intel.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=198.175.65.18;\n 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,\n DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,\n RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001,\n 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":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"If a VFIO device in guest switches from passthrough(PT) domain to block\ndomain, the whole memory address space is unmapped, but we passed a NULL\niotlb entry to unmap_bitmap, then bitmap query didn't happen and we lost\ndirty pages.\n\nBy constructing an iotlb entry with iova = gpa for unmap_bitmap, it can\nset dirty bits correctly.\n\nFor IOMMU address space, we still send NULL iotlb because VFIO don't know\nthe actual mappings in guest. It's vIOMMU's responsibility to send actual\nunmapping notifications, e.g., vtd_address_space_unmap_in_dirty_tracking().\n\nSigned-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>\nTested-by: Giovannio Cabiddu <giovanni.cabiddu@intel.com>\nReviewed-by: Yi Liu <yi.l.liu@intel.com>\n---\n hw/vfio/listener.c | 22 +++++++++++++++++++++-\n 1 file changed, 21 insertions(+), 1 deletion(-)","diff":"diff --git a/hw/vfio/listener.c b/hw/vfio/listener.c\nindex 2109101158..35675e0ed7 100644\n--- a/hw/vfio/listener.c\n+++ b/hw/vfio/listener.c\n@@ -713,14 +713,34 @@ static void vfio_listener_region_del(MemoryListener *listener,\n \n     if (try_unmap) {\n         bool unmap_all = false;\n+        IOMMUTLBEntry entry = {}, *iotlb = NULL;\n \n         if (int128_eq(llsize, int128_2_64())) {\n             assert(!iova);\n             unmap_all = true;\n             llsize = int128_zero();\n         }\n+\n+        /*\n+         * Fake an IOTLB entry for identity mapping which is needed by dirty\n+         * tracking when switch out of PT domain. In fact, in unmap_bitmap,\n+         * only translated_addr field is used to set dirty bitmap.\n+         *\n+         * Note: When switch into PT domain from DMA domain, the whole IOMMU\n+         * MR is deleted without iotlb, before that happen, we depend on\n+         * vIOMMU to send unmap notification with accurate iotlb entry to\n+         * VFIO. See vtd_address_space_unmap_in_dirty_tracking() for example,\n+         * it is triggered during switching to block domain because vtd does\n+         * not support direct switching from DMA to PT domain.\n+         */\n+        if (global_dirty_tracking && memory_region_is_ram(section->mr)) {\n+            entry.iova = iova;\n+            entry.translated_addr = iova;\n+            iotlb = &entry;\n+        }\n+\n         ret = vfio_container_dma_unmap(bcontainer, iova, int128_get64(llsize),\n-                                       NULL, unmap_all);\n+                                       iotlb, unmap_all);\n         if (ret) {\n             error_report(\"vfio_container_dma_unmap(%p, 0x%\"HWADDR_PRIx\", \"\n                          \"0x%\"HWADDR_PRIx\") = %d (%s)\",\n","prefixes":["v6","7/9"]}