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

Konstantin Khorenko khorenko at virtuozzo.com
Fri Aug 27 19:51:36 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-305.3.1.vz8.7.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-305.3.1.vz8.7.10
------>
commit bc5d21f08488fca21acf3c518223a83ae5d41152
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date:   Wed Aug 18 14:00:03 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>
    
    ====================
    cgroup: ifpriomap virtualization
    
    I've also added get_curr_ve() helper as it looks like in many places we
    rely that get_exec_env() gives us ve which would not free under us, but
    all processes can be moved easily from this ve in parallel and ve can be
    freed AFAICS.
    
    https://jira.sw.ru/browse/PSBM-123766
---
 include/linux/cgroup.h |  1 +
 kernel/cgroup/cgroup.c | 21 +++++++++++++++++++++
 2 files changed, 22 insertions(+)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index f6ed94205e51..b73edd5b67c4 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -870,6 +870,7 @@ int cgroup_path_ns(struct cgroup *cgrp, char *buf, size_t buflen,
 void cgroup1_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_subsys_state *css_local_root(struct cgroup_subsys_state *css);
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index dcd7983c393f..bff15d2d42e0 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -2033,6 +2033,27 @@ static inline bool css_has_host_cgroups(struct css_set *cset)
 	return false;
 }
 
+/*
+ * 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)
 {
 	int err;


More information about the Devel mailing list