Skip to content

Commit b09ab05

Browse files
minchanktorvalds
authored andcommitted
zram: support BDI_CAP_STABLE_WRITES
zram has used per-cpu stream feature from v4.7. It aims for increasing cache hit ratio of scratch buffer for compressing. Downside of that approach is that zram should ask memory space for compressed page in per-cpu context which requires stricted gfp flag which could be failed. If so, it retries to allocate memory space out of per-cpu context so it could get memory this time and compress the data again, copies it to the memory space. In this scenario, zram assumes the data should never be changed but it is not true without stable page support. So, If the data is changed under us, zram can make buffer overrun so that zsmalloc free object chain is broken so system goes crash like below https://bugzilla.suse.com/show_bug.cgi?id=997574 This patch adds BDI_CAP_STABLE_WRITES to zram for declaring "I am block device needing *stable write*". Fixes: da9556a ("zram: user per-cpu compression streams") Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Minchan Kim <[email protected]> Reviewed-by: Sergey Senozhatsky <[email protected]> Cc: Takashi Iwai <[email protected]> Cc: Hyeoncheol Lee <[email protected]> Cc: <[email protected]> Cc: Sangseok Lee <[email protected]> Cc: Hugh Dickins <[email protected]> Cc: Darrick J. Wong <[email protected]> Cc: <[email protected]> [4.7+] Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent e7ccfc4 commit b09ab05

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

drivers/block/zram/zram_drv.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/genhd.h>
2626
#include <linux/highmem.h>
2727
#include <linux/slab.h>
28+
#include <linux/backing-dev.h>
2829
#include <linux/string.h>
2930
#include <linux/vmalloc.h>
3031
#include <linux/err.h>
@@ -112,6 +113,14 @@ static inline bool is_partial_io(struct bio_vec *bvec)
112113
return bvec->bv_len != PAGE_SIZE;
113114
}
114115

116+
static void zram_revalidate_disk(struct zram *zram)
117+
{
118+
revalidate_disk(zram->disk);
119+
/* revalidate_disk reset the BDI_CAP_STABLE_WRITES so set again */
120+
zram->disk->queue->backing_dev_info.capabilities |=
121+
BDI_CAP_STABLE_WRITES;
122+
}
123+
115124
/*
116125
* Check if request is within bounds and aligned on zram logical blocks.
117126
*/
@@ -1095,7 +1104,7 @@ static ssize_t disksize_store(struct device *dev,
10951104
zram->comp = comp;
10961105
zram->disksize = disksize;
10971106
set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
1098-
revalidate_disk(zram->disk);
1107+
zram_revalidate_disk(zram);
10991108
up_write(&zram->init_lock);
11001109

11011110
return len;
@@ -1143,7 +1152,7 @@ static ssize_t reset_store(struct device *dev,
11431152
/* Make sure all the pending I/O are finished */
11441153
fsync_bdev(bdev);
11451154
zram_reset_device(zram);
1146-
revalidate_disk(zram->disk);
1155+
zram_revalidate_disk(zram);
11471156
bdput(bdev);
11481157

11491158
mutex_lock(&bdev->bd_mutex);

0 commit comments

Comments
 (0)