Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2196478/?format=api
{ "id": 2196478, "url": "http://patchwork.ozlabs.org/api/patches/2196478/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260214034135.220413-11-zhenzhong.duan@intel.com/", "project": { "id": 14, "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api", "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": "", "list_archive_url": "", "list_archive_url_format": "", "commit_url_format": "" }, "msgid": "<20260214034135.220413-11-zhenzhong.duan@intel.com>", "list_archive_url": null, "date": "2026-02-14T03:41:30", "name": "[RFCv2,10/13] intel_iommu_accel: Support pasid binding/unbinding and PIOTLB flushing", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "eb8b351e4908f5b1c81b045bd30336d3f92b04ea", "submitter": { "id": 81636, "url": "http://patchwork.ozlabs.org/api/people/81636/?format=api", "name": "Zhenzhong Duan", "email": "zhenzhong.duan@intel.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260214034135.220413-11-zhenzhong.duan@intel.com/mbox/", "series": [ { "id": 492156, "url": "http://patchwork.ozlabs.org/api/series/492156/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=492156", "date": "2026-02-14T03:41:20", "name": "intel_iommu: Enable PASID support for passthrough device", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/492156/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2196478/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2196478/checks/", "tags": {}, "related": [], "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=ESgbdJXx;\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 4fCZd05pqlz1xpY\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 14 Feb 2026 14:43:16 +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 1vr6Y9-0005Cz-OA; Fri, 13 Feb 2026 22:42:29 -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 1vr6Y8-0005Cn-8d\n for qemu-devel@nongnu.org; Fri, 13 Feb 2026 22:42:28 -0500", "from mgamail.intel.com ([198.175.65.12])\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 1vr6Y6-0008J1-2v\n for qemu-devel@nongnu.org; Fri, 13 Feb 2026 22:42:28 -0500", "from orviesa009.jf.intel.com ([10.64.159.149])\n by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 13 Feb 2026 19:42:25 -0800", "from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229])\n by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 13 Feb 2026 19:42:22 -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=1771040546; x=1802576546;\n h=from:to:cc:subject:date:message-id:in-reply-to:\n references:mime-version:content-transfer-encoding;\n bh=ZKKihtEHgcuoRua5vriXgwXsCOK8oyODNfFoWZ0XqAE=;\n b=ESgbdJXxhHInR4LJJZ9rt1cUP6uZyUO9BBOLhhXQtH2H9faIF39UuoaV\n S+DhPCBH40QQoOVpbv3Ydpx9xgccCbByxZfNAe1NEirastBHlaEoUUnQo\n ph0+ditbOitAEIq0i8251cmeLUWqviN4WawuRXvbJE+Jh8HCOKpuCDBvz\n uySJqAbXSCYj1TYMoTnSuXXOr0pXP8WHFNh8ev+MpokJH71IXmzXC9SPd\n VNqQWyG8w7wqNnU4CYLxf2zNC+MaocQQVUNZt++SrKIUeXNRuWK78Y0+d\n s/3i89MnZmdH33IDetRUlAfneORzO4f1MPjXwlOn6SIPL5qA96DV+hkjq w==;", "X-CSE-ConnectionGUID": [ "IgtiCMJwRTOIq58M6uL4AQ==", "pzxVkKGOQyCWH/JPnmzHfA==" ], "X-CSE-MsgGUID": [ "1bj6B7FsRD+o52DGoKyROA==", "wo9yD0ZWTsWqSgFZXIaYYg==" ], "X-IronPort-AV": [ "E=McAfee;i=\"6800,10657,11700\"; a=\"83666864\"", "E=Sophos;i=\"6.21,289,1763452800\"; d=\"scan'208\";a=\"83666864\"", "E=Sophos;i=\"6.21,289,1763452800\"; d=\"scan'208\";a=\"212933109\"" ], "X-ExtLoop1": "1", "From": "Zhenzhong Duan <zhenzhong.duan@intel.com>", "To": "qemu-devel@nongnu.org", "Cc": "alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com,\n jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com,\n skolothumtho@nvidia.com, joao.m.martins@oracle.com,\n clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com,\n xudong.hao@intel.com, Zhenzhong Duan <zhenzhong.duan@intel.com>", "Subject": "[RFCv2 PATCH 10/13] intel_iommu_accel: Support pasid\n binding/unbinding and PIOTLB flushing", "Date": "Fri, 13 Feb 2026 22:41:30 -0500", "Message-ID": "<20260214034135.220413-11-zhenzhong.duan@intel.com>", "X-Mailer": "git-send-email 2.47.3", "In-Reply-To": "<20260214034135.220413-1-zhenzhong.duan@intel.com>", "References": "<20260214034135.220413-1-zhenzhong.duan@intel.com>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "Received-SPF": "pass client-ip=198.175.65.12;\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 development <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": "We just switched to use VTDACCELPASIDCacheEntry to cache pasid entry of\npassthrough device, also need to switch the binding/unbinding and PIOTLB\nflushing functions to use the same structure.\n\nAfter the switching, we could remove accel related code from\nvtd_pasid_cache_[reset/sync]_locked() to make intel_iommu.c cleaner.\n\nThe VTDAddressSpace of PASID_0 is still useful as VTD supports a legacy\nmode which needs shadow page table instead of nested page table.\n\nSigned-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>\n---\n hw/i386/intel_iommu_accel.h | 2 +-\n include/hw/i386/intel_iommu.h | 2 -\n hw/i386/intel_iommu.c | 17 +----\n hw/i386/intel_iommu_accel.c | 125 +++++++++++++++++-----------------\n 4 files changed, 64 insertions(+), 82 deletions(-)", "diff": "diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h\nindex 914c690c26..1ae46d9250 100644\n--- a/hw/i386/intel_iommu_accel.h\n+++ b/hw/i386/intel_iommu_accel.h\n@@ -16,6 +16,7 @@ typedef struct VTDACCELPASIDCacheEntry {\n VTDHostIOMMUDevice *vtd_hiod;\n VTDPASIDEntry pe;\n uint32_t pasid;\n+ uint32_t fs_hwpt_id;\n QLIST_ENTRY(VTDACCELPASIDCacheEntry) next;\n } VTDACCELPASIDCacheEntry;\n \n@@ -23,7 +24,6 @@ typedef struct VTDACCELPASIDCacheEntry {\n bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod,\n Error **errp);\n VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as);\n-bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp);\n void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_id,\n uint32_t pasid, hwaddr addr,\n uint64_t npages, bool ih);\ndiff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h\nindex bb957b93e0..64f963412a 100644\n--- a/include/hw/i386/intel_iommu.h\n+++ b/include/hw/i386/intel_iommu.h\n@@ -154,8 +154,6 @@ struct VTDAddressSpace {\n * with the guest IOMMU pgtables for a device.\n */\n IOVATree *iova_tree;\n-\n- uint32_t fs_hwpt_id;\n };\n \n struct VTDIOTLBEntry {\ndiff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c\nindex 96c9a616a8..a8d760eb51 100644\n--- a/hw/i386/intel_iommu.c\n+++ b/hw/i386/intel_iommu.c\n@@ -86,8 +86,6 @@ static void vtd_pasid_cache_reset_locked(IntelIOMMUState *s)\n VTDPASIDCacheEntry *pc_entry = &vtd_as->pasid_cache_entry;\n if (pc_entry->valid) {\n pc_entry->valid = false;\n- /* It's fatal to get failure during reset */\n- vtd_propagate_guest_pasid(vtd_as, &error_fatal);\n }\n }\n }\n@@ -3109,8 +3107,6 @@ static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value,\n VTDPASIDEntry pe;\n IOMMUNotifier *n;\n uint16_t did;\n- const char *err_prefix = \"Attaching to HWPT failed: \";\n- Error *local_err = NULL;\n \n if (vtd_dev_get_pe_from_pasid(vtd_as, &pe)) {\n if (!pc_entry->valid) {\n@@ -3131,9 +3127,6 @@ static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value,\n vtd_address_space_unmap(vtd_as, n);\n }\n vtd_switch_address_space(vtd_as);\n-\n- err_prefix = \"Detaching from HWPT failed: \";\n- goto do_bind_unbind;\n }\n \n /*\n@@ -3161,20 +3154,12 @@ static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value,\n if (!pc_entry->valid) {\n pc_entry->pasid_entry = pe;\n pc_entry->valid = true;\n- } else if (vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) {\n- err_prefix = \"Replacing HWPT attachment failed: \";\n- } else {\n+ } else if (!vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) {\n return;\n }\n \n vtd_switch_address_space(vtd_as);\n vtd_address_space_sync(vtd_as);\n-\n-do_bind_unbind:\n- /* TODO: Fault event injection into guest, report error to QEMU for now */\n- if (!vtd_propagate_guest_pasid(vtd_as, &local_err)) {\n- error_reportf_err(local_err, \"%s\", err_prefix);\n- }\n }\n \n static void vtd_pasid_cache_sync(IntelIOMMUState *s, VTDPASIDCacheInfo *pc_info)\ndiff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c\nindex c1890ca0a5..d7c1ff6b74 100644\n--- a/hw/i386/intel_iommu_accel.c\n+++ b/hw/i386/intel_iommu_accel.c\n@@ -111,23 +111,24 @@ static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,\n }\n \n static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod,\n- VTDAddressSpace *vtd_as)\n+ VTDACCELPASIDCacheEntry *vtd_pce)\n {\n HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);\n \n- if (!vtd_as->fs_hwpt_id) {\n+ if (!vtd_pce->fs_hwpt_id) {\n return;\n }\n- iommufd_backend_free_id(idev->iommufd, vtd_as->fs_hwpt_id);\n- vtd_as->fs_hwpt_id = 0;\n+ iommufd_backend_free_id(idev->iommufd, vtd_pce->fs_hwpt_id);\n+ vtd_pce->fs_hwpt_id = 0;\n }\n \n-static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,\n- VTDAddressSpace *vtd_as, Error **errp)\n+static bool vtd_device_attach_iommufd(VTDACCELPASIDCacheEntry *vtd_pce,\n+ Error **errp)\n {\n+ VTDHostIOMMUDevice *vtd_hiod = vtd_pce->vtd_hiod;\n HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);\n- VTDPASIDEntry *pe = &vtd_as->pasid_cache_entry.pasid_entry;\n- uint32_t hwpt_id = idev->hwpt_id;\n+ VTDPASIDEntry *pe = &vtd_pce->pe;\n+ uint32_t hwpt_id = idev->hwpt_id, pasid = vtd_pce->pasid;\n bool ret;\n \n /*\n@@ -147,14 +148,13 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,\n }\n }\n \n- ret = host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID, hwpt_id,\n- errp);\n- trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret);\n+ ret = host_iommu_device_iommufd_attach_hwpt(idev, pasid, hwpt_id, errp);\n+ trace_vtd_device_attach_hwpt(idev->devid, pasid, hwpt_id, ret);\n if (ret) {\n /* Destroy old fs_hwpt if it's a replacement */\n- vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);\n+ vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_pce);\n if (vtd_pe_pgtt_is_fst(pe)) {\n- vtd_as->fs_hwpt_id = hwpt_id;\n+ vtd_pce->fs_hwpt_id = hwpt_id;\n }\n } else if (vtd_pe_pgtt_is_fst(pe)) {\n iommufd_backend_free_id(idev->iommufd, hwpt_id);\n@@ -163,16 +163,17 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod,\n return ret;\n }\n \n-static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,\n- VTDAddressSpace *vtd_as, Error **errp)\n+static bool vtd_device_detach_iommufd(VTDACCELPASIDCacheEntry *vtd_pce,\n+ Error **errp)\n {\n+ VTDHostIOMMUDevice *vtd_hiod = vtd_pce->vtd_hiod;\n HostIOMMUDeviceIOMMUFD *idev = HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);\n- IntelIOMMUState *s = vtd_as->iommu_state;\n- uint32_t pasid = vtd_as->pasid;\n+ IntelIOMMUState *s = vtd_hiod->iommu_state;\n+ uint32_t pasid = vtd_pce->pasid;\n bool ret;\n \n- if (s->dmar_enabled && s->root_scalable) {\n- ret = host_iommu_device_iommufd_detach_hwpt(idev, IOMMU_NO_PASID, errp);\n+ if (pasid != IOMMU_NO_PASID || (s->dmar_enabled && s->root_scalable)) {\n+ ret = host_iommu_device_iommufd_detach_hwpt(idev, pasid, errp);\n trace_vtd_device_detach_hwpt(idev->devid, pasid, ret);\n } else {\n /*\n@@ -180,72 +181,47 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod,\n * we fallback to the default HWPT which contains shadow page table.\n * So guest DMA could still work.\n */\n- ret = host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID,\n+ ret = host_iommu_device_iommufd_attach_hwpt(idev, pasid,\n idev->hwpt_id, errp);\n trace_vtd_device_reattach_def_hwpt(idev->devid, pasid, idev->hwpt_id,\n ret);\n }\n \n if (ret) {\n- vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as);\n+ vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_pce);\n }\n \n return ret;\n }\n \n-bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp)\n-{\n- VTDPASIDCacheEntry *pc_entry = &vtd_as->pasid_cache_entry;\n- VTDHostIOMMUDevice *vtd_hiod = vtd_find_hiod_iommufd(vtd_as);\n-\n- /* Ignore emulated device or legacy VFIO backed device */\n- if (!vtd_as->iommu_state->fsts || !vtd_hiod) {\n- return true;\n- }\n-\n- if (pc_entry->valid) {\n- return vtd_device_attach_iommufd(vtd_hiod, vtd_as, errp);\n- }\n-\n- return vtd_device_detach_iommufd(vtd_hiod, vtd_as, errp);\n-}\n-\n /*\n- * This function is a loop function for the s->vtd_address_spaces\n- * list with VTDPIOTLBInvInfo as execution filter. It propagates\n- * the piotlb invalidation to host.\n+ * This function is a loop function for the s->vtd_host_iommu_dev\n+ * and vtd_hiod->pasid_cache_list lists with VTDPIOTLBInvInfo as\n+ * execution filter. It propagates the piotlb invalidation to host.\n */\n-static void vtd_flush_host_piotlb_locked(gpointer key, gpointer value,\n- gpointer user_data)\n+static void vtd_flush_host_piotlb(VTDACCELPASIDCacheEntry *vtd_pce,\n+ VTDPIOTLBInvInfo *piotlb_info)\n {\n- VTDPIOTLBInvInfo *piotlb_info = user_data;\n- VTDAddressSpace *vtd_as = value;\n- VTDHostIOMMUDevice *vtd_hiod = vtd_find_hiod_iommufd(vtd_as);\n- VTDPASIDCacheEntry *pc_entry = &vtd_as->pasid_cache_entry;\n+ VTDHostIOMMUDevice *vtd_hiod = vtd_pce->vtd_hiod;\n+ VTDPASIDEntry *pe = &vtd_pce->pe;\n uint16_t did;\n \n- if (!vtd_hiod) {\n- return;\n- }\n-\n- assert(vtd_as->pasid == PCI_NO_PASID);\n-\n /* Nothing to do if there is no first stage HWPT attached */\n- if (!pc_entry->valid ||\n- !vtd_pe_pgtt_is_fst(&pc_entry->pasid_entry)) {\n+ if (!vtd_pe_pgtt_is_fst(pe)) {\n return;\n }\n \n- did = VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry);\n+ did = VTD_SM_PASID_ENTRY_DID(pe);\n \n- if (piotlb_info->domain_id == did && piotlb_info->pasid == PASID_0) {\n+ if (piotlb_info->domain_id == did && piotlb_info->pasid == vtd_pce->pasid) {\n HostIOMMUDeviceIOMMUFD *idev =\n HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod);\n uint32_t entry_num = 1; /* Only implement one request for simplicity */\n Error *local_err = NULL;\n struct iommu_hwpt_vtd_s1_invalidate *cache = piotlb_info->inv_data;\n \n- if (!iommufd_backend_invalidate_cache(idev->iommufd, vtd_as->fs_hwpt_id,\n+ if (!iommufd_backend_invalidate_cache(idev->iommufd,\n+ vtd_pce->fs_hwpt_id,\n IOMMU_HWPT_INVALIDATE_DATA_VTD_S1,\n sizeof(*cache), &entry_num, cache,\n &local_err)) {\n@@ -261,6 +237,8 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_id,\n {\n struct iommu_hwpt_vtd_s1_invalidate cache_info = { 0 };\n VTDPIOTLBInvInfo piotlb_info;\n+ VTDHostIOMMUDevice *vtd_hiod;\n+ GHashTableIter as_it;\n \n cache_info.addr = addr;\n cache_info.npages = npages;\n@@ -271,12 +249,19 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_id,\n piotlb_info.inv_data = &cache_info;\n \n /*\n- * Go through each vtd_as instance in s->vtd_address_spaces, find out\n- * affected host devices which need host piotlb invalidation. Piotlb\n- * invalidation should check pasid cache per architecture point of view.\n+ * Go through each vtd_pce in vtd_hiod->pasid_cache_list for each host\n+ * device, find out affected host device pasid which need host piotlb\n+ * invalidation. Piotlb invalidation should check pasid cache per\n+ * architecture point of view.\n */\n- g_hash_table_foreach(s->vtd_address_spaces,\n- vtd_flush_host_piotlb_locked, &piotlb_info);\n+ g_hash_table_iter_init(&as_it, s->vtd_host_iommu_dev);\n+ while (g_hash_table_iter_next(&as_it, NULL, (void **)&vtd_hiod)) {\n+ VTDACCELPASIDCacheEntry *vtd_pce;\n+\n+ QLIST_FOREACH(vtd_pce, &vtd_hiod->pasid_cache_list, next) {\n+ vtd_flush_host_piotlb(vtd_pce, &piotlb_info);\n+ }\n+ }\n }\n \n static void vtd_pasid_cache_invalidate_one(VTDACCELPASIDCacheEntry *vtd_pce,\n@@ -284,6 +269,7 @@ static void vtd_pasid_cache_invalidate_one(VTDACCELPASIDCacheEntry *vtd_pce,\n {\n VTDPASIDEntry pe;\n uint16_t did;\n+ Error *local_err = NULL;\n \n /*\n * VTD_INV_DESC_PASIDC_G_DSI and VTD_INV_DESC_PASIDC_G_PASID_SI require\n@@ -309,6 +295,9 @@ static void vtd_pasid_cache_invalidate_one(VTDACCELPASIDCacheEntry *vtd_pce,\n * to be either all-zero or non-present. Either case means existing\n * pasid cache should be invalidated.\n */\n+ if (!vtd_device_detach_iommufd(vtd_pce, &local_err)) {\n+ error_reportf_err(local_err, \"%s\", \"Detaching from HWPT failed: \");\n+ }\n QLIST_REMOVE(vtd_pce, next);\n g_free(vtd_pce);\n }\n@@ -329,11 +318,17 @@ static void vtd_find_add_pc(VTDHostIOMMUDevice *vtd_hiod, uint32_t pasid,\n VTDPASIDEntry *pe)\n {\n VTDACCELPASIDCacheEntry *vtd_pce;\n+ Error *local_err = NULL;\n \n QLIST_FOREACH(vtd_pce, &vtd_hiod->pasid_cache_list, next) {\n if (vtd_pce->pasid == pasid) {\n if (vtd_pasid_entry_compare(pe, &vtd_pce->pe)) {\n vtd_pce->pe = *pe;\n+\n+ if (!vtd_device_attach_iommufd(vtd_pce, &local_err)) {\n+ error_reportf_err(local_err, \"%s\",\n+ \"Replacing HWPT attachment failed: \");\n+ }\n }\n return;\n }\n@@ -344,6 +339,10 @@ static void vtd_find_add_pc(VTDHostIOMMUDevice *vtd_hiod, uint32_t pasid,\n vtd_pce->pasid = pasid;\n vtd_pce->pe = *pe;\n QLIST_INSERT_HEAD(&vtd_hiod->pasid_cache_list, vtd_pce, next);\n+\n+ if (!vtd_device_attach_iommufd(vtd_pce, &local_err)) {\n+ error_reportf_err(local_err, \"%s\", \"Attaching to HWPT failed: \");\n+ }\n }\n \n /*\n", "prefixes": [ "RFCv2", "10/13" ] }