linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Gao feng <gaofeng@cn.fujitsu.com>
Cc: cgroups@vger.kernel.org, lizefan@huawei.com,
	linux-kernel@vger.kernel.org,
	containers@lists.linux-foundation.org
Subject: Re: [PATCH 2/2] cgroup: remove subsystem files when remounting cgroup
Date: Fri, 30 Nov 2012 11:27:35 -0800	[thread overview]
Message-ID: <20121130192735.GF3873@htj.dyndns.org> (raw)
In-Reply-To: <1354292489-18434-2-git-send-email-gaofeng@cn.fujitsu.com>

Hello, Gao.

On Sat, Dec 01, 2012 at 12:21:29AM +0800, Gao feng wrote:
> cgroup_clear_directroy is called by cgroup_d_remove_dir
> and cgroup_remount.
> 
> when we call cgroup_remount to remount the cgroup,the subsystem
> may be unlinked from cgroupfs_root->subsys_list in rebind_subsystem,this
> subsystem's files will not be removed in cgroup_clear_directroy.
> And the system will panic when we try to access these files.
> 
> this patch fix it.

I'd really appreciated if you explain how it's fixed.

> Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
> ---
>  kernel/cgroup.c |   86 ++++++++++++++++++++++++++++++++++--------------------
>  1 files changed, 54 insertions(+), 32 deletions(-)
> 
> diff --git a/kernel/cgroup.c b/kernel/cgroup.c
> index e5233b7..90429d5 100644
> --- a/kernel/cgroup.c
> +++ b/kernel/cgroup.c
> @@ -982,10 +982,14 @@ 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;
> +	int i;
>  
> -	for_each_subsys(cgrp->root, ss) {
> +	for (i = 0; i < CGROUP_SUBSYS_COUNT; i++) {
>  		struct cftype_set *set;
> +		struct cgroup_subsys *ss = subsys[i];
> +
> +		if (ss == NULL)
> +			continue;

Ummm... I can't say I like it.  It tries to work around the problem
that the backing subsys may go away earlier by changing how the
subsystems are iterated so that the "gone" subsystems can be iterated,
which really doesn't seem like a good diea.  I mean, what if somebody
tries to access the files inbetween?  root_cgrp->subsys[] would be
%NULL and segfault all the same.

>  static void drop_parsed_module_refcounts(unsigned long subsys_mask)
> @@ -1392,23 +1403,34 @@ static int cgroup_remount(struct super_block *sb, int *flags, char *data)
>  	removed_mask = root->subsys_mask & ~opts.subsys_mask;
>  
>  	/* Don't allow flags or name to change at remount */
> +	ret = -EINVAL;
>  	if (opts.flags != root->flags ||
>  	    (opts.name && strcmp(opts.name, root->name))) {
> -		ret = -EINVAL;
>  		drop_parsed_module_refcounts(opts.subsys_mask);
>  		goto out_unlock;
>  	}
>  
> -	ret = rebind_subsystems(root, opts.subsys_mask);
> +	/*
> +	 * Add the reference of these removed subsystem,we
> +	 * need use subsystems to remove their cgroup files.
> +	 */
> +	ret = cgroup_get_module_refcounts(removed_mask);
>  	if (ret) {
>  		drop_parsed_module_refcounts(opts.subsys_mask);
>  		goto out_unlock;
>  	}
>  
> +	ret = rebind_subsystems(root, opts.subsys_mask);
> +	if (ret) {
> +		drop_parsed_module_refcounts(opts.subsys_mask | removed_mask);
> +		goto out_unlock;
> +	}
> +
>  	/* clear out any existing files and repopulate subsystem files */
>  	cgroup_clear_directory(cgrp->dentry, false, removed_mask);
>  	/* re-populate subsystem files */
>  	cgroup_populate_dir(cgrp, false, added_mask);
> +	drop_parsed_module_refcounts(removed_mask);

So, how about performing cgroup_clear_directory() *before*
rebind_subsystems() and then restore it afterwards?

Thanks.

-- 
tejun

  reply	other threads:[~2012-11-30 19:27 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-30 16:21 [PATCH 1/2] cgroup: use cgroup_addrm_files in cgroup_clear_directory Gao feng
2012-11-30 16:21 ` [PATCH 2/2] cgroup: remove subsystem files when remounting cgroup Gao feng
2012-11-30 19:27   ` Tejun Heo [this message]
2012-12-03  0:45     ` Gao feng
2012-12-03  1:28   ` [PATCH RESEND] " Gao feng
2012-12-03 16:34     ` Tejun Heo
2012-11-30 19:47 ` [PATCH] cgroup: use cgroup_addrm_files() in cgroup_clear_directory() Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121130192735.GF3873@htj.dyndns.org \
    --to=tj@kernel.org \
    --cc=cgroups@vger.kernel.org \
    --cc=containers@lists.linux-foundation.org \
    --cc=gaofeng@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).