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

[PATCH v2] lib: extend ASSERT()


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Thu, 27 Jan 2022 15:34:41 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; 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=j6uvKqA9HgHe7EOgU3bZKcgbjXHaT84fxzLyjZIduUg=; b=IZ5tgGFPGmNGrBt1xb2UNKdzwnSrXMsgS28Wrg+1EAv8+PZtMd6znCiWW+lbNzKGB0NT9XN3tSMVJEpbBfTptR+DjARQnN5bLtNuVYAKBZeBIgM0QQAW3Y5qh6i8kTKAgr6A7d4U4dNgHRZBjSUowkWQReKrR9MxF48MpeesB9ADLXcTWjn8oyMwlclydqz10GvHe3eoUQKXYGmipRxR8oy/HLTkGdTOL12Pqru+ROkGbVBKX8V/05Us0v/Mok9aCrS5SUMv4EJbZCUjN53uwlVLDgPSPyyMnb+foj5C5Rl9DDNZaO8kC9yN+Snb21/HBt5eVABj7Heu0tw/+fHdqQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ahlpuid3CepbKN+EbaKk3EwnV0dHrFTUV1l+qjfSUoP8LILdCXbhKsBF+ijVbVoRhXjhpf6jv0J6J+qArmcmUt6DMp0GwOwEQ1bSQVhqmqInW0akkp2m3VTZ4fkLjaAdBl2UGVfnFBOnIeMSxeZdvDunSxNcYjtLEj/qw0nT6/rGbxHRbc229HWYjHjvAk4fpYrYAODnXxszW0odsJH+4Y2lGlfLpGYj6tKS7dlnYwrAfX/ZFauhQ4p4pgjbCPiHAs221MXWy3fURHkBwhsdhBOYHY1RaEWadGioAlIHcdG9QnvvwWs05eQYHGgBqA55wz9BZaPEI1zF6OccSv7gaw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Delivery-date: Thu, 27 Jan 2022 14:34:58 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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 <jbeulich@xxxxxxxx>
---
v2: Rename new macro parameter.
---
RFC: The use of a control flow construct as a macro argument may be
     controversial.

--- 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
 




 


Rackspace

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