From: Prarit Bhargava <prarit@redhat.com>
To: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
Cc: 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: Wed, 06 Aug 2008 08:29:49 -0400 [thread overview]
Message-ID: <4899993D.3060109@redhat.com> (raw)
In-Reply-To: <20080730094303W.fujita.tomonori@lab.ntt.co.jp>
FUJITA Tomonori wrote:
> On Mon, 28 Jul 2008 15:23:35 -0700
> Jesse Barnes <jbarnes@virtuousgeek.org> wrote:
>
>
>> On Wednesday, July 23, 2008 4:14 pm FUJITA Tomonori wrote:
>>
>>> On Thu, 24 Jul 2008 00:10:33 +0200
>>>
>>> Joerg Roedel <joro@8bytes.org> wrote:
>>>
>>>> On Wed, Jul 23, 2008 at 07:19:43AM -0400, Prarit Bhargava wrote:
>>>>
>>>>> 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."
>>>>>
>>>> Interesting. Have you experienced any problems because of that
>>>> misbehavior in the GART code? AMD IOMMU currently also violates this
>>>> requirement. I will send a patch to fix that there too.
>>>>
>>> IIRC, only PARISC and POWER IOMMUs follow the above rule. So I also
>>> wondered what problem he hit.
>>>
>> Prarit, what's the latest here? The v3 patch I have from you doesn't apply to
>> my tree but it looks like a good fix. Care to send me a new patch against my
>> for-linus branch?
>>
>
> I'm not sure how the following cast to 'unsigned long long' fixes
> something on X86_64.
>
>
You can write a very simple module that kmalloc's a pci_dev, sets up
some trivial values for the dev, and then calls pci_alloc_consistent.
You will panic 100% of the time because 'dma_get_seg_boundary(dev) + 1'
overflows an unsigned long.
>> Signed-off-by: Prarit Bhargava <prarit@redhat.com>
>>
>> diff --git a/arch/x86/kernel/pci-gart_64.c b/arch/x86/kernel/pci-gart_64.c
>> index 744126e..d3eb527 100644
>> --- a/arch/x86/kernel/pci-gart_64.c
>> +++ b/arch/x86/kernel/pci-gart_64.c
>> @@ -85,7 +85,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 mask)
>> {
>> unsigned long offset, flags;
>> unsigned long boundary_size;
>> @@ -93,16 +94,17 @@ static unsigned long alloc_iommu(struct device *dev, int size)
>>
>> base_index = ALIGN(iommu_bus_base & dma_get_seg_boundary(dev),
>> PAGE_SIZE) >> PAGE_SHIFT;
>> - boundary_size = ALIGN(dma_get_seg_boundary(dev) + 1,
>> + boundary_size = ALIGN((unsigned long long)dma_get_seg_boundary(dev) + 1,
>> PAGE_SIZE) >> PAGE_SHIFT;
>>
>
> I don't think that the following code works since the size is not
> always a power of 2.
>
>
>
>> @@ -265,7 +268,7 @@ 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 = dma_map_area(dev, paddr, size, dir, size - 1);
>>
Maybe I'm missing something -- what implies size has to be a power of two?
P.
next prev parent reply other threads:[~2008-08-06 12:35 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-23 11:19 [PATCH]: PCI: GART iommu alignment fixes [v2] 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 [this message]
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
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=4899993D.3060109@redhat.com \
--to=prarit@redhat.com \
--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 \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.