Skip to contentSkip to conversation

cgroup: add xattr support

PATCH Superseded [email protected] 5 participants 19 messages Aug 16, 2012 – Aug 24, 2012

Subsystems (4)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover cgroup: add xattr support

This series are a refreshed version of a patchset submitted by Li Zefan back in march:

	https://lkml.org/lkml/2012/3/1/13

With Li's permission, I refreshed the patches to apply over the latest upstream and added the modifications suggested by others in the thread:
- using a mount option instead of config option to enable the xattr support
- reinitialize the list in kmem_xattrs_free()
- renamed functions to simple_xattr_*()

There're two users for this patchset:
- SELinux: to be able to control access to cgroupfs inside containers
- systemd: to store meta information such as main PID in a service cgroup, set specific services special options in the cgroup.

While the xattrs will use kernel memory like tmpfs, they're restricted to 'security' (which controls the format of the value) and 'trusted' (which requires CAP_SYS_ADMIN). If kernel memory usage is still a concern, we're not far from having memcg account for kernel memory.

v6:
- only allow trusted and security
- replace subsys_bits by something more meaningful v5:
- check for permissions for user xattr namespace v4:
- implemented requested changes by Tejun Heo in patch #2

Cc Li Zefan <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Lennart Poettering <[email protected]>
Signature · 1 line
Aristeu
#1 lore raw

PATCH v6 1/4 xattr: extract simple_xattr code from tmpfs

From: Li Zefan <[email protected]>

Extract in-memory xattr APIs from tmpfs. Will be used by cgroup.

$ size vmlinux.o
   text    data     bss     dec     hex filename
4658782  880729 5195032 10734543         a3cbcf vmlinux.o
$ size vmlinux.o
   text    data     bss     dec     hex filename
4658957  880729 5195032 10734718         a3cc7e vmlinux.o

v6:
- no changes
v5:
- no changes
v4:
- move simple_xattrs_free() to fs/xattr.c
v3:
- in kmem_xattrs_free(), reinitialize the list
- use simple_xattr_* prefix
- introduce simple_xattr_add() to prevent direct list usage

Cc Li Zefan <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Lennart Poettering <[email protected]>
---
 fs/xattr.c               |  200 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/shmem_fs.h |    3 
 include/linux/xattr.h    |   25 +++++
 mm/shmem.c               |  171 +++-------------------------------------
 4 files changed, 240 insertions(+), 159 deletions(-)
fs/xattr.c +200 -0
Index: github/fs/xattr.c
===================================================================
@@ -791,3 +791,203 @@
 EXPORT_SYMBOL(generic_listxattr);
 EXPORT_SYMBOL(generic_setxattr);
 EXPORT_SYMBOL(generic_removexattr);
+
+/*
+ * initialize the simple_xattrs structure
+ */
+void simple_xattrs_init(struct simple_xattrs *xattrs)
+{
+	INIT_LIST_HEAD(&xattrs->head);
+	spin_lock_init(&xattrs->lock);
+}
+
+/*
+ * Allocate new xattr and copy in the value; but leave the name to callers.
+ */
+struct simple_xattr *simple_xattr_alloc(const void *value, size_t size)
+{
+	struct simple_xattr *new_xattr;
+	size_t len;
+
+	/* wrap around? */
+	len = sizeof(*new_xattr) + size;
+	if (len <= sizeof(*new_xattr))
+		return NULL;
+
+	new_xattr = kmalloc(len, GFP_KERNEL);
+	if (!new_xattr)
+		return NULL;
+
+	new_xattr->size = size;
+	memcpy(new_xattr->value, value, size);
+	return new_xattr;
+}
+
+/*
+ * free all the xattrs
+ */
+void simple_xattrs_free(struct simple_xattrs *xattrs)
+{
+	struct simple_xattr *xattr, *node;
+
+	spin_lock(&xattrs->lock);
+	list_for_each_entry_safe(xattr, node, &xattrs->head, list) {
+		kfree(xattr->name);
+		kfree(xattr);
+	}
+	INIT_LIST_HEAD(&xattrs->head);
+	spin_unlock(&xattrs->lock);
+}
+
+/*
+ * xattr GET operation for in-memory/pseudo filesystems
+ */
+int simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
+		     void *buffer, size_t size)
+{
+	struct simple_xattr *xattr;
+	int ret = -ENODATA;
+
+	spin_lock(&xattrs->lock);
+	list_for_each_entry(xattr, &xattrs->head, list) {
+		if (strcmp(name, xattr->name))
+			continue;
+
+		ret = xattr->size;
+		if (buffer) {
+			if (size < xattr->size)
+				ret = -ERANGE;
+			else
+				memcpy(buffer, xattr->value, xattr->size);
+		}
+		break;
+	}
+	spin_unlock(&xattrs->lock);
+	return ret;
+}
+
+static int __simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
+			      const void *value, size_t size, int flags)
+{
+	struct simple_xattr *xattr;
+	struct simple_xattr *new_xattr = NULL;
+	size_t len;
+	int err = 0;
+
+	/* value == NULL means remove */
+	if (value) {
+		/* wrap around? */
+		len = sizeof(*new_xattr) + size;
+		if (len <= sizeof(*new_xattr))
+			return -ENOMEM;
+
+		new_xattr = kmalloc(len, GFP_KERNEL);
+		if (!new_xattr)
+			return -ENOMEM;
+
+		new_xattr->name = kstrdup(name, GFP_KERNEL);
+		if (!new_xattr->name) {
+			kfree(new_xattr);
+			return -ENOMEM;
+		}
+
+		new_xattr->size = size;
+		memcpy(new_xattr->value, value, size);
+	}
+
+	spin_lock(&xattrs->lock);
+	list_for_each_entry(xattr, &xattrs->head, list) {
+		if (!strcmp(name, xattr->name)) {
+			if (flags & XATTR_CREATE) {
+				xattr = new_xattr;
+				err = -EEXIST;
+			} else if (new_xattr) {
+				list_replace(&xattr->list, &new_xattr->list);
+			} else {
+				list_del(&xattr->list);
+			}
+			goto out;
+		}
+	}
+	if (flags & XATTR_REPLACE) {
+		xattr = new_xattr;
+		err = -ENODATA;
+	} else {
+		list_add(&new_xattr->list, &xattrs->head);
+		xattr = NULL;
+	}
+out:
+	spin_unlock(&xattrs->lock);
+	if (xattr) {
+		kfree(xattr->name);
+		kfree(xattr);
+	}
+	return err;
+
+}
+
+/*
+ * xattr SET operation for in-memory/pseudo filesystems
+ */
+int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
+		     const void *value, size_t size, int flags)
+{
+	if (size == 0)
+		value = ""; /* empty EA, do not remove */
+	return __simple_xattr_set(xattrs, name, value, size, flags);
+}
+
+/*
+ * xattr REMOVE operation for in-memory/pseudo filesystems
+ */
+int simple_xattr_remove(struct simple_xattrs *xattrs, const char *name)
+{
+        return __simple_xattr_set(xattrs, name, NULL, 0, XATTR_REPLACE);
+}
+
+static bool xattr_is_trusted(const char *name)
+{
+	return !strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN);
+}
+
+/*
+ * xattr LIST operation for in-memory/pseudo filesystems
+ */
+ssize_t simple_xattr_list(struct simple_xattrs *xattrs, char *buffer, size_t size)
+{
+	bool trusted = capable(CAP_SYS_ADMIN);
+	struct simple_xattr *xattr;
+	size_t used = 0;
+
+	spin_lock(&xattrs->lock);
+	list_for_each_entry(xattr, &xattrs->head, list) {
+		size_t len;
+
+		/* skip "trusted." attributes for unprivileged callers */
+		if (!trusted && xattr_is_trusted(xattr->name))
+			continue;
+
+		len = strlen(xattr->name) + 1;
+		used += len;
+		if (buffer) {
+			if (size < used) {
+				used = -ERANGE;
+				break;
+			}
+			memcpy(buffer, xattr->name, len);
+			buffer += len;
+		}
+	}
+	spin_unlock(&xattrs->lock);
+
+	return used;
+}
+
+void simple_xattr_list_add(struct simple_xattrs *xattrs,
+			   struct simple_xattr *new_xattr)
+{
+	spin_lock(&xattrs->lock);
+	list_add(&new_xattr->list, &xattrs->head);
+	spin_unlock(&xattrs->lock);
+}
+
include/linux/shmem_fs.h +2 -1
Index: github/include/linux/shmem_fs.h
===================================================================
@@ -5,6 +5,7 @@
 #include <linux/mempolicy.h>
 #include <linux/pagemap.h>
 #include <linux/percpu_counter.h>
