From: Jacob Keller <jacob.e.keller@intel.com>
To: Jiawen Wu <jiawenwu@trustnetic.com>, 'Jakub Kicinski' <kuba@kernel.org>
Cc: <netdev@vger.kernel.org>, <mengyuanlou@net-swift.com>,
<andrew+netdev@lunn.ch>, <davem@davemloft.net>,
<edumazet@google.com>, <pabeni@redhat.com>,
<richardcochran@gmail.com>, <linux@armlinux.org.uk>,
<horms@kernel.org>, <michal.swiatkowski@linux.intel.com>,
<kees@kernel.org>, <joe@dama.to>, <larysa.zaremba@intel.com>,
<abdun.nihaal@gmail.com>, <leitao@debian.org>
Subject: Re: [PATCH net-next v6 04/11] net: ngbe: implement libwx reset ops
Date: Tue, 31 Mar 2026 16:05:41 -0700 [thread overview]
Message-ID: <990c010b-f716-499d-b3ca-e8296003c37e@intel.com> (raw)
In-Reply-To: <073601dcc0de$a87b2e30$f9718a90$@trustnetic.com>
On 3/31/2026 12:19 AM, Jiawen Wu wrote:
>>> +static void ngbe_reinit_locked(struct wx *wx)
>>> +{
>>> + int err = 0;
>>> +
>>> + netif_trans_update(wx->netdev);
>>> +
>>> + err = wx_set_state_reset(wx);
>>> + if (err) {
>>> + wx_err(wx, "wait device reset timeout\n");
>>> + return;
>>> + }
>>> +
>>> + ngbe_down(wx);
>>> + ngbe_up(wx);
>>> +
>>> + clear_bit(WX_STATE_RESETTING, wx->state);
>>> +}
>>
>> Is it possible to use a standard kernel mutex here instead of a bit flag for
>> synchronization?
>>
>> Looking at the underlying implementation of wx_set_state_reset(), it relies
>> on an open-coded polling loop:
>>
>> static inline int wx_set_state_reset(struct wx *wx)
>> {
>> u8 timeout = 50;
>>
>> while (test_and_set_bit(WX_STATE_RESETTING, wx->state)) {
>> timeout--;
>> if (!timeout)
>> return -EBUSY;
>>
>> usleep_range(1000, 2000);
>> }
>>
>> return 0;
>> }
>>
>> Using a bit flag and a sleep-polling loop to guard a teardown and bringup
>> section acts as an ad-hoc lock. This approach bypasses standard kernel
>> synchronization guarantees and prevents lockdep from analyzing the lock
>> ordering.
>>
>> Since this context is allowed to sleep, could this section be protected by
>> a standard mutex instead?
> > I think using a state flag here would be better. Because other code
paths
> (like watchdog) need to check if a reset is in process without taking a lock.
>
>
Couldn't you use an atomic and a mutex together?
mutex_lock(wx->reset_lock);
set_bit(WX_STATE_RESETTING, wx->state);
...
Mutex_unlock(wx->reset_lock);
Paths that only need to know a reset has already started can just
test_bit. Paths which need to wait on reset can acquire the lock.
There shouldn't be any issue doing this that doesn't already exist with
the test_and_set loop, because you can already have a path doing "if
(test_bit(resetting)) exit" flow would still potentially begin executing
even if a reset already acquired the lock, it could have ordered the
test path first regardless, so you already aren't really guaranteed that
a reset won't start until your operation is done unless you hold the lock.
Using a mutex also gives you lockdep checking and is generally more sane
to reason about.
Thanks,
Jake
next prev parent reply other threads:[~2026-03-31 23:05 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-26 2:13 [PATCH net-next v6 00/11] Wangxun improvement and new support Jiawen Wu
2026-03-26 2:13 ` [PATCH net-next v6 01/11] net: ngbe: remove netdev->ethtool->wol_enabled setting Jiawen Wu
2026-03-26 2:13 ` [PATCH net-next v6 02/11] net: ngbe: move the WOL functions to libwx Jiawen Wu
2026-03-26 2:13 ` [PATCH net-next v6 03/11] net: ngbe: remove redundant macros Jiawen Wu
2026-03-26 2:13 ` [PATCH net-next v6 04/11] net: ngbe: implement libwx reset ops Jiawen Wu
2026-03-31 0:55 ` Jakub Kicinski
2026-03-31 7:19 ` Jiawen Wu
2026-03-31 13:03 ` Andrew Lunn
2026-03-31 23:05 ` Jacob Keller [this message]
2026-03-26 2:14 ` [PATCH net-next v6 05/11] net: wangxun: move reusable PCI driver ops functions into libwx Jiawen Wu
2026-03-31 0:55 ` Jakub Kicinski
2026-03-26 2:14 ` [PATCH net-next v6 06/11] net: txgbe: add power management support Jiawen Wu
2026-03-31 0:55 ` Jakub Kicinski
2026-03-26 2:14 ` [PATCH net-next v6 07/11] net: wangxun: move ethtool_ops.set_channels into libwx Jiawen Wu
2026-03-26 2:14 ` [PATCH net-next v6 08/11] net: wangxun: delete service_timer before cancel service_work Jiawen Wu
2026-03-31 0:55 ` Jakub Kicinski
2026-03-26 2:14 ` [PATCH net-next v6 09/11] net: wangxun: add Tx timeout process Jiawen Wu
2026-03-31 0:55 ` Jakub Kicinski
2026-03-26 2:14 ` [PATCH net-next v6 10/11] net: wangxun: improve flow control setting Jiawen Wu
2026-03-31 0:55 ` Jakub Kicinski
2026-03-26 2:14 ` [PATCH net-next v6 11/11] net: wangxun: implement pci_error_handlers ops Jiawen Wu
2026-03-31 0:55 ` Jakub Kicinski
2026-03-31 0:54 ` [PATCH net-next v6 00/11] Wangxun improvement and new support Jakub Kicinski
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=990c010b-f716-499d-b3ca-e8296003c37e@intel.com \
--to=jacob.e.keller@intel.com \
--cc=abdun.nihaal@gmail.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jiawenwu@trustnetic.com \
--cc=joe@dama.to \
--cc=kees@kernel.org \
--cc=kuba@kernel.org \
--cc=larysa.zaremba@intel.com \
--cc=leitao@debian.org \
--cc=linux@armlinux.org.uk \
--cc=mengyuanlou@net-swift.com \
--cc=michal.swiatkowski@linux.intel.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.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