History

proc: Use a list of inodes to flush from proc

Rework the flushing of proc to use a list of directory inodes that need to be flushed. The list is kept on struct pid not on struct task_struct, as there is a fixed connection between proc inodes and pids but at least for the case of de_thread the pid of a task_struct changes. This removes the dependency on proc_mnt which allows for different mounts of proc having different mount options even in the same pid namespace and this allows for the removal of proc_mnt which will trivially the first mount of proc to honor it's mount options. This flushing remains an optimization. The functions pid_delete_dentry and pid_revalidate ensure that ordinary dcache management will not attempt to use dentries past the point their respective task has died. When unused the shrinker will eventually be able to remove these dentries. There is a case in de_thread where proc_flush_pid can be called early for a given pid. Which winds up being safe (if suboptimal) as this is just an optiimization. Only pid directories are put on the list as the other per pid files are children of those directories and d_invalidate on the directory will get them as well. So that the pid can be used during flushing it's reference count is taken in release_task and dropped in proc_flush_pid. Further the call of proc_flush_pid is moved after the tasklist_lock is released in release_task so that it is certain that the pid has already been unhashed when flushing it taking place. This removes a small race where a dentry could recreated. As struct pid is supposed to be small and I need a per pid lock I reuse the only lock that currently exists in struct pid the the wait_pidfd.lock. The net result is that this adds all of this functionality with just a little extra list management overhead and a single extra pointer in struct pid. v2: Initialize pid->inodes. I somehow failed to get that initialization into the initial version of the patch. A boot failure was reported by "kernel test robot <lkp@intel.com>", and failure to initialize that pid->inodes matches all of the reported symptoms.

Eric W. Biederman committed 6 years ago

Commit 7bc3e6e1 parent 71448017 files · +45 −79Browse files

Showing the changes to kernel (2 of 7 files). Show all

Unified · Split

2 files
  1. kernel/exit.c +3 −1
  2. kernel/pid.c +1 −0
kernel/exit.c+3−1
@@ -191,6 +191,7 @@ void put_task_struct_rcu_user(struct task_struct *task) · 190 unmodified lines
191191 void release_task(struct task_struct *p)
192192 {
193193 struct task_struct *leader;
194+ struct pid *thread_pid;
194195 int zap_leader;
195196 repeat:
196197 /* don't need to get the RCU readlock here - the process is dead and
@@ -199,11 +200,11 @@ repeat: · 2 unmodified lines
199200 atomic_dec(&__task_cred(p)->user->processes);
200201 rcu_read_unlock();
201202
202− proc_flush_task(p);
203203 cgroup_release(p);
204204
205205 write_lock_irq(&tasklist_lock);
206206 ptrace_release_task(p);
207+ thread_pid = get_pid(p->thread_pid);
207208 __exit_signal(p);
208209
209210 /*
@@ -226,6 +227,7 @@ repeat: · 16 unmodified lines
226227 }
227228
228229 write_unlock_irq(&tasklist_lock);
230+ proc_flush_pid(thread_pid);
229231 release_thread(p);
230232 put_task_struct_rcu_user(p);
231233
kernel/pid.c+1−0
@@ -258,6 +258,7 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid, · 257 unmodified lines
258258 INIT_HLIST_HEAD(&pid->tasks[type]);
259259
260260 init_waitqueue_head(&pid->wait_pidfd);
261+ INIT_HLIST_HEAD(&pid->inodes);
261262
262263 upid = pid->numbers + ns->level;
263264 spin_lock_irq(&pidmap_lock);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t