+#include <linux/xattr.h>
 
 /* inode in-kernel data */
 
@@ -18,7 +19,7 @@
 	};
 	struct shared_policy	policy;		/* NUMA memory alloc policy */
 	struct list_head	swaplist;	/* chain of maybes on swap */
-	struct list_head	xattr_list;	/* list of shmem_xattr */
+	struct simple_xattrs	xattrs;		/* list of xattrs */
 	struct inode		vfs_inode;
 };
 
include/linux/xattr.h +25 -0
Index: github/include/linux/xattr.h
===================================================================
@@ -60,6 +60,7 @@
 #ifdef  __KERNEL__
 
 #include <linux/types.h>
+#include <linux/spinlock.h>
 
 struct inode;
 struct dentry;
@@ -96,6 +97,30 @@
 			   char **xattr_value, size_t size, gfp_t flags);
 int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
 		  const char *value, size_t size, gfp_t flags);
+
+struct simple_xattrs {
+	struct list_head head;
+	spinlock_t lock;
+};
+
+struct simple_xattr {
+	struct list_head list;
+	char *name;
+	size_t size;
+	char value[0];
+};
+
+void simple_xattrs_init(struct simple_xattrs *xattrs);
+struct simple_xattr *simple_xattr_alloc(const void *value, size_t size);
+void simple_xattrs_free(struct simple_xattrs *xattrs);
+int simple_xattr_get(struct simple_xattrs *xattrs, const char *name,
+		     void *buffer, size_t size);
+int simple_xattr_set(struct simple_xattrs *xattrs, const char *name,
+		     const void *value, size_t size, int flags);
+int simple_xattr_remove(struct simple_xattrs *xattrs, const char *name);
+ssize_t simple_xattr_list(struct simple_xattrs *xattrs, char *buffer, size_t size);
+void simple_xattr_list_add(struct simple_xattrs *xattrs, struct simple_xattr *new_xattr);
+
 #endif  /*  __KERNEL__  */
 
 #endif	/* _LINUX_XATTR_H */
mm/shmem.c +13 -158

258 lines not on this page · raw message

maintainer
#2 lore raw

Re: [PATCH v6 1/4] xattr: extract simple_xattr code from tmpfs

Quoted 22 lines · On Thu, Aug 16, 2012 at 01:44:54PM -0400…

From: Li Zefan <[email protected]>

Extract in-memory xattr APIs from tmpfs. Will be used by cgroup.

$ size vmlinux.o
   text    data     bss     dec     hex filename
4658782  880729 5195032 10734543         a3cbcf vmlinux.o
$ size vmlinux.o
   text    data     bss     dec     hex filename
4658957  880729 5195032 10734718         a3cc7e vmlinux.o

v6:
- no changes
v5:
- no changes
v4:
- move simple_xattrs_free() to fs/xattr.c
v3:
- in kmem_xattrs_free(), reinitialize the list
- use simple_xattr_* prefix
- introduce simple_xattr_add() to prevent direct list usage

Quoted 3 lines
Cc Li Zefan <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hugh Dickins <[email protected]>

Hugh, can you please review and ack this one?

Thanks.

Signature · 1 line
tejun
maintainer Acked-by
#3 lore raw

Re: [PATCH v6 1/4] xattr: extract simple_xattr code from tmpfs

Quoted 23 lines · Tejun Heo
Quoted 22 lines · On Thu, Aug 16, 2012 at 01:44:54PM -0400…

From: Li Zefan <[email protected]>

Extract in-memory xattr APIs from tmpfs. Will be used by cgroup.

$ size vmlinux.o
   text    data     bss     dec     hex filename
4658782  880729 5195032 10734543         a3cbcf vmlinux.o
$ size vmlinux.o
   text    data     bss     dec     hex filename
4658957  880729 5195032 10734718         a3cc7e vmlinux.o

v6:
- no changes
v5:
- no changes
v4:
- move simple_xattrs_free() to fs/xattr.c
v3:
- in kmem_xattrs_free(), reinitialize the list
- use simple_xattr_* prefix
- introduce simple_xattr_add() to prevent direct list usage

Quoted 5 lines
Quoted 3 lines
Cc Li Zefan <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hugh Dickins <[email protected]>

Hugh, can you please review and ack this one?

Yes, it looks nice to me. I might have preferred more as inlines in the header file to lower the slight init/evict overhead, and I don't see why __simple_xattr_set() isn't using simple_xattr_alloc() in the same way that shmem_xattr_set() used shmem_xattr_alloc(). But none of that matters:

#4 lore raw

Re: [PATCH v6 1/4] xattr: extract simple_xattr code from tmpfs

