aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMinchan Kim <minchan@kernel.org>2017-01-10 19:58:21 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2017-01-10 21:31:55 -0500
commitb09ab054b69b07077bd3292f67e777861ac796e5 (patch)
treeac9dfa56c3fc89a908eb97c6cc491236637cf93e
parente7ccfc4ccb703e0f033bd4617580039898e912dd (diff)
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: da9556a2367c ("zram: user per-cpu compression streams") Link: http://lkml.kernel.org/r/1482366980-3782-4-git-send-email-minchan@kernel.org Signed-off-by: Minchan Kim <minchan@kernel.org> Reviewed-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Cc: Takashi Iwai <tiwai@suse.de> Cc: Hyeoncheol Lee <cheol.lee@lge.com> Cc: <yjay.kim@lge.com> Cc: Sangseok Lee <sangseok.lee@lge.com> Cc: Hugh Dickins <hughd@google.com> Cc: Darrick J. Wong <darrick.wong@oracle.com> Cc: <stable@vger.kernel.org> [4.7+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/block/zram/zram_drv.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c
index 195376b4472b..e5ab7d9e8c45 100644
--- a/drivers/block/zram/zram_drv.c
+++ b/drivers/block/zram/zram_drv.c
@@ -25,6 +25,7 @@
25#include <linux/genhd.h> 25#include <linux/genhd.h>
26#include <linux/highmem.h> 26#include <linux/highmem.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/backing-dev.h>
28#include <linux/string.h> 29#include <linux/string.h>
29#include <linux/vmalloc.h> 30#include <linux/vmalloc.h>
30#include <linux/err.h> 31#include <linux/err.h>
@@ -112,6 +113,14 @@ static inline bool is_partial_io(struct bio_vec *bvec)
112 return bvec->bv_len != PAGE_SIZE; 113 return bvec->bv_len != PAGE_SIZE;
113} 114}
114 115
116static 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
115/* 124/*
116 * Check if request is within bounds and aligned on zram logical blocks. 125 * Check if request is within bounds and aligned on zram logical blocks.
117 */ 126 */
@@ -1095,7 +1104,7 @@ static ssize_t disksize_store(struct device *dev,
1095 zram->comp = comp; 1104 zram->comp = comp;
1096 zram->disksize = disksize; 1105 zram->disksize = disksize;
1097 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT); 1106 set_capacity(zram->disk, zram->disksize >> SECTOR_SHIFT);
1098 revalidate_disk(zram->disk); 1107 zram_revalidate_disk(zram);
1099 up_write(&zram->init_lock); 1108 up_write(&zram->init_lock);
1100 1109
1101 return len; 1110 return len;
@@ -1143,7 +1152,7 @@ static ssize_t reset_store(struct device *dev,
1143 /* Make sure all the pending I/O are finished */ 1152 /* Make sure all the pending I/O are finished */
1144 fsync_bdev(bdev); 1153 fsync_bdev(bdev);
1145 zram_reset_device(zram); 1154 zram_reset_device(zram);
1146 revalidate_disk(zram->disk); 1155 zram_revalidate_disk(zram);
1147 bdput(bdev); 1156 bdput(bdev);
1148 1157
1149 mutex_lock(&bdev->bd_mutex); 1158 mutex_lock(&bdev->bd_mutex);