Netdev List
 help / color / mirror / Atom feed
* [PATCH net] octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails
@ 2026-11-24 19:00 Yuho Choi
  2026-11-24 19:02 ` netdev-bot+sinfo
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Yuho Choi @ 2026-11-24 19:00 UTC (permalink / raw)
  To: Sunil Goutham, Geetha sowjanya, Ratheesh Kannoth,
	Subbaraya Sundeep, Bharat Bhushan, Hariprasad Kelam
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, Jacob Keller, netdev, Yuho Choi

otx2_qos_disable_sq() asks the AF to disable the QoS send queue, its
aura and its pool, but ignores the result of otx2_qos_ctx_disable().
If the mailbox request fails, for example on a timeout or an AQ error,
the driver cannot confirm that all three contexts have been disabled.
It frees the SQBs, the pool stack, and the aura flow-control buffer
anyway, which the hardware may continue to reference.

If the disable fails, log an error and keep the memory: leaking it is
safer than freeing memory the hardware may still access. If the queue
is not set up again, otx2_free_hw_resources() frees it later with the
other queues when the interface goes down, after the SQ and NPA
contexts of the whole LF have been disabled.

Fixes: ab6dddd2a669 ("octeontx2-pf: qos send queues management")
Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
---
Compile-tested only (x86_64 with COMPILE_TEST, OCTEONTX2_PF=m, W=1). I
don't have OcteonTX2/CN10K hardware, and the disable only fails when
the mailbox request to the AF fails, so I could not trigger this path.

 drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c b/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c
index 683efce519af..e9ca884cfb4d 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c
@@ -283,7 +283,7 @@ void otx2_qos_disable_sq(struct otx2_nic *pfvf, int qidx)
 	struct otx2_hw *hw = &pfvf->hw;
 	struct otx2_snd_queue *sq;
 	struct otx2_cq_queue *cq;
-	int pool_id, sq_idx;
+	int pool_id, sq_idx, err;
 
 	sq_idx = hw->non_qos_queues + qidx;
 
@@ -311,8 +311,16 @@ void otx2_qos_disable_sq(struct otx2_nic *pfvf, int qidx)
 	otx2_cleanup_tx_cqes(pfvf, cq);
 
 	mutex_lock(&pfvf->mbox.lock);
-	otx2_qos_ctx_disable(pfvf, sq_idx, pool_id);
+	err = otx2_qos_ctx_disable(pfvf, sq_idx, pool_id);
 	mutex_unlock(&pfvf->mbox.lock);
+	if (err) {
+		/* The SQ, aura and pool may still be enabled, so don't free
+		 * the memory they point to.
+		 */
+		netdev_err(pfvf->netdev,
+			   "Failed to disable QoS SQ %d (%d)\n", sq_idx, err);
+		return;
+	}
 
 	otx2_qos_sq_free_sqbs(pfvf, sq_idx);
 	otx2_qos_aura_pool_free(pfvf, pool_id);

base-commit: 37fa509e43ba59d7c329025436e8ea64bdf089d7
-- 
2.56.1


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

* Re: [PATCH net] octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails
  2026-11-24 19:00 [PATCH net] octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails Yuho Choi
@ 2026-11-24 19:02 ` netdev-bot+sinfo
  2026-11-26  2:11 ` Ratheesh Kannoth
  2026-11-26  7:00 ` netdev-bot+sashiko
  2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-24 19:02 UTC (permalink / raw)
  To: Yuho Choi
  Cc: Sunil Goutham, Geetha sowjanya, Ratheesh Kannoth,
	Subbaraya Sundeep, Bharat Bhushan, Hariprasad Kelam, Andrew Lunn,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Simon Horman, Jacob Keller, netdev

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH net] octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails
  2026-11-24 19:00 [PATCH net] octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails Yuho Choi
  2026-11-24 19:02 ` netdev-bot+sinfo
@ 2026-11-26  2:11 ` Ratheesh Kannoth
  2026-11-26  7:00 ` netdev-bot+sashiko
  2 siblings, 0 replies; 4+ messages in thread
From: Ratheesh Kannoth @ 2026-11-26  2:11 UTC (permalink / raw)
  To: Yuho Choi
  Cc: Sunil Goutham, Geetha sowjanya, Subbaraya Sundeep, Bharat Bhushan,
	Hariprasad Kelam, Andrew Lunn, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Simon Horman, Jacob Keller, netdev

On 2026-11-25 at 00:30:24, Yuho Choi (oss.patchbox@gmail.com) wrote:
> otx2_qos_disable_sq() asks the AF to disable the QoS send queue, its
> aura and its pool, but ignores the result of otx2_qos_ctx_disable().
> If the mailbox request fails, for example on a timeout or an AQ error,
> the driver cannot confirm that all three contexts have been disabled.
> It frees the SQBs, the pool stack, and the aura flow-control buffer
> anyway, which the hardware may continue to reference.
>
> If the disable fails, log an error and keep the memory: leaking it is
> safer than freeing memory the hardware may still access. If the queue
> is not set up again, otx2_free_hw_resources() frees it later with the
> other queues when the interface goes down, after the SQ and NPA
> contexts of the whole LF have been disabled.
>
> Fixes: ab6dddd2a669 ("octeontx2-pf: qos send queues management")
> Signed-off-by: Yuho Choi <oss.patchbox@gmail.com>
> ---
> Compile-tested only (x86_64 with COMPILE_TEST, OCTEONTX2_PF=m, W=1). I
> don't have OcteonTX2/CN10K hardware, and the disable only fails when
> the mailbox request to the AF fails, so I could not trigger this path.
>
>  drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c b/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c
> index 683efce519af..e9ca884cfb4d 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c
> @@ -283,7 +283,7 @@ void otx2_qos_disable_sq(struct otx2_nic *pfvf, int qidx)
>  	struct otx2_hw *hw = &pfvf->hw;
>  	struct otx2_snd_queue *sq;
>  	struct otx2_cq_queue *cq;
> -	int pool_id, sq_idx;
> +	int pool_id, sq_idx, err;
>
>  	sq_idx = hw->non_qos_queues + qidx;
>
> @@ -311,8 +311,16 @@ void otx2_qos_disable_sq(struct otx2_nic *pfvf, int qidx)
>  	otx2_cleanup_tx_cqes(pfvf, cq);
>
>  	mutex_lock(&pfvf->mbox.lock);
> -	otx2_qos_ctx_disable(pfvf, sq_idx, pool_id);
> +	err = otx2_qos_ctx_disable(pfvf, sq_idx, pool_id);
>  	mutex_unlock(&pfvf->mbox.lock);
function calls like otx2_smq_flush(),otx2_qos_nix_npa_ndc_sync() [ these 2,3 lines
above otx2_qos_ctx_disable() ] can also fail. Marvell need to handle those errors in
a seperate patch.

Reviewed-by: Ratheesh Kannoth <rkannoth@marvell.com>

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

* Re: [PATCH net] octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails
  2026-11-24 19:00 [PATCH net] octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails Yuho Choi
  2026-11-24 19:02 ` netdev-bot+sinfo
  2026-11-26  2:11 ` Ratheesh Kannoth
@ 2026-11-26  7:00 ` netdev-bot+sashiko
  2 siblings, 0 replies; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-26  7:00 UTC (permalink / raw)
  To: oss.patchbox
  Cc: sgoutham, gakula, rkannoth, sbhatta, bbhushan2, hkelam,
	andrew+netdev, davem, edumazet, kuba, pabeni, horms,
	jacob.e.keller, netdev

Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.

