Skip to contentSkip to conversation

kernel analyser to detect sleep under spinlock

DISCUSSION Peter T. Breuer 3 participants 3 messages Nov 13, 2004 – Nov 14, 2004

lore
Share & tools
lore
#0 lore raw
Quoted 1 line · Peter T. Breuer

I've added some extra support for gcc 3.4.0 [...]

And now kernel 2.6 files seem to be being parsed OK too.

% ./c -nostdinc -iwithprefix include -D__KERNEL__ -I/usr/local/src/linux-2.6.3/include -D__KERNEL__ -Wall -Wstrict-prototypes -Wno-trigraphs -I/usr/local/src/linux-2.6.3/include/asm-i386/mach-default -O2 -DMODULE -DKBUILD_BASENAME=nbd -DKBUILD_MODNAME=nbd /usr/local/src/linux-2.6.3/drivers/block/nbd.c *************** sleep calls ************************************
* function line calls (locks)
*
* - /usr/local/src/linux-2.6.3/include/linux/fs.h
* lock_super 741 down (0)
*
* - /usr/local/src/linux-2.6.3/include/net/sock.h
* sk_filter_release 710 kfree (0)
*
* - /usr/local/src/linux-2.6.3/drivers/block/nbd.c

*  nbd_send_req                 264     down (0)
*  do_nbd_request               510     nbd_send_req (-1)
*  nbd_ioctl                    569     nbd_send_req (-1)
*  nbd_ioctl                    574     down (0)

*
*
* *** found 0 instances of sleep under spinlock *** *
***************************************************************

Archive at:

ftp://oboe.it.uc3m.es/pub/Programs/c-1.2.2.tgz

GPL, LGPL, etc.

This is also useful for locating functions which can sleep, though of course that can be done in other ways.

This utility works by applying a programming logic to the code semantics. That bit's fine. What it's not so great at is resolving C references back to the correct declaration, which results in under-reporting. I'll improve that (mumbles, register actions to be carried out whenever anything changes in the fact database instead of coding the inferences by hand).

I'll undertake a survey of the current kernel.

Peter (ptb (at) inv.it.uc3m.es)

#1 lore raw
Quoted 1 line · Peter T. Breuer

I'll undertake a survey of the current kernel.

Just for kicks, I started with the DAC960.c driver (alphabet ..), and it registered 6 alarms!

Linux Driver for Mylex DAC960/AcceleRAID/eXtremeRAID PCI RAID Controllers

Copyright 1998-2001 by Leonard N. Zubkoff <[email protected]>

* function line calls (locks)
* - /usr/local/src/linux-2.6.3/drivers/block/DAC960.c
!! DAC960_BA_InterruptHandler 5219 DAC960_V2_ProcessCompletedCommand (1)
!! DAC960_LP_InterruptHandler 5262 DAC960_V2_ProcessCompletedCommand (1)

!! DAC960_V1_ExecuteUserCommand 5869    DAC960_WaitForCommand (1)
!! DAC960_V2_ExecuteUserCommand 6132    DAC960_WaitForCommand (1)
!! DAC960_gam_ioctl             6663    DAC960_WaitForCommand (1)
!! DAC960_gam_ioctl             6688    DAC960_WaitForCommand (1)

The ProcessCompletedCommand thing really is called under spinlock, but it appears to be detected as sleepy because it calls kmalloc (and kfree), however it calls kmalloc with GFP_ATOMIC, so it's not sleepy and that's a false alarm. Ho hum ... I'll have to detect that.

The WaitForCommand is also definitely called under spinlock ... and is thought to be sleepy because it calls schedule! Well, it calls __wait_event(Controller->CommandWaitQueue, Controller->FreeCommands); Is that going to schedule? I suppose logically it should.

Anyway, that looks a legitimate complaint:

  spin_lock_irqsave(&Controller->queue_lock, flags);
  while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
    DAC960_WaitForCommand(Controller);
  spin_unlock_irqrestore(&Controller->queue_lock, flags);

Looks like it waits under spinlock to me!

I'll go write the generic inference engine required to make this a bit more accurate still.

Peter

#2 lore raw
Quoted 29 lines · Peter T. Breuer
Quoted 1 line · Peter T. Breuer

I'll undertake a survey of the current kernel.

Just for kicks, I started with the DAC960.c driver (alphabet ..), and it registered 6 alarms!

Linux Driver for Mylex DAC960/AcceleRAID/eXtremeRAID PCI RAID Controllers

Copyright 1998-2001 by Leonard N. Zubkoff <[email protected]>

* function line calls (locks)
* - /usr/local/src/linux-2.6.3/drivers/block/DAC960.c
!! DAC960_BA_InterruptHandler 5219 DAC960_V2_ProcessCompletedCommand (1)
!! DAC960_LP_InterruptHandler 5262 DAC960_V2_ProcessCompletedCommand (1)

!! DAC960_V1_ExecuteUserCommand 5869    DAC960_WaitForCommand (1)
!! DAC960_V2_ExecuteUserCommand 6132    DAC960_WaitForCommand (1)
!! DAC960_gam_ioctl             6663    DAC960_WaitForCommand (1)
!! DAC960_gam_ioctl             6688    DAC960_WaitForCommand (1)

The ProcessCompletedCommand thing really is called under spinlock, but it appears to be detected as sleepy because it calls kmalloc (and kfree), however it calls kmalloc with GFP_ATOMIC, so it's not sleepy and that's a false alarm. Ho hum ... I'll have to detect that.

The WaitForCommand is also definitely called under spinlock ... and is thought to be sleepy because it calls schedule! Well, it calls __wait_event(Controller->CommandWaitQueue, Controller->FreeCommands); Is that going to schedule? I suppose logically it should.

Quoted 8 lines

Anyway, that looks a legitimate complaint:

  spin_lock_irqsave(&Controller->queue_lock, flags);
  while ((Command = DAC960_AllocateCommand(Controller)) == NULL)
    DAC960_WaitForCommand(Controller);
  spin_unlock_irqrestore(&Controller->queue_lock, flags);

Looks like it waits under spinlock to me!

static void DAC960_WaitForCommand(DAC960_Controller_T *Controller) {
spin_unlock_irq(&Controller->queue_lock); __wait_event(Controller->CommandWaitQueue, Controller->FreeCommands); spin_lock_irq(&Controller->queue_lock);
}

Looks alright to me, I don't understand your confusion. One thing you could say is that either the path to DAC960_WaitForCommand should not save interrupt flags, _or_ it's a bug to use spin_unlock_irq() if interrutps could already be disabled at that point.

Signature · 1 line
Jens Axboe