Skip to content

Commit b4c5c60

Browse files
minchanktorvalds
authored andcommitted
zram: avoid lockdep splat by revalidate_disk
Sasha reported lockdep warning [1] introduced by [2]. It could be fixed by doing disk revalidation out of the init_lock. It's okay because disk capacity change is protected by init_lock so that revalidate_disk always sees up-to-date value so there is no race. [1] https://lkml.org/lkml/2014/7/3/735 [2] zram: revalidate disk after capacity change Fixes 2e32bae ("zram: revalidate disk after capacity change"). Signed-off-by: Minchan Kim <[email protected]> Reported-by: Sasha Levin <[email protected]> Cc: "Alexander E. Patrakov" <[email protected]> Cc: Nitin Gupta <[email protected]> Cc: Jerome Marchand <[email protected]> Cc: Sergey Senozhatsky <[email protected]> CC: <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent a0f7a75 commit b4c5c60

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,11 +622,18 @@ static void zram_reset_device(struct zram *zram, bool reset_capacity)
622622
memset(&zram->stats, 0, sizeof(zram->stats));
623623

624624
zram->disksize = 0;
625-
if (reset_capacity) {
625+
if (reset_capacity)
626626
set_capacity(zram->disk, 0);
627-
revalidate_disk(zram->disk);
628-
}
627+
629628
up_write(&zram->init_lock);
629+
630+
/*
631+
* Revalidate disk out of the init_lock to avoid lockdep splat.
632+
* It's okay because disk's capacity is protected by init_lock
633+
* so that revalidate_disk always sees up-to-date capacity.
634+
*/
635+
if (reset_capacity)
636+
revalidate_disk(zram->disk);
630637
}
631638

632639
static ssize_t disksize_store(struct device *dev,
@@ -666,8 +673,15 @@ static ssize_t disksize_store(struct device *dev,
666673
zram->comp = comp;
667674
zram->disksize = disksize;
668675
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
669-
revalidate_disk(zram->disk);
670676
up_write(&zram->init_lock);
677+
678+
/*
679+
* Revalidate disk out of the init_lock to avoid lockdep splat.
680+
* It's okay because disk's capacity is protected by init_lock
681+
* so that revalidate_disk always sees up-to-date capacity.
682+
*/
683+
revalidate_disk(zram->disk);
684+
671685
return len;
672686

673687
out_destroy_comp:

0 commit comments

Comments
 (0)