Skip to content

Commit 7e5a510

Browse files
minchankgregkh
authored andcommitted
zram: Fix deadlock bug in partial read/write
Now zram allocates new page with GFP_KERNEL in zram I/O path if IO is partial. Unfortunately, It may cause deadlock with reclaim path like below. write_page from fs fs_lock allocation(GFP_KERNEL) reclaim pageout write_page from fs fs_lock <-- deadlock This patch fixes it by using GFP_NOIO. In read path, we reorganize code flow so that kmap_atomic is called after the GFP_NOIO allocation. Cc: stable@vger.kernel.org Acked-by: Jerome Marchand <jmarchand@redhat.com> Acked-by: Nitin Gupta <ngupta@vflare.org> [ penberg@kernel.org: don't use GFP_ATOMIC ] Signed-off-by: Pekka Enberg <penberg@kernel.org> Signed-off-by: Minchan Kim <minchan@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 7f70410 commit 7e5a510

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

drivers/staging/zram/zram_drv.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,12 @@ static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec,
217217
return 0;
218218
}
219219

220-
user_mem = kmap_atomic(page);
221220
if (is_partial_io(bvec))
222221
/* Use a temporary buffer to decompress the page */
223-
uncmem = kmalloc(PAGE_SIZE, GFP_KERNEL);
224-
else
222+
uncmem = kmalloc(PAGE_SIZE, GFP_NOIO);
223+
224+
user_mem = kmap_atomic(page);
225+
if (!is_partial_io(bvec))
225226
uncmem = user_mem;
226227

227228
if (!uncmem) {
@@ -268,7 +269,7 @@ static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, u32 index,
268269
* This is a partial IO. We need to read the full page
269270
* before to write the changes.
270271
*/
271-
uncmem = kmalloc(PAGE_SIZE, GFP_KERNEL);
272+
uncmem = kmalloc(PAGE_SIZE, GFP_NOIO);
272273
if (!uncmem) {
273274
pr_info("Error allocating temp memory!\n");
274275
ret = -ENOMEM;

0 commit comments

Comments
 (0)