public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Prarit Bhargava <prarit@redhat.com>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
	joro@8bytes.org, linux-kernel@vger.kernel.org,
	linux-pci@vger.kernel.org
Subject: Re: [PATCH]: PCI: GART iommu alignment fixes [v2]
Date: Thu, 07 Aug 2008 13:41:40 -0400	[thread overview]
Message-ID: <489B33D4.1080107@redhat.com> (raw)
In-Reply-To: <200808071003.47326.jbarnes@virtuousgeek.org>



Jesse Barnes wrote:
> On Wednesday, August 6, 2008 7:32 am Prarit Bhargava wrote:
>   
>>> You can't kmalloc pci_dev or setup some trivial values. You need to
>>> use a proper value. The pci code does for us.
>>>       
>> Oops -- I meant struct device, not struct pci_dev.
>>
>> Anwyay, Jesse -- is this true?  I can no longer do something like:
>>
>>
>> static struct device junk_dev = {
>>         .bus_id = "junk device",
>>         .coherent_dma_mask = 0xffffffff,
>>         .dma_mask = &junk_dev.coherent_dma_mask,
>> };
>>
>> And then use that as the device target for dma_alloc_coherent?  AFAIK,
>> that has always worked for me.
>>     
>
> It gets dangerous since platforms are in control of some pci_dev and dev 
> fields, and if they don't get initialized you can get into trouble.
>   

True, but dma_alloc_coherent also allows for a NULL dev pointer, and 
uses a dummy struct dev (fallback_device).  So it should be callable 
without any dev struct pointer.

In that case, I hit the BUG() check warning in iommu_is_span_boundary() 
because boundary_size was calculated as (unsigned long) 0xffffffff + 1 = 0.

That's why we must cast to "unsigned long long".

ie) it is possible to hit this BUG() right now.

>   
>>> Calgary IOMMU has the same code. New AMD IOMMU has the same code too.
>>>       
>> Then they don't handle the above problem and are broken when
>> dma_get_seg_boundary() returns 0xffffffff and will require patches.
>>
>> /me hasn't tried out Calgary of AMD IOMMU.
>>     
>
> Would be good to find someone to do some testing on one of those platforms...
>   

I've pinged someone at AMD to see if I can get my hands on a system (or 
if to see if there is a system available locally).

As for Calgary, I'm looking into it ATM.  I think I can get my hands on one.

If I find the problem on those platforms I'll ping the maintainers and 
post separate patches.  ATM I'm much more concerned about GART.

>   
>>>> Maybe I'm missing something -- what implies  size has to be a power of
>>>> two?
>>>>         
>>> Yes, see iommu_area_alloc().
>>>       
>> /me looks and still doesn't see where the size passed into
>> gart_map_simple() must be a power of two.  ... and if that was the case,
>> shouldn't we be failing all the time?  I mean, I've seen values passed
>> into pci_alloc_consistent like 0x3820 -- clearly not a multiple of 2.
>>
>> iommu_area_alloc() deals with pages, not actual sizes as
>> gart_map_simple() does.
>>     

Tomonori-san, I think I understand where your confusion may lie.  The 
size argument in the iommu-helper.c code is NOT the same size in 
dma_alloc_coherent() and gart_map_simple().  In iommu-helper.c the size 
is the # of pages, and the in the exported function calls it is an 
actual size.  Is that what is confusing you?

>> If anything, I would make this simple fix:
>>
>> dma_addr_t map = dma_map_area(dev, paddr, size, dir, size - 1);
>>
>> should be
>>
>> dma_addr_t map = dma_map_area(dev, paddr, size, dir, size);
>>
>> because after my patch we round up the mask argument to get the correct
>> alignment to # of pages anyway.
>>     
>
> Feel like respinning with a full changelog against my for-linus branch?  Maybe 
> you can convince Tomonori-san this time. :)
>
>   

I no longer think the above suggested change is necessary.  AFAICT, the 
code is doing exactly the right thing.  "size-1" is correct.

P.

> Jesse
>   

  reply	other threads:[~2008-08-07 17:43 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
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 [this message]
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=489B33D4.1080107@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox