From: Simon Horman <horms@kernel.org>
To: dong100@mucse.com
Cc: Simon Horman <horms@kernel.org>,
andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com, vadim.fedorenko@linux.dev,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
yaojun@mucse.com
Subject: Re: [PATCH net-next v8 4/4] net: rnpgbe: Add link status handling support
Date: Wed, 5 Aug 2026 10:39:17 +0100 [thread overview]
Message-ID: <20260805093917.547461-1-horms@kernel.org> (raw)
In-Reply-To: <20260731120322.895955-5-dong100@mucse.com>
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
Full review at: https://sashiko.dev/#/patchset/20260731120322.895955-2-dong100@mucse.com?part=4
---
--- Patch [4]: [PATCH net-next v8 4/4] net: rnpgbe: Add link status handling support ---
commit aaed18098b5cbd048578a3cab86657b190d37796
Author: Dong Yibo <dong100@mucse.com>
net: rnpgbe: Add link status handling support
Add link status management infrastructure to the rnpgbe driver:
- Add link status related data structures (speed, duplex, link state)
- Implement firmware link event handling via mailbox
(fw controls link states, does not support phylink)
- Add service task for periodic link status monitoring
- Implement carrier status management (netif_carrier_on/off)
- Add port up/down notification to firmware
This enables the driver to properly track and report link status changes.
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_lib.c
[ ... ]
> +static int rnpgbe_process_link_event(struct mucse *mucse)
> +{
> + struct mucse_hw *hw = &mucse->hw;
> + unsigned long flags;
> + bool link;
> +
> + /* Only event consumption needs a consistent link-state snapshot. */
> + if (!atomic_read(&mucse->link_pending) ||
> + !atomic_xchg(&mucse->link_pending, 0))
> + return READ_ONCE(hw->link);
> +
> + spin_lock_irqsave(&mucse->link_lock, flags);
> +
> + link = hw->link;
> + spin_unlock_irqrestore(&mucse->link_lock, flags);
> +
> + return link;
> +}
> +
> +/**
> + * rnpgbe_link_is_up - Update netif_carrier status and
> + * print link up message
> + * @mucse: pointer to the device private structure
> + **/
> +static void rnpgbe_link_is_up(struct mucse *mucse)
> +{
> + struct net_device *netdev = mucse->netdev;
> + struct mucse_hw *hw = &mucse->hw;
> + unsigned long flags;
> + int speed;
> + u8 duplex;
> +
> + /* Only continue if link was previously down */
> + if (netif_carrier_ok(netdev))
> + return;
> + spin_lock_irqsave(&mucse->link_lock, flags);
> + speed = hw->speed;
> + duplex = hw->duplex;
> + spin_unlock_irqrestore(&mucse->link_lock, flags);
[Severity: Medium]
Could this cause a torn link state snapshot if an interrupt fires between
these critical sections?
In rnpgbe_process_link_subtask(), the worker thread first reads the link state
in rnpgbe_process_link_event() under the lock, and then drops the lock.
If the link is true, it calls rnpgbe_link_is_up(), which re-acquires the lock
to read the speed and duplex values.
If a link-down event triggers an interrupt between these two lock acquisitions,
could the worker thread end up reading newly zeroed speed and duplex values,
incorrectly reporting "NIC Link is Up 0 Mbps", and turning the netif carrier
ON while the physical link is actually DOWN?
diff --git a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
--- a/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
+++ b/drivers/net/ethernet/mucse/rnpgbe/rnpgbe_main.c
[ ... ]
> @@ -243,6 +249,8 @@ static int rnpgbe_add_adapter(struct pci_dev *pdev,
> if (err)
> goto err_remove_mbx;
>
> + netif_carrier_off(netdev);
> +
> return 0;
[Severity: Medium]
Does calling netif_carrier_off() after register_netdev() expose a transient
carrier up state to userspace?
By default, the networking core assumes the carrier state is OK when a new
network device is created. When register_netdev() is called earlier in
rnpgbe_add_adapter(), the device is exposed to userspace and an RTM_NEWLINK
netlink event is broadcast indicating the link is UP.
Immediately calling netif_carrier_off() right after will emit another event
indicating the carrier is DOWN. Can this spurious UP-then-DOWN transition
confuse userspace network management daemons?
prev parent reply other threads:[~2026-08-05 9:40 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-31 12:03 [PATCH net-next v8 0/4] net: rnpgbe: Add TX/RX and link status support Dong Yibo
2026-07-31 12:03 ` [PATCH net-next v8 1/4] net: rnpgbe: Add interrupt handling Dong Yibo
2026-08-05 9:34 ` Simon Horman
2026-08-05 11:04 ` Yibo Dong
2026-07-31 12:03 ` [PATCH net-next v8 2/4] net: rnpgbe: Add basic TX packet transmission support Dong Yibo
2026-07-31 12:03 ` [PATCH net-next v8 3/4] net: rnpgbe: Add RX packet reception support Dong Yibo
2026-07-31 12:03 ` [PATCH net-next v8 4/4] net: rnpgbe: Add link status handling support Dong Yibo
2026-08-05 9:39 ` Simon Horman [this message]
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=20260805093917.547461-1-horms@kernel.org \
--to=horms@kernel.org \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=dong100@mucse.com \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=vadim.fedorenko@linux.dev \
--cc=yaojun@mucse.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.