Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8ABDFEA795B for ; Thu, 5 Feb 2026 03:13:32 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vnpnD-00054t-Ka; Wed, 04 Feb 2026 22:12:31 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnpnC-00054f-AP for qemu-devel@nongnu.org; Wed, 04 Feb 2026 22:12:30 -0500 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vnpnA-0001vH-OT for qemu-devel@nongnu.org; Wed, 04 Feb 2026 22:12:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1770261149; x=1801797149; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7jxsfmsgdwcTUAekZcRZAkQoAGIK1HAINM8QKao+wdY=; b=If77dpqR+BQoxMVjmBOd8rZIqC8/xu7mlpd0/Fnv3DHL5pBD0UY5if52 jn5dVxP2G4sAn7/HTISXWGPR517EwFg/ENCvOFEglQOzOWHMT8JP+7xyV n89Zvmhi8vFHye7APtWSwIYNEmIxOBTKEGa7SW+EUyQmbmtKScsawYZGh isYdYIa5/qI7PdofQrwNYRbP3GMRcKaOjXKCyPhonKtg/+DXMwQ7qE1wu UH/kY2O9Uj6nM8Q2xfp95N6xS4uVqij/0/bCjFSFT4uTAON1FdhuUPe/U ghj7Fm+336HhSPcACJhBmhzYSwjBFYWkvL5RGEyD1EWekLEFYRi7mp+PI w==; X-CSE-ConnectionGUID: JfEvAy++QjOXb3oQzkvdjw== X-CSE-MsgGUID: r0mdoOYETVuKDxxP5LrobQ== X-IronPort-AV: E=McAfee;i="6800,10657,11691"; a="96910432" X-IronPort-AV: E=Sophos;i="6.21,273,1763452800"; d="scan'208";a="96910432" Received: from orviesa010.jf.intel.com ([10.64.159.150]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2026 19:12:27 -0800 X-CSE-ConnectionGUID: l59SAg+0T2aIKD2OtdS+Mg== X-CSE-MsgGUID: B+Gij9wJQBOG7AP3ETykSQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,273,1763452800"; d="scan'208";a="209651992" Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa010-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Feb 2026 19:12:24 -0800 From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex@shazbot.org, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, skolothumtho@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, xudong.hao@intel.com, Zhenzhong Duan Subject: [RFC PATCH 03/14] vfio/iommufd: Create nesting parent hwpt with IOMMU_HWPT_ALLOC_PASID flag Date: Wed, 4 Feb 2026 22:11:21 -0500 Message-ID: <20260205031133.74357-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260205031133.74357-1-zhenzhong.duan@intel.com> References: <20260205031133.74357-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=192.198.163.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_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+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org When both host device and vIOMMU have PASID enabled, then guest may setup pasid attached translation. We need to create the nesting parent hwpt with IOMMU_HWPT_ALLOC_PASID flag because according to uAPI, any domain attached to the non-PASID part of the device must also be flagged, otherwise attaching a PASID will blocked. Introduce a vfio_device_get_viommu_flags_pasid_supported() helper to facilitate this implementation. Signed-off-by: Zhenzhong Duan --- include/hw/vfio/vfio-device.h | 1 + hw/vfio/device.c | 11 +++++++++++ hw/vfio/iommufd.c | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h index 35a5ec6d92..983eb0ecce 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, VFIOContainer *bcontainer, void vfio_device_unprepare(VFIODevice *vbasedev); bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev); +bool vfio_device_get_viommu_flags_pasid_supported(VFIODevice *vbasedev); bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, uint32_t type, void *caps, uint32_t size); diff --git a/hw/vfio/device.c b/hw/vfio/device.c index 973fc35b59..b15ca6ef0a 100644 --- a/hw/vfio/device.c +++ b/hw/vfio/device.c @@ -533,6 +533,17 @@ bool vfio_device_get_viommu_flags_want_nesting(VFIODevice *vbasedev) return false; } +bool vfio_device_get_viommu_flags_pasid_supported(VFIODevice *vbasedev) +{ + VFIOPCIDevice *vdev = vfio_pci_from_vfio_device(vbasedev); + + if (vdev) { + return !!(pci_device_get_viommu_flags(PCI_DEVICE(vdev)) & + VIOMMU_FLAG_PASID_SUPPORTED); + } + return false; +} + bool vfio_device_get_host_iommu_quirk_bypass_ro(VFIODevice *vbasedev, uint32_t type, void *caps, uint32_t size) diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c index 96735f1fc8..9605bf73b7 100644 --- a/hw/vfio/iommufd.c +++ b/hw/vfio/iommufd.c @@ -354,6 +354,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev, VendorCaps caps; VFIOIOASHwpt *hwpt; uint32_t hwpt_id; + uint8_t max_pasid_log2; int ret; /* Try to find a domain */ @@ -398,7 +399,7 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev, */ if (!iommufd_backend_get_device_info(vbasedev->iommufd, vbasedev->devid, &type, &caps, sizeof(caps), &hw_caps, - NULL, errp)) { + &max_pasid_log2, errp)) { return false; } @@ -420,6 +421,11 @@ static bool iommufd_cdev_autodomains_get(VFIODevice *vbasedev, } } + if (max_pasid_log2 && + vfio_device_get_viommu_flags_pasid_supported(vbasedev)) { + flags |= IOMMU_HWPT_ALLOC_PASID; + } + if (cpr_is_incoming()) { hwpt_id = vbasedev->cpr.hwpt_id; goto skip_alloc; -- 2.47.3