lkml.org 
[lkml]   [2021]   [Feb]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 5.10 04/57] net: octeontx2: Make sure the buffer is 128 byte aligned
Hi!

> commit db2805150a0f27c00ad286a29109397a7723adad upstream.
>
> 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.
>
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c
> @@ -473,10 +473,11 @@ dma_addr_t __otx2_alloc_rbuf(struct otx2
> 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);

So we allocate a buffer, then change it, and then pass modified
pointer to the page_frag_free(buf); in the error path. That... can't
be right, right?

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

BTW otx2_alloc_rbuf and __otx2_alloc_rbuf should probably return s64,
as they return negative error code...

Best regards,
Pavel

--
http://www.livejournal.com/~pavelmachek
[unhandled content-type:application/pgp-signature]
\
 
 \ /
  Last update: 2021-02-07 10:22    [W:0.272 / U:0.628 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site