From: Johannes Berg <johannes@sipsolutions.net>
To: Ben Greear <greearb@candelatech.com>,
linux-wireless <linux-wireless@vger.kernel.org>
Subject: Re: Kernel deadlock in 6.7.5 + hacks, maybe debugfs related.
Date: Tue, 27 Feb 2024 15:58:35 +0100 [thread overview]
Message-ID: <366ed520b5f4b3cd603be11124f9b51e32ce8106.camel@sipsolutions.net> (raw)
In-Reply-To: <492a290b-752f-48c3-be16-59bdf7914487@candelatech.com>
On Tue, 2024-02-27 at 06:51 -0800, Ben Greear wrote:
> On 2/27/24 06:32, Johannes Berg wrote:
> > On Tue, 2024-02-27 at 06:29 -0800, Ben Greear wrote:
> > > > --- a/fs/debugfs/inode.c
> > > > +++ b/fs/debugfs/inode.c
> > > > @@ -751,13 +751,19 @@ static void __debugfs_file_removed(struct dentry *dentry)
> > > > if ((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT)
> > > > return;
> > > >
> > > > - /* if we hit zero, just wait for all to finish */
> > > > - if (!refcount_dec_and_test(&fsd->active_users)) {
> > > > - wait_for_completion(&fsd->active_users_drained);
> > > > - return;
> > > > - }
> > > > + /*
> > > > + * Now that debugfs_file_get() no longer sees a valid entry,
> > > > + * decrement the refcount to remove the initial reference.
> > > > + */
> > > > + refcount_dec(&fsd->active_users);
> >
> > >
> > > [ 94.576688] ------------[ cut here ]------------
> > > [ 94.576699] refcount_t: decrement hit 0; leaking memory.
> > >
> >
> > Ah ... right, refcount_dec() doesn't like to hit 0, it's not meant for
> > this path.
> >
> > I guess we can
> >
> > if (refcount_dec_and_test(...))
> > return;
> >
> > while (refcount_read(...)) { ... }
> >
> > johannes
> >
>
> Like this?
>
> diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
> index 034a617cb1a5..166053095610 100644
> --- a/fs/debugfs/inode.c
> +++ b/fs/debugfs/inode.c
> @@ -751,13 +751,20 @@ static void __debugfs_file_removed(struct dentry *dentry)
> if ((unsigned long)fsd & DEBUGFS_FSDATA_IS_REAL_FOPS_BIT)
> return;
>
> - /* if we hit zero, just wait for all to finish */
> - if (!refcount_dec_and_test(&fsd->active_users)) {
> - wait_for_completion(&fsd->active_users_drained);
> + /*
> + * Now that debugfs_file_get() no longer sees a valid entry,
> + * decrement the refcount to remove the initial reference.
> + */
> + if (!refcount_dec_and_test(&fsd->active_users))
> return;
> - }
>
Which, btw, ignoring comments, braces, whitespace - then really just
removes the line you're getting stuck on.
So actually no ... invert the test?
if (refcount_dec_and_test(...))
return;
If it hit zero here, there's guaranteed to be no user, so we can return.
If it's not zero yet, we might yet go into a new cancellation, so we
need the rest of the function.
johannes
next prev parent reply other threads:[~2024-02-27 14:58 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-23 17:08 Kernel deadlock in 6.7.5 + hacks, maybe debugfs related Ben Greear
2024-02-26 8:42 ` Johannes Berg
2024-02-26 14:58 ` Ben Greear
2024-02-26 15:46 ` Johannes Berg
2024-02-27 13:47 ` Johannes Berg
2024-02-27 13:51 ` Ben Greear
2024-02-27 14:29 ` Ben Greear
2024-02-27 14:32 ` Johannes Berg
2024-02-27 14:51 ` Ben Greear
2024-02-27 14:56 ` Johannes Berg
2024-02-27 14:58 ` Johannes Berg [this message]
2024-02-27 16:13 ` Johannes Berg
2024-02-27 17:25 ` Ben Greear
2024-02-29 4:05 ` Ben Greear
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=366ed520b5f4b3cd603be11124f9b51e32ce8106.camel@sipsolutions.net \
--to=johannes@sipsolutions.net \
--cc=greearb@candelatech.com \
--cc=linux-wireless@vger.kernel.org \
/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