[Devel] [PATCH RH9 2/5] ve: add get_curr_ve helper
Kirill Tkhai
ktkhai at virtuozzo.com
Tue Oct 12 13:48:29 MSK 2021
From: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
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