Critical: 0 · High: 0 (1) · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [Medium] If otx2_qos_ctx_disable() fails, the new early return in
  otx2_qos_disable_sq() (qos_sq.c:316-322) leaves all the queue state in…
- [Low] The commit message says otx2_free_hw_resources() frees the kept
  memory 'after the SQ and NPA contexts of the whole LF have been…

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but
  otx2_qos_sq_free_sqbs() (qos_sq.c:116-148), called on every successful…

--

octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails

This patch makes otx2_qos_disable_sq() check the return value of
otx2_qos_ctx_disable(). If the AF mailbox request fails, it now logs an
error and returns without freeing the SQBs, the pool stack and the aura
flow-control buffer, which the hardware may still reference.

> If the disable fails, log an error and keep the memory: leaking it is
> safer than freeing memory the hardware may still access. If the queue
> is not set up again, otx2_free_hw_resources() frees it later with the
> other queues when the interface goes down, after the SQ and NPA
> contexts of the whole LF have been disabled.

[Severity: Low]
Is this ordering accurate? otx2_free_hw_resources() calls
otx2_free_sq_res(). That function frees the SQB pages of every queue,
QoS queues included, right after a best-effort SQ disable:

drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c:otx2_free_sq_res() {
    ...
	/* Disable SQs */
	otx2_ctx_disable(&pf->mbox, NIX_AQ_CTYPE_SQ, false);
	/* Free SQB pointers */
	otx2_sq_free_sqbs(pf);
    ...
}

otx2_ctx_disable() returns void and only logs a mailbox failure. The NPA
pool and aura contexts are disabled later, in otx2_free_hw_resources():

	/* Disable NPA Pool and Aura hw context */
	otx2_ctx_disable(mbox, NPA_AQ_CTYPE_POOL, true);
	otx2_ctx_disable(mbox, NPA_AQ_CTYPE_AURA, true);
	otx2_aura_pool_free(pf);

So the SQB pages are freed before the NPA contexts are disabled. Only
pool->stack and pool->fc_addr are freed after that. If the AF mailbox is
still broken at ifdown, the memory kept by this patch gets freed anyway,
with no check of the result.

Could the commit message be reworded to match this?

> diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c b/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c
> index 683efce519af0..e9ca884cfb4d5 100644
> --- a/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c
> +++ b/drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c

[ ... ]

