From: Srivatsa Vaddagiri <vatsa@in.ibm.com>
To: "Paul Menage" <menage@google.com>
Cc: "Paul Jackson" <pj@sgi.com>,
akpm@linux-foundation.org, linux-kernel@vger.kernel.org,
"Balbir Singh" <balbir@in.ibm.com>
Subject: Re: [PATCH] Fix race between attach_task and cpuset_exit
Date: Thu, 5 Apr 2007 12:30:33 +0530 [thread overview]
Message-ID: <20070405070033.GB3435@in.ibm.com> (raw)
In-Reply-To: <6599ad830704042255t5c126a0cj86d644cb8174e177@mail.gmail.com>
On Wed, Apr 04, 2007 at 10:55:01PM -0700, Paul Menage wrote:
> >@@ -1257,8 +1260,8 @@ static int attach_task(struct cpuset *cs
> >
> > put_task_struct(tsk);
> > synchronize_rcu();
> >- if (atomic_dec_and_test(&oldcs->count))
> >- check_for_release(oldcs, ppathbuf);
> >+ if (oldcs_to_be_released)
> >+ check_for_release(oldcs_to_be_released, ppathbuf);
> > return 0;
> > }
>
> Is this part of the patch necessary? If we're adding a task_lock() in
> cpuset_exit(), then the problem that Vatsa described (both
> cpuset_attach_task() and cpuset_exit() decrementing the same cpuset
> count, and cpuset_attach_task() incrementing the count on a cpuset
> that the task doesn't eventually end up in) go away, since only one
> thread will retrieve the old value of the task's cpuset in order to
> decrement its count.
You *have* to drop/inc the refcount inside the task_lock, otherwise it is
racy.
task_lock(T1);
old_cs = T1->cputset (C1)
atomic_inc(&C2->count);
T1->cputset = C2;
task_unlock();
...
synchronize_rcu();
if (atomic_dec_and_test(&C1->count))
check_for_release(..)
is incorrect. For ex: T1's refcount on C1 may have already been dropped
by now in cpuset_exit() and dropping the refcount again can lead to
negative refcounts.
.
> > void cpuset_exit(struct task_struct *tsk)
> > {
> > struct cpuset *cs;
> >+ struct cpuset *oldcs_to_be_released = NULL;
> >
> >+ task_lock(tsk);
> > cs = tsk->cpuset;
> > tsk->cpuset = &top_cpuset; /* the_top_cpuset_hack - see above
> > */
> >+ if (atomic_dec_and_test(&cs->count))
> >+ oldcs_to_be_released = cs;
> >+ task_unlock(tsk);
> >
>
> I think this is still racy - at this point we're holding a reference
> on a cpuset that could have a zero count,
How's that possible? That you have a zero-refcount cpuset with non empty
tasks in it?
> and we don't hold
> manage_mutex or callback_mutex. So a concurrent rmdir could zap the
> directory and free the cpuset.
I don't think that is possible. Can you explain?
> Shouldn't we just put a task_lock()/task_unlock() around these lines
> and leave everything else as-is?
>
> task_lock(tsk);
> cs = tsk->cpuset;
> tsk->cpuset = &top_cpuset; /* the_top_cpuset_hack - see above */
> task_unlock(tsk)
If we don't drop refcount inside task_lock() it makes it racy with
attach_task(). 'cs' derived above may not be the right cpuset to drop
refcount on later in cpuset_exit.
--
Regards,
vatsa
next prev parent reply other threads:[~2007-04-05 6:53 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-25 16:47 [PATCH] Fix race between attach_task and cpuset_exit Srivatsa Vaddagiri
2007-03-25 17:52 ` Balbir Singh
2007-03-25 19:54 ` Paul Jackson
2007-03-26 11:50 ` Srivatsa Vaddagiri
2007-03-26 17:58 ` Paul Jackson
2007-03-27 6:35 ` Srivatsa Vaddagiri
2007-03-27 8:45 ` Paul Jackson
2007-03-26 18:30 ` Paul Jackson
2007-03-25 19:50 ` Paul Jackson
2007-03-26 11:55 ` Srivatsa Vaddagiri
2007-04-05 5:55 ` Paul Menage
2007-04-05 7:00 ` Srivatsa Vaddagiri [this message]
2007-04-05 7:01 ` Paul Menage
2007-04-05 8:14 ` Srivatsa Vaddagiri
2007-04-05 8:10 ` Paul Menage
2007-04-10 17:12 ` Srivatsa Vaddagiri
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=20070405070033.GB3435@in.ibm.com \
--to=vatsa@in.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=balbir@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=menage@google.com \
--cc=pj@sgi.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