Quoted 7 lines · Hugh Dickins

Yes, it looks nice to me. I might have preferred more as inlines in the header file to lower the slight init/evict overhead, and I don't see why __simple_xattr_set() isn't using simple_xattr_alloc() in the same way that shmem_xattr_set() used shmem_xattr_alloc(). But none of that matters:

I can submit additional patches to fix these. What functions you want inlined?

On why __simple_xattr_set() is not using simple_xattr_alloc(), there's no reason to be that way, I missed it.

Thanks for reviewing!

Signature · 1 line
Aristeu
maintainer
#5 lore raw

Re: [PATCH v6 1/4] xattr: extract simple_xattr code from tmpfs

Quoted 11 lines · Aristeu Rozanski
Quoted 7 lines · Hugh Dickins

Yes, it looks nice to me. I might have preferred more as inlines in the header file to lower the slight init/evict overhead, and I don't see why __simple_xattr_set() isn't using simple_xattr_alloc() in the same way that shmem_xattr_set() used shmem_xattr_alloc(). But none of that matters:

I can submit additional patches to fix these. What functions you want inlined?

Oh, thank you. I was thinking that it's uncommon for tmpfs files to have xattrs (and the same probably true of other filesystems), so it's best to minimize xattrs impact on shared paths. If simple_xattrs_init() and simple_xattrs_free() can be static inline functions in linux/xattr.h, that would be nice.

Probably more important would be to remove spin_lock() and spin_unlock() (and INIT_LIST_HEAD) from simple_xattrs_free() - those are unnecessary in shmem_evict_inode(), and wouldn't they be unnecessary whenever simple_xattrs_free() gets called?

Hugh

Quoted 10 lines

On why __simple_xattr_set() is not using simple_xattr_alloc(), there's no reason to be that way, I missed it.

Thanks for reviewing!

Signature · 1 line
Aristeu
#6 lore raw

Re: [PATCH v6 1/4] xattr: extract simple_xattr code from tmpfs

Quoted 10 lines · Hugh Dickins
Quoted 9 lines · Aristeu Rozanski
Quoted 7 lines · Hugh Dickins

Yes, it looks nice to me. I might have preferred more as inlines in the header file to lower the slight init/evict overhead, and I don't see why __simple_xattr_set() isn't using simple_xattr_alloc() in the same way that shmem_xattr_set() used shmem_xattr_alloc(). But none of that matters:

Quoted 8 lines
Quoted 2 lines

I can submit additional patches to fix these. What functions you want inlined?

Oh, thank you. I was thinking that it's uncommon for tmpfs files to have xattrs (and the same probably true of other filesystems), so it's best to minimize xattrs impact on shared paths. If simple_xattrs_init() and simple_xattrs_free() can be static inline functions in linux/xattr.h, that would be nice.

ok, done. and since Tejun is waiting for those before integrating, I'll merge them in the original patches and resubmit everything.

Quoted 4 lines

Probably more important would be to remove spin_lock() and spin_unlock() (and INIT_LIST_HEAD) from simple_xattrs_free() - those are unnecessary in shmem_evict_inode(), and wouldn't they be unnecessary whenever simple_xattrs_free() gets called?

Removing INIT_LIST_HEAD() it's possible by actually unlinking each xattr inside the loop before freeing them. still, it'll have to check if the list is empty or not, which might end up being the same?

About the locking, I'm not sure, I'm investigating it.

Signature · 1 line
Aristeu
maintainer
#7 lore raw

Re: [PATCH v6 1/4] xattr: extract simple_xattr code from tmpfs

Quoted 14 lines · Aristeu Rozanski
Quoted 13 lines · Hugh Dickins
Quoted 11 lines · Aristeu Rozanski
Quoted 7 lines · Hugh Dickins

Yes, it looks nice to me. I might have preferred more as inlines in the header file to lower the slight init/evict overhead, and I don't see why __simple_xattr_set() isn't using simple_xattr_alloc() in the same way that shmem_xattr_set() used shmem_xattr_alloc(). But none of that matters:

I can submit additional patches to fix these. What functions you want inlined?

Quoted 8 lines
Quoted 5 lines

Oh, thank you. I was thinking that it's uncommon for tmpfs files to have xattrs (and the same probably true of other filesystems), so it's best to minimize xattrs impact on shared paths. If simple_xattrs_init() and simple_xattrs_free() can be static inline functions in linux/xattr.h, that would be nice.

ok, done. and since Tejun is waiting for those before integrating, I'll merge them in the original patches and resubmit everything.

Thanks.

Quoted 11 lines
Quoted 5 lines

Probably more important would be to remove spin_lock() and spin_unlock() (and INIT_LIST_HEAD) from simple_xattrs_free() - those are unnecessary in shmem_evict_inode(), and wouldn't they be unnecessary whenever simple_xattrs_free() gets called?

Removing INIT_LIST_HEAD() it's possible by actually unlinking each xattr inside the loop before freeing them. still, it'll have to check if the list is empty or not, which might end up being the same?

About the locking, I'm not sure, I'm investigating it.

I think we have a misunderstanding.

INIT_LIST_HEAD() is not expensive, I just meant to remove it because I thought it unnecessary by that point.

Do you envisage anywhere that would call simple_xattrs_free() except a filesystem's evict_inode()?

By that point, the inode is on its way out of the system: nothing much (yes, I am being a bit vague there ;) can get to it any more, there's no need to reinitialize the list head and there's no need for locking, because nothing else can be playing with those xattrs now.

If I'm wrong, then the current shmem_evict_inode() is already wrong not to be locking there.

Would renaming simple_xattrs_free() to simple_xattrs_evict() help?

Hugh

#8 lore raw

Re: [PATCH v6 1/4] xattr: extract simple_xattr code from tmpfs

Quoted 9 lines · Hugh Dickins
Quoted 9 lines
Quoted 4 lines

Probably more important would be to remove spin_lock() and spin_unlock() (and INIT_LIST_HEAD) from simple_xattrs_free() - those are unnecessary in shmem_evict_inode(), and wouldn't they be unnecessary whenever simple_xattrs_free() gets called?

Removing INIT_LIST_HEAD() it's possible by actually unlinking each xattr inside the loop before freeing them. still, it'll have to check if the list is empty or not, which might end up being the same?

Quoted 6 lines
Quoted 1 line

About the locking, I'm not sure, I'm investigating it.

I think we have a misunderstanding.

INIT_LIST_HEAD() is not expensive, I just meant to remove it because I thought it unnecessary by that point.

ah, I see.

Quoted 2 lines

Do you envisage anywhere that would call simple_xattrs_free() except a filesystem's evict_inode()?

