From nobody Wed Apr 16 03:31:43 2025 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=1733992943; cv=none; d=zohomail.com; s=zohoarc; b=UjPd2cQ416E/MZ7Yp60ZmZUp4w9v9wyUWlrGLZBHj5Z2VM59naoprDxOhqEtmVVHzWU9RYrFoGQVZI37m+NNdDnQQfQReX+Yny68ZTXCHjUwh79SsbnsW4rEncDePcwaBIta1iensinn8/oVZw6nxQuZHhifsXhVVfnVHZRPXHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733992943; h=Content-Type: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=NYa73MACnfJq9S6JSSuIM8XfKLqJigyuIny1Wo4q8sM=; b=fgodkko97/nqPPHKS7NITj1gNojzq+Z5u7pgW+99yZVYMr/ypVIPVCARnUsdJWkv+nH5D3DUko2mu1XETAP7wL/fXPlYv0I+rA8G+dWTbVyjkdKexR2d0CSkrh9fJiMrSmxzFSERGw0sX0ksBhwWl4++UBhyZBRc1ZwvxTU/SyU= 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 1733992943853651.9068096311736; Thu, 12 Dec 2024 00:42:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tLell-0004md-V5; Thu, 12 Dec 2024 03:42:02 -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 1tLelb-0004ft-8r for qemu-devel@nongnu.org; Thu, 12 Dec 2024 03:41:56 -0500 Received: from mgamail.intel.com ([198.175.65.20]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tLelZ-0007zv-He for qemu-devel@nongnu.org; Thu, 12 Dec 2024 03:41:51 -0500 Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa112.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2024 00:41:49 -0800 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by fmviesa002-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Dec 2024 00:41:44 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1733992909; x=1765528909; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=NRig9xicZToLVp64jS5HyMBzT+np40CCapHkrXRZR+g=; b=Z7Bbz3OI57rPPak/66g0s2CrYJjI2ul/OmXNWQyxVdydsnt7gOQT4okU CUNmsYOdMpyhF3CwrBFjxaS3zA5U2q9d2wPZDmjO0JhrzsKYoMrLkLQ1z 82tLTG9yUJjOWJZN31Z4dC6ISxR5pOd8ClkwjyT9aKDMSQtlx2FCPFW+P WeIWHr6FOXm9Lcc62Ry6hzUJYVFoCJrLspzFKxPJAyno+Hl7FVQnCgabA UOnJw+GPzI3R5gwfSuRo9T1nEwtxMi8dYTJcTtZYx5OB2YLvtql9lT4hg 4CYp3ksre47EG5YoXYkSwwW+F254Kl1RjcU2u19lwRREiQToE1L6UWE6i g==; X-CSE-ConnectionGUID: 9uchILEwRPygo7DOQvJ3ng== X-CSE-MsgGUID: GTkYoQPXSsq8T0Vgwef6FQ== X-IronPort-AV: E=McAfee;i="6700,10204,11283"; a="34124894" X-IronPort-AV: E=Sophos;i="6.12,228,1728975600"; d="scan'208";a="34124894" X-CSE-ConnectionGUID: MhJDpMSRR0KB1y/CjJ0gow== X-CSE-MsgGUID: OvDdlJWtR8GnynnTXBG3uQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="119407060" From: Zhenzhong Duan To: qemu-devel@nongnu.org Cc: alex.williamson@redhat.com, clg@redhat.com, eric.auger@redhat.com, mst@redhat.com, peterx@redhat.com, jasowang@redhat.com, jgg@nvidia.com, nicolinc@nvidia.com, joao.m.martins@oracle.com, clement.mathieu--drif@eviden.com, kevin.tian@intel.com, yi.l.liu@intel.com, chao.p.peng@intel.com, Zhenzhong Duan , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PATCH v6 08/20] intel_iommu: Check stage-1 translation result with interrupt range Date: Thu, 12 Dec 2024 16:37:45 +0800 Message-Id: <20241212083757.605022-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241212083757.605022-1-zhenzhong.duan@intel.com> References: <20241212083757.605022-1-zhenzhong.duan@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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.20; 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.472, 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: 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: 1733992946444116600 Per VT-d spec 4.1 section 3.15, "Untranslated requests and translation requests that result in an address in the interrupt range will be blocked with condition code LGN.4 or SGN.8." This applies to both stage-1 and stage-2 IOMMU page table, move the check from vtd_iova_to_slpte() to vtd_do_iommu_translate() so stage-1 page table could also be checked. By this chance, update the comment with correct section number. Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif Acked-by: Jason Wang --- hw/i386/intel_iommu.c | 48 ++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index a4a2a44f92..594c8e3272 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1138,7 +1138,6 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDC= ontextEntry *ce, uint32_t offset; uint64_t slpte; uint64_t access_right_check; - uint64_t xlat, size; =20 if (!vtd_iova_sl_range_check(s, iova, ce, aw_bits, pasid)) { error_report_once("%s: detected IOVA overflow (iova=3D0x%" PRIx64 = "," @@ -1191,28 +1190,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTD= ContextEntry *ce, level--; } =20 - xlat =3D vtd_get_pte_addr(*slptep, aw_bits); - size =3D ~vtd_pt_level_page_mask(level) + 1; - - /* - * From VT-d spec 3.14: Untranslated requests and translation - * requests that result in an address in the interrupt range will be - * blocked with condition code LGN.4 or SGN.8. - */ - if ((xlat > VTD_INTERRUPT_ADDR_LAST || - xlat + size - 1 < VTD_INTERRUPT_ADDR_FIRST)) { - return 0; - } else { - error_report_once("%s: xlat address is in interrupt range " - "(iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 ", " - "slpte=3D0x%" PRIx64 ", write=3D%d, " - "xlat=3D0x%" PRIx64 ", size=3D0x%" PRIx64 ", " - "pasid=3D0x%" PRIx32 ")", - __func__, iova, level, slpte, is_write, - xlat, size, pasid); - return s->scalable_mode ? -VTD_FR_SM_INTERRUPT_ADDR : - -VTD_FR_INTERRUPT_ADDR; - } + return 0; } =20 typedef int (*vtd_page_walk_hook)(const IOMMUTLBEvent *event, void *privat= e); @@ -2064,6 +2042,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, uint8_t access_flags; bool rid2pasid =3D (pasid =3D=3D PCI_NO_PASID) && s->root_scalable; VTDIOTLBEntry *iotlb_entry; + uint64_t xlat, size; =20 /* * We have standalone memory region for interrupt addresses, we @@ -2173,6 +2152,29 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *= vtd_as, PCIBus *bus, ret_fr =3D vtd_iova_to_slpte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); } + if (!ret_fr) { + xlat =3D vtd_get_pte_addr(pte, s->aw_bits); + size =3D ~vtd_pt_level_page_mask(level) + 1; + + /* + * Per VT-d spec 4.1 section 3.15: Untranslated requests and trans= lation + * requests that result in an address in the interrupt range will = be + * blocked with condition code LGN.4 or SGN.8. + */ + if ((xlat <=3D VTD_INTERRUPT_ADDR_LAST && + xlat + size - 1 >=3D VTD_INTERRUPT_ADDR_FIRST)) { + error_report_once("%s: xlat address is in interrupt range " + "(iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 = ", " + "pte=3D0x%" PRIx64 ", write=3D%d, " + "xlat=3D0x%" PRIx64 ", size=3D0x%" PRIx64 ",= " + "pasid=3D0x%" PRIx32 ")", + __func__, addr, level, pte, is_write, + xlat, size, pasid); + ret_fr =3D s->scalable_mode ? -VTD_FR_SM_INTERRUPT_ADDR : + -VTD_FR_INTERRUPT_ADDR; + } + } + if (ret_fr) { vtd_report_fault(s, -ret_fr, is_fpd_set, source_id, addr, is_write, pasid !=3D PCI_NO_PASID, pasid); --=20 2.34.1