From: Henrique Carvalho <henrique.carvalho@suse.com>
To: Enzo Matsumiya <ematsumiya@suse.de>
Cc: Steve French <smfrench@gmail.com>,
pc@manguebit.com, ronniesahlberg@gmail.com,
sprasad@microsoft.com, paul@darkrain42.org,
bharathsm@microsoft.com, linux-cifs@vger.kernel.org,
Meetakshi Setiya <msetiya@microsoft.com>
Subject: Re: [PATCH] smb: cached_dir.c: fix race in cfid release
Date: Fri, 2 May 2025 17:59:27 -0300 [thread overview]
Message-ID: <aBUyL2ypuI2PTvoy@precision> (raw)
In-Reply-To: <aBUpD0LzzzPUbRjz@precision>
On Fri, May 02, 2025 at 05:20:31PM -0300, Henrique Carvalho wrote:
> On Fri, May 02, 2025 at 04:58:00PM -0300, Enzo Matsumiya wrote:
> > On 05/02, Steve French wrote:
> > > I fixed a minor checkpatch warning but also noticed this compile
> > > warning - is there a missing lock call?
> > >
> > > cached_dir.c:429:20: warning: context imbalance in 'cfid_release' -
> > > unexpected unlock
> >
> > The lock is taken (inside kref_put_lock) if count == 0 (i.e. when the
> > release function is called) and must be released from within the
> > release function (which is done here).
> >
> > However, sparse can't recognize this and also there doesn't seem to
> > exist an annotation to indicate so.
> >
> > @Henrique do you think you could rework the patch to something like:
> >
> > cfid_release() {
> > list_del();
> > on_list = false;
> > num_entries--;
> > }
> >
> > cfid_put() {
> > lock();
> > if (kref_put(..., cfid_release)) {
> > unlock();
> > dput();
> > SMB2_close();
> > free_cached_dir();
> > return;
> > }
> > unlock();
> > }
> >
>
> @Enzo, good idea. I will rework the patch.
>
Actually, this change would prevent me from calling cfid_put() with the
lock held in cases where the kref does *not* reach 0 and the release
function isn't supposed to run. While it could work, the code won't be
as elegant.
I’m open to suggestions if there's a way to preserve that behavior
while satisfying sparse.
In the meantime, I'm reviewing similar discussions on other mailing
lists to see if there are known solutions.
Henrique
next prev parent reply other threads:[~2025-05-02 21:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-02 18:01 [PATCH] smb: cached_dir.c: fix race in cfid release Henrique Carvalho
2025-05-02 19:07 ` Steve French
2025-05-02 19:58 ` Enzo Matsumiya
2025-05-02 20:20 ` Henrique Carvalho
2025-05-02 20:59 ` Henrique Carvalho [this message]
2025-05-02 21:54 ` Steve French
2025-05-02 22:41 ` Henrique Carvalho
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=aBUyL2ypuI2PTvoy@precision \
--to=henrique.carvalho@suse.com \
--cc=bharathsm@microsoft.com \
--cc=ematsumiya@suse.de \
--cc=linux-cifs@vger.kernel.org \
--cc=msetiya@microsoft.com \
--cc=paul@darkrain42.org \
--cc=pc@manguebit.com \
--cc=ronniesahlberg@gmail.com \
--cc=smfrench@gmail.com \
--cc=sprasad@microsoft.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