diff options
author | Sebastian Andrzej Siewior <bigeasy@linutronix.de> | 2017-10-20 11:29:53 +0200 |
---|---|---|
committer | Clark Williams <williams@redhat.com> | 2020-11-06 15:44:02 -0600 |
commit | bca91a1dfd4caf828d64fc6694cb9469ab7552d0 (patch) | |
tree | 18ed8377f10d16faabe738723392f51c97fc06b1 | |
parent | 288123a371109a16bd1a3c3e9a522f89125d223d (diff) | |
download | linux-rt-bca91a1dfd4caf828d64fc6694cb9469ab7552d0.tar.gz |
fs/dcache: disable preemption on i_dir_seq's write side
i_dir_seq is an opencoded seqcounter. Based on the code it looks like we
could have two writers in parallel despite the fact that the d_lock is
held. The problem is that during the write process on RT the preemption
is still enabled and if this process is interrupted by a reader with RT
priority then we lock up.
To avoid that lock up I am disabling the preemption during the update.
The rename of i_dir_seq is here to ensure to catch new write sides in
future.
Cc: stable-rt@vger.kernel.org
Reported-by: Oleg.Karfich@wago.com
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
-rw-r--r-- | fs/dcache.c | 12 | ||||
-rw-r--r-- | fs/inode.c | 2 | ||||
-rw-r--r-- | include/linux/fs.h | 2 |
3 files changed, 9 insertions, 7 deletions
diff --git a/fs/dcache.c b/fs/dcache.c index 24f154017a4c..ff918e257e87 100644 --- a/fs/dcache.c +++ b/fs/dcache.c @@ -2437,9 +2437,10 @@ EXPORT_SYMBOL(d_rehash); static inline unsigned start_dir_add(struct inode *dir) { + preempt_disable_rt(); for (;;) { - unsigned n = dir->i_dir_seq; - if (!(n & 1) && cmpxchg(&dir->i_dir_seq, n, n + 1) == n) + unsigned n = dir->__i_dir_seq; + if (!(n & 1) && cmpxchg(&dir->__i_dir_seq, n, n + 1) == n) return n; cpu_relax(); } @@ -2447,7 +2448,8 @@ static inline unsigned start_dir_add(struct inode *dir) static inline void end_dir_add(struct inode *dir, unsigned n) { - smp_store_release(&dir->i_dir_seq, n + 2); + smp_store_release(&dir->__i_dir_seq, n + 2); + preempt_enable_rt(); } static void d_wait_lookup(struct dentry *dentry) @@ -2483,7 +2485,7 @@ struct dentry *d_alloc_parallel(struct dentry *parent, retry: rcu_read_lock(); - seq = smp_load_acquire(&parent->d_inode->i_dir_seq); + seq = smp_load_acquire(&parent->d_inode->__i_dir_seq); r_seq = read_seqbegin(&rename_lock); dentry = __d_lookup_rcu(parent, name, &d_seq); if (unlikely(dentry)) { @@ -2511,7 +2513,7 @@ retry: } hlist_bl_lock(b); - if (unlikely(READ_ONCE(parent->d_inode->i_dir_seq) != seq)) { + if (unlikely(READ_ONCE(parent->d_inode->__i_dir_seq) != seq)) { hlist_bl_unlock(b); rcu_read_unlock(); goto retry; diff --git a/fs/inode.c b/fs/inode.c index 0d993ce7a940..394cfe9af58a 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -154,7 +154,7 @@ int inode_init_always(struct super_block *sb, struct inode *inode) inode->i_bdev = NULL; inode->i_cdev = NULL; inode->i_link = NULL; - inode->i_dir_seq = 0; + inode->__i_dir_seq = 0; inode->i_rdev = 0; inode->dirtied_when = 0; diff --git a/include/linux/fs.h b/include/linux/fs.h index b8d65e0ab934..b49278a3e7c4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -695,7 +695,7 @@ struct inode { struct block_device *i_bdev; struct cdev *i_cdev; char *i_link; - unsigned i_dir_seq; + unsigned __i_dir_seq; }; __u32 i_generation; |