Skip to contentSkip to conversation

intel_iommu: fix an incorrect address translation

PATCH Applied Peter Xu 3 participants 3 messages Jan 3, 2017 – Jan 12, 2017 KVM

lore
Share & tools
lore

Peter Xu

author
#0 lore raw

PATCH 1/1 intel_iommu: fix an incorrect address translation

---
Tests: map one page twice and see whether dmar work

Alex, do you mind I add your s-o-b as well in this patch above mine? :)

---
 lib/x86/intel-iommu.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/x86/intel-iommu.c +2 -5
index 20b9240..7a3f324 100644
@@ -166,9 +166,6 @@ static void vtd_install_pte(vtd_pte_t *root, iova_t iova,
 	}
 }
 
-#define  VTD_PHYS_TO_VIRT(x) \
-	((void *)(((uint64_t)phys_to_virt(x)) >> VTD_PAGE_SHIFT))
-
 /**
  * vtd_map_range: setup IO address mapping for specific memory range
  *
@@ -203,7 +200,7 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size)
 		printf("allocated vt-d root entry for PCI bus %d\n",
 		       bus_n);
 	} else
-		ce = VTD_PHYS_TO_VIRT(re->context_table_p);
+		ce = phys_to_virt(re->context_table_p << VTD_PAGE_SHIFT);
 
 	/* Point to the correct context entry */
 	ce += devfn;
@@ -224,7 +221,7 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size)
 		printf("allocated vt-d context entry for devfn 0x%x\n",
 		       devfn);
 	} else
-		slptptr = VTD_PHYS_TO_VIRT(ce->slptptr);
+		slptptr = phys_to_virt(ce->slptptr << VTD_PAGE_SHIFT);
 
 	while (size) {
 		/* TODO: currently we only map 4K pages (level = 1) */
Signature · 1 line
2.7.4
#1 lore raw
Quoted 6 lines · Peter Xu

---
Tests: map one page twice and see whether dmar work

Alex, do you mind I add your s-o-b as well in this patch above mine? :)

I am fine with either :)

Quoted 40 lines
---
 lib/x86/intel-iommu.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/x86/intel-iommu.c +2 -5
index 20b9240..7a3f324 100644
@@ -166,9 +166,6 @@ static void vtd_install_pte(vtd_pte_t *root, iova_t iova,
 	}
 }
 
-#define  VTD_PHYS_TO_VIRT(x) \
-	((void *)(((uint64_t)phys_to_virt(x)) >> VTD_PAGE_SHIFT))
-
 /**
  * vtd_map_range: setup IO address mapping for specific memory range
  *
@@ -203,7 +200,7 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size)
 		printf("allocated vt-d root entry for PCI bus %d\n",
 		       bus_n);
 	} else
-		ce = VTD_PHYS_TO_VIRT(re->context_table_p);
+		ce = phys_to_virt(re->context_table_p << VTD_PAGE_SHIFT);
 
 	/* Point to the correct context entry */
 	ce += devfn;
@@ -224,7 +221,7 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size)
 		printf("allocated vt-d context entry for devfn 0x%x\n",
 		       devfn);
 	} else
-		slptptr = VTD_PHYS_TO_VIRT(ce->slptptr);
+		slptptr = phys_to_virt(ce->slptptr << VTD_PAGE_SHIFT);
 
 	while (size) {
 		/* TODO: currently we only map 4K pages (level = 1) */
Signature · 1 line
2.7.4
maintainer Applied
#2 lore raw
In reply to Peter Xu
Quoted 37 lines · Peter Xu

---
Tests: map one page twice and see whether dmar work

Alex, do you mind I add your s-o-b as well in this patch above mine? :)

---
 lib/x86/intel-iommu.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
lib/x86/intel-iommu.c +1 -4
index 20b9240..7a3f324 100644
@@ -166,9 +166,6 @@ static void vtd_install_pte(vtd_pte_t *root, iova_t iova,
 	}
 }
 
-#define  VTD_PHYS_TO_VIRT(x) \
-	((void *)(((uint64_t)phys_to_virt(x)) >> VTD_PAGE_SHIFT))
-
 /**
  * vtd_map_range: setup IO address mapping for specific memory range
  *
@@ -203,7 +200,7 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size)
 		printf("allocated vt-d root entry for PCI bus %d\n",
 		       bus_n);
 	} else
-		ce = VTD_PHYS_TO_VIRT(re->context_table_p);
+		ce = phys_to_virt(re->context_table_p << VTD_PAGE_SHIFT);
 
 	/* Point to the correct context entry */
 	ce += devfn;

lib/x86/intel-iommu.c void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size) · line 227

Quoted 8 lines
lib/x86/intel-iommu.c +1 -1
@@ -224,7 +221,7 @@ void vtd_map_range(uint16_t sid, iova_t iova, phys_addr_t pa, size_t size)
 		printf("allocated vt-d context entry for devfn 0x%x\n",
 		       devfn);
 	} else
-		slptptr = VTD_PHYS_TO_VIRT(ce->slptptr);
+		slptptr = phys_to_virt(ce->slptptr << VTD_PAGE_SHIFT);
 
 	while (size) {
 		/* TODO: currently we only map 4K pages (level = 1) */

Queued, thanks.

Paolo