[Devel] [PATCH RHEL COMMIT] ve: add get_curr_ve helper
Konstantin Khorenko
khorenko at virtuozzo.com
Tue Oct 12 16:45:09 MSK 2021
The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after ark-5.14
------>
commit 55fee44a371f45eeb118f2ad66ecfe518c0fe374
Author: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
Date: Tue Oct 12 16:45:09 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
Signed-off-by: Kirill Tkhai <ktkhai at virtuozzo.com>
---
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 6e9aca26313a..99bd069a476d 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -960,6 +960,7 @@ static inline void cgroup_bpf_put(struct cgroup *cgrp) {}
#ifdef CONFIG_VE
int ve_hide_cgroups(struct cgroup_root *root);
+struct ve_struct *get_curr_ve(void);
#endif
#endif /* _LINUX_CGROUP_H */
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 217846841fda..04a5e1effbaf 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -1919,6 +1919,27 @@ static int cgroup_reconfigure(struct fs_context *fc)
}
#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;
+}
+
void cgroup_mark_ve_root(struct ve_struct *ve)
{
struct cgrp_cset_link *link;
More information about the Devel
mailing list