> @@ -311,8 +311,16 @@ void otx2_qos_disable_sq(struct otx2_nic *pfvf, int qidx)
>  	otx2_cleanup_tx_cqes(pfvf, cq);
>  
>  	mutex_lock(&pfvf->mbox.lock);
> -	otx2_qos_ctx_disable(pfvf, sq_idx, pool_id);
> +	err = otx2_qos_ctx_disable(pfvf, sq_idx, pool_id);
>  	mutex_unlock(&pfvf->mbox.lock);
> +	if (err) {
> +		/* The SQ, aura and pool may still be enabled, so don't free
> +		 * the memory they point to.
> +		 */
> +		netdev_err(pfvf->netdev,
> +			   "Failed to disable QoS SQ %d (%d)\n", sq_idx, err);
> +		return;
> +	}

[Severity: Medium]
otx2_qos_disable_sq() still returns void, so callers can't tell that the
disable failed. When the same qid is set up again right afterwards, are
the kept SQB pages and queue buffers leaked?

otx2_qos_enadis_sq() re-enables the qid straight after the disable:

drivers/net/ethernet/marvell/octeontx2/nic/qos.c:otx2_qos_enadis_sq() {
	if (pfvf->qos.qid_to_sqmap[qid] != OTX2_QOS_INVALID_SQ)
		otx2_qos_disable_sq(pfvf, qid);

	pfvf->qos.qid_to_sqmap[qid] = node->schq;
	otx2_qos_txschq_config(pfvf, node);
	otx2_qos_enable_sq(pfvf, qid);
}

otx2_qos_leaf_del() works the same way. It disables node->qid and later
calls otx2_qos_enable_sq(pfvf, qid) for the moved leaf.
otx2_qos_leaf_to_inner() and otx2_qos_leaf_del_last() pass the qid to a
child or parent. That node is then enabled through
push_txschq_cfg()->otx2_qos_enadis_sq().

The setup path overwrites the kept pointers without checking them:

drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c:otx2_qos_sq_aura_pool_init() {
    ...
	sq->sqb_count = 0;
	sq->sqb_ptrs = kzalloc_objs(*sq->sqb_ptrs, num_sqbs);
    ...
}

In the same way, otx2_pool_aq_init() always calls qmem_alloc() for
pool->stack. otx2_sq_init() also reallocates sq->sqe, sq->sqe_ring,
sq->cpt_resp and sq->sg.

After that, the old SQB pages stay DMA mapped and keep their page
references. The old qmem buffers are never freed, because
otx2_free_hw_resources() only sees the new pointers. pool->fc_addr is
fine, since otx2_aura_aq_init() reuses it when it is non-NULL.

With default ring sizes this comes to roughly 2 MiB each time. The
commit message only covers the case where the queue is not set up again.
In the common callers the queue is set up again in the same call.

Could otx2_qos_disable_sq() return the error so callers can avoid
reusing the qid? Alternatively, otx2_qos_enable_sq() could refuse, or
retry the disable and free first, while sq->sqb_ptrs is still set.

>  
>  	otx2_qos_sq_free_sqbs(pfvf, sq_idx);

[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Does
otx2_qos_sq_free_sqbs() leak sq->sqe_ring and sq->cpt_resp on every
successful disable?

otx2_sq_init() allocates both buffers for every SQ, QoS SQs included,
with no qidx condition. Those allocations came in with commit
6a77a158848a ("cn10k-ipsec: Process outbound ipsec crypto offload").
otx2_qos_sq_free_sqbs() frees the other buffers and then clears the
struct:

drivers/net/ethernet/marvell/octeontx2/nic/qos_sq.c:otx2_qos_sq_free_sqbs() {
    ...
	qmem_free(pfvf->dev, sq->sqe);
	qmem_free(pfvf->dev, sq->tso_hdrs);
	kfree(sq->sg);
	kfree(sq->sqb_ptrs);
	qmem_free(pfvf->dev, sq->timestamps);

	memset((void *)sq, 0, sizeof(*sq));
}

The only other place that frees them is otx2_free_sq_res(). It only does
so when sq->sqe is set, and the memset above has already cleared it:

		if (sq->sqe) {
			qmem_free(pf->dev, sq->sqe);
			qmem_free(pf->dev, sq->sqe_ring);
			qmem_free(pf->dev, sq->cpt_resp);

The qmem buffers come from otx2_dma_alloc_coherent(), which uses
kzalloc() and dma_map_single(), so they are not devm managed.

With the default sqe_cnt of 4096, each HTB leaf delete, leaf-to-inner,
leaf delete-last, or re-config through otx2_qos_enadis_sq() would leak
about 1 MiB for sqe_ring and 256 KiB for cpt_resp, plus their DMA
mappings. This happens on the normal success path and can be repeated.

>  	otx2_qos_aura_pool_free(pfvf, pool_id);

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261124190046.415260-2-oss.patchbox%40gmail.com

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

end of thread, other threads:[~2026-11-26  7:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 19:00 [PATCH net] octeontx2-pf: QOS: Don't free SQ memory if disabling the SQ fails Yuho Choi
2026-11-24 19:02 ` netdev-bot+sinfo
2026-11-26  2:11 ` Ratheesh Kannoth
2026-11-26  7:00 ` netdev-bot+sashiko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox