Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753778Ab0LTHHM (ORCPT ); Mon, 20 Dec 2010 02:07:12 -0500 Received: from mail-ww0-f44.google.com ([74.125.82.44]:64156 "EHLO mail-ww0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753668Ab0LTHHK convert rfc822-to-8bit (ORCPT ); Mon, 20 Dec 2010 02:07:10 -0500 DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=Ojt8uKeXrvuEehRPgyLO2bW14akrQWNLimPHwykcvg4gRMzRNPjqRxgpw0qeWQ8iks oHYGgESBoVI3pUKBZNFMIqUc67QLkfwrlNTR5jKrKFcOKuwQQaaKZpYXazrBh7OsL5KS ZeFdJMWvARp42tJBGE7lvBOniK/CCVg1KgC58= MIME-Version: 1.0 In-Reply-To: <1292762975.2403.29.camel@localhost> References: <1292762975.2403.29.camel@localhost> Date: Mon, 20 Dec 2010 15:07:09 +0800 Message-ID: Subject: Re: [PATCH] kthread_worker: Initialize dynamically allocated spinlock properly for lockdep From: Yong Zhang To: Andy Walls Cc: linux-kernel@vger.kernel.org, nicolas.mailhot@laposte.net, Tejun Heo , Jarod Wilson , Ingo Molnar , Mauro Carvalho Chehab , Hans Verkuil Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2274 Lines: 62 On Sun, Dec 19, 2010 at 8:49 PM, Andy Walls wrote: > init_kthread_worker(), via KTHREAD_WORKER_INIT(), used an > initializer for static spin_lock objects, SPIN_LOCK_UNLOCKED, on > a dynamically allocated kthread_worker object's internal spinlock_t. > This causes lockdep to gripe: > >        INFO: trying to register non-static key. >        the code is fine but needs lockdep annotation. >        turning off the locking correctness validator. > > To keep lockdep happy, use spin_lock_init() for dynamically > allocated kthread_worker objects' internal spinlock_t. > > Reported-by: Nicolas > Signed-off-by: Andy Walls > > Cc: Tejun Heo > Cc: Jarod Wilson > Cc: Ingo Molnar > Cc: Mauro Carvalho Chehab > Cc: Hans Verkuil > > diff --git a/include/linux/kthread.h b/include/linux/kthread.h > index 685ea65..e65d0b1 100644 > --- a/include/linux/kthread.h > +++ b/include/linux/kthread.h > @@ -83,7 +83,13 @@ struct kthread_work { > >  static inline void init_kthread_worker(struct kthread_worker *worker) >  { > -       *worker = (struct kthread_worker)KTHREAD_WORKER_INIT(*worker); > +       /* > +        * Lockdep complains if a dynamically allocated worker's spinlock_t > +        * is initialzed using SPIN_LOCK_UNLOCKED. > +        */ > +       spin_lock_init(&worker->lock); This will make different kthead_worker->lock initialized with one same key. You know spin_lock_init() will be like below: # define raw_spin_lock_init(lock) \ do { \ static struct lock_class_key __key; \ \ __raw_spin_lock_init((lock), #lock, &__key); \ } while (0) So we should put the real initializer to kernel/kthread.c and make init_kthread_worker() to be a MACRO. BTW, init_kthread_work() should also be changed like above because member done is a wait_queue_head. Thanks, Yong -- Only stand for myself. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/