From nobody Fri Oct 2 01:56:24 2026 Received: from mail-pf1-f176.google.com (mail-pf1-f176.google.com [209.85.210.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1727E1D63F3 for ; Thu, 6 Aug 2026 03:16:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785986210; cv=none; b=m6S9MK4PE/08eELX4VqGWz53Wnuzkq9e7KYTNPjHxxLCASCxno2W70vg4VWPFGQCdX82Tj09TSQZsmNOcAdtCvEfIM4c251So1PkKJG0VGDZkeGDM0WUhvZGTt9GQc8mBFRA00K3rmFbK+X1y99RTmxOMHtDUYOxnlIAFaqeSRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785986210; c=relaxed/simple; bh=RF7iVdvejG0KIkTleZoHOTi63b55T799Z7z64kHVEXE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=M+mp1vB2stCUsmRoMicGvWsgrYkcrmh01k+fQUe47vN+7eXA5cAqHR/9BGLMUiUAu8AEWEm4sEtlTQWWBb/iKWxSrwWPDvGLCUKgJTlphtX+GaHbWkzs0quVSX51xjp4jcNLMDLXABh9LnIdv/TSS35HrBHhjnLG74U1b1i36kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=TO5MpKGs; arc=none smtp.client-ip=209.85.210.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="TO5MpKGs" Received: by mail-pf1-f176.google.com with SMTP id d2e1a72fcca58-8487b7b3fc8so2044953b3a.3 for ; Wed, 05 Aug 2026 20:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1785986207; x=1786591007; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=bQKutsuyXmC3mcIgGGyZh8v3K7WcGuLFo1jhwq9sGxU=; b=TO5MpKGs187q5TfXt2fBUgtJnO9s6V3oSMqhC+nqFgK6Jbe3PJ44/Tyi+TNMOnQ4DE nDtWCIEvyToDbGHRgNVSCzZ1bGafba+HRy1vuhdnzKPfHZac9/K2pL+DfQSPsnwe78dz 0eO+qUJ/wLel7YIjhyF3/P+Jb/jVNX/bayhDs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785986207; x=1786591007; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bQKutsuyXmC3mcIgGGyZh8v3K7WcGuLFo1jhwq9sGxU=; b=AgODJ3VEZCfa//CdTaloVHaR9DvE5Txz7ZqsvrIv5Sexx93OvnXQg1gjD7nZaUZMPM CcecUjs0QN6Q+n+dvX8nbcC9EDOzwLHaSSM89eEx2bCxrI8q/85ddZZLuzoW8kzSmd+f fSGlpjm9G3g6dqJNkWxaOSIZsYIcxRbDKqaQlwmfwRuOepS6RHicfHq828aNfL4ij3IU aE56AgBojgLr9DYSqkeXnDPmnLL81KrT/s6dWwfZbqEo4G5qRLTMiJe3wTGe2oaBwqd9 suGG6NN7Z3fIP3EU1pzRHKkT6cq724Xz80gDwH8Q7Nr1K+br7TI7gi8NnMLsn6vJnq2z 9xcA== X-Forwarded-Encrypted: i=1; AHgh+Rp+zrIcyp/+adDQFjneNCxS0uzbz7lnsydPbsUVqY5YN1RfIPj/ScB/uvEKkvnL93YAd/mhx03mycHoLro=@vger.kernel.org X-Gm-Message-State: AOJu0YybfHH2SN07VD1buwtF2Iti0SkeHiMz0eVYpFuYgo+BHEmOSbgQ 4nTMqJ3cjibq6T5Tbp4RDbl5KQSmdsw+wBDso0kDxjEvhbYAoeqZlaFX4KDWy2jHNw== X-Gm-Gg: AR+sD11PlZ1wmf5DUwj9sUv7uzZLznagxhQD3YCCsktYQ90Vwyj1eG1jh59Wx9H+6R9 Nym6JVZTxVse0KkBpZjlmrRMQqTbf5iYM4rDqyFzc93v9EOHumo2HmnaZjbgqGUD5NmVzVyv9Xh tvh2JF21qh4Joy9i7zSb18/1MYiXBrlZhwYh4GI8IQWetbkeGzjqIZN3hMHegT63rV0WKAnfyzb Ak4TOyJUKDbU0Y1GDU5/xWMqA3ST8TzNvaAk3E885dX/PAp/Zr74tXPX9yzRbsaVvYtdNfLki+4 JG3aIf5T5ilARuTPn7qhoqMOcHI4XEVlWn9ZQ09XwjAAsGBqJVR/zJdCDm8fb/gmcxEeJoCFr+Q vNAD03bvn9EzmruLFOaf55YN03xQRw12A+Vwd3k5mRv+2Aufzm6b/EJ+wrgNlfVlxyeQ+iToxVu D0X5V/m9frPLKtkuqKWWDvnq0mdf+x6cB5pxCwV/FuWwXmMkS2yBSO1PMxHTrkLWeZl2YslBfId Q6E0lFA2k8b1FoY1bbsxUqnss7oyvy0LinY37IMm8uDv1kXt+dg X-Received: by 2002:a05:6a00:94e7:b0:848:3f91:da82 with SMTP id d2e1a72fcca58-84f2e12c1fcmr13358442b3a.32.1785986207378; Wed, 05 Aug 2026 20:16:47 -0700 (PDT) Received: from tigeriii.tok.corp.google.com ([2a00:79e0:2031:6:8002:2a47:a704:5a58]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-84f45bc9facsm373901b3a.60.2026.08.05.20.16.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 20:16:46 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton Cc: Longlong Xia , Minchan Kim , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@vger.kernel.org, Sergey Senozhatsky Subject: [PATCH] zram: switch to unsigned long indexing Date: Thu, 6 Aug 2026 12:16:32 +0900 Message-ID: <20260806031640.536615-1-senozhatsky@chromium.org> X-Mailer: git-send-email 2.55.0.629.g250fe7f194-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" zram has always used "unsigned int" for (page) index calculations, which unnecessarily limited max zram disksize. Switch to "unsigned long" and permit much larger zram devices. Suggested-by: Andrew Morton Co-developed-by: Longlong Xia Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 137 +++++++++++++++++++--------------- 1 file changed, 77 insertions(+), 60 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 56183c827e1b..6af977dbc6fd 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -56,7 +56,7 @@ static size_t huge_class_size; =20 static const struct block_device_operations zram_devops; =20 -static void slot_free(struct zram *zram, u32 index); +static void slot_free(struct zram *zram, unsigned long index); =20 /* * entry locking rules: @@ -70,7 +70,7 @@ static void slot_free(struct zram *zram, u32 index); * 4) Use TRY lock variant when in atomic context * - must check return value and handle locking failers */ -static __must_check bool slot_trylock(struct zram *zram, u32 index) +static __must_check bool slot_trylock(struct zram *zram, unsigned long ind= ex) { unsigned long *lock =3D &zram->table[index].__lock; =20 @@ -83,7 +83,7 @@ static __must_check bool slot_trylock(struct zram *zram, = u32 index) return false; } =20 -static void slot_lock(struct zram *zram, u32 index) +static void slot_lock(struct zram *zram, unsigned long index) { unsigned long *lock =3D &zram->table[index].__lock; =20 @@ -92,7 +92,7 @@ static void slot_lock(struct zram *zram, u32 index) lock_acquired(&zram->table_lock_map, _RET_IP_); } =20 -static void slot_unlock(struct zram *zram, u32 index) +static void slot_unlock(struct zram *zram, unsigned long index) { unsigned long *lock =3D &zram->table[index].__lock; =20 @@ -110,55 +110,56 @@ static inline struct zram *dev_to_zram(struct device = *dev) return (struct zram *)dev_to_disk(dev)->private_data; } =20 -static unsigned long get_slot_handle(struct zram *zram, u32 index) +static unsigned long get_slot_handle(struct zram *zram, unsigned long inde= x) { return zram->table[index].handle; } =20 -static void set_slot_handle(struct zram *zram, u32 index, unsigned long ha= ndle) +static void set_slot_handle(struct zram *zram, unsigned long index, + unsigned long handle) { zram->table[index].handle =3D handle; } =20 -static bool test_slot_flag(struct zram *zram, u32 index, +static bool test_slot_flag(struct zram *zram, unsigned long index, enum zram_pageflags flag) { return zram->table[index].attr.flags & BIT(flag); } =20 -static void set_slot_flag(struct zram *zram, u32 index, +static void set_slot_flag(struct zram *zram, unsigned long index, enum zram_pageflags flag) { zram->table[index].attr.flags |=3D BIT(flag); } =20 -static void clear_slot_flag(struct zram *zram, u32 index, +static void clear_slot_flag(struct zram *zram, unsigned long index, enum zram_pageflags flag) { zram->table[index].attr.flags &=3D ~BIT(flag); } =20 -static size_t get_slot_size(struct zram *zram, u32 index) +static size_t get_slot_size(struct zram *zram, unsigned long index) { return zram->table[index].attr.flags & (BIT(ZRAM_FLAG_SHIFT) - 1); } =20 -static void set_slot_size(struct zram *zram, u32 index, size_t size) +static void set_slot_size(struct zram *zram, unsigned long index, size_t s= ize) { unsigned long flags =3D zram->table[index].attr.flags >> ZRAM_FLAG_SHIFT; =20 zram->table[index].attr.flags =3D (flags << ZRAM_FLAG_SHIFT) | size; } =20 -static inline bool slot_allocated(struct zram *zram, u32 index) +static inline bool slot_allocated(struct zram *zram, unsigned long index) { return get_slot_size(zram, index) || test_slot_flag(zram, index, ZRAM_SAME) || test_slot_flag(zram, index, ZRAM_WB); } =20 -static inline void set_slot_comp_priority(struct zram *zram, u32 index, - u32 prio) +static inline void set_slot_comp_priority(struct zram *zram, + unsigned long index, u32 prio) { prio &=3D ZRAM_COMP_PRIORITY_MASK; /* @@ -170,14 +171,14 @@ static inline void set_slot_comp_priority(struct zram= *zram, u32 index, zram->table[index].attr.flags |=3D (prio << ZRAM_COMP_PRIORITY_BIT1); } =20 -static inline u32 get_slot_comp_priority(struct zram *zram, u32 index) +static inline u32 get_slot_comp_priority(struct zram *zram, unsigned long = index) { u32 prio =3D zram->table[index].attr.flags >> ZRAM_COMP_PRIORITY_BIT1; =20 return prio & ZRAM_COMP_PRIORITY_MASK; } =20 -static void mark_slot_accessed(struct zram *zram, u32 index) +static void mark_slot_accessed(struct zram *zram, unsigned long index) { clear_slot_flag(zram, index, ZRAM_IDLE); clear_slot_flag(zram, index, ZRAM_PP_SLOT); @@ -284,7 +285,7 @@ static void release_pp_ctl(struct zram *zram, struct zr= am_pp_ctl *ctl) } =20 static bool place_pp_slot(struct zram *zram, struct zram_pp_ctl *ctl, - u32 index) + unsigned long index) { struct zram_pp_slot *pps; u32 bid; @@ -418,7 +419,7 @@ static void mark_idle(struct zram *zram, ktime_t cutoff) { int is_idle =3D 1; unsigned long nr_pages =3D zram->disksize >> PAGE_SHIFT; - int index; + unsigned long index; =20 for (index =3D 0; index < nr_pages; index++) { /* @@ -485,8 +486,9 @@ static ssize_t idle_store(struct device *dev, struct de= vice_attribute *attr, #define INVALID_BDEV_BLOCK (~0UL) =20 static int read_from_zspool_raw(struct zram *zram, struct page *page, - u32 index); -static int read_from_zspool(struct zram *zram, struct page *page, u32 inde= x); + unsigned long index); +static int read_from_zspool(struct zram *zram, struct page *page, + unsigned long index); =20 struct zram_wb_ctl { /* idle list is accessed only by the writeback task, no concurency */ @@ -522,7 +524,7 @@ struct zram_rb_req { /* error status (sync read) */ int error; }; - u32 index; + unsigned long index; }; =20 #define FOUR_K(x) ((x) * (1 << (PAGE_SHIFT - 12))) @@ -910,7 +912,7 @@ static void zram_account_writeback_submit(struct zram *= zram) =20 static int zram_writeback_complete(struct zram *zram, struct zram_wb_req *= req) { - u32 index =3D req->pps->index; + unsigned long index =3D req->pps->index; int err; =20 err =3D blk_status_to_errno(req->bio.bi_status); @@ -1032,7 +1034,7 @@ static int zram_writeback_slots(struct zram *zram, struct zram_wb_req *req =3D NULL; struct zram_pp_slot *pps; int ret =3D 0, err =3D 0; - u32 index =3D 0; + unsigned long index =3D 0; =20 while ((pps =3D select_pp_slot(ctl))) { if (zram->wb_limit_enable && !zram->bd_wb_limit) { @@ -1198,7 +1200,7 @@ static void scan_slots_for_writeback(struct zram *zra= m, u32 mode, unsigned long lo, unsigned long hi, struct zram_pp_ctl *ctl) { - u32 index =3D lo; + unsigned long index =3D lo; =20 while (index < hi) { bool ok =3D true; @@ -1235,7 +1237,7 @@ static ssize_t writeback_store(struct device *dev, const char *buf, size_t len) { struct zram *zram =3D dev_to_zram(dev); - u64 nr_pages =3D zram->disksize >> PAGE_SHIFT; + unsigned long nr_pages =3D zram->disksize >> PAGE_SHIFT; unsigned long lo =3D 0, hi =3D nr_pages; struct zram_pp_ctl *pp_ctl =3D NULL; struct zram_wb_ctl *wb_ctl =3D NULL; @@ -1333,7 +1335,8 @@ static ssize_t writeback_store(struct device *dev, return ret; } =20 -static int decompress_bdev_page(struct zram *zram, struct page *page, u32 = index) +static int decompress_bdev_page(struct zram *zram, struct page *page, + unsigned long index) { struct zcomp_strm *zstrm; unsigned int size; @@ -1375,7 +1378,7 @@ static void zram_deferred_decompress(struct work_stru= ct *w) struct zram_rb_req *req =3D container_of(w, struct zram_rb_req, work); struct page *page =3D bio_first_page_all(req->bio); struct zram *zram =3D req->zram; - u32 index =3D req->index; + unsigned long index =3D req->index; int ret; =20 ret =3D decompress_bdev_page(zram, page, index); @@ -1426,7 +1429,7 @@ static void zram_async_read_endio(struct bio *bio) } =20 static int read_from_bdev_async(struct zram *zram, struct page *page, - u32 index, unsigned long blk_idx, + unsigned long index, unsigned long blk_idx, struct bio *parent) { struct zram_rb_req *req; @@ -1476,8 +1479,8 @@ static void zram_sync_read(struct work_struct *w) * chained IO with parent IO in same context, it's a deadlock. To avoid th= at, * use a worker thread context. */ -static int read_from_bdev_sync(struct zram *zram, struct page *page, u32 i= ndex, - unsigned long blk_idx) +static int read_from_bdev_sync(struct zram *zram, struct page *page, + unsigned long index, unsigned long blk_idx) { struct zram_rb_req req; =20 @@ -1496,8 +1499,9 @@ static int read_from_bdev_sync(struct zram *zram, str= uct page *page, u32 index, return decompress_bdev_page(zram, page, index); } =20 -static int read_from_bdev(struct zram *zram, struct page *page, u32 index, - unsigned long blk_idx, struct bio *parent) +static int read_from_bdev(struct zram *zram, struct page *page, + unsigned long index, unsigned long blk_idx, + struct bio *parent) { atomic64_inc(&zram->stats.bd_reads); if (!parent) { @@ -1509,8 +1513,9 @@ static int read_from_bdev(struct zram *zram, struct p= age *page, u32 index, } #else static inline void reset_bdev(struct zram *zram) {}; -static int read_from_bdev(struct zram *zram, struct page *page, u32 index, - unsigned long blk_idx, struct bio *parent) +static int read_from_bdev(struct zram *zram, struct page *page, + unsigned long index, unsigned long blk_idx, + struct bio *parent) { return -EIO; } @@ -1538,7 +1543,8 @@ static ssize_t read_block_state(struct file *file, ch= ar __user *buf, size_t count, loff_t *ppos) { char *kbuf; - ssize_t index, written =3D 0; + unsigned long index; + ssize_t written =3D 0; struct zram *zram =3D file->private_data; unsigned long nr_pages =3D zram->disksize >> PAGE_SHIFT; =20 @@ -1560,7 +1566,7 @@ static ssize_t read_block_state(struct file *file, ch= ar __user *buf, goto next; =20 copied =3D snprintf(kbuf + written, count, - "%12zd %12u.%06d %c%c%c%c%c%c\n", + "%12lu %12u.%06d %c%c%c%c%c%c\n", index, zram->table[index].attr.ac_time, 0, test_slot_flag(zram, index, ZRAM_SAME) ? 's' : '.', test_slot_flag(zram, index, ZRAM_WB) ? 'w' : '.', @@ -1967,8 +1973,8 @@ static ssize_t debug_stat_show(struct device *dev, =20 static void zram_meta_free(struct zram *zram, u64 disksize) { - size_t num_pages =3D disksize >> PAGE_SHIFT; - size_t index; + unsigned long num_pages =3D disksize >> PAGE_SHIFT; + unsigned long index; =20 if (!zram->table) return; @@ -1985,7 +1991,7 @@ static void zram_meta_free(struct zram *zram, u64 dis= ksize) =20 static bool zram_meta_alloc(struct zram *zram, u64 disksize) { - size_t num_pages; + unsigned long num_pages; =20 num_pages =3D disksize >> PAGE_SHIFT; zram->table =3D vzalloc(array_size(num_pages, sizeof(*zram->table))); @@ -2008,7 +2014,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 di= sksize) return true; } =20 -static void slot_free(struct zram *zram, u32 index) +static void slot_free(struct zram *zram, unsigned long index) { unsigned long handle; =20 @@ -2062,7 +2068,7 @@ static void slot_free(struct zram *zram, u32 index) } =20 static int read_same_filled_page(struct zram *zram, struct page *page, - u32 index) + unsigned long index) { void *mem; =20 @@ -2073,7 +2079,7 @@ static int read_same_filled_page(struct zram *zram, s= truct page *page, } =20 static int read_incompressible_page(struct zram *zram, struct page *page, - u32 index) + unsigned long index) { unsigned long handle; void *src, *dst; @@ -2088,7 +2094,8 @@ static int read_incompressible_page(struct zram *zram= , struct page *page, return 0; } =20 -static int read_compressed_page(struct zram *zram, struct page *page, u32 = index) +static int read_compressed_page(struct zram *zram, struct page *page, + unsigned long index) { struct zcomp_strm *zstrm; unsigned long handle; @@ -2113,7 +2120,8 @@ static int read_compressed_page(struct zram *zram, st= ruct page *page, u32 index) } =20 #if defined CONFIG_ZRAM_WRITEBACK -static int read_from_zspool_raw(struct zram *zram, struct page *page, u32 = index) +static int read_from_zspool_raw(struct zram *zram, struct page *page, + unsigned long index) { struct zcomp_strm *zstrm; unsigned long handle; @@ -2145,7 +2153,8 @@ static int read_from_zspool_raw(struct zram *zram, st= ruct page *page, u32 index) * Reads (decompresses if needed) a page from zspool (zsmalloc). * Corresponding ZRAM slot should be locked. */ -static int read_from_zspool(struct zram *zram, struct page *page, u32 inde= x) +static int read_from_zspool(struct zram *zram, struct page *page, + unsigned long index) { if (test_slot_flag(zram, index, ZRAM_SAME) || !get_slot_handle(zram, index)) @@ -2157,8 +2166,8 @@ static int read_from_zspool(struct zram *zram, struct= page *page, u32 index) return read_incompressible_page(zram, page, index); } =20 -static int zram_read_page(struct zram *zram, struct page *page, u32 index, - struct bio *parent) +static int zram_read_page(struct zram *zram, struct page *page, + unsigned long index, struct bio *parent) { int ret; =20 @@ -2180,7 +2189,7 @@ static int zram_read_page(struct zram *zram, struct p= age *page, u32 index, =20 /* Should NEVER happen. Return bio error if it does. */ if (WARN_ON(ret < 0)) - pr_err("Decompression failed! err=3D%d, page=3D%u\n", ret, index); + pr_err("Decompression failed! err=3D%d, page=3D%lu\n", ret, index); =20 return ret; } @@ -2190,7 +2199,7 @@ static int zram_read_page(struct zram *zram, struct p= age *page, u32 index, * always expects a full page for the output. */ static int zram_bvec_read_partial(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset) + unsigned long index, int offset) { struct page *page =3D alloc_page(GFP_NOIO); int ret; @@ -2205,7 +2214,7 @@ static int zram_bvec_read_partial(struct zram *zram, = struct bio_vec *bvec, } =20 static int zram_bvec_read(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset, struct bio *bio) + unsigned long index, int offset, struct bio *bio) { if (is_partial_io(bvec)) return zram_bvec_read_partial(zram, bvec, index, offset); @@ -2213,7 +2222,7 @@ static int zram_bvec_read(struct zram *zram, struct b= io_vec *bvec, } =20 static int write_same_filled_page(struct zram *zram, unsigned long fill, - u32 index) + unsigned long index) { slot_lock(zram, index); slot_free(zram, index); @@ -2228,7 +2237,7 @@ static int write_same_filled_page(struct zram *zram, = unsigned long fill, } =20 static int write_incompressible_page(struct zram *zram, struct page *page, - u32 index) + unsigned long index) { unsigned long handle; void *src; @@ -2268,7 +2277,8 @@ static int write_incompressible_page(struct zram *zra= m, struct page *page, return 0; } =20 -static int zram_write_page(struct zram *zram, struct page *page, u32 index) +static int zram_write_page(struct zram *zram, struct page *page, + unsigned long index) { int ret =3D 0; unsigned long handle; @@ -2335,7 +2345,7 @@ static int zram_write_page(struct zram *zram, struct = page *page, u32 index) * This is a partial IO. Read the full page before writing the changes. */ static int zram_bvec_write_partial(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset) + unsigned long index, int offset) { struct page *page =3D alloc_page(GFP_NOIO); int ret; @@ -2353,7 +2363,7 @@ static int zram_bvec_write_partial(struct zram *zram,= struct bio_vec *bvec, } =20 static int zram_bvec_write(struct zram *zram, struct bio_vec *bvec, - u32 index, int offset) + unsigned long index, int offset) { if (is_partial_io(bvec)) return zram_bvec_write_partial(zram, bvec, index, offset); @@ -2421,8 +2431,9 @@ static void scan_slots_for_recompress(struct zram *zr= am, u32 mode, u32 prio, * * Corresponding ZRAM slot should be locked. */ -static int recompress_slot(struct zram *zram, u32 index, struct page *page, - u64 *num_recomp_pages, u32 threshold, u32 prio) +static int recompress_slot(struct zram *zram, unsigned long index, + struct page *page, u64 *num_recomp_pages, + u32 threshold, u32 prio) { struct zcomp_strm *zstrm =3D NULL; unsigned long handle_old; @@ -2674,7 +2685,7 @@ static ssize_t recompress_store(struct device *dev, static void zram_bio_discard(struct zram *zram, struct bio *bio) { size_t n =3D bio->bi_iter.bi_size; - u32 index =3D bio->bi_iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; + unsigned long index =3D bio->bi_iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; u32 offset =3D (bio->bi_iter.bi_sector & (SECTORS_PER_PAGE - 1)) << SECTOR_SHIFT; =20 @@ -2715,7 +2726,7 @@ static void zram_bio_read(struct zram *zram, struct b= io *bio) struct bvec_iter iter =3D bio->bi_iter; =20 do { - u32 index =3D iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; + unsigned long index =3D iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; u32 offset =3D (iter.bi_sector & (SECTORS_PER_PAGE - 1)) << SECTOR_SHIFT; struct bio_vec bv =3D bio_iter_iovec(bio, iter); @@ -2746,7 +2757,7 @@ static void zram_bio_write(struct zram *zram, struct = bio *bio) struct bvec_iter iter =3D bio->bi_iter; =20 do { - u32 index =3D iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; + unsigned long index =3D iter.bi_sector >> SECTORS_PER_PAGE_SHIFT; u32 offset =3D (iter.bi_sector & (SECTORS_PER_PAGE - 1)) << SECTOR_SHIFT; struct bio_vec bv =3D bio_iter_iovec(bio, iter); @@ -2860,6 +2871,7 @@ static void zram_reset_device(struct zram *zram) static ssize_t disksize_store(struct device *dev, struct device_attribute = *attr, const char *buf, size_t len) { + unsigned long num_pages; u64 disksize; struct zcomp *comp; struct zram *zram =3D dev_to_zram(dev); @@ -2877,6 +2889,11 @@ static ssize_t disksize_store(struct device *dev, st= ruct device_attribute *attr, } =20 disksize =3D PAGE_ALIGN(disksize); + num_pages =3D disksize >> PAGE_SHIFT; + /* Slots are addressed by an unsigned long index */ + if (!num_pages || ((u64)num_pages << PAGE_SHIFT) !=3D disksize) + return -EINVAL; + if (!zram_meta_alloc(zram, disksize)) return -ENOMEM; =20 --=20 2.55.0.629.g250fe7f194-goog