From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) (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 C500E3A381C for ; Thu, 12 Mar 2026 18:56:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773341818; cv=none; b=l5/jlU3uDNsAF38VW7VFaa6zXRSF0A4rFjw5NVcakejThBMz0YlRu0r2Gz2vQTMyjUEaBDlDk/YwgLjlf5KSrKB5X8gnCgEBS3EzgmkU80kXLm2cWJqUVyTxBfhcT8o9a6rzMBLaWco+0bnb+aHvTDUWrnOtj9xK+Af4c6UKPWY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773341818; c=relaxed/simple; bh=2XE4Ll/EhPnfkTCh/VG7g7KTDLlU3+Wnyc+C1jbMugA=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=IUp1x0QcEwMEMvFSStFmgrRSZcy6aBOs1smQ256f7KlcrBjUrRN8Sy9V4ENbT6QGS/jsl+LzCsPGJx4PxnD3L1UCwqfR++v6qfvc3X3XNATCYWrRXIDke3/AjNIth4EGCrKXm1zoU5Td05+Gpb/styqhAbOfbpg1wi9kouumZ2M= 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=D/FzdJrc; arc=none smtp.client-ip=209.85.221.42 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="D/FzdJrc" Received: by mail-wr1-f42.google.com with SMTP id ffacd0b85a97d-439b611274bso937445f8f.3 for ; Thu, 12 Mar 2026 11:56:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773341815; x=1773946615; 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=SBh5+9ZowpcuOJTob06IkV+7nM5VIRsXEM4MdYA0U80=; b=D/FzdJrc/2DXDFii8ayzRNtc0u7eC8uUZVq2V9AY22Cv0Xa/ZVNz+RSY3Nyp++BHe/ RAXjPWCO5xQD7Aq59lxr+JJfUW2W+wbsdH3RLFLvWbUsnZuYLmYSqUoedo+ilysGSmTl w8p/bWZ94Wep+5gW+9u7H8jcneVHWRsPhMRxRxAB1Os6bWDml8FeKcTtrjZvjiSIQQTZ 3or2qVEPtQG5qYnNePgjdu0LfR9uayfu8+zpUCPbWWu6fL+V9JYs0hqrzwYYj5EssYd7 Hf0oMA+wT9qyk3Sk/k3dE1Q9iybyru1kb9itJglOsrCKbRkVs229t54+kJ2HaYFmwBQS cFaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1773341815; x=1773946615; 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=SBh5+9ZowpcuOJTob06IkV+7nM5VIRsXEM4MdYA0U80=; b=VYmKMysKdquaiWA+2bMG+7VWbCr1H098cYAn+Pvg53/YBHVWc1uGgHauQRcFj1e8xt xCRZr+bPhlFdbBCbv48N8UA63x9FXZ+xEK9XatK8CjD06e53mr2tdBkTBx0HfgZkqZRK d4MxJjvgxc6ashborUpDutXa92sYAPkwaJCDxyMrNoCjhuF23A1ysEa/fXCEpEARNnMX p9gYkwz1nQlAc3Csjg8nCKL8XQvQTNAmKmUBcvagd/UQf9tv1qTYyUqFuj3211cHMoYI GvfMr85ZQCS0fPfatyv4gPiNCR0vPVMx0kHIxmRKij6/xMwqsIBJDmMDHon+NbB87wNh TRIA== X-Forwarded-Encrypted: i=1; AJvYcCWLaxJHlaTLmkDx1xKsDhW4ymfIu012aG5nVtyCZrxCvSKIcCB88hSGkIvM7i9Js7IjJErXEvCU9Rx4br0=@vger.kernel.org X-Gm-Message-State: AOJu0YxO06/HdJlQAfkXOzjSeKLtZfsBV86nm6xVGqTWwrO1YBGNx+VC OqMxxE2cHFc+MkgbAJxoArEmVPNk3SHX/iYqzvMrzde0lJiixvdfuKo6 X-Gm-Gg: ATEYQzwOk4XfJFj/SlSkHOktHRcs0ib3iMz4CYKw9NKyKqC2Hir/f4MKPGiE7YuKgyL ClqurgU5jKOuYqm8iFw3F2QZAKCwOoWykR+jQ2BjoP7wGpBp95ckBHmaZT9PKUD5rFOuRt6/sIh tRrlDHL89oXNDMz/VTwtHOhot+tb7JMG2wbci88oLRkJ89J9tNyfGx5WCbGD6BnyEPV32cO+1be W7szhkhwcdwavYCCAGL1nRcBBw50Fv7XSIb3GCn6HFtniNiW9dG6Gevfyt4A/TMTnWYvgA4ELQ5 eCfodJXepDVjZ+aCIsGoWf1zDapzXve2rUQYudSc47rjhN/tHLw8WhIRuKbDG14QdTtyxJ1clwq YYVgZx40a3txud4w+xh+2iXGuU9JsOpX4mFGkVa0wKMrW2BwOneYS+cOckN/XOiEypWFXSz43xy JbjZ22SDLrTK1qrQhQjcM0U9L6TQaHDTJUHJJC16xLap90CZwpahsSevOxRzu8cJEvIjngBoK7S O0= X-Received: by 2002:a05:6000:2882:b0:439:b636:1fa4 with SMTP id ffacd0b85a97d-43a04dcbd70mr1416178f8f.48.1773341814743; Thu, 12 Mar 2026 11:56:54 -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 ffacd0b85a97d-439fe20bb90sm11133374f8f.19.2026.03.12.11.56.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Mar 2026 11:56:54 -0700 (PDT) Date: Thu, 12 Mar 2026 18:56:53 +0000 From: David Laight To: Amit Machhiwal Cc: "Christophe Leroy (CS GROUP)" , Madhavan Srinivasan , linuxppc-dev@lists.ozlabs.org, Vaibhav Jain , Michael Ellerman , Nicholas Piggin , Greg Kurz , linux-kernel@vger.kernel.org Subject: Re: [PATCH] selftests/powerpc: Suppress false positive -Wmaybe-uninitialized with GCC 15 Message-ID: <20260312185653.3b8570a9@pumpkin> In-Reply-To: <20260312123856.65bb5484-2e-amachhiw@linux.ibm.com> References: <20260310101519.67157-1-amachhiw@linux.ibm.com> <3f26916b-5a1f-40b0-9c47-8b53e066e08c@kernel.org> <20260312123856.65bb5484-2e-amachhiw@linux.ibm.com> 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=UTF-8 Content-Transfer-Encoding: quoted-printable On Thu, 12 Mar 2026 13:16:26 +0000 Amit Machhiwal wrote: > Hi Christhophe, >=20 > Thanks for looking at the patch. Please find my comments inline:j >=20 > On 2026/03/10 11:54 AM, Christophe Leroy (CS GROUP) wrote: > >=20 > >=20 > > Le 10/03/2026 =C3=A0 11:15, Amit Machhiwal a =C3=A9crit=C2=A0: =20 > > > GCC 15 reports the below false positive '-Wmaybe-uninitialized' warni= ng > > > in vphn_unpack_associativity() when building the powerpc selftests. > > >=20 > > > # make -C tools/testing/selftests TARGETS=3D"powerpc" > > > [...] > > > CC test-vphn > > > In file included from test-vphn.c:3: > > > In function =E2=80=98vphn_unpack_associativity=E2=80=99, > > > inlined from =E2=80=98test_one=E2=80=99 at test-vphn.c:371:2, > > > inlined from =E2=80=98test_vphn=E2=80=99 at test-vphn.c:399:9: > > > test-vphn.c:10:33: error: =E2=80=98be_packed=E2=80=99 may be used = uninitialized [-Werror=3Dmaybe-uninitialized] > > > 10 | #define be16_to_cpup(x) bswap_16(*x) > > > | ^~~~~~~~ > > > vphn.c:42:27: note: in expansion of macro =E2=80=98be16_to_cpup=E2= =80=99 > > > 42 | u16 new =3D be16_to_cpup(field++); > > > | ^~~~~~~~~~~~ > > > In file included from test-vphn.c:19: > > > vphn.c: In function =E2=80=98test_vphn=E2=80=99: > > > vphn.c:27:16: note: =E2=80=98be_packed=E2=80=99 declared here > > > 27 | __be64 be_packed[VPHN_REGISTER_COUNT]; > > > | ^~~~~~~~~ > > > cc1: all warnings being treated as errors > > >=20 > > > When vphn_unpack_associativity() is called from hcall_vphn(), this er= ror > > > is not seen during compilation because GCC 15 seems to consider 'retb= uf' > > > always populated from the hypervisor which is eventually referred by > > > 'be_packed'. However, GCC 15's dataflow analysis can=E2=80=99t prove = the same > > > before the first dereference when vphn_unpack_associativity() is call= ed > > > from test_one() with pre-initialized array of 'struct test'. This > > > results in a false positive warning which is promoted to an error und= er > > > '-Werror'. This problem is not seen when the compilation is performed > > > with GCC 13 and 14. > > >=20 > > > Suppress the warning locally around the offending statement when > > > building with GCC 15 using a diagnostic pragma. This keeps the build > > > working while limiting the scope of the suppression to the specific > > > statement that triggers the false positive. An issue [1] has also been > > > created on GCC bugzilla. =20 > >=20 > > Usually when we get this kind of warning this is because the code is too > > complex. We should try to make it more obvious instead of just hiding t= he > > warning. =20 >=20 > The real issue here is that GCC 15 emits '-Wmaybe-uninitialized' due to > type punning between __be64[] and __b16* when accessing the buffer via > be16_to_cpup(). The underlying object is fully initialized but GCC 15 > fails to track the aliasing due to the strict aliasing violation here. Nope, I think it is tracking it correctly. The writes to be_packed[] are of 64bit values. The only reads of that memory are 16bit ones through field[]. With 'strict aliasing' the compiler doesn't have to order those accesses. Indeed, it is allowed to completely optimise away the first loop. If you cast to 'unsigned char *' then the accesses do have to be ordered. gcc will also treat accesses to different members of a union as being order= ed (the C stand doesn't require this, IIRC s/union/struct/ is valid). David=20 > Please refer [1] and [2]. >=20 > The selftest compiles fine with '-fno-strict-aliasing'. I see that when > we build vphn.c while compiling the kernel, the top level Makefile > includes '-fno-strict-aliasing' flag always. >=20 > So, I believe the same flag should be used to build vphn tests when > compiling vphn.c via the selftests. I'll send the v2 to achieve this > thus avoiding the compilation failure. >=20 > Please let me know you have different thoughts. >=20 > [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D124427=20 > [2] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D99768 >=20 > ~Amit >=20 > >=20 > > Here the for loop is a bit misleading. > > =20 > > >=20 > > > [1] https://eur01.safelinks.protection.outlook.com/?url=3Dhttps%3A%2F= %2Fgcc.gnu.org%2Fbugzilla%2Fshow_bug.cgi%3Fid%3D124427&data=3D05%7C02%7Cchr= istophe.leroy%40csgroup.eu%7C06a4d55b55f24c5cf00208de7e8e3676%7C8b87af7d864= 74dc78df45f69a2011bb5%7C0%7C0%7C639087346428583316%7CUnknown%7CTWFpbGZsb3d8= eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCI= sIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=3DxEfO94N6IfGYhmmapNFduv3OrMarxpjTpZR6= B38uR1s%3D&reserved=3D0 > > >=20 > > > Fixes: 58dae82843f5 ("selftests/powerpc: Add test for VPHN") > > > Reviewed-by: Vaibhav Jain > > > Signed-off-by: Amit Machhiwal > > > --- > > > arch/powerpc/platforms/pseries/vphn.c | 15 +++++++++++++++ > > > 1 file changed, 15 insertions(+) > > >=20 > > > diff --git a/arch/powerpc/platforms/pseries/vphn.c b/arch/powerpc/pla= tforms/pseries/vphn.c > > > index 3f85ece3c872..9bc891143fec 100644 > > > --- a/arch/powerpc/platforms/pseries/vphn.c > > > +++ b/arch/powerpc/platforms/pseries/vphn.c > > > @@ -39,7 +39,22 @@ static int vphn_unpack_associativity(const long *p= acked, __be32 *unpacked) > > > be_packed[i] =3D cpu_to_be64(packed[i]); > > > for (i =3D 1; i < VPHN_ASSOC_BUFSIZE; i++) { > > > +/* > > > + * When this function is called from hcall_vphn(), GCC 15 seems to c= onsider > > > + * 'retbuf' always populated from the hypervisor which is eventually= referred by > > > + * 'be_packed'. However, GCC 15's dataflow analysis can=E2=80=99t pr= ove the same before > > > + * the first dereference when this function is called from test_one(= ) with > > > + * pre-initialized array of 'struct test'. This results in a false p= ositive > > > + * '-Wmaybe-uninitialized' warning which is promoted to an error und= er > > > + * '-Werror'. This problem is not seen when the compilation is perfo= rmed with > > > + * older GCC versions. > > > + */ > > > +#pragma GCC diagnostic push > > > +#if defined(__GNUC__) && __GNUC__ >=3D 15 > > > +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" > > > +#endif > > > u16 new =3D be16_to_cpup(field++); > > > +#pragma GCC diagnostic pop > > > if (is_32bit) { > > > /* > > >=20 > > > base-commit: 1f318b96cc84d7c2ab792fcc0bfd42a7ca890681 =20 > > =20 >=20