Skip to content

Commit cf634d5

Browse files
Sebastian Andrzej SiewiorAl Viro
authored andcommitted
fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT
i_dir_seq is a sequence counter with a lock which is represented by the lowest bit. The writer atomically updates the counter which ensures that it can be modified by only one writer at a time. This requires preemption to be disabled across the write side critical section. On !PREEMPT_RT kernels this is implicit by the caller acquiring dentry::lock. On PREEMPT_RT kernels spin_lock() does not disable preemption which means that a preempting writer or reader would live lock. It's therefore required to disable preemption explicitly. An alternative solution would be to replace i_dir_seq with a seqlock_t for PREEMPT_RT, but that comes with its own set of problems due to arbitrary lock nesting. A pure sequence count with an associated spinlock is not possible because the locks held by the caller are not necessarily related. As the critical section is small, disabling preemption is a sensible solution. Reported-by: [email protected] Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Al Viro <[email protected]>
1 parent 40a3cb0 commit cf634d5

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

fs/dcache.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2564,7 +2564,15 @@ EXPORT_SYMBOL(d_rehash);
25642564

25652565
static inline unsigned start_dir_add(struct inode *dir)
25662566
{
2567-
2567+
/*
2568+
* The caller holds a spinlock (dentry::d_lock). On !PREEMPT_RT
2569+
* kernels spin_lock() implicitly disables preemption, but not on
2570+
* PREEMPT_RT. So for RT it has to be done explicitly to protect
2571+
* the sequence count write side critical section against a reader
2572+
* or another writer preempting, which would result in a live lock.
2573+
*/
2574+
if (IS_ENABLED(CONFIG_PREEMPT_RT))
2575+
preempt_disable();
25682576
for (;;) {
25692577
unsigned n = dir->i_dir_seq;
25702578
if (!(n & 1) && cmpxchg(&dir->i_dir_seq, n, n + 1) == n)
@@ -2576,6 +2584,8 @@ static inline unsigned start_dir_add(struct inode *dir)
25762584
static inline void end_dir_add(struct inode *dir, unsigned n)
25772585
{
25782586
smp_store_release(&dir->i_dir_seq, n + 2);
2587+
if (IS_ENABLED(CONFIG_PREEMPT_RT))
2588+
preempt_enable();
25792589
}
25802590

25812591
static void d_wait_lookup(struct dentry *dentry)

0 commit comments

Comments
 (0)