From nobody Thu Nov 14 04:01:32 2024 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=1726032493; cv=none; d=zohomail.com; s=zohoarc; b=JCx0WSws+6CTvfeltMl13OictVLZXyCgYagv2IHorMBn6gI+9mMNiFiB2yAWPjbYlJt1TA9Sbsx6c3jHLmnLJTZcEoPI0dBZOE4kCgHVemDDBsnhCSREybNjW8BrOkPEjlwtiI0kg4ggbPYkWV1VNJ2S17IuPeWVDIBfx1EMXms= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032493; 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=d3wldeZLV+uXUt9rNV9bNDM/WKZyrngGWkGRXLWc2Yo=; b=E/fdm0Nu9UxURVgE3WlORd63lLd7EPral2ufgwMo+ha7Z9lQdS3OQ/PU3tF535yXfDVwnBPoB+Hee7aTsw9KsYKR/iVty2Y7x9zMnHFbTsU52giZbumb8X5u8Ui7zrxTUXPAGZA7Maa3+0a+gs9QAuV4QskKYs54WI0EOgqXNlY= 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 1726032493065711.4874696010602; Tue, 10 Sep 2024 22:28:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFre-0001Cz-H5; Wed, 11 Sep 2024 01:26:02 -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 1soFrc-00019Q-PF for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:00 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFrY-0004MK-RO for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:25:59 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:25:56 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:25:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032357; x=1757568357; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WBGd7s08GsIV9E35orrU72LSBIrn/mf1CKQqNso5sGc=; b=k5cE8Z7pGqOXmtHCBY1mMDbkkcUMNSRA43Fm7HtZXYBy58bLt8+4/c2M oNW/GIGdmcQLO3T9Alw8AFbuXcRuZON7NXfVE6dglYG2c35kJ2TJFI1x+ OzKLdIS5OULKEo9/NQlVBdc30mHGTu6NlJNB1pj0yGSbgfHX8g+bTMUdO Np4qYFhmt7DX1QuymstfoA58gSBSoe+u6gClOeRitLNRlyzPJ3bZvc0lt jjYJl+k9eUOxOl4aV9J153/nHlHb/3mVkmFilj5Zoa8yUbrLtrRDNXknD YHi9JgbN76mJsMw5G6MiKvhclK6n4TbdodlqBSmSEi6ygqgFaM1aZ7U1i w==; X-CSE-ConnectionGUID: w+wHqQhaSiKo5A+MdqNKOg== X-CSE-MsgGUID: qEE13Yo0RkWdg/XbrElRTw== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403466" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403466" X-CSE-ConnectionGUID: KVYrI+CvQG2TQXzLxDu9wQ== X-CSE-MsgGUID: J7cmToV8Rl2w+6ptQ8vKAg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536368" 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 , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH v3 01/17] intel_iommu: Use the latest fault reasons defined by spec Date: Wed, 11 Sep 2024 13:22:39 +0800 Message-Id: <20240911052255.1294071-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032494879116601 From: Yu Zhang Spec revision 3.0 or above defines more detailed fault reasons for scalable mode. So introduce them into emulation code, see spec section 7.1.2 for details. Note spec revision has no relation with VERSION register, Guest kernel should not use that register to judge what features are supported. Instead cap/ecap bits should be checked. Signed-off-by: Yu Zhang Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif Reviewed-by: Yi Liu Acked-by: Jason Wang --- hw/i386/intel_iommu_internal.h | 9 ++++++++- hw/i386/intel_iommu.c | 25 ++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 5f32c36943..8fa27c7f3b 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -311,7 +311,14 @@ typedef enum VTDFaultReason { * request while disabled */ VTD_FR_IR_SID_ERR =3D 0x26, /* Invalid Source-ID */ =20 - VTD_FR_PASID_TABLE_INV =3D 0x58, /*Invalid PASID table entry */ + /* PASID directory entry access failure */ + VTD_FR_PASID_DIR_ACCESS_ERR =3D 0x50, + /* The Present(P) field of pasid directory entry is 0 */ + VTD_FR_PASID_DIR_ENTRY_P =3D 0x51, + VTD_FR_PASID_TABLE_ACCESS_ERR =3D 0x58, /* PASID table entry access fa= ilure */ + /* The Present(P) field of pasid table entry is 0 */ + VTD_FR_PASID_ENTRY_P =3D 0x59, + VTD_FR_PASID_TABLE_ENTRY_INV =3D 0x5b, /*Invalid PASID table entry */ =20 /* Output address in the interrupt address range for scalable mode */ VTD_FR_SM_INTERRUPT_ADDR =3D 0x87, diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 16d2885fcc..c52912f593 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -796,7 +796,7 @@ static int vtd_get_pdire_from_pdir_table(dma_addr_t pas= id_dir_base, addr =3D pasid_dir_base + index * entry_size; if (dma_memory_read(&address_space_memory, addr, pdire, entry_size, MEMTXATTRS_UNSPECIFIED)) { - return -VTD_FR_PASID_TABLE_INV; + return -VTD_FR_PASID_DIR_ACCESS_ERR; } =20 pdire->val =3D le64_to_cpu(pdire->val); @@ -814,6 +814,7 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSta= te *s, dma_addr_t addr, VTDPASIDEntry *pe) { + uint8_t pgtt; uint32_t index; dma_addr_t entry_size; X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); @@ -823,7 +824,7 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSta= te *s, addr =3D addr + index * entry_size; if (dma_memory_read(&address_space_memory, addr, pe, entry_size, MEMTXATTRS_UNSPECIFIED)) { - return -VTD_FR_PASID_TABLE_INV; + return -VTD_FR_PASID_TABLE_ACCESS_ERR; } for (size_t i =3D 0; i < ARRAY_SIZE(pe->val); i++) { pe->val[i] =3D le64_to_cpu(pe->val[i]); @@ -831,11 +832,13 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUS= tate *s, =20 /* Do translation type check */ if (!vtd_pe_type_check(x86_iommu, pe)) { - return -VTD_FR_PASID_TABLE_INV; + return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 - if (!vtd_is_level_supported(s, VTD_PE_GET_LEVEL(pe))) { - return -VTD_FR_PASID_TABLE_INV; + pgtt =3D VTD_PE_GET_TYPE(pe); + if (pgtt =3D=3D VTD_SM_PASID_ENTRY_SLT && + !vtd_is_level_supported(s, VTD_PE_GET_LEVEL(pe))) { + return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 return 0; @@ -876,7 +879,7 @@ static int vtd_get_pe_from_pasid_table(IntelIOMMUState = *s, } =20 if (!vtd_pdire_present(&pdire)) { - return -VTD_FR_PASID_TABLE_INV; + return -VTD_FR_PASID_DIR_ENTRY_P; } =20 ret =3D vtd_get_pe_from_pdire(s, pasid, &pdire, pe); @@ -885,7 +888,7 @@ static int vtd_get_pe_from_pasid_table(IntelIOMMUState = *s, } =20 if (!vtd_pe_present(pe)) { - return -VTD_FR_PASID_TABLE_INV; + return -VTD_FR_PASID_ENTRY_P; } =20 return 0; @@ -938,7 +941,7 @@ static int vtd_ce_get_pasid_fpd(IntelIOMMUState *s, } =20 if (!vtd_pdire_present(&pdire)) { - return -VTD_FR_PASID_TABLE_INV; + return -VTD_FR_PASID_DIR_ENTRY_P; } =20 /* @@ -1795,7 +1798,11 @@ static const bool vtd_qualified_faults[] =3D { [VTD_FR_ROOT_ENTRY_RSVD] =3D false, [VTD_FR_PAGING_ENTRY_RSVD] =3D true, [VTD_FR_CONTEXT_ENTRY_TT] =3D true, - [VTD_FR_PASID_TABLE_INV] =3D false, + [VTD_FR_PASID_DIR_ACCESS_ERR] =3D false, + [VTD_FR_PASID_DIR_ENTRY_P] =3D true, + [VTD_FR_PASID_TABLE_ACCESS_ERR] =3D false, + [VTD_FR_PASID_ENTRY_P] =3D true, + [VTD_FR_PASID_TABLE_ENTRY_INV] =3D true, [VTD_FR_SM_INTERRUPT_ADDR] =3D true, [VTD_FR_MAX] =3D false, }; --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032403; cv=none; d=zohomail.com; s=zohoarc; b=NraJEZeUCv9eB/cBtI8EMxDNGfmMVDCKN8jLOFyKAcCP42PW8LsYmjahxl86pFAxbHnoxjWpkemFHWhrdb3CU5GEukw15cizm7gqhCcmtpnHTxpMSNt6tXdFdOwTKKRXmhF6KdO1i97rQGPUI67UwNd9+slCvokzL00z8tnZdy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032403; 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=4xhufuRueKlS2TTHVOTFYFbols3PLO6c2GWAGYgD8/A=; b=eKaldWaZkVEnpkX+Nf4meOw12PirDRJZCjhcIyLQfInnv6abkl5dkMF/rTZaGEhgiY4pDdsmC3IXQBfeAPCZ+Ww6n1O68fPo6f4AhLbfcsNiIrfhlAF5eKLBrFcNJY0ESqrJLhTH962Pi2Mo3hkS7RGT9H2HD30iPJ5ixcBm9ug= 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 1726032403150480.57938711881377; Tue, 10 Sep 2024 22:26:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFrh-0001P5-EB; Wed, 11 Sep 2024 01:26: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 1soFrf-0001I9-M9 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:03 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFre-0004Mp-3M for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:03 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:01 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:25:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032362; x=1757568362; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fdLaeQ2wJhUQtZInKCRoy8xQWv0CTlYap8gAOZpipm4=; b=VAjdTk5t7SG7Y2Bpr+3yhVwBsIYaUCLpWsoZDa09EeXfy5LP9MwENRch nUca63kwi9vcWs/+bPGrEVmEsHV8s1T+GbD4vtYemyICtVb7MCCpvee7Z cIRtO5PmmMets5CIRIRH32sfQKvWX6YJJv8fIjXulfA1u1fKR2aGxEuax eUWhfolApTg0CILXt4VCiJCUf63C0F+ylK4z59xBkalgxIxXAKZ2S/s+r KgOFGP9mdA5UexLtwnVJ2A9VjsNQKzhTfoUqAgFgjW8X46/HBy8Z64OWX c3gFBmJvfZHW6Inf1bfA5wy7k8ri4s3ByIlrndiKN3577tp5Soz0JOT34 A==; X-CSE-ConnectionGUID: d9orO9x6TRW8BSKAKCXLOA== X-CSE-MsgGUID: R4esBhImTfqkURV2tDzcBQ== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403480" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403480" X-CSE-ConnectionGUID: zXCswvAPSVCCI3S2FzOrGA== X-CSE-MsgGUID: LO8D1lGASay+5ncPnJJxWw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536380" 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 v3 02/17] intel_iommu: Make pasid entry type check accurate Date: Wed, 11 Sep 2024 13:22:40 +0800 Message-Id: <20240911052255.1294071-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032405381116600 When guest configures Nested Translation(011b) or First-stage Translation o= nly (001b), type check passed unaccurately. Fails the type check in those cases as their simulation isn't supported yet. Fixes: fb43cf739e1 ("intel_iommu: scalable mode emulation") Suggested-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif Reviewed-by: Yi Liu Acked-by: Jason Wang --- hw/i386/intel_iommu.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index c52912f593..e3465fc27d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -759,20 +759,16 @@ static inline bool vtd_pe_type_check(X86IOMMUState *x= 86_iommu, VTDPASIDEntry *pe) { switch (VTD_PE_GET_TYPE(pe)) { - case VTD_SM_PASID_ENTRY_FLT: case VTD_SM_PASID_ENTRY_SLT: - case VTD_SM_PASID_ENTRY_NESTED: - break; + return true; case VTD_SM_PASID_ENTRY_PT: - if (!x86_iommu->pt_supported) { - return false; - } - break; + return x86_iommu->pt_supported; + case VTD_SM_PASID_ENTRY_FLT: + case VTD_SM_PASID_ENTRY_NESTED: default: /* Unknown type */ return false; } - return true; } =20 static inline bool vtd_pdire_present(VTDPASIDDirEntry *pdire) --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032438; cv=none; d=zohomail.com; s=zohoarc; b=Wd0aqYyKMT7PHl09yjlceK1WUSUZGXD3/+Owx0cAjIYTFJbMRLjby/yJiQIt5UqDlCj/rJrel/xQfyVsmOH97pqZ6KtKwzOISPojvA/0oPIpia2BQbhw0f6dI2+IMddjltKxxe6FFfHhe0tM4f4Y61YoNK2X8z3EX7UGgLcAUqc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032438; 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=pDgGOUkZEPtQ9XcgGcaHAPHAnvpXyDbTXFcxNd+VCB0=; b=X6CXI6WsBL63AsgK6bV0+rNzkV4lIdvP/o8p8tNtw9Ry3z78tx0i2nsKoUqfygIryEYqlV8w3vXfA1w7MA+bZ85UtNkcXnpD8SjTkghd9dXJv+AxIUfgl+C12hE427Rj3rnntpeCvQxGWcWzDBGZj27bxvZXAJsmlrkkwGd+XJQ= 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 1726032437820918.7694573201287; Tue, 10 Sep 2024 22:27:17 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFrm-0001dx-8T; Wed, 11 Sep 2024 01:26: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 1soFrj-0001Yb-Rt for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:07 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFri-0004Mp-7M for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:07 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:06 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032366; x=1757568366; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yRJXEvULghdGdFE/Kjm+649W8BclXyUE8cGTIU3m5lc=; b=DKMkloJwCpmCfpTlzoXjIdzQ2r9wY4WF21DsObfhByu7HgNky7XShJB1 02ms+G53feHsLmBZFoHR1MT6m3RA1q9CyLumV1P8B2HZPFo0eDvFOXvqz PhmMUPxYJUbUG9MU3Yjq0rOvwqK/i/iwNoeodm1TTJbTnb6jB85O+JosK zFI7FNwHAfuEOzJff3wJortHl6hYr+Q+ufN1VPoF8b/vNHC1TubSy4INy qztR6D80COtRPttu+AbeFH1cdh20RDkhMikbfCmXGAKQl9C/VUfFk4QhB fc+2fBiFnTMX7OyRXStbi+YTw3a/YMhzrRTN2Ii5qC37U9+s9UCd2a51b A==; X-CSE-ConnectionGUID: OadyJEarS2yaMyt2YaXLEg== X-CSE-MsgGUID: 5zo+pHneRpyxiwwO6LsQlw== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403489" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403489" X-CSE-ConnectionGUID: 4Ed2/OgfSQO2rccMVHR1cg== X-CSE-MsgGUID: Ddb+p4BdQRi0KA4lVOOGbw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536401" 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 , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH v3 03/17] intel_iommu: Add a placeholder variable for scalable modern mode Date: Wed, 11 Sep 2024 13:22:41 +0800 Message-Id: <20240911052255.1294071-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032438625116600 Content-Type: text/plain; charset="utf-8" Add an new element scalable_mode in IntelIOMMUState to mark scalable modern mode, this element will be exposed as an intel_iommu property finally. For now, it's only a placehholder and used for address width compatibility check and block host device passthrough until nesting is supported. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Acked-by: Jason Wang --- include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 22 ++++++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 1eb05c29fc..788ed42477 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -262,6 +262,7 @@ struct IntelIOMMUState { =20 bool caching_mode; /* RO - is cap CM enabled? */ bool scalable_mode; /* RO - is Scalable Mode supported? */ + bool scalable_modern; /* RO - is modern SM supported? */ bool snoop_control; /* RO - is SNP filed supported? */ =20 dma_addr_t root; /* Current root table pointer */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index e3465fc27d..57c24f67b4 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3872,7 +3872,13 @@ static bool vtd_check_hiod(IntelIOMMUState *s, HostI= OMMUDevice *hiod, return false; } =20 - return true; + if (!s->scalable_modern) { + /* All checks requested by VTD non-modern mode pass */ + return true; + } + + error_setg(errp, "host device is unsupported in scalable modern mode y= et"); + return false; } =20 static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, @@ -4262,14 +4268,22 @@ static bool vtd_decide_config(IntelIOMMUState *s, E= rror **errp) } } =20 - /* Currently only address widths supported are 39 and 48 bits */ if ((s->aw_bits !=3D VTD_HOST_AW_39BIT) && - (s->aw_bits !=3D VTD_HOST_AW_48BIT)) { - error_setg(errp, "Supported values for aw-bits are: %d, %d", + (s->aw_bits !=3D VTD_HOST_AW_48BIT) && + !s->scalable_modern) { + error_setg(errp, "%s mode: supported values for aw-bits are: %d, %= d", + s->scalable_mode ? "Scalable legacy" : "Legacy", VTD_HOST_AW_39BIT, VTD_HOST_AW_48BIT); return false; } =20 + if ((s->aw_bits !=3D VTD_HOST_AW_48BIT) && s->scalable_modern) { + error_setg(errp, + "Scalable modern mode: supported values for aw-bits is:= %d", + VTD_HOST_AW_48BIT); + return false; + } + if (s->scalable_mode && !s->dma_drain) { error_setg(errp, "Need to set dma_drain for scalable mode"); return false; --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032447; cv=none; d=zohomail.com; s=zohoarc; b=GedUVS5A+q91yXn0VcrRCsYTbsyytu8PIBj3il/tbmHCmOPMS9xCQger+yZBnEkW2GrGY81VI8qR5rpYIgQNcsIO8cxLwn3y/bNW/F3l+VxZokQOR8kbLQJD7qjHICd6ANPsMNIoug8eyGRnF+uW7Ag5qzNsPxFoKGZrV3E/6zM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032447; 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=qZxWaSqkximAcg5De96HeHX2m5jbHARiIXS3B2i2bfo=; b=goRfTsnvehLVC81MEr6SKfJczOLbTh1zvRczrQ/Htpl/M0/BSivsHRt6mgXl7QWeBVB2EwIdS+uPrOEZfaBWxZ869VbcHoVVbaFGd7LK5u2VkKZbeN12f8e3qIgAfIlmcyGNGgsJaHyPT2LQHcNUXkiEVfNN2RTph+17qUU9ayI= 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 1726032447934815.4054739524047; Tue, 10 Sep 2024 22:27:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFrr-0001sK-Pz; Wed, 11 Sep 2024 01:26:15 -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 1soFrq-0001p8-5U for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:14 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFrn-0004Mp-7v for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:12 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:11 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032371; x=1757568371; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=8JgOAjqsCXh2Jv2a15ROtZeb/1JSLYnzrXKLtJA4zx4=; b=XuCXz3QZsPAr1dWMJAo7CJLMPAYqkpq02T1aniVQmKrJMQRnYDkNfCMj 9u6e7RwmmL0v2NghRuzjrZ0Nq1ZcRqtIj7peKH9FShoHOMF+1To9GM4KE PFjtqCav5P2URq/lfEiELj2g5lVWSCE7MfEz5yx4bEaQlVV6BzS55VZ10 5l6FCxTj2+ZLgtG0N1A6YstoHknkWBvs+OTbAbC+CI+TQbbH/wFWvdlcF 9HOHnp8YCIRRZXvdRmyW8TjjF1/djTNtMKMyDZYyLKr7DgmSDq5B06QKl svne0zL3FPlask7cpLIkfE4JES2nHdYSAvf8ZrIFcOW0xOFyItEtfBXhf w==; X-CSE-ConnectionGUID: p54VhiY+Qlu1osOuQWk9bA== X-CSE-MsgGUID: jLSQvA8vQSC+RFvpFbQtnA== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403505" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403505" X-CSE-ConnectionGUID: hz89m+W3R1KMGO3QYlXB5w== X-CSE-MsgGUID: /iTRgHc6TlmrI+HC7SpGgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536418" 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 v3 04/17] intel_iommu: Flush stage-2 cache in PASID-selective PASID-based iotlb invalidation Date: Wed, 11 Sep 2024 13:22:42 +0800 Message-Id: <20240911052255.1294071-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032448879116600 Content-Type: text/plain; charset="utf-8" Per spec 6.5.2.4, PADID-selective PASID-based iotlb invalidation will flush stage-2 iotlb entries with matching domain id and pasid. With scalable modern mode introduced, guest could send PASID-selective PASID-based iotlb invalidation to flush both stage-1 and stage-2 entries. By this chance, remove old IOTLB related definition. Signed-off-by: Zhenzhong Duan Acked-by: Jason Wang Reviewed-by: Cl=C3=A9ment Mathieu--Drif --- hw/i386/intel_iommu_internal.h | 14 +++--- hw/i386/intel_iommu.c | 81 ++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 8fa27c7f3b..19e4ed52ca 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -402,11 +402,6 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_IOTLB_AM(val) ((val) & 0x3fULL) #define VTD_INV_DESC_IOTLB_RSVD_LO 0xffffffff0000ff00ULL #define VTD_INV_DESC_IOTLB_RSVD_HI 0xf80ULL -#define VTD_INV_DESC_IOTLB_PASID_PASID (2ULL << 4) -#define VTD_INV_DESC_IOTLB_PASID_PAGE (3ULL << 4) -#define VTD_INV_DESC_IOTLB_PASID(val) (((val) >> 32) & VTD_PASID_ID_MASK) -#define VTD_INV_DESC_IOTLB_PASID_RSVD_LO 0xfff00000000001c0ULL -#define VTD_INV_DESC_IOTLB_PASID_RSVD_HI 0xf80ULL =20 /* Mask for Device IOTLB Invalidate Descriptor */ #define VTD_INV_DESC_DEVICE_IOTLB_ADDR(val) ((val) & 0xfffffffffffff000ULL) @@ -438,6 +433,15 @@ typedef union VTDInvDesc VTDInvDesc; (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM))= : \ (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) =20 +/* Masks for PIOTLB Invalidate Descriptor */ +#define VTD_INV_DESC_PIOTLB_G (3ULL << 4) +#define VTD_INV_DESC_PIOTLB_ALL_IN_PASID (2ULL << 4) +#define VTD_INV_DESC_PIOTLB_PSI_IN_PASID (3ULL << 4) +#define VTD_INV_DESC_PIOTLB_DID(val) (((val) >> 16) & VTD_DOMAIN_ID_M= ASK) +#define VTD_INV_DESC_PIOTLB_PASID(val) (((val) >> 32) & 0xfffffULL) +#define VTD_INV_DESC_PIOTLB_RSVD_VAL0 0xfff000000000f1c0ULL +#define VTD_INV_DESC_PIOTLB_RSVD_VAL1 0xf80ULL + /* Information about page-selective IOTLB invalidate */ struct VTDIOTLBPageInvInfo { uint16_t domain_id; diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 57c24f67b4..be30caef31 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2656,6 +2656,83 @@ static bool vtd_process_iotlb_desc(IntelIOMMUState *= s, VTDInvDesc *inv_desc) return true; } =20 +static gboolean vtd_hash_remove_by_pasid(gpointer key, gpointer value, + gpointer user_data) +{ + VTDIOTLBEntry *entry =3D (VTDIOTLBEntry *)value; + VTDIOTLBPageInvInfo *info =3D (VTDIOTLBPageInvInfo *)user_data; + + return ((entry->domain_id =3D=3D info->domain_id) && + (entry->pasid =3D=3D info->pasid)); +} + +static void vtd_piotlb_pasid_invalidate(IntelIOMMUState *s, + uint16_t domain_id, uint32_t pasid) +{ + VTDIOTLBPageInvInfo info; + VTDAddressSpace *vtd_as; + VTDContextEntry ce; + + info.domain_id =3D domain_id; + info.pasid =3D pasid; + + vtd_iommu_lock(s); + g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_pasid, + &info); + vtd_iommu_unlock(s); + + QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) { + 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)) { + uint32_t rid2pasid =3D VTD_CE_GET_RID2PASID(&ce); + + if ((vtd_as->pasid !=3D PCI_NO_PASID || pasid !=3D rid2pasid) = && + vtd_as->pasid !=3D pasid) { + continue; + } + + if (!s->scalable_modern) { + vtd_address_space_sync(vtd_as); + } + } + } +} + +static bool vtd_process_piotlb_desc(IntelIOMMUState *s, + VTDInvDesc *inv_desc) +{ + uint16_t domain_id; + uint32_t pasid; + + if ((inv_desc->val[0] & VTD_INV_DESC_PIOTLB_RSVD_VAL0) || + (inv_desc->val[1] & VTD_INV_DESC_PIOTLB_RSVD_VAL1)) { + error_report_once("%s: invalid piotlb inv desc hi=3D0x%"PRIx64 + " lo=3D0x%"PRIx64" (reserved bits unzero)", + __func__, inv_desc->val[1], inv_desc->val[0]); + return false; + } + + domain_id =3D VTD_INV_DESC_PIOTLB_DID(inv_desc->val[0]); + pasid =3D VTD_INV_DESC_PIOTLB_PASID(inv_desc->val[0]); + switch (inv_desc->val[0] & VTD_INV_DESC_PIOTLB_G) { + case VTD_INV_DESC_PIOTLB_ALL_IN_PASID: + vtd_piotlb_pasid_invalidate(s, domain_id, pasid); + break; + + case VTD_INV_DESC_PIOTLB_PSI_IN_PASID: + break; + + default: + error_report_once("%s: invalid piotlb inv desc: hi=3D0x%"PRIx64 + ", lo=3D0x%"PRIx64" (type mismatch: 0x%llx)", + __func__, inv_desc->val[1], inv_desc->val[0], + inv_desc->val[0] & VTD_INV_DESC_IOTLB_G); + return false; + } + return true; +} + static bool vtd_process_inv_iec_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { @@ -2775,6 +2852,10 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s) break; =20 case VTD_INV_DESC_PIOTLB: + trace_vtd_inv_desc("p-iotlb", inv_desc.val[1], inv_desc.val[0]); + if (!vtd_process_piotlb_desc(s, &inv_desc)) { + return false; + } break; =20 case VTD_INV_DESC_WAIT: --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032495; cv=none; d=zohomail.com; s=zohoarc; b=kBk8UHzPbfXUwQDoP+ZyBSnW30YMg7gZHtG3gmL5ZjRkUwhkso3QnR0bTuDa+4WG4poZLBpsdKmcF6T8LytNU2P53tgTMjEsmY+tdaCfi9KEi6ZTwnXBAMFn9i4egiTwwHNnvsgy+ESogdQRwl67V/CqGurOPkshhIDFZ97RiWk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032495; 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=snej8WDSIR9BwWNszHeEAzKUTlL5wulYC76HdCj5iWs=; b=Nn1blFOAMoOGoCi/Z284JspY/vY+YQpkFgveHl8M4CaDUfCcQeBvSyIN0WNhd5D+yTfuyFoA1IgzeVu0tbH4dH1I0MaE7UjBSHlEnNLWEcZoRi5O0BDkRdyggXCrAZbAerkHUCqigrEL/JZZm+SVeu4VcIn4sF1p0YDOZXQZlC8= 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 1726032495229223.9226305548816; Tue, 10 Sep 2024 22:28:15 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFrv-00021e-T3; Wed, 11 Sep 2024 01:26: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 1soFrv-00021B-8i for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:19 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFrs-0004Mp-KK for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:19 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:16 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:11 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032377; x=1757568377; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iRap4Jj+oXndq7gbfD0F6CtQ0TTnKar83Vg2fXRZVmM=; b=NqK6QNBqrkP/A073LecuI4higpBerrqokBpaQlcgm02+pxHh1ltzXUsc sVrA9htvN4E/BXsXu8nGviha4xY5MKe0Esg4yqji7UA5ff+ocJTmhH2uj YYqKkPA1Zs4xw8FwKb4vNwQMKY11JBg03THf5yuFRPwCuyqUVhqqjzlwz lEnv87B1Qzbds8pPElN3SSXwYoJEXRkcqyog4lO10rFAJptQHKa99CovC 0K3VA4f7REe/Psv8ztqYBT/XxguCqs5tDcppV//VKhxEkzTy8HypLRNRO X7t1dl2D4+vSlRBG6O6rHNWMlydTMYQBAkzgc/42sVoIhWOsrm3XNzDgV w==; X-CSE-ConnectionGUID: B6WwLsfVTNKiuzcrNaq3Pg== X-CSE-MsgGUID: +OLW7bR5Q6WsK1uXpKbILQ== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403521" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403521" X-CSE-ConnectionGUID: IIYvKm5DT66Ti9S9IVEHmQ== X-CSE-MsgGUID: ygEoTMY1TyqvtW+3t4Yozw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536429" 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 v3 05/17] intel_iommu: Rename slpte to pte Date: Wed, 11 Sep 2024 13:22:43 +0800 Message-Id: <20240911052255.1294071-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032497237116600 From: Yi Liu Because we will support both FST(a.k.a, FLT) and SST(a.k.a, SLT) translatio= n, rename variable and functions from slpte to pte whenever possible. But some are SST only, they are renamed with sl_ prefix. Signed-off-by: Yi Liu Co-developed-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Acked-by: Jason Wang Reviewed-by: Yi Liu --- hw/i386/intel_iommu_internal.h | 24 +++--- include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 129 +++++++++++++++++---------------- 3 files changed, 78 insertions(+), 77 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 19e4ed52ca..1fa4add9e2 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -528,24 +528,24 @@ typedef struct VTDRootEntry VTDRootEntry; /* Second Level Page Translation Pointer*/ #define VTD_SM_PASID_ENTRY_SLPTPTR (~0xfffULL) =20 -/* Paging Structure common */ -#define VTD_SL_PT_PAGE_SIZE_MASK (1ULL << 7) -/* Bits to decide the offset for each level */ -#define VTD_SL_LEVEL_BITS 9 - /* Second Level Paging Structure */ -#define VTD_SL_PML4_LEVEL 4 -#define VTD_SL_PDP_LEVEL 3 -#define VTD_SL_PD_LEVEL 2 -#define VTD_SL_PT_LEVEL 1 -#define VTD_SL_PT_ENTRY_NR 512 - /* Masks for Second Level Paging Entry */ #define VTD_SL_RW_MASK 3ULL #define VTD_SL_R 1ULL #define VTD_SL_W (1ULL << 1) -#define VTD_SL_PT_BASE_ADDR_MASK(aw) (~(VTD_PAGE_SIZE - 1) & VTD_HAW_MASK(= aw)) #define VTD_SL_IGN_COM 0xbff0000000000000ULL #define VTD_SL_TM (1ULL << 62) =20 +/* Common for both First Level and Second Level */ +#define VTD_PML4_LEVEL 4 +#define VTD_PDP_LEVEL 3 +#define VTD_PD_LEVEL 2 +#define VTD_PT_LEVEL 1 +#define VTD_PT_ENTRY_NR 512 +#define VTD_PT_PAGE_SIZE_MASK (1ULL << 7) +#define VTD_PT_BASE_ADDR_MASK(aw) (~(VTD_PAGE_SIZE - 1) & VTD_HAW_MASK(aw)) + +/* Bits to decide the offset for each level */ +#define VTD_LEVEL_BITS 9 + #endif diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 788ed42477..fe9057c50d 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -152,7 +152,7 @@ struct VTDIOTLBEntry { uint64_t gfn; uint16_t domain_id; uint32_t pasid; - uint64_t slpte; + uint64_t pte; uint64_t mask; uint8_t access_flags; }; diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index be30caef31..a22bd43b98 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -48,7 +48,8 @@ =20 /* pe operations */ #define VTD_PE_GET_TYPE(pe) ((pe)->val[0] & VTD_SM_PASID_ENTRY_PGTT) -#define VTD_PE_GET_LEVEL(pe) (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTR= Y_AW)) +#define VTD_PE_GET_SL_LEVEL(pe) \ + (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTRY_AW)) =20 /* * PCI bus number (or SID) is not reliable since the device is usaully @@ -284,15 +285,15 @@ static gboolean vtd_hash_remove_by_domain(gpointer ke= y, gpointer value, } =20 /* The shift of an addr for a certain level of paging structure */ -static inline uint32_t vtd_slpt_level_shift(uint32_t level) +static inline uint32_t vtd_pt_level_shift(uint32_t level) { assert(level !=3D 0); - return VTD_PAGE_SHIFT_4K + (level - 1) * VTD_SL_LEVEL_BITS; + return VTD_PAGE_SHIFT_4K + (level - 1) * VTD_LEVEL_BITS; } =20 -static inline uint64_t vtd_slpt_level_page_mask(uint32_t level) +static inline uint64_t vtd_pt_level_page_mask(uint32_t level) { - return ~((1ULL << vtd_slpt_level_shift(level)) - 1); + return ~((1ULL << vtd_pt_level_shift(level)) - 1); } =20 static gboolean vtd_hash_remove_by_page(gpointer key, gpointer value, @@ -349,7 +350,7 @@ static void vtd_reset_caches(IntelIOMMUState *s) =20 static uint64_t vtd_get_iotlb_gfn(hwaddr addr, uint32_t level) { - return (addr & vtd_slpt_level_page_mask(level)) >> VTD_PAGE_SHIFT_4K; + return (addr & vtd_pt_level_page_mask(level)) >> VTD_PAGE_SHIFT_4K; } =20 /* Must be called with IOMMU lock held */ @@ -360,7 +361,7 @@ static VTDIOTLBEntry *vtd_lookup_iotlb(IntelIOMMUState = *s, uint16_t source_id, VTDIOTLBEntry *entry; unsigned level; =20 - for (level =3D VTD_SL_PT_LEVEL; level < VTD_SL_PML4_LEVEL; level++) { + for (level =3D VTD_PT_LEVEL; level < VTD_PML4_LEVEL; level++) { key.gfn =3D vtd_get_iotlb_gfn(addr, level); key.level =3D level; key.sid =3D source_id; @@ -377,7 +378,7 @@ out: =20 /* Must be with IOMMU lock held */ static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id, - uint16_t domain_id, hwaddr addr, uint64_t slp= te, + uint16_t domain_id, hwaddr addr, uint64_t pte, uint8_t access_flags, uint32_t level, uint32_t pasid) { @@ -385,7 +386,7 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16= _t source_id, struct vtd_iotlb_key *key =3D g_malloc(sizeof(*key)); uint64_t gfn =3D vtd_get_iotlb_gfn(addr, level); =20 - trace_vtd_iotlb_page_update(source_id, addr, slpte, domain_id); + trace_vtd_iotlb_page_update(source_id, addr, pte, domain_id); if (g_hash_table_size(s->iotlb) >=3D VTD_IOTLB_MAX_SIZE) { trace_vtd_iotlb_reset("iotlb exceeds size limit"); vtd_reset_iotlb_locked(s); @@ -393,9 +394,9 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16= _t source_id, =20 entry->gfn =3D gfn; entry->domain_id =3D domain_id; - entry->slpte =3D slpte; + entry->pte =3D pte; entry->access_flags =3D access_flags; - entry->mask =3D vtd_slpt_level_page_mask(level); + entry->mask =3D vtd_pt_level_page_mask(level); entry->pasid =3D pasid; =20 key->gfn =3D gfn; @@ -710,32 +711,32 @@ static inline dma_addr_t vtd_ce_get_slpt_base(VTDCont= extEntry *ce) return ce->lo & VTD_CONTEXT_ENTRY_SLPTPTR; } =20 -static inline uint64_t vtd_get_slpte_addr(uint64_t slpte, uint8_t aw) +static inline uint64_t vtd_get_pte_addr(uint64_t pte, uint8_t aw) { - return slpte & VTD_SL_PT_BASE_ADDR_MASK(aw); + return pte & VTD_PT_BASE_ADDR_MASK(aw); } =20 /* Whether the pte indicates the address of the page frame */ -static inline bool vtd_is_last_slpte(uint64_t slpte, uint32_t level) +static inline bool vtd_is_last_pte(uint64_t pte, uint32_t level) { - return level =3D=3D VTD_SL_PT_LEVEL || (slpte & VTD_SL_PT_PAGE_SIZE_MA= SK); + return level =3D=3D VTD_PT_LEVEL || (pte & VTD_PT_PAGE_SIZE_MASK); } =20 -/* Get the content of a spte located in @base_addr[@index] */ -static uint64_t vtd_get_slpte(dma_addr_t base_addr, uint32_t index) +/* Get the content of a pte located in @base_addr[@index] */ +static uint64_t vtd_get_pte(dma_addr_t base_addr, uint32_t index) { - uint64_t slpte; + uint64_t pte; =20 - assert(index < VTD_SL_PT_ENTRY_NR); + assert(index < VTD_PT_ENTRY_NR); =20 if (dma_memory_read(&address_space_memory, - base_addr + index * sizeof(slpte), - &slpte, sizeof(slpte), MEMTXATTRS_UNSPECIFIED)) { - slpte =3D (uint64_t)-1; - return slpte; + base_addr + index * sizeof(pte), + &pte, sizeof(pte), MEMTXATTRS_UNSPECIFIED)) { + pte =3D (uint64_t)-1; + return pte; } - slpte =3D le64_to_cpu(slpte); - return slpte; + pte =3D le64_to_cpu(pte); + return pte; } =20 /* Given an iova and the level of paging structure, return the offset @@ -743,12 +744,12 @@ static uint64_t vtd_get_slpte(dma_addr_t base_addr, u= int32_t index) */ static inline uint32_t vtd_iova_level_offset(uint64_t iova, uint32_t level) { - return (iova >> vtd_slpt_level_shift(level)) & - ((1ULL << VTD_SL_LEVEL_BITS) - 1); + return (iova >> vtd_pt_level_shift(level)) & + ((1ULL << VTD_LEVEL_BITS) - 1); } =20 /* Check Capability Register to see if the @level of page-table is support= ed */ -static inline bool vtd_is_level_supported(IntelIOMMUState *s, uint32_t lev= el) +static inline bool vtd_is_sl_level_supported(IntelIOMMUState *s, uint32_t = level) { return VTD_CAP_SAGAW_MASK & s->cap & (1ULL << (level - 2 + VTD_CAP_SAGAW_SHIFT)); @@ -833,7 +834,7 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSta= te *s, =20 pgtt =3D VTD_PE_GET_TYPE(pe); if (pgtt =3D=3D VTD_SM_PASID_ENTRY_SLT && - !vtd_is_level_supported(s, VTD_PE_GET_LEVEL(pe))) { + !vtd_is_sl_level_supported(s, VTD_PE_GET_SL_LEVEL(pe))) { return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 @@ -972,7 +973,7 @@ static uint32_t vtd_get_iova_level(IntelIOMMUState *s, =20 if (s->root_scalable) { vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); - return VTD_PE_GET_LEVEL(&pe); + return VTD_PE_GET_SL_LEVEL(&pe); } =20 return vtd_ce_get_level(ce); @@ -1040,9 +1041,9 @@ static inline uint64_t vtd_iova_limit(IntelIOMMUState= *s, } =20 /* Return true if IOVA passes range check, otherwise false. */ -static inline bool vtd_iova_range_check(IntelIOMMUState *s, - uint64_t iova, VTDContextEntry *ce, - uint8_t aw, uint32_t pasid) +static inline bool vtd_iova_sl_range_check(IntelIOMMUState *s, + uint64_t iova, VTDContextEntry = *ce, + uint8_t aw, uint32_t pasid) { /* * Check if @iova is above 2^X-1, where X is the minimum of MGAW @@ -1083,17 +1084,17 @@ static bool vtd_slpte_nonzero_rsvd(uint64_t slpte, = uint32_t level) =20 /* * We should have caught a guest-mis-programmed level earlier, - * via vtd_is_level_supported. + * via vtd_is_sl_level_supported. */ assert(level < VTD_SPTE_RSVD_LEN); /* - * Zero level doesn't exist. The smallest level is VTD_SL_PT_LEVEL=3D1= and - * checked by vtd_is_last_slpte(). + * Zero level doesn't exist. The smallest level is VTD_PT_LEVEL=3D1 and + * checked by vtd_is_last_pte(). */ assert(level); =20 - if ((level =3D=3D VTD_SL_PD_LEVEL || level =3D=3D VTD_SL_PDP_LEVEL) && - (slpte & VTD_SL_PT_PAGE_SIZE_MASK)) { + if ((level =3D=3D VTD_PD_LEVEL || level =3D=3D VTD_PDP_LEVEL) && + (slpte & VTD_PT_PAGE_SIZE_MASK)) { /* large page */ rsvd_mask =3D vtd_spte_rsvd_large[level]; } else { @@ -1119,7 +1120,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDC= ontextEntry *ce, uint64_t access_right_check; uint64_t xlat, size; =20 - if (!vtd_iova_range_check(s, iova, ce, aw_bits, pasid)) { + if (!vtd_iova_sl_range_check(s, iova, ce, aw_bits, pasid)) { error_report_once("%s: detected IOVA overflow (iova=3D0x%" PRIx64 = "," "pasid=3D0x%" PRIx32 ")", __func__, iova, pasid); return -VTD_FR_ADDR_BEYOND_MGAW; @@ -1130,7 +1131,7 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VTDC= ontextEntry *ce, =20 while (true) { offset =3D vtd_iova_level_offset(iova, level); - slpte =3D vtd_get_slpte(addr, offset); + slpte =3D vtd_get_pte(addr, offset); =20 if (slpte =3D=3D (uint64_t)-1) { error_report_once("%s: detected read error on DMAR slpte " @@ -1161,17 +1162,17 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VT= DContextEntry *ce, return -VTD_FR_PAGING_ENTRY_RSVD; } =20 - if (vtd_is_last_slpte(slpte, level)) { + if (vtd_is_last_pte(slpte, level)) { *slptep =3D slpte; *slpte_level =3D level; break; } - addr =3D vtd_get_slpte_addr(slpte, aw_bits); + addr =3D vtd_get_pte_addr(slpte, aw_bits); level--; } =20 - xlat =3D vtd_get_slpte_addr(*slptep, aw_bits); - size =3D ~vtd_slpt_level_page_mask(level) + 1; + xlat =3D vtd_get_pte_addr(*slptep, aw_bits); + size =3D ~vtd_pt_level_page_mask(level) + 1; =20 /* * From VT-d spec 3.14: Untranslated requests and translation @@ -1322,14 +1323,14 @@ static int vtd_page_walk_level(dma_addr_t addr, uin= t64_t start, =20 trace_vtd_page_walk_level(addr, level, start, end); =20 - subpage_size =3D 1ULL << vtd_slpt_level_shift(level); - subpage_mask =3D vtd_slpt_level_page_mask(level); + subpage_size =3D 1ULL << vtd_pt_level_shift(level); + subpage_mask =3D vtd_pt_level_page_mask(level); =20 while (iova < end) { iova_next =3D (iova & subpage_mask) + subpage_size; =20 offset =3D vtd_iova_level_offset(iova, level); - slpte =3D vtd_get_slpte(addr, offset); + slpte =3D vtd_get_pte(addr, offset); =20 if (slpte =3D=3D (uint64_t)-1) { trace_vtd_page_walk_skip_read(iova, iova_next); @@ -1352,12 +1353,12 @@ static int vtd_page_walk_level(dma_addr_t addr, uin= t64_t start, */ entry_valid =3D read_cur | write_cur; =20 - if (!vtd_is_last_slpte(slpte, level) && entry_valid) { + if (!vtd_is_last_pte(slpte, level) && entry_valid) { /* * This is a valid PDE (or even bigger than PDE). We need * to walk one further level. */ - ret =3D vtd_page_walk_level(vtd_get_slpte_addr(slpte, info->aw= ), + ret =3D vtd_page_walk_level(vtd_get_pte_addr(slpte, info->aw), iova, MIN(iova_next, end), level - 1, read_cur, write_cur, info); } else { @@ -1374,7 +1375,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint6= 4_t start, event.entry.perm =3D IOMMU_ACCESS_FLAG(read_cur, write_cur); event.entry.addr_mask =3D ~subpage_mask; /* NOTE: this is only meaningful if entry_valid =3D=3D true */ - event.entry.translated_addr =3D vtd_get_slpte_addr(slpte, info= ->aw); + event.entry.translated_addr =3D vtd_get_pte_addr(slpte, info->= aw); event.type =3D event.entry.perm ? IOMMU_NOTIFIER_MAP : IOMMU_NOTIFIER_UNMAP; ret =3D vtd_page_walk_one(&event, info); @@ -1408,11 +1409,11 @@ static int vtd_page_walk(IntelIOMMUState *s, VTDCon= textEntry *ce, dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); uint32_t level =3D vtd_get_iova_level(s, ce, pasid); =20 - if (!vtd_iova_range_check(s, start, ce, info->aw, pasid)) { + if (!vtd_iova_sl_range_check(s, start, ce, info->aw, pasid)) { return -VTD_FR_ADDR_BEYOND_MGAW; } =20 - if (!vtd_iova_range_check(s, end, ce, info->aw, pasid)) { + if (!vtd_iova_sl_range_check(s, end, ce, info->aw, pasid)) { /* Fix end so that it reaches the maximum */ end =3D vtd_iova_limit(s, ce, info->aw, pasid); } @@ -1527,7 +1528,7 @@ static int vtd_dev_to_context_entry(IntelIOMMUState *= s, uint8_t bus_num, =20 /* Check if the programming of context-entry is valid */ if (!s->root_scalable && - !vtd_is_level_supported(s, vtd_ce_get_level(ce))) { + !vtd_is_sl_level_supported(s, vtd_ce_get_level(ce))) { error_report_once("%s: invalid context entry: hi=3D%"PRIx64 ", lo=3D%"PRIx64" (level %d not supported)", __func__, ce->hi, ce->lo, @@ -1897,7 +1898,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, VTDContextEntry ce; uint8_t bus_num =3D pci_bus_num(bus); VTDContextCacheEntry *cc_entry; - uint64_t slpte, page_mask; + uint64_t pte, page_mask; uint32_t level, pasid =3D vtd_as->pasid; uint16_t source_id =3D PCI_BUILD_BDF(bus_num, devfn); int ret_fr; @@ -1918,13 +1919,13 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, =20 cc_entry =3D &vtd_as->context_cache_entry; =20 - /* Try to fetch slpte form IOTLB, we don't need RID2PASID logic */ + /* Try to fetch pte form IOTLB, we don't need RID2PASID logic */ if (!rid2pasid) { iotlb_entry =3D vtd_lookup_iotlb(s, source_id, pasid, addr); if (iotlb_entry) { - trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->slpte, + trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->pte, iotlb_entry->domain_id); - slpte =3D iotlb_entry->slpte; + pte =3D iotlb_entry->pte; access_flags =3D iotlb_entry->access_flags; page_mask =3D iotlb_entry->mask; goto out; @@ -1996,20 +1997,20 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, return true; } =20 - /* Try to fetch slpte form IOTLB for RID2PASID slow path */ + /* Try to fetch pte form IOTLB for RID2PASID slow path */ if (rid2pasid) { iotlb_entry =3D vtd_lookup_iotlb(s, source_id, pasid, addr); if (iotlb_entry) { - trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->slpte, + trace_vtd_iotlb_page_hit(source_id, addr, iotlb_entry->pte, iotlb_entry->domain_id); - slpte =3D iotlb_entry->slpte; + pte =3D iotlb_entry->pte; access_flags =3D iotlb_entry->access_flags; page_mask =3D iotlb_entry->mask; goto out; } } =20 - ret_fr =3D vtd_iova_to_slpte(s, &ce, addr, is_write, &slpte, &level, + ret_fr =3D vtd_iova_to_slpte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); if (ret_fr) { vtd_report_fault(s, -ret_fr, is_fpd_set, source_id, @@ -2017,14 +2018,14 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, goto error; } =20 - page_mask =3D vtd_slpt_level_page_mask(level); + page_mask =3D vtd_pt_level_page_mask(level); access_flags =3D IOMMU_ACCESS_FLAG(reads, writes); vtd_update_iotlb(s, source_id, vtd_get_domain_id(s, &ce, pasid), - addr, slpte, access_flags, level, pasid); + addr, pte, access_flags, level, pasid); out: vtd_iommu_unlock(s); entry->iova =3D addr & page_mask; - entry->translated_addr =3D vtd_get_slpte_addr(slpte, s->aw_bits) & pag= e_mask; + entry->translated_addr =3D vtd_get_pte_addr(pte, s->aw_bits) & page_ma= sk; entry->addr_mask =3D ~page_mask; entry->perm =3D access_flags; return true; --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032507; cv=none; d=zohomail.com; s=zohoarc; b=KErNDSoLaXOe+Fw4z6zEDSdbGfjC3/QcdQnYO8m/6ej1uBEEr4HwuNSKgbJaHF0uDBUw7NtAby5yhBTnE0/nxVDIXREuesHsObWD28QTsRLR8DZ7KOkD/u9BraKvPWzD8xeTd3RNH0lve21oe4er2sePaDTv/95aMEErfoAvsEs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032507; 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=9qtZmGsoUKzgpOKePWg86hAAnWDuxXnHtaXvHry5VKA=; b=OxcUyzv4KPL3i+OmgQe/QULdzbuw6J6yjtEj19y0teOfXG7/8algCglKugnQ0MvrqFXEVNHXot6sENR2d++yP5zF8wN51rXIvgy2ACTLuvBCiDG203Gj98xlEdJEyx0o3Nl0FONE1t5RjhYTaoiY1x6FjjraMVaJkv94yZXDSQU= 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 1726032507145902.8243629199627; Tue, 10 Sep 2024 22:28:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFs0-0002CP-FF; Wed, 11 Sep 2024 01:26:24 -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 1soFrz-0002Bc-BW for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:23 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFrx-0004Mp-8J for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:23 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:21 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032381; x=1757568381; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zGO3E2RHkJTu1LpuFC+aHQvPLyEXDeX5DBwZcDcQgTg=; b=P+9XZEJEC4Qm89ouJm8DX0pUWlf+Npu/5ZB3ukoUejQ0Zp32yvNi38E2 cZfmg2PMsG8MtY7xyS5uI1nlgvC25NjvI2+CfjkX5ad5nU7OQWJnErtfQ 3xY8RFuRreRkmkvY/DJGPgu1vnw/DN7/QJEt5YjJfpq4A4x4CzrPdtwBI zUrbBILUbRYJscBBZWwuqGpF82dzhzKKgiTI8G0vaHge0r5Zxugp9JooD vKnQZU4SOHD/sNyxoMQUhMfrCIta2gzJr3KXO/XNfEnPkcGgA9QuoPmEj QmGxAbfKLxw6RFzcEp4gVbK2Y2ByrAh5locGg7wwLOq2lagpSoKbsnHjB Q==; X-CSE-ConnectionGUID: ecta29tBT4+tS6vWU7+Gew== X-CSE-MsgGUID: Vzxg9wPzRYGD7Rx22DZAnw== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403526" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403526" X-CSE-ConnectionGUID: lpxZ7I8EQA+MHN8NIs0iLA== X-CSE-MsgGUID: 8VjwMS4wQfWkqEX0kYNIpg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536443" 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 v3 06/17] intel_iommu: Implement stage-1 translation Date: Wed, 11 Sep 2024 13:22:44 +0800 Message-Id: <20240911052255.1294071-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032508975116600 From: Yi Liu This adds stage-1 page table walking to support stage-1 only transltion in scalable modern mode. Signed-off-by: Yi Liu Co-developed-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Acked-by: Jason Wang --- hw/i386/intel_iommu_internal.h | 23 ++++++ hw/i386/intel_iommu.c | 146 ++++++++++++++++++++++++++++++++- 2 files changed, 165 insertions(+), 4 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 1fa4add9e2..51e9b1fc43 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -433,6 +433,21 @@ typedef union VTDInvDesc VTDInvDesc; (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM | VTD_SL_TM))= : \ (0x3ffff800ULL | ~(VTD_HAW_MASK(aw) | VTD_SL_IGN_COM)) =20 +/* Rsvd field masks for fpte */ +#define VTD_FS_UPPER_IGNORED 0xfff0000000000000ULL +#define VTD_FPTE_PAGE_L1_RSVD_MASK(aw) \ + (~(VTD_HAW_MASK(aw) | VTD_FS_UPPER_IGNORED)) +#define VTD_FPTE_PAGE_L2_RSVD_MASK(aw) \ + (~(VTD_HAW_MASK(aw) | VTD_FS_UPPER_IGNORED)) +#define VTD_FPTE_PAGE_L3_RSVD_MASK(aw) \ + (~(VTD_HAW_MASK(aw) | VTD_FS_UPPER_IGNORED)) +#define VTD_FPTE_PAGE_L3_FS1GP_RSVD_MASK(aw) \ + (0x3fffe000ULL | ~(VTD_HAW_MASK(aw) | VTD_FS_UPPER_IGNORED)) +#define VTD_FPTE_PAGE_L2_FS2MP_RSVD_MASK(aw) \ + (0x1fe000ULL | ~(VTD_HAW_MASK(aw) | VTD_FS_UPPER_IGNORED)) +#define VTD_FPTE_PAGE_L4_RSVD_MASK(aw) \ + (0x80ULL | ~(VTD_HAW_MASK(aw) | VTD_FS_UPPER_IGNORED)) + /* Masks for PIOTLB Invalidate Descriptor */ #define VTD_INV_DESC_PIOTLB_G (3ULL << 4) #define VTD_INV_DESC_PIOTLB_ALL_IN_PASID (2ULL << 4) @@ -525,6 +540,14 @@ typedef struct VTDRootEntry VTDRootEntry; #define VTD_SM_PASID_ENTRY_AW 7ULL /* Adjusted guest-address-widt= h */ #define VTD_SM_PASID_ENTRY_DID(val) ((val) & VTD_DOMAIN_ID_MASK) =20 +#define VTD_SM_PASID_ENTRY_FLPM 3ULL +#define VTD_SM_PASID_ENTRY_FLPTPTR (~0xfffULL) + +/* First Level Paging Structure */ +/* Masks for First Level Paging Entry */ +#define VTD_FL_P 1ULL +#define VTD_FL_RW_MASK (1ULL << 1) + /* Second Level Page Translation Pointer*/ #define VTD_SM_PASID_ENTRY_SLPTPTR (~0xfffULL) =20 diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index a22bd43b98..6e31a8d383 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -48,6 +48,8 @@ =20 /* pe operations */ #define VTD_PE_GET_TYPE(pe) ((pe)->val[0] & VTD_SM_PASID_ENTRY_PGTT) +#define VTD_PE_GET_FL_LEVEL(pe) \ + (4 + (((pe)->val[2] >> 2) & VTD_SM_PASID_ENTRY_FLPM)) #define VTD_PE_GET_SL_LEVEL(pe) \ (2 + (((pe)->val[0] >> 2) & VTD_SM_PASID_ENTRY_AW)) =20 @@ -755,6 +757,11 @@ static inline bool vtd_is_sl_level_supported(IntelIOMM= UState *s, uint32_t level) (1ULL << (level - 2 + VTD_CAP_SAGAW_SHIFT)); } =20 +static inline bool vtd_is_fl_level_supported(IntelIOMMUState *s, uint32_t = level) +{ + return level =3D=3D VTD_PML4_LEVEL; +} + /* Return true if check passed, otherwise false */ static inline bool vtd_pe_type_check(X86IOMMUState *x86_iommu, VTDPASIDEntry *pe) @@ -838,6 +845,11 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSt= ate *s, return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 + if (pgtt =3D=3D VTD_SM_PASID_ENTRY_FLT && + !vtd_is_fl_level_supported(s, VTD_PE_GET_FL_LEVEL(pe))) { + return -VTD_FR_PASID_TABLE_ENTRY_INV; + } + return 0; } =20 @@ -973,7 +985,11 @@ static uint32_t vtd_get_iova_level(IntelIOMMUState *s, =20 if (s->root_scalable) { vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); - return VTD_PE_GET_SL_LEVEL(&pe); + if (s->scalable_modern) { + return VTD_PE_GET_FL_LEVEL(&pe); + } else { + return VTD_PE_GET_SL_LEVEL(&pe); + } } =20 return vtd_ce_get_level(ce); @@ -1060,7 +1076,11 @@ static dma_addr_t vtd_get_iova_pgtbl_base(IntelIOMMU= State *s, =20 if (s->root_scalable) { vtd_ce_get_rid2pasid_entry(s, ce, &pe, pasid); - return pe.val[0] & VTD_SM_PASID_ENTRY_SLPTPTR; + if (s->scalable_modern) { + return pe.val[2] & VTD_SM_PASID_ENTRY_FLPTPTR; + } else { + return pe.val[0] & VTD_SM_PASID_ENTRY_SLPTPTR; + } } =20 return vtd_ce_get_slpt_base(ce); @@ -1862,6 +1882,104 @@ out: trace_vtd_pt_enable_fast_path(source_id, success); } =20 +/* + * Rsvd field masks for fpte: + * vtd_fpte_rsvd 4k pages + * vtd_fpte_rsvd_large large pages + * + * We support only 4-level page tables. + */ +#define VTD_FPTE_RSVD_LEN 5 +static uint64_t vtd_fpte_rsvd[VTD_FPTE_RSVD_LEN]; +static uint64_t vtd_fpte_rsvd_large[VTD_FPTE_RSVD_LEN]; + +static bool vtd_flpte_nonzero_rsvd(uint64_t flpte, uint32_t level) +{ + uint64_t rsvd_mask; + + /* + * We should have caught a guest-mis-programmed level earlier, + * via vtd_is_fl_level_supported. + */ + assert(level < VTD_SPTE_RSVD_LEN); + /* + * Zero level doesn't exist. The smallest level is VTD_PT_LEVEL=3D1 and + * checked by vtd_is_last_pte(). + */ + assert(level); + + if ((level =3D=3D VTD_PD_LEVEL || level =3D=3D VTD_PDP_LEVEL) && + (flpte & VTD_PT_PAGE_SIZE_MASK)) { + /* large page */ + rsvd_mask =3D vtd_fpte_rsvd_large[level]; + } else { + rsvd_mask =3D vtd_fpte_rsvd[level]; + } + + return flpte & rsvd_mask; +} + +static inline bool vtd_flpte_present(uint64_t flpte) +{ + return !!(flpte & VTD_FL_P); +} + +/* + * Given the @iova, get relevant @flptep. @flpte_level will be the last le= vel + * of the translation, can be used for deciding the size of large page. + */ +static int vtd_iova_to_flpte(IntelIOMMUState *s, VTDContextEntry *ce, + uint64_t iova, bool is_write, + uint64_t *flptep, uint32_t *flpte_level, + bool *reads, bool *writes, uint8_t aw_bits, + uint32_t pasid) +{ + dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); + uint32_t level =3D vtd_get_iova_level(s, ce, pasid); + uint32_t offset; + uint64_t flpte; + + while (true) { + offset =3D vtd_iova_level_offset(iova, level); + flpte =3D vtd_get_pte(addr, offset); + + if (flpte =3D=3D (uint64_t)-1) { + if (level =3D=3D vtd_get_iova_level(s, ce, pasid)) { + /* Invalid programming of context-entry */ + return -VTD_FR_CONTEXT_ENTRY_INV; + } else { + return -VTD_FR_PAGING_ENTRY_INV; + } + } + if (!vtd_flpte_present(flpte)) { + *reads =3D false; + *writes =3D false; + return -VTD_FR_PAGING_ENTRY_INV; + } + *reads =3D true; + *writes =3D (*writes) && (flpte & VTD_FL_RW_MASK); + if (is_write && !(flpte & VTD_FL_RW_MASK)) { + return -VTD_FR_WRITE; + } + if (vtd_flpte_nonzero_rsvd(flpte, level)) { + error_report_once("%s: detected flpte reserved non-zero " + "iova=3D0x%" PRIx64 ", level=3D0x%" PRIx32 + "flpte=3D0x%" PRIx64 ", pasid=3D0x%" PRIX32 = ")", + __func__, iova, level, flpte, pasid); + return -VTD_FR_PAGING_ENTRY_RSVD; + } + + if (vtd_is_last_pte(flpte, level)) { + *flptep =3D flpte; + *flpte_level =3D level; + return 0; + } + + addr =3D vtd_get_pte_addr(flpte, aw_bits); + level--; + } +} + static void vtd_report_fault(IntelIOMMUState *s, int err, bool is_fpd_set, uint16_t source_id, @@ -2010,8 +2128,13 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *= vtd_as, PCIBus *bus, } } =20 - ret_fr =3D vtd_iova_to_slpte(s, &ce, addr, is_write, &pte, &level, - &reads, &writes, s->aw_bits, pasid); + if (s->scalable_modern && s->root_scalable) { + ret_fr =3D vtd_iova_to_flpte(s, &ce, addr, is_write, &pte, &level, + &reads, &writes, s->aw_bits, pasid); + } else { + ret_fr =3D vtd_iova_to_slpte(s, &ce, addr, is_write, &pte, &level, + &reads, &writes, s->aw_bits, pasid); + } if (ret_fr) { vtd_report_fault(s, -ret_fr, is_fpd_set, source_id, addr, is_write, pasid !=3D PCI_NO_PASID, pasid); @@ -4239,6 +4362,21 @@ static void vtd_init(IntelIOMMUState *s) vtd_spte_rsvd_large[3] =3D VTD_SPTE_LPAGE_L3_RSVD_MASK(s->aw_bits, x86_iommu->dt_supporte= d); =20 + /* + * Rsvd field masks for fpte + */ + vtd_fpte_rsvd[0] =3D ~0ULL; + vtd_fpte_rsvd[1] =3D VTD_FPTE_PAGE_L1_RSVD_MASK(s->aw_bits); + vtd_fpte_rsvd[2] =3D VTD_FPTE_PAGE_L2_RSVD_MASK(s->aw_bits); + vtd_fpte_rsvd[3] =3D VTD_FPTE_PAGE_L3_RSVD_MASK(s->aw_bits); + vtd_fpte_rsvd[4] =3D VTD_FPTE_PAGE_L4_RSVD_MASK(s->aw_bits); + + vtd_fpte_rsvd_large[0] =3D ~0ULL; + vtd_fpte_rsvd_large[1] =3D ~0ULL; + vtd_fpte_rsvd_large[2] =3D VTD_FPTE_PAGE_L2_FS2MP_RSVD_MASK(s->aw_bits= ); + vtd_fpte_rsvd_large[3] =3D VTD_FPTE_PAGE_L3_FS1GP_RSVD_MASK(s->aw_bits= ); + vtd_fpte_rsvd_large[4] =3D ~0ULL; + if (s->scalable_mode || s->snoop_control) { vtd_spte_rsvd[1] &=3D ~VTD_SPTE_SNP; vtd_spte_rsvd_large[2] &=3D ~VTD_SPTE_SNP; --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032456; cv=none; d=zohomail.com; s=zohoarc; b=C70iWNbicbCtt3VKrhaPtlQ3QoGzs3sX6kjBzcq0VDTQr4WuNoytgSevMmAxXaSfmOqxtVMfhChxxp5OAqhmMi4FYH8Gg7BY4pFGEYuBt21T2NNXAcqcGDnzNrTdONu+TEUn3EFtgJH25grTHUfAayhFSkhizwWMUvt2GsG9A3c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032456; 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=mUvROqwTc3xxp+nFQbrIh4o3oWtgn+rpw3ru2uuflog=; b=QrwdUsV+fgE4j/mZOxn/OqV8d2gqSTUV5Jzlm730W3REvGtKMlKf7d8NA87J5JP+WFS4+xFrwDnh/iGvh/o1IOj3aMfCZbmAGeTJwE99S6sHLNrkiazp1/c0AgXjx8nx6u6x9f15CJsbr+s0TccyLoFrzNWabpuxU2flSek0ozs= 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 1726032456369153.49890539829983; Tue, 10 Sep 2024 22:27:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFs6-0002N4-1e; Wed, 11 Sep 2024 01:26:30 -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 1soFs3-0002Ls-TF for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:27 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFs2-0004Mp-6k for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:27 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:25 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:21 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032386; x=1757568386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=yqWqyth2P/d3i3FGK/vIH9NaHNh3ZvisTnQJSetWMNY=; b=jVw6KgDodf34ytw+040CUWcHc2tZZo5GLL1amOMsJQY1j8jlGzBs80f2 oGdZT6I29v8qMCLh/qYpMgFMMf7WeYlE3lXUeYpvTtfacTMKh6OBg8TvR 8PyLOjmvKe+42UOybfNcI+9jQFTyFaMBJ/+slk5bpvEWrC67AqLtk1irf AQBeODB8mDclHyFzvIBbeHttRYQerHr8r6BG/M9A3DUFfZzAmSbasCJ+G yaXoJbEQ0aKRcn8NW14/3iB19AX4/xUOeoyuc8owPxXdIUPT7+QKOyuQk 9zj7NVGsJzEafld1rwAgQ0NT8rVGld8jIzNj8Xnoe3b4YHbUwr9c50xvW Q==; X-CSE-ConnectionGUID: Sc1jmhrKTtOMfJiGuLgSXA== X-CSE-MsgGUID: 5s1de0RRTLKPOsunCEQ8Vw== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403537" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403537" X-CSE-ConnectionGUID: oXRRSOrYT9qyWBD6rZl1iA== X-CSE-MsgGUID: 0U8jvKd3Sb+Loa/IcKN2NA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536453" 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 v3 07/17] intel_iommu: Check if the input address is canonical Date: Wed, 11 Sep 2024 13:22:45 +0800 Message-Id: <20240911052255.1294071-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032456603116600 From: Cl=C3=A9ment Mathieu--Drif First stage translation must fail if the address to translate is not canonical. Signed-off-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Zhenzhong Duan Acked-by: Jason Wang --- hw/i386/intel_iommu_internal.h | 2 ++ hw/i386/intel_iommu.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 51e9b1fc43..668583aeca 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -320,6 +320,8 @@ typedef enum VTDFaultReason { VTD_FR_PASID_ENTRY_P =3D 0x59, VTD_FR_PASID_TABLE_ENTRY_INV =3D 0x5b, /*Invalid PASID table entry */ =20 + VTD_FR_FS_NON_CANONICAL =3D 0x80, /* SNG.1 : Address for FS not canoni= cal.*/ + /* Output address in the interrupt address range for scalable mode */ VTD_FR_SM_INTERRUPT_ADDR =3D 0x87, VTD_FR_MAX, /* Guard */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 6e31a8d383..be73366a64 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1821,6 +1821,7 @@ static const bool vtd_qualified_faults[] =3D { [VTD_FR_PASID_ENTRY_P] =3D true, [VTD_FR_PASID_TABLE_ENTRY_INV] =3D true, [VTD_FR_SM_INTERRUPT_ADDR] =3D true, + [VTD_FR_FS_NON_CANONICAL] =3D true, [VTD_FR_MAX] =3D false, }; =20 @@ -1924,6 +1925,22 @@ static inline bool vtd_flpte_present(uint64_t flpte) return !!(flpte & VTD_FL_P); } =20 +/* Return true if IOVA is canonical, otherwise false. */ +static bool vtd_iova_fl_check_canonical(IntelIOMMUState *s, uint64_t iova, + VTDContextEntry *ce, uint32_t pasi= d) +{ + uint64_t iova_limit =3D vtd_iova_limit(s, ce, s->aw_bits, pasid); + uint64_t upper_bits_mask =3D ~(iova_limit - 1); + uint64_t upper_bits =3D iova & upper_bits_mask; + bool msb =3D ((iova & (iova_limit >> 1)) !=3D 0); + + if (msb) { + return upper_bits =3D=3D upper_bits_mask; + } else { + return !upper_bits; + } +} + /* * Given the @iova, get relevant @flptep. @flpte_level will be the last le= vel * of the translation, can be used for deciding the size of large page. @@ -1939,6 +1956,12 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VTD= ContextEntry *ce, uint32_t offset; uint64_t flpte; =20 + if (!vtd_iova_fl_check_canonical(s, iova, ce, pasid)) { + error_report_once("%s: detected non canonical IOVA (iova=3D0x%" PR= Ix64 "," + "pasid=3D0x%" PRIx32 ")", __func__, iova, pasid); + return -VTD_FR_FS_NON_CANONICAL; + } + while (true) { offset =3D vtd_iova_level_offset(iova, level); flpte =3D vtd_get_pte(addr, offset); --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032500; cv=none; d=zohomail.com; s=zohoarc; b=OMKMyNldBUe5IZ/Q036r1xA2Y0WRfD6iYRNIKM37oxR9Ck0TsKvwCRTVrLL9QVyB/zRPbnvSLgNHbOP3mLOhnILucvDHjFg6Z1KIYc+ZdVpK0AzVbaGB6ea9ACeJnbqgcdCXuxwXiUDm83R8gN9IDPN8qM1xAIAn56gXvxcMB+8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032500; 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=OUE2TfxVhkVEoYKbFwqgf/LbbnSn2fqpbqTcmQ3GInY=; b=b//fVIszXjeZWvTT9GmOsMxGHH63phGq90FPXJWjOjAUVnHHMaf8CoNqftBaidej+kl9YObBVaEED6rTnO7Qk7NvMN3ayo9kHF4Q1SSp6PUPhKXDYD9kWmW0JztJ5syQ5AZXR9IIQGejiklERH57FwNnu8ZcqjBywnyjiCoF+Sw= 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 1726032500647338.32214179920254; Tue, 10 Sep 2024 22:28:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsA-0002X1-Th; Wed, 11 Sep 2024 01:26:34 -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 1soFs8-0002Vi-K8 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:32 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFs6-0004Mp-TQ for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:32 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:30 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:26 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032391; x=1757568391; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VJoRqi++1b3GuZESXgIRFQvtM0ZQW+aZDdqkIgNfyY8=; b=kR0dKmC1UZivp2PhazFxOFAIM3p5U7PkklaqTv9IYXjkSk18BjZzx93y AuOinDjuQ1yAx66ZJJvT7pmMXHCwaD5UjDJthCbCV70IPfTn5M2+gUdeq QvrZL8n/FX7sy4rYMoe+LTvPvWnDpsROh9fw3ra9udJSZX78lRoqGvIbb 5uBYHYx8XEycq934mWUV5c1s87Mz9JZ/3/uutaLc55xGyC8+UCMYVVNQR 6AWgRUFbKVhcu9LOZCLxkYuGdtL98vUc7xTo7svUq89duJprFKCTRAgSm P9FQFRIvHdnJJ5hzPYy4jCIc5fbR4q29GEor3ElIbCXDMKfKvNmyhmGwo g==; X-CSE-ConnectionGUID: LyMVU2CET921tVZK7n4QOA== X-CSE-MsgGUID: iwV0J8MbQz2+N2FV440olg== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403551" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403551" X-CSE-ConnectionGUID: bM1DBTJOQYi+FWXU99n8Ew== X-CSE-MsgGUID: cXNaAeeZSi2jTh7Rr1uevA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536465" 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 v3 08/17] intel_iommu: Set accessed and dirty bits during first stage translation Date: Wed, 11 Sep 2024 13:22:46 +0800 Message-Id: <20240911052255.1294071-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032502825116600 From: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Zhenzhong Duan Acked-by: Jason Wang --- hw/i386/intel_iommu_internal.h | 3 +++ hw/i386/intel_iommu.c | 25 ++++++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 668583aeca..7786ef7624 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -324,6 +324,7 @@ typedef enum VTDFaultReason { =20 /* Output address in the interrupt address range for scalable mode */ VTD_FR_SM_INTERRUPT_ADDR =3D 0x87, + VTD_FR_FS_BIT_UPDATE_FAILED =3D 0x91, /* SFS.10 */ VTD_FR_MAX, /* Guard */ } VTDFaultReason; =20 @@ -549,6 +550,8 @@ typedef struct VTDRootEntry VTDRootEntry; /* Masks for First Level Paging Entry */ #define VTD_FL_P 1ULL #define VTD_FL_RW_MASK (1ULL << 1) +#define VTD_FL_A 0x20 +#define VTD_FL_D 0x40 =20 /* Second Level Page Translation Pointer*/ #define VTD_SM_PASID_ENTRY_SLPTPTR (~0xfffULL) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index be73366a64..180505423d 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1822,6 +1822,7 @@ static const bool vtd_qualified_faults[] =3D { [VTD_FR_PASID_TABLE_ENTRY_INV] =3D true, [VTD_FR_SM_INTERRUPT_ADDR] =3D true, [VTD_FR_FS_NON_CANONICAL] =3D true, + [VTD_FR_FS_BIT_UPDATE_FAILED] =3D true, [VTD_FR_MAX] =3D false, }; =20 @@ -1941,6 +1942,20 @@ static bool vtd_iova_fl_check_canonical(IntelIOMMUSt= ate *s, uint64_t iova, } } =20 +static MemTxResult vtd_set_flag_in_pte(dma_addr_t base_addr, uint32_t inde= x, + uint64_t pte, uint64_t flag) +{ + if (pte & flag) { + return MEMTX_OK; + } + pte |=3D flag; + pte =3D cpu_to_le64(pte); + return dma_memory_write(&address_space_memory, + base_addr + index * sizeof(pte), + &pte, sizeof(pte), + MEMTXATTRS_UNSPECIFIED); +} + /* * Given the @iova, get relevant @flptep. @flpte_level will be the last le= vel * of the translation, can be used for deciding the size of large page. @@ -1954,7 +1969,7 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VTDC= ontextEntry *ce, dma_addr_t addr =3D vtd_get_iova_pgtbl_base(s, ce, pasid); uint32_t level =3D vtd_get_iova_level(s, ce, pasid); uint32_t offset; - uint64_t flpte; + uint64_t flpte, flag_ad =3D VTD_FL_A; =20 if (!vtd_iova_fl_check_canonical(s, iova, ce, pasid)) { error_report_once("%s: detected non canonical IOVA (iova=3D0x%" PR= Ix64 "," @@ -1992,6 +2007,14 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VTD= ContextEntry *ce, return -VTD_FR_PAGING_ENTRY_RSVD; } =20 + if (vtd_is_last_pte(flpte, level) && is_write) { + flag_ad |=3D VTD_FL_D; + } + + if (vtd_set_flag_in_pte(addr, offset, flpte, flag_ad) !=3D MEMTX_O= K) { + return -VTD_FR_FS_BIT_UPDATE_FAILED; + } + if (vtd_is_last_pte(flpte, level)) { *flptep =3D flpte; *flpte_level =3D level; --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032453; cv=none; d=zohomail.com; s=zohoarc; b=apjlloQCvL/MQXYnVz/GUDFlTkIra7wV1Emo5rlM1AhSKqnLbyRG3quiMC8pTUT2qpcBv91YXMNGOjw75UW9pLxkCiB/zE2O4O1zCYLFoALe029i6a1eMMZu2+GC7mAiYCFhu9LR8J0eRNlgE/BzrDWj2u/rodCkieAOeACJFnI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032453; 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=WcK9N4eeA7023Hvcsotzps9+RYIDj0Jy+CdZDFcK9rI=; b=Df1r15nRPWyFeFzrLSjuCqDPoeUYjIWvjPIy8EytV50eTO7ZOYfr+JiK2dNrM7lalOx4BAnh5tOVbXO5w2Fx8CpPZncMwCGzX83vYtL0zYC0VX3mh3UhT/XNqgMLZSXGeeaCgGkbOXCNXIougNEzeF+sG5128LYpDi9dzxA0voU= 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 1726032453536663.5859527913583; Tue, 10 Sep 2024 22:27:33 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsF-0002hV-IM; Wed, 11 Sep 2024 01:26: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 1soFsD-0002fn-I1 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:37 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFsB-0004Mp-Lk for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:37 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:35 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:30 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032396; x=1757568396; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OtJ7o24XryzSrhCXXdVqpmwCE7J6HUiCFhruUiS+HaQ=; b=hnW8v8lya7ZKOVGifJz91AtJpxbNmh7JrGUeLUJkocoTHrlndcL9H+CI /WWEFHQ87Y2csvnW3i4aT3nXP/aW5LLavXKtbqhkTWsk+QJCY2aJN2Ztb GjrfxiZWuyVV7mvGgVRzBmqBliztY2nFF1MypY6CmqEDImNWTICIpiWZD OwLDw8lFotAjUlr5CJOxfwNHtUGcG4jcUP6Gg1NkFFOIRbkkLYeym5MIB hEiiZUHG3SxsYpjWYKlQ7DA11AbCyd5++Tqeq3evmjQwZtHzRvlVYmYCA jH7RrxFl/pL/WWekrNnU+Lry2JxPCaerQtWHoRIl8BASX5gKwvNCCLHwy A==; X-CSE-ConnectionGUID: 1VETSzVmTKuMPFU9K2bkwQ== X-CSE-MsgGUID: AOL2138lS1ax5RV+Q9qT6w== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403561" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403561" X-CSE-ConnectionGUID: 21kXm/TwQ+ulWzB4yztH3A== X-CSE-MsgGUID: GOgI93cSQOqYsZDBOTcBKQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536473" 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 v3 09/17] intel_iommu: Flush stage-1 cache in iotlb invalidation Date: Wed, 11 Sep 2024 13:22:47 +0800 Message-Id: <20240911052255.1294071-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032454625116600 According to spec, Page-Selective-within-Domain Invalidation (11b): 1. IOTLB entries caching second-stage mappings (PGTT=3D010b) or pass-through (PGTT=3D100b) mappings associated with the specified domain-id and the input-address range are invalidated. 2. IOTLB entries caching first-stage (PGTT=3D001b) or nested (PGTT=3D011b) mapping associated with specified domain-id are invalidated. So per spec definition the Page-Selective-within-Domain Invalidation needs to flush first stage and nested cached IOTLB enties as well. We don't support nested yet and pass-through mapping is never cached, so what in iotlb cache are only first-stage and second-stage mappings. Add a tag pgtt in VTDIOTLBEntry to mark PGTT type of the mapping and invalidate entries based on PGTT type. Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif Acked-by: Jason Wang --- include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index fe9057c50d..b843d069cc 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -155,6 +155,7 @@ struct VTDIOTLBEntry { uint64_t pte; uint64_t mask; uint8_t access_flags; + uint8_t pgtt; }; =20 /* VT-d Source-ID Qualifier types */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 180505423d..0df3fe2b6f 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -305,9 +305,21 @@ static gboolean vtd_hash_remove_by_page(gpointer key, = gpointer value, VTDIOTLBPageInvInfo *info =3D (VTDIOTLBPageInvInfo *)user_data; uint64_t gfn =3D (info->addr >> VTD_PAGE_SHIFT_4K) & info->mask; uint64_t gfn_tlb =3D (info->addr & entry->mask) >> VTD_PAGE_SHIFT_4K; - return (entry->domain_id =3D=3D info->domain_id) && - (((entry->gfn & info->mask) =3D=3D gfn) || - (entry->gfn =3D=3D gfn_tlb)); + + if (entry->domain_id !=3D info->domain_id) { + return false; + } + + /* + * According to spec, IOTLB entries caching first-stage (PGTT=3D001b) = or + * nested (PGTT=3D011b) mapping associated with specified domain-id are + * invalidated. Nested isn't supported yet, so only need to check 001b. + */ + if (entry->pgtt =3D=3D VTD_SM_PASID_ENTRY_FLT) { + return true; + } + + return (entry->gfn & info->mask) =3D=3D gfn || entry->gfn =3D=3D gfn_t= lb; } =20 /* Reset all the gen of VTDAddressSpace to zero and set the gen of @@ -382,7 +394,7 @@ out: static void vtd_update_iotlb(IntelIOMMUState *s, uint16_t source_id, uint16_t domain_id, hwaddr addr, uint64_t pte, uint8_t access_flags, uint32_t level, - uint32_t pasid) + uint32_t pasid, uint8_t pgtt) { VTDIOTLBEntry *entry =3D g_malloc(sizeof(*entry)); struct vtd_iotlb_key *key =3D g_malloc(sizeof(*key)); @@ -400,6 +412,7 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16= _t source_id, entry->access_flags =3D access_flags; entry->mask =3D vtd_pt_level_page_mask(level); entry->pasid =3D pasid; + entry->pgtt =3D pgtt; =20 key->gfn =3D gfn; key->sid =3D source_id; @@ -2069,7 +2082,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, bool is_fpd_set =3D false; bool reads =3D true; bool writes =3D true; - uint8_t access_flags; + uint8_t access_flags, pgtt; bool rid2pasid =3D (pasid =3D=3D PCI_NO_PASID) && s->root_scalable; VTDIOTLBEntry *iotlb_entry; =20 @@ -2177,9 +2190,11 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *= vtd_as, PCIBus *bus, if (s->scalable_modern && s->root_scalable) { ret_fr =3D vtd_iova_to_flpte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); + pgtt =3D VTD_SM_PASID_ENTRY_FLT; } else { ret_fr =3D vtd_iova_to_slpte(s, &ce, addr, is_write, &pte, &level, &reads, &writes, s->aw_bits, pasid); + pgtt =3D VTD_SM_PASID_ENTRY_SLT; } if (ret_fr) { vtd_report_fault(s, -ret_fr, is_fpd_set, source_id, @@ -2190,7 +2205,7 @@ static bool vtd_do_iommu_translate(VTDAddressSpace *v= td_as, PCIBus *bus, page_mask =3D vtd_pt_level_page_mask(level); access_flags =3D IOMMU_ACCESS_FLAG(reads, writes); vtd_update_iotlb(s, source_id, vtd_get_domain_id(s, &ce, pasid), - addr, pte, access_flags, level, pasid); + addr, pte, access_flags, level, pasid, pgtt); out: vtd_iommu_unlock(s); entry->iova =3D addr & page_mask; --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032438; cv=none; d=zohomail.com; s=zohoarc; b=ivhIOxvcY347/eJpmXI58MmARCn6OQWljNrLBBlcFuU3d0EgiMCmRyNls1S89Nhy9QXe2vwCss8Ke+xxLjz2XClwd94S/BoQURXr0k6pskj6+xH+orCqKX8LS6XKGAyuxfIVDAUhDCidc1i9GqYEVTdH9u7IgSpFACfQixVBB9M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032438; 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=ZgJXUtXjSwV18fnYcfgfO7LW0SfUJ54P7wrbDILopBA=; b=PyC2cnwPrb1M4CMthSey82qRG6rkxpu512OyPT+a086ImuJTgdNI3/jvTnT7wn3sc2PXzqOGLu/NHpWsx77Jac76wq1wN2m/PfjDO8e0uopSVpWN6zPxj6DH6xJvay2y2rvi8GZ5cF0W0oIN1mugDYlaZowCOI0QATbgmZDyoyk= 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 1726032438649944.8312044100956; Tue, 10 Sep 2024 22:27:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsJ-00030U-TI; Wed, 11 Sep 2024 01:26:43 -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 1soFsI-0002sw-0h for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:42 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFsG-0004Mp-7y for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:41 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:40 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:35 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032400; x=1757568400; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=9Ufmy64my4HMiN1XkgIdfaz4/Nq6iwsGYwbWm6B0P4w=; b=nhX+oHYktIIrBhlIQ1PcuYlWV8MnUftboFVKxft2RuwSj1jnViHZr5MX i7aEVWmxJH6n0xWNFoOdWVfFoiv2+TJK4M116KgcFOr/PeV4TPbo76OCX DdoTJihtdfwdE7Uj1g4sEF6S7mCLgVaoMWLSmKDsxAwsHDo0xuLR0+LOl jsk+w+NmeH09pG0V+52zdu3dn7HGoOr3nMOPGYHIeUn5ceT76LTIj4PxD 1vYtwUjGlFpkcRTKzeXcDSmgJybjjPlm6PpjE1puVorv8QppnhyrXSlMR HDttAhKEVqvJ4PZg4pfaZJqJ/qaYsv87IkyE3Cq+PH5fIRhxFTluH+1j0 A==; X-CSE-ConnectionGUID: b25vehQ+Tw+pF9rlxSIr5g== X-CSE-MsgGUID: 8siLR6oxT1unDljHfqbFqQ== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403569" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403569" X-CSE-ConnectionGUID: E7DkF2ePSg6dDeX/eKIX/Q== X-CSE-MsgGUID: nZ2wuaeGT+6Y3hP6zpxa5w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536485" 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 v3 10/17] intel_iommu: Process PASID-based iotlb invalidation Date: Wed, 11 Sep 2024 13:22:48 +0800 Message-Id: <20240911052255.1294071-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032440605116600 PASID-based iotlb (piotlb) is used during walking Intel VT-d stage-1 page table. This emulates the stage-1 page table iotlb invalidation requested by a PASID-based IOTLB Invalidate Descriptor (P_IOTLB). Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif Acked-by: Jason Wang --- hw/i386/intel_iommu_internal.h | 3 +++ hw/i386/intel_iommu.c | 45 ++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 7786ef7624..4f2c3a9350 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -457,6 +457,9 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_PIOTLB_PSI_IN_PASID (3ULL << 4) #define VTD_INV_DESC_PIOTLB_DID(val) (((val) >> 16) & VTD_DOMAIN_ID_M= ASK) #define VTD_INV_DESC_PIOTLB_PASID(val) (((val) >> 32) & 0xfffffULL) +#define VTD_INV_DESC_PIOTLB_AM(val) ((val) & 0x3fULL) +#define VTD_INV_DESC_PIOTLB_IH(val) (((val) >> 6) & 0x1) +#define VTD_INV_DESC_PIOTLB_ADDR(val) ((val) & ~0xfffULL) #define VTD_INV_DESC_PIOTLB_RSVD_VAL0 0xfff000000000f1c0ULL #define VTD_INV_DESC_PIOTLB_RSVD_VAL1 0xf80ULL =20 diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 0df3fe2b6f..7ad49653f4 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -322,6 +322,28 @@ static gboolean vtd_hash_remove_by_page(gpointer key, = gpointer value, return (entry->gfn & info->mask) =3D=3D gfn || entry->gfn =3D=3D gfn_t= lb; } =20 +static gboolean vtd_hash_remove_by_page_piotlb(gpointer key, gpointer valu= e, + gpointer user_data) +{ + VTDIOTLBEntry *entry =3D (VTDIOTLBEntry *)value; + VTDIOTLBPageInvInfo *info =3D (VTDIOTLBPageInvInfo *)user_data; + uint64_t gfn =3D (info->addr >> VTD_PAGE_SHIFT_4K) & info->mask; + uint64_t gfn_tlb =3D (info->addr & entry->mask) >> VTD_PAGE_SHIFT_4K; + + /* + * According to spec, PASID-based-IOTLB Invalidation in page granulari= ty + * doesn't invalidate IOTLB entries caching second-stage (PGTT=3D010b) + * or pass-through (PGTT=3D100b) mappings. Nested isn't supported yet, + * so only need to check first-stage (PGTT=3D001b) mappings. + */ + if (entry->pgtt !=3D VTD_SM_PASID_ENTRY_FLT) { + return false; + } + + return entry->domain_id =3D=3D info->domain_id && entry->pasid =3D=3D = info->pasid && + ((entry->gfn & info->mask) =3D=3D gfn || entry->gfn =3D=3D gfn_= tlb); +} + /* Reset all the gen of VTDAddressSpace to zero and set the gen of * IntelIOMMUState to 1. Must be called with IOMMU lock held. */ @@ -2884,11 +2906,30 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUS= tate *s, } } =20 +static void vtd_piotlb_page_invalidate(IntelIOMMUState *s, uint16_t domain= _id, + uint32_t pasid, hwaddr addr, uint8_= t am, + bool ih) +{ + VTDIOTLBPageInvInfo info; + + info.domain_id =3D domain_id; + info.pasid =3D pasid; + info.addr =3D addr; + info.mask =3D ~((1 << am) - 1); + + vtd_iommu_lock(s); + g_hash_table_foreach_remove(s->iotlb, + vtd_hash_remove_by_page_piotlb, &info); + vtd_iommu_unlock(s); +} + static bool vtd_process_piotlb_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { uint16_t domain_id; uint32_t pasid; + uint8_t am; + hwaddr addr; =20 if ((inv_desc->val[0] & VTD_INV_DESC_PIOTLB_RSVD_VAL0) || (inv_desc->val[1] & VTD_INV_DESC_PIOTLB_RSVD_VAL1)) { @@ -2906,6 +2947,10 @@ static bool vtd_process_piotlb_desc(IntelIOMMUState = *s, break; =20 case VTD_INV_DESC_PIOTLB_PSI_IN_PASID: + am =3D VTD_INV_DESC_PIOTLB_AM(inv_desc->val[1]); + addr =3D (hwaddr) VTD_INV_DESC_PIOTLB_ADDR(inv_desc->val[1]); + vtd_piotlb_page_invalidate(s, domain_id, pasid, addr, am, + VTD_INV_DESC_PIOTLB_IH(inv_desc->val[1]= )); break; =20 default: --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032509; cv=none; d=zohomail.com; s=zohoarc; b=BS919On2GLUkh0JWaDGkUZxTuob/OQUu6ACiKj2aXc3QJlTF0BqMXGpcM65Ba/libfo2vBzSNxBij+lLyesv/Tth54PZkfU1ILGOvIfqi34T2VGlgQlROC9tdthndbdgEHA7txQ0E6fE8HorXKS4XoKCPSJAqP2iiGX05vF0IoY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032509; 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=hvjdojVNCWrqxNkFvlaRml2C7T2Hj4e56EEAQ+AWtKI=; b=E3ptMDYPvRK3frHl8hjWdjZU8WGi8Cl71KFgUBmda0KNvDeO70lb29w3MbQVclIhNWy2S+1PefVtDGyGHKuI7y2BW6S1ueaf1+P5kXgqq8owNiamDSrvWqjUq/ewwH89coUP2mDR2XhdQlcEg8Wk/I+vwJ6jNwffF3d4yqVd+/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 1726032509991986.6517543221632; Tue, 10 Sep 2024 22:28:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsO-0003KX-Qz; Wed, 11 Sep 2024 01:26:48 -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 1soFsN-0003Db-5W for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:47 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFsL-0004Mp-EK for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:46 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:45 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032406; x=1757568406; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p8EgXwJVLAcgbjmuT4yBh+MXq/IYSvDV2T8BDKbyEho=; b=Q7j1Daz7305Go2AuB0VaHOzNDOWiQApdSC/A6+nBPPI0L7/fnEze5jxY aOtz0nMODa1I6c2QDcAKOcouwNhEJYrFx5xYuSdw7ZASpW0bFGsyvHG21 tYiIjtSR79KFmemCUj2jJn2y6qJ0UpDv/ab2Hg9HTD5+nQ4lAoXwA+bJT GgDeVZJXwZDUfwSDqxNpH46ihskAdv+a24ihBDzdqBrmARR4cqMLsPfOB i1eKbP6jez4QXbWYJW/QzzGXmT7xRJhGyHBF7jWbjjU9ntJ4Qvn3sUy5B WRSZjfi+dNeSLfNDVPkQeOo73GbMiwyjl9gXPaZsTM7QcLvb60i1utAmU Q==; X-CSE-ConnectionGUID: h8ClOElFSqeSWLQ/YOCErA== X-CSE-MsgGUID: YxAVUza7QZi+0hDOb5zmgg== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403581" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403581" X-CSE-ConnectionGUID: pc5zZAixS4KiDDd8UnBG8w== X-CSE-MsgGUID: E4L+K9mtSbK38aNUtprTVQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536499" 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 , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH v3 11/17] intel_iommu: Add an internal API to find an address space with PASID Date: Wed, 11 Sep 2024 13:22:49 +0800 Message-Id: <20240911052255.1294071-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032510883116600 From: Cl=C3=A9ment Mathieu--Drif This will be used to implement the device IOTLB invalidation Signed-off-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Zhenzhong Duan Acked-by: Jason Wang --- hw/i386/intel_iommu.c | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 7ad49653f4..d28c862598 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -70,6 +70,11 @@ struct vtd_hiod_key { uint8_t devfn; }; =20 +struct vtd_as_raw_key { + uint16_t sid; + uint32_t pasid; +}; + struct vtd_iotlb_key { uint64_t gfn; uint32_t pasid; @@ -1875,29 +1880,33 @@ static inline bool vtd_is_interrupt_addr(hwaddr add= r) return VTD_INTERRUPT_ADDR_FIRST <=3D addr && addr <=3D VTD_INTERRUPT_A= DDR_LAST; } =20 -static gboolean vtd_find_as_by_sid(gpointer key, gpointer value, - gpointer user_data) +static gboolean vtd_find_as_by_sid_and_pasid(gpointer key, gpointer value, + gpointer user_data) { struct vtd_as_key *as_key =3D (struct vtd_as_key *)key; - uint16_t target_sid =3D *(uint16_t *)user_data; + struct vtd_as_raw_key target =3D *(struct vtd_as_raw_key *)user_data; uint16_t sid =3D PCI_BUILD_BDF(pci_bus_num(as_key->bus), as_key->devfn= ); - return sid =3D=3D target_sid; + + return (as_key->pasid =3D=3D target.pasid) && + (sid =3D=3D target.sid); } =20 -static VTDAddressSpace *vtd_get_as_by_sid(IntelIOMMUState *s, uint16_t sid) +static VTDAddressSpace *vtd_get_as_by_sid_and_pasid(IntelIOMMUState *s, + uint16_t sid, + uint32_t pasid) { - uint8_t bus_num =3D PCI_BUS_NUM(sid); - VTDAddressSpace *vtd_as =3D s->vtd_as_cache[bus_num]; - - if (vtd_as && - (sid =3D=3D PCI_BUILD_BDF(pci_bus_num(vtd_as->bus), vtd_as->devfn)= )) { - return vtd_as; - } + struct vtd_as_raw_key key =3D { + .sid =3D sid, + .pasid =3D pasid + }; =20 - vtd_as =3D g_hash_table_find(s->vtd_address_spaces, vtd_find_as_by_sid= , &sid); - s->vtd_as_cache[bus_num] =3D vtd_as; + return g_hash_table_find(s->vtd_address_spaces, + vtd_find_as_by_sid_and_pasid, &key); +} =20 - return vtd_as; +static VTDAddressSpace *vtd_get_as_by_sid(IntelIOMMUState *s, uint16_t sid) +{ + return vtd_get_as_by_sid_and_pasid(s, sid, PCI_NO_PASID); } =20 static void vtd_pt_enable_fast_path(IntelIOMMUState *s, uint16_t source_id) --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032460; cv=none; d=zohomail.com; s=zohoarc; b=kPt/V9Mo2ch9KkYsvyHMIPOy9yCCrlOLuheZH7/uSiNc85LA2CsSK//1ejz31UEbzUVTAfQjFfhvGCRXQ6lzUB/2le/N/gHKV632jeCCNUF4+87fv1jlUrDwRy/ZisSwUJfrS+E63vac6sDXWVcInvLGDud1Z/vMh/JoX7L9lm0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032460; 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=h0OIDmDA6eoYraeya/MukN8Ik5z3svyFXIgk0Rui87w=; b=Z/GTg9Nvu2iIBoDrUcxuW5iv6TRbvTrmrs8VPXKwZzi44//kAK3U4X9huifhgzfNArRD/aVpw2ngNCwI/ZHTzEM1K+lCmsrHeaQq/EZtRQoD5qvZlfEnP1dQGrDoojpj6o91CM6CAV6xFBp0LJRA32WeR+SJegQYfCKUQA/EPtE= 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 17260324606951005.2663840093; Tue, 10 Sep 2024 22:27:40 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsT-0003nb-PP; Wed, 11 Sep 2024 01:26:53 -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 1soFsS-0003ds-1A for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:52 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFsQ-0004Mp-63 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:51 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:50 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:45 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032410; x=1757568410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZwKp+8eHtxXPB4bOM2qK/aeQYA/KH0gqZOePfTEvkaQ=; b=nZB3pGTfDONywerjeN0Nr4ZXmRFAWWcQZUzCJVR+B//hNxhQSunyIIdg sxcTfWes7yAilHg0ihfmBf3A4qhrE67F/viHSXL/QRhSXNLIx8QGw+7XS DMgsXs9KEYvb75USz5SBFdoRL5TmDvW34HbwCaYBsxHViKxXkoas334kV jBa913lXhoEyX6oU+i5ClXMd9RvQnn4flR9cDwrQtVb5+xKrcFliiHAv0 HAK5d7EzcQS14PyQNYXV6p8mihtkJpxN+9uurXtOMmMtZuC0KIJqgQ1Ex rc43IxLwDk/pttqVLzfLAKXGrp5KYzeWEjn0JJPX0Y89oDG26RNsQpw1T g==; X-CSE-ConnectionGUID: qFpkx+cwThihmi51/hBCbQ== X-CSE-MsgGUID: nO/KdsUMTMOm1/dfW9hU0Q== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403596" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403596" X-CSE-ConnectionGUID: z0Xoax1LT32dbKs2oHuT3w== X-CSE-MsgGUID: 0a3R6sZYS9+URHIvux5f7A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536504" 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 v3 12/17] intel_iommu: Add support for PASID-based device IOTLB invalidation Date: Wed, 11 Sep 2024 13:22:50 +0800 Message-Id: <20240911052255.1294071-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032462603116600 From: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 11 ++++++++ hw/i386/intel_iommu.c | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 4f2c3a9350..52bdbf3bc5 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -375,6 +375,7 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_WAIT 0x5 /* Invalidation Wait Descripto= r */ #define VTD_INV_DESC_PIOTLB 0x6 /* PASID-IOTLB Invalidate Desc= */ #define VTD_INV_DESC_PC 0x7 /* PASID-cache Invalidate Desc= */ +#define VTD_INV_DESC_DEV_PIOTLB 0x8 /* PASID-based-DIOTLB inv_desc= */ #define VTD_INV_DESC_NONE 0 /* Not an Invalidate Descripto= r */ =20 /* Masks for Invalidation Wait Descriptor*/ @@ -413,6 +414,16 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_DEVICE_IOTLB_RSVD_HI 0xffeULL #define VTD_INV_DESC_DEVICE_IOTLB_RSVD_LO 0xffff0000ffe0fff8 =20 +/* Mask for PASID Device IOTLB Invalidate Descriptor */ +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_ADDR(val) ((val) & \ + 0xfffffffffffff000ULL) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_SIZE(val) ((val >> 11) & 0x1) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_GLOBAL(val) ((val) & 0x1) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_SID(val) (((val) >> 16) & 0xffffUL= L) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_PASID(val) ((val >> 32) & 0xfffffU= LL) +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_RSVD_HI 0x7feULL +#define VTD_INV_DESC_PASID_DEVICE_IOTLB_RSVD_LO 0xfff000000000f000ULL + /* Rsvd field masks for spte */ #define VTD_SPTE_SNP 0x800ULL =20 diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index d28c862598..4cf56924e1 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3017,6 +3017,49 @@ static void do_invalidate_device_tlb(VTDAddressSpace= *vtd_dev_as, memory_region_notify_iommu(&vtd_dev_as->iommu, 0, event); } =20 +static bool vtd_process_device_piotlb_desc(IntelIOMMUState *s, + VTDInvDesc *inv_desc) +{ + uint16_t sid; + VTDAddressSpace *vtd_dev_as; + bool size; + bool global; + hwaddr addr; + uint32_t pasid; + + if ((inv_desc->hi & VTD_INV_DESC_PASID_DEVICE_IOTLB_RSVD_HI) || + (inv_desc->lo & VTD_INV_DESC_PASID_DEVICE_IOTLB_RSVD_LO)) { + error_report_once("%s: invalid pasid-based dev iotlb inv desc:" + "hi=3D%"PRIx64 "(reserved nonzero)", + __func__, inv_desc->hi); + return false; + } + + global =3D VTD_INV_DESC_PASID_DEVICE_IOTLB_GLOBAL(inv_desc->hi); + size =3D VTD_INV_DESC_PASID_DEVICE_IOTLB_SIZE(inv_desc->hi); + addr =3D VTD_INV_DESC_PASID_DEVICE_IOTLB_ADDR(inv_desc->hi); + sid =3D VTD_INV_DESC_PASID_DEVICE_IOTLB_SID(inv_desc->lo); + if (global) { + QLIST_FOREACH(vtd_dev_as, &s->vtd_as_with_notifiers, next) { + if ((vtd_dev_as->pasid !=3D PCI_NO_PASID) && + (PCI_BUILD_BDF(pci_bus_num(vtd_dev_as->bus), + vtd_dev_as->devfn) =3D=3D sid))= { + do_invalidate_device_tlb(vtd_dev_as, size, addr); + } + } + } else { + pasid =3D VTD_INV_DESC_PASID_DEVICE_IOTLB_PASID(inv_desc->lo); + vtd_dev_as =3D vtd_get_as_by_sid_and_pasid(s, sid, pasid); + if (!vtd_dev_as) { + return true; + } + + do_invalidate_device_tlb(vtd_dev_as, size, addr); + } + + return true; +} + static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { @@ -3111,6 +3154,13 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s) } break; =20 + case VTD_INV_DESC_DEV_PIOTLB: + trace_vtd_inv_desc("device-piotlb", inv_desc.hi, inv_desc.lo); + if (!vtd_process_device_piotlb_desc(s, &inv_desc)) { + return false; + } + break; + case VTD_INV_DESC_DEVICE: trace_vtd_inv_desc("device", inv_desc.hi, inv_desc.lo); if (!vtd_process_device_iotlb_desc(s, &inv_desc)) { --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032474; cv=none; d=zohomail.com; s=zohoarc; b=fiQit4qLKX4VvGLUuzXI67bpPpZWfZ5DFdRYJP6rDWBHodRPHJ/9SFPUu+oBQfn/bipWh1S3Fj5AKcbJjouWInqBlVlpnMdpCJMrCCwMvGfO8xKXIe6mTBAlLOW9VsiLBEFtyAnfa94E9qZ4xKGDzI5ahNBuxG5W+JcSf/h4MUc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032474; 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=aHUhw2R+YjkyfFVG5MBI7PE45xgReDlmnB6RprzbVGA=; b=d/EuFFnCUWU6eVEXXET2jm7d+bh2+cyAiwTlW6AtI3dCYBpCqCddW7FAt3dryZR2qw9ovqaIHELii3W0gwsAyhNya/6cjHLXCAYb/pxOoOF8SKwFeXf5cFFhjqdFM5xcLc7EvKYdq6LtEz6dXa+YPpLZ7vYLG79jhNOfuOULplc= 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 1726032474074490.22857069754093; Tue, 10 Sep 2024 22:27:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsX-0004De-HX; Wed, 11 Sep 2024 01:26:57 -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 1soFsW-00044G-Jl for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:56 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFsU-0004Mp-S3 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:26:56 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:54 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:50 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032415; x=1757568415; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ECbMcjn6o5cia7D8tVaZRe3oo5EfRXUadTUK7A95Mk0=; b=N9aNkQGsq8heAAtht7BIE+ovkJfLqDvtNdQclPcVFvsY0CNe9fgdIIqZ KHqP89sxmHNwDlgMnO9Vhp/OIUr0mJx6fx5IuNq8kMN3bJQrkqJ47YfCy 1Veq2sDdahKbSebyVSde3hxySIv5nimJUONkYHLd7ctYnmLY5jcTwvP47 bMyjncxf1idGmUAGWgpTod7CdIAnS8QST6H5ERLt6Aga/GRn7NI84LpKS 81q+90yxGRO4opgto2Fv3hLUq9Ov6JEleUfSEaMKjjw9ai/XkSXMz6H5z bmUxXiJm4O4exGm0XkqZx5wnU7+B6rryFwmr0x2Kay9GUEtngHEUjWAGy A==; X-CSE-ConnectionGUID: b80aAVm+Q0SiX8VoDzm7hQ== X-CSE-MsgGUID: MpVog9LYSQK5dEpFmVce5A== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403607" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403607" X-CSE-ConnectionGUID: lHP/jMwcRRycLZ67vi2XyA== X-CSE-MsgGUID: MnvFhBXdRz2/0olAYpklGw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536520" 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 v3 13/17] intel_iommu: piotlb invalidation should notify unmap Date: Wed, 11 Sep 2024 13:22:51 +0800 Message-Id: <20240911052255.1294071-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032474689116600 This is used by some emulated devices which caches address translation result. When piotlb invalidation issued in guest, those caches should be refreshed. For device that does not implement ATS capability or disable it but still caches the translation result, it is better to implement ATS cap or enable it if there is need to cache the translation result. Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif --- hw/i386/intel_iommu.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 4cf56924e1..c25211ddaf 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2908,7 +2908,7 @@ static void vtd_piotlb_pasid_invalidate(IntelIOMMUSta= te *s, continue; } =20 - if (!s->scalable_modern) { + if (!s->scalable_modern || !vtd_as_has_map_notifier(vtd_as)) { vtd_address_space_sync(vtd_as); } } @@ -2920,6 +2920,9 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUStat= e *s, uint16_t domain_id, bool ih) { VTDIOTLBPageInvInfo info; + VTDAddressSpace *vtd_as; + VTDContextEntry ce; + hwaddr size =3D (1 << am) * VTD_PAGE_SIZE; =20 info.domain_id =3D domain_id; info.pasid =3D pasid; @@ -2930,6 +2933,36 @@ static void vtd_piotlb_page_invalidate(IntelIOMMUSta= te *s, uint16_t domain_id, g_hash_table_foreach_remove(s->iotlb, vtd_hash_remove_by_page_piotlb, &info); vtd_iommu_unlock(s); + + QLIST_FOREACH(vtd_as, &s->vtd_as_with_notifiers, next) { + 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)) { + uint32_t rid2pasid =3D VTD_CE_GET_RID2PASID(&ce); + IOMMUTLBEvent event; + + if ((vtd_as->pasid !=3D PCI_NO_PASID || pasid !=3D rid2pasid) = && + vtd_as->pasid !=3D pasid) { + continue; + } + + /* + * Page-Selective-within-PASID PASID-based-IOTLB Invalidation + * does not flush stage-2 entries. See spec section 6.5.2.4 + */ + if (!s->scalable_modern) { + continue; + } + + event.type =3D IOMMU_NOTIFIER_UNMAP; + event.entry.target_as =3D &address_space_memory; + event.entry.iova =3D addr; + event.entry.perm =3D IOMMU_NONE; + event.entry.addr_mask =3D size - 1; + event.entry.translated_addr =3D 0; + memory_region_notify_iommu(&vtd_as->iommu, 0, event); + } + } } =20 static bool vtd_process_piotlb_desc(IntelIOMMUState *s, --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032500; cv=none; d=zohomail.com; s=zohoarc; b=gD1ci4L3Pb2M/pznsfzKvw3O/K29NRDxivoauLA5QV2L1aGXfJ4oYNHItVKyL797NpXLOpKQZ7JTCzaUKBfh1sslgBkrYJbtyhUSYwFaSI71H3qbk32oEnzu120uibu9Ez9Dhq0uDVn+uvBbXmT+9tCDhvltQW+Is4t42R8URv0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032500; 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=4P/UEmKZh+PR8keUFYxpiYlQ1MdR853x+Nv/HqiMZ5E=; b=fdKHIsi75sowvdm+EuSzcPeKmgQjewlL2FCeWdP0e1eYlclE/Mwgy+l/k5mYBRSpEaVPgVVgivDO4TKA4Qgy42ZDdmQ2PrmGhvi/7UVEMzjjNvC5FFXA2W/t04LfIIEc/fQFioyLUAivrPqRa+E9YMPjq/sl9cez37jejfVt/o0= 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 172603250028240.81153584685558; Tue, 10 Sep 2024 22:28:20 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsh-0004v9-6z; Wed, 11 Sep 2024 01:27:07 -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 1soFsd-0004fz-4K for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:27:03 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFsa-0004Mp-Ja for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:27:01 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:59 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032421; x=1757568421; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UGoxBVA6kzO1gidRWg1XuJWhl0S6Jg6nM4URHbYa68g=; b=c1/CkIqDznyAXcJEBF1kPVW4YcDd86iyBx8QMOtowhCNTVTmT4PWTB9z HGL7OKGvJyUhH+EPrEPrwnwWOj3jRiEHoiTVMIxl3c96zzj3dAUh+kZW+ Nx+y+p+EQEChtL599+bYAStLtguF4M4cnQTBLj33G7JlABVuWwUdGw5ch ZyCJ+ekPGfc+55aCf/qYDZl1D2KsSSeTAbudisjcZAcjznjQ+YE7eT3PA 9FtUcgWTj7Ilw9OYYsqDR/+vJjBl2sa9T/qm2HQPHzvAvgR/+JccyxX9d RVwJHn73Wc4dgFd1CZ1P1AsBy08YVxSdlZwyEBuWKdGcYxGYKOBuMMvxV Q==; X-CSE-ConnectionGUID: LKQP1zxTQ1ymm08qkZxIZQ== X-CSE-MsgGUID: O7d2ASSXRAKTM71TuMa44Q== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403616" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403616" X-CSE-ConnectionGUID: bqxPxb0hSMC3tIHAqN7BIg== X-CSE-MsgGUID: VmVfFZ2uTr2HtHM86d4U3g== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536528" 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 v3 14/17] intel_iommu: Set default aw_bits to 48 in scalable modern mode Date: Wed, 11 Sep 2024 13:22:52 +0800 Message-Id: <20240911052255.1294071-15-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032500810116600 According to VTD spec, stage-1 page table could support 4-level and 5-level paging. However, 5-level paging translation emulation is unsupported yet. That means the only supported value for aw_bits is 48. So default aw_bits to 48 in scalable modern mode. In other cases, it is still default to 39 for compatibility. Add a check to ensure user specified value is 48 in modern mode for now. Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif --- include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index b843d069cc..48134bda11 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -45,7 +45,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(IntelIOMMUState, INTEL_IOMMU_D= EVICE) #define DMAR_REG_SIZE 0x230 #define VTD_HOST_AW_39BIT 39 #define VTD_HOST_AW_48BIT 48 -#define VTD_HOST_ADDRESS_WIDTH VTD_HOST_AW_39BIT +#define VTD_HOST_AW_AUTO 0xff #define VTD_HAW_MASK(aw) ((1ULL << (aw)) - 1) =20 #define DMAR_REPORT_F_INTR (1) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index c25211ddaf..949f120456 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3771,7 +3771,7 @@ static Property vtd_properties[] =3D { ON_OFF_AUTO_AUTO), DEFINE_PROP_BOOL("x-buggy-eim", IntelIOMMUState, buggy_eim, false), DEFINE_PROP_UINT8("aw-bits", IntelIOMMUState, aw_bits, - VTD_HOST_ADDRESS_WIDTH), + VTD_HOST_AW_AUTO), DEFINE_PROP_BOOL("caching-mode", IntelIOMMUState, caching_mode, FALSE), DEFINE_PROP_BOOL("x-scalable-mode", IntelIOMMUState, scalable_mode, FA= LSE), DEFINE_PROP_BOOL("snoop-control", IntelIOMMUState, snoop_control, fals= e), @@ -4686,6 +4686,14 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) } } =20 + if (s->aw_bits =3D=3D VTD_HOST_AW_AUTO) { + if (s->scalable_modern) { + s->aw_bits =3D VTD_HOST_AW_48BIT; + } else { + s->aw_bits =3D VTD_HOST_AW_39BIT; + } + } + if ((s->aw_bits !=3D VTD_HOST_AW_39BIT) && (s->aw_bits !=3D VTD_HOST_AW_48BIT) && !s->scalable_modern) { --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032449; cv=none; d=zohomail.com; s=zohoarc; b=AFdRXYocdThBqFWbic65jgwl2+WrGTGZ0mF4fqKvt96wJkflcgUyQHfSc4cKSZhnwC6GxspO4uYy8QtdDEtbQSqP56T1DDIkeJNg4r+GM7rP5mxOjT2owJmkL1HiXze8fwXGuX0Zi/3BLYvS/JK5e1mKxiDQrPjbXlE+j8q7Xmg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032449; 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=AUzt8J5h1vd0S0oI7YopqsFqpoSMQaUtmung6NWX5ls=; b=GDvx2ZbuwoHxBNIz4qp9VjY1ABjFf86TC89IrS4NOF502YAovFOjZRBjoskJOQj4U+ZBYZ2D/BH8xUdk/hc+fkHAh115JvkxBE629oTIdkU5uZ04BEcHyv71nYW1O/j0yOmU2SVHX5qjrDiTl8+OZeqx9RP/Vm+hYSGU7EFD3cY= 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 1726032449730368.05595079787304; Tue, 10 Sep 2024 22:27:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsk-00055W-0P; Wed, 11 Sep 2024 01:27:11 -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 1soFsg-0004ut-O8 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:27:06 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFse-0004Mp-PL for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:27:06 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:27:04 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:26:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032425; x=1757568425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=AITBgbbwWGVpEmJhWQEQKgwrBpsf2DE8pxN8/CX0AZE=; b=TICwsntcavay9zeFyd/kEkD5Hii9KbOh6nodjIeFVGpdhu5cm/2dV9Fk Gi1W8sjJPi29zOgBw13Ua/bcc7+yIh2V2BSZs+FLJlBDZ+ioKYJSGcM13 ei2czmZmJmaR9+2nO5//BBejmt5/cTGtTT4sXzmBOCy7+eyxOphHEmLbL cOJ0E6LtL8Imp5EWRzUKix620gh7CCQPX/OBPASupcgZtWBrfAS4norUl 43UYzYIxCVr7omrBCdmBGT66dNy8nSO85AQKE8hEHrS/lYSck7B6cvTsI eKHBg512mdyjO8+clUUOtgP20wnS13D3s3svdpBvsrrPdwLS5ijcvu0UF A==; X-CSE-ConnectionGUID: 3JiW++k2R/u40xhisOTwCA== X-CSE-MsgGUID: 1NqqiavzTveOjTWdjglyhA== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403626" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403626" X-CSE-ConnectionGUID: lC8BTSklRRir5Nl5W+eypA== X-CSE-MsgGUID: raa8UZK6QTSNdCeGRkh/mQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536551" 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 v3 15/17] intel_iommu: Modify x-scalable-mode to be string option to expose scalable modern mode Date: Wed, 11 Sep 2024 13:22:53 +0800 Message-Id: <20240911052255.1294071-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032450717116600 Content-Type: text/plain; charset="utf-8" From: Yi Liu Intel VT-d 3.0 introduces scalable mode, and it has a bunch of capabilities related to scalable mode translation, thus there are multiple combinations. While this vIOMMU implementation wants to simplify it for user by providing typical combinations. User could config it by "x-scalable-mode" option. The usage is as below: "-device intel-iommu,x-scalable-mode=3D["legacy"|"modern"|"off"]" - "legacy": gives support for stage-2 page table - "modern": gives support for stage-1 page table - "off": no scalable mode support - any other string, will throw error If x-scalable-mode is not configured, it is equivalent to x-scalable-mode= =3Doff. With scalable modern mode exposed to user, also accurate the pasid entry check in vtd_pe_type_check(). Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif --- hw/i386/intel_iommu_internal.h | 2 ++ include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 46 ++++++++++++++++++++++++++-------- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 52bdbf3bc5..af99deb4cd 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -195,6 +195,7 @@ #define VTD_ECAP_PASID (1ULL << 40) #define VTD_ECAP_SMTS (1ULL << 43) #define VTD_ECAP_SLTS (1ULL << 46) +#define VTD_ECAP_FLTS (1ULL << 47) =20 /* CAP_REG */ /* (offset >> 4) << 24 */ @@ -211,6 +212,7 @@ #define VTD_CAP_SLLPS ((1ULL << 34) | (1ULL << 35)) #define VTD_CAP_DRAIN_WRITE (1ULL << 54) #define VTD_CAP_DRAIN_READ (1ULL << 55) +#define VTD_CAP_FS1GP (1ULL << 56) #define VTD_CAP_DRAIN (VTD_CAP_DRAIN_READ | VTD_CAP_DRAIN_WR= ITE) #define VTD_CAP_CM (1ULL << 7) #define VTD_PASID_ID_SHIFT 20 diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 48134bda11..650641544c 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -263,6 +263,7 @@ struct IntelIOMMUState { =20 bool caching_mode; /* RO - is cap CM enabled? */ bool scalable_mode; /* RO - is Scalable Mode supported? */ + char *scalable_mode_str; /* RO - admin's Scalable Mode config */ bool scalable_modern; /* RO - is modern SM supported? */ bool snoop_control; /* RO - is SNP filed supported? */ =20 diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 949f120456..bb3ed48281 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -803,16 +803,18 @@ static inline bool vtd_is_fl_level_supported(IntelIOM= MUState *s, uint32_t level) } =20 /* Return true if check passed, otherwise false */ -static inline bool vtd_pe_type_check(X86IOMMUState *x86_iommu, - VTDPASIDEntry *pe) +static inline bool vtd_pe_type_check(IntelIOMMUState *s, VTDPASIDEntry *pe) { switch (VTD_PE_GET_TYPE(pe)) { - case VTD_SM_PASID_ENTRY_SLT: - return true; - case VTD_SM_PASID_ENTRY_PT: - return x86_iommu->pt_supported; case VTD_SM_PASID_ENTRY_FLT: + return !!(s->ecap & VTD_ECAP_FLTS); + case VTD_SM_PASID_ENTRY_SLT: + return !!(s->ecap & VTD_ECAP_SLTS); case VTD_SM_PASID_ENTRY_NESTED: + /* Not support NESTED page table type yet */ + return false; + case VTD_SM_PASID_ENTRY_PT: + return !!(s->ecap & VTD_ECAP_PT); default: /* Unknown type */ return false; @@ -861,7 +863,6 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSta= te *s, uint8_t pgtt; uint32_t index; dma_addr_t entry_size; - X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); =20 index =3D VTD_PASID_TABLE_INDEX(pasid); entry_size =3D VTD_PASID_ENTRY_SIZE; @@ -875,7 +876,7 @@ static int vtd_get_pe_in_pasid_leaf_table(IntelIOMMUSta= te *s, } =20 /* Do translation type check */ - if (!vtd_pe_type_check(x86_iommu, pe)) { + if (!vtd_pe_type_check(s, pe)) { return -VTD_FR_PASID_TABLE_ENTRY_INV; } =20 @@ -3773,7 +3774,7 @@ static Property vtd_properties[] =3D { DEFINE_PROP_UINT8("aw-bits", IntelIOMMUState, aw_bits, VTD_HOST_AW_AUTO), DEFINE_PROP_BOOL("caching-mode", IntelIOMMUState, caching_mode, FALSE), - DEFINE_PROP_BOOL("x-scalable-mode", IntelIOMMUState, scalable_mode, FA= LSE), + DEFINE_PROP_STRING("x-scalable-mode", IntelIOMMUState, scalable_mode_s= tr), DEFINE_PROP_BOOL("snoop-control", IntelIOMMUState, snoop_control, fals= e), DEFINE_PROP_BOOL("x-pasid-mode", IntelIOMMUState, pasid, false), DEFINE_PROP_BOOL("dma-drain", IntelIOMMUState, dma_drain, true), @@ -4504,7 +4505,10 @@ static void vtd_cap_init(IntelIOMMUState *s) } =20 /* TODO: read cap/ecap from host to decide which cap to be exposed. */ - if (s->scalable_mode) { + if (s->scalable_modern) { + s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_FLTS; + s->cap |=3D VTD_CAP_FS1GP; + } else if (s->scalable_mode) { s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_SRS | VTD_ECAP_SLTS; } =20 @@ -4686,6 +4690,28 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) } } =20 + if (s->scalable_mode_str && + (strcmp(s->scalable_mode_str, "off") && + strcmp(s->scalable_mode_str, "modern") && + strcmp(s->scalable_mode_str, "legacy"))) { + error_setg(errp, "Invalid x-scalable-mode config," + "Please use \"modern\", \"legacy\" or \"off\""); + return false; + } + + if (s->scalable_mode_str && + !strcmp(s->scalable_mode_str, "legacy")) { + s->scalable_mode =3D true; + s->scalable_modern =3D false; + } else if (s->scalable_mode_str && + !strcmp(s->scalable_mode_str, "modern")) { + s->scalable_mode =3D true; + s->scalable_modern =3D true; + } else { + s->scalable_mode =3D false; + s->scalable_modern =3D false; + } + if (s->aw_bits =3D=3D VTD_HOST_AW_AUTO) { if (s->scalable_modern) { s->aw_bits =3D VTD_HOST_AW_48BIT; --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032443; cv=none; d=zohomail.com; s=zohoarc; b=ZM5ZopX7/eBsS8Hfs3XprG6k8DVS0Cr09Oh8y5GWO/+2TqrAPsJ9tqFx6+u1Q/1rTJgyJDylFufOdXgtgS1Zm9ffKkVkpwf2cNsq0JT0JipWCJ150a88GdNiVGv45TBurOtNPiMo2/4YuLjEmNzUK9btfgyUDn7SVo6zqDR6Vaw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032443; 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=gVrJbVBfSF4V1xxKXPTMHNEPdnSXrMrSsHQH/ixpYzI=; b=hYEvMdCiYaqJYnycCR05GJ2X4T/bAtM875r2or7C/n12UagUnzgCNO9VPTu88nRz01nmLdbqAuCbxbCfeuNqt4QHepTpdmdmtQbXrBRx8v139DTp3z+GhQdYZF2kXBEpmDfzjhfqlviqSvQt6plbUC4c5pmYTWhIWs9sYs2Bzzw= 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 1726032443912116.93481205162948; Tue, 10 Sep 2024 22:27:23 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFsn-0005jU-Rq; Wed, 11 Sep 2024 01:27: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 1soFsl-0005Ky-76 for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:27:11 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFsj-0004Mp-FO for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:27:10 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:27:09 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:27:04 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032430; x=1757568430; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=tEoQH+orwDfVTt6SXkdIsJUa09Wi+h/1pLKCEvfBGUc=; b=X9AdQ4e9OTLh3KUbv8KpSaFuPj8xv8MOhAeuVPM8SzPIRnhnWGI507I8 eP/n5g2fEI4zmZMSue4StsSLYHKEWRhZle9TrYm8UQBI6eRES6m/z8YDV 4UzC+4FPSJGPFOkt3WNp3c6Xwktzo4JtvyXOsI4lW0c+4NK8/vSJc1zzD BovK1Z/azjowBBT9oVxYp7Bx4ntq0vp1BT662T19WXkeo0qOLOGaYjpvv icrhkA1RuAGh8YewNNxatMCg0XV9MyWnJIBM3JlUYFAWXdcvQ08TmhafO TWv3DWf8hIL8sw70QojqR601C2JhkiUPuaVZoGhktQFHO88XskDIdxPlz w==; X-CSE-ConnectionGUID: zfz8evsjRoqlHZ5nitrWAQ== X-CSE-MsgGUID: IZUzYWibTRqwuJHj0a7BMw== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403635" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403635" X-CSE-ConnectionGUID: mXTRuF4TQHW4W/rbYmIgPA== X-CSE-MsgGUID: qECYOD+AQTuiMT3cgDB7vw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536561" 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 v3 16/17] intel_iommu: Introduce a property to control FS1GP cap bit setting Date: Wed, 11 Sep 2024 13:22:54 +0800 Message-Id: <20240911052255.1294071-17-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032444641116600 This gives user flexibility to turn off FS1GP for debug purpose. It is also useful for future nesting feature. When host IOMMU doesn't support FS1GP but vIOMMU does, nested page table on host side works after turn FS1GP off in vIOMMU. This property has no effect when vIOMMU isn't in scalable modern mode. Signed-off-by: Zhenzhong Duan Reviewed-by: Cl=C3=A9ment Mathieu--Drif --- include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 650641544c..f6d9b41b80 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -308,6 +308,7 @@ struct IntelIOMMUState { bool dma_drain; /* Whether DMA r/w draining enabled */ bool dma_translation; /* Whether DMA translation supported */ bool pasid; /* Whether to support PASID */ + bool fs1gp; /* First Stage 1-GByte Page Support */ =20 /* * Protects IOMMU states in general. Currently it protects the diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index bb3ed48281..8b40aace8b 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3779,6 +3779,7 @@ static Property vtd_properties[] =3D { DEFINE_PROP_BOOL("x-pasid-mode", IntelIOMMUState, pasid, false), DEFINE_PROP_BOOL("dma-drain", IntelIOMMUState, dma_drain, true), DEFINE_PROP_BOOL("dma-translation", IntelIOMMUState, dma_translation, = true), + DEFINE_PROP_BOOL("x-cap-fs1gp", IntelIOMMUState, fs1gp, true), DEFINE_PROP_END_OF_LIST(), }; =20 @@ -4507,7 +4508,9 @@ static void vtd_cap_init(IntelIOMMUState *s) /* TODO: read cap/ecap from host to decide which cap to be exposed. */ if (s->scalable_modern) { s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_FLTS; - s->cap |=3D VTD_CAP_FS1GP; + if (s->fs1gp) { + s->cap |=3D VTD_CAP_FS1GP; + } } else if (s->scalable_mode) { s->ecap |=3D VTD_ECAP_SMTS | VTD_ECAP_SRS | VTD_ECAP_SLTS; } --=20 2.34.1 From nobody Thu Nov 14 04:01:32 2024 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=1726032493; cv=none; d=zohomail.com; s=zohoarc; b=TStogOw8iDp8Yu4iwKBLg2Up+nE0L7ivOj2c9TXzTWJcxizdT5LGkmPj5GDqwaxEUWgtziuzdc5KEsf6zTkg/G5TMjYqKPIS2aDP8hdR2t7dQ94Td+q4IBtPeZu7HBDjORaYgryNMXfOIkkTxDh19iagguLQhxo5XDH4iC2grDQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1726032493; 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=EguK0MYIHLC85gmb5d6o5QfzmNPi7Yz1H/Ksmsig06I=; b=i8TxbeN2HkoAmE2HC9p7PUXUffthyBPrd+LhhV9V2twr6iqTGNVjDJUoeKMcjOjXBCQKPnXQgaUmZpyQ6huwP2yTlg/32F+Sa9ir6YvP3Kmsg4wAunXE+nQjP2bbPCsu4p0iviumlMZhbRuNUeSVb+B+zG9iK5ByCBAV4NSWNdY= 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 1726032493715941.7864045101708; Tue, 10 Sep 2024 22:28:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1soFst-0006Ye-1I; Wed, 11 Sep 2024 01:27: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 1soFsq-0006Dl-Lb for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:27:16 -0400 Received: from mgamail.intel.com ([192.198.163.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1soFso-0004Mp-Ef for qemu-devel@nongnu.org; Wed, 11 Sep 2024 01:27:16 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:27:14 -0700 Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Sep 2024 22:27:09 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1726032435; x=1757568435; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=bZWcEWPUvXrW2dfLoI2QO7d604JqxTuRIvII2jmDh/U=; b=dGLQbRcRLy94vD82Eod0NZXJBopqwgUmZdq181tcVc0Oas0Mx5zfxNvz 46+qcbOfBbrt6Lpu121rLfIlM8NwcTEFXNQtdYuAxNJpgkX7J4zohwCvm SYphcz2yns1bAaCLDnm2rWma1n1zOWVGp6GlUwGOD+9r4N+gDOp3yh62z PXQNN1Zvur7PdXHHCJDiX329RxFGIMRYj9R+5J2OHlP4iBmvmLdCnVBIW dpNqjEQ0jitzQeGlA/Dd1lTxWAkuSpWL6bZdI7cMG00LP6HE1xfC2gTST 2MgsHaTn0zP1xs/kYgdetQWncRH57XqrCHVnbskUmcEMwwxjhG5I9sWhk Q==; X-CSE-ConnectionGUID: rz0e0roqRr2XSeO31Js2kA== X-CSE-MsgGUID: bTPJ1ESET2ypAujKjxtj/A== X-IronPort-AV: E=McAfee;i="6700,10204,11191"; a="35403642" X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="35403642" X-CSE-ConnectionGUID: eAjBiPkUSeuEObiY7mJ7Rg== X-CSE-MsgGUID: hCxTUM93R2KKiMoGQKT9UQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.10,219,1719903600"; d="scan'208";a="67536578" 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 , Thomas Huth , Marcel Apfelbaum , Laurent Vivier , Paolo Bonzini Subject: [PATCH v3 17/17] tests/qtest: Add intel-iommu test Date: Wed, 11 Sep 2024 13:22:55 +0800 Message-Id: <20240911052255.1294071-18-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240911052255.1294071-1-zhenzhong.duan@intel.com> References: <20240911052255.1294071-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=192.198.163.11; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -44 X-Spam_score: -4.5 X-Spam_bar: ---- X-Spam_report: (-4.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.145, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1726032494786116600 Add the framework to test the intel-iommu device. Currently only tested cap/ecap bits correctness in scalable modern mode. Also tested cap/ecap bits consistency before and after system reset. Signed-off-by: Zhenzhong Duan Acked-by: Thomas Huth Reviewed-by: Cl=C3=A9ment Mathieu--Drif Acked-by: Jason Wang --- MAINTAINERS | 1 + include/hw/i386/intel_iommu.h | 1 + tests/qtest/intel-iommu-test.c | 70 ++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 4 files changed, 73 insertions(+) create mode 100644 tests/qtest/intel-iommu-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 0c1bc69828..120e8b86e5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3690,6 +3690,7 @@ S: Supported F: hw/i386/intel_iommu.c F: hw/i386/intel_iommu_internal.h F: include/hw/i386/intel_iommu.h +F: tests/qtest/intel-iommu-test.c =20 AMD-Vi Emulation S: Orphan diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index f6d9b41b80..0c9bb8eab6 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -47,6 +47,7 @@ OBJECT_DECLARE_SIMPLE_TYPE(IntelIOMMUState, INTEL_IOMMU_D= EVICE) #define VTD_HOST_AW_48BIT 48 #define VTD_HOST_AW_AUTO 0xff #define VTD_HAW_MASK(aw) ((1ULL << (aw)) - 1) +#define VTD_MGAW_FROM_CAP(cap) ((cap >> 16) & 0x3fULL) =20 #define DMAR_REPORT_F_INTR (1) =20 diff --git a/tests/qtest/intel-iommu-test.c b/tests/qtest/intel-iommu-test.c new file mode 100644 index 0000000000..fa9169f1a3 --- /dev/null +++ b/tests/qtest/intel-iommu-test.c @@ -0,0 +1,70 @@ +/* + * QTest testcase for intel-iommu + * + * Copyright (c) 2024 Intel, Inc. + * + * Author: Zhenzhong Duan + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + */ + +#include "qemu/osdep.h" +#include "libqtest.h" +#include "hw/i386/intel_iommu_internal.h" + +#define CAP_MODERN_FIXED1 (VTD_CAP_FRO | VTD_CAP_NFR | VTD_CAP_ND | \ + VTD_CAP_MAMV | VTD_CAP_PSI | VTD_CAP_SLLPS) +#define ECAP_MODERN_FIXED1 (VTD_ECAP_QI | VTD_ECAP_IR | VTD_ECAP_IRO | \ + VTD_ECAP_MHMV | VTD_ECAP_SMTS | VTD_ECAP_FLT= S) + +static inline uint32_t vtd_reg_readl(QTestState *s, uint64_t offset) +{ + return qtest_readl(s, Q35_HOST_BRIDGE_IOMMU_ADDR + offset); +} + +static inline uint64_t vtd_reg_readq(QTestState *s, uint64_t offset) +{ + return qtest_readq(s, Q35_HOST_BRIDGE_IOMMU_ADDR + offset); +} + +static void test_intel_iommu_modern(void) +{ + uint8_t init_csr[DMAR_REG_SIZE]; /* register values */ + uint8_t post_reset_csr[DMAR_REG_SIZE]; /* register values */ + uint64_t cap, ecap, tmp; + QTestState *s; + + s =3D qtest_init("-M q35 -device intel-iommu,x-scalable-mode=3Dmodern"= ); + + cap =3D vtd_reg_readq(s, DMAR_CAP_REG); + g_assert((cap & CAP_MODERN_FIXED1) =3D=3D CAP_MODERN_FIXED1); + + tmp =3D cap & VTD_CAP_SAGAW_MASK; + g_assert(tmp =3D=3D (VTD_CAP_SAGAW_39bit | VTD_CAP_SAGAW_48bit)); + + tmp =3D VTD_MGAW_FROM_CAP(cap); + g_assert(tmp =3D=3D VTD_HOST_AW_48BIT - 1); + + ecap =3D vtd_reg_readq(s, DMAR_ECAP_REG); + g_assert((ecap & ECAP_MODERN_FIXED1) =3D=3D ECAP_MODERN_FIXED1); + + qtest_memread(s, Q35_HOST_BRIDGE_IOMMU_ADDR, init_csr, DMAR_REG_SIZE); + + qobject_unref(qtest_qmp(s, "{ 'execute': 'system_reset' }")); + qtest_qmp_eventwait(s, "RESET"); + + qtest_memread(s, Q35_HOST_BRIDGE_IOMMU_ADDR, post_reset_csr, DMAR_REG_= SIZE); + /* Ensure registers are consistent after hard reset */ + g_assert(!memcmp(init_csr, post_reset_csr, DMAR_REG_SIZE)); + + qtest_quit(s); +} + +int main(int argc, char **argv) +{ + g_test_init(&argc, &argv, NULL); + qtest_add_func("/q35/intel-iommu/modern", test_intel_iommu_modern); + + return g_test_run(); +} diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build index fc852f3d8b..826e967a81 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -80,6 +80,7 @@ qtests_i386 =3D \ (config_all_devices.has_key('CONFIG_SB16') ? ['fuzz-sb16-test'] : []) + = \ (config_all_devices.has_key('CONFIG_SDHCI_PCI') ? ['fuzz-sdcard-test'] := []) + \ (config_all_devices.has_key('CONFIG_ESP_PCI') ? ['am53c974-test'] : []) = + \ + (config_all_devices.has_key('CONFIG_VTD') ? ['intel-iommu-test'] : []) += \ (host_os !=3D 'windows' and = \ config_all_devices.has_key('CONFIG_ACPI_ERST') ? ['erst-test'] : []) + = \ (config_all_devices.has_key('CONFIG_PCIE_PORT') and = \ --=20 2.34.1