All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <David.Laight@ACULAB.COM>
To: 'Adrian Hunter' <adrian.hunter@intel.com>, Arnd Bergmann <arnd@arndb.de>
Cc: Peter Zijlstra <peterz@infradead.org>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	John Stultz <jstultz@google.com>,
	"H. Peter Anvin" <hpa@zytor.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>,
	"Vincenzo Frascino" <vincenzo.frascino@arm.com>,
	"linux-s390@vger.kernel.org" <linux-s390@vger.kernel.org>,
	Naresh Kamboju <naresh.kamboju@linaro.org>,
	"x86@kernel.org" <x86@kernel.org>,
	Aneesh Kumar K.V <aneesh.kumar@kernel.org>,
	Ingo Molnar <mingo@redhat.com>,
	"Naveen N. Rao" <naveen.n.rao@linux.ibm.com>,
	Christian Borntraeger <borntraeger@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	"Heiko Carstens" <hca@linux.ibm.com>,
	Nicholas Piggin <npiggin@gmail.com>,
	"Borislav Petkov" <bp@alien8.de>,
	Andy Lutomirski <luto@kernel.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Anna-Maria Gleixner" <anna-maria@linutronix.de>,
	Stephen Boyd <sboyd@kernel.org>,
	"Randy Dunlap" <rdunlap@infradead.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Sven Schnelle <svens@linux.ibm.com>,
	"linuxppc-dev@lists.ozlabs.org" <linuxppc-dev@lists.ozlabs.org>
Subject: RE: [PATCH] bug: Fix no-return-statement warning with !CONFIG_BUG
Date: Thu, 11 Apr 2024 10:27:23 +0000	[thread overview]
Message-ID: <a0776e05c5074da2b8394926b2f787a2@AcuMS.aculab.com> (raw)
In-Reply-To: <0fd5e869-720f-41bb-9f0f-c0f3925ffc1b@intel.com>

From: Adrian Hunter
> Sent: 11 April 2024 10:04
> 
> On 11/04/24 10:56, Arnd Bergmann wrote:
> > On Thu, Apr 11, 2024, at 09:16, Adrian Hunter wrote:
> >> On 11/04/24 10:04, Arnd Bergmann wrote:
> >>> On Wed, Apr 10, 2024, at 17:32, Adrian Hunter wrote:
> >>>> BUG() does not return, and arch implementations of BUG() use unreachable()
> >>>> or other non-returning code. However with !CONFIG_BUG, the default
> >>>> implementation is often used instead, and that does not do that. x86 always
> >>>> uses its own implementation, but powerpc with !CONFIG_BUG gives a build
> >>>> error:
> >>>>
> >>>>   kernel/time/timekeeping.c: In function ‘timekeeping_debug_get_ns’:
> >>>>   kernel/time/timekeeping.c:286:1: error: no return statement in function
> >>>>   returning non-void [-Werror=return-type]
> >>>>
> >>>> Add unreachable() to default !CONFIG_BUG BUG() implementation.
> >>>
> >>> I'm a bit worried about this patch, since we have had problems
> >>> with unreachable() inside of BUG() in the past, and as far as I
> >>> can remember, the current version was the only one that
> >>> actually did the right thing on all compilers.
> >>>
> >>> One problem with an unreachable() annotation here is that if
> >>> a compiler misanalyses the endless loop, it can decide to
> >>> throw out the entire code path leading up to it and just
> >>> run into undefined behavior instead of printing a BUG()
> >>> message.
> >>>
> >>> Do you know which compiler version show the warning above?
> >>
> >> Original report has a list
> >>
> >
> > It looks like it's all versions of gcc, though no versions
> > of clang show the warnings. I did a few more tests and could
> > not find any differences on actual code generation, but
> > I'd still feel more comfortable changing the caller than
> > the BUG() macro. It's trivial to add a 'return 0' there.
> 
> AFAICT every implementation of BUG() except this one has
> unreachable() or equivalent, so that inconsistency seems
> wrong.
> 
> Could add 'return 0', but I do notice other cases
> where a function does not have a return value, such as
> cpus_have_final_boot_cap(), so there is already an expectation
> that that is OK.

Isn't that likely to generate an 'unreachable code' warning?
I any case the compiler can generate better code for the non-BUG()
path if it knows BUG() doesn't return.
(And confuse stack back-trace code in the process.)

> 
> > Another interesting observation is that clang-11 and earlier
> > versions end up skipping the endless loop, both with and
> > without the __builtin_unreachable, see
> > https://godbolt.org/z/aqa9zqz8x
> 
> Adding volatile asm("") to the loop would probably fix that,
> but it seems like a separate issue.

I'd guess barrier() would be better.
It might be needed before the loopstop for other reasons.
The compiler might be just moving code below the loop and then
discarding it as unreachable.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

  reply	other threads:[~2024-04-11 10:28 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-10 15:32 [PATCH] bug: Fix no-return-statement warning with !CONFIG_BUG Adrian Hunter
2024-04-10 15:32 ` Adrian Hunter
2024-04-10 17:02 ` Naresh Kamboju
2024-04-10 17:02   ` Naresh Kamboju
2024-04-10 20:05 ` [tip: timers/urgent] " tip-bot2 for Adrian Hunter
2024-04-11  7:04 ` [PATCH] " Arnd Bergmann
2024-04-11  7:04   ` Arnd Bergmann
2024-04-11  7:16   ` Adrian Hunter
2024-04-11  7:16     ` Adrian Hunter
2024-04-11  7:56     ` Arnd Bergmann
2024-04-11  9:03       ` Adrian Hunter
2024-04-11 10:27         ` David Laight [this message]
2024-04-11  8:13     ` Christophe Leroy
2024-04-11  8:13       ` Christophe Leroy
2024-04-11  8:22       ` Christophe Leroy
2024-04-11  8:22         ` Christophe Leroy
2024-04-11  9:27         ` Adrian Hunter
2024-04-11  9:27           ` Adrian Hunter
2024-04-11 11:26           ` Arnd Bergmann
2024-04-11 11:26             ` Arnd Bergmann
2024-04-15  2:19             ` Michael Ellerman
2024-04-15 15:35               ` Arnd Bergmann
2024-04-15 15:35                 ` Arnd Bergmann
2024-04-15 17:07                 ` Christophe Leroy
2024-04-15 17:32                   ` Arnd Bergmann
2024-04-15 17:32                     ` Arnd Bergmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a0776e05c5074da2b8394926b2f787a2@AcuMS.aculab.com \
    --to=david.laight@aculab.com \
    --cc=adrian.hunter@intel.com \
    --cc=agordeev@linux.ibm.com \
    --cc=aneesh.kumar@kernel.org \
    --cc=anna-maria@linutronix.de \
    --cc=arnd@arndb.de \
    --cc=bhelgaas@google.com \
    --cc=borntraeger@linux.ibm.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hpa@zytor.com \
    --cc=jstultz@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=luto@kernel.org \
    --cc=mingo@redhat.com \
    --cc=naresh.kamboju@linaro.org \
    --cc=naveen.n.rao@linux.ibm.com \
    --cc=npiggin@gmail.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=sboyd@kernel.org \
    --cc=svens@linux.ibm.com \
    --cc=tglx@linutronix.de \
    --cc=vincenzo.frascino@arm.com \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.