Skip to content

Commit

Permalink
zram: Fix __zram_bvec_{read,write}() locking order
Browse files Browse the repository at this point in the history
Mikhail reported a lockdep spat detailing how __zram_bvec_read() and
__zram_bvec_write() use zstrm->lock and zspage->lock in opposite order.

Reported-by: Mikhail Gavrilov <[email protected]>
Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Tested-by: Mikhail Gavrilov <[email protected]>
Acked-by: Minchan Kim <[email protected]>
Acked-by: Sebastian Andrzej Siewior <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Peter Zijlstra authored and axboe committed Oct 19, 2020
1 parent db07327 commit 0669d2b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions drivers/block/zram/zram_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1218,10 +1218,11 @@ static void zram_free_page(struct zram *zram, size_t index)
static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index,
struct bio *bio, bool partial_io)
{
int ret;
struct zcomp_strm *zstrm;
unsigned long handle;
unsigned int size;
void *src, *dst;
int ret;

zram_slot_lock(zram, index);
if (zram_test_flag(zram, index, ZRAM_WB)) {
Expand Down Expand Up @@ -1252,15 +1253,16 @@ static int __zram_bvec_read(struct zram *zram, struct page *page, u32 index,

size = zram_get_obj_size(zram, index);

if (size != PAGE_SIZE)
zstrm = zcomp_stream_get(zram->comp);

src = zs_map_object(zram->mem_pool, handle, ZS_MM_RO);
if (size == PAGE_SIZE) {
dst = kmap_atomic(page);
memcpy(dst, src, PAGE_SIZE);
kunmap_atomic(dst);
ret = 0;
} else {
struct zcomp_strm *zstrm = zcomp_stream_get(zram->comp);

dst = kmap_atomic(page);
ret = zcomp_decompress(zstrm, src, size, dst);
kunmap_atomic(dst);
Expand Down

0 comments on commit 0669d2b

Please sign in to comment.