linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Enforce USB DMA allocations to specific range
@ 2020-12-28 13:54 Noam Liron
  2020-12-28 14:18 ` Greg KH
  0 siblings, 1 reply; 6+ messages in thread
From: Noam Liron @ 2020-12-28 13:54 UTC (permalink / raw)
  To: linux-usb, Greg KH; +Cc: Yuval Shaia

Hi Greg and thanks for your reply for my previous q. (Proper way to set a DMA_MASK on a USB device).

I am rephrasing my questions:

I am working on LK 4.14.76, on a SOC in which RAM starts at 0x200000000, and need to limit DMA buffer allocations to be at the range 0x200000000 -  0x220000000.
This is a SoC constraint.
Setting the controller dma_mask to 0x21FFFFFFF, didn't solve the problem, as I noticed that URB streaming DMA are first allocated by kmalloc and alike, which are not affected by the dma_mask.

I plan to do the following:
Alloc coherent memory for the HCD using 'dma_declare_coherent_memory', and use the HCD_LOCAL_MEM so the usb core is told that it must copy data into local memory if the buffers happen to be placed in regular memory.

Is that the right way to deal with this case?


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

* Re: Enforce USB DMA allocations to specific range
  2020-12-28 13:54 Enforce USB DMA allocations to specific range Noam Liron
@ 2020-12-28 14:18 ` Greg KH
  2020-12-28 15:18   ` [EXT] " Noam Liron
  2021-02-11  8:38   ` Noam Liron
  0 siblings, 2 replies; 6+ messages in thread
From: Greg KH @ 2020-12-28 14:18 UTC (permalink / raw)
  To: Noam Liron; +Cc: linux-usb, Yuval Shaia

On Mon, Dec 28, 2020 at 01:54:41PM +0000, Noam Liron wrote:
> Hi Greg and thanks for your reply for my previous q. (Proper way to set a DMA_MASK on a USB device).
> 
> I am rephrasing my questions:
> 
> I am working on LK 4.14.76, on a SOC in which RAM starts at 0x200000000, and need to limit DMA buffer allocations to be at the range 0x200000000 -  0x220000000.
> This is a SoC constraint.
> Setting the controller dma_mask to 0x21FFFFFFF, didn't solve the problem, as I noticed that URB streaming DMA are first allocated by kmalloc and alike, which are not affected by the dma_mask.

Why not get support from who ever is forcing you to use that old kernel
version?  You are paying them for this, right?  :)

> I plan to do the following:
> Alloc coherent memory for the HCD using 'dma_declare_coherent_memory', and use the HCD_LOCAL_MEM so the usb core is told that it must copy data into local memory if the buffers happen to be placed in regular memory.
> 
> Is that the right way to deal with this case?

Have you looked at how all of the existing host controller drivers do
this?  Why will they not "just work" properly for you as well?
What host controller driver are you using?

thanks,

greg k-h

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

