Where we access other task's ve, we should take explicit reference.
Let's handle it with "__free(put_ve) = get_task_ve".

Where we access current's ve, we can go without any locks.

Also remove task_ve_name() as anti-pattern, returning a pointer to
ve_struct field of random task without holding reference to ve is wrong.

https://virtuozzo.atlassian.net/browse/VSTOR-118289
Signed-off-by: Pavel Tikhomirov <[email protected]>

Feature: ve: ve generic structures
---
 fs/proc/array.c          | 5 ++---
 include/linux/ve_proto.h | 8 --------
 kernel/sched/core.c      | 3 ++-
 kernel/time/itimer.c     | 2 +-
 kernel/ve/ve.c           | 7 -------
 lib/dump_stack.c         | 2 +-
 mm/oom_kill.c            | 6 ++++--
 7 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 6e2336c31bf78..fca9046093b97 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -161,6 +161,7 @@ static int task_virtual_pid(struct task_struct *t)
 static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
                                struct pid *pid, struct task_struct *p)
 {
+       struct ve_struct *ve __free(put_ve) = get_task_ve(p);
        struct user_namespace *user_ns = seq_user_ns(m);
        struct group_info *group_info;
        int g, umask = -1;
@@ -237,10 +238,8 @@ static inline void task_state(struct seq_file *m, struct 
pid_namespace *ns,
        seq_printf(m, "Kthread:\t%c\n", p->flags & PF_KTHREAD ? '1' : '0');
 
 #ifdef CONFIG_VE
-       rcu_read_lock();
        seq_printf(m, "envID:\t%s\nVPid:\t%d\n",
-                       task_ve_name(p), vpid);
-       rcu_read_unlock();
+                  ve_name(ve), vpid);
 #endif
 }
 
diff --git a/include/linux/ve_proto.h b/include/linux/ve_proto.h
index d7b613f7d26dc..e63ab8ed3c59c 100644
--- a/include/linux/ve_proto.h
+++ b/include/linux/ve_proto.h
@@ -31,9 +31,6 @@ static inline bool ve_is_super(struct ve_struct *ve)
 
 const char *ve_name(struct ve_struct *ve);
 
-/* must be called under rcu_read_lock if task != current */
-const char *task_ve_name(struct task_struct *task);
-
 extern struct list_head ve_list_head;
 #define for_each_ve(ve)                        \
        list_for_each_entry((ve), &ve_list_head, ve_list)
@@ -102,11 +99,6 @@ static inline const char *ve_name(struct ve_struct *ve)
        return "0";
 }
 
-static inline const char *task_ve_name(struct task_struct *task)
-{
-       return "0";
-}
-
 static inline int nr_threads_ve(struct ve_struct *ve)
 {
        return nr_threads;
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 0480e68d68125..6c1abc40b5ef5 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7844,6 +7844,7 @@ EXPORT_SYMBOL(io_schedule);
 
 void sched_show_task(struct task_struct *p)
 {
+       struct ve_struct *ve __free(put_ve) = get_task_ve(p);
        unsigned long free;
        int ppid;
 
@@ -7862,7 +7863,7 @@ void sched_show_task(struct task_struct *p)
        rcu_read_unlock();
        pr_cont(" stack:%-5lu pid:%-5d tgid:%-5d ppid:%-6d veid:%-4s 
flags:0x%08lx\n",
                free, task_pid_nr(p), task_tgid_nr(p),
-               ppid, task_ve_name(p), read_task_thread_flags(p));
+               ppid, ve_name(ve), read_task_thread_flags(p));
 
        print_worker_info(KERN_INFO, p);
        print_stop_info(KERN_INFO, p);
diff --git a/kernel/time/itimer.c b/kernel/time/itimer.c
index 721741b08381d..4486a3fea63cb 100644
--- a/kernel/time/itimer.c
+++ b/kernel/time/itimer.c
@@ -344,7 +344,7 @@ SYSCALL_DEFINE3(setitimer, int, which, struct 
__kernel_old_itimerval __user *, v
                memset(&set_buffer, 0, sizeof(set_buffer));
                printk_once(KERN_WARNING "cmd: %s CT: %s calls setitimer() with 
new_value NULL pointer."
                            " Misfeature support will be removed\n",
-                           current->comm, task_ve_name(current));
+                           current->comm, ve_name(get_exec_env()));
        }
 
        error = do_setitimer(which, &set_buffer, ovalue ? &get_buffer : NULL);
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index b96c752607a28..c04210bebb7e6 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -162,13 +162,6 @@ const char *ve_name(struct ve_struct *ve)
 }
 EXPORT_SYMBOL(ve_name);
 
