From nobody Sat Apr 11 18:34:21 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=1775188655; cv=none; d=zohomail.com; s=zohoarc; b=idR8MxiiBSmq/6jQYXHVp0Nx271AC4SseX09qJThxwMczzg0+g8bIeHzrw9PDDKER+yjXvQbTSqWdzYWcNoiY7V2BeLjtjU1dTdD1hts5lVU/JQ63jadKpoy+Z/x8PNvQmnoYAUM3gpk9FH1urETjPGZveSZ39NzvoXuj97aSP8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188655; 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=OC6fuwQEdH2eJ2WRU1Roii8vFTJxj1CcTIvku0NIg14=; b=HuAshiMIqzQvEZNmvcPZPSgqMSqDZEfpTjUrb/PMrwXaqvmXSqVlVp4dcForLupdjb6cudv5Mt8DoEwJ9QhEJrce6K6a1NcD7R7UCRJB00Qji/nBVgO6tcLo4aEi8lOvdEq9MemZaA1VyFaSt15nyRQDRMxNh90ggJA93WQdt+g= 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 1775188655866255.129875402862; Thu, 2 Apr 2026 20:57:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8VdX-00018B-BD; Thu, 02 Apr 2026 23:55:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8VdV-00017b-LZ for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:55:57 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8VdT-0004Lu-P0 for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:55:57 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:55:54 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:55:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188556; x=1806724556; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vv9aGh3p6ZT5Ue5A4+Q0A/R3dYVysZvAy1NgM3aG/4I=; b=QLXRhI+Ny3osZkn6Ta7CBMswPgaVJ0JPeOFl38dVjBtxyh9cB5+8bxNP A7ilGOUrq4mMmm3dYaW5OzkwD25C6Fam5uDThqjsKry6yE9QO7QMQSwAX DYLICBPkXqHENm/H/atnGyemozHRB6uyDX1+NYCpnueBFr7U4Z2hQYX/v YmHtfOLqJ8kQCflzaloijt6cIV9A4d1VTY+533LBFMsknxixfe80FaCqy m/D2O4JkVMlq+WETts5PjPEJoonZkW+/Lgjs8bw7FYc7BwZRd5a1IlMhH TBhfYDb/c8f7s0Y1nRuhvE3RKMgH4svjavlHqQ+J85rfmdsL+C3ffDMFJ g==; X-CSE-ConnectionGUID: lMz1cD8UTT2nRuUigvSMmA== X-CSE-MsgGUID: FdpnL/Q2S8eDTSI+gTjfWg== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140587" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140587" X-CSE-ConnectionGUID: 3cRVvxOpTkW1aMJrC25h+Q== X-CSE-MsgGUID: 5EbvvaoJRQuolO+iJQDHNQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884845" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 01/14] vfio/iommufd: Extend attach/detach_hwpt callback implementations with pasid Date: Thu, 2 Apr 2026 23:55:25 -0400 Message-ID: <20260403035541.18355-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188656840158500 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 Reviewed-by: Nicolin Chen Tested-by: Xudong Hao Reviewed-by: C=C3=A9dric Le Goater --- 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 399b36aa75..f020b56208 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -20,6 +20,7 @@ #include "trace.h" #include "qapi/error.h" #include "system/iommufd.h" +#include "hw/core/iommu.h" #include "hw/core/qdev.h" #include "hw/vfio/vfio-cpr.h" #include "system/reset.h" @@ -305,43 +306,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 @@ -362,7 +368,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 { @@ -435,7 +442,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; @@ -488,7 +496,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, @@ -496,7 +505,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 @@ -922,7 +931,8 @@ host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDev= iceIOMMUFD *hiodi, { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(hiodi)->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 @@ -931,7 +941,7 @@ host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDev= iceIOMMUFD *hiodi, { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(hiodi)->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 18:34:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1775188645; cv=none; d=zohomail.com; s=zohoarc; b=USgOJoGbtfv8DX8C1oVLasXiCamROI7O04LyF0bLVYJIqe6BOyNB8YspzwI0Qrk3DkOrqucajYCBq7moEN6BeuaO8jJmr0GLHc3lmEcx5Wn9vcS0HG23nHkErYpjSDSAUFurE2QQ6oM0DjHZR2YWeX3w76U1r2GtyIFSjEedldI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188645; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=G1WAb2Fa1W/XEeJ5xE3uRZ+UsSuoHQhgm/VutK0M0Pc=; b=NH/FZ7+KFtEDHcWnYCamLJ3I18IEk4bLdvbSmh/IX84ByfAChVQT8ruonk3tO6Y5loeImUHMaSLe4VtJexnDzkFCG4UwmYgoqzHjbCCmIJPPl6gQyL6ebEVM55VPmHiDgibwMlRZZELkS9cd/ItUYw2rIjufwtBOvBuCz8n/KCw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1775188645075650.0849472804016; Thu, 2 Apr 2026 20:57:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Vdc-00019w-Rx; Thu, 02 Apr 2026 23:56:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vda-00018f-A6; Thu, 02 Apr 2026 23:56:02 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8VdY-0004MM-9o; Thu, 02 Apr 2026 23:56:02 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:55:58 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:55:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188560; x=1806724560; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4Rip2MVEYhHbVzh8uOkV8uN4ObmaZHKKkwkEvsDmxxI=; b=F1rst69L0gdFN3v5cUJCHIEpSKDZtFUgrVgiWssRssxbTrt7QUEFpxbo q0seqyNPgc4Ahjs93KYxK45M02N3Ue1bIhrYH6nIPcSxzPaBF9NkjhWLm B6VYjTTf23iGEMafg3nRNC7OdWZtwJ4zKMRVsOlfhIft12QOPyzhTcG2g a151VQkBdtJQCBV2hkeVngJ1h/qxKYWpSEWeiI3vJS51IOdumWo52K1hD UZCxsqBcTgurv1Bnpq3IWZUcwwMQuWqQvRDqkQ7kqIJE9FhxTMYardSbW 3Sg6Tg2yD/Kv95rkaDWRzjysfPdf4zbk9T8SgXB9G/pJL4pjchBIfIqhc g==; X-CSE-ConnectionGUID: xcNQRfX/TVy7PP2ktImCZQ== X-CSE-MsgGUID: Kz7hnxPGTV+5/Hni8Y16qg== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140594" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140594" X-CSE-ConnectionGUID: SvR28aqySa+svbZV035AzA== X-CSE-MsgGUID: sWItOVrkSy+a+fcCHV6lZw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884849" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan , qemu-arm@nongnu.org Subject: [PATCH v3 02/14] iommufd: Extend attach/detach_hwpt callbacks to support pasid Date: Thu, 2 Apr 2026 23:55:26 -0400 Message-ID: <20260403035541.18355-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188646547158500 Content-Type: text/plain; charset="utf-8" Same for the two wrappers and their call sites. Suggested-by: Shameer Kolothum Thodi Suggested-by: Nicolin Chen Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Reviewed-by: Nicolin Chen Tested-by: Xudong Hao Reviewed-by: C=C3=A9dric Le Goater --- include/system/iommufd.h | 16 +++++++++++----- backends/iommufd.c | 9 +++++---- hw/arm/smmuv3-accel.c | 12 ++++++++---- hw/i386/intel_iommu_accel.c | 19 ++++++++++--------- hw/vfio/iommufd.c | 10 +++++----- 5 files changed, 39 insertions(+), 27 deletions(-) diff --git a/include/system/iommufd.h b/include/system/iommufd.h index 2925d116ac..da98e79439 100644 --- a/include/system/iommufd.h +++ b/include/system/iommufd.h @@ -138,14 +138,16 @@ struct HostIOMMUDeviceIOMMUFDClass { * * @hiodi: host IOMMU device backed by IOMMUFD backend. * + * @pasid: target pasid of the device to be attached. + * * @hwpt_id: ID of IOMMUFD hardware page table. * * @errp: pass an Error out when attachment fails. * * Returns: true on success, false on failure. */ - bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t hwpt_id, - Error **errp); + bool (*attach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid, + uint32_t hwpt_id, Error **errp); /** * @detach_hwpt: detach host IOMMU device from IOMMUFD hardware page t= able. * VFIO and VDPA device can have different implementation. @@ -154,15 +156,19 @@ struct HostIOMMUDeviceIOMMUFDClass { * * @hiodi: host IOMMU device backed by IOMMUFD backend. * + * @pasid: target pasid of the device to be detached. + * * @errp: pass an Error out when attachment fails. * * Returns: true on success, false on failure. */ - bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, Error **errp); + bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *hiodi, uint32_t pasid, + Error **errp); }; =20 bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - uint32_t hwpt_id, Error **errp); -bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, + uint32_t pasid, uint32_t hwpt_i= d, Error **errp); +bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, + uint32_t pasid, Error **errp); #endif diff --git a/backends/iommufd.c b/backends/iommufd.c index 410b044370..cfde6f2b2c 100644 --- a/backends/iommufd.c +++ b/backends/iommufd.c @@ -539,23 +539,24 @@ bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be= , uint32_t viommu_id, } =20 bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - uint32_t hwpt_id, Error **errp) + uint32_t pasid, uint32_t hwpt_i= d, + Error **errp) { HostIOMMUDeviceIOMMUFDClass *hiodic =3D HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi); =20 g_assert(hiodic->attach_hwpt); - return hiodic->attach_hwpt(hiodi, hwpt_id, errp); + return hiodic->attach_hwpt(hiodi, pasid, hwpt_id, errp); } =20 bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - Error **errp) + uint32_t pasid, Error **errp) { HostIOMMUDeviceIOMMUFDClass *hiodic =3D HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(hiodi); =20 g_assert(hiodic->detach_hwpt); - return hiodic->detach_hwpt(hiodi, errp); + return hiodic->detach_hwpt(hiodi, pasid, errp); } =20 static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **er= rp) diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c index 3630078751..3201bb25af 100644 --- a/hw/arm/smmuv3-accel.c +++ b/hw/arm/smmuv3-accel.c @@ -300,7 +300,8 @@ bool smmuv3_accel_install_ste(SMMUv3State *s, SMMUDevic= e *sdev, int sid, return false; } =20 - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) { + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt= _id, + errp)) { if (s1_hwpt) { iommufd_backend_free_id(hiodi->iommufd, s1_hwpt->hwpt_id); g_free(s1_hwpt); @@ -575,7 +576,8 @@ smmuv3_accel_alloc_viommu(SMMUv3State *s, HostIOMMUDevi= ceIOMMUFD *hiodi, =20 /* Attach a HWPT based on SMMUv3 GBPA.ABORT value */ hwpt_id =3D smmuv3_accel_gbpa_hwpt(s, accel); - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp)) { + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, hwpt= _id, + errp)) { goto free_veventq; } return true; @@ -665,7 +667,8 @@ static void smmuv3_accel_unset_iommu_device(PCIBus *bus= , void *opaque, hiodi =3D accel_dev->hiodi; accel =3D accel_dev->s_accel; /* Re-attach the default s2 hwpt id */ - if (!host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_id, NULL= )) { + if (!host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, + hiodi->hwpt_id, NULL)) { error_report("Unable to attach the default HW pagetable: hiodi dev= id " "0x%x", hiodi->devid); } @@ -879,7 +882,8 @@ bool smmuv3_accel_attach_gbpa_hwpt(SMMUv3State *s, Erro= r **errp) =20 hwpt_id =3D smmuv3_accel_gbpa_hwpt(s, accel); QLIST_FOREACH(accel_dev, &accel->device_list, next) { - if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi, hwpt_= id, + if (!host_iommu_device_iommufd_attach_hwpt(accel_dev->hiodi, + IOMMU_NO_PASID, hwpt_id, &local_err)) { error_append_hint(&local_err, "Failed to attach GBPA hwpt %u f= or " "hiodi devid %u", hwpt_id, diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index ed3793602b..3217a2afac 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -121,8 +121,9 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, } } =20 - ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, hwpt_id, errp); - trace_vtd_device_attach_hwpt(hiodi->devid, vtd_as->pasid, hwpt_id, ret= ); + ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, h= wpt_id, + errp); + trace_vtd_device_attach_hwpt(hiodi->devid, IOMMU_NO_PASID, hwpt_id, re= t); if (ret) { /* Destroy old fs_hwpt if it's a replacement */ vtd_destroy_old_fs_hwpt(hiodi, vtd_as); @@ -141,22 +142,22 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, { HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); IntelIOMMUState *s =3D vtd_as->iommu_state; - uint32_t pasid =3D vtd_as->pasid; bool ret; =20 if (s->dmar_enabled && s->root_scalable) { - ret =3D host_iommu_device_iommufd_detach_hwpt(hiodi, errp); - trace_vtd_device_detach_hwpt(hiodi->devid, pasid, ret); + ret =3D host_iommu_device_iommufd_detach_hwpt(hiodi, IOMMU_NO_PASI= D, + errp); + trace_vtd_device_detach_hwpt(hiodi->devid, IOMMU_NO_PASID, ret); } else { /* * If DMAR remapping is disabled or guest switches to legacy mode, * we fallback to the default HWPT which contains shadow page tabl= e. * So guest DMA could still work. */ - ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, hiodi->hwpt_i= d, - errp); - trace_vtd_device_reattach_def_hwpt(hiodi->devid, pasid, hiodi->hwp= t_id, - ret); + ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASI= D, + hiodi->hwpt_id, errp); + trace_vtd_device_reattach_def_hwpt(hiodi->devid, IOMMU_NO_PASID, + hiodi->hwpt_id, ret); } =20 if (ret) { diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index f020b56208..ecabc33064 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -927,21 +927,21 @@ static void vfio_iommu_iommufd_class_init(ObjectClass= *klass, const void *data) =20 static bool host_iommu_device_iommufd_vfio_attach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - uint32_t hwpt_id, Error **errp) + uint32_t pasid, uint32_t hwpt_i= d, + Error **errp) { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(hiodi)->agent; =20 - return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, - hwpt_id, errp); + return !iommufd_cdev_pasid_attach_ioas_hwpt(vbasedev, pasid, hwpt_id, = errp); } =20 static bool host_iommu_device_iommufd_vfio_detach_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, - Error **errp) + uint32_t pasid, Error **errp) { VFIODevice *vbasedev =3D HOST_IOMMU_DEVICE(hiodi)->agent; =20 - return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, IOMMU_NO_PASID, e= rrp); + return iommufd_cdev_pasid_detach_ioas_hwpt(vbasedev, pasid, errp); } =20 static bool hiod_iommufd_vfio_realize(HostIOMMUDevice *hiod, void *opaque, --=20 2.47.3 From nobody Sat Apr 11 18:34:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=@intel.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1775188645; cv=none; d=zohomail.com; s=zohoarc; b=BvAe8egRflTuc3S9Y+sn2O8jN3bO9bJx+XswSu+9Znfwy77wrFZCetUwXWxYj5y8qzRamj4Js+QupWgZ7TGdUrb6MLaxQCovNnCAeIRqoSKzB5ygjaF/DUoZF/o1u5AcViHgQBw4phmG3dhlQujMh+kHtndvUn7S9+XoGTWYeQg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188645; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lHAkG4Dj3YLLC4szBiQEbwCzdSlJPHkJzzCqThjGn5k=; b=Y5cZ6xLPQLdOo/sYbaEmp/axh5vYFwyx99TTJQ1zoPjxrv91iSiOVgdpmPxYW9gG+bsKCRWqq2ZqnAlt2pttzk/lX8jZbHQEKIkCcCgQrRgs5rPpTJUmvU9x8ayG3o+fBEfOxc0d3gjAdnCIgXX3vc7+iuiIBUT9d6bEr9/wc9U= 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 1775188645207290.94446614618505; Thu, 2 Apr 2026 20:57:25 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Vdd-0001Af-Mk; Thu, 02 Apr 2026 23:56:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdc-00019c-Aq for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:04 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vda-0004MM-KT for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:04 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:01 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:55:58 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188562; x=1806724562; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=IM87H8/Ait4f6rjlrPdAR7O/TnBajxtINCeU247Vyjw=; b=G0qJd9iq0H9/nb2K9GdNMqxE5tBGVZ5MwTxDTRBSqw9DxP8BacG6t9Kw Hu3/OVesqnW5Ks9qPmFEMmhKhKs20gXqMnjJyBlXsA7Yn+OuRTEpZZmDN 7piM7rx/9nECIwwS1XLyaxRZIB4k56/wbFJYr/mL18oecDPSYMP72/+xE QeZkeor1u7UwF6E0JJ1/egCthvRsEDAUqJg5fos+6MUrZyCiOIZM5dxib SFWMhOCBACDw+1ERUCZdGzyc3ozZYaBgj1yhdmxCYmVg/17SoMBt//AvN 5C/eiDZViArByQnXwexr1M+UAYJAxd/taOKEU39YMcwWfWk3GZVjOmADA g==; X-CSE-ConnectionGUID: /nAzXRYpQsKAPD0QgHdEjQ== X-CSE-MsgGUID: 7yXnGwL+S3e2/uJmsq5x/w== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140602" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140602" X-CSE-ConnectionGUID: SsTIyR/UR76nqOxEaKClhg== X-CSE-MsgGUID: nMO9Arz+QNi6BU94BvPifw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884852" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 03/14] vfio/iommufd: Create nesting parent hwpt with IOMMU_HWPT_ALLOC_PASID flag Date: Thu, 2 Apr 2026 23:55:27 -0400 Message-ID: <20260403035541.18355-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188646119154100 Content-Type: text/plain; charset="utf-8" When both device and vIOMMU have PASID enabled, then guest may setup pasid attached translation. VFIO needs to be aware of potential pasid usage and should attach the non-pasid part of pasid-capable device to hwpt flagged with IOMMU_HWPT_ALLOC_PASID. ARM SMMU doesn't support IOMMU_HWPT_ALLOC_PASID, only VTD need it. So we can't check the existing vIOMMU flag VIOMMU_FLAG_PASID_SUPPORTED to determine if set flag IOMMU_HWPT_ALLOC_PASID. Instead, introduce a new flag VIOMMU_FLAG_WANT_PASID_ATTACH which will only be exposed by VTD. Signed-off-by: Zhenzhong Duan Reviewed-by: Yi Liu Tested-by: Xudong Hao --- include/hw/core/iommu.h | 1 + include/hw/vfio/vfio-device.h | 1 + hw/vfio/device.c | 11 +++++++++++ hw/vfio/iommufd.c | 8 +++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/include/hw/core/iommu.h b/include/hw/core/iommu.h index bfcd511013..67c575b08c 100644 --- a/include/hw/core/iommu.h +++ b/include/hw/core/iommu.h @@ -21,6 +21,7 @@ enum viommu_flags { /* vIOMMU needs nesting parent HWPT to create nested HWPT */ VIOMMU_FLAG_WANT_NESTING_PARENT =3D BIT_ULL(0), VIOMMU_FLAG_PASID_SUPPORTED =3D BIT_ULL(1), + VIOMMU_FLAG_WANT_PASID_ATTACH =3D BIT_ULL(2), }; =20 /* Host IOMMU quirks. Extracted from host IOMMU capabilities */ diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 828a31c006..d6e522f8b8 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_want_pasid_attach(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..bc1d37e776 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_want_pasid_attach(VFIODevice *vbasedev) +{ + VFIOPCIDevice *vdev =3D vfio_pci_from_vfio_device(vbasedev); + + if (vdev) { + return !!(pci_device_get_viommu_flags(PCI_DEVICE(vdev)) & + VIOMMU_FLAG_WANT_PASID_ATTACH); + } + 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 ecabc33064..ead40b6617 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -363,6 +363,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 */ @@ -408,7 +409,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 @@ -430,6 +431,11 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *v= basedev, } } =20 + if (max_pasid_log2 && + vfio_device_get_viommu_flags_want_pasid_attach(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 18:34:21 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=1775188641; cv=none; d=zohomail.com; s=zohoarc; b=ku2aujlWq0Vbgnv7UIVCe1DKbnXcpEb7iQru43J7qwWzmeaAYo7YFfhpoy63kurMXP9nSLEki4Bk9VDQTyEV4E2tL6OAOlm4DOBseAeDRSp0N7VZibH62y7yYKFEKcEjUe7MsyDjUEoz+eSyk+41SgiOVOxEiLUhdjDboi4i+BI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188641; 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=ofyAqZGZoZuZx2k4QRqj18R27gCyDv7HT7+BJ93L0ak=; b=P5LwyPDs8n890l+my4Sobt7+HciqWwXXVLo6+eA7l7Sb/uBxdmJWGKzF2oh2fqP4A3s/juQqMW2l+66qwSj+AM/EnA4DIWuzNGQDXffYTRFbvURw7kwVOZx1r3I6R3oeNQWY8UvkAohYuXHYAYZpz8mpDHuYnl9RVxApNONZufA= 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 1775188641978430.3214615150806; Thu, 2 Apr 2026 20:57:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Vdi-0001C7-7U; Thu, 02 Apr 2026 23:56:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdg-0001BP-5P for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:08 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vde-0004N9-HK for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:07 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:05 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:02 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188566; x=1806724566; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WhVGnhbo+Pqtx83Hy48OkP5Wl8zor8CPU++Q6Tws2aA=; b=JBVuOFBnleSL/KvoANYAU1Ilw6z51DXZE+z5klDdaGBvUujKYAd1DbJ+ DzGSJrWIFTZ2yr1uBFMAqKyTvt6Le/6GpgSlVh09nFfqMh+30k6EIrg9a /EVPDn5Z4SL7325aQX6W6D3m0b8aH1ACVX8yJzA5Hi2YK0a7lP67jWfxH KJJ6zkxC34/o/c9lXMdp1rUs9T8kggu82kG8xTW72HKHsdOrvvaAvCEJW ThLy0l/795b3asSTmM7JXKgqo5QmZ6VaUi6xnqVMfCiB3AwzVvqKHVeuw 2cJnbEylNyiG+D6ATQSbgmnlAZdJlgVfVEB1v/Qa1A1qtEIBJ0yZQMIyq g==; X-CSE-ConnectionGUID: R2Nqa2C2Rwa2lQXmuUNMNA== X-CSE-MsgGUID: PJ8VrpDnSdSLmETvJgX+cA== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140609" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140609" X-CSE-ConnectionGUID: sjJeVgYlTcC5k+JuG4N1Aw== X-CSE-MsgGUID: Gsxqc7fMSpWtsbd7rEXfNw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884861" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 04/14] intel_iommu: Create the nested hwpt with IOMMU_HWPT_ALLOC_PASID flag Date: Thu, 2 Apr 2026 23:55:28 -0400 Message-ID: <20260403035541.18355-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188643024158500 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 Tested-by: Xudong Hao --- hw/i386/intel_iommu_accel.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 3217a2afac..bd1236c070 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 *hiodi, +static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod, VTDPASIDEntry *pe, uint32_t *fs_hwpt_id, Error **errp) { + HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); 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,16 @@ static bool vtd_create_fs_hwpt(HostIOMMUDeviceIOMMUFD *= hiodi, vtd.pgtbl_addr =3D (uint64_t)vtd_pe_get_fspt_base(pe); =20 return iommufd_backend_alloc_hwpt(hiodi->iommufd, hiodi->devid, - hiodi->hwpt_id, 0, IOMMU_HWPT_DATA_V= TD_S1, - sizeof(vtd), &vtd, fs_hwpt_id, errp); + hiodi->hwpt_id, flags, + IOMMU_HWPT_DATA_VTD_S1, sizeof(vtd),= &vtd, + fs_hwpt_id, errp); } =20 -static void vtd_destroy_old_fs_hwpt(HostIOMMUDeviceIOMMUFD *hiodi, +static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod, VTDAddressSpace *vtd_as) { + HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); + if (!vtd_as->fs_hwpt_id) { return; } @@ -116,7 +121,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, } =20 if (vtd_pe_pgtt_is_fst(pe)) { - if (!vtd_create_fs_hwpt(hiodi, pe, &hwpt_id, errp)) { + if (!vtd_create_fs_hwpt(vtd_hiod, pe, &hwpt_id, errp)) { return false; } } @@ -126,7 +131,7 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, trace_vtd_device_attach_hwpt(hiodi->devid, IOMMU_NO_PASID, hwpt_id, re= t); if (ret) { /* Destroy old fs_hwpt if it's a replacement */ - vtd_destroy_old_fs_hwpt(hiodi, vtd_as); + 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 +166,7 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDevic= e *vtd_hiod, } =20 if (ret) { - vtd_destroy_old_fs_hwpt(hiodi, vtd_as); + vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as); } =20 return ret; --=20 2.47.3 From nobody Sat Apr 11 18:34:21 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=1775188641; cv=none; d=zohomail.com; s=zohoarc; b=chgOVVs0zu6VWdzpJDXnEf4rX3J8IkSis66QmqS536M+tptCqUy4vW+j5RxdqDYoBJjZyCkWCpzUfXUcZaW7nXNAOHewgXr1LobUzWIOmOFn62psb7u4PwpynHr0vSZZmcte+rzqcnPr3b8Xnvg9/sa7LDH1tjHH8+I57PWn9Rg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188641; 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=+jGXh99uedVvuM1oyUhILNuqGKCGTiiP2kjPx4pNjHI=; b=fOmO/p8KcH1879RG5Lo/2O8Sf0xQSCsTrwmUkxA9ieaOMPSpMwLobIwOlLfk7IaylHaZ4dFkuiwQMViO7LAqmZ6gZX73JDPSLFKaUvpN81svAXnDx5EUlWio6K04aYmJKKlE6yVrLeED7jdC2tpvgpjQvJ6LjtimunVuynXGwc0= 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 1775188641007581.0884423197347; Thu, 2 Apr 2026 20:57:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Vdl-0001Dp-B2; Thu, 02 Apr 2026 23:56:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdj-0001Cr-4S for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:11 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdh-0004N9-BR for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:10 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:08 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:05 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188569; x=1806724569; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5lcU41fo2wxr8bS2AZ65MwY5eZhQl54yOKWZLAku3PA=; b=KP4/Md700Rn18KWWHTuUZTgi2ohAhcRirBjIj4+XEcsT+NwIsNKk+HGZ MLhfZvm++8FDSd7Ib+Q9bpe+xflnSgh1qqTkATYGNxTptbZoFEiCVj3gG dpKsBmp/bSyGBEy9hwU6lzKshb2wZRZkKszl6B74LT1GVK2AwR8zaZHsT NpOgWSG9ZNSFuOXKaZ3hROYD14IyQ/PBjaILQ0bOq9NlJE9tHscLcGSG/ DH+i7IiQ4OL7l625feO7Wqc4kPGREpE8gJulgjGyPHw5iMQhBaGsKQMvn 9wYvlc5yUk+89cp5pBU45fvSB8aJhn79LN84qr7zmYL+vDUFVAF97ww5Z A==; X-CSE-ConnectionGUID: hOXomoTKRjuaQYGhEX+45g== X-CSE-MsgGUID: 83qz2xwUSFeRVShX8oN2og== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140620" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140620" X-CSE-ConnectionGUID: QHNqThdUTSGUbl15vLmXDg== X-CSE-MsgGUID: g0phY0NCTcSrLUdrH+iR6g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884872" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 05/14] intel_iommu: Change pasid property from bool to uint8 Date: Thu, 2 Apr 2026 23:55:29 -0400 Message-ID: <20260403035541.18355-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188642288154100 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. PASID bits size should also be no more than 20 bits according to PCI spec. Signed-off-by: Zhenzhong Duan Reviewed-by: Clement Mathieu--Drif Tested-by: Xudong Hao --- hw/i386/intel_iommu_internal.h | 2 +- include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 11 +++++++++-- 3 files changed, 11 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 e44ce31841..95c76015e4 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -314,7 +314,7 @@ struct IntelIOMMUState { bool intr_eime; /* Extended interrupt mode enabled */ OnOffAuto intr_eim; /* Toggle for EIM cabability */ uint8_t aw_bits; /* Host/IOVA address width (in bits) */ - 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 f395fa248c..635e7ee145 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("stale-tm", IntelIOMMUState, stale_tm, false), DEFINE_PROP_BOOL("fs1gp", IntelIOMMUState, fs1gp, true), @@ -5042,7 +5042,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 @@ -5583,6 +5584,12 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) return false; } =20 + if (s->pasid > PCI_EXT_CAP_PASID_MAX_WIDTH) { + error_setg(errp, "PASID width %d exceeds Max PASID Width %d allowe= d " + "in PCI spec", s->pasid, PCI_EXT_CAP_PASID_MAX_WIDTH); + return false; + } + if (s->svm) { if (!x86_iommu->dt_supported) { error_setg(errp, "Need to set device IOTLB for svm"); --=20 2.47.3 From nobody Sat Apr 11 18:34:21 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=1775188655; cv=none; d=zohomail.com; s=zohoarc; b=eNCiihMGp3hW+YnPOx+OY4Plof0tf2YQ7CoWfY/WT4fItI2alIGmQm2MaASpOqa9NjuyqM0odrqafm70iNGLGVuUQZeMOCRyVSnegnoFJYA2SuCZC/6rF439vN80ZR71sZB0NOT7m7kLBljvlsw0uJT9EaQUpsAWgeC2arADY/E= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188655; 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=CpdQGYYBfS0Rrjmb1I3irHn+B/LbsNqSG7uVtUbsOFg=; b=Dy+LAtJQUOX5pm/IvH89X1DyP1/9uw84WZly3DMcr0RBeQCbL7swJ1dg7EeB4a/oM2ng5vELlJm8egnNahqv78fxoBpqx4Up/uXeQKBDmS1fXyzga86PHucwf8/nnTPioAvmmhfHLN/0qxvA1FDyVHGElqz9vlUz5P2Z5seKQZM= 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 1775188655488760.795404050875; Thu, 2 Apr 2026 20:57:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Vdo-0001Eb-6c; Thu, 02 Apr 2026 23:56:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdm-0001EC-Rw for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:14 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdk-0004N9-WD for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:14 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:12 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188573; x=1806724573; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Js9NLii87RvOIODDyynTxEH0ho3Q87bgpwCKHhwNZL8=; b=dvbjZuTDjP6LeKC2Zop9CR15jY7yKjVvUVDFB/jFX/chhe8oSKRIB9nW 0nQXo6jOJBmjHpqVq0zY16F9E62QIvKDtips7+wKw0KDJVyHGXDldrfWQ Tc3p2ZoScLVcrnj4bXF4u4HMylC4VTADE//3xvYL1QmSiS9EczPtjYjmt VDqJqNQ7bt1aI3/+oxrlGcKMDcY8DbGBjtiq/kVFYZzj2aFSF6eBy74MJ 7UlAZ5LSsYxHl+xPNhS9pilIVfPolktfewl47//p4LkOh8SjbXbi+/1Dz MZjcQaBdOY6oI/A3+8zrVXXMOS4SmitUhrcdFUbM9p40baajCEUdQKorQ Q==; X-CSE-ConnectionGUID: 0lh6xCszSi2vlb4QBnnGEg== X-CSE-MsgGUID: Av5nk56NSvG3EuFh5M5QFA== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140629" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140629" X-CSE-ConnectionGUID: bwyxdQLBQG6Dxh+UeAMqWQ== X-CSE-MsgGUID: f6DIFUBOSGy6NBYKZtXNMw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884882" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan , Clement Mathieu--Drif Subject: [PATCH v3 06/14] intel_iommu: Export some functions Date: Thu, 2 Apr 2026 23:55:30 -0400 Message-ID: <20260403035541.18355-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188658477154100 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 Tested-by: Xudong Hao --- 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 635e7ee145..aa67c89e73 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 18:34:21 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=1775188641; cv=none; d=zohomail.com; s=zohoarc; b=Ilgc4D8RprZ4bsrbqrFbr9rxGj4ijR8PAqUOT4TIA+1O/KLbkS1IqcJPa1zN7+S6hvKR6RGwzq2UrYJk7F5gjt1xZ3bhnetEuedqtCdYyXLkfs7UOwEpBRj9qy9ARb3yhx4Zabm35mWDnSrDaBnSO2coOPI8XcS7Ay7ImUJdp00= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188641; 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=5wG94LOt6YzaIwZzzigYbgYjMDSHqPTNecKVfQdj7kg=; b=ZkqGwTZBe/An8uUqgDYOd6koRtYa0MpCUfIITcRY682MvtRW+ym/jNbutiNKM6R2Sm/B+vm6KqPmdblzm4uLpd5KDwbqGxyEXWnM2GeLAdQiwsfAYSVQLpZp8T7JR426+9VxD+pHpbKmfkpYD5vNGD8uMD/uaWmKO/gPBh1aKcM= 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 1775188641232962.4860067038741; Thu, 2 Apr 2026 20:57:21 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Vdq-0001FB-VV; Thu, 02 Apr 2026 23:56:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdq-0001Ew-4S for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:18 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdo-0004N9-Es for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:17 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:15 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188576; x=1806724576; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iQaCmLmcKbdNrlzqxau5uvh3eGSoDbU2Iuqgw7ziD1M=; b=nBaQUD6UyH4yhBVgrkxnVxSZRUeTIBDSSKMWmdoBSBRRYay28bjodkGw 8Y8z+Q+S9f7i0zoESsW8uPTkeGK4sxpN8CXI3NSYRreZg/6G9TViH2Zcp bICviZawERHXpu1HYsZNIJbY77G/QKhAEQy2yfhjaADt0GcXyLjIBZh/l 3go3PevfCq3UpyhWEsczI634ucHT+ongCWmLya1bdFVjD+JIiKOwrylMD 0hInipMTKKdpeOLAUL5uIv8WuOvxOjoBvASqgemVxErU2nI3jtEesXR5+ ZdjOQGPDPPFrthzDr+T0gj7XMPx/+5SjvFxmrEcH3tnPW8YAdAEa2zRdl w==; X-CSE-ConnectionGUID: r/9A47wSTQyqd50gkcmyyg== X-CSE-MsgGUID: 32EXtFCgR22Ln9blBmh7WA== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140638" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140638" X-CSE-ConnectionGUID: 6AriUrPARGeJH4hE35nvww== X-CSE-MsgGUID: exCLPoykTNmf0W7GENFdJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884888" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 07/14] intel_iommu: Use IOMMU_NO_PASID and delete PASID_0 Date: Thu, 2 Apr 2026 23:55:31 -0400 Message-ID: <20260403035541.18355-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188643024158501 Content-Type: text/plain; charset="utf-8" In previous patch we introduced a global macro IOMMU_NO_PASID(0) for Requests-without-PASID, this makes the local macro PASID_0 redundant. Delete it and use IOMMU_NO_PASID instead. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Tested-by: Xudong Hao --- hw/i386/intel_iommu_internal.h | 1 - hw/i386/intel_iommu.c | 18 +++++++++--------- hw/i386/intel_iommu_accel.c | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index c7e107fe87..0141316f83 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -615,7 +615,6 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_CTX_ENTRY_LEGACY_SIZE 16 #define VTD_CTX_ENTRY_SCALABLE_SIZE 32 =20 -#define PASID_0 0 #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 diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index aa67c89e73..3b8d3a96d2 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -941,7 +941,7 @@ int vtd_ce_get_pasid_entry(IntelIOMMUState *s, VTDConte= xtEntry *ce, dma_addr_t pasid_dir_base; =20 if (pasid =3D=3D PCI_NO_PASID) { - pasid =3D PASID_0; + pasid =3D IOMMU_NO_PASID; } pasid_dir_base =3D VTD_CE_GET_PASID_DIR_TABLE(ce); return vtd_get_pe_from_pasid_table(s, pasid_dir_base, pasid, pe); @@ -958,7 +958,7 @@ static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s, VTDPASIDEntry pe; =20 if (pasid =3D=3D PCI_NO_PASID) { - pasid =3D PASID_0; + pasid =3D IOMMU_NO_PASID; } pasid_dir_base =3D VTD_CE_GET_PASID_DIR_TABLE(ce); =20 @@ -1501,9 +1501,9 @@ static int vtd_ce_pasid_0_check(IntelIOMMUState *s, V= TDContextEntry *ce) =20 /* * Make sure in Scalable Mode, a present context entry - * has valid pasid entry setting at PASID_0. + * has valid pasid entry setting at IOMMU_NO_PASID. */ - return vtd_ce_get_pasid_entry(s, ce, &pe, PASID_0); + return vtd_ce_get_pasid_entry(s, ce, &pe, IOMMU_NO_PASID); } =20 /* Map a device to its corresponding domain (context-entry) */ @@ -1564,7 +1564,7 @@ int vtd_dev_to_context_entry(IntelIOMMUState *s, uint= 8_t bus_num, } } else { /* - * Check if the programming of pasid setting of PASID_0 + * Check if the programming of pasid setting of IOMMU_NO_PASID * is valid, and thus avoids to check pasid entry fetching * result in future helper function calling. */ @@ -2122,7 +2122,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, vtd_iommu_lock(s); =20 if (pasid =3D=3D PCI_NO_PASID && s->root_scalable) { - pasid =3D PASID_0; + pasid =3D IOMMU_NO_PASID; } =20 /* Try to fetch pte from IOTLB */ @@ -2508,10 +2508,10 @@ static void vtd_iotlb_page_invalidate_notify(IntelI= OMMUState *s, * In legacy mode, vtd_as->pasid =3D=3D pasid is always true. * In scalable mode, for vtd address space backing a PCI * device without pasid, needs to compare pasid with - * PASID_0 of this device. + * IOMMU_NO_PASID of this device. */ if (!(vtd_as->pasid =3D=3D pasid || - (vtd_as->pasid =3D=3D PCI_NO_PASID && pasid =3D=3D PASID= _0))) { + (vtd_as->pasid =3D=3D PCI_NO_PASID && pasid =3D=3D IOMMU= _NO_PASID))) { continue; } =20 @@ -3022,7 +3022,7 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, if (!vtd_dev_to_context_entry(s, pci_bus_num(vtd_as->bus), vtd_as->devfn, &ce) && domain_id =3D=3D vtd_get_domain_id(s, &ce, vtd_as->pasid)) { - if ((vtd_as->pasid !=3D PCI_NO_PASID || pasid !=3D PASID_0) && + if ((vtd_as->pasid !=3D PCI_NO_PASID || pasid !=3D IOMMU_NO_PA= SID) && vtd_as->pasid !=3D pasid) { continue; } diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index bd1236c070..8940d240a1 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -217,7 +217,7 @@ static void vtd_flush_host_piotlb_locked(gpointer key, = gpointer value, =20 did =3D VTD_SM_PASID_ENTRY_DID(&pc_entry->pasid_entry); =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 IOM= MU_NO_PASID) { HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod); uint32_t entry_num =3D 1; /* Only implement one request for simpli= city */ --=20 2.47.3 From nobody Sat Apr 11 18:34:21 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=1775188642; cv=none; d=zohomail.com; s=zohoarc; b=O45P+LfJDEglKvIQ12NTB2x6nYRFFUqhX0NiBOvuKCSL9s+u4HvzWL6lqEo7N94rMfHYyAg7hD4xRiIBix6XbgQWRDyXM73PllYlp7rHpdRsV6avalNKZrfFJlmefb+/OUnATxEg42eZoVsjOOLJ9OYP4pJyZoh4aF/I8/tgwnY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188642; 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=hmiMKMSHT+tttZgAuTONKvA3J6uvf4QsbuQXsXMD97E=; b=WZCVt8I7e/gIKyaqdjuJFeC0lQUbkdj3FkWTBYAY0S7WTga+ncUNx0JxvR/ed2GHoOM+vJ3BuXSZDgbvaBGGhjIWkBRhGpaD1WKIyWUzdtEQFCf85+6s6U1xCx4sdl90QZ+GBe1MNsb2itfGj07DHvvnJyEovj2s4LIDt7pUqrc= 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 1775188642180721.0264061792673; Thu, 2 Apr 2026 20:57:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Vdy-0001K9-DZ; Thu, 02 Apr 2026 23:56:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdu-0001Ig-8q for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:22 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vds-0004N9-0b for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:22 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:19 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188580; x=1806724580; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wobN7FdM2GQL0/tu+bmV+dHRcPu7e7YkjeU4rLiTKn8=; b=Qs+UrYLbhlyzjWwas8GU49zRIMwj1IKEHYBVz9sDaEZXsVYsb3wTdjEy UhVQagN8mXGWCVGBC+Y1UGQgD4X1PxS5rCKtf20UHmgwjHEYVksSbIAT5 91BHqS7U955pCc/w7FEXUb2m25LfQ9cmLI6UWkV/ijZKKjuarIz3/Qr7E inJ8fv5R8V2WBuHTFNoowNR5o3U3z+LsL2Nir4DRwJAcMvNAeozUfnX/x i2LaxcEjmf4SoBw7IZ3HvGUzKMGx4TP5OMDurZE+S5Y6qxYZA/NGD/OUX sdCX8ohvySy8r9IycrCIPVyKKsjtBEeyrrERFvUEWKsiN1TUpudUTj17T g==; X-CSE-ConnectionGUID: 1ALftaLJS0uOCS/iG0O6xQ== X-CSE-MsgGUID: VpuTF+PuSP+oJfGlUp4GEg== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140650" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140650" X-CSE-ConnectionGUID: 9DXywhIzRhSLvIH0qTKPSQ== X-CSE-MsgGUID: xdldULSTRUq41WE0wC4adQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884897" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 08/14] intel_iommu_accel: Handle PASID entry addition for pc_inv_dsc request Date: Thu, 2 Apr 2026 23:55:32 -0400 Message-ID: <20260403035541.18355-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188643332158500 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 bound nested hwpt. It's also designed to support IOMMU_NO_PASID. VTDAccelPASIDCacheEntry is designed to only be used in intel_iommu_accel.c, similarly VTDPASIDCacheEntry should only be used in hw/i386/intel_iommu.c 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. IOMMU_NO_PASID of passthrough device still need to register MRs in case guest does not operate in scalable mode. So for IOMMU_NO_PASID, we have both VTDAPASIDCacheEntry and VTDAccelPASIDCacheEntry. Co-developed-by: Yi Liu Signed-off-by: Zhenzhong Duan Tested-by: Xudong Hao --- 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 | 167 +++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index e5f0b077b4..c9b1823745 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 pasid_entry; + 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_accel_pasid_cache_sync(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_accel_pasid_cache_sync(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 0141316f83..623dc24760 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -615,6 +615,7 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_CTX_ENTRY_LEGACY_SIZE 16 #define VTD_CTX_ENTRY_SCALABLE_SIZE 32 =20 +#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 @@ -645,6 +646,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 */ @@ -710,6 +712,7 @@ typedef struct VTDHostIOMMUDevice { PCIBus *bus; uint8_t devfn; HostIOMMUDevice *hiod; + QLIST_HEAD(, VTDAccelPASIDCacheEntry) pasid_cache_list; } VTDHostIOMMUDevice; =20 /* @@ -767,6 +770,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 3b8d3a96d2..656868821f 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_accel_pasid_cache_sync(s, pc_info); } =20 static void vtd_replay_pasid_bindings_all(IntelIOMMUState *s) @@ -4759,6 +4761,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 8940d240a1..46250aa75c 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -259,6 +259,173 @@ void vtd_flush_host_piotlb_all_locked(IntelIOMMUState= *s, uint16_t domain_id, vtd_flush_host_piotlb_locked, &piotlb_info); } =20 +static void vtd_accel_fill_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->pasid_entry)) { + vtd_pce->pasid_entry =3D *pe; + } + return; + } + } + + vtd_pce =3D g_malloc0(sizeof(VTDAccelPASIDCacheEntry)); + vtd_pce->vtd_hiod =3D vtd_hiod; + vtd_pce->pasid =3D pasid; + vtd_pce->pasid_entry =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_accel_fill_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_accel_replay_pasid_bind_for_dev(VTDHostIOMMUDevice *vtd_hi= od, + 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_accel_pasid_cache_sync(IntelIOMMUState *s, VTDPASIDCacheInfo *pc_= info) +{ + int start =3D IOMMU_NO_PASID, end =3D 1 << s->pasid; + VTDHostIOMMUDevice *vtd_hiod; + GHashTableIter hiod_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 IOMMU_NO_PASID; + } + + 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(); + } + + /* + * Loop all the vtd_hiod instances to sync the "pasid cache" per the + * guest pasid configuration. + * + * 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(&hiod_it, s->vtd_host_iommu_dev); + while (g_hash_table_iter_next(&hiod_it, NULL, (void **)&vtd_hiod)) { + if (!object_dynamic_cast(OBJECT(vtd_hiod->hiod), + TYPE_HOST_IOMMU_DEVICE_IOMMUFD)) { + continue; + } + vtd_accel_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 18:34:21 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=1775188647; cv=none; d=zohomail.com; s=zohoarc; b=N5g2YIVgN7BvKw62ms7apPm73Ya6xSMEFcd2Mqu+aV696qoWoJZHIGNNYgZmQJWJAPutIOuCKwZLDjt1DUh7/LY4jLuW9udbrXm5d6ee05Tblyjqa7P1F9257fUAS+CcLuzUIRfp5njsl89Pg3m4aZOxfOVS440tT8kwrstwg1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188647; 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=jQojliTjQVrx8rduzdwDW2xXinVBqxHDdq42jtJoV6E=; b=Qzfhzg2IYPFu3VEgEPqvciGHFiceoSeBTh+oAXzsjVvNJWhcQdhg4Z+nOLv3QJG8J0dtIPKXxrpe2NfdrEw5NvOHvcw32NIYdr5Q69RpDR0pocOPcf3kUfSzoJB3HREMbAr7wBoEeRQhFEJATA6onUgu5J6vxhq1w1qJn3a3GvI= 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 1775188647739106.84576005344866; Thu, 2 Apr 2026 20:57:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Ve4-0001LU-6g; Thu, 02 Apr 2026 23:56:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdx-0001K6-Tn for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:26 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdv-0004N9-Cw for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:24 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:22 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:19 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188583; x=1806724583; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0MFb3HenNSUls1fHNRaU0yBgX5qm6xrytDacYEjt9Sg=; b=k/e5dIQxz3qsTO9GfoXwAwuJAlbwAVbUtqq2KrSiI4eRHKNDBX+oVRo3 pT9mV11MWlKen85gn2byCiXWIJp+nZrlZ79pExzU3dzoHMyk3wBz5ZG3Y jiajZCC0OElCVJ/2Apkqu6tVXa1EcWkK2yB6UM4K1RGlRgI2If2+opfHQ yAx31RYW5b3pw7vBnh3RyqsfzRZ/DvVj7dhaU7yfbUkxxWVwAVLNekO6q jciS60MfyqEOVmwxwo+4JZaN5aRATFsJPwceQLe3aRcZKEzrS1jCscoog V5EpgJUYlw1RlRxOTN6adcY/ae1vFtcIN6Xe0cSWTkm3cyuI20Q3+9Aaa A==; X-CSE-ConnectionGUID: 96jB31MqQryBNTidhD7/9g== X-CSE-MsgGUID: aVfGJ3wyS2SakPUGKZOvWw== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140657" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140657" X-CSE-ConnectionGUID: 0sfQhFlOQVyjMHPwBRX5mg== X-CSE-MsgGUID: xAbM44NEQSSw4aTr0lFT1w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884904" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 09/14] intel_iommu_accel: Handle PASID entry removal for pc_inv_dsc request Date: Thu, 2 Apr 2026 23:55:33 -0400 Message-ID: <20260403035541.18355-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188650054154100 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. Co-developed-by: Yi Liu Signed-off-by: Zhenzhong Duan Tested-by: Xudong Hao --- hw/i386/intel_iommu_accel.c | 80 +++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 46250aa75c..b951d90135 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 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) { @@ -280,6 +302,57 @@ static void vtd_accel_fill_pc(VTDHostIOMMUDevice *vtd_= hiod, uint32_t pasid, QLIST_INSERT_HEAD(&vtd_hiod->pasid_cache_list, vtd_pce, next); } =20 +static void vtd_accel_delete_pc(VTDAccelPASIDCacheEntry *vtd_pce) +{ + QLIST_REMOVE(vtd_pce, next); + g_free(vtd_pce); +} + +static void +vtd_accel_pasid_cache_invalidate_one(VTDAccelPASIDCacheEntry *vtd_pce, + 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->pasid_entry); + 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. + */ + vtd_accel_delete_pc(vtd_pce); + } +} + +static void vtd_accel_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_accel_pasid_cache_invalidate_one(vtd_pce, pc_info); + } +} + /* * This function walks over PASID range within [start, end) in a single * PASID table for entries matching @info type/did, then create @@ -422,6 +495,13 @@ void vtd_accel_pasid_cache_sync(IntelIOMMUState *s, VT= DPASIDCacheInfo *pc_info) TYPE_HOST_IOMMU_DEVICE_IOMMUFD)) { continue; } + + /* + * PASID entry removal is handled before addition intentionally, + * because it's unnecessary to iterate on an entry that will be + * removed. + */ + vtd_accel_pasid_cache_invalidate(vtd_hiod, pc_info); vtd_accel_replay_pasid_bind_for_dev(vtd_hiod, start, end, pc_info); } } --=20 2.47.3 From nobody Sat Apr 11 18:34:21 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=1775188684; cv=none; d=zohomail.com; s=zohoarc; b=k6nzzOPWd1TNuGN1NTEMTEczYImh03ky0hRT3j1n0HU4cACbHGJ+8MSghw7oJiDxaa83L3vh6orjYf5IqShFREiycMqOGSkGFh3ascZiz1nQAy3mIQU0bEs+hzHvHG60dr82MbmHj6esCqYn/rzCKsQx37C3+NNsbe2k+CtHUL4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188684; 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=CTPDQE5nwDeItQE+vuvFjZLq3KOfr1DmNADnSn3o+68=; b=R1xPwgHdx6oMiTSmlltsgPQIptAgK3nHw46Am5cjDcYLuYIUJ/R+rn6te3OW2a79lvOqRGWjcYnekgwjyJ6/RtSkorilvKNTBM8Bi8bWVgLh2r9ow80NgIX4ksJMwyAZO7F/vKhrlr2J3wVOGOBYD/518AVd4P5YPqhIMdwuFcA= 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 1775188684431762.0511732009974; Thu, 2 Apr 2026 20:58:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Ve8-0001MM-4M; Thu, 02 Apr 2026 23:56:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Ve0-0001L6-QE for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:30 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Vdy-0004N9-Us for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:28 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:26 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188587; x=1806724587; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mfXdfQl9POujA0hQEorAHvjyvPh51rTk6rz0RNAFMBU=; b=KlCrfclvCivFL4c6VctewMpjn8TSTrwnFCiB8CcLqb0adMoWdPsfwOvC g4h56mSmbo/CK9pMA8YDK/bUnmXPLbL2ZbYmA9nbF5ZjFSbL3EHxjwsxw cijYn8zI0WVDORYe1HBHxgTCT2xFAF09geF8R7o++94bX2kTGM/WA9jgh dv24tv3CaZZtD9oz4xWj1G/lpinr5ePwl/WAx875WI3aJQWW574RaB5v1 csXuvsm5BCZUdswacjk3ZO/rhIXI7fo0iBBxxN028yuIxJnZTsd9S6DCK mDibmjElErLcGeFDM64GsHNdY/DuO5ck9ShgMfBdubd9T20zXoCvgu8ID A==; X-CSE-ConnectionGUID: kRUrvwVYSEuHzDsZzRcDrg== X-CSE-MsgGUID: EXRz7F7zQS+LD3JX6/pW6A== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140666" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140666" X-CSE-ConnectionGUID: dmytq7ywRkuErKUxuHYG2g== X-CSE-MsgGUID: MXyG1X11RqizFhwtkTjPNA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884918" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 10/14] intel_iommu_accel: Bypass PASID entry addition for just deleted entry Date: Thu, 2 Apr 2026 23:55:34 -0400 Message-ID: <20260403035541.18355-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188687018154100 Content-Type: text/plain; charset="utf-8" For VTD_INV_DESC_PASIDC_G_PASID_SI typed pc_inv_dsc invalidation, if an pasid entry is just removed, it can never be a new entry to add. So calling vtd_replay_pasid_bind_for_dev() is unnecessary. Introduce a new field accel_pce_deleted in VTDPASIDCacheInfo to mark this case and to do the bypassing. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Tested-by: Xudong Hao --- hw/i386/intel_iommu_internal.h | 1 + hw/i386/intel_iommu_accel.c | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 623dc24760..2c716c5297 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -630,6 +630,7 @@ typedef struct VTDPASIDCacheInfo { uint8_t type; uint16_t did; uint32_t pasid; + bool accel_pce_deleted; } VTDPASIDCacheInfo; =20 typedef struct VTDPIOTLBInvInfo { diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index b951d90135..457fdcba62 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -302,10 +302,15 @@ static void vtd_accel_fill_pc(VTDHostIOMMUDevice *vtd= _hiod, uint32_t pasid, QLIST_INSERT_HEAD(&vtd_hiod->pasid_cache_list, vtd_pce, next); } =20 -static void vtd_accel_delete_pc(VTDAccelPASIDCacheEntry *vtd_pce) +static void vtd_accel_delete_pc(VTDAccelPASIDCacheEntry *vtd_pce, + VTDPASIDCacheInfo *pc_info) { QLIST_REMOVE(vtd_pce, next); g_free(vtd_pce); + + if (pc_info->type =3D=3D VTD_INV_DESC_PASIDC_G_PASID_SI) { + pc_info->accel_pce_deleted =3D true; + } } =20 static void @@ -339,7 +344,7 @@ vtd_accel_pasid_cache_invalidate_one(VTDAccelPASIDCache= Entry *vtd_pce, * to be either all-zero or non-present. Either case means existing * pasid cache should be invalidated. */ - vtd_accel_delete_pc(vtd_pce); + vtd_accel_delete_pc(vtd_pce, pc_info); } } =20 @@ -502,7 +507,12 @@ void vtd_accel_pasid_cache_sync(IntelIOMMUState *s, VT= DPASIDCacheInfo *pc_info) * removed. */ vtd_accel_pasid_cache_invalidate(vtd_hiod, pc_info); - vtd_accel_replay_pasid_bind_for_dev(vtd_hiod, start, end, pc_info); + + if (pc_info->accel_pce_deleted) { + pc_info->accel_pce_deleted =3D false; + } else { + vtd_accel_replay_pasid_bind_for_dev(vtd_hiod, start, end, pc_i= nfo); + } } } =20 --=20 2.47.3 From nobody Sat Apr 11 18:34:21 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=1775188682; cv=none; d=zohomail.com; s=zohoarc; b=E774818kEWuv4oMYHSNnX9l5MZbdz7dIH5uEYKBsdQfC971OBz6oSdXIdFwS0FE26F3+xWCRQVB4GK/VgyCXjlBZlc2EC4w0ipJsWP5/rQ1t0w9kfU8qX7wNdZxVJF+q2eRnYDC336zXtAD8bbr/eGNlN2/Dz5U4hx/uvLmgTOk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188682; 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=oWgg6JFk/K3kcxyLWBoLcwJ0FWL6nvmwZDqV1Peyc2o=; b=FII0x1CAHiRlnkSa7PJW3PMrfPXXUAb31qa+xfU21/eUwSHnLoVLadQexMxYtkajWfSjaXAdV2LEnRIZPEOVNiXadbaaBy9cCRztxvyfeHOkjS1NEuNUePZATjfNb/nIUQTxiY8j7ccn+sQn15ufaOIQkztDrLjETLpSelPDoHc= 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 1775188682926732.442595806998; Thu, 2 Apr 2026 20:58:02 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8Ve8-0001Mx-MZ; Thu, 02 Apr 2026 23:56:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Ve4-0001Lu-Db for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:34 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Ve2-0004N9-OY for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:32 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:30 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188591; x=1806724591; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WbcdEfMO9jqgD+yUkekofQPBmJ+ydI867mA3VhM/gFM=; b=FsFuTjUDvqKgcWqUClyEAZd60jvjaVdd8YzhKSiyQHF2ytQoXAczET/I VYw93tFX4QPuFoIO8xm5gq/DXzD8gunAR0aTJlp1brz6H+2yiXhlH2Cqf B/LoDUlI/nYPAfqVKoNrX6wKPrGmni5HkJ/x1Yviyp7pE8V7gyF8lslK6 C6mRomMypeuFkabFVrsG6W7lUxtek9Ef00baXkLa63hDN5USoVYd38OWs GpGssu3e28YLzut0pccO212c/tJARfrJULO9XmonKkWDz7V/LxES3RfN9 sRBX2tNgG2Fb6v72FCPdtA4RCzOgX6UjmYN54y9D3vS3kpzz3sqVaGGWL g==; X-CSE-ConnectionGUID: 8NG+79+HTKKUmz4p1Ge6uQ== X-CSE-MsgGUID: +2nosuyuS1GujdqK9IpEDA== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140677" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140677" X-CSE-ConnectionGUID: oQhU4oYrRkyNBMQCe+g85g== X-CSE-MsgGUID: DxePSie6ReytVHHd1ydkOg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884929" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 11/14] intel_iommu_accel: Handle PASID entry removal for system reset Date: Thu, 2 Apr 2026 23:55:35 -0400 Message-ID: <20260403035541.18355-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188684809158500 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 Reviewed-by: Yi Liu Tested-by: Xudong Hao --- 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 c9b1823745..a2226b28b6 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_accel_pasid_cache_sync(IntelIOMMUState *s, VTDPASIDCacheInfo *pc_= info); +void vtd_accel_pasid_cache_reset(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_accel_pasid_cache_sync(IntelIOMMU= State *s, { } =20 +static inline void vtd_accel_pasid_cache_reset(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 656868821f..023f4a4f7a 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_accel_pasid_cache_reset(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 457fdcba62..4abe1d228d 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -516,6 +516,19 @@ void vtd_accel_pasid_cache_sync(IntelIOMMUState *s, VT= DPASIDCacheInfo *pc_info) } } =20 +/* Fake a global pasid cache invalidation to remove all pasid cache entrie= s */ +void vtd_accel_pasid_cache_reset(IntelIOMMUState *s) +{ + VTDPASIDCacheInfo pc_info =3D { .type =3D VTD_INV_DESC_PASIDC_G_GLOBAL= }; + VTDHostIOMMUDevice *vtd_hiod; + GHashTableIter hiod_it; + + g_hash_table_iter_init(&hiod_it, s->vtd_host_iommu_dev); + while (g_hash_table_iter_next(&hiod_it, NULL, (void **)&vtd_hiod)) { + vtd_accel_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 18:34:21 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=1775188642; cv=none; d=zohomail.com; s=zohoarc; b=JMpkzfu6WFjCdTgA9AFLY9rFUSnJEhyHNPY6cIpaa1KWDjE0Ms5vxOuQv+kTvFhqTTWMRv9Cb7u/XLx9loFkhrwMdeh+6K57pjeQe1n4ga/IS6N0PDe2CMuG/G+fDM6zFm3+WOXcwjAcbAi5UlN0J5HdVDeN4Stx4umBFFh+0Bo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188642; 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=t7rpV+kZt54GTK5uxFPw260Sz+wAX3/J9050XbqQb5A=; b=Kao7ZhPes1wF87osWQx+U4VJ1u1PfgR42bx0wQXzMCtqq8vMsEB/NmbLLGaMVieF7jWKpccYoMgHs52aT9Rf4kJhgfv2a8zKnxWC5akVYnNgzqEdx0gyJq0F9jBUuRrqQo8SwXQ7ztVNPo3dFaJnVavw/02UaxrNmkVHvlue/Qs= 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 1775188642010411.9205040767059; Thu, 2 Apr 2026 20:57:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8VeB-0001No-4C; Thu, 02 Apr 2026 23:56:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Ve9-0001NM-Mr for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:37 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8Ve6-0004N9-Lu for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:37 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:34 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188594; x=1806724594; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=v5BFeGZx1sriX9zuH2GOuWxziI7zrzCLaFH46xipobA=; b=Nt8zJ5wjpVPmbGX80rxaQMykGcnUPO9eEam26PgCZBWIm7ipmfZFdOhG t4jMFQ6Xl5fi+TcWlqSWWXQyNQU9P+z/lmEE4a9nCsNBGiJMJhBmQ0+lv 3TUFs8zYzZSLGWDAMgeU7dtl5PeT62cgGS7OAq26HX0cBjnhC4Lkj6lHL dReqYltn7FUE62/4Iif3BC5Ixm7/fFZ4FNy4soZV5lseUqdwCNKL2pLmw PuVvd8Jkvj4Rhndj+OHSED4Rt+xWRTbaLTLNwG53qT5dXWpPgpW+CLvp9 PbORxMj0rAnR+qZ7bauO8wxc/coge2AZ/1VOBk1ZoGaPlj1nwp+4cCrE1 w==; X-CSE-ConnectionGUID: ZgiP9ES4QLatEp8h7Aumlw== X-CSE-MsgGUID: Vohlmv4QQNyUu/N4V3oZPQ== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140685" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140685" X-CSE-ConnectionGUID: V2kgWQvYRwKJB40h1R9h7Q== X-CSE-MsgGUID: 1EAN2TnQQg+mUeeuz3LPiw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884941" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 12/14] intel_iommu_accel: Switch to VTDAccelPASIDCacheEntry for PASID bind/unbind and PIOTLB invalidation Date: Thu, 2 Apr 2026 23:55:36 -0400 Message-ID: <20260403035541.18355-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188643082158500 Content-Type: text/plain; charset="utf-8" This patch switches from VTDAddressSpace to VTDAccelPASIDCacheEntry for handling PASID bind/unbind operations and PIOTLB invalidations in passthrough scenarios. VTDAccelPASIDCacheEntry was introduced to cache PASID entries for passthrough devices and is now ready to propagate PASID bind/unbind operations and PIOTLB invalidations to the host. Unlike the previous approach, VTDAccelPASIDCacheEntry supports both IOMMU_NO_PASID (rid_pasid) and other valid PASIDs, so this switch drops IOMMU_NO_PASID limitations that existed in the prior PASID bind/unbind and PIOTLB invalidation path. For IOMMU_NO_PASID of passthrough devices, VTDAddressSpace continues to handle shadow page modifications to the host, but no longer manages PASID bind/unbind operations or PIOTLB invalidations for passthrough scenarios. Co-developed-by: Yi Liu Signed-off-by: Zhenzhong Duan Tested-by: Xudong Hao --- 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 | 131 +++++++++++++++++----------------- 4 files changed, 68 insertions(+), 84 deletions(-) diff --git a/hw/i386/intel_iommu_accel.h b/hw/i386/intel_iommu_accel.h index a2226b28b6..4a9003c92d 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 pasid_entry; 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 95c76015e4..1842ba5840 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 023f4a4f7a..abcb0df5d9 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 4abe1d228d..6377db1fb9 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -111,24 +111,25 @@ static bool vtd_create_fs_hwpt(VTDHostIOMMUDevice *vt= d_hiod, fs_hwpt_id, errp); } =20 -static void vtd_destroy_old_fs_hwpt(VTDHostIOMMUDevice *vtd_hiod, - VTDAddressSpace *vtd_as) +static void vtd_destroy_old_fs_hwpt(VTDAccelPASIDCacheEntry *vtd_pce) { - HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); + HostIOMMUDeviceIOMMUFD *hiodi =3D + HOST_IOMMU_DEVICE_IOMMUFD(vtd_pce->vtd_hiod->hiod); =20 - if (!vtd_as->fs_hwpt_id) { + if (!vtd_pce->fs_hwpt_id) { return; } - iommufd_backend_free_id(hiodi->iommufd, vtd_as->fs_hwpt_id); - vtd_as->fs_hwpt_id =3D 0; + iommufd_backend_free_id(hiodi->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 *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); - VTDPASIDEntry *pe =3D &vtd_as->pasid_cache_entry.pasid_entry; - uint32_t hwpt_id =3D hiodi->hwpt_id; + VTDPASIDEntry *pe =3D &vtd_pce->pasid_entry; + uint32_t hwpt_id =3D hiodi->hwpt_id, pasid =3D vtd_pce->pasid; bool ret; =20 /* @@ -148,14 +149,13 @@ static bool vtd_device_attach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, } } =20 - ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, IOMMU_NO_PASID, h= wpt_id, - errp); - trace_vtd_device_attach_hwpt(hiodi->devid, IOMMU_NO_PASID, hwpt_id, re= t); + ret =3D host_iommu_device_iommufd_attach_hwpt(hiodi, pasid, hwpt_id, e= rrp); + trace_vtd_device_attach_hwpt(hiodi->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_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(hiodi->iommufd, hwpt_id); @@ -164,17 +164,19 @@ 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 *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->= hiod); - IntelIOMMUState *s =3D vtd_as->iommu_state; + + 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(hiodi, IOMMU_NO_PASI= D, - errp); - trace_vtd_device_detach_hwpt(hiodi->devid, IOMMU_NO_PASID, ret); + if (pasid !=3D IOMMU_NO_PASID || (s->dmar_enabled && s->root_scalable)= ) { + ret =3D host_iommu_device_iommufd_detach_hwpt(hiodi, pasid, errp); + trace_vtd_device_detach_hwpt(hiodi->devid, pasid, ret); } else { /* * If DMAR remapping is disabled or guest switches to legacy mode, @@ -188,58 +190,32 @@ static bool vtd_device_detach_iommufd(VTDHostIOMMUDev= ice *vtd_hiod, } =20 if (ret) { - vtd_destroy_old_fs_hwpt(vtd_hiod, vtd_as); + vtd_destroy_old_fs_hwpt(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_locked(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->pasid_entry; 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 IOM= MU_NO_PASID) { + if (piotlb_info->domain_id =3D=3D did && piotlb_info->pasid =3D=3D vtd= _pce->pasid) { HostIOMMUDeviceIOMMUFD *hiodi =3D HOST_IOMMU_DEVICE_IOMMUFD(vtd_hiod->hiod); uint32_t entry_num =3D 1; /* Only implement one request for simpli= city */ @@ -247,7 +223,7 @@ static void vtd_flush_host_piotlb_locked(gpointer key, = gpointer value, struct iommu_hwpt_vtd_s1_invalidate *cache =3D piotlb_info->inv_da= ta; =20 if (!iommufd_backend_invalidate_cache(hiodi->iommufd, - vtd_as->fs_hwpt_id, + vtd_pce->fs_hwpt_id, IOMMU_HWPT_INVALIDATE_DATA_V= TD_S1, sizeof(*cache), &entry_num, = cache, &local_err)) { @@ -263,6 +239,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 hiod_it; =20 cache_info.addr =3D addr; cache_info.npages =3D npages; @@ -273,23 +251,36 @@ 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(&hiod_it, s->vtd_host_iommu_dev); + while (g_hash_table_iter_next(&hiod_it, NULL, (void **)&vtd_hiod)) { + VTDAccelPASIDCacheEntry *vtd_pce; + + QLIST_FOREACH(vtd_pce, &vtd_hiod->pasid_cache_list, next) { + vtd_flush_host_piotlb_locked(vtd_pce, &piotlb_info); + } + } } =20 static void vtd_accel_fill_pc(VTDHostIOMMUDevice *vtd_hiod, 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->pasid_entry)) { vtd_pce->pasid_entry =3D *pe; + + if (!vtd_device_attach_iommufd(vtd_pce, &local_err)) { + error_reportf_err(local_err, "%s", + "Replacing HWPT attachment failed: "= ); + } } return; } @@ -300,11 +291,21 @@ static void vtd_accel_fill_pc(VTDHostIOMMUDevice *vtd= _hiod, uint32_t pasid, vtd_pce->pasid =3D pasid; vtd_pce->pasid_entry =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 static void vtd_accel_delete_pc(VTDAccelPASIDCacheEntry *vtd_pce, VTDPASIDCacheInfo *pc_info) { + Error *local_err =3D NULL; + + 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); =20 --=20 2.47.3 From nobody Sat Apr 11 18:34:21 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=1775188661; cv=none; d=zohomail.com; s=zohoarc; b=VoHbDlw/OBaviKgk2FiCQZZHgH37hKY4uAei+gn36NfAYWkNdkhMiWO81zfBVvp0eKrDQ8AjnUBNCE/LIh4q225QuuO0+IbH+sEcLs5oVEvaemGB9xmDLS1SKUywt7qZyf3oklWwEWn4us11RVSYqcXgO1A9K0xPR6q1wWlKUrQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188661; 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=wv+7T+aRlGM2hFqTS6Fy/PD0ziF6u3adFT3tGWakRHw=; b=TovgIvUGF7t2VEUpQzGmoodbqLqA5eaLMSIDEmeMA5+eQhBdgqOcUuqPv0oDaGlRgMcnMB0tTIFzUKPY+0nI5mI/Q0zbamZOfmSYi+d0DToD76ejsGKMzK94E6qjGOQRWcCBwyzA78Y33KN+ZFVnXX0BigDbVmv8HyYUZXdJMR8= 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 17751886619531010.3182959482734; Thu, 2 Apr 2026 20:57:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8VeE-0001Oz-7m; Thu, 02 Apr 2026 23:56:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8VeB-0001OH-Ui for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:39 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8VeA-0004N9-AT for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:39 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:37 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:34 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188598; x=1806724598; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=hIU2vlg7EXU+6k1wCa3nxm6yYsN20b7avvilirDWblw=; b=LdGwZktxbfBn00JVP3m59qPlDVNWd0/P3xdDrcAK+4bAmKb+K3+Bx7LA gPXy3vSVp+fo7NffmX+Zp6Ub4OPmvEM93RbX4d9m9VF6+Z72VEXHLEoPy ohtI76dT+EYjrEqpfAIiD3Nc+uietlRPGdjrKqtueRZUTCby6cjklUjuu 2Kf1kp+gqBiB7xQbONW+4ICnDy/s/VlvZ3TT0/icEligWnLSnuBT6jDkA piE4E7Hjhsnago2y5ql1tKRNnnPhUbHg5wlgUQj2bDwNQCwjOruAbz3fs Au/0C1U8VGcS6hi13MGF+WuzY7LpJAbs1BCJdoV3fMiW8NbR2kHfp9YDb g==; X-CSE-ConnectionGUID: ph6NiwdIR42qUxhG3A4gbg== X-CSE-MsgGUID: 0JMh05t5TBWDSdZwjfi64Q== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140693" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140693" X-CSE-ConnectionGUID: uvjp4ho6TNKSUu1bvxSIgQ== X-CSE-MsgGUID: R5YnfWPvQZ+OEeByqwm1GA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884952" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 13/14] intel_iommu_accel: Add pasid bits size check Date: Thu, 2 Apr 2026 23:55:37 -0400 Message-ID: <20260403035541.18355-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188664227154100 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. Signed-off-by: Zhenzhong Duan Tested-by: Xudong Hao --- hw/i386/intel_iommu_internal.h | 1 + hw/i386/intel_iommu_accel.c | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 2c716c5297..519af3fa90 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_GET_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_accel.c b/hw/i386/intel_iommu_accel.c index 6377db1fb9..32e2c4633f 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_GET_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 18:34:21 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=1775188661; cv=none; d=zohomail.com; s=zohoarc; b=QvHBA84lmVf0qgpUWvGKFKu57Ui9CIXcPJzJl8M04MlkPRcdIPNiOFXSdw1TMK5N4D9xMZak6F2o7NVz3wPN33AiBS2nyp6KICp3XY2ktKrNpzpBHortHvX3VM0zYHnlx0jNyy7RhoVDWkBupFkWxjP7TF3FRF6xKJhhXI1aty0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1775188661; 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=L1qdCrvfX1jxcHL/cGcgwJvXNB1JBJwO3LSOxGyGDps=; b=Z+kTx9ZgEXzKzpS3PMnbKdzRO5HB4pZs142wqtII+tBDvvLfidcb0wd5RnEkyghYu/1T8cc1kVsKzoS9xsPqk5tKeHwdrCs3iP9OxCglOsZeg0jNTpxDP2Hp9H8iVp+4pm5amWSp8+iZeiMNq7NtZiyKpGec3LgXkHjwNiHGw1E= 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 1775188661763230.23330068533164; Thu, 2 Apr 2026 20:57:41 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w8VeH-0001b2-Hl; Thu, 02 Apr 2026 23:56:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8VeF-0001Tv-U4 for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:43 -0400 Received: from mgamail.intel.com ([198.175.65.19]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w8VeD-0004N9-Sn for qemu-devel@nongnu.org; Thu, 02 Apr 2026 23:56:43 -0400 Received: from fmviesa007.fm.intel.com ([10.60.135.147]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:41 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by fmviesa007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Apr 2026 20:56:38 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1775188602; x=1806724602; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Gpq4iT48dEoIvQVMl/RDHwVdK3eHCPEFNnahXMO0tqE=; b=iMdWPuMM8VjZPFfPVH7f2yIaJWwE6ELZB5ARxO1lIH02nKL0ExXl9FFu mtcyimJdO8Q09nrMZiJLRhyBe5ZZTH3XEAnbbdNgEUOva3rhcIEm6wO2y PUjK+r+0IZCVpYEvcXdJ2T12IxEps16kyqTp3Tbc/QPyBFid4fy/jqZMg Y7FYILi4QrpIHGbVd2RIW5FLcu8wQhPY00UwrWJ0lLFqAYS9VII9mGNRo O4Q6S64bNgWK/Zy3f+Gm1jYjCBisyxx7bW+MfLL/23WLQHozxZ8hb0/oS FktblX6sIwAgUD2AlPKVbTni2B6wvaSNCOMreD2yYbo6WqmMCdRDNCvro A==; X-CSE-ConnectionGUID: hkL0BQKcQlS3APi/4PMpbw== X-CSE-MsgGUID: NPTtWIqBSu+Yn4n9pFu4eQ== X-IronPort-AV: E=McAfee;i="6800,10657,11747"; a="76140700" X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="76140700" X-CSE-ConnectionGUID: RAgMnMFBQhOnMme+l00PZw== X-CSE-MsgGUID: sX4x4nkSSK6VrsiAFlnkDA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,157,1770624000"; d="scan'208";a="223884968" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@bull.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [PATCH v3 14/14] intel_iommu: Expose flag VIOMMU_FLAG_PASID_SUPPORTED when configured Date: Thu, 2 Apr 2026 23:55:38 -0400 Message-ID: <20260403035541.18355-15-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260403035541.18355-1-zhenzhong.duan@intel.com> References: <20260403035541.18355-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=198.175.65.19; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -48 X-Spam_score: -4.9 X-Spam_bar: ---- X-Spam_report: (-4.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.542, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1775188663520158500 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 Tested-by: Xudong Hao --- 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 abcb0df5d9..3cb8a547c7 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -4794,6 +4794,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