net: octeontx2: Make sure the buffer is 128 byte aligned
PATCH 1/1 net: octeontx2: Make sure the buffer is 128 byte aligned
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.
--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +2 -1
@@ -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))) {
Signature · 1 line
2.29.2
Hi Kevin,
Tested at my end and works fine. Thanks for the patch.
Sundeep
Quoted 34 lines · Kevin Hao
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 thePTR_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 <[email protected]>Signed-off-by Kevin Hao <[email protected]>--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +2
-2@@ -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
From: Kevin Hao
Quoted 34 lines
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 thePTR_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 <[email protected]>Signed-off-by Kevin Hao <[email protected]>--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +2
-2@@ -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))) { --
Quoted 1 line
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)
Quoted 30 lines · David Laight
From: Kevin Hao
Quoted 29 lines
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 thePTR_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 <[email protected]>Signed-off-by Kevin Hao <[email protected]>--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1
-1@@ -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 ;
Quoted 9 lines
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1
-1+ 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?
Quoted 4 lines
It isn't obvious that
page_frag_free()it correct when the allocator isnapi_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
Quoted 7 lines
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
Quoted 42 lines · Kevin Hao
Quoted 30 lines · David Laight
From: Kevin Hao
Quoted 29 lines
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 thePTR_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 <[email protected]>Signed-off-by Kevin Hao <[email protected]>--- drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1
-1@@ -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 ;Quoted 9 lines
Quoted 6 lines
drivers/net/ethernet/marvell/octeontx2/nic/otx2_common.c +1
-1+ 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.
Quoted 4 lines
Why do we care about the original pointer? The free code should work with the mangling poiner. Did I miss something?
Quoted 1 line
I too agree, put_page(buf) or put_page(buf + OTX2_ALIGN) is same.
This patch was applied to netdev/net.git (refs/heads/master):
Hello:
This patch was applied to netdev/net.git (refs/heads/master):
Quoted 11 lines · 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 thePTR_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 <[email protected]>Signed-off-by Kevin Hao <[email protected]>[...]
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