From c31b26c462d6028efc8d079de942ee89cd5f3a48 Mon Sep 17 00:00:00 2001 From: "Eric W. Biederman" Date: Sat, 12 Apr 2014 12:49:10 -0700 Subject: [PATCH] vfs: Move autoclose of BSD accounting into a work queue The autoclose of BSD accounting writes a record to the BSD accounting file. When mntput is called from moderaly deep within the stack the (3KiB or so) generating I/O can be problemenatic as some I/O paths require nearly 5KiB of stack on their own. Avoid the possibility of stack overflow by moving the close of the BSD accounting file into a work queue. Signed-off-by: "Eric W. Biederman" --- kernel/acct.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/kernel/acct.c b/kernel/acct.c index 8d6e145138bb..1853dd4a1d01 100644 --- a/kernel/acct.c +++ b/kernel/acct.c @@ -93,6 +93,7 @@ struct bsd_acct_struct { static DEFINE_SPINLOCK(acct_lock); static LIST_HEAD(acct_list); +static LIST_HEAD(acct_close_list); /* * Check the amount of free space and suspend/resume accordingly. @@ -280,6 +281,20 @@ SYSCALL_DEFINE1(acct, const char __user *, name) return error; } +static void acct_close_mnts(struct work_struct *unused) +{ + struct bsd_acct_struct *acct; + + spin_lock(&acct_lock); +restart: + list_for_each_entry(acct, &acct_close_list, list) { + acct_file_reopen(acct, NULL, NULL); + goto restart; + } + spin_unlock(&acct_lock); +} +static DECLARE_WORK(acct_close_work, acct_close_mnts); + /** * acct_auto_close - turn off a filesystem's accounting if it is on * @m: vfsmount being shut down @@ -289,15 +304,15 @@ SYSCALL_DEFINE1(acct, const char __user *, name) */ void acct_auto_close_mnt(struct vfsmount *m) { - struct bsd_acct_struct *acct; + struct bsd_acct_struct *acct, *tmp; spin_lock(&acct_lock); -restart: - list_for_each_entry(acct, &acct_list, list) + list_for_each_entry_safe(acct, tmp, &acct_list, list) { if (acct->file && acct->file->f_path.mnt == m) { - acct_file_reopen(acct, NULL, NULL); - goto restart; + list_move_tail(&acct->list, &acct_close_list); + schedule_work(&acct_close_work); } + } spin_unlock(&acct_lock); } -- 2.39.5