linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* semantics of dma_map_single()
@ 2017-07-16  1:24 Vineet Gupta
  2017-07-17  6:42 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Vineet Gupta @ 2017-07-16  1:24 UTC (permalink / raw)
  To: linux-arch, linux-mm, Christoph Hellwig, bart.vanassche,
	Alexander Duyck, Krzysztof Kozlowski, Andrew Morton
  Cc: lkml, arcml

P.S. Apologies in advance for the explicit TO list, it seemed adding people who've 
touched the dma mapping code (for ARC atleast), would respond sooner ;-)

The question is does dma_map_single() imply a single region (possibly > PAGE_SIZE) 
or does it imply PAGE_SIZE. Documentation/DMA-API* is not explicit about one or 
the other and the code below seems to point to "a" struct page, although it could 
also mean multiple pages, specially if the pages are contiguous, say as those 
returned by alloc_pages(with order > 0)


	static inline dma_addr_t dma_map_single_attrs(dev, size, dir, attrs)
	{
		addr = ops->map_page(dev,
			virt_to_page(ptr), <--- this is one struct page
			offset_in_page(ptr), size, dir, attrs);
	}

ARC dma_map_single() currently only handles cache coherency for only one struct 
page or PAGE_SIZE worth of memory, and we have a customer who seem to assume that 
it handles a region.

Looking at other arches dma mapping backend, it is not clear either what the 
semantics are.

Thx,
-Vineet

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: semantics of dma_map_single()
  2017-07-16  1:24 semantics of dma_map_single() Vineet Gupta
@ 2017-07-17  6:42 ` Christoph Hellwig
  2017-07-17 16:06   ` Vineet Gupta
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2017-07-17  6:42 UTC (permalink / raw)
  To: Vineet Gupta
  Cc: linux-arch, linux-mm, Christoph Hellwig, bart.vanassche,
	Alexander Duyck, Krzysztof Kozlowski, Andrew Morton, lkml, arcml

I would expect that it would support any contiguous range in
the kernel mapping (e.g. no vmalloc and friends).  But it's not
documented anywhere, and if no in kernel users makes use of that
fact at the moment it might be better to document a page size
limitation and add asserts to enforce it.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: semantics of dma_map_single()
  2017-07-17  6:42 ` Christoph Hellwig
@ 2017-07-17 16:06   ` Vineet Gupta
  2017-07-17 16:46     ` James Bottomley
  0 siblings, 1 reply; 4+ messages in thread
From: Vineet Gupta @ 2017-07-17 16:06 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: linux-arch, linux-mm, bart.vanassche, Alexander Duyck,
	Krzysztof Kozlowski, Andrew Morton, lkml, arcml

Hi Christoph,

On 07/16/2017 11:42 PM, Christoph Hellwig wrote:
> I would expect that it would support any contiguous range in
> the kernel mapping (e.g. no vmalloc and friends).  But it's not
> documented anywhere, and if no in kernel users makes use of that
> fact at the moment it might be better to document a page size
> limitation and add asserts to enforce it.

My first thought was indeed to add a BUG_ON for @size > PAGE_SIZE (also accounting 
for offset etc), but I have a feeling this will cause too many breakages. So 
perhaps it would be better to add the fact to Documentation that it can handle any 
physically contiguous range.

-Vineet

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: semantics of dma_map_single()
  2017-07-17 16:06   ` Vineet Gupta
@ 2017-07-17 16:46     ` James Bottomley
  0 siblings, 0 replies; 4+ messages in thread
From: James Bottomley @ 2017-07-17 16:46 UTC (permalink / raw)
  To: Vineet Gupta, Christoph Hellwig
  Cc: linux-arch, linux-mm, bart.vanassche, Alexander Duyck,
	Krzysztof Kozlowski, Andrew Morton, lkml, arcml

On Mon, 2017-07-17 at 09:06 -0700, Vineet Gupta wrote:
> Hi Christoph,
> 
> On 07/16/2017 11:42 PM, Christoph Hellwig wrote:
> > 
> > I would expect that it would support any contiguous range in
> > the kernel mapping (e.g. no vmalloc and friends).A A But it's not
> > documented anywhere, and if no in kernel users makes use of that
> > fact at the moment it might be better to document a page size
> > limitation and add asserts to enforce it.
> 
> My first thought was indeed to add a BUG_ON for @size > PAGE_SIZE
> (also accounting for offset etc), but I have a feeling this will
> cause too many breakages. So perhaps it would be better to add the
> fact to Documentation that it can handle any physically contiguous
> range.

Actually, that's not historically right. A dma_map_single() was
originally designed to be called on any region that was kmalloc'd
meaning it was capable of mapping physically contiguous > PAGE_SIZE
regions.

For years (decades?) we've been eliminating the specialised
dma_map_single() calls in favour of dma_map_sg, so it's possible there
may not be any large region consumers anymore, so it *may* be safe to
enforce a PAGE_SIZE limit, but not without auditing the remaining
callers.

James

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2017-07-17 16:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-16  1:24 semantics of dma_map_single() Vineet Gupta
2017-07-17  6:42 ` Christoph Hellwig
2017-07-17 16:06   ` Vineet Gupta
2017-07-17 16:46     ` James Bottomley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).