cgroup does it differently and it's called in d_iput() path (see cgroup_diput), because it needs to selectively remove files upon remount.

Quoted 4 lines

By that point, the inode is on its way out of the system: nothing much (yes, I am being a bit vague there ;) can get to it any more, there's no need to reinitialize the list head and there's no need for locking, because nothing else can be playing with those xattrs now.

I agree with you. That's why I'm looking into it because I'm pretty sure I removed it at some point in the past and decided to put it back after investigating the easily reproducible oops. Sadly I managed to forget the analisys I did at the time.

Signature · 1 line
Aristeu
#9 lore raw

PATCH v6 2/4 cgroup: revise how we re-populate root directory

In reply to [email protected]

From: Li Zefan <[email protected]>

When remounting cgroupfs with some subsystems added to it and some removed, cgroup will remove all the files in root directory and then re-popluate it.

What I'm doing here is, only remove files which belong to subsystems that are to be unbinded, and only create files for newly-added subsystems. The purpose is to have all other files untouched.

This is a preparation for cgroup xattr support.

v6:
- no changes
v5:
- no changes
v4:
- refactored cgroup_clear_directory() to not use cgroup_rm_file()
- instead of going thru the list of files, get the file list using the subsystems
- use 'subsys_mask' instead of {added,removed}_bits and made cgroup_populate_dir() to match the parameters with cgroup_clear_directory()
v3:
- refresh patches after recent refactoring

Cc Li Zefan <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Lennart Poettering <[email protected]>
---
 kernel/cgroup.c |   61 ++++++++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 48 insertions(+), 13 deletions(-)
kernel/cgroup.c +48 -13
Index: github/kernel/cgroup.c
===================================================================
@@ -824,7 +824,8 @@
 static int cgroup_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode);
 static struct dentry *cgroup_lookup(struct inode *, struct dentry *, unsigned int);
 static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry);
-static int cgroup_populate_dir(struct cgroup *cgrp);
+static int cgroup_populate_dir(struct cgroup *cgrp, bool base_files,
+			       unsigned long subsys_mask);
 static const struct inode_operations cgroup_dir_inode_operations;
 static const struct file_operations proc_cgroupstats_operations;
 
@@ -963,12 +964,29 @@
 	return -ENOENT;
 }
 
-static void cgroup_clear_directory(struct dentry *dir)
+/**
+ * cgroup_clear_directory - selective removal of base and subsystem files
+ * @dir: directory containing the files
+ * @base_files: true if the base files should be removed
+ * @subsys_mask: mask of the subsystem ids whose files should be removed
+ */
+static void cgroup_clear_directory(struct dentry *dir, bool base_files,
+				   unsigned long subsys_mask)
 {
 	struct cgroup *cgrp = __d_cgrp(dir);
+	struct cgroup_subsys *ss;
 
-	while (!list_empty(&cgrp->files))
-		cgroup_rm_file(cgrp, NULL);
+	for_each_subsys(cgrp->root, ss) {
+		struct cftype_set *set;
+		if (!test_bit(ss->subsys_id, &subsys_mask))
+			continue;
+		list_for_each_entry(set, &ss->cftsets, node)
+			cgroup_rm_file(cgrp, set->cfts);
+	}
+	if (base_files) {
+		while (!list_empty(&cgrp->files))
+			cgroup_rm_file(cgrp, NULL);
+	}
 }
 
 /*
@@ -977,8 +995,9 @@
 static void cgroup_d_remove_dir(struct dentry *dentry)
 {
 	struct dentry *parent;
+	struct cgroupfs_root *root = dentry->d_sb->s_fs_info;
 
-	cgroup_clear_directory(dentry);
+	cgroup_clear_directory(dentry, true, root->subsys_bits);
 
 	parent = dentry->d_parent;
 	spin_lock(&parent->d_lock);
@@ -1339,6 +1358,7 @@
 	struct cgroupfs_root *root = sb->s_fs_info;
 	struct cgroup *cgrp = &root->top_cgroup;
 	struct cgroup_sb_opts opts;
+	unsigned long added_bits, removed_bits;
 
 	mutex_lock(&cgrp->dentry->d_inode->i_mutex);
 	mutex_lock(&cgroup_mutex);
@@ -1354,6 +1374,9 @@
 		pr_warning("cgroup: option changes via remount are deprecated (pid=%d comm=%s)\n",
 			   task_tgid_nr(current), current->comm);
 
+	added_bits = opts.subsys_bits & ~root->subsys_bits;
+	removed_bits = root->subsys_bits & ~opts.subsys_bits;
+
 	/* Don't allow flags or name to change at remount */
 	if (opts.flags != root->flags ||
 	    (opts.name && strcmp(opts.name, root->name))) {
@@ -1369,8 +1392,9 @@
 	}
 
 	/* clear out any existing files and repopulate subsystem files */
-	cgroup_clear_directory(cgrp->dentry);
-	cgroup_populate_dir(cgrp);
+	cgroup_clear_directory(cgrp->dentry, false, removed_bits);
+	/* re-populate subsystem files */
+	cgroup_populate_dir(cgrp, false, added_bits);
 
 	if (opts.release_agent)
 		strcpy(root->release_agent_path, opts.release_agent);
@@ -1669,7 +1693,7 @@
 		BUG_ON(root->number_of_cgroups != 1);
 
 		cred = override_creds(&init_cred);
-		cgroup_populate_dir(root_cgrp);
+		cgroup_populate_dir(root_cgrp, true, root->subsys_bits);
 		revert_creds(cred);
 		mutex_unlock(&cgroup_root_mutex);
 		mutex_unlock(&cgroup_mutex);
@@ -3843,18 +3867,29 @@
 	{ }	/* terminate */
 };
 