* RE: [EXT] Re: Enforce USB DMA allocations to specific range
  2020-12-28 14:18 ` Greg KH
@ 2020-12-28 15:18   ` Noam Liron
  2021-02-11  8:38   ` Noam Liron
  1 sibling, 0 replies; 6+ messages in thread
From: Noam Liron @ 2020-12-28 15:18 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-usb, Yuval Shaia


-----Original Message-----
From: Greg KH <greg@kroah.com> 
Sent: Monday, December 28, 2020 4:19 PM
To: Noam Liron <lnoam@marvell.com>
Cc: linux-usb@vger.kernel.org; Yuval Shaia <yshaia@marvell.com>
Subject: [EXT] Re: Enforce USB DMA allocations to specific range

External Email

----------------------------------------------------------------------
On Mon, Dec 28, 2020 at 01:54:41PM +0000, Noam Liron wrote:
> Hi Greg and thanks for your reply for my previous q. (Proper way to set a DMA_MASK on a USB device).
> 
> I am rephrasing my questions:
> 
> I am working on LK 4.14.76, on a SOC in which RAM starts at 0x200000000, and need to limit DMA buffer allocations to be at the range 0x200000000 -  0x220000000.
> This is a SoC constraint.
> Setting the controller dma_mask to 0x21FFFFFFF, didn't solve the problem, as I noticed that URB streaming DMA are first allocated by kmalloc and alike, which are not affected by the dma_mask.

Why not get support from who ever is forcing you to use that old kernel version?  You are paying them for this, right?  :)

[NL] As of now, this is the newest kernel version for this soc, and I am the developer of this soc.
The soc enforces that specific constraint, and AFAIK, USB infrastructure is already built to deal with it, and a newer kernel won't supply with better solution.

> I plan to do the following:
> Alloc coherent memory for the HCD using 'dma_declare_coherent_memory', and use the HCD_LOCAL_MEM so the usb core is told that it must copy data into local memory if the buffers happen to be placed in regular memory.
> 
> Is that the right way to deal with this case?

Have you looked at how all of the existing host controller drivers do this?  Why will they not "just work" properly for you as well?[NL]  I have looked at ohci-sm501.c as it seems to solve similar problem to the one I deal with.
What host controller driver are you using?[NL]  ehci-orion.c

thanks,

greg k-h

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

* RE: [EXT] Re: Enforce USB DMA allocations to specific range
  2020-12-28 14:18 ` Greg KH
  2020-12-28 15:18   ` [EXT] " Noam Liron
@ 2021-02-11  8:38   ` Noam Liron
  2021-02-11  9:02     ` Greg Kroah-Hartman
  2021-02-11 16:00     ` Alan Stern
  1 sibling, 2 replies; 6+ messages in thread
From: Noam Liron @ 2021-02-11  8:38 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: linux-usb, Yuval Shaia

Hi Greg,

I am writing you again on the below subject, as I would like to get a "high level" opinion, and you are probably the most experienced ...

As I wrote below, I cannot rely on the DMA mask, as some USB allocation are not affected by it.
I thought of using private DMA pool that will be allocated where I need it (at the start of physical memory). However, this means adding specific ASIC code, which is less elegant.
Do you think that's the right way?

Thanks,
Noam


-----Original Message-----
From: Greg KH <greg@kroah.com> 
Sent: Monday, December 28, 2020 4:19 PM
To: Noam Liron <lnoam@marvell.com>
Cc: linux-usb@vger.kernel.org; Yuval Shaia <yshaia@marvell.com>
Subject: [EXT] Re: Enforce USB DMA allocations to specific range

External Email

----------------------------------------------------------------------
On Mon, Dec 28, 2020 at 01:54:41PM +0000, Noam Liron wrote:
> Hi Greg and thanks for your reply for my previous q. (Proper way to set a DMA_MASK on a USB device).
> 
> I am rephrasing my questions:
> 
> I am working on LK 4.14.76, on a SOC in which RAM starts at 0x200000000, and need to limit DMA buffer allocations to be at the range 0x200000000 -  0x220000000.
> This is a SoC constraint.
> Setting the controller dma_mask to 0x21FFFFFFF, didn't solve the problem, as I noticed that URB streaming DMA are first allocated by kmalloc and alike, which are not affected by the dma_mask.

Why not get support from who ever is forcing you to use that old kernel version?  You are paying them for this, right?  :)

> I plan to do the following:
> Alloc coherent memory for the HCD using 'dma_declare_coherent_memory', and use the HCD_LOCAL_MEM so the usb core is told that it must copy data into local memory if the buffers happen to be placed in regular memory.
> 
> Is that the right way to deal with this case?

Have you looked at how all of the existing host controller drivers do this?  Why will they not "just work" properly for you as well?
What host controller driver are you using?

thanks,

greg k-h

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

