public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Shailabh Nagar <nagar@watson.ibm.com>
To: Shailabh Nagar <nagar@watson.ibm.com>
Cc: Arjan van de Ven <arjan@infradead.org>,
	michal.k.k.piotrowski@gmail.com, linux-kernel@vger.kernel.org,
	mingo@elte.hu, akpm@osdl.org, balbir@in.ibm.com,
	jlan@engr.sgi.com
Subject: Re: + delay-accounting-taskstats-interface-send-tgid-once.patch	added to -mm tree
Date: Tue, 27 Jun 2006 12:06:04 -0400	[thread overview]
Message-ID: <44A1576C.8090307@watson.ibm.com> (raw)
In-Reply-To: <44A15483.30308@watson.ibm.com>

Shailabh Nagar wrote:

> Arjan van de Ven wrote:
>
>> also in response to
>>                           Subject: Re: 2.6.17-mm3
>>                              Date: Tue, 27 Jun 2006 16:12:42 +0200
>> with Message-ID:
>> <6bffcb0e0606270712w166f04a6u237d695e2bfa1913@mail.gmail.com>
>>
>> On Mon, 2006-06-26 at 12:06 -0700, akpm@osdl.org wrote:
>>
>>  
>>
>>> +static inline void taskstats_tgid_alloc(struct signal_struct *sig)
>>> +{
>>> +    struct taskstats *stats;
>>> +
>>> +    stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
>>> +    if (!stats)
>>> +        return;
>>> +
>>> +    spin_lock(&sig->stats_lock);
>>> +    if (!sig->stats) {
>>>   
>>
>>
>> +static inline void taskstats_tgid_free(struct signal_struct *sig)
>> +{
>> +       struct taskstats *stats = NULL;
>> +       spin_lock(&sig->stats_lock);
>> +       if (sig->stats) {
>> +               stats = sig->stats;
>> +               sig->stats = NULL;
>> +       }
>> +       spin_unlock(&sig->stats_lock);
>> +       if (stats)
>> +               kmem_cache_free(taskstats_cache, stats);
>> +}
>>
>> this is buggy and deadlock prone!
>> (found by lockdep)
>>
>> stats_lock nests within tasklist_lock, which is taken in irq context.
>> (and thus needs irq_save treatment). But because of this nesting, it is
>> not allowed to take stats_lock without disabling irqs, or you can have
>> the following scenario
>>
>> CPU 0                        CPU 1
>> (in irq)                     (in the code above)
>>                      stats_lock is taken
>> tasklist_lock is taken            
>> stats_lock_is taken <spin>   
>>                 <interrupt happens>
>>                      tasklist_lock is taken
>>              which now forms an AB-BA deadlock!
>>
>>
>> this happens at least in copy_process which can call taskstats_tgid_free
>> without first disabling interrupts (via cleanup_signal).
>
>
> Arjan,
>
> Didn't get how stats_lock is nesting within tasklist_lock in 
> copy_process ?
> The call to cleanup_signal (or any call to taskstats_tgid_alloc/free) 
> seems to be happening
> outside of holding the tasklist lock ? Or maybe I'm missing something.

Yup...indeed I was.

In release_task(), __cleanup_signal() is being called within tasklist_lock
protection and that leads to stats_lock being held nested within 
tasklist_lock.

>
> Changing to an irqsave variant isn't a problem of course...
>
> --Shailabh
>
>> There may be
>> many other cases, I've not checked deeper yet.
>>
>> Solution should be to make these functions use irqsave variant... any
>> comments from the authors of this patch ?
>
Will submit a patch to switch to irqsave variants.

Thanks,
Shailabh




  reply	other threads:[~2006-06-27 16:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200606261906.k5QJ6vCp025201@shell0.pdx.osdl.net>
2006-06-27 15:15 ` + delay-accounting-taskstats-interface-send-tgid-once.patch added to -mm tree Arjan van de Ven
2006-06-27 15:26   ` Arjan van de Ven
2006-06-27 15:53   ` Shailabh Nagar
2006-06-27 16:06     ` Shailabh Nagar [this message]
2006-06-27 16:55       ` [PATCH] delay accounting taskstats interface: send tgid once locking fix Shailabh Nagar
2006-06-27 18:41         ` Michal Piotrowski

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=44A1576C.8090307@watson.ibm.com \
    --to=nagar@watson.ibm.com \
    --cc=akpm@osdl.org \
    --cc=arjan@infradead.org \
    --cc=balbir@in.ibm.com \
    --cc=jlan@engr.sgi.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.k.k.piotrowski@gmail.com \
    --cc=mingo@elte.hu \
    /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