[Devel] [PATCH v2 1/3] ve: add get_curr_ve helper
Pavel Tikhomirov
ptikhomirov at virtuozzo.com
Tue Aug 17 17:53:30 MSK 2021
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>
---
v2: fix missprint in EXPORT_SYMBOL
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
include/linux/ve.h | 1 +
kernel/ve/ve.c | 22 ++++++++++++++++++++++
2 files changed, 23 insertions(+)
diff --git a/include/linux/ve.h b/include/linux/ve.h
index 1fc1f8051671..412ee96347f6 100644
--- a/include/linux/ve.h
+++ b/include/linux/ve.h
@@ -224,6 +224,7 @@ const char *ve_get_release_agent_path(struct cgroup *cgrp_root);
void ve_cleanup_per_cgroot_data(struct ve_struct *ve, struct cgroup *cgrp);
extern struct ve_struct *get_ve(struct ve_struct *ve);
+extern struct ve_struct *get_curr_ve(void);
extern void put_ve(struct ve_struct *ve);
struct cgroup_subsys_state *ve_get_init_css(struct ve_struct *ve, int subsys_id);
diff --git a/kernel/ve/ve.c b/kernel/ve/ve.c
index 44804761299c..8b7e2ad67530 100644
--- a/kernel/ve/ve.c
+++ b/kernel/ve/ve.c
@@ -133,6 +133,28 @@ struct ve_struct *get_ve(struct ve_struct *ve)
}
EXPORT_SYMBOL(get_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;
+}
+EXPORT_SYMBOL(get_curr_ve);
+
void put_ve(struct ve_struct *ve)
{
if (ve)
--
2.31.1
More information about the Devel
mailing list