[RHEL7,COMMIT] kernfs: keep kernfs node alive for __kernfs_remove()

Submitted by Konstantin Khorenko on April 16, 2019, 3:59 p.m.

Details

Message ID 201904161559.x3GFxC4E014731@finist-ce7.sw.ru
State New
Series "kernfs: keep kernfs node alive for __kernfs_remove()"
Headers show

Commit Message

Konstantin Khorenko April 16, 2019, 3:59 p.m.
The commit is pushed to "branch-rh7-3.10.0-957.10.1.vz7.94.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-957.10.1.vz7.94.15
------>
commit 8f2bfcd1dd05a318c78c6b742751241a847c91ba
Author: Konstantin Khorenko <khorenko@virtuozzo.com>
Date:   Tue Apr 16 15:02:31 2019 +0300

    kernfs: keep kernfs node alive for __kernfs_remove()
    
    __kernfs_remove() which is called under kernfs_mutex,
    assumes nobody kills kernfs node whie it's working on it
    and "get"s current kernfs node for that.
    
    But we hit a warning in kernfs_get(): kn->counter == 0 already:
      ------------[ cut here ]------------
      WARNING: CPU: 2 PID: 63923 at fs/kernfs/dir.c:377 kernfs_get+0x2f/0x40
      ...
      Call Trace:
       [<ffffffffa7f92e67>] dump_stack+0x19/0x1b
       [<ffffffffa78987b8>] __warn+0xd8/0x100
       [<ffffffffa78988fd>] warn_slowpath_null+0x1d/0x20
       [<ffffffffa7aecaff>] kernfs_get+0x2f/0x40
       [<ffffffffa7aed233>] __kernfs_remove+0x113/0x260
       [<ffffffffa7aee201>] kernfs_remove+0x21/0x30
       [<ffffffffa7af1010>] sysfs_remove_dir+0x50/0x80
       [<ffffffffa7b9fb38>] kobject_del+0x18/0x50
       [<ffffffffa7a38a4d>] sysfs_slab_remove+0x3d/0x50
       [<ffffffffa79f1e6b>] do_kmem_cache_release+0x3b/0x70
       [<ffffffffa79f2aa1>] memcg_destroy_kmem_caches+0xb1/0xf0
       [<ffffffffa7a4ed5c>] mem_cgroup_css_free+0x4c/0x280
       [<ffffffffa79377fc>] cgroup_free_fn+0x4c/0x120
       [<ffffffffa78bc222>] process_one_work+0x182/0x440
       [<ffffffffa78bd3d6>] worker_thread+0x126/0x3c0
       [<ffffffffa78c4441>] kthread+0xd1/0xe0
    
    This could be for example because of kernfs_notify_workfn() which
    does kernfs_put(kn) out of kernfs_mutex held section,
    so move kernfs_put(kn) under the mutex.
    
    https://jira.sw.ru/browse/PSBM-93611
    
    Signed-off-by: Konstantin Khorenko <khorenko@virtuozzo.com>
---
 fs/kernfs/file.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index b120e85aa7b9..51af7e2c410a 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -860,8 +860,8 @@  static void kernfs_notify_workfn(struct work_struct *work)
 		iput(inode);
 	}
 
-	mutex_unlock(&kernfs_mutex);
 	kernfs_put(kn);
+	mutex_unlock(&kernfs_mutex);
 	goto repeat;
 }