All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned
@ 2021-01-21  7:09 Kevin Hao
  2021-01-21  9:01 ` sundeep subbaraya
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Kevin Hao @ 2021-01-21  7:09 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, netdev, Subbaraya Sundeep
  Cc: Sunil Goutham, Geetha sowjanya, hariprasad

The octeontx2 hardware needs the buffer to be 128 byte aligned.
But in the current implementation of napi_alloc_frag(), it can't
guarantee the return address is 128 byte aligned even the request size
is a multiple of 128 bytes, so we have to request an extra 128 bytes and
use the PTR_ALIGN() to make sure that the buffer is aligned correctly.

Fixes: 7a36e4918e30 ("octeontx2-pf: Use the napi_alloc_frag() to alloc the pool buffers")
Reported-by: Subbaraya Sundeep <sbhatta@marvell.com>
Signed-off-by: Kevin Hao <haokexin@gmail.com>
---
 drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
index bdfa2e293531..5ddedc3b754d 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
@@ -488,10 +488,11 @@ dma_addr_t __otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool)
 	dma_addr_t iova;
 	u8 *buf;
 
-	buf = napi_alloc_frag(pool->rbsize);
+	buf = napi_alloc_frag(pool->rbsize + OTX2_ALIGN);
 	if (unlikely(!buf))
 		return -ENOMEM;
 
+	buf = PTR_ALIGN(buf, OTX2_ALIGN);
 	iova = dma_map_single_attrs(pfvf->dev, buf, pool->rbsize,
 				    DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
 	if (unlikely(dma_mapping_error(pfvf->dev, iova))) {
-- 
2.29.2


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

* Re: [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned
  2021-01-21  7:09 [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned Kevin Hao
@ 2021-01-21  9:01 ` sundeep subbaraya
  2021-01-21  9:53 ` David Laight
  2021-01-23  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: sundeep subbaraya @ 2021-01-21  9:01 UTC (permalink / raw)
  To: Kevin Hao
  Cc: David S . Miller, Jakub Kicinski, netdev, Subbaraya Sundeep,
	Sunil Goutham, Geetha sowjanya, hariprasad

Hi Kevin,

Tested at my end and works fine. Thanks for the patch.

Tested-by: Subbaraya Sundeep <sbhatta@marvell.com>

Sundeep

On Thu, Jan 21, 2021 at 12:51 PM Kevin Hao <haokexin@gmail.com> wrote:
>
> The octeontx2 hardware needs the buffer to be 128 byte aligned.
> But in the current implementation of napi_alloc_frag(), it can't
> guarantee the return address is 128 byte aligned even the request size
> is a multiple of 128 bytes, so we have to request an extra 128 bytes and
> use the PTR_ALIGN() to make sure that the buffer is aligned correctly.
>
> Fixes: 7a36e4918e30 ("octeontx2-pf: Use the napi_alloc_frag() to alloc the pool buffers")
> Reported-by: Subbaraya Sundeep <sbhatta@marvell.com>
> Signed-off-by: Kevin Hao <haokexin@gmail.com>
> ---
>  drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> index bdfa2e293531..5ddedc3b754d 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> @@ -488,10 +488,11 @@ dma_addr_t __otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool)
>         dma_addr_t iova;
>         u8 *buf;
>
> -       buf = napi_alloc_frag(pool->rbsize);
> +       buf = napi_alloc_frag(pool->rbsize + OTX2_ALIGN);
>         if (unlikely(!buf))
>                 return -ENOMEM;
>
> +       buf = PTR_ALIGN(buf, OTX2_ALIGN);
>         iova = dma_map_single_attrs(pfvf->dev, buf, pool->rbsize,
>                                     DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
>         if (unlikely(dma_mapping_error(pfvf->dev, iova))) {
> --
> 2.29.2
>

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

* RE: [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned
  2021-01-21  7:09 [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned Kevin Hao
  2021-01-21  9:01 ` sundeep subbaraya
@ 2021-01-21  9:53 ` David Laight
  2021-01-21 11:51   ` Kevin Hao
  2021-01-23  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 6+ messages in thread
From: David Laight @ 2021-01-21  9:53 UTC (permalink / raw)
  To: 'Kevin Hao',
	David S . Miller, Jakub Kicinski, netdev, Subbaraya Sundeep
  Cc: Sunil Goutham, Geetha sowjanya, hariprasad

