Skip to content

Commit dc92027

Browse files
ebiggerssmfrench
authored andcommitted
cifs: clear PF_MEMALLOC before exiting demultiplex thread
Leaving PF_MEMALLOC set when exiting a kthread causes it to remain set during do_exit(). That can confuse things. For example, if BSD process accounting is enabled and the accounting file has FS_SYNC_FL set and is located on an ext4 filesystem without a journal, then do_exit() can end up calling ext4_write_inode(). That triggers the WARN_ON_ONCE(current->flags & PF_MEMALLOC) there, as it assumes (appropriately) that inodes aren't written when allocating memory. This was originally reported for another kernel thread, xfsaild() [1]. cifs_demultiplex_thread() also exits with PF_MEMALLOC set, so it's potentially subject to this same class of issue -- though I haven't been able to reproduce the WARN_ON_ONCE() via CIFS, since unlike xfsaild(), cifs_demultiplex_thread() is sent SIGKILL before exiting, and that interrupts the write to the BSD process accounting file. Either way, leaving PF_MEMALLOC set is potentially problematic. Let's clean this up by properly saving and restoring PF_MEMALLOC. [1] https://lore.kernel.org/r/[email protected] Signed-off-by: Eric Biggers <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 266b9fe commit dc92027

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/cifs/connect.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/fs.h>
2222
#include <linux/net.h>
2323
#include <linux/string.h>
24+
#include <linux/sched/mm.h>
2425
#include <linux/sched/signal.h>
2526
#include <linux/list.h>
2627
#include <linux/wait.h>
@@ -1114,8 +1115,9 @@ cifs_demultiplex_thread(void *p)
11141115
struct task_struct *task_to_wake = NULL;
11151116
struct mid_q_entry *mids[MAX_COMPOUND];
11161117
char *bufs[MAX_COMPOUND];
1118+
unsigned int noreclaim_flag;
11171119

1118-
current->flags |= PF_MEMALLOC;
1120+
noreclaim_flag = memalloc_noreclaim_save();
11191121
cifs_dbg(FYI, "Demultiplex PID: %d\n", task_pid_nr(current));
11201122

11211123
length = atomic_inc_return(&tcpSesAllocCount);
@@ -1269,6 +1271,7 @@ cifs_demultiplex_thread(void *p)
12691271
set_current_state(TASK_RUNNING);
12701272
}
12711273

1274+
memalloc_noreclaim_restore(noreclaim_flag);
12721275
module_put_and_exit(0);
12731276
}
12741277

0 commit comments

Comments
 (0)