All of lore.kernel.org
 help / color / mirror / Atom feed
* AF_XDP and dma
@ 2021-04-09  9:36 ratheesh kannoth
  2021-04-09  9:42 ` Magnus Karlsson
  0 siblings, 1 reply; 10+ messages in thread
From: ratheesh kannoth @ 2021-04-09  9:36 UTC (permalink / raw)
  To: xdp-newbies, brouer

Hi List,

Could you help with the below query ?

if userspace allocates UMEM memory in non contiguous physical memory
 (contiguous in virual address space),  how can i configure DMA ?

https://github.com/xdp-project/xdp-tutorial  AF_XDP example uses
posix_memalign(). will it ensure each buffer chunk is in contiguous
physical address space ?

-Ratheesh

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

* Re: AF_XDP and dma
  2021-04-09  9:36 AF_XDP and dma ratheesh kannoth
@ 2021-04-09  9:42 ` Magnus Karlsson
  2021-04-09 10:01   ` ratheesh kannoth
  0 siblings, 1 reply; 10+ messages in thread
From: Magnus Karlsson @ 2021-04-09  9:42 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 11:36 AM ratheesh kannoth <ratheesh.ksz@gmail.com> wrote:
>
> Hi List,
>
> Could you help with the below query ?
>
> if userspace allocates UMEM memory in non contiguous physical memory
>  (contiguous in virual address space),  how can i configure DMA ?
>
> https://github.com/xdp-project/xdp-tutorial  AF_XDP example uses
> posix_memalign(). will it ensure each buffer chunk is in contiguous
> physical address space ?

The short answer is that you do not have to worry about that at all in
user space. DMA is taken care of by the kernel. The only requirement
is that the umem is located in a virtually contiguous address space
since you can only register one area per umem. Physically, it can be
located scattered around the whole memory, but you do not have to
worry about that. posix_memalign() only aligns the allocated area in
virtual memory. It does not guarantee anything else.

/Magnus

> -Ratheesh

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

* Re: AF_XDP and dma
  2021-04-09  9:42 ` Magnus Karlsson
@ 2021-04-09 10:01   ` ratheesh kannoth
  2021-04-09 10:07     ` Magnus Karlsson
  0 siblings, 1 reply; 10+ messages in thread
From: ratheesh kannoth @ 2021-04-09 10:01 UTC (permalink / raw)
  To: Magnus Karlsson; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 3:13 PM Magnus Karlsson
<magnus.karlsson@gmail.com> wrote:
> The short answer is that you do not have to worry about that at all in
> user space.
i am interested in kernel space, where i have to configure these
memory address (physical) in HW

>>>DMA is taken care of by the kernel.
Agreed. For AF_XDP in driver mode (for zero copy mode), I need to
configure the DMA address.

> /Magnus

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

* Re: AF_XDP and dma
  2021-04-09 10:01   ` ratheesh kannoth
@ 2021-04-09 10:07     ` Magnus Karlsson
  2021-04-09 10:12       ` ratheesh kannoth
  0 siblings, 1 reply; 10+ messages in thread
From: Magnus Karlsson @ 2021-04-09 10:07 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 12:01 PM ratheesh kannoth <ratheesh.ksz@gmail.com> wrote:
>
> On Fri, Apr 9, 2021 at 3:13 PM Magnus Karlsson
> <magnus.karlsson@gmail.com> wrote:
> > The short answer is that you do not have to worry about that at all in
> > user space.
> i am interested in kernel space, where i have to configure these
> memory address (physical) in HW
>
> >>>DMA is taken care of by the kernel.
> Agreed. For AF_XDP in driver mode (for zero copy mode), I need to
> configure the DMA address.

Only if you are writing your own kernel driver for a NIC. Are you doing that?

> > /Magnus

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

* Re: AF_XDP and dma
  2021-04-09 10:07     ` Magnus Karlsson
@ 2021-04-09 10:12       ` ratheesh kannoth
  2021-04-09 10:20         ` Magnus Karlsson
  0 siblings, 1 reply; 10+ messages in thread
From: ratheesh kannoth @ 2021-04-09 10:12 UTC (permalink / raw)
  To: Magnus Karlsson; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 3:37 PM Magnus Karlsson
<magnus.karlsson@gmail.com> wrote:
> Only if you are writing your own kernel driver for a NIC. Are you doing that?
Yes.

> > > /Magnus

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

* Re: AF_XDP and dma
  2021-04-09 10:12       ` ratheesh kannoth
@ 2021-04-09 10:20         ` Magnus Karlsson
  2021-04-09 10:50           ` ratheesh kannoth
  0 siblings, 1 reply; 10+ messages in thread
From: Magnus Karlsson @ 2021-04-09 10:20 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 12:12 PM ratheesh kannoth <ratheesh.ksz@gmail.com> wrote:
>
> On Fri, Apr 9, 2021 at 3:37 PM Magnus Karlsson
> <magnus.karlsson@gmail.com> wrote:
> > Only if you are writing your own kernel driver for a NIC. Are you doing that?
> Yes.

Then looking at user-space code will not help you :-). Take a look at
the code in driver/net/ethernet/intel/i40e/i40e_xsk.c in the Linux
kernel for an example on how to DMA map the umem.

> > > > /Magnus

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

* Re: AF_XDP and dma
  2021-04-09 10:20         ` Magnus Karlsson
