* [PATCH AUTOSEL 5.4 24/25] d_add_ci(): make sure we don't miss d_lookup_done()
[not found] <20220811160826.1541971-1-sashal@kernel.org>
@ 2022-08-11 16:08 ` Sasha Levin
2022-08-11 16:08 ` [PATCH AUTOSEL 5.4 25/25] fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT Sasha Levin
1 sibling, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2022-08-11 16:08 UTC (permalink / raw)
To: linux-kernel, stable; +Cc: Al Viro, Sasha Levin, linux-fsdevel
From: Al Viro <viro@zeniv.linux.org.uk>
[ Upstream commit 40a3cb0d2314a41975aa385a74643878454f6eac ]
All callers of d_alloc_parallel() must make sure that resulting
in-lookup dentry (if any) will encounter __d_lookup_done() before
the final dput(). d_add_ci() might end up creating in-lookup
dentries; they are fed to d_splice_alias(), which will normally
make sure they meet __d_lookup_done(). However, it is possible
to end up with d_splice_alias() failing with ERR_PTR(-ELOOP)
without having done so. It takes a corrupted ntfs or case-insensitive
xfs image, but neither should end up with memory corruption...
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/dcache.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/dcache.c b/fs/dcache.c
index b2a7f1765f0b..64b8f737af1b 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2160,6 +2160,7 @@ struct dentry *d_add_ci(struct dentry *dentry, struct inode *inode,
}
res = d_splice_alias(inode, found);
if (res) {
+ d_lookup_done(found);
dput(found);
return res;
}
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH AUTOSEL 5.4 25/25] fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT
[not found] <20220811160826.1541971-1-sashal@kernel.org>
2022-08-11 16:08 ` [PATCH AUTOSEL 5.4 24/25] d_add_ci(): make sure we don't miss d_lookup_done() Sasha Levin
@ 2022-08-11 16:08 ` Sasha Levin
2022-08-12 8:39 ` Sebastian Andrzej Siewior
1 sibling, 1 reply; 3+ messages in thread
From: Sasha Levin @ 2022-08-11 16:08 UTC (permalink / raw)
To: linux-kernel, stable
Cc: Sebastian Andrzej Siewior, Oleg.Karfich, Thomas Gleixner,
Al Viro, Sasha Levin, linux-fsdevel
From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
[ Upstream commit cf634d540a29018e8d69ab1befb7e08182bc6594 ]
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: Oleg.Karfich@wago.com
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Link: https://lkml.kernel.org/r/20220613140712.77932-2-bigeasy@linutronix.de
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/dcache.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index 64b8f737af1b..dc8092e2053a 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -2484,7 +2484,15 @@ EXPORT_SYMBOL(d_rehash);
static inline unsigned start_dir_add(struct inode *dir)
{
-
+ /*
+ * The caller holds a spinlock (dentry::d_lock). On !PREEMPT_RT
+ * kernels spin_lock() implicitly disables preemption, but not on
+ * PREEMPT_RT. So for RT it has to be done explicitly to protect
+ * the sequence count write side critical section against a reader
+ * or another writer preempting, which would result in a live lock.
+ */
+ if (IS_ENABLED(CONFIG_PREEMPT_RT))
+ preempt_disable();
for (;;) {
unsigned n = dir->i_dir_seq;
if (!(n & 1) && cmpxchg(&dir->i_dir_seq, n, n + 1) == n)
@@ -2496,6 +2504,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);
+ if (IS_ENABLED(CONFIG_PREEMPT_RT))
+ preempt_enable();
}
static void d_wait_lookup(struct dentry *dentry)
--
2.35.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH AUTOSEL 5.4 25/25] fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT
2022-08-11 16:08 ` [PATCH AUTOSEL 5.4 25/25] fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT Sasha Levin
@ 2022-08-12 8:39 ` Sebastian Andrzej Siewior
0 siblings, 0 replies; 3+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-08-12 8:39 UTC (permalink / raw)
To: Sasha Levin
Cc: linux-kernel, stable, Oleg.Karfich, Thomas Gleixner, Al Viro,
linux-fsdevel
On 2022-08-11 12:08:20 [-0400], Sasha Levin wrote:
> From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
>
> [ Upstream commit cf634d540a29018e8d69ab1befb7e08182bc6594 ]
Could please drop that one from the stable series? It does not effect
!PREEMPT_RT / mainline. Linus was not to happy about the ifdef
PREEMPT_RT here. This one is about to be reworked…
Sebastian
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-08-12 8:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20220811160826.1541971-1-sashal@kernel.org>
2022-08-11 16:08 ` [PATCH AUTOSEL 5.4 24/25] d_add_ci(): make sure we don't miss d_lookup_done() Sasha Levin
2022-08-11 16:08 ` [PATCH AUTOSEL 5.4 25/25] fs/dcache: Disable preemption on i_dir_seq write side on PREEMPT_RT Sasha Levin
2022-08-12 8:39 ` Sebastian Andrzej Siewior
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).