-static int cgroup_populate_dir(struct cgroup *cgrp)
+/**
+ * cgroup_populate_dir - selectively creation of files in a directory
+ * @cgrp: target cgroup
+ * @base_files: true if the base files should be added
+ * @subsys_mask: mask of the subsystem ids whose files should be added
+ */
+static int cgroup_populate_dir(struct cgroup *cgrp, bool base_files,
+			       unsigned long subsys_mask)
 {
 	int err;
 	struct cgroup_subsys *ss;
 
-	err = cgroup_addrm_files(cgrp, NULL, files, true);
-	if (err < 0)
-		return err;
+        if (base_files) {
+		err = cgroup_addrm_files(cgrp, NULL, files, true);
+		if (err < 0)
+			return err;
+	}
 
 	/* process cftsets of each subsystem */
 	for_each_subsys(cgrp->root, ss) {
 		struct cftype_set *set;
+		if (!test_bit(ss->subsys_id, &subsys_mask))
+			continue;
 
 		list_for_each_entry(set, &ss->cftsets, node)
 			cgroup_addrm_files(cgrp, ss, set->cfts, true);
@@ -3988,7 +4023,7 @@
 
 	list_add_tail(&cgrp->allcg_node, &root->allcg_list);
 
-	err = cgroup_populate_dir(cgrp);
+	err = cgroup_populate_dir(cgrp, true, root->subsys_bits);
 	/* If err < 0, we have a half-filled directory - oh well ;) */
 
 	mutex_unlock(&cgroup_mutex);
#10 lore raw

PATCH v6 3/4 cgroup: add xattr support

In reply to [email protected]

From: Li Zefan <[email protected]>

This is one of the items in the plumber's wish list.

For use cases:

Quoted 17 lines
Quoted 1 line

What would the use case be for this?

Attaching meta information to services, in an easily discoverable way. For example, in systemd we create one cgroup for each service, and could then store data like the main pid of the specific service as an xattr on the cgroup itself. That way we'd have almost all service state in the cgroupfs, which would make it possible to terminate systemd and later restart it without losing any state information. But there's more:
for example, some very peculiar services cannot be terminated on shutdown (i.e. fakeraid DM stuff) and it would be really nice if the services in question could just mark that on their cgroup, by setting an xattr. On the more desktopy side of things there are other
possibilities: for example there are plans defining what an application is along the lines of a cgroup (i.e. an app being a collection of processes). With xattrs one could then attach an icon or human readable program name on the cgroup.

Quoted 8 lines

The key idea is that this would allow attaching runtime meta information to cgroups and everything they model (services, apps, vms), that doesn't need any complex userspace infrastructure, has good access control (i.e. because the file system enforces that anyway, and there's the "trusted." xattr namespace), notifications (inotify), and can easily be shared among applications.

Lennart

v6:
- remove user xattr namespace, only allow trusted and security v5:
- check for capabilities before setting/removing xattrs v4:
- no changes
v3:
- instead of config option, use mount option to enable xattr support

Cc Li Zefan <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Lennart Poettering <[email protected]>
---
 include/linux/cgroup.h |   13 ++++--
 kernel/cgroup.c        |  100 +++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 103 insertions(+), 10 deletions(-)
include/linux/cgroup.h +10 -3
Index: github/include/linux/cgroup.h
===================================================================
@@ -17,6 +17,7 @@
 #include <linux/rwsem.h>
 #include <linux/idr.h>
 #include <linux/workqueue.h>
+#include <linux/xattr.h>
 
 #ifdef CONFIG_CGROUPS
 
@@ -216,6 +217,9 @@
 	/* List of events which userspace want to receive */
 	struct list_head event_list;
 	spinlock_t event_list_lock;
+
+	/* directory xattrs */
+	struct simple_xattrs xattrs;
 };
 
 /*
@@ -309,6 +313,9 @@
 	/* CFTYPE_* flags */
 	unsigned int flags;
 
+	/* file xattrs */
+	struct simple_xattrs xattrs;
+
 	int (*open)(struct inode *inode, struct file *file);
 	ssize_t (*read)(struct cgroup *cgrp, struct cftype *cft,
 			struct file *file,
@@ -394,7 +401,7 @@
  */
 struct cftype_set {
 	struct list_head		node;	/* chained at subsys->cftsets */
-	const struct cftype		*cfts;
+	struct cftype			*cfts;
 };
 
 struct cgroup_scanner {
@@ -406,8 +413,8 @@
 	void *data;
 };
 
-int cgroup_add_cftypes(struct cgroup_subsys *ss, const struct cftype *cfts);
-int cgroup_rm_cftypes(struct cgroup_subsys *ss, const struct cftype *cfts);
+int cgroup_add_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
+int cgroup_rm_cftypes(struct cgroup_subsys *ss, struct cftype *cfts);
 
 int cgroup_is_removed(const struct cgroup *cgrp);
 
kernel/cgroup.c +93 -7

205 lines not on this page · raw message

maintainer
#11 lore raw
Quoted 41 lines · On Thu, Aug 16, 2012 at 01:44:56PM -0400, [email protected] wrote:

From: Li Zefan <[email protected]>

This is one of the items in the plumber's wish list.

For use cases:

Quoted 17 lines
Quoted 1 line

What would the use case be for this?

Attaching meta information to services, in an easily discoverable way. For example, in systemd we create one cgroup for each service, and could then store data like the main pid of the specific service as an xattr on the cgroup itself. That way we'd have almost all service state in the cgroupfs, which would make it possible to terminate systemd and later restart it without losing any state information. But there's more:
for example, some very peculiar services cannot be terminated on shutdown (i.e. fakeraid DM stuff) and it would be really nice if the services in question could just mark that on their cgroup, by setting an xattr. On the more desktopy side of things there are other
possibilities: for example there are plans defining what an application is along the lines of a cgroup (i.e. an app being a collection of processes). With xattrs one could then attach an icon or human readable program name on the cgroup.

Quoted 8 lines

The key idea is that this would allow attaching runtime meta information to cgroups and everything they model (services, apps, vms), that doesn't need any complex userspace infrastructure, has good access control (i.e. because the file system enforces that anyway, and there's the "trusted." xattr namespace), notifications (inotify), and can easily be shared among applications.

Lennart

v6:
- remove user xattr namespace, only allow trusted and security v5:
- check for capabilities before setting/removing xattrs v4:
- no changes
v3:
- instead of config option, use mount option to enable xattr support

Quoted 7 lines
Cc Li Zefan <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Lennart Poettering <[email protected]>

I'm not against this but unsure whether using kmem is enough for the suggested use case. Lennart, would this suit systemd? How much metadata are we talking about?

Thanks.

Signature · 1 line
tejun
#12 lore raw

Heya,

(sorry for the late reply)

Quoted 25 lines · Tejun Heo
Quoted 15 lines · On Thu, Aug 16, 2012 at 01:44:56PM -0400…
Quoted 15 lines

Attaching meta information to services, in an easily discoverable way. For example, in systemd we create one cgroup for each service, and could then store data like the main pid of the specific service as an xattr on the cgroup itself. That way we'd have almost all service state in the cgroupfs, which would make it possible to terminate systemd and later restart it without losing any state information. But there's more:
for example, some very peculiar services cannot be terminated on shutdown (i.e. fakeraid DM stuff) and it would be really nice if the services in question could just mark that on their cgroup, by setting an xattr. On the more desktopy side of things there are other
possibilities: for example there are plans defining what an application is along the lines of a cgroup (i.e. an app being a collection of processes). With xattrs one could then attach an icon or human readable program name on the cgroup.

