linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [VFS PATCH] constify more dcache.h inlined helpers.
@ 2017-08-02  3:24 NeilBrown
  2017-10-20  0:41 ` NeilBrown
  0 siblings, 1 reply; 5+ messages in thread
From: NeilBrown @ 2017-08-02  3:24 UTC (permalink / raw)
  To: Al Viro; +Cc: lkml

[-- Attachment #1: Type: text/plain, Size: 1176 bytes --]


Many of the inlines in dcache.h were changed to accept
const struct pointers in commit f0d3b3ded999 ("constify dcache.c
inlined helpers where possible").
This patch allows 'const' in a couple that were added since then.

Signed-off-by: NeilBrown <neilb@suse.com>
---
 include/linux/dcache.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/dcache.h b/include/linux/dcache.h
index aae1cdb76851..66ca42b1935b 100644
--- a/include/linux/dcache.h
+++ b/include/linux/dcache.h
@@ -358,7 +358,7 @@ static inline void dont_mount(struct dentry *dentry)
 
 extern void __d_lookup_done(struct dentry *);
 
-static inline int d_in_lookup(struct dentry *dentry)
+static inline int d_in_lookup(const struct dentry *dentry)
 {
 	return dentry->d_flags & DCACHE_PAR_LOOKUP;
 }
@@ -486,7 +486,7 @@ static inline bool d_really_is_positive(const struct dentry *dentry)
 	return dentry->d_inode != NULL;
 }
 
-static inline int simple_positive(struct dentry *dentry)
+static inline int simple_positive(const struct dentry *dentry)
 {
 	return d_really_is_positive(dentry) && !d_unhashed(dentry);
 }
-- 
2.14.0.rc0.dirty


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [VFS PATCH] constify more dcache.h inlined helpers.
  2017-08-02  3:24 [VFS PATCH] constify more dcache.h inlined helpers NeilBrown
@ 2017-10-20  0:41 ` NeilBrown
  2017-10-20  3:33   ` Al Viro
  0 siblings, 1 reply; 5+ messages in thread
From: NeilBrown @ 2017-10-20  0:41 UTC (permalink / raw)
  To: Al Viro; +Cc: lkml

[-- Attachment #1: Type: text/plain, Size: 1388 bytes --]

On Wed, Aug 02 2017, NeilBrown wrote:

> Many of the inlines in dcache.h were changed to accept
> const struct pointers in commit f0d3b3ded999 ("constify dcache.c
> inlined helpers where possible").
> This patch allows 'const' in a couple that were added since then.
>
> Signed-off-by: NeilBrown <neilb@suse.com>

Ping ... should I be sending this somewhere else?  Is there a problem
with it?

Thanks,
NeilBrown


> ---
>  include/linux/dcache.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/dcache.h b/include/linux/dcache.h
> index aae1cdb76851..66ca42b1935b 100644
> --- a/include/linux/dcache.h
> +++ b/include/linux/dcache.h
> @@ -358,7 +358,7 @@ static inline void dont_mount(struct dentry *dentry)
>  
>  extern void __d_lookup_done(struct dentry *);
>  
> -static inline int d_in_lookup(struct dentry *dentry)
> +static inline int d_in_lookup(const struct dentry *dentry)
>  {
>  	return dentry->d_flags & DCACHE_PAR_LOOKUP;
>  }
> @@ -486,7 +486,7 @@ static inline bool d_really_is_positive(const struct dentry *dentry)
>  	return dentry->d_inode != NULL;
>  }
>  
> -static inline int simple_positive(struct dentry *dentry)
> +static inline int simple_positive(const struct dentry *dentry)
>  {
>  	return d_really_is_positive(dentry) && !d_unhashed(dentry);
>  }
> -- 
> 2.14.0.rc0.dirty

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [VFS PATCH] constify more dcache.h inlined helpers.
  2017-10-20  0:41 ` NeilBrown
@ 2017-10-20  3:33   ` Al Viro
  2017-10-20  9:39     ` NeilBrown
  2017-12-18 23:15     ` NeilBrown
  0 siblings, 2 replies; 5+ messages in thread
From: Al Viro @ 2017-10-20  3:33 UTC (permalink / raw)
  To: NeilBrown; +Cc: lkml

On Fri, Oct 20, 2017 at 11:41:17AM +1100, NeilBrown wrote:
> On Wed, Aug 02 2017, NeilBrown wrote:
> 
> > Many of the inlines in dcache.h were changed to accept
> > const struct pointers in commit f0d3b3ded999 ("constify dcache.c
> > inlined helpers where possible").
> > This patch allows 'const' in a couple that were added since then.
> >
> > Signed-off-by: NeilBrown <neilb@suse.com>
> 
> Ping ... should I be sending this somewhere else?  Is there a problem
> with it?

Nothing, just slipped through the cracks; July and August had been
insane (move from nc.us to ma.us after well over a decade in one
apartment; 'nuff said...)

Applied.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [VFS PATCH] constify more dcache.h inlined helpers.
  2017-10-20  3:33   ` Al Viro
