* [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock
@ 2022-03-25 19:00 Niels Dossche
2022-03-26 6:44 ` Christoph Hellwig
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Niels Dossche @ 2022-03-25 19:00 UTC (permalink / raw)
To: linux-fsdevel; +Cc: Alexander Viro, Niels Dossche, Christoph Hellwig
Currently, there is a fallback with a WARN that uses down_read_trylock
as a safety measure for when there is no lock taken. The current
callsites expect a write lock to be taken. Moreover, the s_root field
is written to, which is not allowed under a read lock.
This code safety fallback should not be executed unless there is an
issue somewhere else.
Using a lockdep assertion better communicates the intent of the code,
and gets rid of the currently slightly wrong fallback solution.
Note:
I am currently working on a static analyser to detect missing locks
using type-based static analysis as my master's thesis
in order to obtain my master's degree.
If you would like to have more details, please let me know.
This was a reported case. I manually verified the report by looking
at the code, so that I do not send wrong information or patches.
After concluding that this seems to be a true positive, I created
this patch. I have both compile-tested this patch and runtime-tested
this patch on x86_64. The effect on a running system could be a
potential race condition in exceptional cases.
This issue was found on Linux v5.17.
Fixes: c636ebdb186bf ("VFS: Destroy the dentries contributed by a superblock on unmounting")
Suggested-by: Christoph Hellwig <hch@infradead.org>
Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
---
fs/dcache.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/dcache.c b/fs/dcache.c
index c84269c6e8bf..0142f15340e5 100644
--- a/fs/dcache.c
+++ b/fs/dcache.c
@@ -1692,7 +1692,7 @@ void shrink_dcache_for_umount(struct super_block *sb)
{
struct dentry *dentry;
- WARN(down_read_trylock(&sb->s_umount), "s_umount should've been locked");
+ lockdep_assert_held_write(&sb->s_umount);
dentry = sb->s_root;
sb->s_root = NULL;
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock
2022-03-25 19:00 [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock Niels Dossche
@ 2022-03-26 6:44 ` Christoph Hellwig
2022-03-29 15:24 ` Jeff Layton
2022-03-30 10:32 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2022-03-26 6:44 UTC (permalink / raw)
To: Niels Dossche; +Cc: linux-fsdevel, Alexander Viro, Christoph Hellwig
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock
2022-03-25 19:00 [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock Niels Dossche
2022-03-26 6:44 ` Christoph Hellwig
@ 2022-03-29 15:24 ` Jeff Layton
2022-03-30 10:32 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Jeff Layton @ 2022-03-29 15:24 UTC (permalink / raw)
To: Niels Dossche, linux-fsdevel; +Cc: Alexander Viro, Christoph Hellwig
On Fri, 2022-03-25 at 20:00 +0100, Niels Dossche wrote:
> Currently, there is a fallback with a WARN that uses down_read_trylock
> as a safety measure for when there is no lock taken. The current
> callsites expect a write lock to be taken. Moreover, the s_root field
> is written to, which is not allowed under a read lock.
> This code safety fallback should not be executed unless there is an
> issue somewhere else.
> Using a lockdep assertion better communicates the intent of the code,
> and gets rid of the currently slightly wrong fallback solution.
>
> Note:
> I am currently working on a static analyser to detect missing locks
> using type-based static analysis as my master's thesis
> in order to obtain my master's degree.
> If you would like to have more details, please let me know.
> This was a reported case. I manually verified the report by looking
> at the code, so that I do not send wrong information or patches.
> After concluding that this seems to be a true positive, I created
> this patch. I have both compile-tested this patch and runtime-tested
> this patch on x86_64. The effect on a running system could be a
> potential race condition in exceptional cases.
> This issue was found on Linux v5.17.
>
> Fixes: c636ebdb186bf ("VFS: Destroy the dentries contributed by a superblock on unmounting")
> Suggested-by: Christoph Hellwig <hch@infradead.org>
> Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
> ---
> fs/dcache.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/dcache.c b/fs/dcache.c
> index c84269c6e8bf..0142f15340e5 100644
> --- a/fs/dcache.c
> +++ b/fs/dcache.c
> @@ -1692,7 +1692,7 @@ void shrink_dcache_for_umount(struct super_block *sb)
> {
> struct dentry *dentry;
>
> - WARN(down_read_trylock(&sb->s_umount), "s_umount should've been locked");
> + lockdep_assert_held_write(&sb->s_umount);
>
> dentry = sb->s_root;
> sb->s_root = NULL;
Much nicer.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock
2022-03-25 19:00 [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock Niels Dossche
2022-03-26 6:44 ` Christoph Hellwig
2022-03-29 15:24 ` Jeff Layton
@ 2022-03-30 10:32 ` Christian Brauner
2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2022-03-30 10:32 UTC (permalink / raw)
To: Niels Dossche; +Cc: linux-fsdevel, Alexander Viro, Christoph Hellwig
On Fri, Mar 25, 2022 at 08:00:02PM +0100, Niels Dossche wrote:
> Currently, there is a fallback with a WARN that uses down_read_trylock
> as a safety measure for when there is no lock taken. The current
> callsites expect a write lock to be taken. Moreover, the s_root field
> is written to, which is not allowed under a read lock.
> This code safety fallback should not be executed unless there is an
> issue somewhere else.
> Using a lockdep assertion better communicates the intent of the code,
> and gets rid of the currently slightly wrong fallback solution.
>
> Note:
> I am currently working on a static analyser to detect missing locks
> using type-based static analysis as my master's thesis
> in order to obtain my master's degree.
> If you would like to have more details, please let me know.
> This was a reported case. I manually verified the report by looking
> at the code, so that I do not send wrong information or patches.
> After concluding that this seems to be a true positive, I created
> this patch. I have both compile-tested this patch and runtime-tested
> this patch on x86_64. The effect on a running system could be a
> potential race condition in exceptional cases.
> This issue was found on Linux v5.17.
>
> Fixes: c636ebdb186bf ("VFS: Destroy the dentries contributed by a superblock on unmounting")
> Suggested-by: Christoph Hellwig <hch@infradead.org>
> Signed-off-by: Niels Dossche <dossche.niels@gmail.com>
> ---
Reviewed-by: Christian Brauner (Microsoft) <brauner@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-30 10:33 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-25 19:00 [PATCH] fs/dcache: use lockdep assertion instead of warn try_lock Niels Dossche
2022-03-26 6:44 ` Christoph Hellwig
2022-03-29 15:24 ` Jeff Layton
2022-03-30 10:32 ` Christian Brauner
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.