Skip to content

Commit

Permalink
block: fix bd_size_lock use
Browse files Browse the repository at this point in the history
Some block device drivers, e.g. the skd driver, call set_capacity() with
IRQ disabled. This results in lockdep ito complain about inconsistent
lock states ("inconsistent {HARDIRQ-ON-W} -> {IN-HARDIRQ-W} usage")
because set_capacity takes a block device bd_size_lock using the
functions spin_lock() and spin_unlock(). Ensure a consistent locking
state by replacing these calls with spin_lock_irqsave() and
spin_lock_irqrestore(). The same applies to bdev_set_nr_sectors().
With this fix, all lockdep complaints are resolved.

Signed-off-by: Damien Le Moal <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
damien-lemoal authored and axboe committed Jan 28, 2021
1 parent 6c635ca commit 0fe3772
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ static void disk_release_events(struct gendisk *disk);
void set_capacity(struct gendisk *disk, sector_t sectors)
{
struct block_device *bdev = disk->part0;
unsigned long flags;

spin_lock(&bdev->bd_size_lock);
spin_lock_irqsave(&bdev->bd_size_lock, flags);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
spin_unlock(&bdev->bd_size_lock);
spin_unlock_irqrestore(&bdev->bd_size_lock, flags);
}
EXPORT_SYMBOL(set_capacity);

Expand Down
6 changes: 4 additions & 2 deletions block/partitions/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ static int (*check_part[])(struct parsed_partitions *) = {

static void bdev_set_nr_sectors(struct block_device *bdev, sector_t sectors)
{
spin_lock(&bdev->bd_size_lock);
unsigned long flags;

spin_lock_irqsave(&bdev->bd_size_lock, flags);
i_size_write(bdev->bd_inode, (loff_t)sectors << SECTOR_SHIFT);
spin_unlock(&bdev->bd_size_lock);
spin_unlock_irqrestore(&bdev->bd_size_lock, flags);
}

static struct parsed_partitions *allocate_partitions(struct gendisk *hd)
Expand Down

0 comments on commit 0fe3772

Please sign in to comment.