All of lore.kernel.org
 help / color / mirror / Atom feed
* + zram-fix-the-issue-that-the-write-back-limits-might-overflow.patch added to mm-new branch
@ 2025-11-20  0:24 Andrew Morton
  2025-11-21  4:09 ` Sergey Senozhatsky
  0 siblings, 1 reply; 2+ messages in thread
From: Andrew Morton @ 2025-11-20  0:24 UTC (permalink / raw)
  To: mm-commits, senozhatsky, richardycc, minchan, bgeffon, ywen.chen,
	akpm


The patch titled
     Subject: zram: fix the issue that the write - back limits might overflow
has been added to the -mm mm-new branch.  Its filename is
     zram-fix-the-issue-that-the-write-back-limits-might-overflow.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/zram-fix-the-issue-that-the-write-back-limits-might-overflow.patch

This patch will later appear in the mm-new branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Note, mm-new is a provisional staging ground for work-in-progress
patches, and acceptance into mm-new is a notification for others take
notice and to finish up reviews.  Please do not hesitate to respond to
review feedback and post updated versions to replace or incrementally
fixup patches in mm-new.

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via the mm-everything
branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there every 2-3 working days

------------------------------------------------------
From: Yuwen Chen <ywen.chen@foxmail.com>
Subject: zram: fix the issue that the write - back limits might overflow
Date: Wed, 19 Nov 2025 12:13:45 +0800

When the page size exceeds 4KB, if bd_wb_limit is set to a value that is
not aligned with the page size, it will cause a numerical wrap-around
issue for bd_wb_limit.  For example, when the page size is set to 16KB and
bd_wb_limit is set to 3, after one write-back operation, the value of
bd_wb_limit will become -1.  More seriously, since bd_wb_limit is an
unsigned number, its value may become as large as 2^64 - 1.

The core reason for this problem is that the unit of bd_wb_limit is 4KB. 
For example, when a write-back occurs on a system with a page size of
16KB, 4 needs to be subtracted from bd_wb_limit.  This operation takes
place in the zram_account_writeback_submit function.

This patch fixes the issue by limiting bd_wb_limit to be an integer
multiple of PAGE_SIZE / 4096.

Link: https://lkml.kernel.org/r/tencent_5936CFE72BAB2BA76887BB69DCC1B5E67C05@qq.com
Fixes: 1d69a3f8ae77e ("zram: idle writeback fixes and cleanup")
Signed-off-by: Yuwen Chen <ywen.chen@foxmail.com>
Cc: Brian Geffon <bgeffon@google.com>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Richard Chang <richardycc@google.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 drivers/block/zram/zram_drv.c |   10 ++++++++++
 1 file changed, 10 insertions(+)

--- a/drivers/block/zram/zram_drv.c~zram-fix-the-issue-that-the-write-back-limits-might-overflow
+++ a/drivers/block/zram/zram_drv.c
@@ -564,6 +564,16 @@ static ssize_t writeback_limit_store(str
 	if (kstrtoull(buf, 10, &val))
 		return ret;
 
+	/*
+	 * When the page size is greater than 4KB, if bd_wb_limit is set to
+	 * a value that is not page - size aligned, it will cause value
+	 * wrapping. For example, when the page size is set to 16KB and
+	 * bd_wb_limit is set to 3, a single write - back operation will
+	 * cause bd_wb_limit to become -1. Even more terrifying is that
+	 * bd_wb_limit is an unsigned number.
+	 */
+	val = rounddown(val, PAGE_SIZE / 4096);
+
 	down_write(&zram->init_lock);
 	zram->bd_wb_limit = val;
 	up_write(&zram->init_lock);
_

Patches currently in -mm which might be from ywen.chen@foxmail.com are

zram-introduce-writeback-bio-batching-support.patch
zram-fix-the-issue-that-the-write-back-limits-might-overflow.patch


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: + zram-fix-the-issue-that-the-write-back-limits-might-overflow.patch added to mm-new branch
  2025-11-20  0:24 + zram-fix-the-issue-that-the-write-back-limits-might-overflow.patch added to mm-new branch Andrew Morton
@ 2025-11-21  4:09 ` Sergey Senozhatsky
  0 siblings, 0 replies; 2+ messages in thread
From: Sergey Senozhatsky @ 2025-11-21  4:09 UTC (permalink / raw)
  To: Andrew Morton
  Cc: mm-commits, senozhatsky, richardycc, minchan, bgeffon, ywen.chen

On (25/11/19 16:24), Andrew Morton wrote:
> When the page size exceeds 4KB, if bd_wb_limit is set to a value that is
> not aligned with the page size, it will cause a numerical wrap-around
> issue for bd_wb_limit.  For example, when the page size is set to 16KB and
> bd_wb_limit is set to 3, after one write-back operation, the value of
> bd_wb_limit will become -1.  More seriously, since bd_wb_limit is an
> unsigned number, its value may become as large as 2^64 - 1.
> 
> The core reason for this problem is that the unit of bd_wb_limit is 4KB. 
> For example, when a write-back occurs on a system with a page size of
> 16KB, 4 needs to be subtracted from bd_wb_limit.  This operation takes
> place in the zram_account_writeback_submit function.
> 
> This patch fixes the issue by limiting bd_wb_limit to be an integer
> multiple of PAGE_SIZE / 4096.
> 
> Link: https://lkml.kernel.org/r/tencent_5936CFE72BAB2BA76887BB69DCC1B5E67C05@qq.com
> Fixes: 1d69a3f8ae77e ("zram: idle writeback fixes and cleanup")
> Signed-off-by: Yuwen Chen <ywen.chen@foxmail.com>
> Cc: Brian Geffon <bgeffon@google.com>
> Cc: Minchan Kim <minchan@kernel.org>
> Cc: Richard Chang <richardycc@google.com>
> Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Acked-by: Sergey Senozhatsky <senozhatsky@chromium.org>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-21  4:10 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-20  0:24 + zram-fix-the-issue-that-the-write-back-limits-might-overflow.patch added to mm-new branch Andrew Morton
2025-11-21  4:09 ` Sergey Senozhatsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.