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 312916 Details for
Bug 298811
pci_alloc_consistent() for 64k on 16gig machine -> return value is not multiple of 64k
[?]
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]
RHEL4 fix for this issue
298811-v3.patch (text/plain), 8.41 KB, created by
Prarit Bhargava
on 2008-07-29 18:19:57 UTC
(
hide
)
Description:
RHEL4 fix for this issue
Filename:
MIME Type:
Creator:
Prarit Bhargava
Created:
2008-07-29 18:19:57 UTC
Size:
8.41 KB
patch
obsolete
>pci_alloc_consistent/dma_alloc_coherent is supposed to return size aligned >addresses. > >From Documentation/DMA-mapping.txt: > >"pci_alloc_consistent returns two values: the virtual address which you >can use to access it from the CPU and dma_handle which you pass to the >card. > >The cpu return address and the DMA bus master address are both >guaranteed to be aligned to the smallest PAGE_SIZE order which >is greater than or equal to the requested size. This invariant >exists (for example) to guarantee that if you allocate a chunk >which is smaller than or equal to 64 kilobytes, the extent of the >buffer you receive will not cross a 64K boundary." > >1. Backport upstream iommu-helper code into RHEL5. > >While #1 was being done, two bugs were noted: > >2. It is possible that alloc_iommu()'s boundary_size overflows as >dma_get_seg_boundary can return 0xffffffff. In that case, further usage of >boundary_size triggers a BUG_ON() in the iommu code. > >3. Fix the GART's alloc_iommu code to return a size aligned address. Also fix >an incorrect alignment calculation in the iommu-helper code. > >Upstream patch was sent to LKML & the pci maintainer. It is currently in >his the pci-2.6 tree, on branch for-linus which will be merged shortly. > >(The patch is in Jesse Barnes' tree as 074ec1727196c4a2ba2f909902d55ec5014e50c3 > -- I will update the BZ when it lands in Linus' tree) > >Patch was tested with test module provided in BZ 298811, and by customer >who reported BZ 298811. > >Resolves BZ 298811. > > >diff --git a/arch/x86_64/kernel/pci-gart.c b/arch/x86_64/kernel/pci-gart.c >index b71be6c..e06e5d5 100644 >--- a/arch/x86_64/kernel/pci-gart.c >+++ b/arch/x86_64/kernel/pci-gart.c >@@ -22,6 +22,7 @@ > #include <linux/module.h> > #include <linux/topology.h> > #include <linux/interrupt.h> >+#include <linux/iommu-helper.h> > #include <asm/atomic.h> > #include <asm/io.h> > #include <asm/mtrr.h> >@@ -101,7 +102,8 @@ 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 dma_addr_t dma_map_area(struct device *dev, unsigned long phys_mem, >- size_t size, int dir, int do_panic); >+ size_t size, int dir, int do_panic, >+ u64 align_mask); > > /* Dummy device used for NULL arguments (normally ISA). Better would > be probably a smaller DMA mask, but this is bug-to-bug compatible to i386. */ >@@ -111,37 +113,48 @@ static struct device fallback_dev = { > .dma_mask = &fallback_dev.coherent_dma_mask, > }; > >-static unsigned long alloc_iommu(int size) >-{ >+static unsigned long alloc_iommu(struct device *dev, int size, >+ unsigned long mask) >+{ > 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(0x100000000ULL, 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); >+ offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, next_bit, >+ size, base_index, boundary_size, mask); > if (offset == -1) { > need_flush = 1; >- offset = find_next_zero_string(iommu_gart_bitmap,0,next_bit,size); >+ offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, 0, >+ size, base_index, boundary_size, >+ mask); > } >- if (offset != -1) { >- set_bit_string(iommu_gart_bitmap, offset, size); >- next_bit = offset+size; >- if (next_bit >= iommu_pages) { >+ if (offset != -1) { >+ 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. >@@ -252,7 +265,8 @@ dma_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, > } > } > >- *dma_handle = dma_map_area(dev, bus, size, PCI_DMA_BIDIRECTIONAL, 0); >+ *dma_handle = dma_map_area(dev, bus, size, PCI_DMA_BIDIRECTIONAL, 0, >+ size - 1); > if (*dma_handle == bad_dma_address) > goto error; > flush_gart(dev); >@@ -370,10 +384,12 @@ static inline int nonforced_iommu(struct device *dev, unsigned long addr, size_t > * Caller needs to check if the iommu is needed and flush. > */ > static dma_addr_t dma_map_area(struct device *dev, unsigned long phys_mem, >- size_t size, int dir, int do_panic) >+ size_t size, int dir, int do_panic, >+ u64 align_mask) > { > unsigned long npages = to_pages(phys_mem, size); >- unsigned long iommu_page = alloc_iommu(npages); >+ unsigned long palign_mask = align_mask >> PAGE_SHIFT; >+ unsigned long iommu_page = alloc_iommu(dev, npages, palign_mask); > int i; > if (iommu_page == -1) { > if (!nonforced_iommu(dev, phys_mem, size)) >@@ -408,7 +424,7 @@ dma_addr_t dma_map_single(struct device *dev, void *addr, size_t size, int dir) > if (!need_iommu(dev, phys_mem, size)) > return phys_mem; > >- bus = dma_map_area(dev, phys_mem, size, dir, 1); >+ bus = dma_map_area(dev, phys_mem, size, dir, 1, 0); > flush_gart(dev); > return bus; > } >@@ -427,7 +443,7 @@ static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg, > struct scatterlist *s = &sg[i]; > unsigned long addr = page_to_phys(s->page) + s->offset; > if (nonforced_iommu(dev, addr, s->length)) { >- addr = dma_map_area(dev, addr, s->length, dir, 0); >+ addr = dma_map_area(dev, addr, s->length, dir, 0, 0); > if (addr == bad_dma_address) { > if (i > 0) > dma_unmap_sg(dev, sg, i, dir); >@@ -444,10 +460,11 @@ static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg, > } > > /* 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, 0); > unsigned long iommu_page = iommu_start; > int i; > >@@ -482,9 +499,9 @@ static int __dma_map_cont(struct scatterlist *sg, int start, int stopat, > 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); >@@ -492,7 +509,7 @@ static inline int dma_map_cont(struct scatterlist *sg, int start, int stopat, > 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); > } > > /* >@@ -533,8 +550,8 @@ int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir) > 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; >@@ -545,7 +562,7 @@ int dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, int dir) > 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(dev); >diff --git a/lib/Makefile b/lib/Makefile >index 6b0defc..c01f7f8 100644 >--- a/lib/Makefile >+++ b/lib/Makefile >@@ -26,6 +26,8 @@ obj-$(CONFIG_GENERIC_IOMAP) += iomap.o > obj-$(CONFIG_ZLIB_INFLATE) += zlib_inflate/ > obj-$(CONFIG_ZLIB_DEFLATE) += zlib_deflate/ > >+obj-$(CONFIG_GART_IOMMU) += iommu-helper.o >+ > hostprogs-y := gen_crc32table > clean-files := crc32table.h >
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 298811
:
216601
|
217641
|
217701
|
217711
|
246651
|
296071
|
296072
|
302376
|
310803
|
310807
|
310860
|
312159
|
312162
|
312163
|
312462
| 312916