From nobody Sat Apr 11 19:55:47 2026 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=1775188645; cv=none; d=zohomail.com; s=zohoarc; b=USgOJoGbtfv8DX8C1oVLasXiCamROI7O04LyF0bLVYJIqe6BOyNB8YspzwI0Qrk3DkOrqucajYCBq7moEN6BeuaO8jJmr0GLHc3lmEcx5Wn9vcS0HG23nHkErYpjSDSAUFurE2QQ6oM0DjHZR2YWeX3w76U1r2GtyIFSjEedldI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188645; 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=G1WAb2Fa1W/XEeJ5xE3uRZ+UsSuoHQhgm/VutK0M0Pc=; b=NH/FZ7+KFtEDHcWnYCamLJ3I18IEk4bLdvbSmh/IX84ByfAChVQT8ruonk3tO6Y5loeImUHMaSLe4VtJexnDzkFCG4UwmYgoqzHjbCCmIJPPl6gQyL6ebEVM55VPmHiDgibwMlRZZELkS9cd/ItUYw2rIjufwtBOvBuCz8n/KCw= 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 1775188645075650.0849472804016; Thu, 2 Apr 2026 20:57:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Vdc-00019w-Rx; Thu, 02 Apr 2026 23:56:04 -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 1w8Vda-00018f-A6; Thu, 02 Apr 2026 23:56:02 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8VdY-0004MM-9o; Thu, 02 Apr 2026 23:56:02 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:55:58 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:55:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188560; x=1806724560; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4Rip2MVEYhHbVzh8uOkV8uN4ObmaZHKKkwkEvsDmxxI=; b=F1rst69L0gdFN3v5cUJCHIEpSKDZtFUgrVgiWssRssxbTrt7QUEFpxbo q0seqyNPgc4Ahjs93KYxK45M02N3Ue1bIhrYH6nIPcSxzPaBF9NkjhWLm B6VYjTTf23iGEMafg3nRNC7OdWZtwJ4zKMRVsOlfhIft12QOPyzhTcG2g a151VQkBdtJQCBV2hkeVngJ1h/qxKYWpSEWeiI3vJS51IOdumWo52K1hD UZCxsqBcTgurv1Bnpq3IWZUcwwMQuWqQvRDqkQ7kqIJE9FhxTMYardSbW 3Sg6Tg2yD/Kv95rkaDWRzjysfPdf4zbk9T8SgXB9G/pJL4pjchBIfIqhc g==; X-CSE-ConnectionGUID: xcNQRfX/TVy7PP2ktImCZQ== X-CSE-MsgGUID: Kz7hnxPGTV+5/Hni8Y16qg== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140594" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140594" X-CSE-ConnectionGUID: SvR28aqySa+svbZV035AzA== X-CSE-MsgGUID: sWItOVrkSy+a+fcCHV6lZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884849" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan , qemu-arm@nongnu.org Subject: [PATCH v3 02/14] iommufd: Extend attach/detach_hwpt callbacks to support pasid Date: Thu, 2 Apr 2026 23:55:26 -0400 Message-ID: <20260403035541.18355-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-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=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, 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_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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: qemu development 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: 1775188646547158500 Content-Type: text/plain; charset="utf-8" Same for the two wrappers and their call sites. Suggested-by: Shameer Kolothum Thodi Suggested-by: Nicolin Chen Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Reviewed-by: Nicolin Chen Tested-by: Xudong Hao Reviewed-by: C=C3=A9dric Le Goater --- include/system/iommufd.h | 16 +++++++++++----- backends/iommufd.c | 9 +++++---- hw/arm/smmuv3-accel.c | 12 ++++++++---- hw/i386/intel_iommu_accel.c | 19 ++++++++++--------- hw/vfio/iommufd.c | 10 +++++----- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/include/system/iommufd.h b/include/system/iommufd.h index 2925d116ac..da98e79439 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -138,14 +138,16 @@ struct HostIOMMUDeviceIOMMUFDClass { * * @hiodi: host IOMMU device backed by IOMMUFD backend. * + * @pasid: target pasid of the device to be attached. + * * @hwpt_id: ID of IOMMUFD hardware page table. * * @errp: pass an Error out when attachment fails. * * Returns: true on success, false on failure. */ - bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id, - Error **errp); + bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid, + uint32_t hwpt_id, Error **errp); /** * @detach_hwpt: detach host IOMMU device from IOMMUFD hardware page t= able. * VFIO and VDPA device can have different implementation. @@ -154,15 +156,19 @@ struct HostIOMMUDeviceIOMMUFDClass { * * @hiodi: host IOMMU device backed by IOMMUFD backend. * + * @pasid: target pasid of the device to be detached. + * * @errp: pass an Error out when attachment fails. * * Returns: true on success, false on failure. */ - bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp); + bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid, + Error **errp); }; =20 bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - uint32_t hwpt_id, Error **errp); -bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, + uint32_t pasid, uint32_t hwpt_i= d, Error **errp); +bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, + uint32_t pasid, Error **errp); #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 410b044370..cfde6f2b2c 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -539,23 +539,24 @@ bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be= , uint32_t viommu_id, } =20 bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - uint32_t hwpt_id, Error **errp) + uint32_t pasid, uint32_t hwpt_i= d, + Error **errp) { HostIOMMUDeviceIOMMUFDClass *hiodic =3D HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi); =20 g_assert(hiodic->attach_hwpt); - return hiodic->attach_hwpt(hiodi, hwpt_id, errp); + return hiodic->attach_hwpt(hiodi, pasid, hwpt_id, errp); } =20 bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - Error **errp) + uint32_t pasid, Error **errp) { HostIOMMUDeviceIOMMUFDClass *hiodic =3D HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi); =20 g_assert(hiodic->detach_hwpt); - return hiodic->detach_hwpt(hiodi, errp); + return hiodic->detach_hwpt(hiodi, pasid, errp); } =20 static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **er= rp) diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index 3630078751..3201bb25af 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -300,7 +300,8 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, return false; } =20 - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) { + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt= _id, + errp)) { if (s1_hwpt) { iommufd_backend_free_id(hiodi->iommufd, s1_hwpt->hwpt_id); g_free(s1_hwpt); @@ -575,7 +576,8 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDevi= ceIOMMUFD *hiodi, =20 /* Attach a HWPT based on SMMUv3 GBPA.ABORT value */ hwpt_id =3D smmuv3_accel_gbpa_hwpt(s, accel); - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) { + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt= _id, + errp)) { goto free_veventq; } return true; @@ -665,7 +667,8 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus= , void *opaque, hiodi =3D accel_dev->hiodi; accel =3D accel_dev->s_accel; /* Re-attach the default s2 hwpt id */ - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id, NULL= )) { + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, + hiodi->hwpt_id, NULL)) { error_report("Unable to attach the default HW pagetable: hiodi dev= id " "0x%x", hiodi->devid); } @@ -879,7 +882,8 @@ bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Erro= r **errp) =20 hwpt_id =3D smmuv3_accel_gbpa_hwpt(s, accel); QLIST_FOREACH(accel_dev, &accel->device_list, next) { - if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi, hwpt_= id, + if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi, + IOMMU_NO_PASID, hwpt_id, &local_err)) { error_append_hint(&local_err, "Failed to attach GBPA hwpt %u f= or " "hiodi devid %u", hwpt_id, diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index ed3793602b..3217a2afac 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -121,8 +121,9 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, } } =20 - ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp); - trace_vtd_device_attach_hwpt(hiodi->devid, vtd_as->pasid, hwpt_id, ret= ); + ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, h= wpt_id, + errp); + trace_vtd_device_attach_hwpt(hiodi->devid, IOMMU_NO_PASID, hwpt_id, re= t); if (ret) { /* Destroy old fs_hwpt if it's a replacement */ vtd_destroy_old_fs_hwpt(hiodi, vtd_as); @@ -141,22 +142,22 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, { HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); IntelIOMMUState *s =3D vtd_as->iommu_state; - uint32_t pasid =3D vtd_as->pasid; bool ret; =20 if (s->dmar_enabled && s->root_scalable) { - ret =3D host_iommu_device_iommufd_detach_hwpt(hiodi, errp); - trace_vtd_device_detach_hwpt(hiodi->devid, pasid, ret); + ret =3D host_iommu_device_iommufd_detach_hwpt(hiodi, IOMMU_NO_PASI= D, + errp); + trace_vtd_device_detach_hwpt(hiodi->devid, IOMMU_NO_PASID, ret); } else { /* * If DMAR remapping is disabled or guest switches to legacy mode, * we fallback to the default HWPT which contains shadow page tabl= e. * So guest DMA could still work. */ - ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_i= d, - errp); - trace_vtd_device_reattach_def_hwpt(hiodi->devid, pasid, hiodi->hwp= t_id, - ret); + ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASI= D, + hiodi->hwpt_id, errp); + trace_vtd_device_reattach_def_hwpt(hiodi->devid, IOMMU_NO_PASID, + hiodi->hwpt_id, ret); } =20 if (ret) { diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index f020b56208..ecabc33064 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -927,21 +927,21 @@ static void vfio_iommu_iommufd_class_init(ObjectClass= *klass, const void *data) =20 static bool host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - uint32_t hwpt_id, Error **errp) + uint32_t pasid, uint32_t hwpt_i= d, + Error **errp) { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(hiodi)->agent; =20 - return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, - hwpt_id, errp); + return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, pasid, hwpt_id, = errp); } =20 static bool host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - Error **errp) + uint32_t pasid, Error **errp) { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(hiodi)->agent; =20 - return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, e= rrp); + return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, pasid, errp); } =20 static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, --=20 2.47.3