[Devel] [PATCH RHEL7 COMMIT] ve: add get_curr_ve helper

Vasily Averin vvs at virtuozzo.com
Tue Aug 24 14:40:00 MSK 2021


The commit is pushed to "branch-rh7-3.10.0-1160.36.2.vz7.182.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1160.36.2.vz7.182.1
------>
commit cab1d4f472b1da29f4024f29aa3e3d88df5a6750
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Tue Aug 24 14:40:00 2021 +0300

    ve: add get_curr_ve helper
    
    This helper is a safe alternative to get_exec_env(), this helper
    actually gets reference on current ve so if from other thread current
    would be moved from this ve, at least this ve would not be freed under
    us.
    
    https://jira.sw.ru/browse/PSBM-123766
    
    Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 include/linux/cgroup.h |  1 +
 kernel/cgroup.c        | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index ac255e4..6ed84d9 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -671,6 +671,7 @@ int cgroup_task_count(const struct cgroup *cgrp);
 void cgroup_release_agent(struct work_struct *work);
 
 #ifdef CONFIG_VE
+struct ve_struct *get_curr_ve(void);
 int cgroup_mark_ve_roots(struct ve_struct *ve);
 void cgroup_unmark_ve_roots(struct ve_struct *ve);
 struct cgroup *cgroup_get_local_root(struct cgroup *cgrp);
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 9d360a0..8f01cb9 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -4645,6 +4645,27 @@ static struct cftype *get_cftype_by_name(const char *name)
 }
 
 #ifdef CONFIG_VE
+/*
+ * This helper is a safe alternative to get_exec_env(), this helper actually
+ * gets reference on current ve so if in other thread we would be moved from
+ * this ve, at least this ve would not be freed under us.
+ */
+struct ve_struct *get_curr_ve(void)
+{
+	struct ve_struct *ve;
+
+	/*
+	 * Under cgroup_mutex both current tasks ve cgroup and ->task_ve
+	 * pointer can't change. Corresponding cgroup_mutex around
+	 * cgroup_attach_task() protects us from it.
+	 */
+	mutex_lock(&cgroup_mutex);
+	ve = get_ve(current->task_ve);
+	mutex_unlock(&cgroup_mutex);
+
+	return ve;
+}
+
 int cgroup_mark_ve_roots(struct ve_struct *ve)
 {
 	struct cgroup *cgrp, *tmp;


More information about the Devel mailing list