From nobody Sat Apr 11 21:31:43 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 From nobody Sat Apr 11 21:31:43 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=1772768755; cv=none; d=zohomail.com; s=zohoarc; b=TZhnEaRGEQaB+Qt/EjI9dmrX+93PYUDim3NDC7u3hdHyj51A7kjgF7Nu8gA7ygJFFQUDXsHdDbzrZlv+ZrTgeY8kEpkHy1wP8nKJ77xzlKDS/kzmOzQooxJx25dx6s+95O0GtJmXsSQ34Ae31VA7eCkBpp9QzChPjriV4zd3RGI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768755; 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=ECCtehMECzrv2UFaFgRbdDZnuALkW6PNTT56+z/Sa10=; b=eMCF8PPQ+Wlv57L72HsMMxc37Gux84YekOsTDEeAZhXvbfQw6Je9B98qUE0qmxTSWdQzvRaoA9Kb7BMeD5dpQ6VYcSM5y9CXkmGewhc/b9u1W31qQyHY9vwqC5J8w0DQTyG+yH4W7H2U3ZW4Sa95lx72+GrQ/fcn+7PtYVYuAVk= 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 1772768755773891.7228423790485; Thu, 5 Mar 2026 19:45:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM77-0004Jx-1T; Thu, 05 Mar 2026 22:44:33 -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 1vyM75-0004Je-KY; Thu, 05 Mar 2026 22:44:31 -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 1vyM73-00065y-FP; Thu, 05 Mar 2026 22:44:31 -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:26 -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:23 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768669; x=1804304669; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0CFY7/ec9WolJ0TC6427evSbm7/oQkZWjLHaiUI4x3g=; b=RmfKrr6UzQLzQ9zrt1Cs0lcR9ZGvYbp45+4sTqWRuiCi73wCvI+kVGQs VoC4VqeRV/UG6snAu/T0iZQmUbeVPYT2HbupKEiK2aN9KAlH8o7jP6iec 0oUVLmi6ZPuv9OgoewbA1qjgNOYUaJN8EMlB/jMr+qKtDgCNskeJ+hbWO m4Gy8WdpPMCVjDeQzp+fA4hnMFUWLDXERkk/dv1N9hU8ZRBYOCsZ5yKSk oa6el24jqh2cgg5cpowNan8xPmgnL+4QyDTAbbs4xWBG4fhAgpbLzmN89 x9fX/x0X4YfmRIdzPJ+V2pfrl5Y4qQK6A+xkux4PBdYxqtO146F2qsPWl w==; X-CSE-ConnectionGUID: /v/M7AKWTUS4I9LEG7e8Xw== X-CSE-MsgGUID: Dub2oX9FTdKZScirWpDb3Q== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448251" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448251" X-CSE-ConnectionGUID: 2grBRXiLS7SAPapLN3m1dw== X-CSE-MsgGUID: s+pNRSstTAqp0bzNGsx85Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613311" 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 , qemu-arm@nongnu.org Subject: [PATCH v1 02/13] iommufd: Extend attach/detach_hwpt callbacks to support pasid Date: Thu, 5 Mar 2026 22:43:56 -0500 Message-ID: <20260306034409.184873-3-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: 1772768757731154100 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 --- include/system/iommufd.h | 16 +++++++++++----- backends/iommufd.c | 9 +++++---- hw/arm/smmuv3-accel.c | 12 ++++++++---- hw/i386/intel_iommu_accel.c | 8 +++++--- hw/vfio/iommufd.c | 10 +++++----- 5 files changed, 34 insertions(+), 21 deletions(-) diff --git a/include/system/iommufd.h b/include/system/iommufd.h index 80d72469a9..80c8423654 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -124,14 +124,16 @@ struct HostIOMMUDeviceIOMMUFDClass { * * @idev: host IOMMU device backed by IOMMUFD backend. * + * @pasid: pasid of host IOMMU device. + * * @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 *idev, uint32_t hwpt_id, - Error **errp); + bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *idev, 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. @@ -140,15 +142,19 @@ struct HostIOMMUDeviceIOMMUFDClass { * * @idev: host IOMMU device backed by IOMMUFD backend. * + * @pasid: pasid of host IOMMU device. + * * @errp: pass an Error out when attachment fails. * * Returns: true on success, false on failure. */ - bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *idev, Error **errp); + bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *idev, uint32_t pasid, + Error **errp); }; =20 bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev, - uint32_t hwpt_id, Error **errp); -bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev, + uint32_t pasid, uint32_t hwpt_i= d, Error **errp); +bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev, + uint32_t pasid, Error **errp); #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 13822df82f..153edf4f79 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -505,23 +505,24 @@ bool iommufd_backend_alloc_vdev(IOMMUFDBackend *be, u= int32_t dev_id, } =20 bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev, - uint32_t hwpt_id, Error **errp) + uint32_t pasid, uint32_t hwpt_i= d, + Error **errp) { HostIOMMUDeviceIOMMUFDClass *idevc =3D HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(idev); =20 g_assert(idevc->attach_hwpt); - return idevc->attach_hwpt(idev, hwpt_id, errp); + return idevc->attach_hwpt(idev, pasid, hwpt_id, errp); } =20 bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev, - Error **errp) + uint32_t pasid, Error **errp) { HostIOMMUDeviceIOMMUFDClass *idevc =3D HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(idev); =20 g_assert(idevc->detach_hwpt); - return idevc->detach_hwpt(idev, errp); + return idevc->detach_hwpt(idev, 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 f5cd4df336..6b04344959 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -294,7 +294,8 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, return false; } =20 - if (!host_iommu_device_iommufd_attach_hwpt(idev, hwpt_id, errp)) { + if (!host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID, hwpt_= id, + errp)) { if (s1_hwpt) { iommufd_backend_free_id(idev->iommufd, s1_hwpt->hwpt_id); g_free(s1_hwpt); @@ -436,7 +437,8 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDevi= ceIOMMUFD *idev, =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(idev, hwpt_id, errp)) { + if (!host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID, hwpt_= id, + errp)) { goto free_bypass_hwpt; } accel->viommu =3D viommu; @@ -524,7 +526,8 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus= , void *opaque, idev =3D accel_dev->idev; accel =3D accel_dev->s_accel; /* Re-attach the default s2 hwpt id */ - if (!host_iommu_device_iommufd_attach_hwpt(idev, idev->hwpt_id, NULL))= { + if (!host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID, + idev->hwpt_id, NULL)) { error_report("Unable to attach the default HW pagetable: idev devi= d " "0x%x", idev->devid); } @@ -720,7 +723,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->idev, hwpt_i= d, + if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->idev, + IOMMU_NO_PASID, hwpt_id, &local_err)) { error_append_hint(&local_err, "Failed to attach GBPA hwpt %u f= or " "idev devid %u", hwpt_id, accel_dev->idev->d= evid); diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 67d54849f2..45c08c8f6f 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -121,7 +121,8 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, } } =20 - ret =3D host_iommu_device_iommufd_attach_hwpt(idev, hwpt_id, errp); + ret =3D host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID, hw= pt_id, + errp); trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret); if (ret) { /* Destroy old fs_hwpt if it's a replacement */ @@ -145,7 +146,7 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, bool ret; =20 if (s->dmar_enabled && s->root_scalable) { - ret =3D host_iommu_device_iommufd_detach_hwpt(idev, errp); + ret =3D host_iommu_device_iommufd_detach_hwpt(idev, IOMMU_NO_PASID= , errp); trace_vtd_device_detach_hwpt(idev->devid, pasid, ret); } else { /* @@ -153,7 +154,8 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, * 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(idev, idev->hwpt_id,= errp); + ret =3D host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID, + idev->hwpt_id, errp); trace_vtd_device_reattach_def_hwpt(idev->devid, pasid, idev->hwpt_= id, ret); } diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index b4c5e81b1d..005f97fe25 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -924,21 +924,21 @@ static void vfio_iommu_iommufd_class_init(ObjectClass= *klass, const void *data) =20 static bool host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev, - uint32_t hwpt_id, Error **errp) + uint32_t pasid, uint32_t hwpt_i= d, + Error **errp) { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(idev)->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 *idev, - Error **errp) + uint32_t pasid, Error **errp) { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(idev)->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 From nobody Sat Apr 11 21:31:43 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=1772768777; cv=none; d=zohomail.com; s=zohoarc; b=f0fjgwZLHJjjbluA6l/511mGRrKuJFdEFcj8fjEO1pVwJBKBjf3EH6kHd/nyHarGC4LkSUZx1V/trxVONl/JtwThOqO8LHAFzb5/w8ki5iaPktmbWoRwGZamSoiWFN1HSaT1PyU/cwMtwEUGGu15AF94/FRWEQ52E+KEhZ61BV8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768777; 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=Cf7b9Fxi/T4IKa6hWEl1YTmJhzULCB2F+OP7SCjMGfI=; b=l/5Z1FcIlNRwzXHfFpHLdkHCilw3tfRnqCTTrdR4siYJcQo0MnHXriwO0GvKEQAngso4740zEMaNYlLPSI3zjgbCIWujOrltEVP0SUAgkNQUOfLGC8UZNcG8zEAkkIqmCX4mD1PM1tiagLqbFvQ5vam5AIBn8mNQ3b09U/agU8Y= 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 1772768777138924.2459084936411; Thu, 5 Mar 2026 19:46:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM78-0004Kp-MV; Thu, 05 Mar 2026 22:44:34 -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 1vyM76-0004Jq-PE for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:32 -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 1vyM75-00066N-5N for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:32 -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:29 -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:26 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768671; x=1804304671; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wZfm3l+pt9GPO5d+ueB5arOo7ms9ffG3yjILZIiceOQ=; b=NCA2jxCfxKaaGeaBIFU4b9cvaz0E32UUpTUVn/sANoTcRsGyyQyypFyN F72gJ9Vi2uIPLh4OYebPKekUckFOvGSIZtsrju5wa/pC8L77hvzgpDCLE UqQPpkTcvWhqhdxD2H3ArZZ783kzdzAP4ZUkDWDD0j2pudWocfohRNbav niJ+MjhtmojFaveWGjySO2yCz0PtFd3P4XtWRs5gjsFFGaqra7fncseW1 Dp24aSIdI0iSMuOEhHLsIlAPYsQZGDShwwUtV0Nskha+0DG5sjH3zBEfm po1ON4OfTf0qdimdw7orJu4HdccXXF6Kx7rCBiygljWvLi7O7c01O1Ve1 Q==; X-CSE-ConnectionGUID: tpJo1tumR+mEd0nW+NMq8g== X-CSE-MsgGUID: sE6zIousS/C14tNoHQWKtg== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448260" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448260" X-CSE-ConnectionGUID: iUuDeGgmQQ6VcqG0QBHcDg== X-CSE-MsgGUID: w847j0w7TlyvNdHJ/VYbbQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613330" 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 03/13] vfio/iommufd: Create nesting parent hwpt with IOMMU_HWPT_ALLOC_PASID flag Date: Thu, 5 Mar 2026 22:43:57 -0500 Message-ID: <20260306034409.184873-4-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: 1772768780118154100 Content-Type: text/plain; charset="utf-8" When both host device and vIOMMU have PASID enabled, then guest may setup pasid attached translation. We need to create the nesting parent hwpt with IOMMU_HWPT_ALLOC_PASID flag because according to uAPI, any domain attached to the non-PASID part of the device must also be flagged, otherwise attaching a PASID will blocked. Introduce a vfio_device_get_viommu_flags_pasid_supported() helper to facilitate this implementation. Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu --- include/hw/vfio/vfio-device.h | 1 + hw/vfio/device.c | 11 +++++++++++ hw/vfio/iommufd.c | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 828a31c006..dd0355eb3d 100644 --- a/include/hw/vfio/vfio-device.h +++ b/include/hw/vfio/vfio-device.h @@ -268,6 +268,7 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOCont= ainer *bcontainer, void vfio_device_unprepare(VFIODevice *vbasedev); =20 bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev); +bool vfio_device_get_viommu_flags_pasid_supported(VFIODevice *vbasedev); bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, uint32_t type, void *caps, uint32_t size); diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 973fc35b59..b15ca6ef0a 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -533,6 +533,17 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODev= ice *vbasedev) return false; } =20 +bool vfio_device_get_viommu_flags_pasid_supported(VFIODevice *vbasedev) +{ + VFIOPCIDevice *vdev =3D vfio_pci_from_vfio_device(vbasedev); + + if (vdev) { + return !!(pci_device_get_viommu_flags(PCI_DEVICE(vdev)) & + VIOMMU_FLAG_PASID_SUPPORTED); + } + return false; +} + bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, uint32_t type, void *caps, uint32_t size) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 005f97fe25..c408f9151b 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -360,6 +360,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, VendorCaps caps; VFIOIOASHwpt *hwpt; uint32_t hwpt_id; + uint8_t max_pasid_log2 =3D 0; int ret; =20 /* Try to find a domain */ @@ -405,7 +406,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vb= asedev, */ if (!iommufd_backend_get_device_info(vbasedev->iommufd, vbasedev->devi= d, &type, &caps, sizeof(caps), &hw_c= aps, - NULL, errp)) { + &max_pasid_log2, errp)) { return false; } =20 @@ -427,6 +428,11 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, } } =20 + if (max_pasid_log2 && + vfio_device_get_viommu_flags_pasid_supported(vbasedev)) { + flags |=3D IOMMU_HWPT_ALLOC_PASID; + } + if (cpr_is_incoming()) { hwpt_id =3D vbasedev->cpr.hwpt_id; goto skip_alloc; --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768749; cv=none; d=zohomail.com; s=zohoarc; b=bN0tvZvMs3zKH6az7y8svWMq+CO1JKIdEfQIsK5dHXOBGXvDYQVX0StpYB6HyDjF6hl8mClU2aq6VmlA4gEFUad3oygec9yd6MZARQ/CJ9ui62Dz2MM++mYT/JsI/aVS/ypcvkVGp9IIArnc4zAQiutDAZslGqqOuu2JNBjDnjk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768749; 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=4r7LxamsNAjRRDhuWSH0gIQ3+cj9bb4HfzZfgkqaRJ4=; b=PLJiyZHKKyolSBxr3N7HnpDGRpCKD/O3j61i3jNGrmpef2BSjQH/sjbbp/1k1xj5HJBE48ESriZS155+w0VYxpILkG9KNsXCBiWTYD5nrXymEtcJ1thxAGlYYgnttAO9qxoAA1cWCkaYRUWx/Oapp8lV+t00sPadKiA40SfYQPU= 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 1772768749406914.3105365286477; Thu, 5 Mar 2026 19:45:49 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7C-0004LS-UE; Thu, 05 Mar 2026 22:44:38 -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 1vyM7A-0004LK-Qm for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:37 -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 1vyM79-00066q-5j for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:36 -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:33 -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:30 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768675; x=1804304675; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eonLPTLYxHldYtymxYRdcAgJia5SUfNkvhTZV0PxX1E=; b=iPgYHdLM+4t62EPeY8woRHqAXwXE2N8DlpLaUDKSzwx2Zy3YNDmsyden /DLzUl3sSjbDqZEiN2A5Ugih1f7Cn8pWYn6mXGCJyM6OEp0gx8cGk+mny FYb5/nRvYaAOBXLtn/+eHQFjYHqroGDLKiSgvbvgX+gWPJT20O6wYHAXv 7KdfvlrbcKJ/v6mn3ZVqWuawDDCd6BEs7UFsGdI3jSVQfvnzkeNx9X7WV vFK+OL50Aw1tcYZgUfsfWJ70O1jIP1TYu+WQkJeae3fe29WEtP9H5Dm1l zb0nK/nS4LKaDmknnUZOfa/UEWsRXMiyik9Yn/S6FA3xLQe5plFqnLL/u w==; X-CSE-ConnectionGUID: nWUV2aClQc++VuZ8egRLtw== X-CSE-MsgGUID: cw8rb+nBRb6WRZBEfnzeyA== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448267" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448267" X-CSE-ConnectionGUID: UvSvuhViQz2cLlYXrvlHoA== X-CSE-MsgGUID: 2gAVdIDNSxyRYKg82obZBg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613340" 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 04/13] intel_iommu: Create the nested hwpt with IOMMU_HWPT_ALLOC_PASID flag Date: Thu, 5 Mar 2026 22:43:58 -0500 Message-ID: <20260306034409.184873-5-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: 1772768751720154100 Content-Type: text/plain; charset="utf-8" When pasid is enabled, any hwpt attached to non-PASID or PASID should be IOMMU_HWPT_ALLOC_PASID flagged, or else attachment fails. Change vtd_destroy_old_fs_hwpt() to pass in 'VTDHostIOMMUDevice *' for naming consistency. Signed-off-by: Zhenzhong Duan Reviewed-by: Clement Mathieu--Drif Reviewed-by: Yi Liu --- hw/i386/intel_iommu_accel.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 45c08c8f6f..c2757f3bcd 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -69,11 +69,13 @@ VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpa= ce *as) return NULL; } =20 -static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, +static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod, VTDPASIDEntry *pe, uint32_t *fs_hwpt_id, Error **errp) { + HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); struct iommu_hwpt_vtd_s1 vtd =3D {}; + uint32_t flags =3D vtd_hiod->iommu_state->pasid ? IOMMU_HWPT_ALLOC_PAS= ID : 0; =20 vtd.flags =3D (VTD_SM_PASID_ENTRY_SRE(pe) ? IOMMU_VTD_S1_SRE : 0) | (VTD_SM_PASID_ENTRY_WPE(pe) ? IOMMU_VTD_S1_WPE : 0) | @@ -82,13 +84,15 @@ static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *= idev, vtd.pgtbl_addr =3D (uint64_t)vtd_pe_get_fspt_base(pe); =20 return iommufd_backend_alloc_hwpt(idev->iommufd, idev->devid, idev->hw= pt_id, - 0, IOMMU_HWPT_DATA_VTD_S1, sizeof(vt= d), - &vtd, fs_hwpt_id, errp); + flags, IOMMU_HWPT_DATA_VTD_S1, + sizeof(vtd), &vtd, fs_hwpt_id, errp); } =20 -static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *idev, +static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod, VTDAddressSpace *vtd_as) { + HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); + if (!vtd_as->fs_hwpt_id) { return; } @@ -116,7 +120,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, } =20 if (vtd_pe_pgtt_is_fst(pe)) { - if (!vtd_create_fs_hwpt(idev, pe, &hwpt_id, errp)) { + if (!vtd_create_fs_hwpt(vtd_hiod, pe, &hwpt_id, errp)) { return false; } } @@ -126,7 +130,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret); if (ret) { /* Destroy old fs_hwpt if it's a replacement */ - vtd_destroy_old_fs_hwpt(idev, vtd_as); + vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as); if (vtd_pe_pgtt_is_fst(pe)) { vtd_as->fs_hwpt_id =3D hwpt_id; } @@ -161,7 +165,7 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, } =20 if (ret) { - vtd_destroy_old_fs_hwpt(idev, vtd_as); + vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as); } =20 return ret; --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768742; cv=none; d=zohomail.com; s=zohoarc; b=WxSwypGSald/ZSWsOT687f481DDg8j46KMReu3fSbjBRRIP+FAY13TaqWEkFt+fhGlLmD7WG7km3RKsIW2m+GrfFFlKe9bHZ7D1c5SEx7ONshVu/NGO3Uuw5GPX46uC5ju91C27IVR5G41KAMNCBGDwo+nKRuVyQXzcOAJPZlJ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768742; 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=Nj8a/H5D5obhe69Ctzg4etQjNTODbaECVANWlmDEe4k=; b=UbmNiP31HKR91KE3XxMXfZ9IytJTrCGBaNAppyOHlj067Ehaxx4ByTkDHfOCCmCxKyyfEbEyAaHWXAp2B69I3Vt+MRfvQWOeE1nsn5UmxOTHF5c1AhUdYhN8fDcJ7lu7AHGEGAKSuw4FMKWdbTz5+62PUNdfJeikwwVLUY8zzX0= 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 1772768740065855.5634664776453; Thu, 5 Mar 2026 19:45:40 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7F-0004MD-E6; Thu, 05 Mar 2026 22:44:41 -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 1vyM7D-0004LY-B3 for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:39 -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 1vyM7B-00066q-O8 for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:39 -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:37 -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:34 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768677; x=1804304677; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dLwKjHysMyWUSXi/3JataqskFEyXcx5vPfq/HPK+gnI=; b=UWEuSRgLxW508FpsiM6QeEkPv8yYS5jNFUiSZCUWJddn2CZ982nCmn+f OWp8fpioxl62wYYIcydFzwCcDArz3Ma0zqlLWIoacxl9ovPemC3SxhEFw XWsC2FQ40XMI2I3OQxcDE3GuOIG+HBuG0FZBi+rGhx9rEtCOMNI5fdGy1 08XPxVrLbOI7nxTlK+IBbS5Cz2lJfH/65Ad4+j9qFo2IGdH7kzfz9k7IN 2vj7pA6w5DXOLjKWpERIUBWii5/rwMqSnyFOBptOXH9FfjZzAzhR9d1UC 2EkOotXXGNcCd4uYo9L5zQ3PncYB0r0O/hlpKE8RlJdrdAouHg8Nk9OjC Q==; X-CSE-ConnectionGUID: O+U0GVvBS3W5vkGblZ4PNA== X-CSE-MsgGUID: 7169VqdEQWiwOSXb44jUmg== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448280" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448280" X-CSE-ConnectionGUID: 6PQHxinISeKA/GJlv9Oflw== X-CSE-MsgGUID: Ve0C4ycoQkC9XKok/1oMqw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613355" 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 05/13] intel_iommu: Change pasid property from bool to uint8 Date: Thu, 5 Mar 2026 22:43:59 -0500 Message-ID: <20260306034409.184873-6-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: 1772768745147158500 Content-Type: text/plain; charset="utf-8" 'x-pasid-mode' is a bool property, we need an extra 'pss' property to represent PASID size supported. Because there is no any device in QEMU supporting pasid capability yet, no guest could use the pasid feature until now, 'x-pasid-mode' takes no effect. So instead of an extra 'pss' property we can use a single 'pasid' property of uint8 type to represent if pasid is supported and the PASID bits size. A value of N > 0 means pasid is supported and N - 1 is the value in PSS field in ECAP register. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 2 +- include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 11a53aa369..db4f186a3e 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -195,7 +195,7 @@ #define VTD_ECAP_MHMV (15ULL << 20) #define VTD_ECAP_SRS (1ULL << 31) #define VTD_ECAP_NWFS (1ULL << 33) -#define VTD_ECAP_PSS (7ULL << 35) /* limit: MemTxAttrs::pid= */ +#define VTD_ECAP_SET_PSS(x, v) ((x)->ecap =3D deposit64((x)->ecap, 35= , 5, v)) #define VTD_ECAP_PASID (1ULL << 40) #define VTD_ECAP_PDS (1ULL << 42) #define VTD_ECAP_SMTS (1ULL << 43) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 54c2b6b77a..bb957b93e0 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -315,7 +315,7 @@ struct IntelIOMMUState { OnOffAuto intr_eim; /* Toggle for EIM cabability */ uint8_t aw_bits; /* Host/IOVA address width (in bits) */ bool dma_drain; /* Whether DMA r/w draining enabled */ - bool pasid; /* Whether to support PASID */ + uint8_t pasid; /* PASID supported in bits, 0 if not */ bool fs1gp; /* First Stage 1-GByte Page Support */ =20 /* Transient Mapping, Reserved(0) since VTD spec revision 3.2 */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index d24ba989bf..e5b9689fae 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4203,7 +4203,7 @@ static const Property vtd_properties[] =3D { DEFINE_PROP_BOOL("x-scalable-mode", IntelIOMMUState, scalable_mode, FA= LSE), DEFINE_PROP_BOOL("x-flts", IntelIOMMUState, fsts, FALSE), DEFINE_PROP_BOOL("snoop-control", IntelIOMMUState, snoop_control, fals= e), - DEFINE_PROP_BOOL("x-pasid-mode", IntelIOMMUState, pasid, false), + DEFINE_PROP_UINT8("pasid", IntelIOMMUState, pasid, 0), DEFINE_PROP_BOOL("svm", IntelIOMMUState, svm, false), DEFINE_PROP_BOOL("dma-drain", IntelIOMMUState, dma_drain, true), DEFINE_PROP_BOOL("stale-tm", IntelIOMMUState, stale_tm, false), @@ -5046,7 +5046,8 @@ static void vtd_cap_init(IntelIOMMUState *s) } =20 if (s->pasid) { - s->ecap |=3D VTD_ECAP_PASID | VTD_ECAP_PSS; + VTD_ECAP_SET_PSS(s, s->pasid - 1); + s->ecap |=3D VTD_ECAP_PASID; } } =20 --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768739; cv=none; d=zohomail.com; s=zohoarc; b=cuWfFVof6nGYDfsvPPKwVX5+/PaQjBwbIrxKMgoIbCPc7Ihej3kCddGWXv/GC4feIsUBT5ExocdQkRZPMeQc2cun/ZdnaKDjnXFz6clVErQK5m6/bs6xBLsGCXZ1pda+Yx54dCZ1I/b1enljy7s6zcHfQc+7rh+rkQp2JQgSKNw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768739; 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=JEpADGwHM/bgbNPE9bxhNIRKusep6McntRL4Z2KMNh8=; b=ltj7rZk5RDZFWHlKvQ5w6W1JtWWrx6seAMBJb+5B+KtBf4ednWDvbQr0f93Nkj2Ooid0sklPy+jznZv7e+oQMxEy86lOEdDwfDQdekDgfRSN5GhWwefzUrYEHOTmkolUEvy32gCLOKsoXhyJpRdZnUBtmnQKNvJDCXG3wFTdHHE= 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 1772768739374793.4174425586241; Thu, 5 Mar 2026 19:45:39 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7J-0004Mh-59; Thu, 05 Mar 2026 22:44:45 -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 1vyM7H-0004MF-1W for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:43 -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 1vyM7F-00066q-9q for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:42 -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:40 -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:37 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768681; x=1804304681; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bgET0pUqtfC1GpAEdQKcEp9Nbfix/RiapqmMyUlS4Y0=; b=PwRUnQbdHSWGIaLayn1DNj5kuEqa9uuPr+N1rwxB/76SdlwsjQ8XrjZI /Q44NCVYOddwh21xv1W7LXcfIX2PdJXQWMZcUGdmpUdsdUKkN8vjO1TTb J/oaxQIhWckurZl1BCXsZ964eOLaL5HKtUGgR0pUeK+YbrBbdThXlaO8s +PKqNX4M5k8IAN2+QKAaAQs/7ZGH+nemzYtztT3zhcyqNTFg4YWxHcFCq TMwHsL6HdBf0tlso0qM4D9b14ba4xQ+v0+5KSq5uKbWxrLSZIQuQad7Rg Adhox4uic8Dx01uvSNq7CImw5XxUimABJOw+GpfA2VQRdqCGgkrzHiJ88 w==; X-CSE-ConnectionGUID: rejs2Du5QHuVs2YoCfhFZw== X-CSE-MsgGUID: pNVImnBDTNu5HZAsqB8jiw== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448290" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448290" X-CSE-ConnectionGUID: GMv2sGzxSkGjKRDG9eG8GA== X-CSE-MsgGUID: hpKRLn8CTFakTNIR66yTeA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613368" 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 06/13] intel_iommu: Export some functions Date: Thu, 5 Mar 2026 22:44:00 -0500 Message-ID: <20260306034409.184873-7-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: 1772768741910154100 Content-Type: text/plain; charset="utf-8" Export some functions for accel code usages. Inline functions and MACROs are moved to internal header files. Then accel code in following patches could access them. Signed-off-by: Zhenzhong Duan Reviewed-by: Clement Mathieu--Drif Reviewed-by: Yi Liu --- hw/i386/intel_iommu_internal.h | 31 +++++++++++++++++++++++++ hw/i386/intel_iommu.c | 42 ++++++++-------------------------- 2 files changed, 40 insertions(+), 33 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index db4f186a3e..c7e107fe87 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -620,6 +620,12 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL1 0xffffffffffe00000ULL #define VTD_SM_CONTEXT_ENTRY_PRE 0x10ULL =20 +/* context entry operations */ +#define VTD_CE_GET_PASID_DIR_TABLE(ce) \ + ((ce)->val[0] & VTD_PASID_DIR_BASE_ADDR_MASK) +#define VTD_CE_GET_PRE(ce) \ + ((ce)->val[0] & VTD_SM_CONTEXT_ENTRY_PRE) + typedef struct VTDPASIDCacheInfo { uint8_t type; uint16_t did; @@ -746,4 +752,29 @@ static inline bool vtd_pe_pgtt_is_fst(VTDPASIDEntry *p= e) { return (VTD_SM_PASID_ENTRY_PGTT(pe) =3D=3D VTD_SM_PASID_ENTRY_FST); } + +static inline bool vtd_pdire_present(VTDPASIDDirEntry *pdire) +{ + return pdire->val & 1; +} + +static inline bool vtd_pe_present(VTDPASIDEntry *pe) +{ + return pe->val[0] & VTD_PASID_ENTRY_P; +} + +static inline int vtd_pasid_entry_compare(VTDPASIDEntry *p1, VTDPASIDEntry= *p2) +{ + return memcmp(p1, p2, sizeof(*p1)); +} + +int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base, uint32_t pasi= d, + VTDPASIDDirEntry *pdire); +int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, uint32_t pasid, + dma_addr_t addr, VTDPASIDEntry *pe); +int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num, + uint8_t devfn, VTDContextEntry *ce); +int vtd_ce_get_pasid_entry(IntelIOMMUState *s, VTDContextEntry *ce, + VTDPASIDEntry *pe, uint32_t pasid); +VTDAddressSpace *vtd_get_as_by_sid(IntelIOMMUState *s, uint16_t sid); #endif diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index e5b9689fae..744b5967b2 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -42,12 +42,6 @@ #include "migration/vmstate.h" #include "trace.h" =20 -/* context entry operations */ -#define VTD_CE_GET_PASID_DIR_TABLE(ce) \ - ((ce)->val[0] & VTD_PASID_DIR_BASE_ADDR_MASK) -#define VTD_CE_GET_PRE(ce) \ - ((ce)->val[0] & VTD_SM_CONTEXT_ENTRY_PRE) - /* * Paging mode for first-stage translation (VTD spec Figure 9-6) * 00: 4-level paging, 01: 5-level paging @@ -831,18 +825,12 @@ static inline bool vtd_pe_type_check(IntelIOMMUState = *s, VTDPASIDEntry *pe) } } =20 -static inline bool vtd_pdire_present(VTDPASIDDirEntry *pdire) -{ - return pdire->val & 1; -} - /** * Caller of this function should check present bit if wants * to use pdir entry for further usage except for fpd bit check. */ -static int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base, - uint32_t pasid, - VTDPASIDDirEntry *pdire) +int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base, uint32_t pasi= d, + VTDPASIDDirEntry *pdire) { uint32_t index; dma_addr_t addr, entry_size; @@ -860,15 +848,8 @@ static int vtd_get_pdire_from_pdir_table(dma_addr_t pa= sid_dir_base, return 0; } =20 -static inline bool vtd_pe_present(VTDPASIDEntry *pe) -{ - return pe->val[0] & VTD_PASID_ENTRY_P; -} - -static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, - uint32_t pasid, - dma_addr_t addr, - VTDPASIDEntry *pe) +int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, uint32_t pasid, + dma_addr_t addr, VTDPASIDEntry *pe) { uint8_t pgtt; uint32_t index; @@ -954,8 +935,8 @@ static int vtd_get_pe_from_pasid_table(IntelIOMMUState = *s, return 0; } =20 -static int vtd_ce_get_pasid_entry(IntelIOMMUState *s, VTDContextEntry *ce, - VTDPASIDEntry *pe, uint32_t pasid) +int vtd_ce_get_pasid_entry(IntelIOMMUState *s, VTDContextEntry *ce, + VTDPASIDEntry *pe, uint32_t pasid) { dma_addr_t pasid_dir_base; =20 @@ -1526,8 +1507,8 @@ static int vtd_ce_pasid_0_check(IntelIOMMUState *s, V= TDContextEntry *ce) } =20 /* Map a device to its corresponding domain (context-entry) */ -static int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num, - uint8_t devfn, VTDContextEntry *ce) +int vtd_dev_to_context_entry(IntelIOMMUState *s, uint8_t bus_num, + uint8_t devfn, VTDContextEntry *ce) { VTDRootEntry re; int ret_fr; @@ -1909,7 +1890,7 @@ static VTDAddressSpace *vtd_get_as_by_sid_and_pasid(I= ntelIOMMUState *s, vtd_find_as_by_sid_and_pasid, &key); } =20 -static VTDAddressSpace *vtd_get_as_by_sid(IntelIOMMUState *s, uint16_t sid) +VTDAddressSpace *vtd_get_as_by_sid(IntelIOMMUState *s, uint16_t sid) { return vtd_get_as_by_sid_and_pasid(s, sid, PCI_NO_PASID); } @@ -3133,11 +3114,6 @@ static inline int vtd_dev_get_pe_from_pasid(VTDAddre= ssSpace *vtd_as, return vtd_ce_get_pasid_entry(s, &ce, pe, vtd_as->pasid); } =20 -static int vtd_pasid_entry_compare(VTDPASIDEntry *p1, VTDPASIDEntry *p2) -{ - return memcmp(p1, p2, sizeof(*p1)); -} - /* Update or invalidate pasid cache based on the pasid entry in guest memo= ry. */ static void vtd_pasid_cache_sync_locked(gpointer key, gpointer value, gpointer user_data) --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768777; cv=none; d=zohomail.com; s=zohoarc; b=l2mXBqsWSNeE4AvffUNNYuQeTAIvpKsDjj8tyv3Re51eJHrZ1DugPHaHIT+hvBUyxBOcgXxwylzFIJiYlw7uUrLz+DezmFc/JW2WwcjrfbwuNjctvafAbq0D4FRrfDALxhLpCkEBaeE00t93RrJ18tZX9N5Ho85tcWxHDK7SmLE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768777; 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=HoJlHD6tRKXYaz317iZWXF4Bd+hprm6FzrnjOOM86yQ=; b=SatyY+jmO7JBZ/n2P25aNo+3OWMd6WwIGTEg0HA+DSYfd0MYfK4m47q4Q+jOpAxv63OVNhdS23PyPK7Wv4HdtAlr3jCGg077HVfUptOBBwmdTSIHAH8kDybaU7SVfBHADgQKSusx3duzSPnGSqxZ4qnJpOheMfkGHiuv0c5nMM4= 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 1772768777421549.4186846062594; Thu, 5 Mar 2026 19:46:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7M-0004N5-Ml; Thu, 05 Mar 2026 22:44:48 -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 1vyM7L-0004Mi-6w for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:47 -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 1vyM7J-00066q-3H for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:46 -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:44 -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:41 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768685; x=1804304685; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7Oc2ap/2vBHa1CvqcCRfuFQWfhHRxAgxxazTjCokbeM=; b=Sp5V1pqQLTxyPOXFM06EwUuCpr+qRWuCcnPkVkV6gSbza6D5osT+rFia dAxdMPAQcaqPmgOmsQ+jBFkcdoNBW2x3rsguf6jHENd1grCMq6XdeVs57 xo6xO7XKAfD7MfANvYyCwhMp5Z10Ues2PAbRRBYMMeGp10hAKJA7Uu5+E mb3+Jx5a9diRVyIfEE1i+JkBHYYvqJUMdznsGq22sEDZE6AwUbHjT1wwo UQcpKkIK/l9Bs7teb7W6mp3FDWEQQqjAHyJ/Ct5GJljr5iyGiVPi7TeN2 Mx1HuWdgxnqJ34zLhEPXA3iRDRTPtCTvJ6qIIqI6h/S+SXpHN8r7ofmLt w==; X-CSE-ConnectionGUID: 7Nt7CwMOQz+4pJXcju/SpQ== X-CSE-MsgGUID: FV4j+jiRQgi5ivHdukbNeg== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448297" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448297" X-CSE-ConnectionGUID: txIYmVGeR/uyVxyjWIcGog== X-CSE-MsgGUID: QCQRRwguRPO35uk8OFplrQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613378" 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 07/13] intel_iommu: Handle PASID entry addition for pc_inv_dsc request Date: Thu, 5 Mar 2026 22:44:01 -0500 Message-ID: <20260306034409.184873-8-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: 1772768779522158500 Content-Type: text/plain; charset="utf-8" Structure VTDAddressSpace includes some elements suitable for emulated device and passthrough device without PASID, e.g., address space, different memory regions, etc, it is also protected by vtd iommu lock, all these are useless and become a burden for passthrough device with PASID. When there are lots of PASIDs used in one device, the AS and MRs are all registered to memory core and impact the whole system performance. So instead of using VTDAddressSpace to cache pasid entry for each pasid of a passthrough device, we define a light weight structure VTDACCELPASIDCacheEntry with only necessary elements for each pasid. We will use this struct as a parameter to conduct binding/unbinding to nested hwpt and to record the current binded nested hwpt. It's also designed to support PASID_0. When guest creates new PASID entries, QEMU will capture the pc_inv_dsc (pasid cache invalidation) request, walk through each pasid in each passthrough device for valid pasid entries, create a new VTDACCELPASIDCacheEntry if not existing yet. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_accel.h | 13 +++ hw/i386/intel_iommu_internal.h | 8 ++ hw/i386/intel_iommu.c | 3 + hw/i386/intel_iommu_accel.c | 170 +++++++++++++++++++++++++++++++++ 4 files changed, 194 insertions(+) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index e5f0b077b4..a77fd06fe0 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -12,6 +12,13 @@ #define HW_I386_INTEL_IOMMU_ACCEL_H #include CONFIG_DEVICES =20 +typedef struct VTDACCELPASIDCacheEntry { + VTDHostIOMMUDevice *vtd_hiod; + VTDPASIDEntry pe; + uint32_t pasid; + QLIST_ENTRY(VTDACCELPASIDCacheEntry) next; +} VTDACCELPASIDCacheEntry; + #ifdef CONFIG_VTD_ACCEL bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); @@ -20,6 +27,7 @@ bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, E= rror **errp); void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, uint32_t pasid, hwaddr addr, uint64_t npages, bool ih); +void vtd_pasid_cache_sync_accel(IntelIOMMUState *s, VTDPASIDCacheInfo *pc_= info); void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, @@ -49,6 +57,11 @@ static inline void vtd_flush_host_piotlb_all_locked(Inte= lIOMMUState *s, { } =20 +static inline void vtd_pasid_cache_sync_accel(IntelIOMMUState *s, + VTDPASIDCacheInfo *pc_info) +{ +} + static inline void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops) { } diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index c7e107fe87..ede4db6d2d 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -616,6 +616,7 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_CTX_ENTRY_SCALABLE_SIZE 32 =20 #define PASID_0 0 +#define VTD_SM_CONTEXT_ENTRY_PDTS(x) extract64((x)->val[0], 9, 3) #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL0(aw) (0x1e0ULL | ~VTD_HAW_MASK(aw)) #define VTD_SM_CONTEXT_ENTRY_RSVD_VAL1 0xffffffffffe00000ULL #define VTD_SM_CONTEXT_ENTRY_PRE 0x10ULL @@ -646,6 +647,7 @@ typedef struct VTDPIOTLBInvInfo { #define VTD_PASID_DIR_BITS_MASK (0x3fffULL) #define VTD_PASID_DIR_INDEX(pasid) (((pasid) >> 6) & VTD_PASID_DIR_BITS= _MASK) #define VTD_PASID_DIR_FPD (1ULL << 1) /* Fault Processing Disa= ble */ +#define VTD_PASID_TABLE_ENTRY_NUM (1ULL << 6) #define VTD_PASID_TABLE_BITS_MASK (0x3fULL) #define VTD_PASID_TABLE_INDEX(pasid) ((pasid) & VTD_PASID_TABLE_BITS_MASK) #define VTD_PASID_ENTRY_FPD (1ULL << 1) /* Fault Processing Disa= ble */ @@ -711,6 +713,7 @@ typedef struct VTDHostIOMMUDevice { PCIBus *bus; uint8_t devfn; HostIOMMUDevice *hiod; + QLIST_HEAD(, VTDACCELPASIDCacheEntry) pasid_cache_list; } VTDHostIOMMUDevice; =20 /* @@ -768,6 +771,11 @@ static inline int vtd_pasid_entry_compare(VTDPASIDEntr= y *p1, VTDPASIDEntry *p2) return memcmp(p1, p2, sizeof(*p1)); } =20 +static inline uint32_t vtd_sm_ce_get_pdt_entry_num(VTDContextEntry *ce) +{ + return 1U << (VTD_SM_CONTEXT_ENTRY_PDTS(ce) + 7); +} + int vtd_get_pdire_from_pdir_table(dma_addr_t pasid_dir_base, uint32_t pasi= d, VTDPASIDDirEntry *pdire); int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUState *s, uint32_t pasid, diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 744b5967b2..984adc639a 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3202,6 +3202,8 @@ static void vtd_pasid_cache_sync(IntelIOMMUState *s, = VTDPASIDCacheInfo *pc_info) g_hash_table_foreach(s->vtd_address_spaces, vtd_pasid_cache_sync_locke= d, pc_info); vtd_iommu_unlock(s); + + vtd_pasid_cache_sync_accel(s, pc_info); } =20 static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s) @@ -4760,6 +4762,7 @@ static bool vtd_dev_set_iommu_device(PCIBus *bus, voi= d *opaque, int devfn, vtd_hiod->devfn =3D (uint8_t)devfn; vtd_hiod->iommu_state =3D s; vtd_hiod->hiod =3D hiod; + QLIST_INIT(&vtd_hiod->pasid_cache_list); =20 if (!vtd_check_hiod(s, vtd_hiod, errp)) { g_free(vtd_hiod); diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index c2757f3bcd..0acf3ae77f 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -257,6 +257,176 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState= *s, uint16_t domain_id, vtd_flush_host_piotlb_locked, &piotlb_info); } =20 +static void vtd_find_add_pc(VTDHostIOMMUDevice *vtd_hiod, uint32_t pasid, + VTDPASIDEntry *pe) +{ + VTDACCELPASIDCacheEntry *vtd_pce; + + QLIST_FOREACH(vtd_pce, &vtd_hiod->pasid_cache_list, next) { + if (vtd_pce->pasid =3D=3D pasid) { + if (vtd_pasid_entry_compare(pe, &vtd_pce->pe)) { + vtd_pce->pe =3D *pe; + } + return; + } + } + + vtd_pce =3D g_malloc0(sizeof(VTDACCELPASIDCacheEntry)); + vtd_pce->vtd_hiod =3D vtd_hiod; + vtd_pce->pasid =3D pasid; + vtd_pce->pe =3D *pe; + QLIST_INSERT_HEAD(&vtd_hiod->pasid_cache_list, vtd_pce, next); +} + +/* + * This function walks over PASID range within [start, end) in a single + * PASID table for entries matching @info type/did, then create + * VTDACCELPASIDCacheEntry if not exist yet. + */ +static void vtd_sm_pasid_table_walk_one(VTDHostIOMMUDevice *vtd_hiod, + dma_addr_t pt_base, + int start, + int end, + VTDPASIDCacheInfo *info) +{ + IntelIOMMUState *s =3D vtd_hiod->iommu_state; + VTDPASIDEntry pe; + int pasid; + + for (pasid =3D start; pasid < end; pasid++) { + if (vtd_get_pe_in_pasid_leaf_table(s, pasid, pt_base, &pe) || + !vtd_pe_present(&pe)) { + continue; + } + + if ((info->type =3D=3D VTD_INV_DESC_PASIDC_G_DSI || + info->type =3D=3D VTD_INV_DESC_PASIDC_G_PASID_SI) && + (info->did !=3D VTD_SM_PASID_ENTRY_DID(&pe))) { + /* + * VTD_PASID_CACHE_DOMSI and VTD_PASID_CACHE_PASIDSI + * requires domain id check. If domain id check fail, + * go to next pasid. + */ + continue; + } + + vtd_find_add_pc(vtd_hiod, pasid, &pe); + } +} + +/* + * In VT-d scalable mode translation, PASID dir + PASID table is used. + * This function aims at looping over a range of PASIDs in the given + * two level table to identify the pasid config in guest. + */ +static void vtd_sm_pasid_table_walk(VTDHostIOMMUDevice *vtd_hiod, + dma_addr_t pdt_base, + int start, int end, + VTDPASIDCacheInfo *info) +{ + VTDPASIDDirEntry pdire; + int pasid =3D start; + int pasid_next; + dma_addr_t pt_base; + + while (pasid < end) { + pasid_next =3D (pasid + VTD_PASID_TABLE_ENTRY_NUM) & + ~(VTD_PASID_TABLE_ENTRY_NUM - 1); + pasid_next =3D pasid_next < end ? pasid_next : end; + + if (!vtd_get_pdire_from_pdir_table(pdt_base, pasid, &pdire) + && vtd_pdire_present(&pdire)) { + pt_base =3D pdire.val & VTD_PASID_TABLE_BASE_ADDR_MASK; + vtd_sm_pasid_table_walk_one(vtd_hiod, pt_base, pasid, pasid_ne= xt, + info); + } + pasid =3D pasid_next; + } +} + +static void vtd_replay_pasid_bind_for_dev(VTDHostIOMMUDevice *vtd_hiod, + int start, int end, + VTDPASIDCacheInfo *pc_info) +{ + IntelIOMMUState *s =3D vtd_hiod->iommu_state; + VTDContextEntry ce; + int dev_max_pasid =3D 1 << vtd_hiod->hiod->caps.max_pasid_log2; + + if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_hiod->bus), + vtd_hiod->devfn, &ce)) { + VTDPASIDCacheInfo walk_info =3D *pc_info; + uint32_t ce_max_pasid =3D vtd_sm_ce_get_pdt_entry_num(&ce) * + VTD_PASID_TABLE_ENTRY_NUM; + + end =3D MIN(end, MIN(dev_max_pasid, ce_max_pasid)); + + vtd_sm_pasid_table_walk(vtd_hiod, VTD_CE_GET_PASID_DIR_TABLE(&ce), + start, end, &walk_info); + } +} + +/* + * This function replays the guest pasid bindings by walking the two level + * guest PASID table. For each valid pasid entry, it creates an entry + * VTDACCELPASIDCacheEntry dynamically if not exist yet. This entry holds + * info specific to a pasid + */ +void vtd_pasid_cache_sync_accel(IntelIOMMUState *s, VTDPASIDCacheInfo *pc_= info) +{ + int start =3D PASID_0, end =3D 1 << s->pasid; + VTDHostIOMMUDevice *vtd_hiod; + GHashTableIter as_it; + + if (!s->fsts) { + return; + } + + /* + * VTDPASIDCacheInfo honors PCI pasid but VTDACCELPASIDCacheEntry hono= rs + * iommu pasid + */ + if (pc_info->pasid =3D=3D PCI_NO_PASID) { + pc_info->pasid =3D PASID_0; + } + + switch (pc_info->type) { + case VTD_INV_DESC_PASIDC_G_PASID_SI: + start =3D pc_info->pasid; + end =3D pc_info->pasid + 1; + /* fall through */ + case VTD_INV_DESC_PASIDC_G_DSI: + /* + * loop all assigned devices, do domain id check in + * vtd_sm_pasid_table_walk_one() after get pasid entry. + */ + break; + case VTD_INV_DESC_PASIDC_G_GLOBAL: + /* loop all assigned devices */ + break; + default: + g_assert_not_reached(); + } + + /* + * In this replay, one only needs to care about the devices which are + * backed by host IOMMU. Those devices have a corresponding vtd_hiod + * in s->vtd_host_iommu_dev. For devices not backed by host IOMMU, it + * is not necessary to replay the bindings since their cache should be + * created in the future DMA address translation. + * + * VTD translation callback never accesses vtd_hiod and its correspond= ing + * cached pasid entry, so no iommu lock needed here. + */ + g_hash_table_iter_init(&as_it, s->vtd_host_iommu_dev); + while (g_hash_table_iter_next(&as_it, NULL, (void **)&vtd_hiod)) { + if (!object_dynamic_cast(OBJECT(vtd_hiod->hiod), + TYPE_HOST_IOMMU_DEVICE_IOMMUFD)) { + continue; + } + vtd_replay_pasid_bind_for_dev(vtd_hiod, start, end, pc_info); + } +} + static uint64_t vtd_get_host_iommu_quirks(uint32_t type, void *caps, uint32_t size) { --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768794; cv=none; d=zohomail.com; s=zohoarc; b=MJFTPTPTeMGnvE2tzNSPXn/w7WSvC2qeBttxxyS3xYXoth3cA8wLCM+Jg6MRd+VH9uMWIewn+K588mBOJAVwNQl5ccrKl2hBPKh2J9zB0vWTaN++Ko1fXC88DCEPdI+fcjnhT2Lky80FbYh2FH994iEPWiS38gcHQgM2nJ18MZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768794; 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=O5te5nYhmGMyg4PO6bGWqMHkRy5FRpluAmUlPxsOulg=; b=ZIjL/EWxSGB2Q504rDBW2xL0OPS2qS7O3iD6hWWuGOHyyKFuDD/ZsVEyLVY4X42PGxizx8M00yfJ6AuFBG9zuGj9B1/MfXkE8KVgmP4qTIJPDf2bBMa8P3bVtfVbBxrVfHDYM5mk6+OwBTbh1ue1fJIVDnDoDp8PygHY+cj8nOA= 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 1772768794769176.2304256837699; Thu, 5 Mar 2026 19:46:34 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7Q-0004Nc-3b; Thu, 05 Mar 2026 22:44:52 -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 1vyM7O-0004NE-4a for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:50 -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 1vyM7M-00066q-Ip for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:49 -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:48 -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:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768688; x=1804304688; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PKdn5LzomzWI5ewjG4Qibnqt/n1gU9PWe89FsmPl/so=; b=AB430QoAmg1aseBE3qEgk9p0X+NC3Q5NPtVWcSaVAdqWuArT5cjsHKeD SAelu1+hZLyVZUckmbNYRilP8GVl/FPX/WI6/W2aEDzlf5psU1bBfBET/ FU8GS88pkia5smSrfYJKWs2fnUJbiVr6GkSdlydlEQ8tuq0Fp+gNG8DjF vKWr7lt/GnpymJ6nV4asx9MtlxskWuq/G3+JNFofTYPvcSJjcpndJUU+K nKp6xPGYrSPB85BrzohABSU33nmKcS6f9fY2XVmyipQBIyFrP+LQ551HE b293/3eATleo2A/Wj4E+Azq3GQ+1hIxGSdSsTy4qac1rcvxRK+LF9Ws6O Q==; X-CSE-ConnectionGUID: fXC1aQwDTpSO3lNTb7CY9A== X-CSE-MsgGUID: fXq4D9boRVKYOYINYBdplw== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448304" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448304" X-CSE-ConnectionGUID: EnSih1SOTtKqFHpLqqtzgQ== X-CSE-MsgGUID: qwPi/f/yTlOJad14PAmsPA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613388" 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 08/13] intel_iommu: Handle PASID entry removal for pc_inv_dsc request Date: Thu, 5 Mar 2026 22:44:02 -0500 Message-ID: <20260306034409.184873-9-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: 1772768795526158500 Content-Type: text/plain; charset="utf-8" When guest deletes PASID entries, QEMU will capture the pasid cache invalidation request, walk through pasid_cache_list in each passthrough device to find stale VTDACCELPASIDCacheEntry and delete them. This happen before the PASID entry addition, because a new added entry should never be removed. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_accel.c | 70 +++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 0acf3ae77f..5a956af916 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -16,6 +16,28 @@ #include "hw/pci/pci_bus.h" #include "trace.h" =20 +static inline int vtd_hiod_get_pe_from_pasid(VTDACCELPASIDCacheEntry *vtd_= pce, + VTDPASIDEntry *pe) +{ + VTDHostIOMMUDevice *vtd_hiod =3D vtd_pce->vtd_hiod; + IntelIOMMUState *s =3D vtd_hiod->iommu_state; + uint32_t pasid =3D vtd_pce->pasid; + VTDContextEntry ce; + int ret; + + if (!s->dmar_enabled || !s->root_scalable) { + return -VTD_FR_RTADDR_INV_TTM; + } + + ret =3D vtd_dev_to_context_entry(s, pci_bus_num(vtd_hiod->bus), + vtd_hiod->devfn, &ce); + if (ret) { + return ret; + } + + return vtd_ce_get_pasid_entry(s, &ce, pe, pasid); +} + bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp) { @@ -257,6 +279,52 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState = *s, uint16_t domain_id, vtd_flush_host_piotlb_locked, &piotlb_info); } =20 +static void vtd_pasid_cache_invalidate_one(VTDACCELPASIDCacheEntry *vtd_pc= e, + VTDPASIDCacheInfo *pc_info) +{ + VTDPASIDEntry pe; + uint16_t did; + + /* + * VTD_INV_DESC_PASIDC_G_DSI and VTD_INV_DESC_PASIDC_G_PASID_SI require + * DID check. If DID doesn't match the value in cache or memory, then + * it's not a pasid entry we want to invalidate. + */ + switch (pc_info->type) { + case VTD_INV_DESC_PASIDC_G_PASID_SI: + if (pc_info->pasid !=3D vtd_pce->pasid) { + return; + } + /* Fall through */ + case VTD_INV_DESC_PASIDC_G_DSI: + did =3D VTD_SM_PASID_ENTRY_DID(&vtd_pce->pe); + if (pc_info->did !=3D did) { + return; + } + } + + if (vtd_hiod_get_pe_from_pasid(vtd_pce, &pe)) { + /* + * No valid pasid entry in guest memory. e.g. pasid entry was modi= fied + * to be either all-zero or non-present. Either case means existing + * pasid cache should be invalidated. + */ + QLIST_REMOVE(vtd_pce, next); + g_free(vtd_pce); + } +} + +/* Delete invalid pasid cache entry from pasid_cache_list */ +static void vtd_pasid_cache_invalidate(VTDHostIOMMUDevice *vtd_hiod, + VTDPASIDCacheInfo *pc_info) +{ + VTDACCELPASIDCacheEntry *vtd_pce, *next; + + QLIST_FOREACH_SAFE(vtd_pce, &vtd_hiod->pasid_cache_list, next, next) { + vtd_pasid_cache_invalidate_one(vtd_pce, pc_info); + } +} + static void vtd_find_add_pc(VTDHostIOMMUDevice *vtd_hiod, uint32_t pasid, VTDPASIDEntry *pe) { @@ -423,6 +491,8 @@ void vtd_pasid_cache_sync_accel(IntelIOMMUState *s, VTD= PASIDCacheInfo *pc_info) TYPE_HOST_IOMMU_DEVICE_IOMMUFD)) { continue; } + + vtd_pasid_cache_invalidate(vtd_hiod, pc_info); vtd_replay_pasid_bind_for_dev(vtd_hiod, start, end, pc_info); } } --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768728; cv=none; d=zohomail.com; s=zohoarc; b=KgXmSS9uf/itJsqf5XLaJsEUokBUYBJiI7kYZ3J43w8ABs4fRP6PAZwsWHS0I7SVpntTsmPQL4/lJLhhlET0rvONDeAFE0XbJB+x4h0uoKAW+NpVcUEDeV6gyhKzGKOMdyUc3CHpFfpO6iwexLaJDp9nBOEf2+67+U/2R5rcl84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768728; 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=RaGsnZGOVfBiPPfaIu9bpHx+odI7dbiEOXxPkrlJnT8=; b=Ck/8X1Qd/xh/za5UtDvQMXRmmtg2UcdEI2vUqZaMZMy7Vphe15bj3h/6upCxrcEM9l+6e7nk51MmgAzrnm5rAKe0Q5e+ROO2GZIFrWpSBxs831Q++nbfMFReokCMYhAqBmtUs5nKS1hRJtD2rmQpKbywVUqWK0rKJz96ursT4Pw= 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 1772768728308891.8057970848065; Thu, 5 Mar 2026 19:45:28 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7S-0004Nr-H0; Thu, 05 Mar 2026 22:44:54 -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 1vyM7R-0004Ne-N7 for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:53 -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 1vyM7Q-00066q-6H for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:53 -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:51 -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:48 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768692; x=1804304692; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FMdfoErsVWTZGvITzgR+KeePttIPFZ1xf2+gbybJYJM=; b=OXGmpfAu2QNc0IqpA5hBVxgd5F52HK+XgWCmK6NozSSOe6Iu8zgRJh2A oa2jDXBs/ZqGApqOCiFC24Ar1zoxLEJBcO6u1qNUKeZo6dFN3FW1BYV19 ybINdT/tbY+sAlV77mK5JO01bIauDR9IHK3bNen9iiFwc1smzvJyfm0G1 ES0p291dVJo2DrbD98ICYalAs50n1dNhbKes93z0xhDDiWAtSml5/TKia eSSpdGJlQcPnFfu9Zy7IkoZmur3JjxJ17cVdtWiDAyHj5pVp8n6XFf+sN iW6UJbw+cUO8xLJjn7TbF+ubPQvXqljMcFRTWZ0OdI36YbQFANaFVMEM1 w==; X-CSE-ConnectionGUID: vqqCoF5QS+aYoe1zQ7UN0A== X-CSE-MsgGUID: C/a8ev6pTJKITOxclxBIbg== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448311" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448311" X-CSE-ConnectionGUID: UxDkJC3YRCa3fPvyNUxZ3w== X-CSE-MsgGUID: ni954tg0TrSEM0seCbwgqw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613394" 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 09/13] intel_iommu: Handle PASID entry removal for system reset Date: Thu, 5 Mar 2026 22:44:03 -0500 Message-ID: <20260306034409.184873-10-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: 1772768729685154100 Content-Type: text/plain; charset="utf-8" When system level reset, DMA translation is turned off, all PASID entries become stale and should be deleted. vtd_hiod list is never accessed without BQL, so no need to guard with iommu lock. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_accel.h | 5 +++++ hw/i386/intel_iommu.c | 2 ++ hw/i386/intel_iommu_accel.c | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index a77fd06fe0..914c690c26 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -28,6 +28,7 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s,= uint16_t domain_id, uint32_t pasid, hwaddr addr, uint64_t npages, bool ih); void vtd_pasid_cache_sync_accel(IntelIOMMUState *s, VTDPASIDCacheInfo *pc_= info); +void vtd_pasid_cache_reset_accel(IntelIOMMUState *s); void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops); #else static inline bool vtd_check_hiod_accel(IntelIOMMUState *s, @@ -62,6 +63,10 @@ static inline void vtd_pasid_cache_sync_accel(IntelIOMMU= State *s, { } =20 +static inline void vtd_pasid_cache_reset_accel(IntelIOMMUState *s) +{ +} + static inline void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops) { } diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 984adc639a..b7d487bf5a 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -391,6 +391,8 @@ static void vtd_reset_caches(IntelIOMMUState *s) vtd_reset_context_cache_locked(s); vtd_pasid_cache_reset_locked(s); vtd_iommu_unlock(s); + + vtd_pasid_cache_reset_accel(s); } =20 static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 5a956af916..c1890ca0a5 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -497,6 +497,19 @@ void vtd_pasid_cache_sync_accel(IntelIOMMUState *s, VT= DPASIDCacheInfo *pc_info) } } =20 +/* Fake a gloal pasid cache invalidation to remove all pasid cache entries= */ +void vtd_pasid_cache_reset_accel(IntelIOMMUState *s) +{ + VTDPASIDCacheInfo pc_info =3D { .type =3D VTD_INV_DESC_PASIDC_G_GLOBAL= }; + VTDHostIOMMUDevice *vtd_hiod; + GHashTableIter as_it; + + g_hash_table_iter_init(&as_it, s->vtd_host_iommu_dev); + while (g_hash_table_iter_next(&as_it, NULL, (void **)&vtd_hiod)) { + vtd_pasid_cache_invalidate(vtd_hiod, &pc_info); + } +} + static uint64_t vtd_get_host_iommu_quirks(uint32_t type, void *caps, uint32_t size) { --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768777; cv=none; d=zohomail.com; s=zohoarc; b=VyDBy9Yqq2x+0BCjLv+l7XovNFHMjuIgmWRsd7zLZwHhkftCvgoMCnqObH6mobnh1pNwgeLZUhmuJWw/hQrk4F8nyKHM+e2UvNSQUYps81xwfDnooknVlVRx7jFKZn1sbXiFv9fdO3yUHHFWKOt+8hEDqFDt8ZxagCfWFsP3hrU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768777; 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=UoZoejKxI43bIwLkVnCFBsM5fQQNffbS7p3Mttofgbk=; b=ZQrECnpWcVwmyvaCClBvOL9nSpTHGNhR5YYOlCRdJnib/zxVpfYZJoZz9xSnoSZuBaW2d/xn4Ivhj8FSEnmpNiyYWRvyVnu2xzi5K5iVr3H40ksSCXZK1vCRneHhJVhDVUJpsPq6MSFMZPfqbYh5sO8gEmLg67ckNpc8fI6e6i8= 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 1772768777312197.8291312639683; Thu, 5 Mar 2026 19:46:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7d-0004Oy-2e; Thu, 05 Mar 2026 22:45:05 -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 1vyM7W-0004OH-HC for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:58 -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 1vyM7T-00066q-RQ for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:44:58 -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:55 -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:52 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768695; x=1804304695; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=aO1S2Zzbk9Za9t2nHKvhIBMp482gunk92lqjS4Uk5DM=; b=Ru1ysyeYAeHYlPReA02nlF9UNCHtWyivP8ExM9fnk1HKTrKjQ+YM/clz xikKMs3y4mvFTJx7egP0w6VLjYryAP7QmVc8bcZ/J8nfP2A7nAFHJk2x3 segKSfmuMiRzFqV7U3UGcdswoHg+2JKBt2cf3Yz5gEf90+Y1+vt3F+e/3 WzmZ8hFIl/792m7tonD2RbS1nd1viH+tF7/8NKNfvWwFV3kBQlll2lgVF MCPfRztcAgtoThyqWZh5MK9ASY7mxlugwPuZXrxXBLkE3a9Ny9MC+6CG9 2HOLMvL5UPmwJoUele1j5Ugxw+UiUNJw5lNyNhFzpOCH5tJplRRUYAWub g==; X-CSE-ConnectionGUID: vtHlNh2OSTaV+Lfi9dDZdg== X-CSE-MsgGUID: y7HCTrDUQXeCuvPgt04spw== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448325" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448325" X-CSE-ConnectionGUID: ILB2egHCQ7SAwP5aenAqgQ== X-CSE-MsgGUID: Atsf2fUrRa2wfsqnWukk5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613410" 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 10/13] intel_iommu_accel: Support pasid binding/unbinding and PIOTLB flushing Date: Thu, 5 Mar 2026 22:44:04 -0500 Message-ID: <20260306034409.184873-11-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: 1772768779526158500 Content-Type: text/plain; charset="utf-8" We just switched to use VTDACCELPASIDCacheEntry to cache pasid entry of passthrough device, also need to switch the binding/unbinding and PIOTLB flushing functions to use the same structure. After the switching, we could remove accel related code from vtd_pasid_cache_[reset/sync]_locked() to make intel_iommu.c cleaner. The VTDAddressSpace of PASID_0 is still useful as VTD supports a legacy mode which needs shadow page table instead of nested page table. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_accel.h | 2 +- include/hw/i386/intel_iommu.h | 2 - hw/i386/intel_iommu.c | 17 +---- hw/i386/intel_iommu_accel.c | 125 +++++++++++++++++----------------- 4 files changed, 64 insertions(+), 82 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 914c690c26..1ae46d9250 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -16,6 +16,7 @@ typedef struct VTDACCELPASIDCacheEntry { VTDHostIOMMUDevice *vtd_hiod; VTDPASIDEntry pe; uint32_t pasid; + uint32_t fs_hwpt_id; QLIST_ENTRY(VTDACCELPASIDCacheEntry) next; } VTDACCELPASIDCacheEntry; =20 @@ -23,7 +24,6 @@ typedef struct VTDACCELPASIDCacheEntry { bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as); -bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp); void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, uint32_t pasid, hwaddr addr, uint64_t npages, bool ih); diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index bb957b93e0..64f963412a 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -154,8 +154,6 @@ struct VTDAddressSpace { * with the guest IOMMU pgtables for a device. */ IOVATree *iova_tree; - - uint32_t fs_hwpt_id; }; =20 struct VTDIOTLBEntry { diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index b7d487bf5a..edd2b8f0cc 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -86,8 +86,6 @@ static void vtd_pasid_cache_reset_locked(IntelIOMMUState = *s) VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; if (pc_entry->valid) { pc_entry->valid =3D false; - /* It's fatal to get failure during reset */ - vtd_propagate_guest_pasid(vtd_as, &error_fatal); } } } @@ -3126,8 +3124,6 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, VTDPASIDEntry pe; IOMMUNotifier *n; uint16_t did; - const char *err_prefix =3D "Attaching to HWPT failed: "; - Error *local_err =3D NULL; =20 if (vtd_dev_get_pe_from_pasid(vtd_as, &pe)) { if (!pc_entry->valid) { @@ -3148,9 +3144,6 @@ static void vtd_pasid_cache_sync_locked(gpointer key,= gpointer value, vtd_address_space_unmap(vtd_as, n); } vtd_switch_address_space(vtd_as); - - err_prefix =3D "Detaching from HWPT failed: "; - goto do_bind_unbind; } =20 /* @@ -3178,20 +3171,12 @@ static void vtd_pasid_cache_sync_locked(gpointer ke= y, gpointer value, if (!pc_entry->valid) { pc_entry->pasid_entry =3D pe; pc_entry->valid =3D true; - } else if (vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) { - err_prefix =3D "Replacing HWPT attachment failed: "; - } else { + } else if (!vtd_pasid_entry_compare(&pe, &pc_entry->pasid_entry)) { return; } =20 vtd_switch_address_space(vtd_as); vtd_address_space_sync(vtd_as); - -do_bind_unbind: - /* TODO: Fault event injection into guest, report error to QEMU for no= w */ - if (!vtd_propagate_guest_pasid(vtd_as, &local_err)) { - error_reportf_err(local_err, "%s", err_prefix); - } } =20 static void vtd_pasid_cache_sync(IntelIOMMUState *s, VTDPASIDCacheInfo *pc= _info) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index c1890ca0a5..d7c1ff6b74 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -111,23 +111,24 @@ static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vt= d_hiod, } =20 static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod, - VTDAddressSpace *vtd_as) + VTDACCELPASIDCacheEntry *vtd_pce) { HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); =20 - if (!vtd_as->fs_hwpt_id) { + if (!vtd_pce->fs_hwpt_id) { return; } - iommufd_backend_free_id(idev->iommufd, vtd_as->fs_hwpt_id); - vtd_as->fs_hwpt_id =3D 0; + iommufd_backend_free_id(idev->iommufd, vtd_pce->fs_hwpt_id); + vtd_pce->fs_hwpt_id =3D 0; } =20 -static bool vtd_device_attach_iommufd(VTDHostIOMMUDevice *vtd_hiod, - VTDAddressSpace *vtd_as, Error **err= p) +static bool vtd_device_attach_iommufd(VTDACCELPASIDCacheEntry *vtd_pce, + Error **errp) { + VTDHostIOMMUDevice *vtd_hiod =3D vtd_pce->vtd_hiod; HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); - VTDPASIDEntry *pe =3D &vtd_as->pasid_cache_entry.pasid_entry; - uint32_t hwpt_id =3D idev->hwpt_id; + VTDPASIDEntry *pe =3D &vtd_pce->pe; + uint32_t hwpt_id =3D idev->hwpt_id, pasid =3D vtd_pce->pasid; bool ret; =20 /* @@ -147,14 +148,13 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, } } =20 - ret =3D host_iommu_device_iommufd_attach_hwpt(idev, IOMMU_NO_PASID, hw= pt_id, - errp); - trace_vtd_device_attach_hwpt(idev->devid, vtd_as->pasid, hwpt_id, ret); + ret =3D host_iommu_device_iommufd_attach_hwpt(idev, pasid, hwpt_id, er= rp); + trace_vtd_device_attach_hwpt(idev->devid, pasid, hwpt_id, ret); if (ret) { /* Destroy old fs_hwpt if it's a replacement */ - vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as); + vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_pce); if (vtd_pe_pgtt_is_fst(pe)) { - vtd_as->fs_hwpt_id =3D hwpt_id; + vtd_pce->fs_hwpt_id =3D hwpt_id; } } else if (vtd_pe_pgtt_is_fst(pe)) { iommufd_backend_free_id(idev->iommufd, hwpt_id); @@ -163,16 +163,17 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, return ret; } =20 -static bool vtd_device_detach_iommufd(VTDHostIOMMUDevice *vtd_hiod, - VTDAddressSpace *vtd_as, Error **err= p) +static bool vtd_device_detach_iommufd(VTDACCELPASIDCacheEntry *vtd_pce, + Error **errp) { + VTDHostIOMMUDevice *vtd_hiod =3D vtd_pce->vtd_hiod; HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->h= iod); - IntelIOMMUState *s =3D vtd_as->iommu_state; - uint32_t pasid =3D vtd_as->pasid; + IntelIOMMUState *s =3D vtd_hiod->iommu_state; + uint32_t pasid =3D vtd_pce->pasid; bool ret; =20 - if (s->dmar_enabled && s->root_scalable) { - ret =3D host_iommu_device_iommufd_detach_hwpt(idev, IOMMU_NO_PASID= , errp); + if (pasid !=3D IOMMU_NO_PASID || (s->dmar_enabled && s->root_scalable)= ) { + ret =3D host_iommu_device_iommufd_detach_hwpt(idev, pasid, errp); trace_vtd_device_detach_hwpt(idev->devid, pasid, ret); } else { /* @@ -180,72 +181,47 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, * 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(idev, IOMMU_NO_PASID, + ret =3D host_iommu_device_iommufd_attach_hwpt(idev, pasid, idev->hwpt_id, errp); trace_vtd_device_reattach_def_hwpt(idev->devid, pasid, idev->hwpt_= id, ret); } =20 if (ret) { - vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as); + vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_pce); } =20 return ret; } =20 -bool vtd_propagate_guest_pasid(VTDAddressSpace *vtd_as, Error **errp) -{ - VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; - VTDHostIOMMUDevice *vtd_hiod =3D vtd_find_hiod_iommufd(vtd_as); - - /* Ignore emulated device or legacy VFIO backed device */ - if (!vtd_as->iommu_state->fsts || !vtd_hiod) { - return true; - } - - if (pc_entry->valid) { - return vtd_device_attach_iommufd(vtd_hiod, vtd_as, errp); - } - - return vtd_device_detach_iommufd(vtd_hiod, vtd_as, errp); -} - /* - * This function is a loop function for the s->vtd_address_spaces - * list with VTDPIOTLBInvInfo as execution filter. It propagates - * the piotlb invalidation to host. + * This function is a loop function for the s->vtd_host_iommu_dev + * and vtd_hiod->pasid_cache_list lists with VTDPIOTLBInvInfo as + * execution filter. It propagates the piotlb invalidation to host. */ -static void vtd_flush_host_piotlb_locked(gpointer key, gpointer value, - gpointer user_data) +static void vtd_flush_host_piotlb(VTDACCELPASIDCacheEntry *vtd_pce, + VTDPIOTLBInvInfo *piotlb_info) { - VTDPIOTLBInvInfo *piotlb_info =3D user_data; - VTDAddressSpace *vtd_as =3D value; - VTDHostIOMMUDevice *vtd_hiod =3D vtd_find_hiod_iommufd(vtd_as); - VTDPASIDCacheEntry *pc_entry =3D &vtd_as->pasid_cache_entry; + VTDHostIOMMUDevice *vtd_hiod =3D vtd_pce->vtd_hiod; + VTDPASIDEntry *pe =3D &vtd_pce->pe; uint16_t did; =20 - if (!vtd_hiod) { - return; - } - - assert(vtd_as->pasid =3D=3D PCI_NO_PASID); - /* Nothing to do if there is no first stage HWPT attached */ - if (!pc_entry->valid || - !vtd_pe_pgtt_is_fst(&pc_entry->pasid_entry)) { + if (!vtd_pe_pgtt_is_fst(pe)) { return; } =20 - did =3D VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry); + did =3D VTD_SM_PASID_ENTRY_DID(pe); =20 - if (piotlb_info->domain_id =3D=3D did && piotlb_info->pasid =3D=3D PAS= ID_0) { + if (piotlb_info->domain_id =3D=3D did && piotlb_info->pasid =3D=3D vtd= _pce->pasid) { HostIOMMUDeviceIOMMUFD *idev =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod); uint32_t entry_num =3D 1; /* Only implement one request for simpli= city */ Error *local_err =3D NULL; struct iommu_hwpt_vtd_s1_invalidate *cache =3D piotlb_info->inv_da= ta; =20 - if (!iommufd_backend_invalidate_cache(idev->iommufd, vtd_as->fs_hw= pt_id, + if (!iommufd_backend_invalidate_cache(idev->iommufd, + vtd_pce->fs_hwpt_id, IOMMU_HWPT_INVALIDATE_DATA_V= TD_S1, sizeof(*cache), &entry_num, = cache, &local_err)) { @@ -261,6 +237,8 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *= s, uint16_t domain_id, { struct iommu_hwpt_vtd_s1_invalidate cache_info =3D { 0 }; VTDPIOTLBInvInfo piotlb_info; + VTDHostIOMMUDevice *vtd_hiod; + GHashTableIter as_it; =20 cache_info.addr =3D addr; cache_info.npages =3D npages; @@ -271,12 +249,19 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState= *s, uint16_t domain_id, piotlb_info.inv_data =3D &cache_info; =20 /* - * Go through each vtd_as instance in s->vtd_address_spaces, find out - * affected host devices which need host piotlb invalidation. Piotlb - * invalidation should check pasid cache per architecture point of vie= w. + * Go through each vtd_pce in vtd_hiod->pasid_cache_list for each host + * device, find out affected host device pasid which need host piotlb + * invalidation. Piotlb invalidation should check pasid cache per + * architecture point of view. */ - g_hash_table_foreach(s->vtd_address_spaces, - vtd_flush_host_piotlb_locked, &piotlb_info); + g_hash_table_iter_init(&as_it, s->vtd_host_iommu_dev); + while (g_hash_table_iter_next(&as_it, NULL, (void **)&vtd_hiod)) { + VTDACCELPASIDCacheEntry *vtd_pce; + + QLIST_FOREACH(vtd_pce, &vtd_hiod->pasid_cache_list, next) { + vtd_flush_host_piotlb(vtd_pce, &piotlb_info); + } + } } =20 static void vtd_pasid_cache_invalidate_one(VTDACCELPASIDCacheEntry *vtd_pc= e, @@ -284,6 +269,7 @@ static void vtd_pasid_cache_invalidate_one(VTDACCELPASI= DCacheEntry *vtd_pce, { VTDPASIDEntry pe; uint16_t did; + Error *local_err =3D NULL; =20 /* * VTD_INV_DESC_PASIDC_G_DSI and VTD_INV_DESC_PASIDC_G_PASID_SI require @@ -309,6 +295,9 @@ static void vtd_pasid_cache_invalidate_one(VTDACCELPASI= DCacheEntry *vtd_pce, * to be either all-zero or non-present. Either case means existing * pasid cache should be invalidated. */ + if (!vtd_device_detach_iommufd(vtd_pce, &local_err)) { + error_reportf_err(local_err, "%s", "Detaching from HWPT failed= : "); + } QLIST_REMOVE(vtd_pce, next); g_free(vtd_pce); } @@ -329,11 +318,17 @@ static void vtd_find_add_pc(VTDHostIOMMUDevice *vtd_h= iod, uint32_t pasid, VTDPASIDEntry *pe) { VTDACCELPASIDCacheEntry *vtd_pce; + Error *local_err =3D NULL; =20 QLIST_FOREACH(vtd_pce, &vtd_hiod->pasid_cache_list, next) { if (vtd_pce->pasid =3D=3D pasid) { if (vtd_pasid_entry_compare(pe, &vtd_pce->pe)) { vtd_pce->pe =3D *pe; + + if (!vtd_device_attach_iommufd(vtd_pce, &local_err)) { + error_reportf_err(local_err, "%s", + "Replacing HWPT attachment failed: "= ); + } } return; } @@ -344,6 +339,10 @@ static void vtd_find_add_pc(VTDHostIOMMUDevice *vtd_hi= od, uint32_t pasid, vtd_pce->pasid =3D pasid; vtd_pce->pe =3D *pe; QLIST_INSERT_HEAD(&vtd_hiod->pasid_cache_list, vtd_pce, next); + + if (!vtd_device_attach_iommufd(vtd_pce, &local_err)) { + error_reportf_err(local_err, "%s", "Attaching to HWPT failed: "); + } } =20 /* --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768775; cv=none; d=zohomail.com; s=zohoarc; b=HC3yhiFHis2YyiNgIi5JVY2jTwbbl7Cr/xWc/Xg6UDrCQF7+9OldvDyH8OQ+UBzVr97K+QwON+099W0hZWfuTJM2OyESH+xDvwksYBo7ljvbICW0hmEON3/kYkbSVKXckBkRIXvAEoaTk1HTJH9S3DUw1kqck3z5oE7eGSBeeNM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768775; 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=1Vlu6P4YngEf4ZZN0exqZPRad3IOO9V+7kWs3E3ikF4=; b=aowqIOWyCqYz3icL2aJhfWB4arTyBmI4uJdRNXe26dO7nk1Q9yr0x9QRViZ/MfR0leVxaF6a+iErNCIqqwPMWHfshSeLg9gQFh+23No9U1HS3uQZQrPV9+bly8rFloNKYcfFv1i2IwgRNZQ1nHsfpRxq1Ez5z6inx3X+Fk3HrW0= 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 1772768775348103.27169724431985; Thu, 5 Mar 2026 19:46:15 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7m-0004gJ-4u; Thu, 05 Mar 2026 22:45:14 -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 1vyM7j-0004ah-HV for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:45:11 -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 1vyM7g-00066q-Un for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:45:10 -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:58 -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:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768709; x=1804304709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GzTHKeCzkvGzGvmu2TSXymj1N9dxdmDs7odFcKcpL9U=; b=jWcLzDDS4LDadUG9zFBiAfEDAfq2km/g0/IO4RhQy0ns+tCYIRZ2QE1G nDQo3gmd0O8Uzn8Oh4u+CSxyVocauaxI2LMBS5bjpF+a1qW+3U69Ok1p3 swB+2UvwUeajlWxlyrTM8676dFqCx9kN12Z3CA6rCw8pSTKbb7XhwvPLp ZXvwTOl7LPBkf0tnDxm1WsuwvsH0GqFmnaWRNoS1+p7fYLtYLodpMLzyx 6+DhZibJZKJzGhXZoDD8eV2gqVxf0A0Rcdf0wtRZL0RK44DLK7x9VsMli YEuY1z9TvlUTQiJkCLU27PXilBbjqLnUXcL86biROWDzco6QmWCT+M8JJ A==; X-CSE-ConnectionGUID: ay/uaaSYRI6Zb53aIkTYTw== X-CSE-MsgGUID: esG7oj1+RRCLqmrrRTF0DQ== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448336" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448336" X-CSE-ConnectionGUID: 6BhxTXjSRyCt0nuiMANDew== X-CSE-MsgGUID: ZkaiZ92zRki14IIvjXhZNw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613427" 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 11/13] intel_iommu_accel: drop _lock suffix in vtd_flush_host_piotlb_all_locked() Date: Thu, 5 Mar 2026 22:44:05 -0500 Message-ID: <20260306034409.184873-12-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: 1772768777496158500 Content-Type: text/plain; charset="utf-8" In order to support PASID, we have switched from looping vtd_as to vtd_hiod, vtd_hiod represents host passthrough device and never deferenced without BQ= L. So we don't need extra iommu lock to protect it. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_accel.h | 14 +++++++------- hw/i386/intel_iommu.c | 7 ++++--- hw/i386/intel_iommu_accel.c | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index 1ae46d9250..3f1b1002b8 100644 --- a/hw/i386/intel_iommu_accel.h +++ b/hw/i386/intel_iommu_accel.h @@ -24,9 +24,9 @@ typedef struct VTDACCELPASIDCacheEntry { bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMMUDevice *vtd_hiod, Error **errp); VTDHostIOMMUDevice *vtd_find_hiod_iommufd(VTDAddressSpace *as); -void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, - uint32_t pasid, hwaddr addr, - uint64_t npages, bool ih); +void vtd_flush_host_piotlb_all_accel(IntelIOMMUState *s, uint16_t domain_i= d, + uint32_t pasid, hwaddr addr, + uint64_t npages, bool ih); void vtd_pasid_cache_sync_accel(IntelIOMMUState *s, VTDPASIDCacheInfo *pc_= info); void vtd_pasid_cache_reset_accel(IntelIOMMUState *s); void vtd_iommu_ops_update_accel(PCIIOMMUOps *ops); @@ -51,10 +51,10 @@ static inline bool vtd_propagate_guest_pasid(VTDAddress= Space *vtd_as, return true; } =20 -static inline void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, - uint16_t domain_id, - uint32_t pasid, hwaddr= addr, - uint64_t npages, bool = ih) +static inline void vtd_flush_host_piotlb_all_accel(IntelIOMMUState *s, + uint16_t domain_id, + uint32_t pasid, hwaddr = addr, + uint64_t npages, bool i= h) { } =20 diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index edd2b8f0cc..3ea5b92b34 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3011,11 +3011,11 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUS= tate *s, info.domain_id =3D domain_id; info.pasid =3D pasid; =20 + vtd_flush_host_piotlb_all_accel(s, domain_id, pasid, 0, (uint64_t)-1, + false); vtd_iommu_lock(s); g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_pasid, &info); - vtd_flush_host_piotlb_all_locked(s, domain_id, pasid, 0, (uint64_t)-1, - false); vtd_iommu_unlock(s); =20 QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) { @@ -3045,10 +3045,11 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUSt= ate *s, uint16_t domain_id, info.addr =3D addr; info.mask =3D ~((1 << am) - 1); =20 + vtd_flush_host_piotlb_all_accel(s, domain_id, pasid, addr, 1 << am, ih= ); + vtd_iommu_lock(s); g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_page_piotlb, &info); - vtd_flush_host_piotlb_all_locked(s, domain_id, pasid, addr, 1 << am, i= h); vtd_iommu_unlock(s); =20 vtd_iotlb_page_invalidate_notify(s, domain_id, addr, am, pasid); diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index d7c1ff6b74..acb1b1e238 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -231,9 +231,9 @@ static void vtd_flush_host_piotlb(VTDACCELPASIDCacheEnt= ry *vtd_pce, } } =20 -void vtd_flush_host_piotlb_all_locked(IntelIOMMUState *s, uint16_t domain_= id, - uint32_t pasid, hwaddr addr, - uint64_t npages, bool ih) +void vtd_flush_host_piotlb_all_accel(IntelIOMMUState *s, uint16_t domain_i= d, + uint32_t pasid, hwaddr addr, + uint64_t npages, bool ih) { struct iommu_hwpt_vtd_s1_invalidate cache_info =3D { 0 }; VTDPIOTLBInvInfo piotlb_info; --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768803; cv=none; d=zohomail.com; s=zohoarc; b=nyqUgk969IikCbv9iAEJvhwWc1XAhWuf+99lnkwCIm35XvA7HFXZd7FRJ2ht3pXK1EjJvuPcgOXuOKq0fnwBSqepSzm6Btef/drvELMkkHHVg7b2mDxlb8uW5ql6TOMNjrqD+PtyTRTRFY1tBGCZOMN+CEyQHTRlJXxWVSC17C8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768803; 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=E9z+TqpyXGN3D/s9rBN5Bpxsc119i7Lr0vmd3r6pxO8=; b=PON/ha9Ql22dL6iY8y7yB4nFq9jwY8GoEqFsBR3BlNCHifNhlO2L39ftgE+dh49YWGqNMEf0qQlY6Yyt8re5M2IDYIJk6hUgwqhA7yeUARfHtmimq8Wefem4kBalKtHonuz8jc8Zir8n7K3TR8l/hOuyRwubDwGuI6dFO91bWnU= 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 1772768803466420.0390329539832; Thu, 5 Mar 2026 19:46:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7n-0004in-6Z; Thu, 05 Mar 2026 22:45:15 -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 1vyM7l-0004dP-2H for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:45:13 -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 1vyM7h-00068f-3b for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:45:12 -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:45:02 -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:59 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768709; x=1804304709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=b91JdyM3r/MB3Pt3bkvQ/9SxtTmgr/eLQVr5X5DOaXU=; b=D9DPaXmY7cbF1cNi7vtqUcomcxLSZy0+NxshH2nyHor4nmzLj0nfPkxk 9I3bGSOmTqS7lODZW4iO8iB6V3Mvmt5FREwVYbGIBtKhsOrThX+tehrMM LpRMdVfAOOc0e75GKg63DQNwkjbnjIDIPASNGJrlXMZXvpCyMGwsoAD3W +H94v87Snr84i/fXjG19NTD2dNTfEWdMMAzRj4CqCL1SmWtPAjBgsen2Q DJFCM4SVkAAxLpkaABUBkREkXkD3e9BH64vLTPRdFZAcKD7B+bs4jXmBe fMEVYS+MaGRpa3TokFYd7wi6ZVhiz7XgSr0wK0GVi25qOJ44yXFfjRkQ+ Q==; X-CSE-ConnectionGUID: atKsW3Z8S3ytXR8uM3FqIQ== X-CSE-MsgGUID: DZJQtT2yRniul/HU2A9biw== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448343" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448343" X-CSE-ConnectionGUID: DNBX2CNzQiaFPYy1vJik6Q== X-CSE-MsgGUID: WYycjowlRsqNj+OEtUFvow== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613452" 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 12/13] intel_iommu_accel: Add pasid bits size check Date: Thu, 5 Mar 2026 22:44:06 -0500 Message-ID: <20260306034409.184873-13-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: 1772768804373154100 Content-Type: text/plain; charset="utf-8" If pasid bits size is bigger than host side, host could fail to emulate all bindings in guest. Add a check to fail device plug early. Pasid bits size should also be no more than 20 bits according to PCI spec. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 1 + hw/i386/intel_iommu.c | 5 +++++ hw/i386/intel_iommu_accel.c | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index ede4db6d2d..d6674861fd 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -196,6 +196,7 @@ #define VTD_ECAP_SRS (1ULL << 31) #define VTD_ECAP_NWFS (1ULL << 33) #define VTD_ECAP_SET_PSS(x, v) ((x)->ecap =3D deposit64((x)->ecap, 35= , 5, v)) +#define VTD_ECAP_PSS(ecap) extract64(ecap, 35, 5) #define VTD_ECAP_PASID (1ULL << 40) #define VTD_ECAP_PDS (1ULL << 42) #define VTD_ECAP_SMTS (1ULL << 43) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 3ea5b92b34..e99a9cf9c6 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -5559,6 +5559,11 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) error_setg(errp, "Need to set scalable mode for PASID"); return false; } + if (s->pasid > PCI_EXT_CAP_PASID_MAX_WIDTH) { + error_setg(errp, "PASID width %d, exceed Max PASID Width %d allowe= d " + "in PCI spec", s->pasid, PCI_EXT_CAP_PASID_MAX_WIDTH); + return false; + } =20 if (s->svm) { if (!x86_iommu->dt_supported) { diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index acb1b1e238..15412123d5 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -44,6 +44,7 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMM= UDevice *vtd_hiod, HostIOMMUDevice *hiod =3D vtd_hiod->hiod; struct HostIOMMUDeviceCaps *caps =3D &hiod->caps; struct iommu_hw_info_vtd *vtd =3D &caps->vendor_caps.vtd; + uint8_t hpasid =3D VTD_ECAP_PSS(vtd->ecap_reg) + 1; PCIBus *bus =3D vtd_hiod->bus; PCIDevice *pdev =3D bus->devices[vtd_hiod->devfn]; =20 @@ -64,6 +65,13 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOM= MUDevice *vtd_hiod, return false; } =20 + /* Only do the check when host device support PASIDs */ + if (caps->max_pasid_log2 && s->pasid > hpasid) { + error_setg(errp, "PASID bits size %d > host IOMMU PASID bits size = %d", + s->pasid, hpasid); + return false; + } + if (pci_device_get_iommu_bus_devfn(pdev, &bus, NULL, NULL)) { error_setg(errp, "Host device downstream to a PCI bridge is " "unsupported when x-flts=3Don"); --=20 2.47.3 From nobody Sat Apr 11 21:31:43 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=1772768747; cv=none; d=zohomail.com; s=zohoarc; b=YLH0BbGOvrTt0jcZi6gr1870ByB0DUDcltgqNjK+pgEhtYlDjyMRZ+Pa2m5Xl6UiMWpPu+U8TEUd29tse6nOY0v9xNR0C0br3Km/yObmh6uVAC6TiTHKD/gwv+TNe7+nomq8RHSfwOMHZVXYndhIwqvwoz++ZxbmQ2SIcNOIy4o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772768747; 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=0jTRdt+ebfZ6YM5HEgmmeilGiz6ebFr4M5DPZSD3UfI=; b=nqvCDpv3xzdK0aEy4e6IzcSAWt6WtelH+K/YFFSLEr4afIxxkKpMxrtvKwa3j21uHtyh780AXO6azgXURvr7+BYKx5ZyuQ4vvDhqYAW4xnMpxEuMYXzps3hGLNnzDWgojeZIpwseLXZcrgNKpRS5NVPfrmhE0xk333IpyDzddDs= 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 1772768746755839.7810986209423; Thu, 5 Mar 2026 19:45:46 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyM7m-0004iB-O8; Thu, 05 Mar 2026 22:45:14 -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 1vyM7k-0004cw-QR for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:45:12 -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 1vyM7h-0006Ja-3N for qemu-devel@nongnu.org; Thu, 05 Mar 2026 22:45:12 -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:45:05 -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:45:02 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1772768709; x=1804304709; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=/rSjrNJDHcn9lT9mlx+7/Jfo07GOetgWVoKK9X4qUbo=; b=EHD90/5Vxv/j5Dntozsv+N3S5XLw7v82Ipr6O8a0GX35u9dzWEVStY9B Byh19VYlD1cLdLk5NgbLwuWECoTJCqAd84cUNeFwsK7X0bh2uCEgUT7H3 BtmTHowi+DKItVTs0jIwg+6mnXZ5h+FSc8f3I3jJhSddfjnc0UzAKbbLj EzWbD86ID0OTt83jTMZl/RnWq/rGGAeahJBIA7l8YloJmPbXcol4lNNq2 UkUQT7vOMw5fKjpVWK41DErS36qmkh+2N0tP4JrkuuAKsC79vU5Nem4VH Pl4D6ivoxEddmo00HUKa368cKESzCvdc4T8bJhwAyP23M5yqui4weiRIy g==; X-CSE-ConnectionGUID: u1F46LUuQXWZoZP5klQ8lg== X-CSE-MsgGUID: v3+8uYECQOWaHhgjGpsAKw== X-IronPort-AV: E=McAfee;i="6800,10657,11720"; a="91448351" X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="91448351" X-CSE-ConnectionGUID: Wu0ypxU4SfWHqI/g8Yrjfw== X-CSE-MsgGUID: TpCaGPTUS3OKmQQs39jRdA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,104,1770624000"; d="scan'208";a="215613520" 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 13/13] intel_iommu: Expose flag VIOMMU_FLAG_PASID_SUPPORTED when configured Date: Thu, 5 Mar 2026 22:44:07 -0500 Message-ID: <20260306034409.184873-14-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: 1772768749392158500 Content-Type: text/plain; charset="utf-8" VFIO device will check flag VIOMMU_FLAG_PASID_SUPPORTED and expose PASID capability, or else guest could not enable PASID of this device even if vIOMMU's pasid is configured. This is the final knob to enable PASID. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index e99a9cf9c6..af4904e341 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4796,6 +4796,7 @@ static uint64_t vtd_get_viommu_flags(void *opaque) uint64_t flags; =20 flags =3D s->fsts ? VIOMMU_FLAG_WANT_NESTING_PARENT : 0; + flags |=3D s->pasid ? VIOMMU_FLAG_PASID_SUPPORTED : 0; =20 return flags; } --=20 2.47.3