Skip to contentSkip to conversation

net/irda: fix lockdep annotation

PATCH Superseded Dmitry Vyukov 2 participants 3 messages Jan 16, 2017

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net/irda: fix lockdep annotation

The current annotation uses a global variable as recursion counter. The variable is not atomic nor protected with a mutex, but mutated by multiple threads. This causes lockdep bug reports episodically:

BUG: looking up invalid subclass: 4294967295
...
_raw_spin_lock_irqsave_nested+0x120/0x180
hashbin_delete+0x4fe/0x750
__irias_delete_object+0xab/0x170
irias_delete_object+0x5f/0xc0
ircomm_tty_detach_cable+0x1d5/0x3f0

...

Make the hashbin_lock_depth variable atomic to prevent bug reports.

Cc Dave Jones <[email protected]>
Cc Samuel Ortiz <[email protected]>
Cc David S. Miller <[email protected]>
Fixes c7630a4b932af ("[IrDA]: irda lockdep annotation")
---
 net/irda/irqueue.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
net/irda/irqueue.c +7 -5
index acbe61c7e683..b9fd74e6ca99 100644
@@ -384,21 +384,23 @@ EXPORT_SYMBOL(hashbin_new);
  *    just supply kfree, which should take care of the job.
  */
 #ifdef CONFIG_LOCKDEP
-static int hashbin_lock_depth = 0;
+static atomic_t hashbin_lock_depth = ATOMIC_INIT(0);
 #endif
 int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
 {
 	irda_queue_t* queue;
 	unsigned long flags = 0;
-	int i;
+	int i, depth = 0;
 
 	IRDA_ASSERT(hashbin != NULL, return -1;);
 	IRDA_ASSERT(hashbin->magic == HB_MAGIC, return -1;);
 
 	/* Synchronize */
 	if ( hashbin->hb_type & HB_LOCK ) {
-		spin_lock_irqsave_nested(&hashbin->hb_spinlock, flags,
-					 hashbin_lock_depth++);
+#ifdef CONFIG_LOCKDEP
+		depth = atomic_inc_return(&hashbin_lock_depth) - 1;
+#endif
+		spin_lock_irqsave_nested(&hashbin->hb_spinlock, flags, depth);
 	}
 
 	/*
@@ -423,7 +425,7 @@ int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
 	if ( hashbin->hb_type & HB_LOCK) {
 		spin_unlock_irqrestore(&hashbin->hb_spinlock, flags);
 #ifdef CONFIG_LOCKDEP
-		hashbin_lock_depth--;
+		atomic_dec(&hashbin_lock_depth);
 #endif
 	}
 
Signature · 1 line
2.11.0.483.g087da7b7c-goog
#1 lore raw
url: https://github.com/0day-ci/linux/commits/Dmitry-Vyukov/net-irda-fix-lockdep-annotation/20170116-183405 config: x86_64-randconfig-s2-01161850 (attached as .config) compiler: gcc-4.4 (Debian…

Hi Dmitry,

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.10-rc4 next-20170116]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Dmitry-Vyukov/net-irda-fix-lockdep-annotation/20170116-183405
config: x86_64-randconfig-s2-01161850 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7 reproduce:

        # save the attached .config to linux build tree
        make ARCH=x86_64 

All warnings (new ones prefixed by >>):

net/irda/irqueue.c: In function 'hashbin_delete':

>> net/irda/irqueue.c:393: warning: unused variable 'depth'

At top level:
cc1: warning: unrecognized command line option "-Wno-maybe-uninitialized"

vim +/depth +393 net/irda/irqueue.c

377
378
379 /*
380 * Function hashbin_delete (hashbin, free_func)
381 *

   382	 *    Destroy hashbin, the free_func can be a user supplied special routine
   383	 *    for deallocating this structure if it's complex. If not the user can
   384	 *    just supply kfree, which should take care of the job.
   385	 */
   386	#ifdef CONFIG_LOCKDEP
   387	static atomic_t hashbin_lock_depth = ATOMIC_INIT(0);
   388	#endif
   389	int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
   390	{
   391		irda_queue_t* queue;
   392		unsigned long flags = 0;
 > 393		int i, depth = 0;

394
395 IRDA_ASSERT(hashbin != NULL, return -1;);
396 IRDA_ASSERT(hashbin->magic == HB_MAGIC, return -1;);
397
398 /* Synchronize */
399 if ( hashbin->hb_type & HB_LOCK ) {
400 #ifdef CONFIG_LOCKDEP
401 depth = atomic_inc_return(&hashbin_lock_depth) - 1;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
Quoted 10 lines · kbuild test robot

Hi Dmitry,

[auto build test WARNING on net-next/master]
[also build test WARNING on v4.10-rc4 next-20170116]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Dmitry-Vyukov/net-irda-fix-lockdep-annotation/20170116-183405
config: x86_64-randconfig-s2-01161850 (attached as .config)
compiler: gcc-4.4 (Debian 4.4.7-8) 4.4.7 reproduce:

Quoted 7 lines
        # save the attached .config to linux build tree
        make ARCH=x86_64

All warnings (new ones prefixed by >>):

net/irda/irqueue.c: In function 'hashbin_delete':

Quoted 1 line
Quoted 1 line

net/irda/irqueue.c:393: warning: unused variable 'depth'

Mailed v2 with a fix for the warning.

Thanks, 0-DAY!

Quoted 34 lines

At top level:
cc1: warning: unrecognized command line option "-Wno-maybe-uninitialized"

vim +/depth +393 net/irda/irqueue.c

   377
   378
   379  /*
   380   * Function hashbin_delete (hashbin, free_func)
   381   *
   382   *    Destroy hashbin, the free_func can be a user supplied special routine
   383   *    for deallocating this structure if it's complex. If not the user can
   384   *    just supply kfree, which should take care of the job.
   385   */
   386  #ifdef CONFIG_LOCKDEP
   387  static atomic_t hashbin_lock_depth = ATOMIC_INIT(0);
   388  #endif
   389  int hashbin_delete( hashbin_t* hashbin, FREE_FUNC free_func)
   390  {
   391          irda_queue_t* queue;
   392          unsigned long flags = 0;
Quoted 1 line

393 int i, depth = 0;

394

   395          IRDA_ASSERT(hashbin != NULL, return -1;);
   396          IRDA_ASSERT(hashbin->magic == HB_MAGIC, return -1;);
   397
   398          /* Synchronize */
   399          if ( hashbin->hb_type & HB_LOCK ) {
   400  #ifdef CONFIG_LOCKDEP
   401                  depth = atomic_inc_return(&hashbin_lock_depth) - 1;

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation