In places where we only check ve pointer itself, we may avoid taking the reference to ve so we use task_ve() helper there.
In places where we access fields on ve_struct from other task use get_task_ve() helper which takes explicit reference to ve_struct. Also use "__free(put_ve)" cleanup attribute to simiplify the reference put after get_task_ve(). https://virtuozzo.atlassian.net/browse/VSTOR-118289 Signed-off-by: Pavel Tikhomirov <[email protected]> Feature: ve: ve generic structures --- block/ioprio.c | 5 +++-- drivers/connector/cn_proc.c | 2 +- kernel/sched/stats.c | 4 +++- kernel/sys.c | 2 +- kernel/ve/ve.c | 4 ++-- kernel/ve/vzstat.c | 4 +++- 6 files changed, 13 insertions(+), 8 deletions(-) diff --git a/block/ioprio.c b/block/ioprio.c index db515442089ac..3c7a417b1e90f 100644 --- a/block/ioprio.c +++ b/block/ioprio.c @@ -29,6 +29,7 @@ #include <linux/syscalls.h> #include <linux/security.h> #include <linux/pid_namespace.h> +#include <linux/ve.h> int ioprio_check_cap(int ioprio) { @@ -136,7 +137,7 @@ SYSCALL_DEFINE3(ioprio_set, int, which, int, who, int, ioprio) for_each_process_thread(g, p) { #ifdef CONFIG_VE - if (p->task_ve != get_exec_env()) + if (task_ve(p) != get_exec_env()) continue; #endif if (!uid_eq(task_uid(p), uid) || @@ -250,7 +251,7 @@ SYSCALL_DEFINE2(ioprio_get, int, which, int, who) for_each_process_thread(g, p) { #ifdef CONFIG_VE - if (p->task_ve != get_exec_env()) + if (task_ve(p) != get_exec_env()) continue; #endif if (!uid_eq(task_uid(p), user->uid) || diff --git a/drivers/connector/cn_proc.c b/drivers/connector/cn_proc.c index eb280258b5b6b..d41c8aca1866b 100644 --- a/drivers/connector/cn_proc.c +++ b/drivers/connector/cn_proc.c @@ -181,7 +181,7 @@ static void proc_event_connector(struct task_struct *task, struct task_struct *task, long cookie)) { - struct ve_struct *ve = task->task_ve; + struct ve_struct *ve __free(put_ve) = get_task_ve(task); if (!ve_is_super(ve)) proc_event_connector_ve(task, ve, what, cookie, fill_event); diff --git a/kernel/sched/stats.c b/kernel/sched/stats.c index 15a2f1063fbe2..7c3f311b416d0 100644 --- a/kernel/sched/stats.c +++ b/kernel/sched/stats.c @@ -22,8 +22,10 @@ void __update_stats_wait_start(struct rq *rq, struct task_struct *p, static inline void update_sched_lat(struct task_struct *t, u64 delta, u64 now) { #ifdef CONFIG_VE + struct ve_struct *ve __free(put_ve) = get_task_ve(t); + KSTAT_LAT_PCPU_ADD(&kstat_glob.sched_lat, delta); - KSTAT_LAT_PCPU_ADD(&t->task_ve->sched_lat_ve, delta); + KSTAT_LAT_PCPU_ADD(&ve->sched_lat_ve, delta); t->alloc_lat[KSTAT_SCHED].totlat += delta; t->alloc_lat[KSTAT_SCHED].count++; diff --git a/kernel/sys.c b/kernel/sys.c index fce3d2d4350a6..a2a6722f9fe5b 100644 --- a/kernel/sys.c +++ b/kernel/sys.c @@ -2319,7 +2319,7 @@ static int prctl_set_task_ct_fields(struct task_struct *t, unsigned long arg, { struct prctl_task_ct_fields params; #ifdef CONFIG_VE - struct ve_struct *ve = t->task_ve; + struct ve_struct *ve __free(put_ve) = get_task_ve(t); if (!ve_is_super(ve) && !ve->is_pseudosuper) return -EPERM; diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c index ba0d64dea7b2e..b96c752607a28 100644 --- a/kernel/ve/ve.c +++ b/kernel/ve/ve.c @@ -797,7 +797,7 @@ void ve_stop_ns(struct pid_namespace *pid_ns) ve_nsproxy = rcu_dereference_protected(ve->ve_nsproxy, lockdep_is_held(&ve->op_sem)); /* * current->cgroups already switched to init_css_set in cgroup_exit(), - * but current->task_ve still points to our exec ve. + * but get_exec_env() still points to our exec ve. */ if (!ve_nsproxy || ve_nsproxy->pid_ns_for_children != pid_ns) goto unlock; @@ -1784,7 +1784,7 @@ static ssize_t ve_write_ctty(struct kernfs_open_file *of, char *buf, goto out; } - if (tsk_from->task_ve == tsk_to->task_ve) { + if (task_ve(tsk_from) == task_ve(tsk_to)) { spin_lock_irqsave(&tsk_to->sighand->siglock, flags); tty_to = tsk_to->signal->tty; if (!tty_to) diff --git a/kernel/ve/vzstat.c b/kernel/ve/vzstat.c index 8420adba3af5f..46ac756ba21d0 100644 --- a/kernel/ve/vzstat.c +++ b/kernel/ve/vzstat.c @@ -121,13 +121,15 @@ static void update_max_sched_latency_snap(void) read_lock(&tasklist_lock); now = ktime_to_ns(ktime_get()); for_each_process_thread(g, t) { + struct ve_struct *ve __free(put_ve) = NULL; if (likely(t->__state != TASK_RUNNING)) continue; tmp = get_task_lat(t, now); if (max < tmp) max = tmp; - st = &t->task_ve->sched_lat_ve; + ve = get_task_ve(t); + st = &ve->sched_lat_ve; if (st->max_snap < tmp) st->max_snap = tmp; } -- 2.51.1 _______________________________________________ Devel mailing list [email protected] https://lists.openvz.org/mailman/listinfo/devel
