From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 228AB1448E4; Thu, 11 Apr 2024 09:28:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712827689; cv=none; b=NWcZmzuvRjNHBsoy+mKe7tSHnPUTswIq77PlpCnQibtZ6fot9IY8AqhsnRNtjzz5uEceCBxPmNbe/1IY24WUwb0nC+Qgk7LeRhjDSNOn/vstrTuHIXnlHNOWRgn1Y6CGc9vTI78Xgj8V2xhezgW+DyI5KFUh76ZMb+5VT613T4Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712827689; c=relaxed/simple; bh=zITqgZVojLh4dUSaGKV239z9RvbFs2+NfPNhuOaA6RY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=kiKzvkUoW2M3UdHshXibZwI4Rp6HBTh4cululUDP5QG+4vUWIJpQDEeMXMoR3V6xzXVHYGfGfCB60VjG+rOi8VMzf7QF9kx8+d1MRRNqwYBMNGiu5d0U8anUxlpHYjUJGr0h7iJC99IKNV2VgV8G/yfLLWhfqHLWYgLrMS2uvqI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OHHacQgD; arc=none smtp.client-ip=192.198.163.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OHHacQgD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712827687; x=1744363687; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=zITqgZVojLh4dUSaGKV239z9RvbFs2+NfPNhuOaA6RY=; b=OHHacQgDYRiNowmTSbhA9P6GvF9lTuwW6mgJXtjAN9CVGs3v5hpa9Vwl Zc59bfEg+q8kR7mwDw9FFe7D2NYeVZ4GkfW6a7u+q2mfhdFgXRRm0MW4C LukqIi47l/0LlE2x9FMWiyrxQjqSr97ogBGszsoIgRTEw95bVFMzo+0vl 2l45m0l/QgvDIg2PrXvNbF+Daqj9cl/gHV8WdKQk9+2p70iDU8yWLoo34 J8xzKtFVL8KCAgywbAvbM2z0I5G0ljaNaWuGSArXV+QKMFifZcRBIPk8m IySOuRBZO0O88lwLkw6JkyjvoaS1XxQbjvBWuhZGBI/+9gEfZVnTqNtOW w==; X-CSE-ConnectionGUID: N9AKuPqDSkqw1ah5BaW1UA== X-CSE-MsgGUID: 9iM7Pl4AR+apieVATzFJ0A== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="8083353" X-IronPort-AV: E=Sophos;i="6.07,193,1708416000"; d="scan'208";a="8083353" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2024 02:28:05 -0700 X-CSE-ConnectionGUID: off1ptQUS5SR8wQ5l3jZ/Q== X-CSE-MsgGUID: WwenVoetQbuHdgS5T+1EqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,193,1708416000"; d="scan'208";a="25622263" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.251.215.66]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2024 02:27:58 -0700 Message-ID: <4d429a10-eb45-4262-8e74-69af810ef1ac@intel.com> Date: Thu, 11 Apr 2024 12:27:53 +0300 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] bug: Fix no-return-statement warning with !CONFIG_BUG To: Christophe Leroy , Arnd Bergmann Cc: Naresh Kamboju , Michael Ellerman , Nicholas Piggin , "Aneesh Kumar K.V" , "Naveen N. Rao" , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , Ingo Molnar , Borislav Petkov , Dave Hansen , "x86@kernel.org" , "H. Peter Anvin" , Andy Lutomirski , Vincenzo Frascino , John Stultz , Stephen Boyd , Peter Zijlstra , Randy Dunlap , Bjorn Helgaas , Anna-Maria Gleixner , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" , "linux-s390@vger.kernel.org" , Thomas Gleixner References: <20240410153212.127477-1-adrian.hunter@intel.com> <87be83da-6102-483d-b1dc-a77eecc9f780@app.fastmail.com> Content-Language: en-US From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 11/04/24 11:22, Christophe Leroy wrote: > > > Le 11/04/2024 à 10:12, Christophe Leroy a écrit : >> >> >> Le 11/04/2024 à 09:16, Adrian Hunter a écrit : >>> 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 >>> >>>     https://lore.kernel.org/all/CA+G9fYvjdZCW=7ZGxS6A_3bysjQ56YF7S-+PNLQ_8a4DKh1Bhg@mail.gmail.com/ >>> >> >> Looking at the report, I think the correct fix should be to use >> BUILD_BUG() instead of BUG() > > I confirm the error goes away with the following change to next-20240411 > on powerpc tinyconfig with gcc 13.2 > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index 4e18db1819f8..3d5ac0cdd721 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -282,7 +282,7 @@ static inline void timekeeping_check_update(struct > timekeeper *tk, u64 offset) > } > static inline u64 timekeeping_debug_get_ns(const struct tk_read_base *tkr) > { > - BUG(); > + BUILD_BUG(); > } > #endif > That is fragile because it depends on defined(__OPTIMIZE__), so it should still be: BUILD_BUG(); return 0; From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5ABA5CD128A for ; Thu, 11 Apr 2024 09:28:54 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=mdPGjSNV; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VFZBr5CBDz3vXc for ; Thu, 11 Apr 2024 19:28:52 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=mdPGjSNV; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=intel.com (client-ip=192.198.163.19; helo=mgamail.intel.com; envelope-from=adrian.hunter@intel.com; receiver=lists.ozlabs.org) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VFZB23NJkz3bq0 for ; Thu, 11 Apr 2024 19:28:08 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712827690; x=1744363690; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=zITqgZVojLh4dUSaGKV239z9RvbFs2+NfPNhuOaA6RY=; b=mdPGjSNVB30cUHomHmjBo7DOroMf9J1cSX5GHqu0aSOcBq/xL7oncM9D ACykMnwWcUm4RbJYaKt792BxK3dERXcbx50Wtn7MsiPUjRi+/XssnzIKo HG14RP1JQ09gQvLqDAwUTgC20hqlTWogOY5EaroCEuX04SRG5GCuXYJUb 6TbdhV18MBX8qUQ0wI8hUphSAyrpanZFZT0TMQRKQzOZrPzkrMTGKMpo3 n9SwnUGERBv6pkdSh6LM2JP+oZvDrQ+r18ESJI6jJIvWDGyfNtj0EIcSb liGQaAfxqN0T7rLqX+Znh+iPIAXx4LSN1GVyd5g1ssnj64/7PFxhVKi61 A==; X-CSE-ConnectionGUID: pW2+Dx2bQQqbmCJ4RmqFsA== X-CSE-MsgGUID: RVQEcjRsTY2nXR+XKWHMZg== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="8083340" X-IronPort-AV: E=Sophos;i="6.07,193,1708416000"; d="scan'208";a="8083340" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2024 02:28:05 -0700 X-CSE-ConnectionGUID: off1ptQUS5SR8wQ5l3jZ/Q== X-CSE-MsgGUID: WwenVoetQbuHdgS5T+1EqA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,193,1708416000"; d="scan'208";a="25622263" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.251.215.66]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2024 02:27:58 -0700 Message-ID: <4d429a10-eb45-4262-8e74-69af810ef1ac@intel.com> Date: Thu, 11 Apr 2024 12:27:53 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] bug: Fix no-return-statement warning with !CONFIG_BUG To: Christophe Leroy , Arnd Bergmann References: <20240410153212.127477-1-adrian.hunter@intel.com> <87be83da-6102-483d-b1dc-a77eecc9f780@app.fastmail.com> Content-Language: en-US From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Zijlstra , Dave Hansen , John Stultz , "H. Peter Anvin" , Alexander Gordeev , Vincenzo Frascino , "linux-s390@vger.kernel.org" , Naresh Kamboju , "x86@kernel.org" , "Aneesh Kumar K.V" , Ingo Molnar , "Naveen N. Rao" , Christian Borntraeger , Vasily Gorbik , Heiko Carstens , Nicholas Piggin , Borislav Petkov , Andy Lutomirski , Bjorn Helgaas , Thomas Gleixner , Anna-Maria Gleixner , Stephen Boyd , Randy Dunlap , "linux-kernel@vger.kernel.org" , Sven Sch nelle , "linuxppc-dev@lists.ozlabs.org" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On 11/04/24 11:22, Christophe Leroy wrote: > > > Le 11/04/2024 à 10:12, Christophe Leroy a écrit : >> >> >> Le 11/04/2024 à 09:16, Adrian Hunter a écrit : >>> 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 >>> >>>     https://lore.kernel.org/all/CA+G9fYvjdZCW=7ZGxS6A_3bysjQ56YF7S-+PNLQ_8a4DKh1Bhg@mail.gmail.com/ >>> >> >> Looking at the report, I think the correct fix should be to use >> BUILD_BUG() instead of BUG() > > I confirm the error goes away with the following change to next-20240411 > on powerpc tinyconfig with gcc 13.2 > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index 4e18db1819f8..3d5ac0cdd721 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -282,7 +282,7 @@ static inline void timekeeping_check_update(struct > timekeeper *tk, u64 offset) > } > static inline u64 timekeeping_debug_get_ns(const struct tk_read_base *tkr) > { > - BUG(); > + BUILD_BUG(); > } > #endif > That is fragile because it depends on defined(__OPTIMIZE__), so it should still be: BUILD_BUG(); return 0;