public inbox for linux-hwmon@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Rasmus Villemoes <ravi@prevas.dk>
Cc: Peter Rosin <peda@axentia.se>, Guenter Roeck <linux@roeck-us.net>,
	<linux-iio@vger.kernel.org>, <linux-hwmon@vger.kernel.org>
Subject: Re: lockdep splat involving iio-hwmon and iio-rescale drivers
Date: Sat, 13 Dec 2025 16:57:23 +0000	[thread overview]
Message-ID: <20251213165723.762035e4@jic23-huawei> (raw)
In-Reply-To: <87ms3nu9m7.fsf@prevas.dk>

On Fri, 12 Dec 2025 14:12:48 +0100
Rasmus Villemoes <ravi@prevas.dk> wrote:

> On Thu, Dec 11 2025, Peter Rosin <peda@axentia.se> wrote:
> 
> > 2025-12-10 at 23:54, Peter Rosin wrote:  
> >> Before commit 3092bde731ca ("iio: inkern: move to the cleanup.h
> >> magic") I think this could have been solved with a number of:
> >> 
> >> -	mutex_lock(&iio_dev_opaque->info_exist_lock);
> >> +	mutex_lock_nested(&iio_dev_opaque->info_exist_lock);  
> >
> > Oops, we need something clever for the (missing) subclass
> > argument to the mutex_lock_nested() calls, which I simply forgot
> > all about. It should have been:
> >
> > +	mutex_lock_nested(&iio_dev_opaque->info_exist_lock, *subclass*);
> >
> > I don't know what sane subclasses there are. One thing could be
> > the recursion depth, but I don't think we want to keep track of that
> > just for lockdep? Another is to use one lockdep class for every
> > info_exist_lock, but that can generate a lot of lockdep classes...  

Either option should work but agreed tracking depth when
we otherwise don't care about it feels excessive.
We already have classes for the other major internal lock in IIO devices (mlock)

https://elixir.bootlin.com/linux/v6.18.1/source/drivers/iio/industrialio-core.c#L1722

I'm a bit curious we haven't seen many reports of this one. Whilst
there are relatively few IIO drivers that consume other IIO driver provided
channels it's also not a particularly new thing.

> 
> It doesn't seem to me that that info_exist_lock is the proper
> mechanism for whatever it is it is protecting against.
> 
> I'm not even sure it's needed, because if the device could be
> unregistered while somebody has a reference to it, why is it even
> allowed to take that lock in the first place (i.e., why is the memory
> containing the info_exist_lock guaranteed to still be valid)?

It's to protect against racing with setting of iio_dev->info to NULL.
The iio_dev itself is reference counted so it should always be safe
to do this lookup. Note that use of info == NULL isn't about accessing
info alone, but as a general gate on device has gone away (but
structures are still there until all consumers - in kernel or userspace
- are done).

In theory at least all consumers use proxy functions that check that
and error out if the thing being consumed has gone away.  Those that
are sleeping on anything are woken up and return errors.

Sure there are other approaches to providing that protection and
there was an attempt to do a generic solution a while back. I lost
track of where that got to.  Might be worth a revisit at some point.

For now though a lockdep class per instance seems the way to go to me.

Jonathan


> 
> But, since I'm not going to propose just ripping it out, perhaps a
> better approach would be something like what the gpio subsystem did in
> d83cee3d2bb1 ("gpio: protect the pointer to gpio_chip in gpio_device
> with SRCU"), at least superficially it seems to be about a similar
> problem.
> 
> Rasmus


  reply	other threads:[~2025-12-13 16:57 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-10 14:31 lockdep splat involving iio-hwmon and iio-rescale drivers Rasmus Villemoes
2025-12-10 19:12 ` Guenter Roeck
2025-12-10 22:54   ` Peter Rosin
2025-12-10 23:29     ` Peter Rosin
2025-12-12 13:12       ` Rasmus Villemoes
2025-12-13 16:57         ` Jonathan Cameron [this message]
     [not found]           ` <98101700-35EB-4D45-AEE4-6FF1E9D55505@axentia.se>
2025-12-14 14:39             ` Jonathan Cameron
2025-12-15  9:14             ` Rasmus Villemoes

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=20251213165723.762035e4@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux@roeck-us.net \
    --cc=peda@axentia.se \
    --cc=ravi@prevas.dk \
    /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