Linux Container Development
 help / color / mirror / Atom feed
From: Pavel Emelyanov <xemul-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
To: Oleg Nesterov <oleg-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org>
Cc: "Eric W. Biederman"
	<ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>,
	Linux Containers
	<containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>,
	"Paul E. McKenney"
	<paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Subject: Re: [RFC][PATCH] Make access to taks's nsproxy liter
Date: Thu, 09 Aug 2007 11:14:18 +0400	[thread overview]
Message-ID: <46BABECA.9000502@openvz.org> (raw)
In-Reply-To: <20070808164107.GB578-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org>

Oleg Nesterov wrote:
> This time Paul E. McKenney actually cc'ed, sorry for the extra
> noise...
> 
> On 08/08, Pavel Emelyanov wrote:
>> When someone wants to deal with some other taks's namespaces
>> it has to lock the task and then to get the desired namespace
>> if the one exists. This is slow on read-only paths and may be
>> impossible in some cases.
>>
>> E.g. Oleg recently noticed a race between unshare() and the
>> (just sent for review) pid namespaces - when the task notifies
>> the parent it has to know the parent's namespace, but taking
>> the task_lock() is impossible there - the code is under write
>> locked tasklist lock.
>>
>> On the other hand switching the namespace on task (daemonize)
>> and releasing the namespace (after the last task exit) is rather
>> rare operation and we can sacrifice its speed to solve the
>> issues above.
> 
> Still it is a bit sad we slow down process's exit. Perhaps I missed
> some other ->nsproxy access, but can't we make a simpler patch?
> 
> --- kernel/fork.c	2007-07-28 16:58:17.000000000 +0400
> +++ /proc/self/fd/0	2007-08-08 20:30:33.325216944 +0400
> @@ -1633,7 +1633,9 @@ asmlinkage long sys_unshare(unsigned lon
>  
>  		if (new_nsproxy) {
>  			old_nsproxy = current->nsproxy;
> +			read_lock(&tasklist_lock);
>  			current->nsproxy = new_nsproxy;
> +			read_unlock(&tasklist_lock);
>  			new_nsproxy = old_nsproxy;
>  		}
>  
> 
> This way ->nsproxy is stable under task_lock() or write_lock(tasklist).

We may, but the intention of this patch is just (!) to make the access 
to other's task namespaces lockless. Solving the accessing parent's
nsproxy in do_notify_parent() is a (good) side effect :)

>> +void switch_task_namespaces(struct task_struct *p, struct nsproxy *new)
>> +{
>> +	struct nsproxy *ns;
>> +
>> +	might_sleep();
>> +
>> +	ns = p->nsproxy;
>> +	if (ns == new)
>> +		return;
>> +
>> +	if (new)
>> +		get_nsproxy(new);
>> +	rcu_assign_pointer(p->nsproxy, new);
>> +
>> +	if (ns && atomic_dec_and_test(&ns->count)) {
>> +		/*
>> +		 * wait for others to get what they want from this
>> +		 * nsproxy. cannot release this nsproxy via the
>> +		 * call_rcu() since put_mnt_ns will want to sleep
>> +		 */
>> +		synchronize_rcu();
>> +		free_nsproxy(ns);
>> +	}
>> +}
> 
> (I may be wrong, Paul cc'ed)
> 
> This is correct with the current implementation of RCU, but strictly speaking,
> we can't use synchronize_rcu() here, because write_lock_irq() doesn't imply
> rcu_read_lock() in theory.
> 
> Oleg.
> 
> 

  parent reply	other threads:[~2007-08-09  7:14 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-08-08 15:37 [RFC][PATCH] Make access to taks's nsproxy liter Pavel Emelyanov
     [not found] ` <46B9E321.6070602-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-08-08 16:29   ` Eric W. Biederman
     [not found]     ` <m1ps1yc7mp.fsf-T1Yj925okcoyDheHMi7gv2pdwda3JcWeAL8bYrjMMd8@public.gmane.org>
2007-08-09  7:10       ` Pavel Emelyanov
     [not found]         ` <46BABDE9.6090508-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-08-09  8:00           ` Eric W. Biederman
     [not found]             ` <m13aytb0j0.fsf-T1Yj925okcoyDheHMi7gv2pdwda3JcWeAL8bYrjMMd8@public.gmane.org>
2007-08-09  8:17               ` Pavel Emelyanov
2007-08-08 16:37   ` Oleg Nesterov
     [not found]     ` <20070808163757.GA578-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org>
2007-08-08 17:03       ` Eric W. Biederman
     [not found]         ` <m14pjac61z.fsf-T1Yj925okcoyDheHMi7gv2pdwda3JcWeAL8bYrjMMd8@public.gmane.org>
2007-08-08 17:19           ` Oleg Nesterov
     [not found]             ` <20070808171955.GA655-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org>
2007-08-09  7:09               ` Pavel Emelyanov
2007-08-08 16:41   ` Oleg Nesterov
     [not found]     ` <20070808164107.GB578-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org>
2007-08-08 17:23       ` Paul E. McKenney
     [not found]         ` <20070808172309.GA8909-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2007-08-08 17:36           ` Oleg Nesterov
     [not found]             ` <20070808173647.GA676-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org>
2007-08-08 18:48               ` Paul E. McKenney
2007-08-09  7:15           ` Pavel Emelyanov
     [not found]             ` <46BABF25.1090307-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-08-09  7:39               ` Oleg Nesterov
     [not found]                 ` <20070809073900.GA86-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org>
2007-08-09  7:46                   ` Pavel Emelyanov
     [not found]                     ` <46BAC671.4070908-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-08-09  8:06                       ` Oleg Nesterov
2007-08-09  7:49                   ` Oleg Nesterov
2007-08-09  7:14       ` Pavel Emelyanov [this message]
2007-08-08 16:48   ` Serge E. Hallyn
     [not found]     ` <20070808164854.GB28455-6s5zFf/epYLPQpwDFJZrxKsjOiXwFzmk@public.gmane.org>
2007-08-08 16:58       ` Oleg Nesterov
2007-08-09  7:12       ` Pavel Emelyanov
     [not found]         ` <46BABE53.6050604-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2007-08-09 14:10           ` Serge E. Hallyn

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=46BABECA.9000502@openvz.org \
    --to=xemul-gefaqzzx7r8dnm+yrofe0a@public.gmane.org \
    --cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org \
    --cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
    --cc=oleg-6lXkIZvqkOAvJsYlp49lxw@public.gmane.org \
    --cc=paulmck-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
    /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