@ 2021-04-09 10:50           ` ratheesh kannoth
  2021-04-09 11:06             ` Magnus Karlsson
  0 siblings, 1 reply; 10+ messages in thread
From: ratheesh kannoth @ 2021-04-09 10:50 UTC (permalink / raw)
  To: Magnus Karlsson; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 3:50 PM Magnus Karlsson
<magnus.karlsson@gmail.com> wrote:
> Then looking at user-space code will not help you :-). Take a look at
> the code in driver/net/ethernet/intel/i40e/i40e_xsk.c in the Linux
> kernel for an example on how to DMA map the umem.

Thanks, i could see that it is pinning the pages and mapping.

Using Kernel DMA api, we can map the virtual memory. But how the NIC
can write/read to the memory if it is not physically contiguous. NIC
card only understand physical addresses. Correct me.

> > > > > /Magnus

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

* Re: AF_XDP and dma
  2021-04-09 10:50           ` ratheesh kannoth
@ 2021-04-09 11:06             ` Magnus Karlsson
  2021-04-09 11:23               ` ratheesh kannoth
  0 siblings, 1 reply; 10+ messages in thread
From: Magnus Karlsson @ 2021-04-09 11:06 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 12:50 PM ratheesh kannoth <ratheesh.ksz@gmail.com> wrote:
>
> On Fri, Apr 9, 2021 at 3:50 PM Magnus Karlsson
> <magnus.karlsson@gmail.com> wrote:
> > Then looking at user-space code will not help you :-). Take a look at
> > the code in driver/net/ethernet/intel/i40e/i40e_xsk.c in the Linux
> > kernel for an example on how to DMA map the umem.
>
> Thanks, i could see that it is pinning the pages and mapping.
>
> Using Kernel DMA api, we can map the virtual memory. But how the NIC
> can write/read to the memory if it is not physically contiguous. NIC
> card only understand physical addresses. Correct me.

In XDP/AF_XDP mode, the NIC only uses a single 4K page (on x86-64) per
packet so it will be physically contiguous by definition. Every single
page will be dma mapped separately and can reside anywhere. There is
no scatter-gather in XDP/AF_XDP mode.

> > > > > > /Magnus

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

* Re: AF_XDP and dma
  2021-04-09 11:06             ` Magnus Karlsson
@ 2021-04-09 11:23               ` ratheesh kannoth
  2021-04-09 11:30                 ` Magnus Karlsson
  0 siblings, 1 reply; 10+ messages in thread
From: ratheesh kannoth @ 2021-04-09 11:23 UTC (permalink / raw)
  To: Magnus Karlsson; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 4:36 PM Magnus Karlsson
<magnus.karlsson@gmail.com> wrote:

> In XDP/AF_XDP mode, the NIC only uses a single 4K page (on x86-64) per
> packet so it will be physically contiguous by definition.
How ? if userspace allocates memory, it would be only contiguous in
virtual address space.
 >Every single
> page will be dma mapped separately and can reside anywhere.
I agree.  My concern is not on total memory. it is about each chunk.

>There is
> no scatter-gather in XDP/AF_XDP mode.
i agree.  i am not talking about Scatter gather (nr_frags or frag_list)

> > > > > > > /Magnus

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

* Re: AF_XDP and dma
  2021-04-09 11:23               ` ratheesh kannoth
@ 2021-04-09 11:30                 ` Magnus Karlsson
  0 siblings, 0 replies; 10+ messages in thread
From: Magnus Karlsson @ 2021-04-09 11:30 UTC (permalink / raw)
  To: ratheesh kannoth; +Cc: Xdp, Jesper Dangaard Brouer

On Fri, Apr 9, 2021 at 1:23 PM ratheesh kannoth <ratheesh.ksz@gmail.com> wrote:
>
> On Fri, Apr 9, 2021 at 4:36 PM Magnus Karlsson
> <magnus.karlsson@gmail.com> wrote:
>
> > In XDP/AF_XDP mode, the NIC only uses a single 4K page (on x86-64) per
> > packet so it will be physically contiguous by definition.
> How ? if userspace allocates memory, it would be only contiguous in
> virtual address space.

Physically it only has to be contiguous in a 4K page, since we are
only using a single 4K page for each packet. And a single page is
always contiguous in both virtual and physical memory by definition.
The umem is broken up into pages and these are mapped separately. The
whole umem does not have to be physically contiguous. The NIC only
cares about every single frame (and only one frame per packet is
allowed with XDP for now) being in a physically contiguous region and
that we satisfy by limiting the size of a packet to one page.

>  >Every single
> > page will be dma mapped separately and can reside anywhere.
> I agree.  My concern is not on total memory. it is about each chunk.
>
> >There is
> > no scatter-gather in XDP/AF_XDP mode.
> i agree.  i am not talking about Scatter gather (nr_frags or frag_list)
>
> > > > > > > > /Magnus

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

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

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-09  9:36 AF_XDP and dma ratheesh kannoth
2021-04-09  9:42 ` Magnus Karlsson
2021-04-09 10:01   ` ratheesh kannoth
2021-04-09 10:07     ` Magnus Karlsson
2021-04-09 10:12       ` ratheesh kannoth
2021-04-09 10:20         ` Magnus Karlsson
2021-04-09 10:50           ` ratheesh kannoth
2021-04-09 11:06             ` Magnus Karlsson
2021-04-09 11:23               ` ratheesh kannoth
2021-04-09 11:30                 ` Magnus Karlsson

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.