All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chenguang Zhao <chenguang.zhao@linux.dev>
To: Jakub Kicinski <kuba@kernel.org>
Cc: andrew@lunn.ch, hkallweit1@gmail.com, linux@armlinux.org.uk,
	davem@davemloft.net, edumazet@google.com, pabeni@redhat.com,
	netdev@vger.kernel.org,
	syzbot+694b49f41098a5df4fd7@syzkaller.appspotmail.com
Subject: Re: [PATCH net-next v3] net: phy: make the hwtstamp provider lifetime symmetric with the PHY
Date: Fri, 2 Oct 2026 17:43:44 +0800	[thread overview]
Message-ID: <83eeeff9-5271-471f-89ed-2644da69d923@linux.dev> (raw)
In-Reply-To: <20260929170300.39a8cb63@kernel.org>


在 2026/9/30 08:03, Jakub Kicinski 写道:
> On Wed, 23 Sep 2026 15:11:32 +0800 Chenguang Zhao wrote:
>> phy_detach() removes dev->hwprov when it points at the PHY being
>> detached, but phy_attach() does not install anything: the setup and
>> teardown are not symmetric. The teardown path is also reached from
>> the probe error path with no RTNL and an unregistered netdev, making
>> rtnl_dereference() of dev->hwprov trigger a lockdep splat.
>>
>> Track the provider with the PHY instead: dev_attach_hwtstamp_phylib()
>> installs a default provider in phy_attach_direct(), and
>> dev_clear_hwtstamp_phylib() removes it in phy_detach(). Both sit
>> next to dev_set_hwtstamp_phylib() so the locking is obviously the
>> same, relaxed for unregistered netdevs via
>> netdev_ops_lock_dereference_or_invisible(). No driver callback is
>> invoked; installation is skipped when the PHY is not the default
>> hwtstamp provider or when ethtool already set one.
> This is pure slop, you added this incredibly ugly
> netdev_ops_lock_dereference_or_invisible()
> instead of just taking the RCU lock.
>
> Please don't send send any patches to networking for the next 2 months
> and use this time to learn kernel programming basics.

Hi Jakub

You are right. dev->hwprov is an RCU pointer. The probe error path does not hold RTNL, 

and I silenced the lockdep splat by teaching the ops-lock helper that an unregistered netdev 

needs no lock. That was the wrong fix. The access should use rcu_read_lock() with rcu_dereference().


I was trapped in a misleading mindset: I overly focused on making the phy_attach() and phy_detach() 

paths fully symmetric and tried to avoid RTNL lockdep warnings in the error path, which led me to 

invent an inappropriate workaround instead of using the proper RCU pattern.

I will not send networking patches for the next two months. Thank you for pointing this out.


Thanks

Chenguang


      reply	other threads:[~2026-10-02  9:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-23  7:11 [PATCH net-next v3] net: phy: make the hwtstamp provider lifetime symmetric with the PHY Chenguang Zhao
2026-09-30  0:03 ` Jakub Kicinski
2026-10-02  9:43   ` Chenguang Zhao [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=83eeeff9-5271-471f-89ed-2644da69d923@linux.dev \
    --to=chenguang.zhao@linux.dev \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=syzbot+694b49f41098a5df4fd7@syzkaller.appspotmail.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.