From: netdev-bot+sashiko@kernel.org
To: tianx@yunsilicon.com
Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, jgg@ziepe.ca,
leon@kernel.org, huangjunxian6@hisilicon.com,
weihg@yunsilicon.com, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
kerneljasonxing@gmail.com
Subject: Re: [PATCH v2 09/11] net/xsc: report link state changes
Date: Fri, 27 Nov 2026 15:58:02 +0000 [thread overview]
Message-ID: <179579508256.3135.6252294453824096365@kernel.org> (raw)
In-Reply-To: <20261126145736.70868-10-tianx@yunsilicon.com>
Thank you for your contribution! Sashiko AI review found 4 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 3 · 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] In xsc_eth_open()
(drivers/net/ethernet/yunsilicon/xsc/net/main.c), the initial carrier…
- [Medium] xsc_eth_link_event_handler() (main.c:765-778) runs from
xsc_event_work() on xdev->event_wq with no lock held.
- [Medium] xsc_eth_open() (main.c:883-893) samples the link state with
xsc_eth_get_link_status() and sets the carrier before it sets…
- [Low] The comment above xsc_event_work() in
drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.c (lines 164-169) says…
--
net/xsc: report link state changes
This commit adds xsc_core_query_vport_state() and uses it to set the
netdev carrier in xsc_eth_open(). It also registers a link event callback
with the PCI layer, so the port is re-queried and the carrier updated on
every XSC_CMD_EVENT_RESP_CHANGE_LINK event.
> 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)
[ ... ]
> +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);
[Severity: Medium]
Can this race with xsc_eth_close() and leave the carrier on for a closed
device?
The handler runs from xsc_event_work() on xdev->event_wq with no lock
held. Its only guard is a plain read of adapter->opened. After that it
sends a sleeping firmware command and then checks and sets the carrier
in two separate steps.
xsc_eth_close() writes opened and the carrier under RTNL. It does not
exclude or wait for a handler that has already passed the check:
event_wq ip link set down (RTNL)
xsc_eth_link_event_handler()
adapter->opened == true
xsc_eth_change_link_status()
xsc_core_query_vport_state()
xsc_eth_close()
adapter->opened = false;
netif_carrier_off()
xsc_eth_sw_deinit()
...
link_up && !netif_carrier_ok()
netif_carrier_on()
On the next xsc_eth_open(), the "Link down" branch never calls
netif_carrier_off(). If the link is down at reopen, the interface comes
up with carrier and operstate up and stays that way until the next link
transition.
The opened bool acts as a gate guard rather than a real lock. It is also
read and written without READ_ONCE()/WRITE_ONCE().
Would it work to take rtnl_lock() in the handler, or a driver state mutex
that open and close also hold (like state_lock in
mlx5e_update_carrier_work()), and re-check opened under it? Remove and
the probe error path call xsc_irq_event_unregister() without RTNL, so
its flush_workqueue() should not deadlock against that.
> + if (err)
> + netdev_err(adapter->netdev, "failed to change linkstatus, err=%d\n",
> + err);
> +}
[Severity: Low]
This isn't a bug, but once this handler is registered, the comment above
xsc_event_work() in drivers/net/ethernet/yunsilicon/xsc/pci/pci_irq.c no
longer matches what the work does:
/*
* Handle an asynchronous event. This runs on the PCI layer's own workqueue,
* so it outlives any auxiliary driver: the driver only ever registers a
* callback here, and the memory this touches belongs to xsc_core_device
* rather than to the eth private area.
*/
xsc_event_work() calls the callback inline:
handler = READ_ONCE(xdev->link_event_handler);
if (handler)
handler(xdev);
xsc_eth_link_event_handler() dereferences xdev->eth_priv,
adapter->opened and adapter->netdev. All of these live in the
alloc_etherdev() private area that free_netdev() frees.
What actually keeps this safe is that xsc_eth_remove() and the probe
error path call xsc_irq_event_unregister() before free_netdev().
Could the comment say that callbacks may touch client-owned memory, and
that clients must unregister before freeing it?
[ ... ]
> @@ -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;
[Severity: Medium]
Can a link change event get lost between the query and this assignment?
The link state is sampled before adapter->opened is set. While opened is
false, xsc_eth_link_event_handler() returns early and records nothing:
if (!adapter || !adapter->opened)
return;
Suppose the link changes after the firmware answers QUERY_VPORT_STATE,
and the CHANGE_LINK work reaches that check before adapter->opened is
set to true. The event is dropped. Nothing re-queries afterwards, so the
carrier stays wrong until the next link transition, which may never come
on a stable link. This looks reachable at least on the first open after
probe.
Also, if xsc_eth_get_link_status() fails here, for example because
xsc_cmd_exec() times out, open only warns and returns 0. The carrier
stays off and the query is never retried. A link that is up and stays
up would then be reported down indefinitely.
Would either of these close the window and let a later event correct a
failed query?
- set opened before the query, as mlx5e_open_locked() does with
MLX5E_STATE_OPENED before updating the carrier
- re-query once opened and admin-up are both set
>
> xsc_set_port_admin_status(adapter, XSC_PORT_UP);
[Severity: Medium]
Does the oper state read above mean anything while the port is still
admin-down?
xsc_eth_close() always ends with:
xsc_set_port_admin_status(adapter, XSC_PORT_DOWN);
So on every re-open, xsc_eth_get_link_status() queries a port the driver
has just set admin-down. XSC_PORT_UP is only sent after the carrier has
been decided.
The reply carries separate admin and oper nibbles:
#define XSC_QUERY_VPORT_ADMIN_STATE_MASK GENMASK(3, 0)
#define XSC_QUERY_VPORT_STATE_MASK GENMASK(7, 4)
xsc_core_query_vport_state() returns the oper nibble.
If the firmware reports oper-down while the port is admin-down, open
takes the "Link down" branch. After that, only a later
XSC_CMD_EVENT_RESP_CHANGE_LINK event can turn the carrier on.
Does the firmware raise that event when admin-up changes the oper state?
If it does not, the netdev stays carrier-off after ip link set down
followed by ip link set up, even though the physical link is up. It
would stay that way until the link next flaps.
mlx5e queries the state before admin-up in the same way and relies on
firmware port change events. So this may be fine if the xsc firmware
behaves the same way.
Would setting opened, then sending XSC_PORT_UP, and only then sampling
the link state make the initial sample match the real link?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261126145711.70868-1-tianx%40yunsilicon.com
next prev parent reply other threads:[~2026-11-27 15:58 UTC|newest]
Thread overview: 23+ 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-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-26 14:57 ` [PATCH v2 03/11] net/xsc: add the command queue Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 04/11] net/xsc: query HCA capabilities and reset function Xin Tian
2026-11-27 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 05/11] net/xsc: add event queues and MSI-X Xin Tian
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 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 15:57 ` netdev-bot+sashiko
2026-11-26 14:57 ` [PATCH v2 08/11] net/xsc: add the single TX/RX channel Xin Tian
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 15:58 ` netdev-bot+sashiko [this message]
2026-11-26 14:57 ` [PATCH v2 10/11] net/xsc: add the transmit path Xin Tian
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 15:58 ` netdev-bot+sashiko
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=179579508256.3135.6252294453824096365@kernel.org \
--to=netdev-bot+sashiko@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=huangjunxian6@hisilicon.com \
--cc=jgg@ziepe.ca \
--cc=kerneljasonxing@gmail.com \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=tianx@yunsilicon.com \
--cc=weihg@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
all inboxes | Powered by JetHome®