Skip to contentSkip to conversation

x86/iommu: fix dma pte address size error

PATCH In review Li, Zhen-Hua 2 participants 4 messages May 24, 2013 – Jun 17, 2013 IOMMU

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/iommu: fix dma pte address size error

In Intel Vt-D specs, Chapter 9.3 Page-Table Entry,
The size of ADDR(address) field is 12:51, but the function dma_pte_addr
treats it as 12:63.

---
 drivers/iommu/intel-iommu.c   |    4 ++--
 include/linux/dma_remapping.h |    2 ++
 2 files changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/intel-iommu.c +2 -2
index b4f0e28..c6d2847 100644
@@ -311,10 +311,10 @@ static inline void dma_set_pte_prot(struct dma_pte *pte, unsigned long prot)
 static inline u64 dma_pte_addr(struct dma_pte *pte)
 {
 #ifdef CONFIG_64BIT
-	return pte->val & VTD_PAGE_MASK;
+	return pte->val & DMA_PTE_MASK;
 #else
 	/* Must have a full atomic 64-bit read */
-	return  __cmpxchg64(&pte->val, 0ULL, 0ULL) & VTD_PAGE_MASK;
+	return  __cmpxchg64(&pte->val, 0ULL, 0ULL) & DMA_PTE_MASK;
 #endif
 }
 
include/linux/dma_remapping.h +2 -0
index 57c9a8a..7a1e212 100644
@@ -16,6 +16,8 @@
 #define DMA_PTE_WRITE (2)
 #define DMA_PTE_LARGE_PAGE (1 << 7)
 #define DMA_PTE_SNP (1 << 11)
+#define DMA_PTE_ADD_LENGTH (40)
+#define DMA_PTE_MASK	((((u64)1 << DMA_PTE_ADD_LENGTH) - 1) << VTD_PAGE_SHIFT)
 
 #define CONTEXT_TT_MULTI_LEVEL	0
 #define CONTEXT_TT_DEV_IOTLB	1
Signature · 1 line
1.7.10.4
author
#1 lore raw

Hi guys,
I think this patch is necessary. Please take a look at it.

Thanks
Zhen-Hua

Quoted 40 lines · Zhen-Hua

In Intel Vt-D specs, Chapter 9.3 Page-Table Entry,
The size of ADDR(address) field is 12:51, but the function dma_pte_addr
treats it as 12:63.

---
  drivers/iommu/intel-iommu.c   |    4 ++--
  include/linux/dma_remapping.h |    2 ++
  2 files changed, 4 insertions(+), 2 deletions(-)
drivers/iommu/intel-iommu.c +2 -2
index b4f0e28..c6d2847 100644
@@ -311,10 +311,10 @@ static inline void dma_set_pte_prot(struct dma_pte *pte, unsigned long prot)
  static inline u64 dma_pte_addr(struct dma_pte *pte)
  {
  #ifdef CONFIG_64BIT
-	return pte->val & VTD_PAGE_MASK;
+	return pte->val & DMA_PTE_MASK;
  #else
  	/* Must have a full atomic 64-bit read */
-	return  __cmpxchg64(&pte->val, 0ULL, 0ULL) & VTD_PAGE_MASK;
+	return  __cmpxchg64(&pte->val, 0ULL, 0ULL) & DMA_PTE_MASK;
  #endif
  }
 
include/linux/dma_remapping.h +2 -0
index 57c9a8a..7a1e212 100644
@@ -16,6 +16,8 @@
  #define DMA_PTE_WRITE (2)
  #define DMA_PTE_LARGE_PAGE (1 << 7)
  #define DMA_PTE_SNP (1 << 11)
+#define DMA_PTE_ADD_LENGTH (40)
+#define DMA_PTE_MASK	((((u64)1 << DMA_PTE_ADD_LENGTH) - 1) << VTD_PAGE_SHIFT)
 
  #define CONTEXT_TT_MULTI_LEVEL	0
  #define CONTEXT_TT_DEV_IOTLB	1
#2 lore raw
In reply to Li, Zhen-Hua
Quoted 10 lines · Zhen-Hua

In Intel Vt-D specs, Chapter 9.3 Page-Table Entry,
The size of ADDR(address) field is 12:51, but the function dma_pte_addr
treats it as 12:63.

---
  drivers/iommu/intel-iommu.c   |    4 ++--
  include/linux/dma_remapping.h |    2 ++
  2 files changed, 4 insertions(+), 2 deletions(-)

