]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
zram: do not leak blk idx at the end of writeback
authorSergey Senozhatsky <senozhatsky@chromium.org>
Tue, 26 May 2026 02:27:16 +0000 (11:27 +0900)
committerAndrew Morton <akpm@linux-foundation.org>
Thu, 4 Jun 2026 21:45:07 +0000 (14:45 -0700)
zram_writeback_slots() loop can terminate with valid reserved backing
device blk_idx.  The problem is that cleanup code doesn't release that
reserved blk_idx before zram_writeback_slots() returns, which leads to
blk_idx leak (it becomes permanently busy and can not be used for actual
writeback.) This does not lead to any system instabilities, it only means
that we can writeback less pages.  The scenario is hard to hit in practice
as it requires writeabck to race with modification (slot-free or
overwrite) of the final post-processing slot.

Release reserved but unused blk_idx before returning from
zram_writeback_slots().

Link: https://lore.kernel.org/20260526022754.2377730-2-senozhatsky@chromium.org
Fixes: f405066a1f0db ("zram: introduce writeback bio batching")
Signed-off-by: Sergey Senozhatsky <senozhatsky@chromium.org>
Suggested-by: Brian Geffon <bgeffon@google.com>
Cc: Jens Axboe <axboe@kernel.dk>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Richard Chang <richardycc@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
drivers/block/zram/zram_drv.c

index 07111455eecff7ab66b7e2b9c7da2f831b795fbb..602abfe23797e1b151da403da57ccceff3e1654e 100644 (file)
@@ -1127,6 +1127,9 @@ next:
        if (req)
                release_wb_req(req);
 
+       if (blk_idx != INVALID_BDEV_BLOCK)
+               zram_release_bdev_block(zram, blk_idx);
+
        while (atomic_read(&wb_ctl->num_inflight) > 0) {
                wait_event(wb_ctl->done_wait, !list_empty(&wb_ctl->done_reqs));
                err = zram_complete_done_reqs(zram, wb_ctl);