[RHEL8,COMMIT] cgroup: Add rcu node string wrapper for in-cgroup usage

Submitted by Konstantin Khorenko on March 3, 2021, 5:21 p.m.

Details

Message ID 202103031721.123HLBp2294691@finist-co8.sw.ru
State New
Series "Port release_agent virtualization from vz7"
Headers show

Commit Message

Konstantin Khorenko March 3, 2021, 5:21 p.m.
The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.5
------>
commit dbe83106266e0d82dc93bf5265eb61036fb605da
Author: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
Date:   Wed Mar 3 20:21:11 2021 +0300

    cgroup: Add rcu node string wrapper for in-cgroup usage
    
    This will be used in further patches in same patchset.
    
    Cherry-picked from vz7 commit
    e828803a5d77 ("cgroup: added rcu node string wrapper for in-cgroup usage.")
    
    Signed-off-by: Valeriy Vdovin <valeriy.vdovin@virtuozzo.com>
    Reviewed-by: Kirill Tkhai <ktkhai@virtuozzo.com>
    
    =====================
    Patchset description:
    
    ve/cgroup: Port release_agent virtualization from vz7
    
    This patchset ports virtualization of cgroup release_agent
    virtualization from vz7.
    
    Major challanges of porting are differences between vz7 and vz8 cgroup
    implementations:
    - transition of cgroups to kernfs
    - slightly changed locking scheme, which relies on css_set_lock in
      places, previously relied on cgroup_mutex.
    
    There is a small number of patches that have been ported without
    modifications, but most of the patches had suffered a lot of
    modification due to the factors described above.
    
    v1:
      - original patchset
    v2:
      - removed port of CGRP_REMOVED due to the use of CSS_ONLINE in VZ8 for
        same reason
      - changed ve_set(get)_release_agent_path signature for more optimal
      - added ve->is_running check before calling userspace executable
    v3:
      - use goto after check for ve->is_running in last patch
---
 include/linux/cgroup-defs.h |  5 +++++
 include/linux/cgroup.h      |  4 ++++
 kernel/cgroup/cgroup-v1.c   | 15 +++++++++++++++
 3 files changed, 24 insertions(+)

Patch hide | download patch | download mbox

diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h
index a3b309ab1a90..772fcee71f37 100644
--- a/include/linux/cgroup-defs.h
+++ b/include/linux/cgroup-defs.h
@@ -360,6 +360,11 @@  struct cgroup_freezer_state {
 	int nr_frozen_tasks;
 };
 
+struct cgroup_rcu_string {
+	struct rcu_head rcu_head;
+	char val[];
+};
+
 struct cgroup {
 	/* self css with NULL ->ss, points back to this cgroup */
 	struct cgroup_subsys_state self;
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index c0a42c3d43fa..808b31605d07 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -689,6 +689,10 @@  static inline union kernfs_node_id *cgroup_get_kernfs_id(struct cgroup *cgrp)
 
 void cgroup_path_from_kernfs_id(const union kernfs_node_id *id,
 					char *buf, size_t buflen);
+
+struct cgroup_rcu_string;
+
+struct cgroup_rcu_string *cgroup_rcu_strdup(const char *str, int len);
 #else /* !CONFIG_CGROUPS */
 
 struct cgroup_subsys_state;
diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c
index db10a1ed282a..fb06fc9d96ca 100644
--- a/kernel/cgroup/cgroup-v1.c
+++ b/kernel/cgroup/cgroup-v1.c
@@ -231,6 +231,21 @@  static void cgroup_pidlist_destroy_work_fn(struct work_struct *work)
 	kfree(tofree);
 }
 
+struct cgroup_rcu_string *cgroup_rcu_strdup(const char *str, int len)
+{
+	struct cgroup_rcu_string *result;
+	size_t buflen = len + 1;
+
+	result = kmalloc(sizeof(*result) + buflen, GFP_KERNEL);
+	if (!result)
+		return ERR_PTR(-ENOMEM);
+	if (strlcpy(result->val, str, buflen) >= buflen) {
+		kfree(result);
+		return ERR_PTR(-ENAMETOOLONG);
+	}
+	return result;
+}
+
 /*
  * pidlist_uniq - given a kmalloc()ed list, strip out all duplicate entries
  * Returns the number of unique elements.