Netdev List
 help / color / mirror / Atom feed
From: Ratheesh Kannoth <rkannoth@marvell.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: <davem@davemloft.net>, <gakula@marvell.com>,
	<linux-kernel@vger.kernel.org>, <netdev@vger.kernel.org>,
	<sgoutham@marvell.com>, <andrew+netdev@lunn.ch>,
	<edumazet@google.com>, <kuba@kernel.org>, <pabeni@redhat.com>
Subject: Re: [PATCH v7 net] octeontx2-af: switch qmem from coherent DMA alloc to streaming DMA mapping
Date: Mon, 7 Sep 2026 16:12:37 +0530	[thread overview]
Message-ID: <ap6VHVYnXcUcMTNG@rkannoth-OptiPlex-7090> (raw)
In-Reply-To: <20260907072055.GF13683@unreal>

On 2026-09-07 at 12:50:55, Leon Romanovsky (leon@kernel.org) wrote:
> On Mon, Sep 07, 2026 at 09:56:16AM +0530, Ratheesh Kannoth wrote:
> > qmem_alloc() uses dma_alloc_attrs() with DMA_ATTR_FORCE_CONTIGUOUS, which
> > allocates CPU-cache-coherent DMA memory and, with CMA enabled, draws from
> > the CMA pool. qmem backs NIX/NPA queue contexts, admin queues, and LMTST
> > regions (including CN10K LMTST areas that span page boundaries), so
> > consumption grows with enabled interfaces and is hard to provision in CMA.
> >
> >
> > v1 -> v2: Rewrote patch as per sashiko comment
>
> Your changelog says nothing. It should contain bullet points describing
> what was actually changed. A generic "Addressed Sashiko comments" is not
> sufficient.

Thanks for pointing this out. I relied on the Sashiko link to avoid
over-cluttering the notes, as sashiko coments are many.
I will make sure to explicitly list all notable changes in the
changelog in future revisions.

> >
> > +static inline bool otx2_dma_phys_in_mask(struct device *dev, phys_addr_t paddr,
> > +					 size_t size)
> > +{
> > +	dma_addr_t dma_addr = phys_to_dma(dev, paddr);
> > +
> > +	return dma_capable(dev, dma_addr, size, true, 0);
>
> This line makes no sense in the driver code.

ACK. will remove internal APIs

>
> > +}
> > +
> > +static inline void *otx2_dma_alloc_coherent(struct device *dev, size_t size,
> > +					    dma_addr_t *dma_handle)
> > +{
> > +	dma_addr_t dma_addr;
> > +	unsigned int order;
> > +	gfp_t alloc_gfp;
> > +	void *vaddr;
> > +
> > +	if (!dev || !dma_handle || !size)
> > +		return NULL;
>
> Please remove defensive programming style, how can you call to DMA API
> without device, dma_handle or size?
ACK.

>
> > +
> > +	if (!dev_is_dma_coherent(dev))
> > +		return NULL;
> > +
> > +	size = PAGE_ALIGN(size);
> > +	order = get_order(size);
> > +
> > +	/* Octeontx2 qmem call sites size their allocations within
> > +	 * MAX_PAGE_ORDER; mailbox, queue context, and ring memory
> > +	 * requirements stay below the buddy allocator's limit.
> > +	 */
> > +	if (order > MAX_PAGE_ORDER) {
>
> Size is coming from the kernel, how can it be with order more than MAX_PAGE_ORDER?
There is contigious memory allocation request from driver for PF-to-VF mail box memory.
It is crossing max page order in newer platforms as number of VFs per PF increased.

>
> > +		dev_err(dev,
> > +			"CONFIG_ARCH_FORCE_MAX_ORDER is set to %u, minimum needed is %u\n",
> > +			MAX_PAGE_ORDER, order);
> > +		return NULL;
> > +	}
> > +
> > +	if (size > dma_max_mapping_size(dev))
> > +		return NULL;
>
> Same comment.
Will remove this code and depend on dma_map_page_attrs().

>
> > +
> > +	alloc_gfp = GFP_KERNEL | __GFP_ZERO | __GFP_COMP;
>
> __GFP_COMP???
Will remove this flag.

>
> > +
> > +	vaddr = (void *)__get_free_pages(alloc_gfp, order);
>
> You should use plain ksmalloc(). There was ongoing effort to remove
> useless __get_free_pages().
> https://lore.kernel.org/all/20260713-b4-rdma-v2-0-65d2a1a5180c@kernel.org/
will replace get_free_pages with kmalloc.

>
> > +	while (vaddr &&
> > +	       !otx2_dma_phys_in_mask(dev, virt_to_phys(vaddr), size)) {
> > +		free_pages((unsigned long)vaddr, order);
> > +		if (alloc_gfp & GFP_DMA32)
> > +			return NULL;
> > +		alloc_gfp |= GFP_DMA32;
> > +		vaddr = (void *)__get_free_pages(alloc_gfp, order);
> > +	}
>
> If you want to use streamline API, please use it like any other driver
> without these DMA32 hacks.
Will kmalloc() with GFP_ZERO | GFP_KERNEL

>
> > +	if (!vaddr)
> > +		return NULL;
> > +
> > +	/* dev_is_dma_coherent() only guarantees cache coherency, not that the
> > +	 * mapped DMA address aliases qmem->base.  Require a coherent mapping
> > +	 * so the DMA API rejects SWIOTLB bounce buffers.
> > +	 */
> > +	dma_addr = dma_map_page_attrs(dev, virt_to_page(vaddr), 0, size,
> > +				      DMA_BIDIRECTIONAL, DMA_ATTR_REQUIRE_COHERENT);
>
> I don't understand why you insist on DMA_ATTR_REQUIRE_COHERENT. It is
> clearly documented as being required for UAPI-visible memory.
ACK.
I overlooked this uAPI part, as  AI tool recommended adding
this logic to reject allocations with SWIOTLB or cache management
support.

  reply	other threads:[~2026-09-07 10:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-07  4:26 [PATCH v7 net] octeontx2-af: switch qmem from coherent DMA alloc to streaming DMA mapping Ratheesh Kannoth
2026-09-07  7:20 ` Leon Romanovsky
2026-09-07 10:42   ` Ratheesh Kannoth [this message]
2026-09-07 11:32     ` Leon Romanovsky
2026-09-07 12:14       ` Ratheesh Kannoth
2026-09-08  6:19         ` Leon Romanovsky

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ap6VHVYnXcUcMTNG@rkannoth-OptiPlex-7090 \
    --to=rkannoth@marvell.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=gakula@marvell.com \
    --cc=kuba@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sgoutham@marvell.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox