All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Xin Tian" <tianx@yunsilicon.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH v2 06/11] net/xsc: add CQ and QP helpers
Date: Fri, 27 Nov 2026 14:58:09 +0000	[thread overview]
Message-ID: <sashiko-outbox-237639@kernel.org> (raw)
In-Reply-To: <20261126145727.70868-7-tianx@yunsilicon.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/xsc: xsc_core_eth_destroy_cq() skips waiting on xcq->free
  on error
--

commit e696a8de856ac33999eafa7adfe7de1ccd665f4e
Author: Xin Tian <tianx@yunsilicon.com>

net/xsc: add CQ and QP helpers

This commit adds CQ and QP radix-tree tables, helpers to create, modify,
and destroy ethernet CQs and QPs, and EQ dispatching for completion and
error events.

> diff --git a/drivers/net/ethernet/yunsilicon/xsc/pci/cq.c b/drivers/net/ethernet/yunsilicon/xsc/pci/cq.c
> new file mode 100644
> index 0000000000000..a4f9b488d659d
> --- /dev/null
> +++ b/drivers/net/ethernet/yunsilicon/xsc/pci/cq.c
[ ... ]
> +int xsc_core_eth_destroy_cq(struct xsc_core_device *xdev,
> +			    struct xsc_core_cq *xcq)
> +{
> +	struct xsc_cq_table *table = &xdev->cq_table;
> +	struct xsc_core_cq *tmp;
> +	int err;
> +
> +	spin_lock_irq(&table->lock);
> +	tmp = radix_tree_delete(&table->tree, xcq->cqn);
> +	spin_unlock_irq(&table->lock);
> +	if (!tmp) {
> +		err = -ENOENT;
> +		goto err_delete_cq;
> +	}
> +
> +	if (tmp != xcq) {
> +		err = -EINVAL;
> +		goto err_delete_cq;
> +	}
> +
> +	/* the completion reader looks the cq up under rcu_read_lock and
> +	 * takes its reference afterwards; wait for it before dropping
> +	 * the tree reference so it never touches a freed cq
> +	 */
> +	synchronize_rcu();
> +
> +	err = xsc_destroy_cq(xdev, xcq->cqn);
> +	if (err)
> +		goto err_destroy_cq;
> +
> +	if (atomic_dec_and_test(&xcq->refcount))
> +		complete(&xcq->free);
> +	wait_for_completion(&xcq->free);
> +	return 0;

[Severity: Medium]
If xsc_destroy_cq() fails, can xsc_core_eth_destroy_cq() return while an
in-flight xsc_cq_completion() or xsc_eq_cq_event() callback is still using
xcq?

Both xsc_cq_completion() and xsc_eq_cq_event() drop rcu_read_unlock() or
table->lock after incrementing cq->refcount and before calling cq->comp()
or cq->event(), so synchronize_rcu() does not wait for those callbacks to
finish.  Jumping to err_destroy_cq after xcq has already been deleted from
table->tree skips waiting on xcq->free, allowing the caller to zero or
free the enclosing structure while a callback is still running:

CPU0                                  CPU1
xsc_core_eth_destroy_cq()
  radix_tree_delete(..., xcq->cqn)
                                      xsc_cq_completion()
                                        rcu_read_lock()
                                        /* looked up before delete */
                                        atomic_inc(&cq->refcount)
                                        rcu_read_unlock()
  synchronize_rcu()
  xsc_destroy_cq() -> fails
  goto err_destroy_cq
/* caller zeroes or frees xcq */
                                        cq->comp(cq)  <-- use-after-free

Dropping the initial refcount and waiting on xcq->free right after
synchronize_rcu(), before xsc_destroy_cq(), would ensure all in-flight
callbacks have finished even if the firmware command fails.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126145711.70868-1-tianx@yunsilicon.com?part=6

  reply	other threads:[~2026-11-27 14:58 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 14:57 [PATCH v2 00/11] net/xsc: add the Yunsilicon XSC ethernet driver Xin Tian
2026-11-26 14:57 ` [PATCH v2 01/11] net/xsc: add Yunsilicon XSC ethernet PCI driver Xin Tian
2026-11-27 15:57   ` netdev-bot+sashiko
2026-11-28 17:32   ` Andrew Lunn
2026-12-01  9:48     ` Xin Tian
2026-11-29  2:53   ` Jason Xing
2026-11-26 14:57 ` [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors Xin Tian
2026-11-27 15:57   ` netdev-bot+sashiko
2026-11-29  5:47   ` Jason Xing
2026-12-01  9:16     ` Xin Tian
2026-11-26 14:57 ` [PATCH v2 03/11] net/xsc: add the command queue Xin Tian
2026-11-27 14:58   ` sashiko-bot
2026-11-27 15:57   ` netdev-bot+sashiko
2026-11-29  7:30   ` Jason Xing
2026-12-01  9:22     ` Xin Tian
2026-12-02  6:21       ` Jason Xing
2026-11-26 14:57 ` [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function Xin Tian
2026-11-27 14:58   ` sashiko-bot
2026-11-27 15:57   ` netdev-bot+sashiko
2026-11-29  7:48   ` Jason Xing
2026-12-01  9:24     ` Xin Tian
2026-11-26 14:57 ` [PATCH v2 05/11] net/xsc: add event queues and MSI-X Xin Tian
2026-11-27 14:58   ` sashiko-bot
2026-11-27 15:57   ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 06/11] net/xsc: add CQ and QP helpers Xin Tian
2026-11-27 14:58   ` sashiko-bot [this message]
2026-11-27 15:57   ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 07/11] net/xsc: add the ethernet netdev Xin Tian
2026-11-27 14:58   ` sashiko-bot
2026-11-27 15:57   ` netdev-bot+sashiko
2026-11-28 17:49   ` Andrew Lunn
2026-12-01 10:06     ` Xin Tian
2026-11-26 14:57 ` [PATCH v2 08/11] net/xsc: add the single TX/RX channel Xin Tian
2026-11-27 14:58   ` sashiko-bot
2026-11-27 15:58   ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 09/11] net/xsc: report link state changes Xin Tian
2026-11-27 14:58   ` sashiko-bot
2026-11-27 15:58   ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 10/11] net/xsc: add the transmit path Xin Tian
2026-11-27 14:58   ` sashiko-bot
2026-11-27 15:58   ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 11/11] net/xsc: add the receive path Xin Tian
2026-11-27 14:58   ` sashiko-bot
2026-11-27 15:58   ` netdev-bot+sashiko
2026-11-27 14:58 ` [PATCH v2 00/11] net/xsc: add the Yunsilicon XSC ethernet driver sashiko-bot

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=sashiko-outbox-237639@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=tianx@yunsilicon.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.