Received: by 2002:ab2:1347:0:b0:1f4:ac9d:b246 with SMTP id g7csp271858lqg; Thu, 11 Apr 2024 02:14:42 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWd8dBxk2XwjcO8F6XwJNUuJ3s0wfVOSFacpSsfBthgiAF/Do1lVsxO/8RU8C3CoBkL5rojLLfPUHt3w4GC9dGcGt9JlOaCL/7XZ79CVQ== X-Google-Smtp-Source: AGHT+IGxFmtMaoYm6/s/qdTlDqcajX5hmkp9Fj9Gv0sUrYNOqEkyoqynlXbweCKb2/wgcN0m1HXY X-Received: by 2002:a50:ccdb:0:b0:56e:64b:8733 with SMTP id b27-20020a50ccdb000000b0056e064b8733mr3513373edj.40.1712826882638; Thu, 11 Apr 2024 02:14:42 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712826882; cv=pass; d=google.com; s=arc-20160816; b=KALwG2mZ5dnWG8Gc9CKuYTGlwzrKhnKqS2jBZm9ZY//1HRZwGlVk9X8xuzhohijgY1 Egh82XZPC79431eGatsMDIkthgzUwCE/Pdp4ADo7p7xjF34/bt4jwdrQCski63zGOmkU Yx6PY2NYaRmgdgqikSgOFLkyDE8qOYWeyl+FAwRllidiXSFR2lvkQtvYrT27dGTVoFU5 +RMPOz0Zyv9+DUQxhK3r8e9L+/1wu6OnrgmQYNQal1o0kuLdpXLv8j19+zN8kcZWr1tF s0l/llowaWt1oWp1e4Zh3bJrVEmCFE6KMOY4YMAXtGwkmDqiFB2DzPOy6C9Z1AUVgEpg kOvw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:date:message-id :dkim-signature; bh=RVOX2f+6vPzIEavSn3Z44c56fm48kd/aUWN5wj0Jgu4=; fh=uJan4VyNGtDAMAsdXFBLT3BXAJPYoKp4s1XyP+vr3O8=; b=KKMtF5TiqoGhzF3u49gs4lBPBNNK7C+Du+jjqlFIV96aVyPNOUTm0CQUFeKoFtX6p0 xlRQDQbAnBPbiKCmIL78B39HNkBnCnpuHEDEhZ6B/KcXHN5Jx8g6NztKHM3G1OWqN2z+ CFS7oPmhsAk/6fnGBiTxymb7SSkpuaGVXEn4ILbaW4eEmB9WIGeiurOa3j/wDAUYV2EG Tghkc8nR35bpyiiTZ5Q7OgQXvHawPIozU1Blly0RiFO4UZl+A9/D7VBjZHIGyWseMgNN cx3f6iGI0T+oADpmmWyQvhv6L1dOPpagfVf4V/kL1oTJ/R0Co2CsBwnIOjtLGSY2nxL9 9cAw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=disR6yM2; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-140130-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140130-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id z13-20020a1709063acd00b00a51d8b6b83fsi554494ejd.423.2024.04.11.02.14.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 02:14:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-140130-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=disR6yM2; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-140130-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-140130-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id C8B1B1F25469 for ; Thu, 11 Apr 2024 09:04:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7334F1428EA; Thu, 11 Apr 2024 09:04:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="disR6yM2" 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 smtp.subspace.kernel.org (Postfix) with ESMTPS id 00CBA62144; Thu, 11 Apr 2024 09:04:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712826245; cv=none; b=TAWo9e5f1CFyHjFKDyERPYkHA8dTO1EWbEQIwCR/2Jc5l0Zt4PqBDh9XWBYu/q9UVjm0fJABGCeti1GkeC5F7FHgDf8pPE+Quy1evAz5L+bMa2/9iLOTBzqeYNtt02CFMqpBUWIOcd0b9y6jFBsiCeZteNFB0Vtprn7Yc4ExDpo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712826245; c=relaxed/simple; bh=psBauhL+pjKeENmsetnmfnJUWvmR2xRdeP4w3fPxpxw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=KCxW09vmgxPyX8YPYMPPpo1tv9XD9Z05IfPSWaXkT/2YvXf1COfM5aqeXuv+/Vvae9158lgjAwv8RoP06lzXcc+vnDcMExd1K73Fha/cr4X8zY/cdmq7yPoxTY5iY3vZmE3VoGyFqgFOQoA+WY+4TDeW8aL1Jt1LU/4f0oiVsv8= 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=disR6yM2; arc=none smtp.client-ip=192.198.163.13 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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712826244; x=1744362244; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=psBauhL+pjKeENmsetnmfnJUWvmR2xRdeP4w3fPxpxw=; b=disR6yM2opfBgNKyUJbqJ8EpNYe32CPDu0cJn9ohBSfScrWFYCQTNgMT KeXQg6JkErTerG1PGlMIAm9pn2xdJfhgITmGj4esvHBTo4+4+kgMbRljs w2dsDi+dC0fdujkg0ombirx9F/jgUCGaN8ZUzruPFG+jQtl3gzxNavJuh HcwFSxSOGewS1xTodXaIvsuHMIqTRgotsWztlnkW2oVGUKZdgVpgr7rEg Q9v9W1bJNe1/W3wxEekzbn4SZBtHy77xutcUncXIlu1DQ1K2lhuacqeFl udhDgLKeK86f0uXV9UpJEkk1gvZsKjSKQYAYNv8z2FcOzz3P+pmSsQVV3 g==; X-CSE-ConnectionGUID: yxqXurRcSt24+Eew1QQSjg== X-CSE-MsgGUID: ZYGkJ0kISaKuOjQtRnBxoQ== X-IronPort-AV: E=McAfee;i="6600,9927,11039"; a="11186361" X-IronPort-AV: E=Sophos;i="6.07,193,1708416000"; d="scan'208";a="11186361" 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 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: Arnd Bergmann 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 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 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