From nobody Sun Apr 12 07:21:49 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=1771040605; cv=none; d=zohomail.com; s=zohoarc; b=ClILlXxoiyV4CgnaxzWT4pVqAlxqNdmtNl7rlE0YJtV4VF+HcgJO/a03I1tu4hx1Lhf2CZsXvKsvMK+CMKpIKIiotG/ZvcisS2QK+r5lxsOBRHNnBVRe7XpP1Papj/bMGedGjRJJHePDEqdwebVTQs1v57N7GEkH1k5OdNo/18I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771040605; 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=FPMflk7grzhIcO3AFjaRy3sVv64jX/zJkBQ4FOaP4TY=; b=GvOjCxFJZbxdcKQ6MOgndms47Iz7s2UfSjjML9GBewR1KKB4xAC2k0hu+HTjMmaQfgYOjhtL0R8YDiPm8V3eSdYyALVJjCr2KQr5vuC2v+qkHh0I/mFYmo7x/chyp+VvtqAEwWJSK0SQxW0l4rfPi09ivSago3F56qD+sbA+sI4= 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 177104060579319.937837113345722; Fri, 13 Feb 2026 19:43:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vr6YG-0005JD-1Z; Fri, 13 Feb 2026 22:42:36 -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 1vr6YF-0005Hz-71 for qemu-devel@nongnu.org; Fri, 13 Feb 2026 22:42:35 -0500 Received: from mgamail.intel.com ([198.175.65.12]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vr6YD-0008J1-Kp for qemu-devel@nongnu.org; Fri, 13 Feb 2026 22:42:34 -0500 Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2026 19:42:33 -0800 Received: from unknown (HELO gnr-sp-2s-612.sh.intel.com) ([10.112.230.229]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2026 19:42:29 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1771040554; x=1802576554; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=SDpCFayu97R5owktLGHAkU9F+zX5Nl2NSUvxpfROTIE=; b=VFSoW0ZLsCVB4SFIzWwi2nY7v7ZQotzMXgHkakk4OSUGSNoUxZQcOW3A eYjQmkAc9GoSMcmq5YxLbKhVrUnhAdcdnPisYtH3h+UYAcWl6bdEiC9ZQ xRENjK+08mjZs31a8Z+LEgxoKHrmi23F1RrKqQcC1V0rH4U2faWRLNW13 NuDMMkakuSclopH33L+lG7EqfqhbBIt6uhmu9KZITGXUVzXdKlZaiVnKO 4CxsB0KIBSIrClIO2zwSx9M3sMnI9WH+MNVRQCNB1BoEGX4/3gNDXfn8J zDJvteo8KYWiBxTHI+/Q+0IbTEvFeisYsI3W/6ANSfm1dy43afg2dKhz4 w==; X-CSE-ConnectionGUID: EqByieCcR2ixmcP/cFmWxg== X-CSE-MsgGUID: vaT1F+OpQruyVgdqUyRpHg== X-IronPort-AV: E=McAfee;i="6800,10657,11700"; a="83666877" X-IronPort-AV: E=Sophos;i="6.21,289,1763452800"; d="scan'208";a="83666877" X-CSE-ConnectionGUID: Q9A+0ZH+Q1mINV4PkNrjug== X-CSE-MsgGUID: DyMFskqeSDW2xzh2ajFqKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.21,289,1763452800"; d="scan'208";a="212933129" 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: [RFCv2 PATCH 12/13] intel_iommu_accel: Add pasid bits size check Date: Fri, 13 Feb 2026 22:41:32 -0500 Message-ID: <20260214034135.220413-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260214034135.220413-1-zhenzhong.duan@intel.com> References: <20260214034135.220413-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.12; 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: 1771040606827154100 Content-Type: text/plain; charset="utf-8" If pasid bits size is bigger than host side, host could fail to emulate all bindings in guest. Add a check to fail device plug early. Pasid bits size should also be no more than 20 bits according to PCI spec. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 1 + hw/i386/intel_iommu.c | 5 +++++ hw/i386/intel_iommu_accel.c | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index e4bcc884b0..e5518a94ea 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -195,6 +195,7 @@ #define VTD_ECAP_MHMV (15ULL << 20) #define VTD_ECAP_SRS (1ULL << 31) #define VTD_ECAP_NWFS (1ULL << 33) +#define VTD_ECAP_PSS(x) extract64(x, 35, 5) #define VTD_ECAP_PASID (1ULL << 40) #define VTD_ECAP_PDS (1ULL << 42) #define VTD_ECAP_SMTS (1ULL << 43) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 6483cb3d85..c1b31b17de 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -5545,6 +5545,11 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) error_setg(errp, "Need to set scalable mode for PASID"); return false; } + if (s->pasid >=3D PCI_EXT_CAP_PASID_MAX_WIDTH) { + error_setg(errp, "PASID width %d, exceed Max PASID Width %d allowe= d " + "in PCI spec", s->pasid, PCI_EXT_CAP_PASID_MAX_WIDTH); + return false; + } =20 if (s->svm) { if (!x86_iommu->dt_supported) { diff --git a/hw/i386/intel_iommu_accel.c b/hw/i386/intel_iommu_accel.c index acb1b1e238..15412123d5 100644 --- a/hw/i386/intel_iommu_accel.c +++ b/hw/i386/intel_iommu_accel.c @@ -44,6 +44,7 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOMM= UDevice *vtd_hiod, HostIOMMUDevice *hiod =3D vtd_hiod->hiod; struct HostIOMMUDeviceCaps *caps =3D &hiod->caps; struct iommu_hw_info_vtd *vtd =3D &caps->vendor_caps.vtd; + uint8_t hpasid =3D VTD_ECAP_PSS(vtd->ecap_reg) + 1; PCIBus *bus =3D vtd_hiod->bus; PCIDevice *pdev =3D bus->devices[vtd_hiod->devfn]; =20 @@ -64,6 +65,13 @@ bool vtd_check_hiod_accel(IntelIOMMUState *s, VTDHostIOM= MUDevice *vtd_hiod, return false; } =20 + /* Only do the check when host device support PASIDs */ + if (caps->max_pasid_log2 && s->pasid > hpasid) { + error_setg(errp, "PASID bits size %d > host IOMMU PASID bits size = %d", + s->pasid, hpasid); + return false; + } + if (pci_device_get_iommu_bus_devfn(pdev, &bus, NULL, NULL)) { error_setg(errp, "Host device downstream to a PCI bridge is " "unsupported when x-flts=3Don"); --=20 2.47.3