@ 2017-10-20  9:39     ` NeilBrown
  2017-12-18 23:15     ` NeilBrown
  1 sibling, 0 replies; 5+ messages in thread
From: NeilBrown @ 2017-10-20  9:39 UTC (permalink / raw)
  To: Al Viro; +Cc: lkml, Goldwyn Rodrigues

[-- Attachment #1: Type: text/plain, Size: 5517 bytes --]

On Fri, Oct 20 2017, Al Viro wrote:

> On Fri, Oct 20, 2017 at 11:41:17AM +1100, NeilBrown wrote:
>> On Wed, Aug 02 2017, NeilBrown wrote:
>> 
>> > Many of the inlines in dcache.h were changed to accept
>> > const struct pointers in commit f0d3b3ded999 ("constify dcache.c
>> > inlined helpers where possible").
>> > This patch allows 'const' in a couple that were added since then.
>> >
>> > Signed-off-by: NeilBrown <neilb@suse.com>
>> 
>> Ping ... should I be sending this somewhere else?  Is there a problem
>> with it?
>
> Nothing, just slipped through the cracks; July and August had been
> insane (move from nc.us to ma.us after well over a decade in one
> apartment; 'nuff said...)
>
> Applied.

Great, thanks!

Something else that might have slipped through the cracks
is the following.  There have been a few different patches for
this issue floating around including at
   https://patchwork.kernel.org/patch/9455345/
and
  https://patchwork.kernel.org/patch/9944661/
  
I think this approach is best, though adding that 'moving' arg to
___d_drop() isn't the most elegant thing I've ever done.

Thoughts?

Thanks,
NeilBrown


From: NeilBrown <neilb@suse.com>
Date: Fri, 8 Sep 2017 16:03:42 +1000
Subject: [PATCH] VFS: close race between getcwd() and d_move()

d_move() will call __d_drop() and then __d_rehash()
on the dentry being moved.  This creates a small window
when the dentry appears to be unhashed.  Many tests
of d_unhashed() are made under ->d_lock and so are safe
from racing with this window, but some aren't.
In particular, getcwd() calls d_unlinked() (which calls
d_unhashed()) without d_lock protection, so it can race.

This races has been seen in practice with lustre, which uses d_move() as
part of name lookup.  See:
   https://jira.hpdd.intel.com/browse/LU-9735
It could race with a regular rename(), and result in ENOENT instead
of either the 'before' or 'after' name.

We could fix this race by taking d_lock an rechecking when
d_unhashed() reports true.  Alternately when can remove the window,
which is the approach this patch takes.

When __d_drop and __d_rehash are used to move a dentry, an extra
flag is passed which causes d_hash.pprev to not be cleared, and
to not be tested.

Signed-off-by: NeilBrown <neilb@suse.com>
---
 fs/dcache.c | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/fs/dcache.c b/fs/dcache.c
index f90141387f01..3d1f14c6c306 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -469,8 +469,11 @@ static void dentry_lru_add(struct dentry *dentry)
  * reason (NFS timeouts or autofs deletes).
  *
  * __d_drop requires dentry->d_lock.
+ * ___d_drop takes an extra @moving argument.
+ * If true, d_hash.pprev is not cleared, so there is no transient d_unhashed()
+ * state.
  */
-void __d_drop(struct dentry *dentry)
+static void inline ___d_drop(struct dentry *dentry, bool moving)
 {
 	if (!d_unhashed(dentry)) {
 		struct hlist_bl_head *b;
@@ -486,12 +489,18 @@ void __d_drop(struct dentry *dentry)
 
 		hlist_bl_lock(b);
 		__hlist_bl_del(&dentry->d_hash);
-		dentry->d_hash.pprev = NULL;
+		if (likely(!moving))
+			dentry->d_hash.pprev = NULL;
 		hlist_bl_unlock(b);
 		/* After this call, in-progress rcu-walk path lookup will fail. */
 		write_seqcount_invalidate(&dentry->d_seq);
 	}
 }
+
+void __d_drop(struct dentry *dentry)
+{
+	___d_drop(dentry, false);
+}
 EXPORT_SYMBOL(__d_drop);
 
 void d_drop(struct dentry *dentry)
@@ -2378,10 +2387,10 @@ void d_delete(struct dentry * dentry)
 }
 EXPORT_SYMBOL(d_delete);
 
-static void __d_rehash(struct dentry *entry)
+static void __d_rehash(struct dentry *entry, bool moving)
 {
 	struct hlist_bl_head *b = d_hash(entry->d_name.hash);
-	BUG_ON(!d_unhashed(entry));
+	BUG_ON(!moving && !d_unhashed(entry));
 	hlist_bl_lock(b);
 	hlist_bl_add_head_rcu(&entry->d_hash, b);
 	hlist_bl_unlock(b);
@@ -2397,7 +2406,7 @@ static void __d_rehash(struct dentry *entry)
 void d_rehash(struct dentry * entry)
 {
 	spin_lock(&entry->d_lock);
-	__d_rehash(entry);
+	__d_rehash(entry, false);
 	spin_unlock(&entry->d_lock);
 }
 EXPORT_SYMBOL(d_rehash);
@@ -2571,7 +2580,7 @@ static inline void __d_add(struct dentry *dentry, struct inode *inode)
 		raw_write_seqcount_end(&dentry->d_seq);
 		fsnotify_update_flags(dentry);
 	}
-	__d_rehash(dentry);
+	__d_rehash(dentry, false);
 	if (dir)
 		end_dir_add(dir, n);
 	spin_unlock(&dentry->d_lock);
@@ -2633,7 +2642,7 @@ struct dentry *d_exact_alias(struct dentry *entry, struct inode *inode)
 			alias = NULL;
 		} else {
 			__dget_dlock(alias);
-			__d_rehash(alias);
+			__d_rehash(alias, false);
 			spin_unlock(&alias->d_lock);
 		}
 		spin_unlock(&inode->i_lock);
@@ -2819,8 +2828,8 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
 
 	/* unhash both */
 	/* __d_drop does write_seqcount_barrier, but they're OK to nest. */
-	__d_drop(dentry);
-	__d_drop(target);
+	___d_drop(dentry, true);
+	___d_drop(target, exchange);
 
 	/* Switch the names.. */
 	if (exchange)
@@ -2829,9 +2838,9 @@ static void __d_move(struct dentry *dentry, struct dentry *target,
 		copy_name(dentry, target);
 
 	/* rehash in new place(s) */
-	__d_rehash(dentry);
+	__d_rehash(dentry, true);
 	if (exchange)
-		__d_rehash(target);
+		__d_rehash(target, true);
 
 	/* ... and switch them in the tree */
 	if (IS_ROOT(dentry)) {
-- 
2.14.0.rc0.dirty


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [VFS PATCH] constify more dcache.h inlined helpers.
  2017-10-20  3:33   ` Al Viro
  2017-10-20  9:39     ` NeilBrown
@ 2017-12-18 23:15     ` NeilBrown
  1 sibling, 0 replies; 5+ messages in thread
From: NeilBrown @ 2017-12-18 23:15 UTC (permalink / raw)
  To: Al Viro; +Cc: lkml

[-- Attachment #1: Type: text/plain, Size: 1083 bytes --]

On Fri, Oct 20 2017, Al Viro wrote:

> On Fri, Oct 20, 2017 at 11:41:17AM +1100, NeilBrown wrote:
>> On Wed, Aug 02 2017, NeilBrown wrote:
>> 
>> > Many of the inlines in dcache.h were changed to accept
>> > const struct pointers in commit f0d3b3ded999 ("constify dcache.c
>> > inlined helpers where possible").
>> > This patch allows 'const' in a couple that were added since then.
>> >
>> > Signed-off-by: NeilBrown <neilb@suse.com>
>> 
>> Ping ... should I be sending this somewhere else?  Is there a problem
>> with it?
>
> Nothing, just slipped through the cracks; July and August had been
> insane (move from nc.us to ma.us after well over a decade in one
> apartment; 'nuff said...)
>
> Applied.

Hi Al,
 I don't see this in linux-next, but it seems to be pulling from
    git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6.git
 which doesn't exist any more.

 I don't see it in the for-next branch of
   git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
 either, or in for-linus.

 Where should I be looking?

Thanks,
NeilBrown

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-12-18 23:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-02  3:24 [VFS PATCH] constify more dcache.h inlined helpers NeilBrown
2017-10-20  0:41 ` NeilBrown
2017-10-20  3:33   ` Al Viro
2017-10-20  9:39     ` NeilBrown
2017-12-18 23:15     ` NeilBrown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).