From nobody Tue Nov 26 00:37:05 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 243F615B0EC for ; Wed, 23 Oct 2024 08:41:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729672861; cv=none; b=cKwD+yHbn12O1mBKSj3oR73Um6daKbEnHVT+TpOAeGMk4AZ9cXZuGSuQp2zFyTl+KQKHxIsAJU94xyB4J034XEUR17J+CzHHXPzZ+z/oDV6a0KtioGx6b3gF6tK2PY9naQZ7gUpND0rGXWbjEV5T5/e1f+6hLEo8AS8jk87M/gY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729672861; c=relaxed/simple; bh=TKfb3FYCYQ9R4HYL6swULU5MIrnn5Cj8544DnGCTNMs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uQBRARYeSsUKf/+KhWV0oNZJpOUsn0LGsuD/qmHGcvCwCYD2qXDLrQlu4i/xZ0BAUATbqW0EjBnjkU3vWgIJu+O6SH/bJmEMoxULIG1uUV67HxBaOSMe4BNf9oRPRnE/rHG3G2jLXmh1YduTd8WnG1reLsTL4EV3bTKAMBQyp1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=K2LaB2Ga; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="K2LaB2Ga" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729672860; x=1761208860; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TKfb3FYCYQ9R4HYL6swULU5MIrnn5Cj8544DnGCTNMs=; b=K2LaB2GaYNJF7ftXQFtHG90DX5ArNrm//U15BU7w5Jg9Jhqu+RH4DUwQ ZP8Ui+daqnvKlkGfeyL7WPIX9F/5Apzqme1bURA1fWt8R3uI3IKnZbZ1J dcu8lzg3b7R/L1rbD5ST6kDrH8B2bU2nyQoX8eHIqIAnfahz3JJ2AS/G/ UyKqynShVgsGYH8uQZ7rob6O8TMj42Tyn1y5oxh/NRTORY6LTWk2mNVc4 hTXOMZF5B3SLj1HXBwAzH8crIA/EtkYaDdnOqYnY2kbA+sd2fXRcOT0d5 CuPFeQKrem/qMao9tL5Vqi1utnJnFuIQ92O262F10LSTCZd0OfqXrCMI/ g==; X-CSE-ConnectionGUID: owzXBRydQ9SDo6T3JRupBg== X-CSE-MsgGUID: 8eRIm6RYRpOCQSLWUu3Jvg== X-IronPort-AV: E=McAfee;i="6700,10204,11233"; a="32108928" X-IronPort-AV: E=Sophos;i="6.11,225,1725346800"; d="scan'208";a="32108928" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2024 01:40:55 -0700 X-CSE-ConnectionGUID: izdtrW4jQui9uoZNttvzlg== X-CSE-MsgGUID: Ll37NpZ0SEaUlz7oTass9Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,225,1725346800"; d="scan'208";a="80048654" Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2024 01:40:52 -0700 From: Zhenzhong Duan To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: dwmw2@infradead.org, baolu.lu@linux.intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, chao.p.peng@intel.com, Zhenzhong Duan , Kyung Min Park Subject: [PATCH v2 1/2] iommu/vt-d: Fix checks in dmar_fault_dump_ptes() Date: Wed, 23 Oct 2024 16:37:14 +0800 Message-Id: <20241023083715.582149-2-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241023083715.582149-1-zhenzhong.duan@intel.com> References: <20241023083715.582149-1-zhenzhong.duan@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In dmar_fault_dump_ptes(), return value of phys_to_virt() is used for checking if an entry is present. It's never NULL on x86 platform at least. This makes some zero entries are dumped like below: [ 442.240357] DMAR: pasid dir entry: 0x000000012c83e001 [ 442.246661] DMAR: pasid table entry[0]: 0x0000000000000000 [ 442.253429] DMAR: pasid table entry[1]: 0x0000000000000000 [ 442.260203] DMAR: pasid table entry[2]: 0x0000000000000000 [ 442.266969] DMAR: pasid table entry[3]: 0x0000000000000000 [ 442.273733] DMAR: pasid table entry[4]: 0x0000000000000000 [ 442.280479] DMAR: pasid table entry[5]: 0x0000000000000000 [ 442.287234] DMAR: pasid table entry[6]: 0x0000000000000000 [ 442.293989] DMAR: pasid table entry[7]: 0x0000000000000000 [ 442.300742] DMAR: PTE not present at level 2 Fix it by checking present bit of an entry before dump its content. Fixes: 914ff7719e8a ("iommu/vt-d: Dump DMAR translation structure when DMA = fault occurs") Signed-off-by: Zhenzhong Duan --- drivers/iommu/intel/iommu.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index a564eeaf2375..8288b0ee7a61 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -733,12 +733,17 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, = u16 source_id, u8 devfn =3D source_id & 0xff; u8 bus =3D source_id >> 8; struct dma_pte *pgtable; + u64 entry; =20 pr_info("Dump %s table entries for IOVA 0x%llx\n", iommu->name, addr); =20 /* root entry dump */ rt_entry =3D &iommu->root_entry[bus]; - if (!rt_entry) { + entry =3D rt_entry->lo; + if (sm_supported(iommu) && devfn >=3D 0x80) + entry =3D rt_entry->hi; + + if (!(entry & 1)) { pr_info("root table entry is not present\n"); return; } @@ -766,28 +771,32 @@ void dmar_fault_dump_ptes(struct intel_iommu *iommu, = u16 source_id, goto pgtable_walk; } =20 + /* For request-without-pasid, get the pasid from context entry */ + if (pasid =3D=3D IOMMU_PASID_INVALID) + pasid =3D IOMMU_NO_PASID; + /* get the pointer to pasid directory entry */ dir =3D phys_to_virt(ctx_entry->lo & VTD_PAGE_MASK); - if (!dir) { + dir_index =3D pasid >> PASID_PDE_SHIFT; + pde =3D &dir[dir_index]; + + if (!pasid_pde_is_present(pde)) { pr_info("pasid directory entry is not present\n"); return; } - /* For request-without-pasid, get the pasid from context entry */ - if (intel_iommu_sm && pasid =3D=3D IOMMU_PASID_INVALID) - pasid =3D IOMMU_NO_PASID; =20 - dir_index =3D pasid >> PASID_PDE_SHIFT; - pde =3D &dir[dir_index]; pr_info("pasid dir entry: 0x%016llx\n", pde->val); =20 /* get the pointer to the pasid table entry */ - entries =3D get_pasid_table_from_pde(pde); - if (!entries) { + entries =3D phys_to_virt(READ_ONCE(pde->val) & PDE_PFN_MASK); + index =3D pasid & PASID_PTE_MASK; + pte =3D &entries[index]; + + if (!pasid_pte_is_present(pte)) { pr_info("pasid table entry is not present\n"); return; } - index =3D pasid & PASID_PTE_MASK; - pte =3D &entries[index]; + for (i =3D 0; i < ARRAY_SIZE(pte->val); i++) pr_info("pasid table entry[%d]: 0x%016llx\n", i, pte->val[i]); =20 --=20 2.34.1 From nobody Tue Nov 26 00:37:05 2024 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 51A0815852F for ; Wed, 23 Oct 2024 08:40:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729672860; cv=none; b=fROdjAGrN/AbryZmVaz94s+lMr+5dVbTzF31XrYpNbdfJpZri9GwEyARqz5oazdXHcHPE7lCFaaiBDl+mN/qSigSzId8iKucBDDV0lhgBAB4vD5rHFF7FSB4d2x/23GZLUXzt9SPlDigfxfET7GrU6YvHBbh4V/eVAIeaQ8g3fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729672860; c=relaxed/simple; bh=1xgmr/Jdzs7NSnAqqcZTvBWcfjR/pYYOZT4P/xKMir8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=u3djClaMLMJE5m4930OlfzoTE7qj9Xv0+RcxBZ93bCzCGpdWJolKcMPKlEniQpI4jndGfB1ta7jz8X4vInmTjLX3r0ZxCdLkZGBTdggmMU7icq1X4Orbi5xKC/Gs2jPdhZbg5us1D4t3+rLvIt+FdjN1+wR10bOMvrdV/XqIzXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=lw7vBMGT; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="lw7vBMGT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1729672858; x=1761208858; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1xgmr/Jdzs7NSnAqqcZTvBWcfjR/pYYOZT4P/xKMir8=; b=lw7vBMGTkB2WQCLvv4q6B2Dxyl7LqLdPZqpppW/g4nC/7LCR3eV+gaEr iWFrdYnYxHcmz4jmDrUoDDJDq2A4L8p60JnsVXy/l+8ikkGzy8VN2gH4P n0IWVwGgQ9SejCb4U0c4sRH+QGsvkjC7wxp6ripFD91G2tcqUv69DNvk6 Nq49Z3sYnpM9goAbje9rrG2j5vNiZFexqcn8kIE3dMDEKsHRPTBCeP9iN XKw06WwKu4RU7LUFoAvUuyOjdFWIgcK3nUcmBLzd0kBeZYgQMl78xZkyu 0JBLIgB9hsLo8er2+qOksnmQZpBMsxWRKS61Evhu6yUkgIzCXdrpT6n/R A==; X-CSE-ConnectionGUID: jGQEDmeLTJu26fPubr674Q== X-CSE-MsgGUID: YA35rlZ7Ta+g+frQIVnAMQ== X-IronPort-AV: E=McAfee;i="6700,10204,11233"; a="32108934" X-IronPort-AV: E=Sophos;i="6.11,225,1725346800"; d="scan'208";a="32108934" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2024 01:40:57 -0700 X-CSE-ConnectionGUID: Xo0ZdLXFRPq73WgkyBM/jg== X-CSE-MsgGUID: ioVUBKqnQly74fGxC+pOJQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,225,1725346800"; d="scan'208";a="80048668" Received: from spr-s2600bt.bj.intel.com ([10.240.192.127]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 Oct 2024 01:40:55 -0700 From: Zhenzhong Duan To: iommu@lists.linux.dev, linux-kernel@vger.kernel.org Cc: dwmw2@infradead.org, baolu.lu@linux.intel.com, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, chao.p.peng@intel.com, Zhenzhong Duan , Kyung Min Park Subject: [PATCH v2 2/2] iommu/vt-d: Fix checks in pgtable_walk() Date: Wed, 23 Oct 2024 16:37:15 +0800 Message-Id: <20241023083715.582149-3-zhenzhong.duan@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241023083715.582149-1-zhenzhong.duan@intel.com> References: <20241023083715.582149-1-zhenzhong.duan@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There are some issues in pgtable_walk(): 1. Super page is dumped as non-present page 2. dma_pte_superpage() should not check against leaf page table entries 3. Pointer pte is never NULL so checking it is meaningless Fix it by moving the check of super page after (level =3D=3D 1) check and removing pte check. Fixes: 914ff7719e8a ("iommu/vt-d: Dump DMAR translation structure when DMA = fault occurs") Signed-off-by: Zhenzhong Duan --- drivers/iommu/intel/iommu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index 8288b0ee7a61..fec5cc1147f3 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -707,14 +707,14 @@ static void pgtable_walk(struct intel_iommu *iommu, u= nsigned long pfn, while (1) { offset =3D pfn_level_offset(pfn, level); pte =3D &parent[offset]; - if (!pte || (dma_pte_superpage(pte) || !dma_pte_present(pte))) { + if (!dma_pte_present(pte)) { pr_info("PTE not present at level %d\n", level); break; } =20 pr_info("pte level: %d, pte value: 0x%016llx\n", level, pte->val); =20 - if (level =3D=3D 1) + if (level =3D=3D 1 || dma_pte_superpage(pte)) break; =20 parent =3D phys_to_virt(dma_pte_addr(pte)); --=20 2.34.1