[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2] lib: extend ASSERT()


  • To: Julien Grall <julien@xxxxxxx>
  • From: Bertrand Marquis <Bertrand.Marquis@xxxxxxx>
  • Date: Wed, 16 Feb 2022 09:25:07 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ERvVUvPQYrt93/XLk61uDEFALhwDIgk3XgZP011Jyg0=; b=WbJxZ3ME2ZzE2CXQh3hgWo+Gv5WDlcBQ3T9x6hf8/MDtfo2pB0GAUxEQ9/IyoS9FcC0GpVHqtf8q8rhK3BxGYqbXzaB2uznF0Mv/hVXFR29anBdJS0X5bHwCTflHWXR/vcerBV0J1S1GUvqrCerlkRmkbHdKaqIg528U2Q9NrYdNOIg7zN1QvdHqBiLVfeXJ2s/qKHgpS/rGZoToJWPMPvQ71qIHOTrtSL0msk1nC7AvBQFsrhqvrkFmeHKcGfkv9jFHeZmPiXMqKlLcKqo3PPC6uXxmfgDJZ1mLS7//mvN9Sg7Qdw2EQQwsFcwAbyNKOyt/GjdZ+DThfs5y4Sm9yA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iMn3EojuW8uCH99oY/OIY0SKPYE5hTXyaZLzoVwHida1iWPUIwlI+T1nlLSYoZ015rBdUlV98Py8hAgwgThzU6H7peta4LOYZp3xxXAVuLzYddyuZyWTaeyAl70npnLySuwudwZMbQSdeLhK26BdzurY4jP2lHJr9eQ2O0IVk22sSsVqCKJQxGnLZxQqmITrY5P0ZbGknKo4xPz0atkCENCr04IL2w7iRXH3a8KIaZfNvFooPqtV2500hhwv0uY3HFkfHl7wr/4nCCGAAFzIJkYB/gGSSGCI5/n438GlrsEjmdqBRXfUC3ihpoLfvPAi12Om9ypa0YyFrZ+d611lqQ==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: Jan Beulich <jbeulich@xxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Wed, 16 Feb 2022 09:25:28 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Original-authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Thread-index: AQHYE4sUwaOwwc8tCU249z99fRIDqqyVNw0AgADQBoA=
  • Thread-topic: [PATCH v2] lib: extend ASSERT()

Hi Jan, Julien,

> On 15 Feb 2022, at 21:00, Julien Grall <julien@xxxxxxx> wrote:
> 
> (+ Bertrand)
> 
> Hi Jan,
> 
> On 27/01/2022 14:34, 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).
> 
> So I agree that this construct will always result to a minimum 5 lines. Which 
> is not nice. But the proposed change is...
> 
>> 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 <jbeulich@xxxxxxxx>
>> ---
>> v2: Rename new macro parameter.
>> ---
>> RFC: The use of a control flow construct as a macro argument may be
>>      controversial.
> 
> indeed controversial. I find this quite confusing and not something I would 
> request a user to switch to if they use the longer version.
> 
> That said, this is mainly a matter of taste. So I am interested to hear 
> others view.
> 
> I have also CCed Bertrand to have an opinions from the Fusa Group (I suspect 
> this will go backward for them).

Thanks and here is my feedback in regards to Fusa here.

Most certification standards are forbidding completely macros including
conditions (and quite a number are forbidding static inline with conditions).
The main reason for that is MCDC coverage (condition/decisions and not only
code line) is not possible to do anymore down to the source code and has to be
done down to the pre-processed code.

Out of Fusa considerations, one thing I do not like in this solution is the 
fact that
you put some code as parameter of the macro (the return).

To make this a bit better you could put the return code as parameter
instead of having “return CODE” as parameter.

An other thing is that Xen ASSERT after this change will be quite different from
any ASSERT found in other projects which could make it misleading for 
developers.
Maybe we could introduce an ASSERT_RETURN macros instead of modifying the
behaviour of the standard ASSERT ?

Regards
Bertrand

> 
>> --- a/xen/common/memory.c
>> +++ b/xen/common/memory.c
>> @@ -826,11 +826,7 @@ int xenmem_add_to_physmap(struct domain
>>      union add_to_physmap_extra extra = {};
>>      struct page_info *pages[16];
>>  -    if ( !paging_mode_translate(d) )
>> -    {
>> -        ASSERT_UNREACHABLE();
>> -        return -EACCES;
>> -    }
>> +    ASSERT(paging_mode_translate(d), return -EACCES);
>>        if ( xatp->space == XENMAPSPACE_gmfn_foreign )
>>          extra.foreign_domid = DOMID_INVALID;
>> @@ -920,11 +916,7 @@ static int xenmem_add_to_physmap_batch(s
>>       * call doesn't succumb to dead-code-elimination. Duplicate the 
>> short-circut
>>       * from xatp_permission_check() to try and help the compiler out.
>>       */
>> -    if ( !paging_mode_translate(d) )
>> -    {
>> -        ASSERT_UNREACHABLE();
>> -        return -EACCES;
>> -    }
>> +    ASSERT(paging_mode_translate(d), return -EACCES);
>>        if ( unlikely(xatpb->size < extent) )
>>          return -EILSEQ;
>> --- a/xen/include/xen/lib.h
>> +++ b/xen/include/xen/lib.h
>> @@ -49,11 +49,13 @@
>>  #endif
>>    #ifndef NDEBUG
>> -#define ASSERT(p) \
>> +#define ASSERT(p, ...) \
>>      do { if ( unlikely(!(p)) ) assert_failed(#p); } while (0)
>>  #define ASSERT_UNREACHABLE() assert_failed("unreachable")
>>  #else
>> -#define ASSERT(p) do { if ( 0 && (p) ) {} } while (0)
>> +#define ASSERT(p, failsafe...) do { \
>> +        if ( !count_args(failsafe) || unlikely(!(p)) ) { failsafe; } \
>> +    } while ( 0 )
>>  #define ASSERT_UNREACHABLE() do { } while (0)
>>  #endif
>>  
> 
> Cheers,
> 
> -- 
> Julien Grall


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.