From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (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 7DC4038B7DB for ; Tue, 7 Apr 2026 10:31:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775557882; cv=none; b=mon4l7FjgDqUH+HDDXS26KSnBIyp0U5ZAsX2vfZrRwe4JwPocueMniDulSwaTcyuVTxeUzh/3r+JznTtaEbAWI1HOSsuFYyDALh/l9qBpFwjaio0biMaY1fCSs2XAk3qCLCJrw/r6SIG+Dsr7wVz80/pialS+dsI06TXESIr2QY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775557882; c=relaxed/simple; bh=Ns5jjjTfJV+i/TeTxOZ94Cylidwstx6f3BYuQbVirBo=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AmDaoesyChlPtxZHluLh1bg6Lz58YPbkGVWbt48RfSlSGqw8/n0o6mefWe6nPyR0v1nRaF30xzR/yVnFChuHxMvw5sJdhMZS/egLfpTgMohfJsRdj8oS0HPttsJNchgYx/VS/uYuZHO2og1ZE2DGzYi+EbfJQQdoNUNwTMqkRxk= 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=PkHLzMA+; arc=none smtp.client-ip=209.85.128.49 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="PkHLzMA+" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-488a4bc360bso14841005e9.0 for ; Tue, 07 Apr 2026 03:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775557880; x=1776162680; 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=lip3owYNVh4Y6wPGr1TWEoHeQbKxzTWWmz7TOhaw338=; b=PkHLzMA+A40Ne9UPX/TSZqEBXnNK41CSOz4RxOWTWJAFyL4GuxWTAv68E2S2+zBw/l p/ZMlU0+FwliICEB0OKppsgUA7/dFNLDTZPKrzU+o+u7MiW2dSVsY3nXW7TCbTE1DjB9 VEem/nVN7YgHiB50Dn0+Y4JdzB78+tTnYgsfT/FTQNri1L2HL6naMWQoChYP4DMhUDm8 RxgGYcEtfPwlgk+XIkPETm0a2PraoktNV8V6wIOUnJMvaRdJQNR+rPi/5cQ+JxrUyLOp qnH1Ka2xbJI41Q1qa8EdIxSfpilSuAnuUBlO1vYs0JoVi7uKjSqlHM//TnBmCZoVAJ66 Np7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775557880; x=1776162680; 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=lip3owYNVh4Y6wPGr1TWEoHeQbKxzTWWmz7TOhaw338=; b=gJlCtkN1jW3CCkt8Owz062/5z7OMfpnSPHbNjjQ9TgC1q9ssAMrKyb12sB2fF5aujh NEmjK9v0FnevqNL0yWGVBUyNRxx//6hNjvGyYSTgNuRS+nyfhw3IX4DnfZnPxGzphwXz cMywkIxHhlCoxA+E7M0a73rQCid5+zj0nA8cpNOpSMxsq425lNHXOGdML7iJwqRDhN5c 30ASpQZtyObWaikVe4/nwpxNAqfXCq31pHOLWxU9Fi/co+DXdhZWg8zM5kQX7dLSFgPH uCSCTMryZYGr+9/aHfgVwl020FMzUVCPfnx0ZYmLFOV9+2bs2XB6Xeqg6w7CeCtgouVV Vkig== X-Forwarded-Encrypted: i=1; AJvYcCUTiPyhbQK1WjexoFn84Bjeye1/mZPuTLKkiJlfAnCP6fanSEIM1hHWhZ8arXiI4l6mS6xL+TZ3p4nQ+xw=@vger.kernel.org X-Gm-Message-State: AOJu0Ywu6/Klp3PHW4fdLPYio2FbWWskj4fZNASzRSgu028JOv8hqp77 rPB0szfNw54yNGXPsahgcP9uB9cbR+mGSqSLOweJUVHvxnCj0/787eqm X-Gm-Gg: AeBDietP3BjpbFpeD8FsD+PihG0kbXGX3NGloZManbVi4aWxwWxq3oithGBdNeF2Pqh 9F5aq2bXaT23mkFFE4b00que15f3yBr0mFO05YLGxhmN7xh2f/Ohph9IuvvUVtBye3o+FUHtSTl phLmHaH2yLA63VLE3GkW2DnU7Q3r1kwTJWeOyP/uGbXQvXfinxRa5/ri2RS6LFmYRrr20vQS2GE 1bLQzvjVLIQ7VRjdZX4OoYSueA9UBhzTb82t5vqNDD/W++3VWOeHOY27ZT9Hc/h6s8EmZOz5rmS 2XzLi1xPzIXdDMrCTsy4/9+usodOD6hknOIDN+iJz+rdPydwuCf4hMupMoZxE38pTu0yxyxhNV6 aK63ljfET/uVaxd9LDvMuY9BcDPQ0a0TrqzKtzsOMYnIkmuETfMxZsw3Q8PEVzQPLOwdykh2kB8 T0ZQnlZLkGHaZrCjZAz/ukvi83qy7d/NI7Th8Ct2mf5KErey3KqAOFLBBSXlk+rcJu X-Received: by 2002:a05:600c:1c0f:b0:488:b99b:4177 with SMTP id 5b1f17b1804b1-488b99b7636mr55064655e9.25.1775557879563; Tue, 07 Apr 2026 03:31:19 -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-488a91686f9sm273581495e9.10.2026.04.07.03.31.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Apr 2026 03:31:19 -0700 (PDT) Date: Tue, 7 Apr 2026 11:31:17 +0100 From: David Laight To: Tamir Duberstein Cc: Petr Mladek , Steven Rostedt , Andy Shevchenko , Rasmus Villemoes , Sergey Senozhatsky , linux-kernel@vger.kernel.org, stable@vger.kernel.org, kernel test robot Subject: Re: [PATCH] printf: mark errptr() noinline Message-ID: <20260407113117.79cf04e8@pumpkin> In-Reply-To: <20260405-printf-test-old-gcc-v1-1-76d24d9bb60e@kernel.org> References: <20260405-printf-test-old-gcc-v1-1-76d24d9bb60e@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 Sun, 05 Apr 2026 13:31:50 -0400 Tamir Duberstein wrote: > Old GCC can miscompile printf_kunit's errptr() test when branch > profiling is enabled. BUILD_BUG_ON(IS_ERR(PTR)) is a constant false > expression, but CONFIG_TRACE_BRANCH_PROFILING and > CONFIG_PROFILE_ALL_BRANCHES make the IS_ERR() path side-effectful. > GCC's IPA splitter can then outline the cold assert arm into > errptr.part.* and leave that clone with an unconditional > __compiletime_assert_*() call, causing a false build failure. > > This started showing up after test_hashed() became a macro and moved its > local buffer into errptr(), which changed GCC's inlining and splitting > decisions enough to expose the compiler bug. > > Mark errptr() noinline to keep it out of that buggy IPA path while > preserving the BUILD_BUG_ON(IS_ERR(PTR)) check and the macro-based > printf argument checking. Why not convert that check to a run-time one? It isn't as though IS_ERR() is usually used with constants. (There are a lot of other tests which would be better as compile-time ones; since the run-time code just checks the compiler generated the correct constant. So a compile failure saves you having to run the tests; but that isn't true here.) I'd also test -4095 and -4096... > > Fixes: 9bfa52dac27a ("printf: convert test_hashed into macro") > Reported-by: kernel test robot > Closes: https://lore.kernel.org/oe-kbuild-all/202604030636.NqjaJvYp-lkp@intel.com/ > Signed-off-by: Tamir Duberstein > --- > lib/tests/printf_kunit.c | 18 +++++++++++++++++- > 1 file changed, 17 insertions(+), 1 deletion(-) > > diff --git a/lib/tests/printf_kunit.c b/lib/tests/printf_kunit.c > index f6f21b445ece..a8087e8ac826 100644 > --- a/lib/tests/printf_kunit.c > +++ b/lib/tests/printf_kunit.c > @@ -749,7 +749,23 @@ static void fourcc_pointer(struct kunit *kunittest) > fourcc_pointer_test(kunittest, try_cb, ARRAY_SIZE(try_cb), "%p4cb"); > } > > -static void > +/* > + * GCC < 12.1 can miscompile this test when branch profiling is enabled. > + * > + * BUILD_BUG_ON(IS_ERR(PTR)) is a constant false expression, but old GCC can > + * still trip over it after CONFIG_TRACE_BRANCH_PROFILING and > + * CONFIG_PROFILE_ALL_BRANCHES rewrite the IS_ERR() unlikely() path into > + * side-effectful branch counter updates. IPA splitting then outlines the cold > + * assert arm into errptr.part.* and leaves that clone with an unconditional > + * __compiletime_assert_*() call, so the build fails even though PTR is not an > + * ERR_PTR. > + * > + * Keep this test out of that buggy IPA path so the BUILD_BUG_ON() can stay in > + * place without open-coding IS_ERR(). This can be removed once the minimum GCC > + * includes commit 76fe49423047 ("Fix tree-optimization/101941: IPA splitting > + * out function with error attribute"), which first shipped in GCC 12.1. > + */ > +static noinline void While that might make a difference, I'm not sure that it has to. You aren't changing anything directly related to the failing expansion. David > errptr(struct kunit *kunittest) > { > test("-1234", "%pe", ERR_PTR(-1234)); > > --- > base-commit: d8a9a4b11a137909e306e50346148fc5c3b63f9d > change-id: 20260405-printf-test-old-gcc-f13fecda6524 > > Best regards, > -- > Tamir Duberstein > >