Skip to contentSkip to conversation

x86: fix broken flushing in GART nofullflush path

PATCH Applied Joerg Roedel 3 participants 4 messages Dec 2, 2008 – Dec 3, 2008 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: fix broken flushing in GART nofullflush path

In the non-default nofullflush case the GART is only flushed when next_bit wraps around. But it can happen that an unmap operation unmaps memory which is behind the current next_bit location. If these addresses are reused it may result in stale GART IO/TLB entries. Fix this by setting the GART next_bit always behind an unmapped location.

---
 arch/x86/kernel/pci-gart_64.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
arch/x86/kernel/pci-gart_64.c +2 -0
index a42b02b..ba7ad83 100644
@@ -123,6 +123,8 @@ static void free_iommu(unsigned long offset, int size)
 
 	spin_lock_irqsave(&iommu_bitmap_lock, flags);
 	iommu_area_free(iommu_gart_bitmap, offset, size);
+	if (offset >= next_bit)
+		next_bit = offset + size;
 	spin_unlock_irqrestore(&iommu_bitmap_lock, flags);
 }
 
Signature · 1 line
1.5.6.4
Applied
#1 lore raw
Quoted 10 lines · Joerg Roedel

In the non-default nofullflush case the GART is only flushed when next_bit wraps around. But it can happen that an unmap operation unmaps memory which is behind the current next_bit location. If these addresses are reused it may result in stale GART IO/TLB entries. Fix this by setting the GART next_bit always behind an unmapped location.

---
 arch/x86/kernel/pci-gart_64.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

applied to tip/x86/iommu, thanks Joerg!

a stale iotlb should not cause any problems in this particular GART case, right? It might be a security leak in a security-domain enforcing iotlb case, but the GART is a DMA bouncing helper in essence. Can you see any failure mode of this bug?

Ingo

#2 lore raw
Quoted 14 lines · Ingo Molnar
Quoted 10 lines · Joerg Roedel

In the non-default nofullflush case the GART is only flushed when next_bit wraps around. But it can happen that an unmap operation unmaps memory which is behind the current next_bit location. If these addresses are reused it may result in stale GART IO/TLB entries. Fix this by setting the GART next_bit always behind an unmapped location.

---
 arch/x86/kernel/pci-gart_64.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Quoted 6 lines

applied to tip/x86/iommu, thanks Joerg!

a stale iotlb should not cause any problems in this particular GART case, right? It might be a security leak in a security-domain enforcing iotlb case, but the GART is a DMA bouncing helper in essence. Can you see any failure mode of this bug?

It can cause data corruption because the GART redirects the IO to a wrong address because of a stale entry in its TLB. I found this bug after I fixed the same issue in the AMD IOMMU code (commit 80be308d).

The reason this was not found earlier is that lazy flushing is not the default in GART. But I didn't try to trigger the bug.

Joerg

#3 lore raw

u

Quoted 22 lines · Joerg Roedel
Quoted 14 lines · Ingo Molnar
Quoted 10 lines · Joerg Roedel

In the non-default nofullflush case the GART is only flushed when next_bit wraps around. But it can happen that an unmap operation unmaps memory which is behind the current next_bit location. If these addresses are reused it may result in stale GART IO/TLB entries. Fix this by setting the GART next_bit always behind an unmapped location.

---
 arch/x86/kernel/pci-gart_64.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Quoted 6 lines

applied to tip/x86/iommu, thanks Joerg!

a stale iotlb should not cause any problems in this particular GART case, right? It might be a security leak in a security-domain enforcing iotlb case, but the GART is a DMA bouncing helper in essence. Can you see any failure mode of this bug?

Quoted 6 lines

It can cause data corruption because the GART redirects the IO to a wrong address because of a stale entry in its TLB. I found this bug after I fixed the same issue in the AMD IOMMU code (commit 80be308d).

The reason this was not found earlier is that lazy flushing is not the default in GART. But I didn't try to trigger the bug.

ah, indeed. The stale entries themselves are not an issue - the problem is reuse: if a stale entry is reused but then we do not flush, we can get data corruption. I've cherry-picked it over into x86/urgent as well.

Ingo