Re: [PATCH] mm/vmscan: avoid false-positive -Wuninitialized warning, again
From: Baoquan He
Date: Wed Sep 16 2026 - 22:57:27 EST
On 09/16/26 at 04:30pm, Andrew Morton wrote:
> On Wed, 16 Sep 2026 16:28:16 -0700 Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> 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!
I drafted one to change 'tier' as 'unsigned int'. While in mm-new this
issue has gone away because Kairui's patch change 'tier' to 'tier_min'
and 'tier_max' and remove min().
commit b447513eee2f ("mm/mglru: use explicit tier range in read_ctrl_pos()")
I personally think your one line change is better for backporting to
stable tree.
From: Baoquan He <hebaoquan@xxxxxxxxxx>
Subject: [PATCH] mm/vmscan: fix min() signedness mismatch in read_ctrl_pos()
read_ctrl_pos() declares 'tier' as int, but MAX_NR_TIERS is 4U, so
min(tier, MAX_NR_TIERS - 1) compares int with unsigned int and min()
reports a signedness error:
error: min(tier, 4U - 1) signedness error
'tier' is never negative, it is a tier index or MAX_NR_TIERS to mean
all tiers. Make it unsigned int, then min() compares two unsigned
values and no min_t() needed.
Signed-off-by: Baoquan He <hebaoquan@xxxxxxxxxx>
---
diff --git a/mm/vmscan.c b/mm/vmscan.c
index f11491ee9ed5..1844d92a6732 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -3195,10 +3195,10 @@ struct ctrl_pos {
int gain;
};
-static void read_ctrl_pos(struct lruvec *lruvec, int type, int tier, int gain,
- struct ctrl_pos *pos)
+static void read_ctrl_pos(struct lruvec *lruvec, int type, unsigned int tier,
+ int gain, struct ctrl_pos *pos)
{
- int i;
+ unsigned int i;
struct lru_gen_folio *lrugen = &lruvec->lrugen;
int hist = lru_hist_from_seq(lrugen->min_seq[type]);
@@ -4801,7 +4801,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;
+ unsigned int tier;
struct ctrl_pos sp, pv = {};
/*