All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] iommu/vt-d: Fix a bug in intel_iommu_iova_to_phys() for huge page
@ 2020-02-26 20:30 ` Yonghyun Hwang via iommu
  0 siblings, 0 replies; 4+ messages in thread
From: Yonghyun Hwang @ 2020-02-26 20:30 UTC (permalink / raw)
  To: David Woodhouse, Lu Baolu, Joerg Roedel
  Cc: iommu, linux-kernel, Havard Skinnemoen, Deepa Dinamani,
	Moritz Fischer, Yonghyun Hwang, stable

intel_iommu_iova_to_phys() has a bug when it translates an IOVA for a huge
page onto its corresponding physical address. This commit fixes the bug by
accomodating the level of page entry for the IOVA and adds IOVA's lower
address to the physical address.

Cc: <stable@vger.kernel.org>
Acked-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Yonghyun Hwang <yonghyun@google.com>
---

Changes from v2:
- a new condition is added to check whether the pte is present.

Changes from v1:
- level cannot be 0. So, the condition, "if (level > 1)", is removed, which results in a simple code.
- a macro, BIT_MASK, is used to have a bit mask

---
 drivers/iommu/intel-iommu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 932267f49f9a..0837e0063973 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -5553,8 +5553,10 @@ static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
 	u64 phys = 0;
 
 	pte = pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT, &level);
-	if (pte)
-		phys = dma_pte_addr(pte);
+	if (pte && dma_pte_present(pte))
+		phys = dma_pte_addr(pte) +
+			(iova & (BIT_MASK(level_to_offset_bits(level) +
+						VTD_PAGE_SHIFT) - 1));
 
 	return phys;
 }
-- 
2.25.0.265.gbab2e86ba0-goog


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3] iommu/vt-d: Fix a bug in intel_iommu_iova_to_phys() for huge page
@ 2020-02-26 20:30 ` Yonghyun Hwang via iommu
  0 siblings, 0 replies; 4+ messages in thread
From: Yonghyun Hwang via iommu @ 2020-02-26 20:30 UTC (permalink / raw)
  To: David Woodhouse, Lu Baolu, Joerg Roedel
  Cc: Yonghyun Hwang, linux-kernel, stable, Havard Skinnemoen, iommu,
	Moritz Fischer, Deepa Dinamani

intel_iommu_iova_to_phys() has a bug when it translates an IOVA for a huge
page onto its corresponding physical address. This commit fixes the bug by
accomodating the level of page entry for the IOVA and adds IOVA's lower
address to the physical address.

Cc: <stable@vger.kernel.org>
Acked-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Moritz Fischer <mdf@kernel.org>
Signed-off-by: Yonghyun Hwang <yonghyun@google.com>
---

Changes from v2:
- a new condition is added to check whether the pte is present.

Changes from v1:
- level cannot be 0. So, the condition, "if (level > 1)", is removed, which results in a simple code.
- a macro, BIT_MASK, is used to have a bit mask

---
 drivers/iommu/intel-iommu.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 932267f49f9a..0837e0063973 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -5553,8 +5553,10 @@ static phys_addr_t intel_iommu_iova_to_phys(struct iommu_domain *domain,
 	u64 phys = 0;
 
 	pte = pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT, &level);
-	if (pte)
-		phys = dma_pte_addr(pte);
+	if (pte && dma_pte_present(pte))
+		phys = dma_pte_addr(pte) +
+			(iova & (BIT_MASK(level_to_offset_bits(level) +
+						VTD_PAGE_SHIFT) - 1));
 
 	return phys;
 }
-- 
2.25.0.265.gbab2e86ba0-goog

_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] iommu/vt-d: Fix a bug in intel_iommu_iova_to_phys() for huge page
  2020-02-26 20:30 ` Yonghyun Hwang via iommu
@ 2020-03-02 16:08   ` Joerg Roedel
  -1 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2020-03-02 16:08 UTC (permalink / raw)
  To: Yonghyun Hwang
  Cc: David Woodhouse, Lu Baolu, iommu, linux-kernel,
	Havard Skinnemoen, Deepa Dinamani, Moritz Fischer, stable

On Wed, Feb 26, 2020 at 12:30:06PM -0800, Yonghyun Hwang wrote:
> intel_iommu_iova_to_phys() has a bug when it translates an IOVA for a huge
> page onto its corresponding physical address. This commit fixes the bug by
> accomodating the level of page entry for the IOVA and adds IOVA's lower
> address to the physical address.
> 
> Cc: <stable@vger.kernel.org>
> Acked-by: Lu Baolu <baolu.lu@linux.intel.com>
> Reviewed-by: Moritz Fischer <mdf@kernel.org>
> Signed-off-by: Yonghyun Hwang <yonghyun@google.com>

Applied with Fixes tag:

Fixes: 3871794642579 ("VT-d: Changes to support KVM")

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3] iommu/vt-d: Fix a bug in intel_iommu_iova_to_phys() for huge page
@ 2020-03-02 16:08   ` Joerg Roedel
  0 siblings, 0 replies; 4+ messages in thread
From: Joerg Roedel @ 2020-03-02 16:08 UTC (permalink / raw)
  To: Yonghyun Hwang
  Cc: Havard Skinnemoen, stable, linux-kernel, iommu, Deepa Dinamani,
	Moritz Fischer, David Woodhouse

On Wed, Feb 26, 2020 at 12:30:06PM -0800, Yonghyun Hwang wrote:
> intel_iommu_iova_to_phys() has a bug when it translates an IOVA for a huge
> page onto its corresponding physical address. This commit fixes the bug by
> accomodating the level of page entry for the IOVA and adds IOVA's lower
> address to the physical address.
> 
> Cc: <stable@vger.kernel.org>
> Acked-by: Lu Baolu <baolu.lu@linux.intel.com>
> Reviewed-by: Moritz Fischer <mdf@kernel.org>
> Signed-off-by: Yonghyun Hwang <yonghyun@google.com>

Applied with Fixes tag:

Fixes: 3871794642579 ("VT-d: Changes to support KVM")
_______________________________________________
iommu mailing list
iommu@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/iommu

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-03-02 16:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-26 20:30 [PATCH v3] iommu/vt-d: Fix a bug in intel_iommu_iova_to_phys() for huge page Yonghyun Hwang
2020-02-26 20:30 ` Yonghyun Hwang via iommu
2020-03-02 16:08 ` Joerg Roedel
2020-03-02 16:08   ` Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.