From nobody Mon Nov 25 07:35:07 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=1716359195; cv=none; d=zohomail.com; s=zohoarc; b=WU68SRY92Qc7oLkTjDKKdNk7x/7MqbcYXHb4XmdPFKFtX6PqtOZyOMjgyHs/CLAM9sppE50qhazs9eaqrp7vdBk70sDNn4gFWCVru0zs+QakS78UkVYd/eDF23AL6ffaRnLmtAPV4FWT34yPIS+uNrRwUWLP+M/vdrrsII2RNiM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359195; 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=5Aoc+0eJZ++7xfloDqQvjP1ODMOSKe0CkKpByBded6o=; b=l6QxBOhKXuKYmtShAUD4QG+nr8rbm24c6PFpgdM74Dy2AmBGXfY9mnd6GN7ZpAd+osi9ymRAGBCtqglQh56ZR+2F2kew7GMtPWb34JZJ1lq7Pn8rEIXyDLa0IAiNyMpuaYiYOj9mD/ol33aeYJOI7VV+29iTPSC6uoiz5peR2S0= 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 17163591959271015.6464491112905; Tue, 21 May 2024 23:26:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fQJ-0004Xo-Sf; Wed, 22 May 2024 02:26:03 -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 1s9fQD-0004QQ-4v for qemu-devel@nongnu.org; Wed, 22 May 2024 02:25:59 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQB-0006eK-3H for qemu-devel@nongnu.org; Wed, 22 May 2024 02:25:56 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:25:54 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:25:49 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359155; x=1747895155; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xM2zyrutJTAoCRZwE67zEYgDwAvX9tqJ2pps0NC9kp8=; b=RT/h1tfzlXQ6wynpdbsLQM/m0QxBq3299NQYByccTyjBj9DbEY29ffvF g9UgLvXKp5H06qOt4GYvdymcYjKJZpYvxaOUpXsAsdbc5uPO30j+hHlDN 1IbE56QkMU2d7D16M6ZM5XfzYyu7B4jutOsI+NElCZN0EPUPdVi2oX199 7y+ocfTtRtr8xeWWVxykHQyAOYN+l9lh40rINsktb7PW58aIttc6aGpvS 536Ro/YrVFdvf0GInW8EJpbsMemgXm16FCr3o0uytE1szqZ5m5fGD8Iy7 bobLGv4Bvnp3RImgzSWtXOSGACN/8ZfOtgkXOieTtrzu8FpUB0honRim8 Q==; X-CSE-ConnectionGUID: /gg1zlc4Qbu0wA4aerIoHg== X-CSE-MsgGUID: drhRJSHSRUe4SEwHhOHUnA== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972439" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972439" X-CSE-ConnectionGUID: 6hiXjF3BSz6J+CcHrt4gMA== X-CSE-MsgGUID: nNXji3pgSXauaO/ao6BPXA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597569" 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, Yu Zhang , Zhenzhong Duan , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH rfcv2 01/17] intel_iommu: Update version to 3.0 and add the latest fault reasons Date: Wed, 22 May 2024 14:22:57 +0800 Message-Id: <20240522062313.453317-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359196186100004 Content-Type: text/plain; charset="utf-8" From: Yu Zhang The scalable mode was introduced in VTD spec 3.0, now that the scalable mode is already supported, bump version to 3.0. In spec 3.0 some more detailed fault reasons are defined for scalable mode. So introduce them into emulation code, see spec section 7.1.2 for details. Guest kernel should use the version for informational purpose not feature check, cap/ecap bits should be checked instead. So this change will not impact migration. Signed-off-by: Yu Zhang Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 9 ++++++++- hw/i386/intel_iommu.c | 27 +++++++++++++++++---------- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index b800d62ca0..955bc24787 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -312,7 +312,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 07bfd4f99e..d85aaf4bb8 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -779,7 +779,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); @@ -797,6 +797,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); @@ -806,7 +807,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]); @@ -814,11 +815,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; @@ -859,7 +862,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); @@ -868,7 +871,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; @@ -921,7 +924,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 /* @@ -1778,7 +1781,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, }; @@ -4138,7 +4145,7 @@ static void vtd_init(IntelIOMMUState *s) vtd_reset_caches(s); =20 /* Define registers with default values and bit semantics */ - vtd_define_long(s, DMAR_VER_REG, 0x10UL, 0, 0); + vtd_define_long(s, DMAR_VER_REG, 0x30UL, 0, 0); vtd_define_quad(s, DMAR_CAP_REG, s->cap, 0, 0); vtd_define_quad(s, DMAR_ECAP_REG, s->ecap, 0, 0); vtd_define_long(s, DMAR_GCMD_REG, 0, 0xff800000UL, 0); --=20 2.34.1 From nobody Mon Nov 25 07:35:07 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=1716359195; cv=none; d=zohomail.com; s=zohoarc; b=Wm7jULyxw1nAm1EkBNvEqEyDdj29cuMm3Tk4bkHXQTZX1YvkuRzoCCenfbJG+f1oDoZbHLyx+5oh2TLlQHdnKg7/iKXpJhQyW5J3Xv58Rdh0ej9SHeR00K0c7WQvPYnKXrLou14bPvuDrQc0tCkhChPHdzpfSn7vW/9LTYX2v3M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359195; 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=qCMt3UFYzaJrZZal/desyekOAUIFvYqV/dOlTQnKMzw=; b=WrffgzGDSEfJYVEK6CstIlhJi2JH82I6XJD2DIFcvirNin2tL7DeqoqhjF2M2WpwBk1z8KyPwnH2A78eeKMWvt84/sZmh4YLR3I1DtJ1lyjCmTFFYH19FSl4LQCKPCdyP+dTCU6zgnV5WxIxA9GFeabaPRWvFWTtD3TtFjbXyec= 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 1716359195876942.3204395420703; Tue, 21 May 2024 23:26:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fQT-0004f4-Fq; Wed, 22 May 2024 02:26: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 1s9fQI-0004V8-AA for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:02 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQF-0006eK-Oy for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:01 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:25:59 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:25:54 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359160; x=1747895160; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2sqa5xD65ChPp2kFgW+ttHAbtCvBnY8XoaP9JWX78tA=; b=nxLWephLT45/P/VRr5bD1wyT9v+/AFW2qktBJlsV4c1Olg4g/AKjjcgm 2dvrOxs/XjZesNgOBLSb+fTAbR38oDv3O9SzV7AZiRaQ3jX2ZL96+CmCy 0Qnkj3NHKGnI8lh0ego6GxgY1zHAXEDzcm5xVgoPleUWjbh//+3/hbEhE 4cnvNkRScGgd5SBUhtW7Fq65XJTi+y2nI2f1/XGTux7bnG4bSiT1TWhYL WVVRpN7zV6n4ipT78hZkrkf3rtVudHiqUB/o83jTs7nCnGWh2MjjM0nm+ nfHvTWs4klvudaMF/BlQwkHPmIy7nU1vL9zrjlmYZY5F+899z9DXGB0fb Q==; X-CSE-ConnectionGUID: 6ddlfq9vQxugMnXQgIjCCQ== X-CSE-MsgGUID: 5WQtO+qdSQ2OxNvwMnFHHg== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972450" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972450" X-CSE-ConnectionGUID: Zvoe2BO9RvWN3FmvHCS5fg== X-CSE-MsgGUID: 6CwyhW0+TA2SXHhrqkpMoQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597597" 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 rfcv2 02/17] intel_iommu: Make pasid entry type check accurate Date: Wed, 22 May 2024 14:22:58 +0800 Message-Id: <20240522062313.453317-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359196160100001 Content-Type: text/plain; charset="utf-8" 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 --- 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 d85aaf4bb8..348e3a441e 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -742,20 +742,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 Mon Nov 25 07:35:07 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=1716359196; cv=none; d=zohomail.com; s=zohoarc; b=Z+EY/S178pUdaHh3AT9IeS+n+xQ0/HOC9+R4Ot4og3fARoaYRRZD+gvB6oJEFzTO+OPwPfEhbYbyNVXCox+DO7dUT6g/knHZhMzElIokwIjaHcKkEYWEt3ewG5WdiPCf3oCdNMvARG6feAImbQsUu0zNFDqsp9nY5ESxl2zEYIM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359196; 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=qFkCrdnmUe/hH5Y5yc7OZ160NO9xliUSpquMJAcvBcw=; b=cxulqSYVlUd0RT/eRZKTPvtZAG8Ej0BqedzX1GPFWKz4QHEKmM/iUs6MbdmDup7KofSXF+0Rpz9UDXc6MUkYPtbQifGLwtMABxQPmHdwZlL6rekuI0tFhlDIQVH7KZoDeREJwil029/EzsqpTEawCnFc7SlDauw01rImQw78OSw= 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 1716359196262397.693697700651; Tue, 21 May 2024 23:26:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fQj-0004gO-3t; Wed, 22 May 2024 02:26:29 -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 1s9fQN-0004ds-G7 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:07 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQL-0006eK-Hi for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:07 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:04 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:25:59 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359165; x=1747895165; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=+nja1FsyQjlZ15iCQFoLofuev/SaDnUyHRaMOK5gZk0=; b=jKusiLQg+Lm964LHjVe2J+I1qd2GCeKxLXqNI+mVoH5bleS5zL6GfujS 7zBcX3nBph61ydK8O/czziVzXoJIbrguIApNwrvxNfQ9tCGO2sZ0bYcJp czEmUwB6X+TCYqKQQ5wB77iyICAbAjdpwi6Ivx9cbCb8t/nTJcUSc4sGU 732oPVu1XTVXzUzAHvwSvOYqc3uqTu/8RE9LV/6u2edFobdBP5w/p/x0T aAxATWKkdGE2JckHRwUxVriR8AsshwafIxXAKX+kusz3j/2Hr46T0/JwP BJa27BG9urExnc17jZju0ipcWDFjSKxpatPxCzVUD8La8z5PNU3HFc6NE A==; X-CSE-ConnectionGUID: 5kQrgRn/RhSv6S4nWB9+bQ== X-CSE-MsgGUID: BS9m9c9CQw+83uVhIQGEbw== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972460" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972460" X-CSE-ConnectionGUID: 6eSDi8hkTyadN/WjyGPM2Q== X-CSE-MsgGUID: yoOIUQCKTu6Ybuv/RxoEMA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597634" 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 rfcv2 03/17] intel_iommu: Add a placeholder variable for scalable modern mode Date: Wed, 22 May 2024 14:22:59 +0800 Message-Id: <20240522062313.453317-4-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359198090100015 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 cap/ecap initialization, compatibility check and block host device passthrough until nesting is supported. Signed-off-by: Yi Liu Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 2 ++ include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 37 ++++++++++++++++++++++++---------- 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 955bc24787..75aea80942 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -196,6 +196,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 */ @@ -212,6 +213,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 2bbde41e45..9ba9c45015 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? */ + 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 348e3a441e..6d1d94ada3 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -738,16 +738,20 @@ static inline bool vtd_is_level_supported(IntelIOMMUS= tate *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) { + X86IOMMUState *x86_iommu =3D X86_IOMMU_DEVICE(s); + switch (VTD_PE_GET_TYPE(pe)) { + case VTD_SM_PASID_ENTRY_FLT: + return s->scalable_modern; case VTD_SM_PASID_ENTRY_SLT: - return true; + return !s->scalable_modern; + case VTD_SM_PASID_ENTRY_NESTED: + /* Not support NESTED page table type yet */ + return false; case VTD_SM_PASID_ENTRY_PT: return x86_iommu->pt_supported; - case VTD_SM_PASID_ENTRY_FLT: - case VTD_SM_PASID_ENTRY_NESTED: default: /* Unknown type */ return false; @@ -796,7 +800,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; @@ -810,7 +813,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 @@ -3839,8 +3842,17 @@ static bool vtd_check_hdev(IntelIOMMUState *s, VTDHo= stIOMMUDevice *vtd_hdev, error_setg(errp, "aw-bits %d > host aw-bits %d", s->aw_bits, ret); return false; } -#endif + + 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; +#else return true; +#endif } =20 static bool vtd_dev_set_iommu_device(PCIBus *bus, void *opaque, int devfn, @@ -4076,7 +4088,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 @@ -4243,9 +4258,9 @@ static bool vtd_decide_config(IntelIOMMUState *s, Err= or **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)) { + (s->aw_bits !=3D VTD_HOST_AW_48BIT) && + !s->scalable_modern) { error_setg(errp, "Supported values for aw-bits are: %d, %d", VTD_HOST_AW_39BIT, VTD_HOST_AW_48BIT); return false; --=20 2.34.1 From nobody Mon Nov 25 07:35:07 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=1716359256; cv=none; d=zohomail.com; s=zohoarc; b=VXr9i/zYhRNdv2AKfDLs5pgE+IDKndQrl6pPL5pCsjaxy9sitjhiRpAKiXS0caj59fEHG12Fb8zONXZD3XqVFKNVfcK58o2j5g3W79gWyndgU3g8zHbE3+bgynVc6qaqXPqWYRlJuLfKStdCRxo0JBcKRdlVBnXyk0tJq82Dd/4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359256; 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=ZTGqZWFdQap1822Uv1kx59wjNo3y64CSrb0fh7mHQeo=; b=AdlbgZSZ1fycZSV1NB1gfQhQM+b/sXkPfSeEVVJbPm1GWsKAn7zTx5SM0c2mqj0k+GO60XJ2I5x1NwSo2qhxYq3/nzIAS8fX3qce4YqOubwJw80t1KNitf81UqKCtpIAI9ZfvtLoGd7NeKyd4hjNZsHv/cjRuoZLG8s77/0/UJY= 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 1716359256358624.1942846594793; Tue, 21 May 2024 23: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 1s9fQl-0004kf-Sq; Wed, 22 May 2024 02:26:32 -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 1s9fQR-0004fS-RD for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:13 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQP-0006eK-Sj for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:11 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:09 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:05 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359170; x=1747895170; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cD5cVdgSzb6ZO3BTQ0aYaHnDKOU7WL/AhIvLCiXf+9g=; b=LDA/aTzopXtaEqXZ1XijBO7aDgSBB5U0NSMWHYbdibfXlmCwPA1sToUM /3a2AJPDUHEltPTbfMdpGknRONnYlZBBoUSLqT/U+DvuHeTuRY0EWFNJf QV8TY9pZ1+eo4gv8KUaeNyhZ9vwITAlZCJbi3wqXW0gUNoAfVxMxnv4aU dDo8IjYjFvGU9eD6qtLxhmcgQ2EDpkm2jXTMpgd8emaL5a9l2cM0bj1kj kVYglVqYaITgW8uqnkLLvS2zGlp46/5dBh+obLmNWim8c2Vxz96knHsoL bP+kHpq60iK6h3B1RveQqCJqFgLkItah0Z2edENsd84rrFgWtSLNtUELW g==; X-CSE-ConnectionGUID: T9Vt+ZOZT5yxYmABi0xYEA== X-CSE-MsgGUID: 7DEoL3EXR62y6KZx0iomvA== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972470" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972470" X-CSE-ConnectionGUID: M6H+BaCBSiSyd46fqhuK7A== X-CSE-MsgGUID: dYpEbwUfTmyUKXO66Z3L7Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597666" 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 rfcv2 04/17] intel_iommu: Flush stage-2 cache in PADID-selective PASID-based iotlb invalidation Date: Wed, 22 May 2024 14:23:00 +0800 Message-Id: <20240522062313.453317-5-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359258411100001 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 mdoe introduced, guest could send PADID-selective PASID-based iotlb invalidation to flush both stage-1 and stage-2 entries. Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 10 +++++ hw/i386/intel_iommu.c | 78 ++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 75aea80942..b0d9b1f986 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -441,6 +441,16 @@ 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 +#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_RSVD_VAL0 0xfff000000000ffc0ULL +#define VTD_INV_DESC_PIOTLB_RSVD_VAL1 0xf80ULL + +#define VTD_INV_DESC_PIOTLB_PASID(val) (((val) >> 32) & 0xfffffULL) +#define VTD_INV_DESC_PIOTLB_DID(val) (((val) >> 16) & \ + VTD_DOMAIN_ID_MASK) + /* 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 6d1d94ada3..ed95b5ba2e 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2642,6 +2642,80 @@ 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("non-zero-field-in-piotlb_inv_desc hi: 0x%" PRIx= 64 + " lo: 0x%" PRIx64, 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_IOTLB_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("Invalid granularity in P-IOTLB desc hi: 0x%" PR= Ix64 + " lo: 0x%" PRIx64, inv_desc->val[1], inv_desc->val[0]); + return false; + } + return true; +} + static bool vtd_process_inv_iec_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { @@ -2752,6 +2826,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 Mon Nov 25 07:35:07 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=1716359228; cv=none; d=zohomail.com; s=zohoarc; b=A6yvEa/nfTLoEUyHXB74eDWJcPVn/Triseqycgd35R1AH/DqWo0lE0DPjLoriRUvVPWlkMBX+95hHadjmK02KEpyDr8UN+bcVHfn3GAca3OuiOFnbdPeQS1OPOk7V1df+vS8DoOl8JNOc6JgPIDugLQsHlHUc5PZmuNYYzJWtjM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359228; 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=z3wSX4XZMGwG41kT8DIMiUqT3YBRl5/WH57MMWTz/AQ=; b=Aw7fqPW1Es2jEH19IOz1Vv69ax5Cwwi2JfDO2T6BqySn+Va1PEATb0P3loxaG5SvAHNUCxybgipYrMAsrvJNZxIOTqRCBsHn2/W9LRq631y8at3DTm2TtcsIK5rN8v+rUd5kmu76rO6iS4epcCfLhuIS/27DGcmx7zdebvu2BgU= 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 1716359228502121.71440412189656; Tue, 21 May 2024 23:27:08 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fQv-0004xo-D6; Wed, 22 May 2024 02:26:41 -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 1s9fQY-0004gi-GB for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:23 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQV-0006eK-M1 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:18 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:15 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:10 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359176; x=1747895176; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uPUVQFGDFxFSLvmCcNQ6Dut0feFHx5NOEumo20sJpRw=; b=geR+YSrtMlZoaVU+zdnc03/4q1PrifD7SBIdeiXPJ6hYOyOVwhX6r5aA 0a+kSXkrUXscAO7FWqMf3bgQ2ZB4HRuBQq7MpHXlLm0HbU+vwjtz+ovMf gdH4kYfzOB4qCfSYxaYFTST4Y9UuAOC7f9RthhzQ1JZbO27G/6nzvMDkh 7nR2Mn7fg7arTnyAORjLKJmlPYsSHPl/dIFRfn34ooi4slG1LmrUprPgy gLnzguMJAun85/RBLSKNLhXKIQxuqBufC4le/yQ/eAdhArAXakmFzi9ZM XaEgfd1ZNpL0V5FK1Yax97E0eBty0vhxFSUQzb/yighHQDm6qeryfLnqQ g==; X-CSE-ConnectionGUID: fh5bGqBIRrK66zNSQ7pvEw== X-CSE-MsgGUID: 2S/TTeMkQ2iFCaPK/GQqXA== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972490" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972490" X-CSE-ConnectionGUID: /2IrnlxoSW+ZZGmOi1W3Ug== X-CSE-MsgGUID: BmmNIJUeQlCKl48ONHnT+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597713" 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, Yi Sun , Zhenzhong Duan , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH rfcv2 05/17] intel_iommu: Rename slpte to pte Date: Wed, 22 May 2024 14:23:01 +0800 Message-Id: <20240522062313.453317-6-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359230280100003 Content-Type: text/plain; charset="utf-8" From: Yi Liu Because we will support both FST(a.k.a, FLT) and SST(a.k.a, SLT) translatio= n, rename slpte to pte to make it generic. Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 3 ++- include/hw/i386/intel_iommu.h | 2 +- hw/i386/intel_iommu.c | 39 +++++++++++++++++----------------- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index b0d9b1f986..0e240d6d54 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -553,10 +553,11 @@ typedef struct VTDRootEntry VTDRootEntry; #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_PT_BASE_ADDR_MASK(aw) (~(VTD_PAGE_SIZE - 1) & VTD_HAW_MASK(aw)) =20 typedef struct VTDHostIOMMUDevice { IntelIOMMUState *iommu_state; diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 9ba9c45015..011f374883 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -153,7 +153,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 ed95b5ba2e..544e8f0e40 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -360,7 +360,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) { @@ -368,7 +368,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); @@ -376,7 +376,7 @@ 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->pasid =3D pasid; @@ -693,9 +693,9 @@ static inline dma_addr_t vtd_ce_get_slpt_base(VTDContex= tEntry *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 slpte, uint8_t aw) { - return slpte & VTD_SL_PT_BASE_ADDR_MASK(aw); + return slpte & VTD_PT_BASE_ADDR_MASK(aw); } =20 /* Whether the pte indicates the address of the page frame */ @@ -1152,11 +1152,11 @@ static int vtd_iova_to_slpte(IntelIOMMUState *s, VT= DContextEntry *ce, *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); + xlat =3D vtd_get_pte_addr(*slptep, aw_bits); size =3D ~vtd_slpt_level_page_mask(level) + 1; =20 /* @@ -1343,7 +1343,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint6= 4_t start, * 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 { @@ -1360,7 +1360,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); @@ -1883,7 +1883,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; @@ -1904,13 +1904,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; @@ -1982,21 +1982,22 @@ 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, addr, is_write, pasid !=3D PCI_NO_PASID, pasid); @@ -2006,11 +2007,11 @@ static bool vtd_do_iommu_translate(VTDAddressSpace = *vtd_as, PCIBus *bus, page_mask =3D vtd_slpt_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 Mon Nov 25 07:35:07 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=1716359358; cv=none; d=zohomail.com; s=zohoarc; b=Ri3ifdUUTC9KFKCYYgahR1H1Ox3TOWWuK7dIOypDBOW80MOTV+VXV4NZs6kbg+i7sgeoQxGnNKr1IW/awDDLJpic0RgegJXkWoCiN8vSQVorye8B7DMiryIhWA1Hc9EfxdjPQH/JAsMsSPiE+n9qzUHuMjbGcRIoF68PhYvjjoc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359358; 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=ya2z8yS2Cz31hKE5uxuQ9JCkzJmP3T9Ps7qSdfqNleU=; b=dHugB8sRvA5afMuepebAXND/wFmIt+zBQSAmcCzLcsds/6OEGhxXQsbxsHkVNGBeEflj72wx/PF85S74CiDvDwWw2y175g357xQsoAkwXn/niKoAnD/Vn6hfDgaj+gGnytikbT02kjHo9MKm8ZeqS+aqA3hstyYUIUQ6MfZtLCA= 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 1716359358011157.98413588335325; Tue, 21 May 2024 23:29:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fQq-0004tb-Fw; Wed, 22 May 2024 02:26:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQc-0004hE-V9 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:26 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQb-0006eK-2d for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:22 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:20 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:15 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359181; x=1747895181; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cUHaYrw4M5g3+Y/4geeEr+F2a1tGgIj677+LINY9b6c=; b=AIWOTI8yWFyv2ZqZCBSWfUqPvQ9H6btjazwarB1/CTbKuyzyzpZZbFPf n2C6WeBi0kDq1Ri/vEfVDXLw/m8iPN4vrN0OBTX15GO4/GXhN0YxvcOch gZNLPi0siCjZ9KFPlE4JEPv4F+QjzzCX9VIsKDCG9XSFdAEJN8SY4aS7N sYDU9Ew6F2vjVtnFaAdQTn5RndVX5wkOhYgTUQfOEdn6wbuBo4GL6q0BR p9tdX++4AOmIclDmQ1nHp2J6xEQ2DMcuiZTxFEBCIZRxwCBXJduC1BvL1 wwmqkAzKaFuze6ohxmqPG2WXq9dg8+wIDlGWAVAjO0qwINIZyXuuIOEn9 Q==; X-CSE-ConnectionGUID: SJU4JKg1SJWNvArLfrDEnQ== X-CSE-MsgGUID: BTTP5QT1QgexLEDakBDTUw== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972513" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972513" X-CSE-ConnectionGUID: t84vdBkrSOWOu55os9EQQA== X-CSE-MsgGUID: ymIhH+8wQD+23mb1bvap3w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597743" 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, Yi Sun , Zhenzhong Duan , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH rfcv2 06/17] intel_iommu: Implement stage-1 translation Date: Wed, 22 May 2024 14:23:02 +0800 Message-Id: <20240522062313.453317-7-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359358857100001 Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu_internal.h | 17 +++++ hw/i386/intel_iommu.c | 128 +++++++++++++++++++++++++++++++-- 2 files changed, 141 insertions(+), 4 deletions(-) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index 0e240d6d54..abfdbd5f65 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -534,6 +534,23 @@ 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) + +/* Paging Structure common */ +#define VTD_FL_PT_PAGE_SIZE_MASK (1ULL << 7) +/* Bits to decide the offset for each level */ +#define VTD_FL_LEVEL_BITS 9 + +/* First Level Paging Structure */ +#define VTD_FL_PT_LEVEL 1 +#define VTD_FL_PT_ENTRY_NR 512 + +/* Masks for First Level Paging Entry */ +#define VTD_FL_RW_MASK (1ULL << 1) +#define VTD_FL_PT_BASE_ADDR_MASK(aw) (~(VTD_PAGE_SIZE - 1) & VTD_HAW_MASK(= aw)) +#define VTD_PASID_ENTRY_FPD (1ULL << 1) /* Fault Processing Disabl= e */ + /* 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 544e8f0e40..cf29809bc1 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -50,6 +50,8 @@ /* 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_FLPT_LEVEL(pe) \ + (4 + (((pe)->val[2] >> 2) & VTD_SM_PASID_ENTRY_FLPM)) =20 /* * PCI bus number (or SID) is not reliable since the device is usaully @@ -823,6 +825,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_PE_GET_FLPT_LEVEL(pe) !=3D 4) { + return -VTD_FR_PASID_TABLE_ENTRY_INV; + } + return 0; } =20 @@ -958,7 +965,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_LEVEL(&pe); + if (s->scalable_modern) { + return VTD_PE_GET_FLPT_LEVEL(&pe); + } else { + return VTD_PE_GET_LEVEL(&pe); + } } =20 return vtd_ce_get_level(ce); @@ -1045,7 +1056,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); @@ -1847,6 +1862,106 @@ out: trace_vtd_pt_enable_fast_path(source_id, success); } =20 +/* The shift of an addr for a certain level of paging structure */ +static inline uint32_t vtd_flpt_level_shift(uint32_t level) +{ + assert(level !=3D 0); + return VTD_PAGE_SHIFT_4K + (level - 1) * VTD_FL_LEVEL_BITS; +} + +/* + * Given an iova and the level of paging structure, return the offset + * of current level. + */ +static inline uint32_t vtd_iova_fl_level_offset(uint64_t iova, uint32_t le= vel) +{ + return (iova >> vtd_flpt_level_shift(level)) & + ((1ULL << VTD_FL_LEVEL_BITS) - 1); +} + +/* Get the content of a flpte located in @base_addr[@index] */ +static uint64_t vtd_get_flpte(dma_addr_t base_addr, uint32_t index) +{ + uint64_t flpte; + + assert(index < VTD_FL_PT_ENTRY_NR); + + if (dma_memory_read(&address_space_memory, + base_addr + index * sizeof(flpte), &flpte, + sizeof(flpte), MEMTXATTRS_UNSPECIFIED)) { + flpte =3D (uint64_t)-1; + return flpte; + } + flpte =3D le64_to_cpu(flpte); + return flpte; +} + +static inline bool vtd_flpte_present(uint64_t flpte) +{ + return !!(flpte & 0x1); +} + +/* Whether the pte indicates the address of the page frame */ +static inline bool vtd_is_last_flpte(uint64_t flpte, uint32_t level) +{ + return level =3D=3D VTD_FL_PT_LEVEL || (flpte & VTD_FL_PT_PAGE_SIZE_MA= SK); +} + +static inline uint64_t vtd_get_flpte_addr(uint64_t flpte, uint8_t aw) +{ + return flpte & VTD_FL_PT_BASE_ADDR_MASK(aw); +} + +/* + * 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_fl_level_offset(iova, level); + flpte =3D vtd_get_flpte(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_is_last_flpte(flpte, level)) { + *flptep =3D flpte; + *flpte_level =3D level; + return 0; + } + + addr =3D vtd_get_flpte_addr(flpte, aw_bits); + level--; + } +} + static void vtd_report_fault(IntelIOMMUState *s, int err, bool is_fpd_set, uint16_t source_id, @@ -1995,8 +2110,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) { + 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); + } =20 if (ret_fr) { vtd_report_fault(s, -ret_fr, is_fpd_set, source_id, --=20 2.34.1 From nobody Mon Nov 25 07:35:07 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=1716359473; cv=none; d=zohomail.com; s=zohoarc; b=oJrSMALkY7xYJbDUUH5Q9DW7h34yo6aq8u9jnrsjOWp3IAMhSuC7ICiTbqPJdgRl3a6KTUThU+oqcfu7G5UyA+wkn5Toshl4Z1O+wsuAaXoVUyEJ4Lpuj7DcHKrjUDQD7YbRN0RgWBxgzsbnSsvQuopf23i+F2RxivYtxpoziGc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359473; 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=vM/h7P23wINBagjnl7ZI1GyDS0zsoDQbRX/MKrXpxyA=; b=FtFUj6M16F4HJL5tj2GpOnYuMcj2YWtLBXE+iiDE2AWNQ7CfWQPwvkO/d5bGTGAXEmfbdXsTR3wCmwNb80I/16MFScc+YtN8AlT0369E0VJIgrT9BMaXyyFQ/xn+E/gNUsR+t66CDuaGXquW75PRQaWfkWNeKBW97z7OOPh/0cA= 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 1716359473024183.44428752799558; Tue, 21 May 2024 23:31:13 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fQo-0004mR-Ft; Wed, 22 May 2024 02: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 1s9fQh-0004iR-Fw for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:29 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQf-0006eK-P9 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:27 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:25 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359186; x=1747895186; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=goZvInl61uVRC5qKvio5oLdRwdDHhcN/OMVw305hMug=; b=a9TJ5Qlkr/voEC+gePR92P4GbNgWXnpElFhRAkUqMiYrbXCac2eLIJuE aPaH0Q1fLdTeHJ9QBz34lurtcA36xzwV+idzNFdSMge/pJz4lyUHpJuSh YTkJdK7y5aB/RyxxxFGzM6Fossa5ajlUsvGKpP/Ka0XcgR+Zq9NmF9h0O UmLtLBHHHHuKhItWpfpw5isNJb7Fgc9dxm36Qr5eAj/8evWHiiEXv/8X2 aNvXQvaKtPm33y/ftQUHh/eVQFT3AoCbuswKEP7xBZcuF8NtFHYOb1l6v x/7K/Z/KGk9F96V5BL3BKQqi3Q7Nm4+gfhpUsocSDOTyeyfdmT1NDUSob Q==; X-CSE-ConnectionGUID: sHxjPf7QRcyliJKCu5I5Iw== X-CSE-MsgGUID: A1z4N+euSeGh0k73ruxJNg== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972523" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972523" X-CSE-ConnectionGUID: xjgoX4U7T9ifzGtiKMVNwQ== X-CSE-MsgGUID: JK3yOzy5SLy5PmdbPFcSDQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597772" 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 rfcv2 07/17] intel_iommu: check if the input address is canonical Date: Wed, 22 May 2024 14:23:03 +0800 Message-Id: <20240522062313.453317-8-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359473366100001 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 --- hw/i386/intel_iommu_internal.h | 2 ++ hw/i386/intel_iommu.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index abfdbd5f65..b6820dbca3 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -323,6 +323,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 cf29809bc1..1ea030bfbe 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1801,6 +1801,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 @@ -1912,6 +1913,20 @@ static inline uint64_t vtd_get_flpte_addr(uint64_t f= lpte, uint8_t aw) return flpte & VTD_FL_PT_BASE_ADDR_MASK(aw); } =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); + return !( + (!msb && (upper_bits !=3D 0)) || + (msb && (upper_bits !=3D upper_bits_mask)) + ); +} + /* * 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. @@ -1927,6 +1942,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_fl_level_offset(iova, level); flpte =3D vtd_get_flpte(addr, offset); --=20 2.34.1 From nobody Mon Nov 25 07:35:07 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=1716359511; cv=none; d=zohomail.com; s=zohoarc; b=Uda+OP8Hhs3XZtrbDrxZMAvu3dkw8k1WtbZKySktwgcvC5syiCqul4U8JnosC4VC7v3x4NPOaN30EduwStWdbYANqi8IsRBq6BNcof5CokiXTeM8s3ufnACwWqKoL8if34xYPIqvoZySJYbdGi+MSW3XETj+OyVdcmIiGV732Js= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359511; 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=wh5MhxV2/YR8337JwOJml1hnE1zLjqRo711a0HxXWGA=; b=WvJrYv2aslJ1v83aVeeJBlfPTyLNYFlvIa7OiybNbKdGphFsK1N3vI0KJObXmVVoeCV8AdtJxf9W/vDFfe2bpdkdpLqwuB/FJZmj+kbRLp0RcIas8ZmjHrMqG0+8rd2Wfdgo/6j00YvEKIFVRXI4znhyhM/LePUmAufx64fTelM= 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 1716359511606276.23175883952206; Tue, 21 May 2024 23:31:51 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fQv-0004yI-FM; Wed, 22 May 2024 02:26:41 -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 1s9fQm-0004li-Vs for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:33 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQk-0006eK-Oq for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:32 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:30 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:25 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359191; x=1747895191; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PTpYwvhKNL/GkXgHdnrW7sO+QlTIBmFpWaRFq585gVQ=; b=flyFsdkpc3A+7tQFsMkx1qeSgESuGayuN7C8V/k7J+xd2qtXEuS59R+f LDe3jsraOvNxbEv1ZN/0NFIdWSE6yial35fhENRKx34VK8zdTk69qVDrr +byJMM50+8ehAzY4tW7NAnZVaURl+ev4ewtEGzTazC05s3DKpjhksPD5N vVabE1uLzpNOFSnAe+Gpia8C3NM1pdmJX1PWbOCCUWpc+/IeLL0tCXwdk FM3NEtFzbFQjF+j4AzCpKuz35b2mjZgtjwa7FQ+G+5kQboedxNhmijPqK iotcfyDIzMK9yxLIvW7A0A8FXuCK9+f1Y1dolztk1H+mhrApBVCgZVRmr w==; X-CSE-ConnectionGUID: b8u4kNWzQjeDUg9u0x8hvg== X-CSE-MsgGUID: 6Dyzkp1WTy62Ft//n+/Bww== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972538" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972538" X-CSE-ConnectionGUID: 5VI/SIFPQvGQpuYmbxISpg== X-CSE-MsgGUID: /ur7f/pLTb6RQJvfpe5BPQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597791" 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 rfcv2 08/17] intel_iommu: set accessed and dirty bits during first stage translation Date: Wed, 22 May 2024 14:23:04 +0800 Message-Id: <20240522062313.453317-9-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359513559100007 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 | 3 +++ hw/i386/intel_iommu.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h index b6820dbca3..c0a94af820 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -327,6 +327,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 @@ -547,6 +548,8 @@ typedef struct VTDRootEntry VTDRootEntry; /* First Level Paging Structure */ #define VTD_FL_PT_LEVEL 1 #define VTD_FL_PT_ENTRY_NR 512 +#define VTD_FL_PTE_A 0x20 +#define VTD_FL_PTE_D 0x40 =20 /* Masks for First Level Paging Entry */ #define VTD_FL_RW_MASK (1ULL << 1) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 1ea030bfbe..0801112e2e 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1802,6 +1802,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 @@ -1927,6 +1928,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. @@ -1972,7 +1987,17 @@ static int vtd_iova_to_flpte(IntelIOMMUState *s, VTD= ContextEntry *ce, return -VTD_FR_WRITE; } =20 + if (vtd_set_flag_in_pte(addr, offset, flpte, VTD_FL_PTE_A) + !=3D MEMTX= _OK) { + return -VTD_FR_FS_BIT_UPDATE_FAILED; + } + if (vtd_is_last_flpte(flpte, level)) { + if (is_write && + (vtd_set_flag_in_pte(addr, offset, flpte, VTD_FL_PTE_D) != =3D + MEMTX_= OK)) { + return -VTD_FR_FS_BIT_UPDATE_FAILED; + } *flptep =3D flpte; *flpte_level =3D level; return 0; --=20 2.34.1 From nobody Mon Nov 25 07:35:07 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=1716359429; cv=none; d=zohomail.com; s=zohoarc; b=STbeQeKhEA8xnA+S93See2OnTgDRuaAcFgiGDqaonBYwSfcgIzL+xVfs1nux9V0qzE8WWFj0UXc6VoxxDtVGeu//wk3Zqw44/ZY3ubrz1qpCOKPtIJRnWQv+kgKmHY9m0oIFVhXLK5SZ1oI6/hIc79h0FVdvQ7Um+hMJT4fXl7w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359429; 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=oCZS4WC+l6gE34W7+KwNPPvZ3y7zhkYucRG1cAqoUnA=; b=AapKGRin7h+1NkCHcsvtutGAIFSqJpJwbHQhhCmbhb+pB6Wsis5MYtwNs9Z3GKV0pOP8FlaDR0HsXhp+b7y9nCQNyR7xEX66RTlhTZRPNcuhgDqR4ts/cI9ra2+EV4JAlF/wBVXtEUEVRrMrWxzkWWXylnJh2RcDQ85d53YUm8Q= 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 1716359429237570.4547310992485; Tue, 21 May 2024 23:30:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fR5-00051N-2B; Wed, 22 May 2024 02:26:54 -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 1s9fQs-0004wn-PF for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:41 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQp-0006eK-Su for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:37 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:35 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23: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=1716359196; x=1747895196; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=vE8rkSdU6dEMAH+0MFwIrTelTaY4cA16PyXwyT6nphQ=; b=GuGori3ePDBledBnzEYGFsvLFmmohJX+SvI+Q81JpYnliwt7Uo0cL1jA mmQnlSjxUeJFTLLsPaZYuUIAtLZbgVUtFzPL5rySvCArNF1Hb1EoKfXss LHCUvHOGm/DHUY4TaQbHur+hYPiauDaYwMmXF1wcQWVvV3hCcLXBOYgYQ GfTY1zi91RNsnL23SxSxzr826av+iykuHLKE9ij1MV5E62yyjLWTFTA8N kFcnSwtPWobYslsnWcTX1s5ba8CHyNs81W40MUAXU6Tib2KLDDbmnniNm nKc7Go4jA2/ltVGfDBZXI3m+rFMZygNOdDnLw4TOeOtLDtrYWL9SZq3Ji A==; X-CSE-ConnectionGUID: AYYMSbfVRWWOsoP7pYNkbg== X-CSE-MsgGUID: +M0iWahSQPqLaufdirNYZA== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972551" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972551" X-CSE-ConnectionGUID: i3CxBjhBTG++xFsUmObw7Q== X-CSE-MsgGUID: SlMmBEhAQ3qSTSd+BK7lFA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597804" 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 rfcv2 09/17] intel_iommu: Flush stage-1 cache in iotlb invalidation Date: Wed, 22 May 2024 14:23:05 +0800 Message-Id: <20240522062313.453317-10-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359431131100003 Content-Type: text/plain; charset="utf-8" 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 --- include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 011f374883..b0d5b5a5be 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -156,6 +156,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 0801112e2e..0078bad9d4 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -287,9 +287,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,6 +394,8 @@ static void vtd_update_iotlb(IntelIOMMUState *s, uint16= _t source_id, entry->access_flags =3D access_flags; entry->mask =3D vtd_slpt_level_page_mask(level); entry->pasid =3D pasid; + entry->pgtt =3D s->scalable_modern ? VTD_SM_PASID_ENTRY_FLT + : VTD_SM_PASID_ENTRY_SLT; =20 key->gfn =3D gfn; key->sid =3D source_id; --=20 2.34.1 From nobody Mon Nov 25 07:35:07 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=1716359463; cv=none; d=zohomail.com; s=zohoarc; b=Zt7DZfNWPp6snO6T0Fd3bWu/qV10PWchOdw0I7tgR2hwHbltZa3tb2VK0OtylLGZtQSSg//xsOO8zcTxWHsy20SHgVBbX42pguCwdN28gN8WUDY+m5Zzo5bD4q3bKUKv5tlxdRof61fJymDtqh6LPmqbwFTkreCSyL0wGygW6QU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359463; 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=0O6n7kPzHBO9GWYJ0Tl7+sNGM+pDJYUauEXepeQJ7Kc=; b=gFgrWxWxN9EkcEf4NkG3S3a6c+9AR+N7e7loAbfjD0wyjXt//a4+zKg0Vw0yGaZvkkfxj3lBgqoJCu8C3CeNG3g6xLeo1sfHzTw+sd0adunloWXTURL9nAQafzGIMv5SW+wyxfuiOA5rJlMNYFcJvYn7356oc4zMSxyMt0jiWCg= 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 1716359463695127.18163927145099; Tue, 21 May 2024 23:31:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fRH-0005F0-2F; Wed, 22 May 2024 02:27:04 -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 1s9fQw-00050M-P5 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:45 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fQu-0006eK-L0 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:42 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:40 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23: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=1716359201; x=1747895201; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2KJSZHksRpJmurDXEl7K+Gmaryd8njXwBKxopxGT9Pw=; b=KW/ktIIJgdNUbGfRMj9wVlngw9GKZKabBbRRjRrORg2OV4mQwBEyDzsg tQvuPK3yT8vG+FB2ZJTNKYvB+IQBXd5DEJa6auyt2JojA8HDl1uZPM4Sm huglk7LD8zbKwkhWUDMuNFfYefzW8DhVtA6kzIdnOKJm8zpm+II5EMo6x clLYfn+XJoLfnF/QwXyQERqcNwBy5Cjz4TvmB8KNjGgrTewkZdOuNRQtD n8BehfLeKPUn/Y6nynJdZy0Ez1tHI8ljNh9++HWeEEirMF3uLu+mkoKJE mDjjpuGpDQZ0N8p7ZhIndSAltFod0u0XSIdrkGrLmRBq6zzDnGNFmdrQc A==; X-CSE-ConnectionGUID: Aon7b4aDSFimYPvl0owpOw== X-CSE-MsgGUID: 3cx3ETdMTSK9WO93rCHZ0A== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972573" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972573" X-CSE-ConnectionGUID: CBQ+VyBzQHOM3zQcJpjZzA== X-CSE-MsgGUID: 7YBgPqafRMyBkN+1Sa/B+A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597823" 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 rfcv2 10/17] intel_iommu: Process PASID-based iotlb invalidation Date: Wed, 22 May 2024 14:23:06 +0800 Message-Id: <20240522062313.453317-11-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359465317100023 Content-Type: text/plain; charset="utf-8" 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 --- 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 c0a94af820..8a375d038a 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -453,6 +453,9 @@ typedef union VTDInvDesc VTDInvDesc; #define VTD_INV_DESC_PIOTLB_PASID(val) (((val) >> 32) & 0xfffffULL) #define VTD_INV_DESC_PIOTLB_DID(val) (((val) >> 16) & \ VTD_DOMAIN_ID_MASK) +#define VTD_INV_DESC_PIOTLB_ADDR(val) ((val) & ~0xfffULL) +#define VTD_INV_DESC_PIOTLB_AM(val) ((val) & 0x3fULL) +#define VTD_INV_DESC_PIOTLB_IH(val) (((val) >> 6) & 0x1) =20 /* Information about page-selective IOTLB invalidate */ struct VTDIOTLBPageInvInfo { diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 0078bad9d4..f6c429ae4c 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -304,6 +304,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. */ @@ -2866,11 +2888,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)) { @@ -2887,6 +2928,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 Mon Nov 25 07:35:07 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=1716359460; cv=none; d=zohomail.com; s=zohoarc; b=FJnq/ynr5PFutsFBgvV0GvTp5CeWAxZyPknXePNHiIz9ZO3fty6vqtYTScBc0QrqEOeUXkgLM5udnI30/pp6eJWuMZR/0l4QrPyuNOKp+GBXXfqKXQajGTemoRuxdDscWEgxYZWsx1I/+n11nMfRJKFoVOkA8UUVj7GuyjXZXRY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359460; 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=aIcLp+/WQ0lfw0N1IWAK9y1h+GUwMdrKKGtcMN/URcU=; b=Y5SVwTft126Uns66mP1FB95sJr7IL5og9bup48PX+fK8mor1vZAmA6wauHfQffxPquxw1osQ6mL/76H9+I9Pl7nQBh43Ph2twSlNg/JFtqU1HvgUxjX/yMPmddVi07kT9TFcwX4VPYYWXqMGQGjO1t3wMWVjizKjKLkXfgCyBn0= 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 1716359460943262.86739702738305; Tue, 21 May 2024 23:31:00 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fRO-0005hh-Rp; Wed, 22 May 2024 02:27: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 1s9fR2-00052A-MP for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:50 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fR0-0006eK-S9 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:48 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:45 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23: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=1716359207; x=1747895207; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PywuVHJo6MudZYuNud+3f7D1VlMyEmDMUVp3O2ronZo=; b=Msb04GtLO4iVLkxaShzeq1h6Dnkn0sgdflApO2WoyjHK6KZsNeafkguJ tM+BOI8qJN1XpG4xIGXp4TiteqLT8G4wN/AM7E2BXduLpnhkPZ2y0m0LT edd1E9ZMjdK7te+MIP0OhvKB9mTI3JIoHbG9x2a65N4h4Hl2T94pj1LC3 Yunba1JP1rvfUrxizNblMGZ1r/s7SroEwEshuesIu735Vtq6ZQABh1v7o B1rN350mc1RZm3cGLBJJZF83YSgKB64n+Q6Nr2OIilxTEdJwcwHdqHmmg OomN5K0Wa1h2Agf4HewkXuotL3UNtr+au76otXsa3iqZXtqXSUibDS4AZ g==; X-CSE-ConnectionGUID: K8x6VxAeR0y/qDdFISIPUQ== X-CSE-MsgGUID: CkGkJQpfRIioEdfd5OaiPA== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972598" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972598" X-CSE-ConnectionGUID: sK/wx7g0RHuybRbUvu6qhg== X-CSE-MsgGUID: HK9q6lR9S4aiY1zhbTU+Tg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597830" 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, =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhenzhong Duan , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PATCH rfcv2 11/17] intel_iommu: Extract device IOTLB invalidation logic Date: Wed, 22 May 2024 14:23:07 +0800 Message-Id: <20240522062313.453317-12-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359461333100017 From: Cl=C3=A9ment Mathieu--Drif This piece of code can be shared by both IOTLB invalidation and PASID-based IOTLB invalidation No functional changes intended. Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: Cl=C3=A9ment Mathieu--Drif Signed-off-by: Zhenzhong Duan --- hw/i386/intel_iommu.c | 57 +++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index f6c429ae4c..3c14fd85cc 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2955,13 +2955,43 @@ static bool vtd_process_inv_iec_desc(IntelIOMMUStat= e *s, return true; } =20 +static void do_invalidate_device_tlb(VTDAddressSpace *vtd_dev_as, + bool size, hwaddr addr) +{ + /* + * According to ATS spec table 2.4: + * S =3D 0, bits 15:12 =3D xxxx range size: 4K + * S =3D 1, bits 15:12 =3D xxx0 range size: 8K + * S =3D 1, bits 15:12 =3D xx01 range size: 16K + * S =3D 1, bits 15:12 =3D x011 range size: 32K + * S =3D 1, bits 15:12 =3D 0111 range size: 64K + * ... + */ + + IOMMUTLBEvent event; + uint64_t sz; + + if (size) { + sz =3D (VTD_PAGE_SIZE * 2) << cto64(addr >> VTD_PAGE_SHIFT); + addr &=3D ~(sz - 1); + } else { + sz =3D VTD_PAGE_SIZE; + } + + event.type =3D IOMMU_NOTIFIER_DEVIOTLB_UNMAP; + event.entry.target_as =3D &vtd_dev_as->as; + event.entry.addr_mask =3D sz - 1; + event.entry.iova =3D addr; + event.entry.perm =3D IOMMU_NONE; + event.entry.translated_addr =3D 0; + memory_region_notify_iommu(&vtd_dev_as->iommu, 0, event); +} + static bool vtd_process_device_iotlb_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc) { VTDAddressSpace *vtd_dev_as; - IOMMUTLBEvent event; hwaddr addr; - uint64_t sz; uint16_t sid; bool size; =20 @@ -2986,28 +3016,7 @@ static bool vtd_process_device_iotlb_desc(IntelIOMMU= State *s, goto done; } =20 - /* According to ATS spec table 2.4: - * S =3D 0, bits 15:12 =3D xxxx range size: 4K - * S =3D 1, bits 15:12 =3D xxx0 range size: 8K - * S =3D 1, bits 15:12 =3D xx01 range size: 16K - * S =3D 1, bits 15:12 =3D x011 range size: 32K - * S =3D 1, bits 15:12 =3D 0111 range size: 64K - * ... - */ - if (size) { - sz =3D (VTD_PAGE_SIZE * 2) << cto64(addr >> VTD_PAGE_SHIFT); - addr &=3D ~(sz - 1); - } else { - sz =3D VTD_PAGE_SIZE; - } - - event.type =3D IOMMU_NOTIFIER_DEVIOTLB_UNMAP; - event.entry.target_as =3D &vtd_dev_as->as; - event.entry.addr_mask =3D sz - 1; - event.entry.iova =3D addr; - event.entry.perm =3D IOMMU_NONE; - event.entry.translated_addr =3D 0; - memory_region_notify_iommu(&vtd_dev_as->iommu, 0, event); + do_invalidate_device_tlb(vtd_dev_as, size, addr); =20 done: return true; --=20 2.34.1 From nobody Mon Nov 25 07:35:07 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=1716359465; cv=none; d=zohomail.com; s=zohoarc; b=QFUkhaVY58JCqs4W6oW649czk/eJJbPLZUrDlun5Nqfx+xct1E67jbtti49fGbhJKAhoYUCQf7Ats1tN6E++aTTkBouFSRlANST+XLas8JV4sytJJ4M0kE8uIod3Ntbb6wmFC1qr0RktC1KplzSJYny90Q8e9kpUZAFFpe2haK4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359465; 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=RhYJI8COIpPNfKnytqH7xP1Nx2ryFNnZdj70KtVV01Q=; b=efQNFUZQNOnuMnu2QKCzkuNQKyhz2qOQfAymJPbufhDBQ0bv3Tv9hK1V9x/oH1Hvzs3ErLJCpNUDl2fY3hCdZML058IhRDx3JKE7hcWaZkkPvupGU1CRw9lRY7DWwAvpqsfukMvzL81+h1CsgLI8dLnohln6rh6xr9CDWjF7y7k= 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 1716359465578845.4631949885901; Tue, 21 May 2024 23:31:05 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fRK-0005WF-Hk; Wed, 22 May 2024 02: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 1s9fR8-00054W-La for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:55 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fR6-0006eK-SQ for qemu-devel@nongnu.org; Wed, 22 May 2024 02:26:54 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:50 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:46 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359213; x=1747895213; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=DY3OmG2gHlQPppQdopy00y0xEFseCiOLCfJ5psDQUwU=; b=ZFMdVLIpAhzOUvlvvg3pEeJo5GqFxosDu+czit8Yypv9pHu+IVDji+nd iBfWxeRAQ1YAYOAJcP0PDs+hMhTDTwd1d2s06O18G31QIp8DHKUNhRCoK rZrtZJb+E2KdL6dksM9wF4tgNtXKTAbjw4Dz88UrnbwOCR/spWt5ASJXx ZkGAlR0prRMDQqYJRK22+cliWujdODOa8jlIvOLQO+w2A/lh+zVvlBgvy IZ/4C9ops4a29QYsiIHQWxXO/EaFgnNVX4DQnyoY3Wu9S13MRFrsZwveQ AbIvqa5AO9Q3VobJdMs1skOg7b7Ubp8GoDMJ8HkID9ovaQpcD4mwmCyax w==; X-CSE-ConnectionGUID: MopFzDKkRdGO2X/ci+TBCQ== X-CSE-MsgGUID: O33qt5jTRhq+UzzOEq8SPw== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972639" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972639" X-CSE-ConnectionGUID: enyxv5BTTfKgcWqnTw1+JQ== X-CSE-MsgGUID: SgSG/ksCQfiEncqm6sRMUw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597870" 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 rfcv2 12/17] intel_iommu: add an internal API to find an address space with PASID Date: Wed, 22 May 2024 14:23:08 +0800 Message-Id: <20240522062313.453317-13-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359467383100027 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 --- 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 3c14fd85cc..7ae8df2f49 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -64,6 +64,11 @@ struct vtd_as_key { uint32_t pasid; }; =20 +struct vtd_as_raw_key { + uint16_t sid; + uint32_t pasid; +}; + struct vtd_iotlb_key { uint64_t gfn; uint32_t pasid; @@ -1856,29 +1861,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 Mon Nov 25 07:35:07 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=1716359455; cv=none; d=zohomail.com; s=zohoarc; b=L+MYaCLPTQAgk8BhGHHknlycTGE869TxRftpVWLWZN2EIHaFbUlVBpdhwXG2OLYWOhnJr7U1dADZI3a9HhDLkQeIbHRlr1w4tZBN0IWoP5jwxr98O9nq//hKT21u5jlmM56ckasMuS7AT2C3bwZw7+ALxq164VBWWwAWFzMl1+M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359455; 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=1Rf6yrWLu9m1sN0QCkS2/VeUBBssCEfKN75rS6OsGKc=; b=LdQrlWiySwriIjm8Rowuwno9UCZp3LRuxpEKTzGxPXfPWHHagWv9V/6fydZCSoZKa3se1whD8HHkhTnRq91/dsrbUvwvOX92BpGtgyZMac5zfVESFBFGnp+LH93SiW6PGkA20e/VDHQe8hEDYPmdNuSoz34GzgfoXgQv7ydd/PY= 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 1716359455654624.6918019236067; Tue, 21 May 2024 23:30:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fS1-0006jT-0N; Wed, 22 May 2024 02:27:55 -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 1s9fRL-0005Xh-57 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:08 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fRA-0006eK-CT for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:04 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:55 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:51 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359216; x=1747895216; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=z9khbUCc5VNyOxUeFYO0mj/DGw0TvLCaSAfPG0hqVeQ=; b=SMjjwUtTKaIFbrIE/6p7+YtB+alWjyyClWVXqamO2HrGqG7Fs+BLu7wb alST2WNLlirl70Tyk9IYIV+FkLkwN2rimAug+5xzLI2pv2M08oBK9Ni4+ refxSqf1uGWsNJHuohEx8Gdo5DdZ3I91qnq5D5D8a0N6XKwuGYXgMdbOa XCtB7wCwwEoSeGVthYCOvoAOQfPl8ZbEAwQAqPT4xhCB/90uGfVd1HHnf jTVijO12csMyree95zOHUleTMXb+gWbTPsUpTst/nJE1UAMET2ZNMi26y qIcswSgXvmm3o4KPOa7K/WdOagupvgWb5Abd7ADdVvuwikd7ZwI/jOG7i w==; X-CSE-ConnectionGUID: oI3WBwCKSima7cggKYaKgw== X-CSE-MsgGUID: 1JcddY3ORWukx8fvj7mPOQ== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972681" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972681" X-CSE-ConnectionGUID: FW+kQK8oRXS65aQ+JEZdrw== X-CSE-MsgGUID: 9dmoY6reSv+NIJ7QQC22fw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597910" 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 rfcv2 13/17] intel_iommu: add support for PASID-based device IOTLB invalidation Date: Wed, 22 May 2024 14:23:09 +0800 Message-Id: <20240522062313.453317-14-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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: 1716359457249100011 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 8a375d038a..5831aa4d82 100644 --- a/hw/i386/intel_iommu_internal.h +++ b/hw/i386/intel_iommu_internal.h @@ -378,6 +378,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*/ @@ -421,6 +422,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 7ae8df2f49..de4e8afcf9 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2996,6 +2996,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) { @@ -3090,6 +3133,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 Mon Nov 25 07:35:07 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=1716359515; cv=none; d=zohomail.com; s=zohoarc; b=Pf2ZOzLzSSlGW3MXlPNKNoB2BQ1lY5/ZseNeKfHPCKOHRhUq/suyWO/0VbdERM6XKhIqDEMPp+qED6A17gIyerK1XIQfDXxIiagUT+4gTA8rW8sHQXv1iyqk6tP3nm/AmElUvSACc6mWGl4ThPg80GzPvpO83QfED7Mqyb2FzIc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359515; 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=a6sZCV3LY/SaN39LnM6IOYA9WCBtQ5uK+34RpgK7N4A=; b=I+rmS1a/7ZQfKaCqQZyuozYH+5AZb0o8ZikBsvvBZxrJRDwTqGhtxpZpgltIJz653eo3zpsEfhnwOi450wH7OBjJWxHAHI6UPRfVPm3s/Ye3QUdS8BC31mEuG6xyp71fpBk9bbBgWaAj9bpgXL6OSpf7AjyB5AjWMtRxgKpLzt4= 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 1716359515054169.7615129960093; Tue, 21 May 2024 23:31:55 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fRv-0006RU-7E; Wed, 22 May 2024 02:27: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 1s9fRI-0005UD-C0 for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:04 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fRG-0006je-7J for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:03 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:27:00 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:26:56 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359222; x=1747895222; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=MvDqM9kfp1JUceyLOpnfxHWaYOB5yCLfdRu6z6ix0uE=; b=Mv9d9BmPvGxue1GDEYH/3HS0YswicCg0V2PSaXtvU61yqg5BY+syYzTJ C6O0ft4rHTM9O1OmNjMsYkc527TpcMYrljtIdv99JcpDIJBLqa7lQ5e8W v3BSMRFlUufBLsO81DWD6J6MPhOZsOaaMlq5/Rs5g9yIj2iqYjIjCp5NB KFY7ZyrYd2rCXyKj1L15zI2xQL3+bj0v2c7wx28/F964/FGPBTNgtoqEL JixpKwCyhZFU9WZr8+cDtNQ0UOOF0rHYHI8pTSZ/WvMd+xom0A+ALVCkx nRXWR3ucIH0yaigDj0wJfNGxmb4yHP0H9KtENfAYqggSJkHTt+QQLrz3C w==; X-CSE-ConnectionGUID: m7yLMZqURTSzc72VVZ6QNA== X-CSE-MsgGUID: r91qBpaUT9KQ3WHL0Mhpmg== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972709" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972709" X-CSE-ConnectionGUID: /oHbJ0bmSHKClRD1Qcfdjg== X-CSE-MsgGUID: bQIQB1kbQjulb/D3IopSaw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597941" 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 , Yi Sun , Paolo Bonzini , Richard Henderson , Eduardo Habkost , Marcel Apfelbaum Subject: [PATCH rfcv2 14/17] intel_iommu: piotlb invalidation should notify unmap Date: Wed, 22 May 2024 14:23:10 +0800 Message-Id: <20240522062313.453317-15-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359515762100001 Content-Type: text/plain; charset="utf-8" This is used by some emulated devices which caches address translation result. When piotlb invalidation issued in guest, those caches should be refreshed. Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- 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 de4e8afcf9..e07daaba99 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -2890,7 +2890,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); } } @@ -2902,6 +2902,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; @@ -2912,6 +2915,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 Mon Nov 25 07:35:07 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=1716359452; cv=none; d=zohomail.com; s=zohoarc; b=frVmH6Knfi9LiFjcPEfAlmZ4//41ZvLcCKsxn684PgPGma2WBK93kXNpC5feceDKaWN1apI1Snn8iB56J125CbuDJvzBC0ADSX9PG4X0wJ2C6S7Sl36GqMeIG6inYxzN0W24ODuDcTiKVwCW+gVQue4ithBhKyUb1MYWOwkQZYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359452; 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=sK17AonbvMdBhQkM/g5pO5qWEYgH+Uy+WpPQaqTXaO4=; b=JWcoMPmbAy8W7DkQjdexY1R+dOEBN0IqFjo/R+T/gzCwlapBVS6yIYwL3MAra2XI1UcVW5E/bp8s+GUNenwX5GyV4gSezubgKEF8Ojnyt+JYPvl0gb+uPH7q0arXJQ4O0Ei6mmjHCVHGI+P2WIFoC4T29E7mZi+ZwsoGcuLZOIw= 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 17163594527841018.287987011962; Tue, 21 May 2024 23:30:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fSi-000789-53; Wed, 22 May 2024 02:28:32 -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 1s9fRO-0005hx-0J for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:10 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fRM-0006jy-8n for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:09 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:27:06 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:27:01 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359228; x=1747895228; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=jvy+iy1hOkE9h3oLFlev3YfseKo4APjCUCxIGJhkwOo=; b=Rwax7vnu2j6i4hqZfx6O9pJJlK7g8LxZ0gHKxsxmUU7v05TZ8n1QJEda ujrGLYKmzYhqG/qhJZa463Pgh/D/gsBUf6Jez8lfZfYM+By4qRbulhM++ dl5Qtk7zR4A7MELUQuzwpQHc4yi23ohY6RORHp7YOLQqLx7faDesfVR2/ SRPhZMFqus+XARA3y1liNnY0MX0AoOQJn/ab2dIchgEqU8stSxtdGco8g KmnXXP82WiOdtEi4hj6p8Lu09Lh+kdFeS8s0KjYA+525oBVhKpzAZwCVR acHsuQ5dxRNHJAFR8LUJDVLdzRSGGc1o9nBOfW4mNBOjQyDxRzo7zU5GY A==; X-CSE-ConnectionGUID: 2aoXNAvURCeYjlFipdvLMw== X-CSE-MsgGUID: xQndOPgcTrikIgY+2SAEPw== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972750" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972750" X-CSE-ConnectionGUID: 0UlVAaF3ThGmkBwwwqO5lg== X-CSE-MsgGUID: XihXTWhITxeUlgtwRj7Vpg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33597978" 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 rfcv2 15/17] intel_iommu: Set default aw_bits to 48 in scalable modren mode Date: Wed, 22 May 2024 14:23:11 +0800 Message-Id: <20240522062313.453317-16-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359453262100001 Content-Type: text/plain; charset="utf-8" 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 --- hw/i386/intel_iommu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index e07daaba99..a4c241ea96 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3748,7 +3748,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), + 0xff), 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), @@ -4663,6 +4663,14 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) } } =20 + if (s->aw_bits =3D=3D 0xff) { + 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) { @@ -4671,6 +4679,12 @@ static bool vtd_decide_config(IntelIOMMUState *s, Er= ror **errp) return false; } =20 + if ((s->aw_bits !=3D VTD_HOST_AW_48BIT) && s->scalable_modern) { + error_setg(errp, "Supported values for aw-bits are: %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 Mon Nov 25 07:35:07 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=1716359452; cv=none; d=zohomail.com; s=zohoarc; b=HJ1lTBaX28cg0pWtx9i/pP+tPZ6zq313a6wK90pIVMa6TnY6RK3k1+HHJV69m6KlGEauhmI/G1zQVzESRDAr1DPOAchrhw24EOmWO0Bl2H0rcVgNR/ZObnayrEIPBdH/gh0SGn8tIWiaP1kpQBx67WhXh0plOgGgIM7XKaWt8p4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359452; 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=Dlh/06UKwIXodtvgAsXzXeX2iJJD7AiPq1b0K5lKUM8=; b=aFT2DdpKIw3PX/PHDcRfV41T78PodKu0x2v3abLvRBhjXbp6MSE06qg/YytUaJrTJwtQE4eOmB8YTWrgQz61N+0X6+fRcfFbzOpeNK9eWhTTMthgi4XJK3i8eR+RcOVpA8jeeDWfrOL/nmLNnTo70MhlBA1OC4VYH8RZuhA/fy0= 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 1716359452896228.38844823416684; Tue, 21 May 2024 23:30:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fSn-0007IE-2I; Wed, 22 May 2024 02:28:37 -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 1s9fRU-0005ny-3t for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:19 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fRR-0006jy-0I for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:15 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:27:12 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:27:06 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359233; x=1747895233; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1OS5SSIJv4L2XO7cycsnJ2tgbCdBTv0xT1j9iZpLEMo=; b=REWT5AgSbNWkpSqE9XXIYD+Yd2On6wrcKYilzU2zS4K9FMJ/AsZCwySB d5oDBh3W8OMvbSOVuJ0noGw/iilkE/W0IX3XrGydGF20Mb0CHmSSCK0hH ruB0mUhLD+v3UFz+XqTkFL30+xGCLcxI6qE83Y7s29qF0JCpZDzbIUjJN etsUJMtB+6T8bXvIb9y77nuMhOCnniiywCbX9+DvnxUo3tdA+8eQQg2OW t5As5PB490RvMd6c7lxCHSpQoeyWC4052jAEFMAMxsbW05CFXZykCyKjc gAGDVpSI/9Oknfif0kOUg7u/rK3I/b+QahI+y1F3lL7a1oHaJER6lIBh6 w==; X-CSE-ConnectionGUID: L/qh0eKITgKLIFGTmyfJcQ== X-CSE-MsgGUID: W2aaVkUfQLmoBeeHEVEVUQ== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972792" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972792" X-CSE-ConnectionGUID: 2aH0temHQQ6JUe+wJnaXQA== X-CSE-MsgGUID: fYR5G0UzSguTCIMgwNjZDw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33598022" 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, Yi Sun , Zhenzhong Duan , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost Subject: [PATCH rfcv2 16/17] intel_iommu: Modify x-scalable-mode to be string option Date: Wed, 22 May 2024 14:23:12 +0800 Message-Id: <20240522062313.453317-17-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359453268100002 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 - if not configured, means no scalable mode support, if not proper configured, will throw error Signed-off-by: Yi Liu Signed-off-by: Yi Sun Signed-off-by: Zhenzhong Duan --- include/hw/i386/intel_iommu.h | 1 + hw/i386/intel_iommu.c | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index b0d5b5a5be..dd032b1081 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -264,6 +264,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 a4c241ea96..1bd91fcf4c 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -3750,7 +3750,7 @@ static Property vtd_properties[] =3D { DEFINE_PROP_UINT8("aw-bits", IntelIOMMUState, aw_bits, 0xff), 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), @@ -4663,6 +4663,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 0xff) { if (s->scalable_modern) { s->aw_bits =3D VTD_HOST_AW_48BIT; --=20 2.34.1 From nobody Mon Nov 25 07:35:07 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=1716359474; cv=none; d=zohomail.com; s=zohoarc; b=ADVdp8tqHxyLCjykuB06lhib7iUN75nnmrT9ndrNx3PiBJIEO30ODIPOkTM+Ml+z4YJZ9VW0qYvEfxunyis3bKuCl0T4o652dAiKhOOLODqUYs9BDMWJWg3WJEmTwvd3zWkXMipiWCYSiXP9/CvkCClYlfkPxIcz37BOJQUTMe8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1716359474; 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=TypvKu98eFxyHbUSwFp/ce5pjSMVoEvpqSEuBt8ILnw=; b=Z8NBoOfFtZxalBjognHO+wc5nuLM8cjKktmMVMsl0+9A+TygS3G6LiUlIYYJEQwfVLZvShx17Trq1BU7Y5Ivk7WWcq7+nRjzl5kEAOwpGDaIHzUVJmJsGyG+4iKL9D7slx5N9q1xwTF1Afc1oL3/OIR6QADJexJOeiWY9W+Fldw= 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 1716359474406998.6675207584707; Tue, 21 May 2024 23:31:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1s9fSK-0006lT-5j; Wed, 22 May 2024 02:28: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 1s9fRY-0006B9-Mk for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:24 -0400 Received: from mgamail.intel.com ([192.198.163.7]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1s9fRV-0006jy-Cm for qemu-devel@nongnu.org; Wed, 22 May 2024 02:27:20 -0400 Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:27:16 -0700 Received: from unknown (HELO SPR-S2600BT.bj.intel.com) ([10.240.192.124]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 May 2024 23:27:12 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716359237; x=1747895237; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XbvGY/yne5qZRRsCJ3DXqnpyiiOKvycEPODgYdQNGng=; b=KGlFWB9OXKiT36X85rfIaEwagZVNEpANZuo9g6bs82od/RBion+fWBdF Gj+O9jr3+H4l1wB1nsNQqg98V6jzAAT+GUHJaVnXHPOSeC1Xp9nmRiFmn eSilgzzOlftm/px1eu0O9eTDfdwpFneiZUq8My+CkwmX6kOMxRJfnLQKY H0EPn3SzleM64QZRX3NHYrE0D99qsOWT/Z3QbB59NVI97xvlT7ZHzfyaV AE+EUbewYn88511qcKIoUUdAf6urWnjVdY6Qmm1c5kWoLv+2dbAAZx4Rp cF1VwaPXndAr4Y+SEj2psRhgVKDYBCArZrfb2c7pOV0wTsAvTS1xWC66L A==; X-CSE-ConnectionGUID: puCGhZElRbew4Qux4MF3OA== X-CSE-MsgGUID: AVsgMcb/Sum/LAEx0rYrbA== X-IronPort-AV: E=McAfee;i="6600,9927,11079"; a="37972807" X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="37972807" X-CSE-ConnectionGUID: 7Tb3TMLsTbW7HlXetnm/mw== X-CSE-MsgGUID: YUO8KYBgQyumG4tl7z/J8Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,179,1712646000"; d="scan'208";a="33598064" 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 , Laurent Vivier , Paolo Bonzini Subject: [PATCH rfcv2 17/17] tests/qtest: Add intel-iommu test Date: Wed, 22 May 2024 14:23:13 +0800 Message-Id: <20240522062313.453317-18-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240522062313.453317-1-zhenzhong.duan@intel.com> References: <20240522062313.453317-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.7; envelope-from=zhenzhong.duan@intel.com; helo=mgamail.intel.com X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: 1716359475350100007 Content-Type: text/plain; charset="utf-8" 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 --- MAINTAINERS | 1 + tests/qtest/intel-iommu-test.c | 63 ++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 3 files changed, 65 insertions(+) create mode 100644 tests/qtest/intel-iommu-test.c diff --git a/MAINTAINERS b/MAINTAINERS index 5dab60bd04..f1ef6128c8 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -3656,6 +3656,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/tests/qtest/intel-iommu-test.c b/tests/qtest/intel-iommu-test.c new file mode 100644 index 0000000000..e1273bce14 --- /dev/null +++ b/tests/qtest/intel-iommu-test.c @@ -0,0 +1,63 @@ +/* + * 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-single.h" +#include "hw/i386/intel_iommu_internal.h" + +#define vtd_reg_readl(offset) (readq(Q35_HOST_BRIDGE_IOMMU_ADDR + offse= t)) +#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_IRO | VTD_ECAP_MHMV = | \ + VTD_ECAP_SMTS | VTD_ECAP_FLTS) + +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; + + qtest_start("-M q35 -device intel-iommu,x-scalable-mode=3Dmodern"); + + g_assert(vtd_reg_readl(DMAR_VER_REG) =3D=3D 0x30); + + cap =3D vtd_reg_readl(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_readl(DMAR_ECAP_REG); + g_assert((ecap & ECAP_MODERN_FIXED1) =3D=3D ECAP_MODERN_FIXED1); + g_assert(ecap & VTD_ECAP_IR); + + memread(Q35_HOST_BRIDGE_IOMMU_ADDR, init_csr, DMAR_REG_SIZE); + + qobject_unref(qmp("{ 'execute': 'system_reset' }")); + qmp_eventwait("RESET"); + + memread(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_end(); +} + +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 6f2f594ace..09106739d2 100644 --- a/tests/qtest/meson.build +++ b/tests/qtest/meson.build @@ -79,6 +79,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