Re: [PATCH v2 0/4] fix unexpected type conversions and potential overflows

Qi Zheng
2026-03-25T14:25:11Z

Forgot to include the changelog:

Changes in v2:

- modified all commit messages. (suggested-by Lorenzo Stoakes)
- added a fix patch to resolve the unexpected massive positive number
(pointed-by Harry Yoo and sashiko)
- fix the print type mismatch in [PATCH 3/3]
- collect Reviewed-by

On 3/25/26 10:13 PM, Qi Zheng wrote:
> From: Qi Zheng <zhengqi.arch@bytedance.com>
>
> Hi all,
>
> As Harry Yoo pointed out [1], in scenarios where massive state updates occur
> (e.g., during the reparenting of LRU folios), the values passed to memcg stat
> update functions can accumulate and exceed the upper limit of a 32-bit integer.
>
> If the parameter types are not large enough (like 'int') or are handled
> incorrectly, it can lead to severe truncation, potential overflow issues,
> and unexpected type conversion bugs.
>
> This series aims to address these issues by correcting the parameter types
> in the relevant functions, and fixing an implicit conversion bug in
> memcg_state_val_in_pages().
>
> This series is based on the next-20260323.
>
> Comments and suggestions are welcome!
>
> Thanks,
> Qi
>
> [1]. https://lore.kernel.org/all/acDxaEgnqPI-Z4be@hyeyoo/
>
> Qi Zheng (4):
> mm: memcontrol: correct the type of stats_updates to unsigned long
> mm: memcontrol: change val type to long in
> __mod_memcg_{lruvec_}state()
> mm: memcontrol: correct the nr_pages parameter type of
> mem_cgroup_update_lru_size()
> mm: memcontrol: fix unexpected massive positive number in
> memcg_state_val_in_pages()
>
> include/linux/memcontrol.h | 2 +-
> include/trace/events/memcg.h | 10 +++++-----
> mm/memcontrol.c | 37 +++++++++++++++++++-----------------
> 3 files changed, 26 insertions(+), 23 deletions(-)
>