* [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again
@ 2026-09-16 8:34 Arnd Bergmann
2026-09-16 23:08 ` Andrew Morton
2026-09-16 23:28 ` Andrew Morton
0 siblings, 2 replies; 4+ messages in thread
From: Arnd Bergmann @ 2026-09-16 8:34 UTC (permalink / raw)
To: Andrew Morton, Johannes Weiner, Arnd Bergmann
Cc: David Hildenbrand, Michal Hocko, Qi Zheng, Shakeel Butt,
Lorenzo Stoakes, Kairui Song, Barry Song, Axel Rasmussen,
Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang, Ridong Chen,
linux-mm, linux-kernel
From: Arnd Bergmann <arnd@arndb.de>
I previously worked around a false-postive gcc-16 warning in the
get_tier_idx() function, by adding a fake initializer. This happens with
the -fsanitize=bounds sanitizer when the compiler creates a specialized
variant of isolate_folios():
In function 'get_tier_idx',
inlined from 'isolate_folios.constprop' at mm/vmscan.c:4982:9:
mm/vmscan.c:4934:9: error: 'sp.refaulted' is used uninitialized [-Werror=uninitialized]
4934 | read_ctrl_pos(lruvec, type, LRU_TIER_MIN, LRU_TIER_MIN, 2, &sp);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mm/vmscan.c: In function 'isolate_folios.constprop':
mm/vmscan.c:4946:25: note: 'sp.refaulted' was declared here
4946 | struct ctrl_pos sp, pv = {};
| ^~
Adding another "= {}" would solve the problem as well, but to prevent
this from happening again after the next code refactoring, try instead to
prevent this by forbidding interprocedural optimizations on this function.
Link: https://lore.kernel.org/all/20260213123902.3466040-1-arnd@kernel.org/
Fixes: 3de705a43a46 ("mm/vmscan: avoid false-positive -Wuninitialized warning")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
mm/vmscan.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/mm/vmscan.c b/mm/vmscan.c
index 11387a0fbeeb..626d2fc78cc9 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3274,8 +3274,10 @@ struct ctrl_pos {
int gain;
};
-static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier_min,
- int tier_max, int gain, struct ctrl_pos *pos)
+/* __noipa works around gcc-16 warning for uninitizled use of pos->refaulted */
+static __noipa void read_ctrl_pos(struct lruvec *lruvec, int type,
+ int tier_min, int tier_max, int gain,
+ struct ctrl_pos *pos)
{
int i;
struct lru_gen_folio *lrugen = &lruvec->lrugen;
@@ -4924,7 +4926,7 @@ static int scan_folios(unsigned long nr_to_scan, struct lruvec *lruvec,
static int get_tier_idx(struct lruvec *lruvec, int type)
{
int tier;
- struct ctrl_pos sp, pv = {};
+ struct ctrl_pos sp, pv;
/*
* To leave a margin for fluctuations, use a larger gain factor (2:3).
@@ -4943,7 +4945,7 @@ static int get_tier_idx(struct lruvec *lruvec, int type)
static int get_type_to_scan(struct lruvec *lruvec, int swappiness)
{
- struct ctrl_pos sp, pv = {};
+ struct ctrl_pos sp, pv;
if (swappiness <= MIN_SWAPPINESS + 1)
return LRU_GEN_FILE;
--
2.53.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again
2026-09-16 8:34 [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again Arnd Bergmann
@ 2026-09-16 23:08 ` Andrew Morton
2026-09-16 23:28 ` Andrew Morton
1 sibling, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-09-16 23:08 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Johannes Weiner, Arnd Bergmann, David Hildenbrand, Michal Hocko,
Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Barry Song,
Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang,
Ridong Chen, linux-mm, linux-kernel
On Wed, 16 Sep 2026 10:34:46 +0200 Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> I previously worked around a false-postive gcc-16 warning in the
> get_tier_idx() function, by adding a fake initializer. This happens with
> the -fsanitize=bounds sanitizer when the compiler creates a specialized
> variant of isolate_folios():
>
> In function 'get_tier_idx',
> inlined from 'isolate_folios.constprop' at mm/vmscan.c:4982:9:
> mm/vmscan.c:4934:9: error: 'sp.refaulted' is used uninitialized [-Werror=uninitialized]
> 4934 | read_ctrl_pos(lruvec, type, LRU_TIER_MIN, LRU_TIER_MIN, 2, &sp);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> mm/vmscan.c: In function 'isolate_folios.constprop':
> mm/vmscan.c:4946:25: note: 'sp.refaulted' was declared here
> 4946 | struct ctrl_pos sp, pv = {};
> | ^~
>
> Adding another "= {}" would solve the problem as well, but to prevent
> this from happening again after the next code refactoring, try instead to
> prevent this by forbidding interprocedural optimizations on this function.
>
> Link: https://lore.kernel.org/all/20260213123902.3466040-1-arnd@kernel.org/
> Fixes: 3de705a43a46 ("mm/vmscan: avoid false-positive -Wuninitialized warning")
I believe we want older kernel to compile properly with gcc-16, so I'm
suggesting this be backported?
Perhaps we should have done that with 3de705a43a46 also.
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again
2026-09-16 8:34 [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again Arnd Bergmann
2026-09-16 23:08 ` Andrew Morton
@ 2026-09-16 23:28 ` Andrew Morton
2026-09-16 23:30 ` Andrew Morton
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Morton @ 2026-09-16 23:28 UTC (permalink / raw)
To: Arnd Bergmann
Cc: Johannes Weiner, Arnd Bergmann, David Hildenbrand, Michal Hocko,
Qi Zheng, Shakeel Butt, Lorenzo Stoakes, Kairui Song, Barry Song,
Axel Rasmussen, Yuanchu Xie, Wei Xu, Baoquan He, Baolin Wang,
Ridong Chen, linux-mm, linux-kernel
On Wed, 16 Sep 2026 10:34:46 +0200 Arnd Bergmann <arnd@kernel.org> wrote:
> From: Arnd Bergmann <arnd@arndb.de>
>
> I previously worked around a false-postive gcc-16 warning in the
> get_tier_idx() function, by adding a fake initializer. This happens with
> the -fsanitize=bounds sanitizer when the compiler creates a specialized
> variant of isolate_folios():
>
> In function 'get_tier_idx',
> inlined from 'isolate_folios.constprop' at mm/vmscan.c:4982:9:
> mm/vmscan.c:4934:9: error: 'sp.refaulted' is used uninitialized [-Werror=uninitialized]
> 4934 | read_ctrl_pos(lruvec, type, LRU_TIER_MIN, LRU_TIER_MIN, 2, &sp);
> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> mm/vmscan.c: In function 'isolate_folios.constprop':
> mm/vmscan.c:4946:25: note: 'sp.refaulted' was declared here
> 4946 | struct ctrl_pos sp, pv = {};
> | ^~
>
> Adding another "= {}" would solve the problem as well, but to prevent
> this from happening again after the next code refactoring, try instead to
> prevent this by forbidding interprocedural optimizations on this function.
>
> ...
>
> --- a/mm/vmscan.c
> +++ b/mm/vmscan.c
> @@ -3274,8 +3274,10 @@ struct ctrl_pos {
> int gain;
> };
>
> -static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier_min,
> - int tier_max, int gain, struct ctrl_pos *pos)
> +/* __noipa works around gcc-16 warning for uninitizled use of pos->refaulted */
> +static __noipa void read_ctrl_pos(struct lruvec *lruvec, int type,
> + int tier_min, int tier_max, int gain,
> + struct ctrl_pos *pos)
> {
> int i;
> struct lru_gen_folio *lrugen = &lruvec->lrugen;
Current code has changed here somewhat, but I expect the error is still
there. I fixed that "uninitizled" while in there. Altered patch is
below.
--- a/mm/vmscan.c~mm-vmscan-avoid-false-positive-wuninitialized-warning-again
+++ a/mm/vmscan.c
@@ -3195,8 +3195,12 @@ struct ctrl_pos {
int gain;
};
-static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier, int gain,
- struct ctrl_pos *pos)
+/*
+ * __noipa works around gcc-16 warning for uninitialized use of
+ * pos->refaulted
+ */
+static __noipa void read_ctrl_pos(struct lruvec *lruvec, int type, int tier,
+ int gain, struct ctrl_pos *pos)
{
int i;
struct lru_gen_folio *lrugen = &lruvec->lrugen;
@@ -4802,7 +4806,7 @@ static int scan_folios(unsigned long nr_
static int get_tier_idx(struct lruvec *lruvec, int type)
{
int tier;
- struct ctrl_pos sp, pv = {};
+ struct ctrl_pos sp, pv;
/*
* To leave a margin for fluctuations, use a larger gain factor (2:3).
@@ -4821,7 +4825,7 @@ static int get_tier_idx(struct lruvec *l
static int get_type_to_scan(struct lruvec *lruvec, int swappiness)
{
- struct ctrl_pos sp, pv = {};
+ struct ctrl_pos sp, pv;
if (swappiness <= MIN_SWAPPINESS + 1)
return LRU_GEN_FILE;
_
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again
2026-09-16 23:28 ` Andrew Morton
@ 2026-09-16 23:30 ` Andrew Morton
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Morton @ 2026-09-16 23:30 UTC (permalink / raw)
To: Arnd Bergmann, Johannes Weiner, Arnd Bergmann, David Hildenbrand,
Michal Hocko, Qi Zheng, Shakeel Butt, Lorenzo Stoakes,
Kairui Song, Barry Song, Axel Rasmussen, Yuanchu Xie, Wei Xu,
Baoquan He, Baolin Wang, Ridong Chen, linux-mm, linux-kernel
On Wed, 16 Sep 2026 16:28:16 -0700 Andrew Morton <akpm@linux-foundation.org> wrote:
> >
> > --- a/mm/vmscan.c
> > +++ b/mm/vmscan.c
> > @@ -3274,8 +3274,10 @@ struct ctrl_pos {
> > int gain;
> > };
> >
> > -static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier_min,
> > - int tier_max, int gain, struct ctrl_pos *pos)
> > +/* __noipa works around gcc-16 warning for uninitizled use of pos->refaulted */
> > +static __noipa void read_ctrl_pos(struct lruvec *lruvec, int type,
> > + int tier_min, int tier_max, int gain,
> > + struct ctrl_pos *pos)
> > {
> > int i;
> > struct lru_gen_folio *lrugen = &lruvec->lrugen;
>
> Current code has changed here somewhat, but I expect the error is still
> there. I fixed that "uninitizled" while in there. Altered patch is
> below.
Then the build blew up in unexpected ways. gcc-15.2.0.
The failure looks like a legit min() signedness thing which has been
there quite a while. I'm thinking that __noipa surfaced this for some
reason?
CC mm/vmscan.o
In file included from <command-line>:
mm/vmscan.c: In function 'read_ctrl_pos':
././include/linux/compiler_types.h:702:45: error: call to '__compiletime_assert_798' declared with attribute error: min(tier, 4U - 1) signedness error
702 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
I'll queue a fix to switch this to min_t (yuck) for now. It would of
course be better to use more appropriate types in this code. Unless
tiers can be negative!
From: Andrew Morton <akpm@linux-foundation.org>
Subject: mm/vmscan.c: fix min() signedness mismatch
Date: Wed Sep 16 04:21:22 PM PDT 2026
A __noipa conversion from Arnd [1] somehow revealed a longstanding min()
error in read_ctrl_pos(). Plug it with min_t().
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Axel Rasmussen <axelrasmussen@google.com>
Cc: Baolin Wang <baolin.wang@linux.alibaba.com>
Cc: Baoquan He <baoquan.he@linux.dev>
Cc: Barry Song <baohua@kernel.org>
Cc: David Hildenbrand <david@kernel.org>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: Kairui Song <kasong@tencent.com>
Cc: Lorenzo Stoakes <ljs@kernel.org>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Wei Xu <weixugc@google.com>
Cc: Yuanchu Xie <yuanchu@google.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/vmscan.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/mm/vmscan.c~mm-vmscanc-fix-min-signedness-mismatch
+++ a/mm/vmscan.c
@@ -3205,7 +3205,7 @@ static void read_ctrl_pos(struct lruvec
pos->gain = gain;
pos->refaulted = pos->total = 0;
- for (i = tier % MAX_NR_TIERS; i <= min(tier, MAX_NR_TIERS - 1); i++) {
+ for (i = tier % MAX_NR_TIERS; i <= min_t(unsigned int, tier, MAX_NR_TIERS - 1); i++) {
pos->refaulted += lrugen->avg_refaulted[type][i] +
atomic_long_read(&lrugen->refaulted[hist][type][i]);
pos->total += lrugen->avg_total[type][i] +
_
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-09-16 23:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-16 8:34 [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again Arnd Bergmann
2026-09-16 23:08 ` Andrew Morton
2026-09-16 23:28 ` Andrew Morton
2026-09-16 23:30 ` Andrew Morton
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®