Quoted 6 lines
Quoted 6 lines

The key idea is that this would allow attaching runtime meta information to cgroups and everything they model (services, apps, vms), that doesn't need any complex userspace infrastructure, has good access control (i.e. because the file system enforces that anyway, and there's the "trusted." xattr namespace), notifications (inotify), and can easily be shared among applications.

Quoted 3 lines

I'm not against this but unsure whether using kmem is enough for the suggested use case. Lennart, would this suit systemd? How much metadata are we talking about?

Just small things, like values, PIDs, i.e. a few 100 bytes or so per cgroup should be more than sufficient for our needs.

Lennart

maintainer
#13 lore raw

Hello,

Quoted 6 lines · Lennart Poettering
Quoted 3 lines

I'm not against this but unsure whether using kmem is enough for the suggested use case. Lennart, would this suit systemd? How much metadata are we talking about?

Just small things, like values, PIDs, i.e. a few 100 bytes or so per cgroup should be more than sufficient for our needs.

Alright, then. I think there's gonna be one more round to address Hugh's comments. Hugh, how should this be routed? Is there some git branch that tmpfs changes can go in so that cgroup tree can pull?

Thanks.

Signature · 1 line
tejun
maintainer
#14 lore raw
Quoted 7 lines · Tejun Heo
Quoted 6 lines · Lennart Poettering
Quoted 3 lines

I'm not against this but unsure whether using kmem is enough for the suggested use case. Lennart, would this suit systemd? How much metadata are we talking about?

Just small things, like values, PIDs, i.e. a few 100 bytes or so per cgroup should be more than sufficient for our needs.

That is reasonable.

Quoted 4 lines

Alright, then. I think there's gonna be one more round to address Hugh's comments. Hugh, how should this be routed? Is there some git branch that tmpfs changes can go in so that cgroup tree can pull?

No git tree, but we can easily handle it in one of two ways.

include/linux/shmem_fs.h and mm/shmem.c usually go to Linus from Andrew from his mmotm tree (which includes and is included in linux-next, by some magic escaping infinite recursion).

Are we expecting Aristeu+Zefan's simple_xattr patches to go into 3.7? I don't have anything planned for shmem.c for 3.7 beyond a bugfix, which shouldn't interact with the simple_xattr changes at all (I could remove info->lock, but will not do so this time around, precisely so as not to interfere with those patches).

So it should be perfectly workable for you to take Aristeu+Zefan's shmem patches into your cgroup tree, then any further mods from mmotm will get layered on top.

But if you prefer to leave shmem.c changes to Andrew, then it would also be perfectly workable for Aristeu to split the 1/4 into two:
one for you which updates fs/xattr.c and include/linux/xattr.h with simple_xattr code stolen from mm/shmem.c and include/linux/shmem_fs.h; and one for Andrew which updates mm/shmem.c and include/linux/shmem_fs.h to delete its shmem_xattr stuff and use simple_xattr interfaces instead.

Either approach is fine with me.

Hugh

maintainer
#15 lore raw

Hello, Hugh.

Quoted 1 line · Hugh Dickins

Are we expecting Aristeu+Zefan's simple_xattr patches to go into 3.7?

Yeah, probably.

Quoted 8 lines

I don't have anything planned for shmem.c for 3.7 beyond a bugfix, which shouldn't interact with the simple_xattr changes at all (I could remove info->lock, but will not do so this time around, precisely so as not to interfere with those patches).

So it should be perfectly workable for you to take Aristeu+Zefan's shmem patches into your cgroup tree, then any further mods from mmotm will get layered on top.

I think this approach would be simpler. Once Aristeu posts the updated version, I'll route the whole series through cgroup/for-3.7.

Thanks.

Signature · 1 line
tejun
#16 lore raw
Quoted 12 lines · Tejun Heo

Hello, Hugh.

Quoted 1 line · Hugh Dickins

Are we expecting Aristeu+Zefan's simple_xattr patches to go into 3.7?

Yeah, probably.

Quoted 5 lines

I don't have anything planned for shmem.c for 3.7 beyond a bugfix, which shouldn't interact with the simple_xattr changes at all (I could remove info->lock, but will not do so this time around, precisely so as not to interfere with those patches).

Quoted 6 lines
Quoted 3 lines

So it should be perfectly workable for you to take Aristeu+Zefan's shmem patches into your cgroup tree, then any further mods from mmotm will get layered on top.

I think this approach would be simpler. Once Aristeu posts the updated version, I'll route the whole series through cgroup/for-3.7.

I'm about to submit it, just doing last build and testing round. Merged back the changes Hugh asked in patch 1.

Also found why the list reinitialization was needed in the past; one of the old iterations had a bug in the remount code and was cleaning the xattrs out of the cgroup directory but not actually removing the directory, thus new xattrs got added to a list of freed xattrs.

So I believe we're good to go.

Signature · 1 line
Aristeu
#17 lore raw
In reply to Lennart Poettering
Quoted 30 lines · Lennart Poettering

Heya,

(sorry for the late reply)

Quoted 25 lines · Tejun Heo
Quoted 21 lines · On Thu, Aug 16, 2012 at 01:44:56PM -0400…
Quoted 21 lines

Attaching meta information to services, in an easily discoverable way. For example, in systemd we create one cgroup for each service, and could then store data like the main pid of the specific service as an xattr on the cgroup itself. That way we'd have almost all service state in the cgroupfs, which would make it possible to terminate systemd and later restart it without losing any state information. But there's more:
for example, some very peculiar services cannot be terminated on shutdown (i.e. fakeraid DM stuff) and it would be really nice if the services in question could just mark that on their cgroup, by setting an xattr. On the more desktopy side of things there are other
possibilities: for example there are plans defining what an application is along the lines of a cgroup (i.e. an app being a collection of processes). With xattrs one could then attach an icon or human readable program name on the cgroup.

The key idea is that this would allow attaching runtime meta information to cgroups and everything they model (services, apps, vms), that doesn't need any complex userspace infrastructure, has good access control (i.e. because the file system enforces that anyway, and there's the "trusted." xattr namespace), notifications (inotify), and can easily be shared among applications.

Quoted 6 lines
Quoted 3 lines

I'm not against this but unsure whether using kmem is enough for the suggested use case. Lennart, would this suit systemd? How much metadata are we talking about?

Just small things, like values, PIDs, i.e. a few 100 bytes or so per cgroup should be more than sufficient for our needs.

I have a really silly question. Why is storing these things in xattrs in a cgroup better than simply implementing a file in a cgroup?

It is most definitely going to be a real pain to discover as unix tools do not support xattrs well.

Furthermore I am having nasty visiions that storing pids is going to start breaking cgroups the way storing pids already breaks futexes. Which pid namespace is that pid relative to?

