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 59CA6CD128A for ; Thu, 11 Apr 2024 09:04:56 +0000 (UTC) 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=lGL4GD0a; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VFYgC06qPz3vZx for ; Thu, 11 Apr 2024 19:04:55 +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=lGL4GD0a; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=intel.com (client-ip=192.198.163.13; 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.13]) (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 4VFYfK1K2jz3bWH for ; Thu, 11 Apr 2024 19:04:06 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712826250; x=1744362250; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=psBauhL+pjKeENmsetnmfnJUWvmR2xRdeP4w3fPxpxw=; b=lGL4GD0aL7ud0pmg64Cw++T1SEoFc7z2Dns2aFGkfjmBi1KXcRa7WLdF pc+3diADn/G0D72nm6tTrOFrBhIIT6sSso9m8T2WCc6s+dIIip12TsCu0 f0AGsLHKnB8nD4n2riaBY15mMyhc/TNaMo8WuQeijwWmcTfIgPSQEjide oxKYF0AG82vCyNL+AoDYu8tIrYMvACmVAgHSx9WbP88ayLZ1Y5VillQRo NCJzIoxCG4oh+KiWG1zxSWtiMrLFew/HolR6ERoKH+AewWyLQNaYeClox o5atO2nnXrd60Tunse5s77pp09GzVyOUvH7LE1SZwxN8HoLJO+W/jJrF7 A==; X-CSE-ConnectionGUID: c5sSIMzjTdSnAitYYGRwcw== X-CSE-MsgGUID: A3qxNRh7QnGJN7iZpS2yxQ== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="11186370" X-IronPort-AV: E=Sophos;i="6.07,193,1708416000"; d="scan'208";a="11186370" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2024 02:04:02 -0700 X-CSE-ConnectionGUID: jxyzJahlR7mafm9v/t3HUQ== X-CSE-MsgGUID: 7WEppJyAQbCpQrc3PO3miw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,193,1708416000"; d="scan'208";a="20799716" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO [10.0.2.15]) ([10.251.215.66]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 11 Apr 2024 02:03:56 -0700 Message-ID: <0fd5e869-720f-41bb-9f0f-c0f3925ffc1b@intel.com> Date: Thu, 11 Apr 2024 12:03:52 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] bug: Fix no-return-statement warning with !CONFIG_BUG To: 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 Schnelle , 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 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. > 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. > > clang-12 and above do work like gcc, so I guess that is good. > > Arnd