Linux USB
 help / color / mirror / Atom feed
From: Johan Hovold <johan@kernel.org>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	Danilo Krummrich <dakr@kernel.org>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Mario Peter <mario.peter@leica-geosystems.com>,
	driver-core@lists.linux.dev, linux-usb@vger.kernel.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH v2 3/3] driver core: take parent lock in async device attach
Date: Wed, 14 Oct 2026 16:58:43 +0200	[thread overview]
Message-ID: <as-Yo_ge-2C6NZRO@hovoldconsulting.com> (raw)
In-Reply-To: <a68b8b6c-c84e-44a2-baff-aff56824a465@rowland.harvard.edu>

On Wed, Oct 14, 2026 at 10:52:48AM -0400, Alan Stern wrote:
> On Wed, Oct 14, 2026 at 03:31:09PM +0200, Johan Hovold wrote:
> > From: Mario Peter <mario.peter@leica-geosystems.com>

> > Take the parent lock in __device_attach_async_helper() as well, like
> > __driver_attach_async_helper() does, and move
> > __device_driver_lock/unlock() up for that. With this the warning was
> > gone in 300 boots on the board and in 6000 iterations in QEMU.
> > 
> > Fixes: 765230b5f084 ("driver-core: add asynchronous probing support for drivers")
> > Assisted-by: LLM
> > Signed-off-by: Mario Peter <mario.peter@leica-geosystems.com>

> > [ johan: switch to async_schedule_dev_nocall() to avoid deadlock if
> >          async_schedule_dev() runs synchronously when parent lock is
> > 	 held ]

> > @@ -1118,8 +1150,13 @@ static int __device_attach(struct device *dev, bool allow_async)
> >  	}
> >  out_unlock:
> >  	device_unlock(dev);
> > -	if (async)
> > -		async_schedule_dev(__device_attach_async_helper, dev);
> > +	if (async) {
> > +		if (!async_schedule_dev_nocall(__device_attach_async_helper, dev)) {
> > +			put_device(dev);
> > +			ret = 2;	/* retry synchronously */
> > +		}
> > +	}
> > +
> >  	return ret;
> >  }
> >  
> > @@ -1146,48 +1183,20 @@ EXPORT_SYMBOL_GPL(device_attach);
> >  void device_initial_probe(struct device *dev)
> >  {
> >  	struct subsys_private *sp = bus_to_subsys(dev->bus);
> > +	int ret;
> >  
> >  	if (!sp)
> >  		return;
> >  
> > -	if (sp->drivers_autoprobe)
> > -		__device_attach(dev, true);
> > +	if (sp->drivers_autoprobe) {
> > +		ret = __device_attach(dev, true);
> > +		if (ret == 2)
> > +			__device_attach(dev, false);
> > +	}
> >  
> >  	subsys_put(sp);
> >  }
> 
> These two pieces do not seem to be related to the changes mentioned in 
> the patch description.  Are they leftovers from some other patch?

They are needed since async_schedule_dev() may execute the callback
synchronously and in which case we'll deadlock if the caller already
holds the parent mutex (e.g. during initial probe).

I only highlighted the issue in the trailer section of the patch,
perhaps I should have amended the commit message proper.

Johan

      reply	other threads:[~2026-10-14 14:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14 13:31 [PATCH v2 0/3] driver core: parent lock fixes Johan Hovold
2026-10-14 13:31 ` [PATCH v2 1/3] driver core: fix parent lock use-after-free on USB disconnect Johan Hovold
2026-10-14 13:43   ` sashiko-bot
2026-10-14 14:49   ` Danilo Krummrich
2026-10-14 14:58     ` Alan Stern
2026-10-14 13:31 ` [PATCH v2 2/3] driver core: take parent lock on deferred probe Johan Hovold
2026-10-14 13:48   ` sashiko-bot
2026-10-14 13:31 ` [PATCH v2 3/3] driver core: take parent lock in async device attach Johan Hovold
2026-10-14 13:40   ` sashiko-bot
2026-10-14 14:52   ` Alan Stern
2026-10-14 14:58     ` Johan Hovold [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=as-Yo_ge-2C6NZRO@hovoldconsulting.com \
    --to=johan@kernel.org \
    --cc=dakr@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=driver-core@lists.linux.dev \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mario.peter@leica-geosystems.com \
    --cc=rafael@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