From nobody Sat Apr 11 23:04:10 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=1772768748; cv=none; d=zohomail.com; s=zohoarc; b=L16SMT2zdDaDA/WAQS2L0UWVo8Y+1JJiL6NGeZIT1bHYxrT2IVCAeSGh5g/ZaQD2sVABci68+tSJYfsYnB6VDb5mksoE9UpaURdi60aTTcP+yfw6W3qA8lEgedsKb1jW+QWQnK3nd3bAvcWsPaQrXGUWkIYSVe6FkhwukuMkvgw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768748; 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=nVrNETZvvybRoxL+OeUbc47akboubRpnU/WreTH3G14=; b=Vy3iqu2R02vlQtWrqa6yRz94KFcBXNH3Le7MzO6N82UXWNmr0/ak69Wqsnk5GcoaddDGtKfYP4KyZqxllLsgn/gXB4dW3jf2ENMBKcV6G4C48BOv4Dqygprz/HVJJOxcDKKY0Srti4h5Jbui0SA44N7IgUTyYh+NtLCIYpqmHHo= 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 1772768748057412.3546513151937; Thu, 5 Mar 2026 19:45:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM70-0004J3-Su; Thu, 05 Mar 2026 22:44:26 -0500 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 1vyM6z-0004Iu-Iy for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:25 -0500 Received: from mgamail.intel.com ([192.198.163.8]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyM6x-00065P-OK for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:25 -0500 Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Mar 2026 19:44:22 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Mar 2026 19:44:19 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768663; x=1804304663; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=18dtOvGTWDZahCxxiczFaosuF0dbwCjkXGH5XXISKsQ=; b=e7rrqbCmjy51zRCClF8MMT6Yi6uftXhTM2nLL/OSK1EoQDB1WtYJuGfS iP6NL0gXkqdQeuykZH7nSzQoBZr/qUlLVXaIwULy6EOPaUkbGR5NC4mAP GZ8/98O2fAp5zNix4gjtJusj+vfIj0d+w8YlBGwTTJ6MJwI46+yidnKt6 5zMG8Wh5PCMdAxG/HYXQTQcgcZExh5M7l2BqRAgTocUuFFZEJ+HPQXyqh RAlBGfMM3yVo8ZInplCpDQXef2xNxALPUFds0UEOGhnzWDT/1pYHJeMgj /n+5E2KI7vSBReuN+9zHeXI9EgChWlp4j1zFjLK/U7IHiWGJ20lkQxAED A==; X-CSE-ConnectionGUID: dItTmlJSS5a5Fvtd0VLUYQ== X-CSE-MsgGUID: VdYBS0HMQBGfNytugvy1Zg== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448243" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448243" X-CSE-ConnectionGUID: nlfREK2DTuCxcM1W+tjH6Q== X-CSE-MsgGUID: WBsvf7DvS36HNYXSHEEp7A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613306" 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@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v1 01/13] vfio/iommufd: Extend attach/detach_hwpt callback implementations with pasid Date: Thu, 5 Mar 2026 22:43:55 -0500 Message-ID: <20260306034409.184873-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260306034409.184873-1-zhenzhong.duan@intel.com> References: <20260306034409.184873-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.8; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 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_VALIDITY_RPBL_BLOCKED=0.892, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.622, 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: 1772768751786154100 Content-Type: text/plain; charset="utf-8" For attachment with pasid, pasid together with flag VFIO_DEVICE_ATTACH_PASID should be passed in. Define IOMMU_NO_PASID to represent device attachment without pasid same as in kernel. The implementation is similar for detachment. Suggested-by: Shameer Kolothum Thodi Suggested-by: Nicolin Chen Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu --- include/hw/core/iommu.h | 2 ++ hw/vfio/iommufd.c | 44 +++++++++++++++++++++++++---------------- hw/vfio/trace-events | 4 ++-- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/include/hw/core/iommu.h b/include/hw/core/iommu.h index 86af315c15..bfcd511013 100644 --- a/include/hw/core/iommu.h +++ b/include/hw/core/iommu.h @@ -28,4 +28,6 @@ enum host_iommu_quirks { HOST_IOMMU_QUIRK_NESTING_PARENT_BYPASS_RO =3D BIT_ULL(0), }; =20 +#define IOMMU_NO_PASID 0 + #endif /* HW_IOMMU_H */ diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 131612eb83..b4c5e81b1d 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -21,6 +21,7 @@ #include "qapi/error.h" #include "system/iommufd.h" #include "hw/core/qdev.h" +#include "hw/core/iommu.h" #include "hw/vfio/vfio-cpr.h" #include "system/reset.h" #include "qemu/cutils.h" @@ -302,43 +303,48 @@ out: return ret; } =20 -static int iommufd_cdev_attach_ioas_hwpt(VFIODevice *vbasedev, uint32_t id, - Error **errp) +static int iommufd_cdev_pasid_attach_ioas_hwpt(VFIODevice *vbasedev, + uint32_t pasid, uint32_t id, + Error **errp) { int iommufd =3D vbasedev->iommufd->fd; struct vfio_device_attach_iommufd_pt attach_data =3D { .argsz =3D sizeof(attach_data), - .flags =3D 0, + .flags =3D pasid =3D=3D IOMMU_NO_PASID ? 0 : VFIO_DEVICE_ATTACH_PA= SID, + .pasid =3D pasid, .pt_id =3D id, }; =20 /* Attach device to an IOAS or hwpt within iommufd */ if (ioctl(vbasedev->fd, VFIO_DEVICE_ATTACH_IOMMUFD_PT, &attach_data)) { error_setg_errno(errp, errno, - "[iommufd=3D%d] error attach %s (%d) to id=3D%d", - iommufd, vbasedev->name, vbasedev->fd, id); + "[iommufd=3D%d] error attach %s (%d) pasid %d to = id=3D%d", + iommufd, vbasedev->name, vbasedev->fd, pasid, id); return -errno; } =20 - trace_iommufd_cdev_attach_ioas_hwpt(iommufd, vbasedev->name, - vbasedev->fd, id); + trace_iommufd_cdev_pasid_attach_ioas_hwpt(iommufd, vbasedev->name, + vbasedev->fd, pasid, id); return 0; } =20 -static bool iommufd_cdev_detach_ioas_hwpt(VFIODevice *vbasedev, Error **er= rp) +static bool iommufd_cdev_pasid_detach_ioas_hwpt(VFIODevice *vbasedev, + uint32_t pasid, Error **er= rp) { int iommufd =3D vbasedev->iommufd->fd; struct vfio_device_detach_iommufd_pt detach_data =3D { .argsz =3D sizeof(detach_data), - .flags =3D 0, + .flags =3D pasid =3D=3D IOMMU_NO_PASID ? 0 : VFIO_DEVICE_DETACH_PA= SID, + .pasid =3D pasid, }; =20 if (ioctl(vbasedev->fd, VFIO_DEVICE_DETACH_IOMMUFD_PT, &detach_data)) { - error_setg_errno(errp, errno, "detach %s failed", vbasedev->name); + error_setg_errno(errp, errno, "detach %s pasid %d failed", + vbasedev->name, pasid); return false; } =20 - trace_iommufd_cdev_detach_ioas_hwpt(iommufd, vbasedev->name); + trace_iommufd_cdev_pasid_detach_ioas_hwpt(iommufd, vbasedev->name, pas= id); return true; } =20 @@ -359,7 +365,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, /* Try to find a domain */ QLIST_FOREACH(hwpt, &container->hwpt_list, next) { if (!cpr_is_incoming()) { - ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt->hwpt_id,= errp); + ret =3D iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO= _PASID, + hwpt->hwpt_id, errp); } else if (vbasedev->cpr.hwpt_id =3D=3D hwpt->hwpt_id) { ret =3D 0; } else { @@ -432,7 +439,8 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, return false; } =20 - ret =3D iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt_id, errp); + ret =3D iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, = hwpt_id, + errp); if (ret) { iommufd_backend_free_id(container->be, hwpt_id); return false; @@ -485,7 +493,8 @@ static bool iommufd_cdev_attach_container(VFIODevice *v= basedev, =20 /* If CPR, we are already attached to ioas_id. */ return cpr_is_incoming() || - !iommufd_cdev_attach_ioas_hwpt(vbasedev, container->ioas_id, er= rp); + !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, + container->ioas_id, errp); } =20 static void iommufd_cdev_detach_container(VFIODevice *vbasedev, @@ -493,7 +502,7 @@ static void iommufd_cdev_detach_container(VFIODevice *v= basedev, { Error *err =3D NULL; =20 - if (!iommufd_cdev_detach_ioas_hwpt(vbasedev, &err)) { + if (!iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, &er= r)) { error_report_err(err); } =20 @@ -919,7 +928,8 @@ host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDev= iceIOMMUFD *idev, { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(idev)->agent; =20 - return !iommufd_cdev_attach_ioas_hwpt(vbasedev, hwpt_id, errp); + return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, + hwpt_id, errp); } =20 static bool @@ -928,7 +938,7 @@ host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDev= iceIOMMUFD *idev, { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(idev)->agent; =20 - return iommufd_cdev_detach_ioas_hwpt(vbasedev, errp); + return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, e= rrp); } =20 static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events index 846e3625c5..764a3e4855 100644 --- a/hw/vfio/trace-events +++ b/hw/vfio/trace-events @@ -182,8 +182,8 @@ vfio_vmstate_change_prepare(const char *name, int runni= ng, const char *reason, c =20 iommufd_cdev_connect_and_bind(int iommufd, const char *name, int devfd, in= t devid) " [iommufd=3D%d] Successfully bound device %s (fd=3D%d): output de= vid=3D%d" iommufd_cdev_getfd(const char *dev, int devfd) " %s (fd=3D%d)" -iommufd_cdev_attach_ioas_hwpt(int iommufd, const char *name, int devfd, in= t id) " [iommufd=3D%d] Successfully attached device %s (%d) to id=3D%d" -iommufd_cdev_detach_ioas_hwpt(int iommufd, const char *name) " [iommufd=3D= %d] Successfully detached %s" +iommufd_cdev_pasid_attach_ioas_hwpt(int iommufd, const char *name, int dev= fd, uint32_t pasid, int id) " [iommufd=3D%d] Successfully attached device %= s (%d) pasid %d to id=3D%d" +iommufd_cdev_pasid_detach_ioas_hwpt(int iommufd, const char *name, uint32_= t pasid) " [iommufd=3D%d] Successfully detached %s pasid %d" iommufd_cdev_fail_attach_existing_container(const char *msg) " %s" iommufd_cdev_alloc_ioas(int iommufd, int ioas_id) " [iommufd=3D%d] new IOM= MUFD container with ioasid=3D%d" iommufd_cdev_device_info(char *name, int devfd, int num_irqs, int num_regi= ons, int flags) " %s (%d) num_irqs=3D%d num_regions=3D%d flags=3D%d" --=20 2.47.3