public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Danilo Krummrich" <dakr@kernel.org>
To: "Marc Zyngier" <maz@kernel.org>
Cc: "Doug Anderson" <dianders@chromium.org>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J . Wysocki" <rafael@kernel.org>,
	"Alan Stern" <stern@rowland.harvard.edu>,
	"Saravana Kannan" <saravanak@kernel.org>,
	"Christoph Hellwig" <hch@lst.de>,
	"Eric Dumazet" <edumazet@google.com>,
	"Johan Hovold" <johan@kernel.org>,
	"Leon Romanovsky" <leon@kernel.org>,
	"Alexander Lobakin" <aleksander.lobakin@intel.com>,
	"Alexey Kardashevskiy" <aik@ozlabs.ru>,
	"Robin Murphy" <robin.murphy@arm.com>, <stable@vger.kernel.org>,
	<driver-core@lists.linux.dev>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 1/9] driver core: Don't let a device probe until it's ready
Date: Mon, 06 Apr 2026 20:11:39 +0200	[thread overview]
Message-ID: <DHM9WIABIULA.VZ9HOKU62SC9@kernel.org> (raw)
In-Reply-To: <87zf3gauid.wl-maz@kernel.org>

On Mon Apr 6, 2026 at 7:06 PM CEST, Marc Zyngier wrote:
> On Mon, 06 Apr 2026 17:43:22 +0100,
> "Danilo Krummrich" <dakr@kernel.org> wrote:
>> 
>> On Mon Apr 6, 2026 at 6:34 PM CEST, Marc Zyngier wrote:
>> > On Mon, 06 Apr 2026 15:41:08 +0100,
>> > Doug Anderson <dianders@chromium.org> wrote:
>> >> 
>> >> Hi,
>> >> 
>> >> On Sun, Apr 5, 2026 at 11:32 PM Marc Zyngier <maz@kernel.org> wrote:
>> >> >
>> >> > > +      * blocked those attempts. Now that all of the above initialization has
>> >> > > +      * happened, unblock probe. If probe happens through another thread
>> >> > > +      * after this point but before bus_probe_device() runs then it's fine.
>> >> > > +      * bus_probe_device() -> device_initial_probe() -> __device_attach()
>> >> > > +      * will notice (under device_lock) that the device is already bound.
>> >> > > +      */
>> >> > > +     dev_set_ready_to_probe(dev);
>> >> >
>> >> > I think this lacks some ordering properties that we should be allowed
>> >> > to rely on. In this case, the 'ready_to_probe' flag being set should
>> >> > that all of the data structures are observable by another CPU.
>> >> >
>> >> > Unfortunately, this doesn't seem to be the case, see below.
>> >> 
>> >> I agree. I think Danilo was proposing fixing this by just doing:
>> >> 
>> >> device_lock(dev);
>> >> dev_set_ready_to_probe(dev);
>> >> device_unlock(dev);
>> >> 
>> >> While that's a bit of an overkill, it also works I think. Do folks
>> >> have a preference for what they'd like to see in v5?
>> >
>> > It would work, but I find the construct rather obscure, and it implies
>> > that there is a similar lock taken on the read path. Looking at the
>> > code for a couple of minutes doesn't lead to an immediate clue that
>> > such lock is indeed taken on all read paths.
>> 
>> Why do you think this is obscure?
>
> Because you're not using the lock to protect any data. You're using
> the lock for its release effect. Yes, it works. But the combination of
> atomics *and* locking is just odd. You normally pick one model or the
> other, not a combination of both.

Yeah, the choice of bitops was purely because previously (in v2) this was a C
bitfield member in struct device protected with the device lock. But, not all of
the bitfield members were protected by the same lock or protected by a lock at
all, which would have made this racy with the other bitfield members. I.e. the
choice of bitops was independent; see also [2] for context.

[2] https://lore.kernel.org/driver-core/DHH1PD0ASG8H.1K3KG9L658DYN@kernel.org/

>> As I mentioned in [1], the whole purpose of
>> dev_set_ready_to_probe() is to protect against a concurrent probe() attempt of
>> driver_attach() in __driver_probe_device(), while __driver_probe_device() is
>> protected by the device lock is by design.
>> 
>> [1] https://lore.kernel.org/driver-core/DHM5TCBT6GDE.EFG3IPRP99G7@kernel.org/
>
> I don't have much skin in this game, and you seem to have strong
> opinions about how these things are supposed to work. So whatever
> floats your boat, as long as it is correct.

Not overly, it's more about calling out the fact that probe() paths are
serialized through the device lock by design, so it seems natural to protect
dev_set_ready_to_probe() with the device lock.

The fact that dev_set_ready_to_probe() uses a bitop under the hood is an
implementation detail, i.e. it could also be an independent boolean.

That said, as I caught the issue in [3], I also mentioned the option of an
explicit memory barrier in device_add() and __driver_probe_device(). I.e. I'm
not entirely against it, but I think the device lock is a bit cleaner.

[3] https://lore.kernel.org/driver-core/DHLITCTY913U.J59JSQOVL0NH@kernel.org/

  reply	other threads:[~2026-04-06 18:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-04  0:04 [PATCH v4 0/9] driver core: Fix some race conditions Douglas Anderson
2026-04-04  0:04 ` [PATCH v4 1/9] driver core: Don't let a device probe until it's ready Douglas Anderson
2026-04-04 17:35   ` Danilo Krummrich
2026-04-05 20:58   ` Danilo Krummrich
2026-04-05 22:39     ` Doug Anderson
2026-04-06  6:39       ` Greg Kroah-Hartman
2026-04-06 14:15         ` Danilo Krummrich
2026-04-06  6:32   ` Marc Zyngier
2026-04-06 14:41     ` Doug Anderson
2026-04-06 14:59       ` Danilo Krummrich
2026-04-06 16:34       ` Marc Zyngier
2026-04-06 16:43         ` Danilo Krummrich
2026-04-06 17:06           ` Marc Zyngier
2026-04-06 18:11             ` Danilo Krummrich [this message]
2026-04-06 18:59               ` Doug Anderson
2026-04-06 16:45         ` Doug Anderson
2026-04-04  0:04 ` [PATCH v4 2/9] driver core: Replace dev->can_match with dev_can_match() Douglas Anderson
2026-04-04  0:04 ` [PATCH v4 3/9] driver core: Replace dev->dma_iommu with dev_dma_iommu() Douglas Anderson
2026-04-04  0:04 ` [PATCH v4 4/9] driver core: Replace dev->dma_skip_sync with dev_dma_skip_sync() Douglas Anderson
2026-04-04  0:04 ` [PATCH v4 5/9] driver core: Replace dev->dma_ops_bypass with dev_dma_ops_bypass() Douglas Anderson
2026-04-04  0:05 ` [PATCH v4 6/9] driver core: Replace dev->state_synced with dev_state_synced() Douglas Anderson
2026-04-04  0:05 ` [PATCH v4 7/9] driver core: Replace dev->dma_coherent with dev_dma_coherent() Douglas Anderson
2026-04-06  5:49   ` Vinod Koul
2026-04-04  0:05 ` [PATCH v4 8/9] driver core: Replace dev->of_node_reused with dev_of_node_reused() Douglas Anderson
2026-04-04  0:05 ` [PATCH v4 9/9] driver core: Replace dev->offline + ->offline_disabled with accessors Douglas Anderson
2026-04-04 17:11 ` [PATCH v4 0/9] driver core: Fix some race conditions Rafael J. Wysocki
2026-04-05  5:27 ` Greg Kroah-Hartman
2026-04-05 12:02   ` Danilo Krummrich
2026-04-05 22:43   ` Doug Anderson

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=DHM9WIABIULA.VZ9HOKU62SC9@kernel.org \
    --to=dakr@kernel.org \
    --cc=aik@ozlabs.ru \
    --cc=aleksander.lobakin@intel.com \
    --cc=dianders@chromium.org \
    --cc=driver-core@lists.linux.dev \
    --cc=edumazet@google.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@lst.de \
    --cc=johan@kernel.org \
    --cc=leon@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maz@kernel.org \
    --cc=rafael@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=saravanak@kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=stern@rowland.harvard.edu \
    /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