From: sashiko-bot@kernel.org
To: "Xin Tian" <tianx@yunsilicon.com>
Cc: linux-rdma@vger.kernel.org
Subject: Re: [PATCH v2 09/11] net/xsc: report link state changes
Date: Fri, 27 Nov 2026 14:58:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-237642@kernel.org> (raw)
In-Reply-To: <20261126145736.70868-10-tianx@yunsilicon.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net/xsc: unsynchronized carrier updates in
xsc_eth_link_event_handler()
--
commit e468bd52287d3b4539c22501cb440d036af1c666
Author: Xin Tian <tianx@yunsilicon.com>
net/xsc: report link state changes
This commit queries virtual port state to update the netdev carrier and
registers an event handler for PCI link state change notifications.
> diff --git a/drivers/net/ethernet/yunsilicon/xsc/net/main.c b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> index 1c7bbc27d8c4f..75a6abd6ed136 100644
> --- a/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> +++ b/drivers/net/ethernet/yunsilicon/xsc/net/main.c
> @@ -721,6 +721,62 @@ static void xsc_eth_sw_deinit(struct xsc_adapter *adapter)
> xsc_eth_close_channels(adapter);
> }
>
> +static int xsc_eth_get_link_status(struct xsc_adapter *adapter, bool *link_up)
> +{
> + struct xsc_core_device *xdev = adapter->xdev;
> + u8 state;
> + int err;
> +
> + err = xsc_core_query_vport_state(xdev, 0, &state);
> + if (err)
> + return err;
> +
> + *link_up = state;
> + return 0;
> +}
> +
> +static int xsc_eth_change_link_status(struct xsc_adapter *adapter)
> +{
> + bool link_up;
> + int err;
> +
> + err = xsc_eth_get_link_status(adapter, &link_up);
> + if (err) {
> + netdev_err(adapter->netdev, "failed to query link status, err=%d\n",
> + err);
> + return err;
> + }
> +
> + if (link_up && !netif_carrier_ok(adapter->netdev)) {
> + netdev_info(adapter->netdev, "Link up\n");
> + netif_carrier_on(adapter->netdev);
> + } else if (!link_up && netif_carrier_ok(adapter->netdev)) {
> + netdev_info(adapter->netdev, "Link down\n");
> + netif_carrier_off(adapter->netdev);
> + }
> +
> + return 0;
> +}
> +
> +/*
> + * Registered with the PCI layer, which runs it on its own workqueue for
> + * every XSC_CMD_EVENT_RESP_CHANGE_LINK event.
> + */
> +static void xsc_eth_link_event_handler(void *arg)
> +{
> + struct xsc_core_device *xdev = arg;
> + struct xsc_adapter *adapter = xdev->eth_priv;
> + int err;
> +
> + if (!adapter || !adapter->opened)
> + return;
> +
> + err = xsc_eth_change_link_status(adapter);
> + if (err)
> + netdev_err(adapter->netdev, "failed to change linkstatus, err=%d\n",
> + err);
> +}
> +
> static bool xsc_get_pct_drop_config(struct xsc_core_device *xdev)
> {
> return (xdev->pdev->device == XSC_MC_PF_DEV_ID) ||
> @@ -813,6 +869,7 @@ static void xsc_set_port_admin_status(struct xsc_adapter *adapter,
> static int xsc_eth_open(struct net_device *netdev)
> {
> struct xsc_adapter *adapter = netdev_priv(netdev);
> + bool link_up;
> int ret;
>
> ret = xsc_eth_sw_init(adapter);
> @@ -823,6 +880,16 @@ static int xsc_eth_open(struct net_device *netdev)
> if (ret)
> goto err_sw_deinit;
>
> + ret = xsc_eth_get_link_status(adapter, &link_up);
> + if (ret) {
> + netdev_warn(netdev, "failed to query link status, err=%d\n", ret);
> + } else if (link_up) {
> + netdev_info(netdev, "Link up\n");
> + netif_carrier_on(adapter->netdev);
> + } else {
> + netdev_info(netdev, "Link down\n");
> + }
> +
> adapter->opened = true;
>
> xsc_set_port_admin_status(adapter, XSC_PORT_UP);
[Severity: Medium]
Can xsc_eth_link_event_handler() race with xsc_eth_close() and
xsc_eth_open() and leave the netdev carrier state out of sync?
xsc_eth_link_event_handler() checks adapter->opened without locking and
then sleeps in xsc_core_query_vport_state() -> xsc_cmd_exec(), while
xsc_eth_close() clears adapter->opened and calls netif_carrier_off()
without waiting for in-flight link event work:
drivers/net/ethernet/yunsilicon/xsc/net/main.c:xsc_eth_close() {
adapter->opened = false;
netif_carrier_off(adapter->netdev);
...
}
CPU0 (event_wq) CPU1
xsc_eth_link_event_handler()
if (!adapter->opened)
xsc_eth_change_link_status()
xsc_eth_get_link_status()
/* sleeps in cmd exec */
xsc_eth_close()
adapter->opened = false;
netif_carrier_off(netdev);
netif_carrier_on(netdev);
/* carrier enabled while closed */
Because xsc_eth_open() only calls netif_carrier_on() when link_up is true
and does not call netif_carrier_off() in the else branch, if the physical
link goes down while the interface is closed, a subsequent xsc_eth_open()
logs "Link down" but leaves netif_carrier_ok() true.
Also in xsc_eth_open(), xsc_eth_get_link_status() runs before
adapter->opened = true and before xsc_set_port_admin_status(adapter,
XSC_PORT_UP). That queries the vport while it is still administratively
down from a prior close, and any link change event arriving between
xsc_eth_get_link_status() and adapter->opened = true is dropped by
xsc_eth_link_event_handler().
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261126145711.70868-1-tianx@yunsilicon.com?part=9
next prev parent reply other threads:[~2026-11-27 14:58 UTC|newest]
Thread overview: 22+ 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-26 14:57 ` [PATCH v2 02/11] net/xsc: add doorbell and cmdq MMIO accessors 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-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-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-26 14:57 ` [PATCH v2 06/11] net/xsc: add CQ and QP helpers Xin Tian
2026-11-27 14:58 ` sashiko-bot
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-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-26 14:57 ` [PATCH v2 09/11] net/xsc: report link state changes Xin Tian
2026-11-27 14:58 ` sashiko-bot [this message]
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-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 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-237642@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox