From nobody Thu Apr 2 23:57:03 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=1774516448; cv=none; d=zohomail.com; s=zohoarc; b=QnoBXtm+Zsq9GL/3qcCYnQ7PqSIYDHGbDnKPFM3liI8nF0DDoKqIsYZQQdMLhhUQyyPcxBKoEZAMDsfYLHovVvYglSV+AwRjZtXyoMytw1EjWoy+b9zHhVXbJNQy+yALbTrRKQyg9DxoBfOxUVPGNaobroBnxGS7QD65MZ95hTI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774516448; 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=j8l0QfGEJMy6comTjDnfjNYkAzJ1ty0yyhtm1/7haiw=; b=IbpHDH1EvpD2dhB4Q3eoDqeMAxEb+AV6raHsfUrut10Mknvh0+atc8eDSSRAfW465XgukI+cOkhNRDxos0co7vLKw8rWFXPqO764BSYjTXXh/6Hhfvd6d3vMv1umTrb7gOpXcXqh+7HfzveHKrYCKHR49zucqYL/vXg0EtqFbMo= 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 1774516448055778.7298372395788; Thu, 26 Mar 2026 02:14:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w5glY-0002vt-4L; Thu, 26 Mar 2026 05:12: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 1w5glU-0002qX-RW for qemu-devel@nongnu.org; Thu, 26 Mar 2026 05:12:32 -0400 Received: from mgamail.intel.com ([198.175.65.17]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w5glT-0003yp-9V for qemu-devel@nongnu.org; Thu, 26 Mar 2026 05:12:32 -0400 Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2026 02:12:31 -0700 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Mar 2026 02:12:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1774516352; x=1806052352; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GiTxNugRVA5SQjUBXgagPR7sTF6AAfIiRNl9HM/VsCw=; b=d6bynWaA3235dZLUMjmCNeLE+0rbfkRe5aKfXyLB3elOpmuFiC826VOW fRzj+otc645oaSxNjwMJTj0hIQVQ80yfSRAhpAEMttAIDi7MoPk0YiEFp Aw53c9nBJYwGhkUJBetDmbHe/j/0LnM8Rpybo4jEeyYFjkuTNGiG1dYmR db3IT+zKCzgnl45iZBFvuq7sI4FMwTA3TdNurzNoqFUnGsua6o/i4ioR6 KxwegxDPdlGQqjj+k+m6y17D1UXeNHISxW2SdGblDaYgRXB3yFgOPvri7 uZT70asx84o5kPUOR130VoLAqal3socVPK3qXWau41RzvQRufoAooUrrv w==; X-CSE-ConnectionGUID: 4sZRl7w3TxyqYW0AhgdFgQ== X-CSE-MsgGUID: TPxr02NVSYyvkRXPKkt5gA== X-IronPort-AV: E=McAfee;i="6800,10657,11740"; a="75531401" X-IronPort-AV: E=Sophos;i="6.23,141,1770624000"; d="scan'208";a="75531401" X-CSE-ConnectionGUID: OrEuHGdrTbytLfUEqeyK6Q== X-CSE-MsgGUID: MAhKxbBERzWbB76zSOs2LQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.23,141,1770624000"; d="scan'208";a="248368612" 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 v2 13/14] intel_iommu_accel: Add pasid bits size check Date: Thu, 26 Mar 2026 05:11:27 -0400 Message-ID: <20260326091130.321483-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260326091130.321483-1-zhenzhong.duan@intel.com> References: <20260326091130.321483-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.17; 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @intel.com) X-ZM-MESSAGEID: 1774516450066154100 Content-Type: text/plain; charset="utf-8" If pasid bits size is bigger than host side, host could fail to emulate all bindings in guest. Add a check to fail device plug early. Pasid bits size should also be no more than 20 bits according to PCI spec. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 1 + hw/i386/intel_iommu_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 f3cb6cff1c..d11064b527 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -196,6 +196,7 @@ #define VTD_ECAP_SRS (1ULL << 31) #define VTD_ECAP_NWFS (1ULL << 33) #define VTD_ECAP_SET_PSS(x, v) ((x)->ecap =3D deposit64((x)->ecap, 35= , 5, v)) +#define VTD_ECAP_PSS(ecap) extract64(ecap, 35, 5) #define VTD_ECAP_PASID (1ULL << 40) #define VTD_ECAP_PDS (1ULL << 42) #define VTD_ECAP_SMTS (1ULL << 43) diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index 2fd26690b9..e73695ff83 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -44,6 +44,7 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMM= UDevice *vtd_hiod, HostIOMMUDevice *hiod =3D vtd_hiod->hiod; struct HostIOMMUDeviceCaps *caps =3D &hiod->caps; struct iommu_hw_info_vtd *vtd =3D &caps->vendor_caps.vtd; + uint8_t hpasid =3D VTD_ECAP_PSS(vtd->ecap_reg) + 1; PCIBus *bus =3D vtd_hiod->bus; PCIDevice *pdev =3D bus->devices[vtd_hiod->devfn]; =20 @@ -64,6 +65,13 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOM= MUDevice *vtd_hiod, return false; } =20 + /* Only do the check when host device support PASIDs */ + if (caps->max_pasid_log2 && s->pasid > hpasid) { + error_setg(errp, "PASID bits size %d > host IOMMU PASID bits size = %d", + s->pasid, hpasid); + return false; + } + if (pci_device_get_iommu_bus_devfn(pdev, &bus, NULL, NULL)) { error_setg(errp, "Host device downstream to a PCI bridge is " "unsupported when x-flts=3Don"); --=20 2.47.3