Is this patching for the sake of spec interpretation?
a dma-pte format (consumed by iommu) has 63,61:52 as available for sw, ignored by hw. 62 is 'transient mapping' bit, which is a _hint_ for selecting iotlbs to flush sooner. finally, the system would have to have a memory map that actually has bit 62 set to be affected.

So, for intel-iommu, I don't see a bug occurring. Did you actually have one with previous definition, and if so, could you provide that information ?

Cheers,
- Don

Quoted 30 lines
drivers/iommu/intel-iommu.c +2 -2
index b4f0e28..c6d2847 100644
@@ -311,10 +311,10 @@ static inline void dma_set_pte_prot(struct dma_pte *pte, unsigned long prot)
  static inline u64 dma_pte_addr(struct dma_pte *pte)
  {
  #ifdef CONFIG_64BIT
-	return pte->val&  VTD_PAGE_MASK;
+	return pte->val&  DMA_PTE_MASK;
  #else
  	/* Must have a full atomic 64-bit read */
-	return  __cmpxchg64(&pte->val, 0ULL, 0ULL)&  VTD_PAGE_MASK;
+	return  __cmpxchg64(&pte->val, 0ULL, 0ULL)&  DMA_PTE_MASK;
  #endif
  }
 
include/linux/dma_remapping.h +2 -0
index 57c9a8a..7a1e212 100644
@@ -16,6 +16,8 @@
  #define DMA_PTE_WRITE (2)
  #define DMA_PTE_LARGE_PAGE (1<<  7)
  #define DMA_PTE_SNP (1<<  11)
+#define DMA_PTE_ADD_LENGTH (40)
+#define DMA_PTE_MASK	((((u64)1<<  DMA_PTE_ADD_LENGTH) - 1)<<  VTD_PAGE_SHIFT)
 
  #define CONTEXT_TT_MULTI_LEVEL	0
  #define CONTEXT_TT_DEV_IOTLB	1
#3 lore raw

Hi Don,

This patch is not only for the sake of spec interpretation. Till now I did not see any bugs , but it does not meant no bugs will appear in the future. The address returned by dma_pte_addr is used in many places.

Thanks
Zhenhua

Quoted 60 lines · Don Dutile
Quoted 10 lines · Zhen-Hua

In Intel Vt-D specs, Chapter 9.3 Page-Table Entry,
The size of ADDR(address) field is 12:51, but the function dma_pte_addr
treats it as 12:63.

---
  drivers/iommu/intel-iommu.c   |    4 ++--
  include/linux/dma_remapping.h |    2 ++
  2 files changed, 4 insertions(+), 2 deletions(-)

Is this patching for the sake of spec interpretation?
a dma-pte format (consumed by iommu) has 63,61:52 as available for sw, ignored by hw. 62 is 'transient mapping' bit, which is a _hint_ for selecting iotlbs to flush sooner. finally, the system would have to have a memory map that actually has bit 62 set to be affected.

So, for intel-iommu, I don't see a bug occurring. Did you actually have one with previous definition, and if so, could you provide that information ?

Cheers,
- Don

Quoted 31 lines
drivers/iommu/intel-iommu.c +2 -2
index b4f0e28..c6d2847 100644
@@ -311,10 +311,10 @@ static inline void dma_set_pte_prot(struct 
 dma_pte *pte, unsigned long prot)
  static inline u64 dma_pte_addr(struct dma_pte *pte)
  {
  #ifdef CONFIG_64BIT
-    return pte->val&  VTD_PAGE_MASK;
+    return pte->val&  DMA_PTE_MASK;
  #else
      /* Must have a full atomic 64-bit read */
-    return  __cmpxchg64(&pte->val, 0ULL, 0ULL)& VTD_PAGE_MASK;
+    return  __cmpxchg64(&pte->val, 0ULL, 0ULL)& DMA_PTE_MASK;
  #endif
  }
include/linux/dma_remapping.h +2 -0
index 57c9a8a..7a1e212 100644
@@ -16,6 +16,8 @@
  #define DMA_PTE_WRITE (2)
  #define DMA_PTE_LARGE_PAGE (1<<  7)
  #define DMA_PTE_SNP (1<<  11)
+#define DMA_PTE_ADD_LENGTH (40)
+#define DMA_PTE_MASK    ((((u64)1<<  DMA_PTE_ADD_LENGTH) - 1)<<  
 VTD_PAGE_SHIFT)
 
  #define CONTEXT_TT_MULTI_LEVEL    0
Quoted 1 line
  #define CONTEXT_TT_DEV_IOTLB    1

.