From: Kevin Hao
> Sent: 21 January 2021 07:09
> 
> The octeontx2 hardware needs the buffer to be 128 byte aligned.
> But in the current implementation of napi_alloc_frag(), it can't
> guarantee the return address is 128 byte aligned even the request size
> is a multiple of 128 bytes, so we have to request an extra 128 bytes and
> use the PTR_ALIGN() to make sure that the buffer is aligned correctly.
> 
> Fixes: 7a36e4918e30 ("octeontx2-pf: Use the napi_alloc_frag() to alloc the pool buffers")
> Reported-by: Subbaraya Sundeep <sbhatta@marvell.com>
> Signed-off-by: Kevin Hao <haokexin@gmail.com>
> ---
>  drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> index bdfa2e293531..5ddedc3b754d 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> @@ -488,10 +488,11 @@ dma_addr_t __otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool)
>  	dma_addr_t iova;
>  	u8 *buf;
> 
> -	buf = napi_alloc_frag(pool->rbsize);
> +	buf = napi_alloc_frag(pool->rbsize + OTX2_ALIGN);
>  	if (unlikely(!buf))
>  		return -ENOMEM;
> 
> +	buf = PTR_ALIGN(buf, OTX2_ALIGN);
>  	iova = dma_map_single_attrs(pfvf->dev, buf, pool->rbsize,
>  				    DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
>  	if (unlikely(dma_mapping_error(pfvf->dev, iova))) {
> --
> 2.29.2

Doesn't that break the 'free' code ?
Surely it needs the original pointer.

It isn't obvious that page_frag_free() it correct when the
allocator is napi_alloc_frag() either.
I'd have thought it ought to be returned to the pool.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)


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

* Re: [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned
  2021-01-21  9:53 ` David Laight
@ 2021-01-21 11:51   ` Kevin Hao
  2021-01-21 12:42     ` Sunil Kovvuri
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Hao @ 2021-01-21 11:51 UTC (permalink / raw)
  To: David Laight
  Cc: David S . Miller, Jakub Kicinski, netdev, Subbaraya Sundeep,
	Sunil Goutham, Geetha sowjanya, hariprasad

[-- Attachment #1: Type: text/plain, Size: 2318 bytes --]

On Thu, Jan 21, 2021 at 09:53:08AM +0000, David Laight wrote:
> From: Kevin Hao
> > Sent: 21 January 2021 07:09
> > 
> > The octeontx2 hardware needs the buffer to be 128 byte aligned.
> > But in the current implementation of napi_alloc_frag(), it can't
> > guarantee the return address is 128 byte aligned even the request size
> > is a multiple of 128 bytes, so we have to request an extra 128 bytes and
> > use the PTR_ALIGN() to make sure that the buffer is aligned correctly.
> > 
> > Fixes: 7a36e4918e30 ("octeontx2-pf: Use the napi_alloc_frag() to alloc the pool buffers")
> > Reported-by: Subbaraya Sundeep <sbhatta@marvell.com>
> > Signed-off-by: Kevin Hao <haokexin@gmail.com>
> > ---
> >  drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> > b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> > index bdfa2e293531..5ddedc3b754d 100644
> > --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> > @@ -488,10 +488,11 @@ dma_addr_t __otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool)
> >  	dma_addr_t iova;
> >  	u8 *buf;
> > 
> > -	buf = napi_alloc_frag(pool->rbsize);
> > +	buf = napi_alloc_frag(pool->rbsize + OTX2_ALIGN);
> >  	if (unlikely(!buf))
> >  		return -ENOMEM;
> > 
> > +	buf = PTR_ALIGN(buf, OTX2_ALIGN);
> >  	iova = dma_map_single_attrs(pfvf->dev, buf, pool->rbsize,
> >  				    DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
> >  	if (unlikely(dma_mapping_error(pfvf->dev, iova))) {
> > --
> > 2.29.2
> 
> Doesn't that break the 'free' code ?
> Surely it needs the original pointer.

Why do we care about the original pointer? The free code should work with
the mangling poiner. Did I miss something?

> 
> It isn't obvious that page_frag_free() it correct when the
> allocator is napi_alloc_frag() either.
> I'd have thought it ought to be returned to the pool.

Sorry, I didn't get what you mean. Could you elaborate a bit more?

Thanks,
Kevin

> 
> 	David
> 
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned
  2021-01-21 11:51   ` Kevin Hao
@ 2021-01-21 12:42     ` Sunil Kovvuri
  0 siblings, 0 replies; 6+ messages in thread
From: Sunil Kovvuri @ 2021-01-21 12:42 UTC (permalink / raw)
  To: Kevin Hao
  Cc: David Laight, David S . Miller, Jakub Kicinski, netdev,
	Subbaraya Sundeep, Sunil Goutham, Geetha sowjanya, hariprasad

On Thu, Jan 21, 2021 at 5:26 PM Kevin Hao <haokexin@gmail.com> wrote:
>
> On Thu, Jan 21, 2021 at 09:53:08AM +0000, David Laight wrote:
> > From: Kevin Hao
> > > Sent: 21 January 2021 07:09
> > >
> > > The octeontx2 hardware needs the buffer to be 128 byte aligned.
> > > But in the current implementation of napi_alloc_frag(), it can't
> > > guarantee the return address is 128 byte aligned even the request size
> > > is a multiple of 128 bytes, so we have to request an extra 128 bytes and
> > > use the PTR_ALIGN() to make sure that the buffer is aligned correctly.
> > >
> > > Fixes: 7a36e4918e30 ("octeontx2-pf: Use the napi_alloc_frag() to alloc the pool buffers")
> > > Reported-by: Subbaraya Sundeep <sbhatta@marvell.com>
> > > Signed-off-by: Kevin Hao <haokexin@gmail.com>
> > > ---
> > >  drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++-
> > >  1 file changed, 2 insertions(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> > > b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> > > index bdfa2e293531..5ddedc3b754d 100644
> > > --- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> > > +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> > > @@ -488,10 +488,11 @@ dma_addr_t __otx2_alloc_rbuf(struct otx2_nic *pfvf, struct otx2_pool *pool)
> > >     dma_addr_t iova;
> > >     u8 *buf;
> > >
> > > -   buf = napi_alloc_frag(pool->rbsize);
> > > +   buf = napi_alloc_frag(pool->rbsize + OTX2_ALIGN);
> > >     if (unlikely(!buf))
> > >             return -ENOMEM;
> > >
> > > +   buf = PTR_ALIGN(buf, OTX2_ALIGN);
> > >     iova = dma_map_single_attrs(pfvf->dev, buf, pool->rbsize,
> > >                                 DMA_FROM_DEVICE, DMA_ATTR_SKIP_CPU_SYNC);
> > >     if (unlikely(dma_mapping_error(pfvf->dev, iova))) {
> > > --
> > > 2.29.2
> >
> > Doesn't that break the 'free' code ?
> > Surely it needs the original pointer.
>
> Why do we care about the original pointer? The free code should work with
> the mangling poiner. Did I miss something?
>
> >

I too agree, put_page(buf) or put_page(buf + OTX2_ALIGN) is same.

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

* Re: [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned
  2021-01-21  7:09 [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned Kevin Hao
  2021-01-21  9:01 ` sundeep subbaraya
  2021-01-21  9:53 ` David Laight
@ 2021-01-23  2:10 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-01-23  2:10 UTC (permalink / raw)
  To: Kevin Hao; +Cc: davem, kuba, netdev, sbhatta, sgoutham, gakula, hkelam

Hello:

This patch was applied to netdev/net.git (refs/heads/master):

On Thu, 21 Jan 2021 15:09:06 +0800 you wrote:
> The octeontx2 hardware needs the buffer to be 128 byte aligned.
> But in the current implementation of napi_alloc_frag(), it can't
> guarantee the return address is 128 byte aligned even the request size
> is a multiple of 128 bytes, so we have to request an extra 128 bytes and
> use the PTR_ALIGN() to make sure that the buffer is aligned correctly.
> 
> Fixes: 7a36e4918e30 ("octeontx2-pf: Use the napi_alloc_frag() to alloc the pool buffers")
> Reported-by: Subbaraya Sundeep <sbhatta@marvell.com>
> Signed-off-by: Kevin Hao <haokexin@gmail.com>
> 
> [...]

Here is the summary with links:
  - net: octeontx2: Make sure the buffer is 128 byte aligned
    https://git.kernel.org/netdev/net/c/db2805150a0f

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2021-01-23  2:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21  7:09 [PATCH] net: octeontx2: Make sure the buffer is 128 byte aligned Kevin Hao
2021-01-21  9:01 ` sundeep subbaraya
2021-01-21  9:53 ` David Laight
2021-01-21 11:51   ` Kevin Hao
2021-01-21 12:42     ` Sunil Kovvuri
2021-01-23  2:10 ` patchwork-bot+netdevbpf

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.