]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
proc: smaller readlock section in readdir("/proc")
authorAlexey Dobriyan <adobriyan@gmail.com>
Wed, 22 Aug 2018 04:54:23 +0000 (21:54 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 22 Aug 2018 17:52:45 +0000 (10:52 -0700)
Readdir context is thread local, so ->pos is thread local,
move it out of readlock.

Link: http://lkml.kernel.org/r/20180627195339.GD18113@avx2
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/proc/generic.c

index bb1c1625b158d03f5c8685f55e370267e1cc76fb..8ae109429a883939ed0241c1e122db7ba857ac1a 100644 (file)
@@ -286,9 +286,9 @@ int proc_readdir_de(struct file *file, struct dir_context *ctx,
        if (!dir_emit_dots(file, ctx))
                return 0;
 
+       i = ctx->pos - 2;
        read_lock(&proc_subdir_lock);
        de = pde_subdir_first(de);
-       i = ctx->pos - 2;
        for (;;) {
                if (!de) {
                        read_unlock(&proc_subdir_lock);
@@ -309,8 +309,8 @@ int proc_readdir_de(struct file *file, struct dir_context *ctx,
                        pde_put(de);
                        return 0;
                }
-               read_lock(&proc_subdir_lock);
                ctx->pos++;
+               read_lock(&proc_subdir_lock);
                next = pde_subdir_next(de);
                pde_put(de);
                de = next;