Eric

#18 lore raw

PATCH v6 4/4 cgroup: rename subsys_bits to subsys_mask

In reply to [email protected]

In a previous discussion, Tejun Heo suggested to rename references to subsys_bits (added_bits, removed_bits, etc) by something more meaningful.

Cc Li Zefan <[email protected]>
Cc Tejun Heo <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Hillf Danton <[email protected]>
Cc Lennart Poettering <[email protected]>
---
 kernel/cgroup.c |   84 ++++++++++++++++++++++++++++----------------------------
 1 file changed, 42 insertions(+), 42 deletions(-)
kernel/cgroup.c +42 -42
Index: github/kernel/cgroup.c
===================================================================
@@ -111,13 +111,13 @@
 	 * The bitmask of subsystems intended to be attached to this
 	 * hierarchy
 	 */
-	unsigned long subsys_bits;
+	unsigned long subsys_mask;
 
 	/* Unique id for this hierarchy. */
 	int hierarchy_id;
 
 	/* The bitmask of subsystems currently attached to this hierarchy */
-	unsigned long actual_subsys_bits;
+	unsigned long actual_subsys_mask;
 
 	/* A list running through the attached subsystems */
 	struct list_head subsys_list;
@@ -557,7 +557,7 @@
 	 * won't change, so no need for locking.
 	 */
 	for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
-		if (root->subsys_bits & (1UL << i)) {
+		if (root->subsys_mask & (1UL << i)) {
 			/* Subsystem is in this hierarchy. So we want
 			 * the subsystem state from the new
 			 * cgroup */
@@ -1002,7 +1002,7 @@
 	struct dentry *parent;
 	struct cgroupfs_root *root = dentry->d_sb->s_fs_info;
 
-	cgroup_clear_directory(dentry, true, root->subsys_bits);
+	cgroup_clear_directory(dentry, true, root->subsys_mask);
 
 	parent = dentry->d_parent;
 	spin_lock(&parent->d_lock);
@@ -1046,22 +1046,22 @@
  * returns an error, no reference counts are touched.
  */
 static int rebind_subsystems(struct cgroupfs_root *root,
-			      unsigned long final_bits)
+			      unsigned long final_subsys_mask)
 {
-	unsigned long added_bits, removed_bits;
+	unsigned long added_mask, removed_mask;
 	struct cgroup *cgrp = &root->top_cgroup;
 	int i;
 
 	BUG_ON(!mutex_is_locked(&cgroup_mutex));
 	BUG_ON(!mutex_is_locked(&cgroup_root_mutex));
 
-	removed_bits = root->actual_subsys_bits & ~final_bits;
-	added_bits = final_bits & ~root->actual_subsys_bits;
+	removed_mask = root->actual_subsys_mask & ~final_subsys_mask;
+	added_mask = final_subsys_mask & ~root->actual_subsys_mask;
 	/* Check that any added subsystems are currently free */
 	for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
 		unsigned long bit = 1UL << i;
 		struct cgroup_subsys *ss = subsys[i];
-		if (!(bit & added_bits))
+		if (!(bit & added_mask))
 			continue;
 		/*
 		 * Nobody should tell us to do a subsys that doesn't exist:
@@ -1086,7 +1086,7 @@
 	for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
 		struct cgroup_subsys *ss = subsys[i];
 		unsigned long bit = 1UL << i;
-		if (bit & added_bits) {
+		if (bit & added_mask) {
 			/* We're binding this subsystem to this hierarchy */
 			BUG_ON(ss == NULL);
 			BUG_ON(cgrp->subsys[i]);
@@ -1099,7 +1099,7 @@
 			if (ss->bind)
 				ss->bind(cgrp);
 			/* refcount was already taken, and we're keeping it */
-		} else if (bit & removed_bits) {
+		} else if (bit & removed_mask) {
 			/* We're removing this subsystem */
 			BUG_ON(ss == NULL);
 			BUG_ON(cgrp->subsys[i] != dummytop->subsys[i]);
@@ -1112,7 +1112,7 @@
 			list_move(&ss->sibling, &rootnode.subsys_list);
 			/* subsystem is now free - drop reference on module */
 			module_put(ss->module);
-		} else if (bit & final_bits) {
+		} else if (bit & final_subsys_mask) {
 			/* Subsystem state should already exist */
 			BUG_ON(ss == NULL);
 			BUG_ON(!cgrp->subsys[i]);
@@ -1129,7 +1129,7 @@
 			BUG_ON(cgrp->subsys[i]);
 		}
 	}
-	root->subsys_bits = root->actual_subsys_bits = final_bits;
+	root->subsys_mask = root->actual_subsys_mask = final_subsys_mask;
 	synchronize_rcu();
 
 	return 0;
@@ -1158,7 +1158,7 @@
 }
 
 struct cgroup_sb_opts {
-	unsigned long subsys_bits;
+	unsigned long subsys_mask;
 	unsigned long flags;
 	char *release_agent;
 	bool clone_children;
@@ -1267,7 +1267,7 @@
 			/* Mutually exclusive option 'all' + subsystem name */
 			if (all_ss)
 				return -EINVAL;
-			set_bit(i, &opts->subsys_bits);
+			set_bit(i, &opts->subsys_mask);
 			one_ss = true;
 
 			break;
@@ -1288,7 +1288,7 @@
 				continue;
 			if (ss->disabled)
 				continue;
-			set_bit(i, &opts->subsys_bits);
+			set_bit(i, &opts->subsys_mask);
 		}
 	}
 
@@ -1300,19 +1300,19 @@
 	 * the cpuset subsystem.
 	 */
 	if (test_bit(ROOT_NOPREFIX, &opts->flags) &&
-	    (opts->subsys_bits & mask))
+	    (opts->subsys_mask & mask))
 		return -EINVAL;
 
 
 	/* Can't specify "none" and some subsystems */
-	if (opts->subsys_bits && opts->none)
+	if (opts->subsys_mask && opts->none)
 		return -EINVAL;
 
 	/*
 	 * We either have to specify by name or by subsystems. (So all
 	 * empty hierarchies must have a name).
 	 */
-	if (!opts->subsys_bits && !opts->name)
+	if (!opts->subsys_mask && !opts->name)
 		return -EINVAL;
 
 	/*
@@ -1324,7 +1324,7 @@
 	for (i = CGROUP_BUILTIN_SUBSYS_COUNT; i < CGROUP_SUBSYS_COUNT; i++) {
 		unsigned long bit = 1UL << i;
 
-		if (!(bit & opts->subsys_bits))
+		if (!(bit & opts->subsys_mask))
 			continue;
 		if (!try_module_get(subsys[i]->module)) {
 			module_pin_failed = true;
@@ -1341,7 +1341,7 @@
 			/* drop refcounts only on the ones we took */
 			unsigned long bit = 1UL << i;
 
