hc
2024-10-12 a5969cabbb4660eab42b6ef0412cbbd1200cf14d
kernel/fs/proc/base.c
....@@ -96,7 +96,6 @@
9696 #include <linux/posix-timers.h>
9797 #include <linux/time_namespace.h>
9898 #include <linux/resctrl.h>
99
-#include <linux/swait.h>
10099 #include <linux/cpufreq_times.h>
101100 #include <trace/events/oom.h>
102101 #include "internal.h"
....@@ -1883,7 +1882,7 @@
18831882 put_pid(pid);
18841883 }
18851884
1886
-struct inode *proc_pid_make_inode(struct super_block * sb,
1885
+struct inode *proc_pid_make_inode(struct super_block *sb,
18871886 struct task_struct *task, umode_t mode)
18881887 {
18891888 struct inode * inode;
....@@ -1912,11 +1911,6 @@
19121911
19131912 /* Let the pid remember us for quick removal */
19141913 ei->pid = pid;
1915
- if (S_ISDIR(mode)) {
1916
- spin_lock(&pid->lock);
1917
- hlist_add_head_rcu(&ei->sibling_inodes, &pid->inodes);
1918
- spin_unlock(&pid->lock);
1919
- }
19201914
19211915 task_dump_owner(task, 0, &inode->i_uid, &inode->i_gid);
19221916 security_task_to_inode(task, inode);
....@@ -1927,6 +1921,39 @@
19271921 out_unlock:
19281922 iput(inode);
19291923 return NULL;
1924
+}
1925
+
1926
+/*
1927
+ * Generating an inode and adding it into @pid->inodes, so that task will
1928
+ * invalidate inode's dentry before being released.
1929
+ *
1930
+ * This helper is used for creating dir-type entries under '/proc' and
1931
+ * '/proc/<tgid>/task'. Other entries(eg. fd, stat) under '/proc/<tgid>'
1932
+ * can be released by invalidating '/proc/<tgid>' dentry.
1933
+ * In theory, dentries under '/proc/<tgid>/task' can also be released by
1934
+ * invalidating '/proc/<tgid>' dentry, we reserve it to handle single
1935
+ * thread exiting situation: Any one of threads should invalidate its
1936
+ * '/proc/<tgid>/task/<pid>' dentry before released.
1937
+ */
1938
+static struct inode *proc_pid_make_base_inode(struct super_block *sb,
1939
+ struct task_struct *task, umode_t mode)
1940
+{
1941
+ struct inode *inode;
1942
+ struct proc_inode *ei;
1943
+ struct pid *pid;
1944
+
1945
+ inode = proc_pid_make_inode(sb, task, mode);
1946
+ if (!inode)
1947
+ return NULL;
1948
+
1949
+ /* Let proc_flush_pid find this directory inode */
1950
+ ei = PROC_I(inode);
1951
+ pid = ei->pid;
1952
+ spin_lock(&pid->lock);
1953
+ hlist_add_head_rcu(&ei->sibling_inodes, &pid->inodes);
1954
+ spin_unlock(&pid->lock);
1955
+
1956
+ return inode;
19301957 }
19311958
19321959 int pid_getattr(const struct path *path, struct kstat *stat,
....@@ -2040,7 +2067,7 @@
20402067
20412068 child = d_hash_and_lookup(dir, &qname);
20422069 if (!child) {
2043
- DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(wq);
2070
+ DECLARE_WAIT_QUEUE_HEAD_ONSTACK(wq);
20442071 child = d_alloc_parallel(dir, &qname, &wq);
20452072 if (IS_ERR(child))
20462073 goto end_instantiate;
....@@ -3346,7 +3373,8 @@
33463373 {
33473374 struct inode *inode;
33483375
3349
- inode = proc_pid_make_inode(dentry->d_sb, task, S_IFDIR | S_IRUGO | S_IXUGO);
3376
+ inode = proc_pid_make_base_inode(dentry->d_sb, task,
3377
+ S_IFDIR | S_IRUGO | S_IXUGO);
33503378 if (!inode)
33513379 return ERR_PTR(-ENOENT);
33523380
....@@ -3511,7 +3539,8 @@
35113539 }
35123540
35133541 static const struct inode_operations proc_tid_comm_inode_operations = {
3514
- .permission = proc_tid_comm_permission,
3542
+ .setattr = proc_setattr,
3543
+ .permission = proc_tid_comm_permission,
35153544 };
35163545
35173546 /*
....@@ -3644,7 +3673,8 @@
36443673 struct task_struct *task, const void *ptr)
36453674 {
36463675 struct inode *inode;
3647
- inode = proc_pid_make_inode(dentry->d_sb, task, S_IFDIR | S_IRUGO | S_IXUGO);
3676
+ inode = proc_pid_make_base_inode(dentry->d_sb, task,
3677
+ S_IFDIR | S_IRUGO | S_IXUGO);
36483678 if (!inode)
36493679 return ERR_PTR(-ENOENT);
36503680