mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Catalin Marinas <catalin.marinas@arm.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu
Subject: Re: [PATCH 01/15] kmemleak: Add the base support
Date: Thu, 18 Dec 2008 09:28:46 +0000	[thread overview]
Message-ID: <1229592526.12846.10.camel@pc1117.cambridge.arm.com> (raw)
In-Reply-To: <20081202132828.5c84b815.akpm@linux-foundation.org>

On Tue, 2008-12-02 at 13:28 -0800, Andrew Morton wrote:
> On Sat, 29 Nov 2008 10:43:12 +0000
> Catalin Marinas <catalin.marinas@arm.com> wrote:
> > +	INIT_LIST_HEAD(&object->object_list);
> > +	INIT_LIST_HEAD(&object->gray_list);
> > +	INIT_HLIST_HEAD(&object->area_list);
> > +	spin_lock_init(&object->lock);
> > +	atomic_set(&object->use_count, 1);
> > +	object->flags = OBJECT_ALLOCATED;
> > +	object->pointer = ptr;
> > +	object->size = size;
> > +	object->ref_count = ref_count;
> > +	object->count = -1;				/* black color initially */
> > +	object->jiffies = jiffies;
> > +	if (in_irq()) {
> > +		object->pid = 0;
> > +		strncpy(object->comm, "hardirq", TASK_COMM_LEN);
> > +	} else if (in_softirq()) {
> > +		object->pid = 0;
> > +		strncpy(object->comm, "softirq", TASK_COMM_LEN);
> > +	} else {
> > +		object->pid = current->pid;
> > +		strncpy(object->comm, current->comm, TASK_COMM_LEN);
> 
> Access to current->comm is a teeny but racy.  Use get_task_comm() here.

This seems to cause some problems. First of all, the IRQs aren't
necessarily disabled and get_task_comm() acquires current->alloc_lock
without disabling the IRQs (I could add local_irq_save/restore around
it). The alloc_lock comment in task_struct also states that the lock
protects the (de)allocation of some members which may imply that the
lock could be held when kmemleak is called.

The other issue which I couldn't completely figure out is a lockdep
warning caused by calling get_task_comm() in kmemleak:

Starting the hotplug events dispatcher: udevd                                   
======================================================                          
[ INFO: soft-safe -> soft-unsafe lock order detected ]                          
2.6.28-rc8-00074-g1134084-dirty #158                                            
------------------------------------------------------                          
udevd/350 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire:                         
 (&p->alloc_lock){--..}, at: [<c008a000>] get_task_comm+0x20/0x40               
                                                                                
and this task is already holding:                                               
 (nl_table_lock){..-?}, at: [<c01c3628>] netlink_table_grab+0x18/0xd0           
which would create a new lock dependency:                                       
 (nl_table_lock){..-?} -> (&p->alloc_lock){--..}                                
                                                                                
but this new dependency connects a soft-irq-safe lock:                          
 (nl_table_lock){..-?}                                                          
... which became soft-irq-safe at:                                              
  [<c0055770>] __lock_acquire+0x51c/0x14b0                                      
  [<c0056768>] lock_acquire+0x64/0x78                                           
  [<c0229690>] _read_lock+0x34/0x44                                             
  [<c01c474c>] netlink_broadcast+0xbc/0x3bc                                     
  [<c01c52f4>] nlmsg_notify+0x6c/0x98                                           
  [<c01bde40>] rtnl_notify+0x44/0x4c                                            
  [<c01ba0f0>] __neigh_notify+0x98/0xcc                                         
  [<c01bb35c>] neigh_update_notify+0x2c/0x30                                    
  [<c01bbad8>] neigh_update+0x350/0x36c                                         
  [<c01ee5ec>] arp_process+0x624/0x6b0                                          
  [<c01ee764>] arp_rcv+0xd8/0xec                                                
  [<c01b34b4>] netif_receive_skb+0x278/0x2bc                                    
  [<c01b3580>] process_backlog+0x88/0x120                                       
  [<c01b1b78>] net_rx_action+0x6c/0x19c                                         
  [<c0039f34>] __do_softirq+0x74/0x124                                          
  [<c003a03c>] irq_exit+0x58/0x60                                               
  [<c0020068>] __exception_text_start+0x68/0x84                                 
  [<c0020a1c>] __irq_svc+0x3c/0x80                                              
  [<c0022360>] cpu_idle+0x38/0x54                                               
  [<c0223a30>] rest_init+0x58/0x6c                                              
  [<c000892c>] start_kernel+0x234/0x27c                                         
  [<70008034>] 0x70008034                                                       
  [<ffffffff>] 0xffffffff                                                       
                                                                                
to a soft-irq-unsafe lock:                                                      
 (&p->alloc_lock){--..}                                                         
... which became soft-irq-unsafe at:                                            
...  [<c0055800>] __lock_acquire+0x5ac/0x14b0                                   
  [<c0056768>] lock_acquire+0x64/0x78                                           
  [<c02292e0>] _spin_lock+0x3c/0x4c                                             
  [<c0089944>] set_task_comm+0x20/0x3c                                          
  [<c0049774>] kthreadd+0x2c/0x174                                              
  [<c0037db0>] do_exit+0x0/0x6ec                                                
  [<ffffffff>] 0xffffffff                                                       

[ ... removed some other info ... ]

stack backtrace:                                                                
[<c0226594>] (dump_stack+0x0/0x14) from [<c00551f0>] (check_usage+0x34c/0x3b0)  
[<c0054ea4>] (check_usage+0x0/0x3b0) from [<c00560ac>] (__lock_acquire+0xe58/0x1
4b0)                                                                            
[<c0055254>] (__lock_acquire+0x0/0x14b0) from [<c0056768>] (lock_acquire+0x64/0x
78)                                                                             
[<c0056704>] (lock_acquire+0x0/0x78) from [<c02292e0>] (_spin_lock+0x3c/0x4c)   
 r7:df4cebd8 r6:df4cebd8 r5:df41328c r4:df41328c                                
[<c02292a4>] (_spin_lock+0x0/0x4c) from [<c008a000>] (get_task_comm+0x20/0x40)  
 r4:df413000                                                                    
[<c0089fe0>] (get_task_comm+0x0/0x40) from [<c00828a8>] (kmemleak_alloc+0x134/0x
2b0)                                                                            
 r7:df4cebd8 r6:df4ceb28 r5:df41c000 r4:40000093                                
[<c0082774>] (kmemleak_alloc+0x0/0x2b0) from [<c0080fc0>] (__kmalloc_node+0xac/0
xb8)                                                                            
[<c0080f14>] (__kmalloc_node+0x0/0xb8) from [<c006f88c>] (__krealloc+0x4c/0x74) 
 r7:00000020 r6:00000004 r5:00000000 r4:00000000                                
[<c006f840>] (__krealloc+0x0/0x74) from [<c006f8dc>] (krealloc+0x28/0x48)       
 r7:df41df00 r6:00000020 r5:00000000 r4:00000004                                
[<c006f8b4>] (krealloc+0x0/0x48) from [<c01c37a4>] (netlink_realloc_groups+0x68/
0xb0)                                                                           
 r5:df4b5270 r4:00000004                                                        
[<c01c373c>] (netlink_realloc_groups+0x0/0xb0) from [<c01c4320>] (netlink_bind+0
x6c/0x148)                                                                      
 r7:df41df00 r6:df4b5270 r5:bef07cc4 r4:df4b5000                                
[<c01c42b4>] (netlink_bind+0x0/0x148) from [<c01a61a0>] (sys_bind+0x6c/0x90)    
 r7:df41df00 r6:0000000c r5:bef07cc4 r4:df4b5000                                
[<c01a6134>] (sys_bind+0x0/0x90) from [<c0020dc0>] (ret_fast_syscall+0x0/0x2c)  
 r7:0000011a r6:bef07cc4 r5:00000004 r4:000204f4                                

Thanks.

-- 
Catalin


  parent reply	other threads:[~2008-12-18  9:29 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-29 10:43 [PATCH 00/15] Kernel memory leak detector Catalin Marinas
2008-11-29 10:43 ` [PATCH 01/15] kmemleak: Add the base support Catalin Marinas
2008-12-01  5:39   ` Yasunori Goto
2008-12-01  6:49     ` Pekka Enberg
2008-12-01  8:11       ` Yasunori Goto
2008-12-01 12:29       ` Catalin Marinas
2008-12-01  7:15   ` Pekka Enberg
2008-12-02 21:28   ` Andrew Morton
2008-12-04 18:50     ` Catalin Marinas
2008-12-04 19:03       ` Andrew Morton
2008-12-18  9:28     ` Catalin Marinas [this message]
2008-11-29 10:43 ` [PATCH 02/15] kmemleak: Add documentation on the memory leak detector Catalin Marinas
2008-11-29 10:43 ` [PATCH 03/15] kmemleak: Add the slab memory allocation/freeing hooks Catalin Marinas
2008-11-29 10:43 ` [PATCH 04/15] kmemleak: Add the slob " Catalin Marinas
2008-11-30 17:30   ` Matt Mackall
2008-11-29 10:43 ` [PATCH 05/15] kmemleak: Add the slub " Catalin Marinas
2008-11-29 11:46   ` Pekka Enberg
2008-11-29 10:43 ` [PATCH 06/15] kmemleak: Add the vmalloc " Catalin Marinas
2008-11-29 10:43 ` [PATCH 07/15] kmemleak: Add memleak_alloc callback from alloc_large_system_hash Catalin Marinas
2008-11-29 10:43 ` [PATCH 08/15] kmemleak: Add modules support Catalin Marinas
2008-11-29 10:43 ` [PATCH 09/15] x86: Provide _sdata in the vmlinux_*.lds.S files Catalin Marinas
2008-11-29 10:44 ` [PATCH 10/15] arm: Provide _sdata and __bss_stop in the vmlinux.lds.S file Catalin Marinas
2008-11-29 10:44 ` [PATCH 11/15] kmemleak: Remove some of the kmemleak false positives Catalin Marinas
2008-11-29 11:48   ` Pekka Enberg
2008-11-30 19:02     ` Catalin Marinas
2008-11-29 10:44 ` [PATCH 12/15] kmemleak: Enable the building of the memory leak detector Catalin Marinas
2008-11-29 10:44 ` [PATCH 13/15] kmemleak: Keep the __init functions after initialization Catalin Marinas
2008-11-29 10:44 ` [PATCH 14/15] kmemleak: Simple testing module for kmemleak Catalin Marinas
2008-11-29 10:44 ` [PATCH 15/15] kmemleak: Add the corresponding MAINTAINERS entry Catalin Marinas
2008-12-10 18:26 [PATCH 00/15] Kernel memory leak detector Catalin Marinas
2008-12-10 18:26 ` [PATCH 01/15] kmemleak: Add the base support Catalin Marinas
2008-12-11 22:01   ` Pekka Enberg
2008-12-12 11:36     ` Catalin Marinas
2008-12-12 13:14       ` Pekka Enberg
2008-12-16 19:36   ` Paul E. McKenney
2008-12-17  9:44     ` Catalin Marinas
2008-12-17 17:15       ` Paul E. McKenney

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=1229592526.12846.10.camel@pc1117.cambridge.arm.com \
    --to=catalin.marinas@arm.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

all inboxes | Powered by JetHome®