octeontx2-af: Fix memory scaling limitation in SR-IOV mode

The original code used DMA_ATTR_FORCE_CONTIGUOUS, which could exhaust
the CMA pool when a large number of VFs were requested.

Fix this by switching to the DMA streaming API. This is equivalent on
Octeon platforms, which provide full I/O coherency via the SMMU.

Cc: Leon Romanovsky <leon@kernel.org>
Fixes: 73d33dbc07 ("octeontx2-af: Use DMA_ATTR_FORCE_CONTIGUOUS attribute in DMA alloc")
Signed-off-by: Ratheesh Kannoth <rkannoth@marvell.com>
Reviewed-by: Leon Romanovsky <leon@kernel.org>
Link: https://patch.msgid.link/20260916022111.1083017-1-rkannoth@marvell.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Ratheesh Kannoth 2026-09-16 07:51:11 +05:30 committed by Jakub Kicinski
parent 12fec40907
commit d06f2ebf67

View File

@ -7,6 +7,10 @@
#ifndef COMMON_H
#define COMMON_H
#include <linux/dma-mapping.h>
#include <linux/gfp.h>
#include <linux/mm.h>
#include "rvu_struct.h"
#define OTX2_ALIGN 128 /* Align to cacheline */
@ -44,6 +48,33 @@ struct qmem {
u32 qsize;
};
static inline void *otx2_dma_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle)
{
dma_addr_t dma_addr;
void *vaddr;
vaddr = kzalloc(size, GFP_KERNEL);
if (!vaddr)
return NULL;
dma_addr = dma_map_single(dev, vaddr, size, DMA_BIDIRECTIONAL);
if (dma_mapping_error(dev, dma_addr)) {
kfree(vaddr);
return NULL;
}
*dma_handle = dma_addr;
return vaddr;
}
static inline void otx2_dma_free_coherent(struct device *dev, size_t size,
void *vaddr, dma_addr_t dma_handle)
{
dma_unmap_single(dev, dma_handle, size, DMA_BIDIRECTIONAL);
kfree(vaddr);
}
static inline int qmem_alloc(struct device *dev, struct qmem **q,
int qsize, int entry_sz)
{
@ -60,8 +91,11 @@ static inline int qmem_alloc(struct device *dev, struct qmem **q,
qmem->entry_sz = entry_sz;
qmem->alloc_sz = (qsize * entry_sz) + OTX2_ALIGN;
qmem->base = dma_alloc_attrs(dev, qmem->alloc_sz, &qmem->iova,
GFP_KERNEL, DMA_ATTR_FORCE_CONTIGUOUS);
if (get_order(PAGE_ALIGN(qmem->alloc_sz)) > MAX_PAGE_ORDER)
return -ENOMEM;
qmem->base = otx2_dma_alloc_coherent(dev, qmem->alloc_sz, &qmem->iova);
if (!qmem->base)
return -ENOMEM;
@ -80,10 +114,9 @@ static inline void qmem_free(struct device *dev, struct qmem *qmem)
return;
if (qmem->base)
dma_free_attrs(dev, qmem->alloc_sz,
qmem->base - qmem->align,
qmem->iova - qmem->align,
DMA_ATTR_FORCE_CONTIGUOUS);
otx2_dma_free_coherent(dev, qmem->alloc_sz,
qmem->base - qmem->align,
qmem->iova - qmem->align);
devm_kfree(dev, qmem);
}