-/* under rcu_read_lock if task != current */
-const char *task_ve_name(struct task_struct *task)
-{
-       return rcu_dereference_check(task->task_ve, task == current)->ve_name;
-}
-EXPORT_SYMBOL(task_ve_name);
-
 struct ve_struct *get_ve_by_id(envid_t veid)
 {
        struct ve_struct *ve;
diff --git a/lib/dump_stack.c b/lib/dump_stack.c
index 4708f9081d20c..bde2ee3ca8fcf 100644
--- a/lib/dump_stack.c
+++ b/lib/dump_stack.c
@@ -62,7 +62,7 @@ void dump_stack_print_info(const char *log_lvl)
               log_lvl, raw_smp_processor_id(),
               __kuid_val(current_real_cred()->euid),
               current->pid, current->comm,
-              task_ve_name(current),
+              ve_name(get_exec_env()),
               kexec_crash_loaded() ? "Kdump: loaded " : "",
               print_tainted(),
               init_utsname()->release,
diff --git a/mm/oom_kill.c b/mm/oom_kill.c
index a553919ea4758..3bcbe2d383908 100644
--- a/mm/oom_kill.c
+++ b/mm/oom_kill.c
@@ -38,6 +38,7 @@
 #include <linux/mempolicy.h>
 #include <linux/security.h>
 #include <linux/ve_proto.h>
+#include <linux/ve.h>
 #include <linux/ptrace.h>
 #include <linux/freezer.h>
 #include <linux/ftrace.h>
@@ -939,6 +940,7 @@ static bool task_will_free_mem(struct task_struct *task)
 
 static void __oom_kill_process(struct task_struct *victim, const char *message)
 {
+       struct ve_struct *ve __free(put_ve) = get_task_ve(victim);
        struct task_struct *p;
        struct mm_struct *mm;
        bool can_oom_reap = true;
@@ -973,7 +975,7 @@ static void __oom_kill_process(struct task_struct *victim, 
const char *message)
        rcu_read_lock();
        pr_err("%s: Killed process %d (%s) VE \"%s\" total-vm:%lukB, 
anon-rss:%lukB, file-rss:%lukB, shmem-rss:%lukB, UID:%u pgtables:%lukB 
oom_score_adj:%hd\n",
                message, task_pid_nr(victim), victim->comm,
-               task_ve_name(victim),
+               ve_name(ve),
                K(mm->total_vm),
                K(get_mm_counter(mm, MM_ANONPAGES)),
                K(get_mm_counter(mm, MM_FILEPAGES)),
@@ -1002,7 +1004,7 @@ static void __oom_kill_process(struct task_struct 
*victim, const char *message)
                        can_oom_reap = false;
                        set_bit(MMF_OOM_SKIP, &mm->flags);
                        pr_info("oom killer %d (%s) in VE \"%s\" has mm pinned 
by %d (%s)\n",
-                                       task_pid_nr(victim), victim->comm, 
task_ve_name(victim),
+                                       task_pid_nr(victim), victim->comm, 
ve_name(ve),
                                        task_pid_nr(p), p->comm);
                        continue;
                }
-- 
2.51.1

_______________________________________________
Devel mailing list
[email protected]
https://lists.openvz.org/mailman/listinfo/devel

Reply via email to