Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 312136 Details for
Bug 455813
Under heavy memory usage dma_alloc_coherent does not return aligned address
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
RHEL5 fix for this issue (with DMA short-circuit code and debug)
455813.patch (text/plain), 14.48 KB, created by
Prarit Bhargava
on 2008-07-18 13:47:32 UTC
(
hide
)
Description:
RHEL5 fix for this issue (with DMA short-circuit code and debug)
Filename:
MIME Type:
Creator:
Prarit Bhargava
Created:
2008-07-18 13:47:32 UTC
Size:
14.48 KB
patch
obsolete
>diff -urNp -X linux-2.6.18.x86_64/Documentation/dontdiff linux-2.6.18.x86_64.orig/arch/x86_64/Kconfig linux-2.6.18.x86_64/arch/x86_64/Kconfig >--- linux-2.6.18.x86_64.orig/arch/x86_64/Kconfig 2008-07-17 13:46:24.000000000 -0400 >+++ linux-2.6.18.x86_64/arch/x86_64/Kconfig 2008-07-17 13:49:57.000000000 -0400 >@@ -469,6 +469,13 @@ config IOMMU > device) unless CONFIG_IOMMU_DEBUG or iommu=force is specified > too. > >+config IOMMU_HELPER >+ bool "IOMMU_HELPER support" >+ default y >+ depends on IOMMU >+ help >+ Support for alignment of DMA regions above 4GB. >+ > config CALGARY_IOMMU > bool "IBM Calgary IOMMU support" > default y >diff -urNp -X linux-2.6.18.x86_64/Documentation/dontdiff linux-2.6.18.x86_64.orig/arch/x86_64/kernel/pci-dma.c linux-2.6.18.x86_64/arch/x86_64/kernel/pci-dma.c >--- linux-2.6.18.x86_64.orig/arch/x86_64/kernel/pci-dma.c 2008-07-17 13:46:24.000000000 -0400 >+++ linux-2.6.18.x86_64/arch/x86_64/kernel/pci-dma.c 2008-07-18 07:39:35.000000000 -0400 >@@ -77,6 +77,9 @@ dma_alloc_coherent(struct device *dev, s > unsigned long dma_mask = 0; > u64 bus; > >+ if (panic_on_oops) >+ printk("%s: called\n", __FUNCTION__); >+ > if (!dev) > dev = &fallback_dev; > dma_mask = dev->coherent_dma_mask; >@@ -97,6 +100,9 @@ dma_alloc_coherent(struct device *dev, s > if (dma_mask <= DMA_32BIT_MASK) > gfp |= GFP_DMA32; > >+ if (panic_on_oops) >+ printk("%s: dma_mask = 0x%0x\n", __FUNCTION__, >+ (unsigned long)dma_mask); > again: > memory = dma_alloc_pages(dev, gfp, get_order(size)); > if (memory == NULL) >@@ -107,8 +113,18 @@ dma_alloc_coherent(struct device *dev, s > bus = virt_to_bus(memory); > high = (bus + size) >= dma_mask; > mmu = high; >- if (force_iommu && !(gfp & GFP_DMA)) >+ >+ if (panic_on_oops) { >+ printk("%s: bus = 0x%0x | high = %d\n",__FUNCTION__, >+ (unsigned long)bus, high); >+ printk("%s: setting mmu = 1\n", __FUNCTION__); >+ mmu = 1; /* force iommu */ >+ } >+ >+ if (force_iommu && !(gfp & GFP_DMA)) { > mmu = 1; >+ printk("%s: setting mmu = 1\n", __FUNCTION__); >+ } > else if (high) { > free_pages((unsigned long)memory, > get_order(size)); >@@ -117,6 +133,9 @@ dma_alloc_coherent(struct device *dev, s > needed. It's better to use remapping first. */ > if (dma_mask < DMA_32BIT_MASK && !(gfp & GFP_DMA)) { > gfp = (gfp & ~GFP_DMA32) | GFP_DMA; >+ if (panic_on_oops) >+ printk("%s: trying again\n", >+ __FUNCTION__); > goto again; > } > >@@ -132,16 +151,21 @@ dma_alloc_coherent(struct device *dev, s > memset(memory, 0, size); > if (!mmu) { > *dma_handle = virt_to_bus(memory); >+ if (panic_on_oops) >+ printk("%s: mmu=%d dma_handle = 0x%p\n", >+ __FUNCTION__, mmu, *dma_handle); > return memory; > } > } > >+/* > if (dma_ops->alloc_coherent) { > free_pages((unsigned long)memory, get_order(size)); > gfp &= ~(GFP_DMA|GFP_DMA32); > return dma_ops->alloc_coherent(dev, size, dma_handle, gfp); > } >- >+*/ >+prarit: > if (dma_ops->map_simple) { > *dma_handle = dma_ops->map_simple(dev, memory, > size, >diff -urNp -X linux-2.6.18.x86_64/Documentation/dontdiff linux-2.6.18.x86_64.orig/arch/x86_64/kernel/pci-gart.c linux-2.6.18.x86_64/arch/x86_64/kernel/pci-gart.c >--- linux-2.6.18.x86_64.orig/arch/x86_64/kernel/pci-gart.c 2008-07-17 13:46:24.000000000 -0400 >+++ linux-2.6.18.x86_64/arch/x86_64/kernel/pci-gart.c 2008-07-18 09:25:18.000000000 -0400 >@@ -22,6 +22,7 @@ > #include <linux/topology.h> > #include <linux/interrupt.h> > #include <linux/bitops.h> >+#include <linux/iommu-helper.h> > #include <asm/atomic.h> > #include <asm/io.h> > #include <asm/mtrr.h> >@@ -76,37 +77,60 @@ AGPEXTERN __u32 *agp_gatt_table; > static unsigned long next_bit; /* protected by iommu_bitmap_lock */ > static int need_flush; /* global flush state. set for each gart wrap */ > >-static unsigned long alloc_iommu(int size) >-{ >+static unsigned long alloc_iommu(struct device *dev, int size) >+{ > unsigned long offset, flags; >+ unsigned long boundary_size; >+ unsigned long base_index; >+ >+ base_index = ALIGN(iommu_bus_base & 0xffffffff, >+ PAGE_SIZE) >> PAGE_SHIFT; >+ boundary_size = ALIGN((unsigned long long) 0x100000000, >+ PAGE_SIZE) >> PAGE_SHIFT; > >- spin_lock_irqsave(&iommu_bitmap_lock, flags); >- offset = find_next_zero_string(iommu_gart_bitmap,next_bit,iommu_pages,size); >+ spin_lock_irqsave(&iommu_bitmap_lock, flags); >+ if (panic_on_oops) { >+ printk("%s: ALIGN(0xffffffff, PAGE_SIZE) = %0lx\n", >+ __FUNCTION__, ALIGN(0xffffffff, PAGE_SIZE)); >+ printk("%s: ALIGN(0x100000000, PAGE_SIZE) >> PAGE_SHIFT=%0lx\n", >+ __FUNCTION__, ALIGN((unsigned long long)0x100000000, >+ PAGE_SIZE)); >+ printk("%s: boundary_size = %0lx\n", __FUNCTION__, >+ boundary_size); >+ printk("%s: size = %0lx\n", __FUNCTION__, size); >+ printk("%s: base_index = %0lx\n", __FUNCTION__, base_index); >+ } >+ offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, next_bit, >+ size, base_index, boundary_size, size - 1); > if (offset == -1) { > need_flush = 1; >- offset = find_next_zero_string(iommu_gart_bitmap,0,iommu_pages,size); >- } >- if (offset != -1) { >- set_bit_string(iommu_gart_bitmap, offset, size); >- next_bit = offset+size; >- if (next_bit >= iommu_pages) { >+ offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, 0, >+ size, base_index, boundary_size, >+ size - 1); >+ } >+ if (offset != -1) { >+ set_bit_string(iommu_gart_bitmap, offset, size); >+ next_bit = offset+size; >+ if (next_bit >= iommu_pages) { > next_bit = 0; > need_flush = 1; >- } >- } >+ } >+ } > if (iommu_fullflush) > need_flush = 1; >- spin_unlock_irqrestore(&iommu_bitmap_lock, flags); >+ spin_unlock_irqrestore(&iommu_bitmap_lock, flags); >+ > return offset; >-} >+} > > static void free_iommu(unsigned long offset, int size) >-{ >+{ > unsigned long flags; >+ > spin_lock_irqsave(&iommu_bitmap_lock, flags); >- __clear_bit_string(iommu_gart_bitmap, offset, size); >+ iommu_area_free(iommu_gart_bitmap, offset, size); > spin_unlock_irqrestore(&iommu_bitmap_lock, flags); >-} >+} > > /* > * Use global flush state to avoid races with multiple flushers. >@@ -207,7 +231,7 @@ static dma_addr_t dma_map_area(struct de > size_t size, int dir) > { > unsigned long npages = to_pages(phys_mem, size); >- unsigned long iommu_page = alloc_iommu(npages); >+ unsigned long iommu_page = alloc_iommu(dev, npages); > int i; > if (iommu_page == -1) { > if (!nonforced_iommu(dev, phys_mem, size)) >@@ -223,6 +247,20 @@ static dma_addr_t dma_map_area(struct de > SET_LEAK(iommu_page + i); > phys_mem += PAGE_SIZE; > } >+ >+ if (panic_on_oops) { >+ printk(" iommu_bus_base = %0lx\n", iommu_bus_base); >+ printk(" iommu_page = %0lx\n", iommu_page); >+ printk(" iommu_page*PAGE_SIZE = %0lx\n", >+ iommu_page*PAGE_SIZE); >+ printk(" phys_mem = %0lx\n", phys_mem); >+ printk(" (phys_mem & ~PAGE_MASK) = %0lx\n", >+ (phys_mem & ~PAGE_MASK)); >+ printk(" returning %0lx [%0lx]\n", >+ iommu_bus_base + iommu_page*PAGE_SIZE + (phys_mem & ~PAGE_MASK), >+ (void *)(iommu_bus_base + iommu_page*PAGE_SIZE + (phys_mem & ~PAGE_MASK))); >+ } >+ > return iommu_bus_base + iommu_page*PAGE_SIZE + (phys_mem & ~PAGE_MASK); > } > >@@ -320,10 +358,11 @@ static int dma_map_sg_nonforce(struct de > } > > /* Map multiple scatterlist entries continuous into the first. */ >-static int __dma_map_cont(struct scatterlist *sg, int start, int stopat, >- struct scatterlist *sout, unsigned long pages) >+static int __dma_map_cont(struct device *dev, struct scatterlist *sg, int start, >+ int stopat, struct scatterlist *sout, >+ unsigned long pages) > { >- unsigned long iommu_start = alloc_iommu(pages); >+ unsigned long iommu_start = alloc_iommu(dev, pages); > unsigned long iommu_page = iommu_start; > int i; > >@@ -358,9 +397,10 @@ static int __dma_map_cont(struct scatter > return 0; > } > >-static inline int dma_map_cont(struct scatterlist *sg, int start, int stopat, >- struct scatterlist *sout, >- unsigned long pages, int need) >+static inline int dma_map_cont(struct device *dev, struct scatterlist *sg, >+ int start, int stopat, >+ struct scatterlist *sout, >+ unsigned long pages, int need) > { > if (!need) { > BUG_ON(stopat - start != 1); >@@ -368,7 +408,7 @@ static inline int dma_map_cont(struct sc > sout->dma_length = sg[start].length; > return 0; > } >- return __dma_map_cont(sg, start, stopat, sout, pages); >+ return __dma_map_cont(dev, sg, start, stopat, sout, pages); > } > > /* >@@ -407,8 +447,8 @@ int gart_map_sg(struct device *dev, stru > boundary and the new one doesn't have an offset. */ > if (!iommu_merge || !nextneed || !need || s->offset || > (ps->offset + ps->length) % PAGE_SIZE) { >- if (dma_map_cont(sg, start, i, sg+out, pages, >- need) < 0) >+ if (dma_map_cont(dev, sg, start, i, sg+out, >+ pages, need) < 0) > goto error; > out++; > pages = 0; >@@ -419,7 +459,7 @@ int gart_map_sg(struct device *dev, stru > need = nextneed; > pages += to_pages(s->offset, s->length); > } >- if (dma_map_cont(sg, start, i, sg+out, pages, need) < 0) >+ if (dma_map_cont(dev, sg, start, i, sg+out, pages, need) < 0) > goto error; > out++; > flush_gart(); >diff -urNp -X linux-2.6.18.x86_64/Documentation/dontdiff linux-2.6.18.x86_64.orig/include/linux/iommu-helper.h linux-2.6.18.x86_64/include/linux/iommu-helper.h >--- linux-2.6.18.x86_64.orig/include/linux/iommu-helper.h 1969-12-31 19:00:00.000000000 -0500 >+++ linux-2.6.18.x86_64/include/linux/iommu-helper.h 2008-07-17 13:49:57.000000000 -0400 >@@ -0,0 +1,10 @@ >+extern int iommu_is_span_boundary(unsigned int index, unsigned int nr, >+ unsigned long shift, >+ unsigned long boundary_size); >+extern unsigned long iommu_area_alloc(unsigned long *map, unsigned long size, >+ unsigned long start, unsigned int nr, >+ unsigned long shift, >+ unsigned long boundary_size, >+ unsigned long align_mask); >+extern void iommu_area_free(unsigned long *map, unsigned long start, >+ unsigned int nr); >diff -urNp -X linux-2.6.18.x86_64/Documentation/dontdiff linux-2.6.18.x86_64.orig/kernel/panic.c linux-2.6.18.x86_64/kernel/panic.c >--- linux-2.6.18.x86_64.orig/kernel/panic.c 2008-07-17 13:46:22.000000000 -0400 >+++ linux-2.6.18.x86_64/kernel/panic.c 2008-07-17 13:49:57.000000000 -0400 >@@ -20,7 +20,7 @@ > #include <linux/kexec.h> > #include <linux/debug_locks.h> > >-int panic_on_oops = 1; >+int panic_on_oops = 0; > int tainted; > static int pause_on_oops; > static int pause_on_oops_flag; >@@ -30,6 +30,7 @@ int panic_timeout; > > ATOMIC_NOTIFIER_HEAD(panic_notifier_list); > >+EXPORT_SYMBOL(panic_on_oops); > EXPORT_SYMBOL(panic_notifier_list); > > static int __init panic_setup(char *str) >diff -urNp -X linux-2.6.18.x86_64/Documentation/dontdiff linux-2.6.18.x86_64.orig/lib/iommu-helper.c linux-2.6.18.x86_64/lib/iommu-helper.c >--- linux-2.6.18.x86_64.orig/lib/iommu-helper.c 1969-12-31 19:00:00.000000000 -0500 >+++ linux-2.6.18.x86_64/lib/iommu-helper.c 2008-07-18 09:25:03.000000000 -0400 >@@ -0,0 +1,105 @@ >+/* >+ * IOMMU helper functions for the free area management >+ */ >+ >+#include <linux/module.h> >+#include <linux/bitops.h> >+ >+static unsigned long find_next_zero_area(unsigned long *map, >+ unsigned long size, >+ unsigned long start, >+ unsigned int nr, >+ unsigned long align_mask) >+{ >+ unsigned long index, end, i; >+again: >+ index = find_next_zero_bit(map, size, start); >+ >+ if (panic_on_oops) { >+ printk("%s: index = %0x\n", __FUNCTION__, index); >+ printk("%s: index + align_mask + 1= %0x\n", __FUNCTION__, >+ index + align_mask + 1); >+ printk("%s: ~align_mask = %0x\n", __FUNCTION__, >+ ~align_mask); >+ } >+ /* Align allocation */ >+ index = (index + (align_mask + 1)) & ~align_mask; >+ if (panic_on_oops) { >+ printk("%s: index = %0x\n", __FUNCTION__, index); >+ } >+ end = index + nr; >+ if (end >= size) >+ return -1; >+ for (i = index; i < end; i++) { >+ if (test_bit(i, map)) { >+ start = i+1; >+ goto again; >+ } >+ } >+ return index; >+} >+ >+static inline void set_bit_area(unsigned long *map, unsigned long i, >+ int len) >+{ >+ unsigned long end = i + len; >+ while (i < end) { >+ __set_bit(i, map); >+ i++; >+ } >+} >+ >+int iommu_is_span_boundary(unsigned int index, unsigned int nr, >+ unsigned long shift, >+ unsigned long boundary_size) >+{ >+ BUG_ON(!is_power_of_2(boundary_size)); >+ >+ if (panic_on_oops) { >+ printk("%s: index = %0x nr = %0x shift = %0lx" >+ " boundary_size = %0lx\n", >+ __FUNCTION__, index, nr, shift, boundary_size); >+ } >+ shift = (shift + index) & (boundary_size - 1); >+ if (panic_on_oops) >+ printk("%s: returning %d\n", __FUNCTION__, >+ shift + nr > boundary_size); >+ >+ return shift + nr > boundary_size; >+} >+ >+unsigned long iommu_area_alloc(unsigned long *map, unsigned long size, >+ unsigned long start, unsigned int nr, >+ unsigned long shift, unsigned long boundary_size, >+ unsigned long align_mask) >+{ >+ unsigned long index = 0; >+ int iteration = 0; >+again: >+ if (panic_on_oops) { >+ printk("%s: [%d] index = %0x\n", __FUNCTION__, iteration, >+ index); >+ } >+ index = find_next_zero_area(map, size, start, nr, align_mask); >+ if (index != -1) { >+ if (iommu_is_span_boundary(index, nr, shift, boundary_size)) { >+ /* we could do more effectively */ >+ start = index + 1; >+ goto again; >+ } >+ set_bit_area(map, index, nr); >+ } >+ return index; >+} >+EXPORT_SYMBOL(iommu_area_alloc); >+ >+void iommu_area_free(unsigned long *map, unsigned long start, unsigned int nr) >+{ >+ unsigned long end = start + nr; >+ >+ while (start < end) { >+ __clear_bit(start, map); >+ start++; >+ } >+} >+EXPORT_SYMBOL(iommu_area_free); >diff -urNp -X linux-2.6.18.x86_64/Documentation/dontdiff linux-2.6.18.x86_64.orig/lib/Makefile linux-2.6.18.x86_64/lib/Makefile >--- linux-2.6.18.x86_64.orig/lib/Makefile 2008-07-17 13:46:24.000000000 -0400 >+++ linux-2.6.18.x86_64/lib/Makefile 2008-07-17 13:49:57.000000000 -0400 >@@ -55,6 +55,8 @@ obj-$(CONFIG_SMP) += percpu_counter.o > obj-$(CONFIG_AUDIT_GENERIC) += audit.o > > obj-$(CONFIG_SWIOTLB) += swiotlb.o >+obj-$(CONFIG_IOMMU_HELPER) += iommu-helper.o >+ > ifeq ($(CONFIG_X86),y) > swiotlb-$(CONFIG_XEN) := ../arch/i386/kernel/swiotlb.o > endif >diff -urNp -X linux-2.6.18.x86_64/Documentation/dontdiff linux-2.6.18.x86_64.orig/lib/swiotlb.c linux-2.6.18.x86_64/lib/swiotlb.c >--- linux-2.6.18.x86_64.orig/lib/swiotlb.c 2008-07-17 13:46:24.000000000 -0400 >+++ linux-2.6.18.x86_64/lib/swiotlb.c 2008-07-17 13:49:57.000000000 -0400 >@@ -437,6 +437,8 @@ swiotlb_alloc_coherent(struct device *hw > void *ret; > int order = get_order(size); > >+ if (panic_on_oops) >+ printk("%s: called \n", __FUNCTION__); > /* > * XXX fix me: the DMA API should pass us an explicit DMA mask > * instead, or use ZONE_DMA32 (ia64 overloads ZONE_DMA to be a ~32
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 455813
:
312088
|
312089
|
312135
| 312136 |
312164
|
312463
|
313699