* Re: [EXT] Re: Enforce USB DMA allocations to specific range
  2021-02-11  8:38   ` Noam Liron
@ 2021-02-11  9:02     ` Greg Kroah-Hartman
  2021-02-11 16:00     ` Alan Stern
  1 sibling, 0 replies; 6+ messages in thread
From: Greg Kroah-Hartman @ 2021-02-11  9:02 UTC (permalink / raw)
  To: Noam Liron; +Cc: linux-usb, Yuval Shaia

A: http://en.wikipedia.org/wiki/Top_post
Q: Were do I find info about this thing called top-posting?
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

On Thu, Feb 11, 2021 at 08:38:40AM +0000, Noam Liron wrote:
> Hi Greg,
> 
> I am writing you again on the below subject, as I would like to get a
> "high level" opinion, and you are probably the most experienced ...

I am not a DMA expert at all, why not ask the dma developers instead?

> As I wrote below, I cannot rely on the DMA mask, as some USB
> allocation are not affected by it.

Why "some" and not "others"?  Perhaps you need to fix your platform code
to prevent that from happening instead?  Why is USB unique here?

> I thought of using private DMA pool that will be allocated where I
> need it (at the start of physical memory). However, this means adding
> specific ASIC code, which is less elegant.
> Do you think that's the right way?

I do not know your platform, only you do.

But I do think you should not be doing new development on 4.14, as that
is a very old and obsolete kernel and the dma code in the kernel has
changed a lot since 2017.

good luck!

greg k-h

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

* Re: [EXT] Re: Enforce USB DMA allocations to specific range
  2021-02-11  8:38   ` Noam Liron
  2021-02-11  9:02     ` Greg Kroah-Hartman
@ 2021-02-11 16:00     ` Alan Stern
  1 sibling, 0 replies; 6+ messages in thread
From: Alan Stern @ 2021-02-11 16:00 UTC (permalink / raw)
  To: Noam Liron; +Cc: Greg Kroah-Hartman, linux-usb, Yuval Shaia

On Thu, Feb 11, 2021 at 08:38:40AM +0000, Noam Liron wrote:
> Hi Greg,
> 
> I am writing you again on the below subject, as I would like to get a "high level" opinion, and you are probably the most experienced ...
> 
> As I wrote below, I cannot rely on the DMA mask, as some USB allocation are not affected by it.
> I thought of using private DMA pool that will be allocated where I need it (at the start of physical memory). However, this means adding specific ASIC code, which is less elegant.
> Do you think that's the right way?
> 
> Thanks,
> Noam
> 
> 
> -----Original Message-----
> From: Greg KH <greg@kroah.com> 
> Sent: Monday, December 28, 2020 4:19 PM
> To: Noam Liron <lnoam@marvell.com>
> Cc: linux-usb@vger.kernel.org; Yuval Shaia <yshaia@marvell.com>
> Subject: [EXT] Re: Enforce USB DMA allocations to specific range
> 
> External Email
> 
> ----------------------------------------------------------------------
> On Mon, Dec 28, 2020 at 01:54:41PM +0000, Noam Liron wrote:
> > Hi Greg and thanks for your reply for my previous q. (Proper way to set a DMA_MASK on a USB device).
> > 
> > I am rephrasing my questions:
> > 
> > I am working on LK 4.14.76, on a SOC in which RAM starts at 0x200000000, and need to limit DMA buffer allocations to be at the range 0x200000000 -  0x220000000.
> > This is a SoC constraint.
> > Setting the controller dma_mask to 0x21FFFFFFF, didn't solve the problem, as I noticed that URB streaming DMA are first allocated by kmalloc and alike, which are not affected by the dma_mask.
> 
> Why not get support from who ever is forcing you to use that old kernel version?  You are paying them for this, right?  :)
> 
> > I plan to do the following:
> > Alloc coherent memory for the HCD using 'dma_declare_coherent_memory', and use the HCD_LOCAL_MEM so the usb core is told that it must copy data into local memory if the buffers happen to be placed in regular memory.
> > 
> > Is that the right way to deal with this case?

I think that is the correct way.  That's what the HCD_LOCAL_MEM flag was 
meant for.

Alan Stern

> Have you looked at how all of the existing host controller drivers do this?  Why will they not "just work" properly for you as well?
> What host controller driver are you using?
> 
> thanks,
> 
> greg k-h

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

end of thread, other threads:[~2021-02-11 16:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28 13:54 Enforce USB DMA allocations to specific range Noam Liron
2020-12-28 14:18 ` Greg KH
2020-12-28 15:18   ` [EXT] " Noam Liron
2021-02-11  8:38   ` Noam Liron
2021-02-11  9:02     ` Greg Kroah-Hartman
2021-02-11 16:00     ` Alan Stern

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).