remarkable-linux/drivers
Nikanth Karthikesan f028f3b2f9 loop: fix circular locking in loop_clr_fd()
With CONFIG_PROVE_LOCKING enabled

$ losetup /dev/loop0 file
$ losetup -o 32256 /dev/loop1 /dev/loop0

$ losetup -d /dev/loop1
$ losetup -d /dev/loop0

triggers a [ INFO: possible circular locking dependency detected ]

I think this warning is a false positive.

Open/close on a loop device acquires bd_mutex of the device before
acquiring lo_ctl_mutex of the same device. For ioctl(LOOP_CLR_FD) after
acquiring lo_ctl_mutex, fput on the backing_file might acquire the bd_mutex of
a device, if backing file is a device and this is the last reference to the
file being dropped . But it is guaranteed that it is impossible to have a
circular list of backing devices.(say loop2->loop1->loop0->loop2 is not
possible), which guarantees that this can never deadlock.

So this warning should be suppressed. It is very difficult to annotate lockdep
not to warn here in the correct way. A simple way to silence lockdep could be
to mark the lo_ctl_mutex in ioctl to be a sub class, but this might mask some
other real bugs.

@@ -1164,7 +1164,7 @@ static int lo_ioctl(struct block_device *bdev, fmode_t mode,
 	struct loop_device *lo = bdev->bd_disk->private_data;
 	int err;

-	mutex_lock(&lo->lo_ctl_mutex);
+	mutex_lock_nested(&lo->lo_ctl_mutex, 1);
 	switch (cmd) {
 	case LOOP_SET_FD:
 		err = loop_set_fd(lo, mode, bdev, arg);

Or actually marking the bd_mutex after lo_ctl_mutex as a sub class could be
a better solution.

Luckily it is easy to avoid calling fput on backing file with lo_ctl_mutex
held, so no lockdep annotation is required.

If you do not like the special handling of the lo_ctl_mutex just for the
LOOP_CLR_FD ioctl in lo_ioctl(), the mutex handling could be moved inside
each of the individual ioctl handlers and I could send you another patch.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
2009-03-26 11:01:19 +01:00
..
accessibility
acpi acpi: check for pxm_to_node_map overflow 2009-03-16 00:35:30 -04:00
amba
ata ata_piix: add workaround for Samsung DB-P70 2009-03-13 14:56:07 -04:00
atm
auxdisplay
base mm: get_nid_for_pfn() returns int 2009-03-10 15:55:10 -07:00
block loop: fix circular locking in loop_clr_fd() 2009-03-26 11:01:19 +01:00
bluetooth
cdrom
char parisc: remove klist iterators 2009-03-13 01:16:58 -04:00
clocksource
connector
cpufreq Revert "[CPUFREQ] Disable sysfs ui for p4-clockmod." 2009-03-09 15:07:33 -04:00
cpuidle
crypto crypto: ixp4xx - Fix qmgr_request_queue build failure 2009-03-04 08:01:22 +08:00
dca Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6 2009-03-23 09:25:58 -07:00
dio
dma Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/djbw/async_tx 2009-03-08 10:23:05 -07:00
edac
eisa
firewire
firmware
gpio
gpu drm/i915: fix 945 fence register writes for fence 8 and above. 2009-03-11 11:02:06 -07:00
hid Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid 2009-03-19 14:50:15 -07:00
hwmon hwmon: (f75375s) Remove unnecessary and confusing initialization 2009-03-12 13:36:39 +01:00
i2c Merge master.kernel.org:/home/rmk/linux-2.6-arm 2009-03-03 14:12:41 -08:00
ide ide: save the returned value of dma_map_sg 2009-03-13 21:16:13 +01:00
idle
ieee1394 Make ieee1394_init a fs-initcall 2009-02-26 10:32:31 -08:00
infiniband RDMA/nes: Don't allow userspace QPs to use STag zero 2009-03-12 16:21:41 -07:00
input Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input 2009-03-02 15:43:03 -08:00
isdn bas_gigaset: correctly allocate USB interrupt transfer buffer 2009-03-18 23:44:23 -07:00
leds
lguest lguest: fix for CONFIG_SPARSE_IRQ=y 2009-03-09 10:06:29 +10:30
macintosh
mca
md dm crypt: wait for endio to complete before destruction 2009-03-16 17:44:36 +00:00
media V4L/DVB (10978): Report tuning algorith correctly 2009-03-13 13:19:42 -03:00
memstick
message [SCSI] mpt: fix disable lsi sas to use msi as default 2009-02-22 08:51:07 -06:00
mfd mfd: add support for WM8351 revision B 2009-03-12 16:20:24 -07:00
misc hpilo: new pci device 2009-02-27 16:26:22 -08:00
mmc mmc: s3cmci: fix s3c2410_dma_config() arguments. 2009-03-12 16:20:24 -07:00
mtd ps3/block: Replace mtd/ps3vram by block/ps3vram 2009-03-13 16:07:19 +11:00
net Merge git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-2.6 2009-03-23 09:25:58 -07:00
nubus
of
oprofile
parisc parisc: sba_iommu: fix build bug when CONFIG_PARISC_AGP=y 2009-03-15 13:36:22 -07:00
parport m68k: atari - Rename "mfp" to "st_mfp" 2009-02-22 09:23:02 -08:00
pci PCIe: portdrv: call pci_disable_device during remove 2009-03-12 15:42:35 -04:00
pcmcia
platform acpi-wmi: unsigned cannot be less than 0 2009-03-16 00:38:24 -04:00
pnp
power ds2760_battery.c: fix division by zero 2009-03-12 16:20:23 -07:00
ps3
rapidio
regulator
rtc
s390
sbus sbus: Auto-load openprom module when device opened. 2009-03-13 14:30:08 -07:00
scsi Merge git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi-rc-fixes-2.6 2009-03-14 12:01:37 -07:00
serial Merge branch 'sh/for-2.6.29' of git://git.kernel.org/pub/scm/linux/kernel/git/lethal/sh-2.6 2009-02-27 16:40:00 -08:00
sh
sn
spi
ssb
staging Staging: benet: remove driver now that it is merged in drivers/net/ 2009-03-18 09:22:17 -07:00
tc
telephony
thermal
uio
usb USB: storage: Unusual USB device Prolific 2507 variation added 2009-03-17 14:01:29 -07:00
uwb
video radeonfb: Whack the PCI PM register until it sticks 2009-03-22 11:08:53 -07:00
virtio
w1 drivers/w1/masters/w1-gpio.c: fix read_bit() 2009-03-12 16:20:23 -07:00
watchdog [WATCHDOG] orion5x_wdt.c: 'ORION5X_TCLK' undeclared 2009-03-05 19:25:05 +00:00
xen PM: Split up sysdev_[suspend|resume] from device_power_[down|up] 2009-02-22 10:33:44 -08:00
zorro
Kconfig
Makefile