From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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 2AB5A30EF89 for ; Tue, 14 Apr 2026 21:05:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776200737; cv=none; b=MdZTnPK/ZTwiaCicyw2E+IEpzEubrhK4fBMYBttfoqC2ht+9F8VTxNd9luBhs8XXVGygWEQJsRLlgNjcFPjO8P+Wn3txrx9Dy/vrGaOD2GcurfMkM9EAw1dmYIr6JFywTczvWhtLyPcGnly6/wgo06K8rIA2RUUJO2Oja12deZ0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776200737; c=relaxed/simple; bh=50a9Yi8400JDZ95LyqH8I6X7z4CJBw/eHIU9jBu7VGs=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AU+M3PwhsFzsiu7DpyBTYZ2bF0j2TYbivImvAElYpIsU7+eYS+5bZlp6gSBVrHF1mHT1nvtiw9MUKKA5v8i+Ff9HjEsR7+1VYAuSL+rqKAIg5Ur91u9KMYc1UyfBoQYKBYvZKKuasjFxjSfQo0VtFJAqc/gLVmkJJhlk3rggO6A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pjsUHckb; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pjsUHckb" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-48896199cbaso64293385e9.1 for ; Tue, 14 Apr 2026 14:05:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776200734; x=1776805534; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=WFQt6WFmWVPfUNz0yp/lCGugbU7zTlDBXyrUbnhxBDw=; b=pjsUHckbA1ii/JdRMd1319bCDfuNFl9Ds3MCcV7BZNbQogJcOdeUm1gGc6KRSgpjwt kF3xIs6DvLwyp7g2Ee5Pn0MLR2vs6Eb9FW76pGgWUGcSMvTeHidqdll11cuJVje3bz9O /5l1pft4gqIiCF7ZbAD09LWqZz5L+FYqm7cD6+30RNXAwq5JoCKMj93aIhO7X35dC5v2 3LlUozVSeXaEyU1CMs9YOZiip0+xahpPKZYc/dR+9a21OqoX8X6wlPlRVnDVdk4fc26e ZWz5qMDTxnLFKyg7CqPx9Jlu+P+eIJvVTrTmHrd3MQ3wiTSM89p4PgCbuAdt0UCa3jzQ cAmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776200734; x=1776805534; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WFQt6WFmWVPfUNz0yp/lCGugbU7zTlDBXyrUbnhxBDw=; b=VRl8MUWYXWVLxfXIcUL4pK6YKWmjQCOVhuEgFxSek3gWMDWW0Tyt80i7E9vMe4QjUx ctunh+LOlkCwD2d4/7vUhC/S9wT3TP1IaPQ5kN4AXPfwXFjMhGZI1TfocF01BjmhSLJD YGmAgohhoCGrwjH6gtJrr9KHzSIhP7PV8fBTWjKbh3KeEfhlX45H3tmaKd4OsRLJnpLr 3Ob7aBbvi+ZvDd3G0COQYu44tAHv4+R0kfNxLZJE+H5EoIhnQAK/RhDL+BJ281CztsoK xgTD3khTIoInbHVvzBNhW2i0kB6zj8ev1Hh9igqYWSX3XkCFaIzAGuxsRKIHxY36kpM1 c9nA== X-Forwarded-Encrypted: i=1; AFNElJ/+YEs3a0SqhTpCLTyms7Bf9UgNnP1gCejcLmKu7/4SK/SMN4wX05kBLL3igflW97GNh66oEjFgB94L1fM=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0uj8k/qMHrj/tB3oHOIw3DrGRlr5asYwiTCwUa+27LNAjwdSH NOb5Cl266ce4s5VGku1AIKnRtf8xYokUHCAjLUQO/L+UCALuAwV3y9U+ X-Gm-Gg: AeBDieuctD4iarX5sVu+Pr1gm9o7QbwPf/vSKM2ZxMCxbHCTRMfgzPyNXe+JSzoZCLa UQ14d7XsIDdG+5FV7BH5QJa9pGg4IC0ZrtP1Fm+1ktWHuPiOoOIK0rzzS8mJjK6u1wvvYSZ40Yt mey6o6VFhq2HP/yQLMgtSDIFZjjgCdCEFIV50oHVjR1ibvKk5VspVs7D7djA1TWBtZw0m4iFXZE zZCHQMl9Od+UdOiZeCaIfazqdOYEUNOS763u8RY6s2gWT03ufOBDRVMsEdDjAz4MjvvfMB0xoJh PUQams5fDSOsyj/p8SMPO1AMr4ZyKBdoi67OZ7ZT4KgUkIG/87dZMJhor0LLJCID1govvf6C2VZ FjiXebvFZfdcQSDemFTgLFtVHV3B2ETrRDwDCWXdFcaXUC/60zsFtx18Xw79kftu3wntulk79Qt JwHPAOP4Uza/JGS1M00CZnyTe1Fdfkey2wkGZZ14krQ3Qsag0dHDqQsNtDcLeKxN8A X-Received: by 2002:a05:600d:d:b0:488:ba5f:984f with SMTP id 5b1f17b1804b1-488d67b8dadmr205583445e9.6.1776200734242; Tue, 14 Apr 2026 14:05:34 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488ede15cfbsm83786205e9.1.2026.04.14.14.05.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Apr 2026 14:05:33 -0700 (PDT) Date: Tue, 14 Apr 2026 22:05:32 +0100 From: David Laight To: Arnd Bergmann Cc: Andrew Morton , Johannes Weiner , Arnd Bergmann , Kairui Song , Qi Zheng , Shakeel Butt , Barry Song , Axel Rasmussen , Yuanchu Xie , Wei Xu , David Hildenbrand , Michal Hocko , Lorenzo Stoakes , Muchun Song , Baolin Wang , Davidlohr Bueso , Koichiro Den , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] [v2] mm/vmscan: avoid false-positive -Wuninitialized warning Message-ID: <20260414220532.3c89dfa3@pumpkin> In-Reply-To: <20260414065206.3236176-1-arnd@kernel.org> References: <20260414065206.3236176-1-arnd@kernel.org> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Tue, 14 Apr 2026 08:51:58 +0200 Arnd Bergmann wrote: > From: Arnd Bergmann > > When the -fsanitize=bounds sanitizer is enabled, gcc-16 sometimes runs > into a corner case in the read_ctrl_pos() pos function, where it sees > possible undefined behavior from the 'tier' index overflowing, presumably > in the case that this was called with a negative tier: > > In function 'get_tier_idx', > inlined from 'isolate_folios' at mm/vmscan.c:4671:14: > mm/vmscan.c: In function 'isolate_folios': > mm/vmscan.c:4645:29: error: 'pv.refaulted' is used uninitialized [-Werror=uninitialized] > > Part of the problem seems to be that read_ctrl_pos() has unusual calling > conventions since commit 37a260870f2c ("mm/mglru: rework type selection") > where passing MAX_NR_TIERS makes it accumulate all tiers but passing a > smaller positive number makes it read a single tier instead. We've had issues with that code before, might have been related to the min(). Unless that function is inlined (and the compiler generates a sane loop) the generated code will be completely horrid. If this code is executed in any kind of 'hot path' it should really be done differently. It isn't as though there are many callers; and one want to process all the tiers - but not in the same way. The code isn't even that readable. David > > Shut up the warning by adding a fake initialization to the two instances > of this variable that can run into that corner case. > > Link: https://lore.kernel.org/all/CAJHvVcjtFW86o5FoQC8MMEXCHAC0FviggaQsd5EmiCHP+1fBpg@mail.gmail.com/ > Signed-off-by: Arnd Bergmann > --- > v2: replace the earlier more invasive cleanup with a trivial > workaround > --- > mm/vmscan.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/mm/vmscan.c b/mm/vmscan.c > index d3312c51f3f2..f829435d2807 100644 > --- a/mm/vmscan.c > +++ b/mm/vmscan.c > @@ -4760,7 +4760,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). > @@ -4779,7 +4779,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;