Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8A9EBC433E0 for ; Tue, 5 Jan 2021 14:47:17 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5189622B45 for ; Tue, 5 Jan 2021 14:47:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5189622B45 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.62025.109526 (Exim 4.92) (envelope-from ) id 1kwnc5-0002yk-3h; Tue, 05 Jan 2021 14:47:09 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 62025.109526; Tue, 05 Jan 2021 14:47:09 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwnc5-0002yd-0n; Tue, 05 Jan 2021 14:47:09 +0000 Received: by outflank-mailman (input) for mailman id 62025; Tue, 05 Jan 2021 14:47:07 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kwnc3-0002yW-SV for xen-devel@lists.xenproject.org; Tue, 05 Jan 2021 14:47:07 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id add2f3be-5470-4337-9f4a-c6785c01104b; Tue, 05 Jan 2021 14:47:06 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 167DEAA7C; Tue, 5 Jan 2021 14:47:06 +0000 (UTC) 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: add2f3be-5470-4337-9f4a-c6785c01104b X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1609858026; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=eKe8X2YEOx6i+NnPh2d4vzoW4AVTKnJD+NJ4Y7ik2z0=; b=kdz+dHsG2J1LdnPWTOfXKCS3QFtikXWRN8o25ceUIoyMox8wmrIkTLfs1KqL4bl/W6GA6H 6wj8opiXAgBQUSz0qnuKsQH5jtmziY8TvjraFvUcsDKak2GzfbDasLGcKY8AedRFwOqs4v jsk3za9sGqnVityeXObgUDuWOdf8ReU= Subject: Re: [PATCH RFC] lib: extend ASSERT() To: Andrew Cooper Cc: George Dunlap , Ian Jackson , Julien Grall , Stefano Stabellini , Wei Liu , "xen-devel@lists.xenproject.org" References: <8afb661c-a2eb-3188-8351-01de16ff1b22@suse.com> <4d46370c-44a5-07de-9e7d-ab4611e941bf@citrix.com> From: Jan Beulich Message-ID: <5d032a58-c79c-e8b7-1caa-1e229e14e866@suse.com> Date: Tue, 5 Jan 2021 15:47:05 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.0 MIME-Version: 1.0 In-Reply-To: <4d46370c-44a5-07de-9e7d-ab4611e941bf@citrix.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 05.01.2021 14:56, Andrew Cooper wrote: > On 05/01/2021 12:45, Jan Beulich wrote: >> The increasing amount of constructs along the lines of >> >> if ( !condition ) >> { >> ASSERT_UNREACHABLE(); >> return; >> } >> >> is not only longer than necessary, but also doesn't produce incident >> specific console output (except for file name and line number). Allow >> the intended effect to be achieved with ASSERT(), by giving it a second >> parameter allowing specification of the action to take in release builds >> in case an assertion would have triggered in a debug one. The example >> above then becomes >> >> ASSERT(condition, return); >> >> Make sure the condition will continue to not get evaluated when just a >> single argument gets passed to ASSERT(). >> >> Signed-off-by: Jan Beulich >> --- >> RFC: The use of a control flow construct as a macro argument may be >> controversial. > > So I had been putting some consideration towards this.  I agree that the > current use of ASSERT_UNREACHABLE() isn't great, and that we ought to do > something to improve the status quo. > > However, the more interesting constructs to consider are the ones with > printk()'s and/or domain_crash().  While a straight return or goto in > alt... is perhaps acceptable, anything more complicated probably isn't. Since syntactically this is no problem, it is up to us whether we consider this unacceptable. Personally I wouldn't mind as long as the set of statements doesn't get excessive. Otoh I'm not sure the more complex uses are in need of such a transformation - the relatively simple ones are where the current arrangement has most significant impact. > I also found, with my still-pending domain_crash() cleanup series, that > domain_crash()/ASSERT_UNREACHABE()/return/goto became an increasingly > common combination. Which may call for further abstraction along the lines of what I'm doing here? >> --- a/xen/include/xen/lib.h >> +++ b/xen/include/xen/lib.h >> @@ -55,12 +55,14 @@ >> #endif >> >> #ifndef NDEBUG >> -#define ASSERT(p) \ >> +#define ASSERT(p, ...) \ >> do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0) >> #define ASSERT_UNREACHABLE() assert_failed("unreachable") >> #define debug_build() 1 >> #else >> -#define ASSERT(p) do { if ( 0 && (p) ) {} } while (0) >> +#define ASSERT(p, alt...) do { \ >> + if ( !count_args(alt) || unlikely(!(p)) ) { alt; } \ > > I'd strongly recommend naming this failsafe... rather than alt, to make > it clear what its purpose is. No problem. Albeit I wonder whether "failsafe" is really better - maybe "fallback"? > Also, we really can't have (p) conditionally evaluated depending on > whether there are any failsafe arguments or not.  It is already bad > enough that its state of evaluation differs between debug and release > builds. Are you suggesting to evaluate it unconditionally, producing unnecessary binary code in release builds _and_ diverging from the C standard's assert()? I'm not outright against, but I'm also not sure this is a good idea. But like you I also don't really like the new asymmetry, but I thought it would be best to leave existing uses of ASSERT() entirely unchanged in their behavior. Jan