-			if (!(bit & opts->subsys_bits))
+			if (!(bit & opts->subsys_mask))
 				continue;
 			module_put(subsys[i]->module);
 		}
@@ -1351,13 +1351,13 @@
 	return 0;
 }
 
-static void drop_parsed_module_refcounts(unsigned long subsys_bits)
+static void drop_parsed_module_refcounts(unsigned long subsys_mask)
 {
 	int i;
 	for (i = CGROUP_BUILTIN_SUBSYS_COUNT; i < CGROUP_SUBSYS_COUNT; i++) {
 		unsigned long bit = 1UL << i;
 
-		if (!(bit & subsys_bits))
+		if (!(bit & subsys_mask))
 			continue;
 		module_put(subsys[i]->module);
 	}
@@ -1369,7 +1369,7 @@
 	struct cgroupfs_root *root = sb->s_fs_info;
 	struct cgroup *cgrp = &root->top_cgroup;
 	struct cgroup_sb_opts opts;
-	unsigned long added_bits, removed_bits;
+	unsigned long added_mask, removed_mask;
 
 	mutex_lock(&cgrp->dentry->d_inode->i_mutex);
 	mutex_lock(&cgroup_mutex);
@@ -1381,31 +1381,31 @@
 		goto out_unlock;
 
 	/* See feature-removal-schedule.txt */
-	if (opts.subsys_bits != root->actual_subsys_bits || opts.release_agent)
+	if (opts.subsys_mask != root->actual_subsys_mask || opts.release_agent)
 		pr_warning("cgroup: option changes via remount are deprecated (pid=%d comm=%s)\n",
 			   task_tgid_nr(current), current->comm);
 
-	added_bits = opts.subsys_bits & ~root->subsys_bits;
-	removed_bits = root->subsys_bits & ~opts.subsys_bits;
+	added_mask = opts.subsys_mask & ~root->subsys_mask;
+	removed_mask = root->subsys_mask & ~opts.subsys_mask;
 
 	/* Don't allow flags or name to change at remount */
 	if (opts.flags != root->flags ||
 	    (opts.name && strcmp(opts.name, root->name))) {
 		ret = -EINVAL;
-		drop_parsed_module_refcounts(opts.subsys_bits);
+		drop_parsed_module_refcounts(opts.subsys_mask);
 		goto out_unlock;
 	}
 
-	ret = rebind_subsystems(root, opts.subsys_bits);
+	ret = rebind_subsystems(root, opts.subsys_mask);
 	if (ret) {
-		drop_parsed_module_refcounts(opts.subsys_bits);
+		drop_parsed_module_refcounts(opts.subsys_mask);
 		goto out_unlock;
 	}
 
 	/* clear out any existing files and repopulate subsystem files */
-	cgroup_clear_directory(cgrp->dentry, false, removed_bits);
+	cgroup_clear_directory(cgrp->dentry, false, removed_mask);
 	/* re-populate subsystem files */
-	cgroup_populate_dir(cgrp, false, added_bits);
+	cgroup_populate_dir(cgrp, false, added_mask);
 
 	if (opts.release_agent)
 		strcpy(root->release_agent_path, opts.release_agent);
@@ -1491,8 +1491,8 @@
 	 * If we asked for subsystems (or explicitly for no
 	 * subsystems) then they must match
 	 */
-	if ((opts->subsys_bits || opts->none)
-	    && (opts->subsys_bits != root->subsys_bits))
+	if ((opts->subsys_mask || opts->none)
+	    && (opts->subsys_mask != root->subsys_mask))
 		return 0;
 
 	return 1;
@@ -1502,7 +1502,7 @@
 {
 	struct cgroupfs_root *root;
 
-	if (!opts->subsys_bits && !opts->none)
+	if (!opts->subsys_mask && !opts->none)
 		return NULL;
 
 	root = kzalloc(sizeof(*root), GFP_KERNEL);
@@ -1515,7 +1515,7 @@
 	}
 	init_cgroup_root(root);
 
-	root->subsys_bits = opts->subsys_bits;
+	root->subsys_mask = opts->subsys_mask;
 	root->flags = opts->flags;
 	if (opts->release_agent)
 		strcpy(root->release_agent_path, opts->release_agent);
@@ -1547,7 +1547,7 @@
 	if (!opts->new_root)
 		return -EINVAL;
 
-	BUG_ON(!opts->subsys_bits && !opts->none);
+	BUG_ON(!opts->subsys_mask && !opts->none);
 
 	ret = set_anon_super(sb, NULL);
 	if (ret)
@@ -1665,7 +1665,7 @@
 		if (ret)
 			goto unlock_drop;
 
-		ret = rebind_subsystems(root, root->subsys_bits);
+		ret = rebind_subsystems(root, root->subsys_mask);
 		if (ret == -EBUSY) {
 			free_cg_links(&tmp_cg_links);
 			goto unlock_drop;
@@ -1705,7 +1705,7 @@
 		BUG_ON(root->number_of_cgroups != 1);
 
 		cred = override_creds(&init_cred);
-		cgroup_populate_dir(root_cgrp, true, root->subsys_bits);
+		cgroup_populate_dir(root_cgrp, true, root->subsys_mask);
 		revert_creds(cred);
 		mutex_unlock(&cgroup_root_mutex);
 		mutex_unlock(&cgroup_mutex);
@@ -1717,7 +1717,7 @@
 		 */
 		cgroup_drop_root(opts.new_root);
 		/* no subsys rebinding, so refcounts don't change */
-		drop_parsed_module_refcounts(opts.subsys_bits);
+		drop_parsed_module_refcounts(opts.subsys_mask);
 	}
 
 	kfree(opts.release_agent);
@@ -1731,7 +1731,7 @@
  drop_new_super:
 	deactivate_locked_super(sb);
  drop_modules:
-	drop_parsed_module_refcounts(opts.subsys_bits);
+	drop_parsed_module_refcounts(opts.subsys_mask);
  out_err:
 	kfree(opts.release_agent);
 	kfree(opts.name);
@@ -4109,7 +4109,7 @@
 
 	list_add_tail(&cgrp->allcg_node, &root->allcg_list);
 
-	err = cgroup_populate_dir(cgrp, true, root->subsys_bits);
+	err = cgroup_populate_dir(cgrp, true, root->subsys_mask);
 	/* If err < 0, we have a half-filled directory - oh well ;) */
 
 	mutex_unlock(&cgroup_mutex);