From: Leon Romanovsky <leon@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Danilo Krummrich <dakr@kernel.org>,
Tariq Toukan <tariqt@nvidia.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Saeed Mahameed <saeedm@nvidia.com>,
Mark Bloch <mbloch@nvidia.com>,
Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
driver-core@lists.linux.dev, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org, linux-rdma@vger.kernel.org,
Gal Pressman <gal@nvidia.com>, Moshe Shemesh <moshe@nvidia.com>,
Amir Tzin <amirtz@nvidia.com>
Subject: Re: [PATCH V2] driver core: auxiliary bus: Fix sysfs creation on bind
Date: Fri, 20 Feb 2026 10:08:59 +0200 [thread overview]
Message-ID: <20260220080859.GC10607@unreal> (raw)
In-Reply-To: <2026022040-casualty-dexterity-543c@gregkh>
On Fri, Feb 20, 2026 at 07:34:02AM +0100, Greg Kroah-Hartman wrote:
> On Fri, Feb 20, 2026 at 12:59:45AM +0100, Danilo Krummrich wrote:
> > On Thu Feb 19, 2026 at 10:04 PM CET, Tariq Toukan wrote:
> > > +/**
> > > + * auxiliary_device_sysfs_irq_dir_init - initialize the IRQ sysfs directory
> > > + * @auxdev: auxiliary bus device to initialize the sysfs directory.
> > > + *
> > > + * This function should be called by drivers to initialize the IRQ directory
> > > + * before adding any IRQ sysfs entries. The driver is responsible for ensuring
> > > + * this function is called only once and for handling any concurrency control
> > > + * if needed.
> > > + *
> > > + * Drivers must call auxiliary_device_sysfs_irq_dir_destroy() to clean up when
> > > + * done.
> > > + *
> > > + * Return: zero on success or an error code on failure.
> > > + */
> > > +int auxiliary_device_sysfs_irq_dir_init(struct auxiliary_device *auxdev)
> > > {
> > > - int ret = 0;
> > > -
> > > - guard(mutex)(&auxdev->sysfs.lock);
> > > - if (auxdev->sysfs.irq_dir_exists)
> > > - return 0;
> > > + int ret;
> > >
> > > - ret = devm_device_add_group(&auxdev->dev, &auxiliary_irqs_group);
> > > + ret = sysfs_create_group(&auxdev->dev.kobj, &auxiliary_irqs_group);
> > > if (ret)
> > > return ret;
> > >
> > > - auxdev->sysfs.irq_dir_exists = true;
> > > xa_init(&auxdev->sysfs.irqs);
> > > return 0;
> > > }
> > > +EXPORT_SYMBOL_GPL(auxiliary_device_sysfs_irq_dir_init);
> > > +
> > > +/**
> > > + * auxiliary_device_sysfs_irq_dir_destroy - destroy the IRQ sysfs directory
> > > + * @auxdev: auxiliary bus device to destroy the sysfs directory.
> > > + *
> > > + * This function should be called by drivers to clean up the IRQ directory
> > > + * after all IRQ sysfs entries have been removed. The driver is responsible
> > > + * for ensuring all IRQs are removed before calling this function.
> > > + */
> > > +void auxiliary_device_sysfs_irq_dir_destroy(struct auxiliary_device *auxdev)
> > > +{
> > > + xa_destroy(&auxdev->sysfs.irqs);
> > > + sysfs_remove_group(&auxdev->dev.kobj, &auxiliary_irqs_group);
> > > +}
> > > +EXPORT_SYMBOL_GPL(auxiliary_device_sysfs_irq_dir_destroy);
> > >
> > > /**
> > > * auxiliary_device_sysfs_irq_add - add a sysfs entry for the given IRQ
> > > @@ -45,7 +70,8 @@ static int auxiliary_irq_dir_prepare(struct auxiliary_device *auxdev)
> > > * @irq: The associated interrupt number.
> > > *
> > > * This function should be called after auxiliary device have successfully
> > > - * received the irq.
> > > + * received the irq. The driver must call auxiliary_device_sysfs_irq_dir_init()
> > > + * before calling this function for the first time.
> >
> > I'm not convinced by this approach. This adds two new sources of bugs for
> > drivers.
> >
> > 1. Drivers can now forget to call auxiliary_device_sysfs_irq_dir_init()
> > *before* auxiliary_device_sysfs_irq_add().
> >
> > 2. Drivers can forget to call auxiliary_device_sysfs_irq_dir_destroy().
> >
> > Instead, I suggest to keep the current approach and just replace
> > devm_device_add_group() with devm_auxiliary_device_add_group(), which in its
> > devres callback additionally clears auxdev->sysfs.irq_dir_exists.
> >
> > In terms of the auxdev->sysfs.lock, I think this can still be removed, as it
> > wasn't needed in the first place.
> >
> > auxiliary_device_sysfs_irq_add() must only be called from a scope where the
> > auxiliary device is guaranteed to be bound, so there can't be a concurrent
> > unbind.
> >
> > There may only be multiple concurrent calls to auxiliary_device_sysfs_irq_add()
> > itself, and in this case irq_dir_exists can just be an atomic.
> >
> > Yes, we're still stuck with an atomic for irq_dir_exists, but the driver API
> > remains much simpler and less error prone.
>
> I agree, your recommendations make sense.
Unfortunately no, https://lore.kernel.org/all/20260220080413.GB10607@unreal/.
Just to summarize:
1. atomic is not a replacement for locking.
2. drivers already handle this irq thing.
3. init->add->remove->destroy is standard Linux kernel coding pattern.
Thanks
next prev parent reply other threads:[~2026-02-20 8:09 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-19 21:04 [PATCH V2] driver core: auxiliary bus: Fix sysfs creation on bind Tariq Toukan
2026-02-19 22:21 ` Jacob Keller
2026-02-19 23:59 ` Danilo Krummrich
2026-02-20 6:34 ` Greg Kroah-Hartman
2026-02-20 8:08 ` Leon Romanovsky [this message]
2026-02-20 8:04 ` Leon Romanovsky
2026-02-20 11:14 ` Danilo Krummrich
2026-02-20 14:11 ` Leon Romanovsky
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=20260220080859.GC10607@unreal \
--to=leon@kernel.org \
--cc=amirtz@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=dakr@kernel.org \
--cc=davem@davemloft.net \
--cc=driver-core@lists.linux.dev \
--cc=edumazet@google.com \
--cc=gal@nvidia.com \
--cc=gregkh@linuxfoundation.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=moshe@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rafael@kernel.org \
--cc=saeedm@nvidia.com \
--cc=tariqt@nvidia.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