From: Ingo Molnar <mingo@elte.hu>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: prarit@redhat.com, jbarnes@virtuousgeek.org, joro@8bytes.org,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH]: PCI: GART iommu alignment fixes [v2]
Date: Sun, 17 Aug 2008 14:56:14 +0200 [thread overview]
Message-ID: <20080817125614.GA31875@elte.hu> (raw)
In-Reply-To: <20080816101601K.fujita.tomonori@lab.ntt.co.jp>
* FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> wrote:
> > Config is:
> >
> > http://redhat.com/~mingo/misc/config-Fri_Aug_15_18_30_56_CEST_2008.bad
> >
> > Any idea why that is so? Apparently the alignment change wasnt as benign
> > as assumed.
>
> Ah, sorry,
>
> @@ -262,7 +264,11 @@ static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
> static dma_addr_t
> gart_map_simple(struct device *dev, phys_addr_t paddr, size_t size, int dir)
> {
> - dma_addr_t map = dma_map_area(dev, paddr, size, dir);
> + dma_addr_t map;
> + unsigned long align_mask;
> +
> + align_mask = (roundup_pow_of_two(size) >> PAGE_SHIFT) - 1;
> + map = dma_map_area(dev, paddr, size, dir, align_mask);
>
> This code doesn't work with the case size < PAGE_SIZE.
>
> I think that dmam_alloc_consistent in libata-core fails due to this
> bug.
>
> Can you try this?
ok - merged the commit below in tip/x86/iommu.
> BTW, I think that this is not urgent stuff at all.
ok - i've queued it up for v2.6.28.
Ingo
-------------->
>From 4ae29849888f85a0cee12553995d47ec527ad049 Mon Sep 17 00:00:00 2001
From: Prarit Bhargava <prarit@redhat.com>
Date: Sat, 16 Aug 2008 10:15:32 +0900
Subject: [PATCH] x86 gart: allocate size-aligned address for alloc_coherent, v2
pci_alloc_consistent/dma_alloc_coherent does not 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. Modify alloc_iommu to allow for an alignment mask
2. Modify pci_gart_simple to return size-aligned values.
3. Fixup the alignment calculation in the iommu-helper code.
4. Fix possible overflow in alloc_iommu's boundary_size calculation.
(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.)
End result: When allocating from IOMMU, pci_alloc_consistent/dma_alloc_coherent
will now return a size aligned value.
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
[ FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>: boot hang fix. ]
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/kernel/pci-gart_64.c | 25 ++++++++++++++++---------
1 files changed, 16 insertions(+), 9 deletions(-)
diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
index cdab678..4d8efb0 100644
--- a/arch/x86/kernel/pci-gart_64.c
+++ b/arch/x86/kernel/pci-gart_64.c
@@ -82,7 +82,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 unsigned long alloc_iommu(struct device *dev, int size)
+static unsigned long alloc_iommu(struct device *dev, int size,
+ unsigned long align_mask)
{
unsigned long offset, flags;
unsigned long boundary_size;
@@ -95,11 +96,12 @@ static unsigned long alloc_iommu(struct device *dev, int size)
spin_lock_irqsave(&iommu_bitmap_lock, flags);
offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, next_bit,
- size, base_index, boundary_size, 0);
+ size, base_index, boundary_size, align_mask);
if (offset == -1) {
need_flush = 1;
offset = iommu_area_alloc(iommu_gart_bitmap, iommu_pages, 0,
- size, base_index, boundary_size, 0);
+ size, base_index, boundary_size,
+ align_mask);
}
if (offset != -1) {
next_bit = offset+size;
@@ -236,10 +238,10 @@ nonforced_iommu(struct device *dev, unsigned long addr, size_t size)
* Caller needs to check if the iommu is needed and flush.
*/
static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
- size_t size, int dir)
+ size_t size, int dir, unsigned long align_mask)
{
unsigned long npages = iommu_num_pages(phys_mem, size);
- unsigned long iommu_page = alloc_iommu(dev, npages);
+ unsigned long iommu_page = alloc_iommu(dev, npages, align_mask);
int i;
if (iommu_page == -1) {
@@ -262,7 +264,11 @@ static dma_addr_t dma_map_area(struct device *dev, dma_addr_t phys_mem,
static dma_addr_t
gart_map_simple(struct device *dev, phys_addr_t paddr, size_t size, int dir)
{
- dma_addr_t map = dma_map_area(dev, paddr, size, dir);
+ dma_addr_t map;
+ unsigned long align_mask;
+
+ align_mask = (1UL << get_order(size)) - 1;
+ map = dma_map_area(dev, paddr, size, dir, align_mask);
flush_gart();
@@ -281,7 +287,8 @@ gart_map_single(struct device *dev, phys_addr_t paddr, size_t size, int dir)
if (!need_iommu(dev, paddr, size))
return paddr;
- bus = gart_map_simple(dev, paddr, size, dir);
+ bus = dma_map_area(dev, paddr, size, dir, 0);
+ flush_gart();
return bus;
}
@@ -340,7 +347,7 @@ static int dma_map_sg_nonforce(struct device *dev, struct scatterlist *sg,
unsigned long addr = sg_phys(s);
if (nonforced_iommu(dev, addr, s->length)) {
- addr = dma_map_area(dev, addr, s->length, dir);
+ addr = dma_map_area(dev, addr, s->length, dir, 0);
if (addr == bad_dma_address) {
if (i > 0)
gart_unmap_sg(dev, sg, i, dir);
@@ -362,7 +369,7 @@ static int __dma_map_cont(struct device *dev, struct scatterlist *start,
int nelems, struct scatterlist *sout,
unsigned long pages)
{
- unsigned long iommu_start = alloc_iommu(dev, pages);
+ unsigned long iommu_start = alloc_iommu(dev, pages, 0);
unsigned long iommu_page = iommu_start;
struct scatterlist *s;
int i;
next prev parent reply other threads:[~2008-08-17 12:56 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-23 11:19 Prarit Bhargava
2008-07-23 22:10 ` Joerg Roedel
2008-07-23 23:14 ` FUJITA Tomonori
2008-07-23 23:47 ` Prarit Bhargava
2008-07-24 7:46 ` Joerg Roedel
2008-07-24 10:09 ` Prarit Bhargava
2008-07-24 10:34 ` FUJITA Tomonori
2008-07-24 12:37 ` Joerg Roedel
2008-07-24 12:49 ` Prarit Bhargava
2008-07-24 13:32 ` FUJITA Tomonori
2008-07-24 14:31 ` Prarit Bhargava
2008-07-24 14:40 ` FUJITA Tomonori
2008-07-24 15:13 ` Prarit Bhargava
2008-07-24 14:45 ` Prarit Bhargava
2008-07-28 22:23 ` Jesse Barnes
2008-07-29 14:24 ` Prarit Bhargava
2008-07-29 17:08 ` Jesse Barnes
2008-07-30 0:43 ` FUJITA Tomonori
2008-08-06 12:29 ` Prarit Bhargava
2008-08-06 13:23 ` Prarit Bhargava
2008-08-06 13:35 ` FUJITA Tomonori
2008-08-06 14:32 ` Prarit Bhargava
2008-08-07 17:03 ` Jesse Barnes
2008-08-07 17:41 ` Prarit Bhargava
2008-08-08 7:12 ` Muli Ben-Yehuda
2008-08-08 15:18 ` Prarit Bhargava
2008-08-08 16:15 ` Jesse Barnes
2008-08-08 21:13 ` FUJITA Tomonori
2008-08-09 1:40 ` Prarit Bhargava
2008-08-09 3:50 ` FUJITA Tomonori
2008-08-15 16:16 ` Ingo Molnar
2008-08-15 18:00 ` Ingo Molnar
2008-08-15 20:39 ` Prarit Bhargava
2008-08-15 21:20 ` Ingo Molnar
2008-08-16 1:15 ` FUJITA Tomonori
2008-08-17 12:56 ` Ingo Molnar [this message]
2008-08-17 15:36 ` FUJITA Tomonori
2008-08-17 15:42 ` Ingo Molnar
2008-08-17 15:48 ` FUJITA Tomonori
2008-08-17 15:54 ` FUJITA Tomonori
2008-08-07 17:45 ` Prarit Bhargava
2008-07-23 23:23 ` FUJITA Tomonori
2008-07-23 23:24 ` Prarit Bhargava
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080817125614.GA31875@elte.hu \
--to=mingo@elte.hu \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=jbarnes@virtuousgeek.org \
--cc=joro@8bytes.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=prarit@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome