All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Schoenebeck <linux_oss@crudebyte.com>
To: Dominique Martinet <asmadeus@codewreck.org>
Cc: Eric Van Hensbergen <ericvh@kernel.org>,
	Latchesar Ionkov <lucho@ionkov.net>, Greg Kurz <groug@kaod.org>,
	Jianyong Wu <jianyong.wu@arm.com>,
	stable@vger.kernel.org, Eric Van Hensbergen <ericvh@gmail.com>,
	v9fs@lists.linux.dev, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] 9p: add missing locking around taking dentry fid list
Date: Thu, 23 May 2024 12:05:44 +0200	[thread overview]
Message-ID: <2675095.dNBKFZOyUv@silver> (raw)
In-Reply-To: <Zk8MAFAWIUPlhGFe@codewreck.org>

On Thursday, May 23, 2024 11:27:28 AM CEST Dominique Martinet wrote:
> Christian Schoenebeck wrote on Thu, May 23, 2024 at 10:34:14AM +0200:
> > > The comment still works -- if detry->d_fsdata is NULL then
> > > hlist_for_each_entry will stop short and not iterate over anything (it
> > > won't bug out), so that part is fine in my opinion.
> > 
> > I meant the opposite: dentry->d_fsdata not being NULL.
> 
> I also meant that in the d_fsdata not being NULL branch, if d_fsdata
> turns out to be NULL when it is read under lock later.
> 
> > In this case v9fs_fid_find() takes a local copy of the list head
> > pointer as `h` without taking a lock before.
> 
> It doesn't, it takes &dentry->d_fsdata so the address of d_fsdata before
> the lock, but that address cannot change here (another thread cannot
> change the address of the dentry) ...(continuing below)

Aaah right, I was missing the `&`, my bad!

> > Then v9fs_fid_find() takes the lock to run hlist_for_each_entry(), but at this
> > point `h` could already point at garbage.
> 
> ... so *h (in practice, head->first in hlist_for_each_entry()) will
> properly contain the first node of the list under lock: either NULL if
> we just cleared it (at which point the loop won't iterate anything), or
> a new list if other items have been added meanwhile.

Yeah, looks fine to me.

> I really think it's safe, but I do agree that it's hard to read, happy
> to move the `h = &dentry->d_fsdata` inside the lock if you prefer -- it
> compiles to the same code for me (x86_64/gcc 13.2.0)

No need, you can add my RB. Thanks for the clarification!

Reviewed-by: Christian Schoenebeck <linux_oss@crudebyte.com>




  reply	other threads:[~2024-05-23 10:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-21 12:29 [PATCH] 9p: add missing locking around taking dentry fid list Dominique Martinet
2024-05-22 14:35 ` Christian Schoenebeck
2024-05-22 17:25   ` Dominique Martinet
2024-05-23  8:34     ` Christian Schoenebeck
2024-05-23  9:27       ` Dominique Martinet
2024-05-23 10:05         ` Christian Schoenebeck [this message]
2024-05-23 11:38           ` Dominique Martinet

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=2675095.dNBKFZOyUv@silver \
    --to=linux_oss@crudebyte.com \
    --cc=asmadeus@codewreck.org \
    --cc=ericvh@gmail.com \
    --cc=ericvh@kernel.org \
    --cc=groug@kaod.org \
    --cc=jianyong.wu@arm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lucho@ionkov.net \
    --cc=stable@vger.kernel.org \
    --cc=v9fs@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.