From patchwork Wed Aug 24 10:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SsO8cmdlbiBHcm/Dnw==?= X-Patchwork-Id: 12953185 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.xenproject.org (lists.xenproject.org [192.237.175.120]) (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 281A3C00140 for ; Wed, 24 Aug 2022 10:22:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.392368.630670 (Exim 4.92) (envelope-from ) id 1oQnWn-00039s-LY; Wed, 24 Aug 2022 10:22:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 392368.630670; Wed, 24 Aug 2022 10:22:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oQnWn-00039l-Ir; Wed, 24 Aug 2022 10:22:29 +0000 Received: by outflank-mailman (input) for mailman id 392368; Wed, 24 Aug 2022 10:22:28 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1oQnWm-00039P-4i for xen-devel@lists.xenproject.org; Wed, 24 Aug 2022 10:22:28 +0000 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id a6d0ec8e-2396-11ed-9250-1f966e50362f; Wed, 24 Aug 2022 12:22:27 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id B7278203AB; Wed, 24 Aug 2022 10:22:26 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 69BBE13AC0; Wed, 24 Aug 2022 10:22:26 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id z1VqGOL7BWNCGQAAMHmgww (envelope-from ); Wed, 24 Aug 2022 10:22:26 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: a6d0ec8e-2396-11ed-9250-1f966e50362f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1661336546; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=/7EYD7Keid1p57myps4QR3QvxF3egN0T6fhaNudvLW0=; b=Vc4VIyX2sK0MlN5HoOs6QGgP7qxdRX1eTIKAMnFz3PdckVok5H88iTzSjA9UaMaEeUTwUb tUBwA8K17e2PkI5L1lrUwQABsF6TpWG8tBHKi58mKrjvqYoC1ilQbqtpEdiobe/wLCakYW gUW6IFi7xrCwtzLibB5gYT9IW+KTcvs= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Henry.Wang@arm.com, Juergen Gross , Andrew Cooper , George Dunlap , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu Subject: [PATCH] xen: let ASSERT_UNREACHABLE() WARN() in non-debug builds Date: Wed, 24 Aug 2022 12:22:25 +0200 Message-Id: <20220824102225.11431-1-jgross@suse.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Hitting an ASSERT_UNREACHABLE() is always wrong, so even in production builds a warning seems to be appropriate when hitting one. In order not to flood the console in reproducible cases, introduce WARN_ONCE() to be used in this case. Signed-off-by: Juergen Gross Acked-by: Julien Grall --- Notice for the release manager: this patch isn't really urgent for the 4.17 release, OTOH it is adding probably useful debug information for the unlikely case of hitting an ASSERT_UNREACHABLE(). The risk for taking the patch should be rather low, but you have the last saying, of course. Signed-off-by: Juergen Gross --- xen/include/xen/lib.h | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h index 05ee1e18af..b8472d753c 100644 --- a/xen/include/xen/lib.h +++ b/xen/include/xen/lib.h @@ -40,6 +40,16 @@ unlikely(ret_warn_on_); \ }) +#define WARN_ONCE() do { \ + static bool warned = false; \ + \ + if ( !warned ) \ + { \ + warned = true; \ + WARN(); \ + } \ +} while (0) + /* All clang versions supported by Xen have _Static_assert. */ #if defined(__clang__) || \ (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) @@ -63,7 +73,7 @@ #define ASSERT_UNREACHABLE() assert_failed("unreachable") #else #define ASSERT(p) do { if ( 0 && (p) ) {} } while (0) -#define ASSERT_UNREACHABLE() do { } while (0) +#define ASSERT_UNREACHABLE() WARN_ONCE() #endif #define ABS(_x) ({ \