Linux IOMMU Development
 help / color / mirror / Atom feed
* Re: [PATCH v2 25/26] omap3isp: Move to videobuf2
       [not found]         ` <5509E6DF.4080900@logicpd.com>
@ 2015-03-18 21:44           ` Sakari Ailus
  2015-03-18 22:43             ` Tim Nordell
  0 siblings, 1 reply; 2+ messages in thread
From: Sakari Ailus @ 2015-03-18 21:44 UTC (permalink / raw)
  To: Tim Nordell; +Cc: Laurent Pinchart, linux-media, iommu

Hi Tim,

On Wed, Mar 18, 2015 at 03:58:07PM -0500, Tim Nordell wrote:
> Laurent -
> 
> On 03/18/15 14:49, Tim Nordell wrote:
> >Digging through to find who is responsible for assigning the virtual
> >addresses, I find that it's buried inside
> >arch/arm/mm/dma-mapping.c:__alloc_iova(...).  This call is called
> >individually for each entry in the scatter-gather table via
> >__map_sg_chunk from iommu_map_sg(...).  If this is supposed to allocate
> >a contiguous virtual memory region, it seems that __iommu_map_sg(...)
> >should be considering the full buffer range rather than parts of the
> >buffer at a time for the virtual allocation, similar to how
> >__iommu_create_mapping(...) works in the same file.
> >
> >- Tim
> >
> 
> I've confirmed that this code is the culprit for allocating a
> non-contiguous space (called via the dma_map_sg_attrs(...) back down
> in the videobuf2-dma-contig).  I've reworked it for testing so that
> it does an __alloc_iova(...) on the entire region rather than a
> chunk at a time, however, I don't think what I have locally is
> completely the right approach for the generic case since I think
> technically a given entry in the scatterlist could end up with the
> end of a page partially used (the per list entry ->offset and such).
> 
> Looks like code (the specific functions in mm/dma-mapping.c) in
> question was last touched in 2012 with a quick git-blame, but I
> don't know how long the OMAP 3 ISP code has been using this common
> code.  I'm guessing it's only been since the virtual memory manager
> internal to the IOMMU code was removed in July of last year.

I don't think omap3isp has been using this very long. A few minor versions
perhaps.

> Do you know if this common code is supposed to guarantee a
> physically contiguous memory region?  The documentation for the
> function doesn't indicate that it should, and it certainly doesn't
> as-is.  It seems like hitting this issue is highly dependent on the
> size of the buffer one is allocating.

I guess there aren't too many drivers that may map large areas of memory
pinned using get_user_pages() to IOMMU. If dma_map_sg() couldn't be used to
allocate virtually contiguous memory, then what could be? This looks like a
bug in __iommu_map_sg() to me.

Cc the iommu list.

-- 
Kind regards,

Sakari Ailus
e-mail: sakari.ailus@iki.fi	XMPP: sailus@retiisi.org.uk

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 25/26] omap3isp: Move to videobuf2
  2015-03-18 21:44           ` [PATCH v2 25/26] omap3isp: Move to videobuf2 Sakari Ailus
@ 2015-03-18 22:43             ` Tim Nordell
  0 siblings, 0 replies; 2+ messages in thread
From: Tim Nordell @ 2015-03-18 22:43 UTC (permalink / raw)
  To: Sakari Ailus; +Cc: Laurent Pinchart, linux-media, iommu

On 03/18/15 16:44, Sakari Ailus wrote:
>
> I don't think omap3isp has been using this very long. A few minor versions
> perhaps.
>
>> Do you know if this common code is supposed to guarantee a
>> physically contiguous memory region?  The documentation for the
>> function doesn't indicate that it should, and it certainly doesn't
>> as-is.  It seems like hitting this issue is highly dependent on the
>> size of the buffer one is allocating.
>
> I guess there aren't too many drivers that may map large areas of memory
> pinned using get_user_pages() to IOMMU. If dma_map_sg() couldn't be used to
> allocate virtually contiguous memory, then what could be? This looks like a
> bug in __iommu_map_sg() to me.
>
> Cc the iommu list.
>

After staring at this for a while, I realized that the mm/dma-mapping.c 
is doing exactly what it's supposed to (and works similarly to how I was 
starting to refactor the outer function) and that the omap3isp driver 
needs to do one further step in initialization.

There is a call dma_set_max_seg_size(...) that defines how the code in 
dma-mapping.c chunks things up.  If it's set larger, the dma-mapping 
routine will allocate larger physically contiguous chunks in the virtual 
memory space.  Any clue where the best place in omap3isp to set this is?

At least it's a short patch to omap3isp to fix this behavior.  I'll be 
sending a patch along shortly.

- Tim

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-18 22:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <1398083352-8451-1-git-send-email-laurent.pinchart@ideasonboard.com>
     [not found] ` <2315546.eR07gyadH5@avalon>
     [not found]   ` <55099773.2010809@logicpd.com>
     [not found]     ` <2250003.9yO29CjKoc@avalon>
     [not found]       ` <5509D6BC.6080006@logicpd.com>
     [not found]         ` <5509E6DF.4080900@logicpd.com>
2015-03-18 21:44           ` [PATCH v2 25/26] omap3isp: Move to videobuf2 Sakari Ailus
2015-03-18 22:43             ` Tim Nordell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox