* [PATCH v2] xen: Rework WARN_ON() to return whether a warning was triggered
@ 2020-12-18 13:30 Julien Grall
2020-12-18 18:56 ` Stefano Stabellini
2020-12-21 8:47 ` Jan Beulich
0 siblings, 2 replies; 3+ messages in thread
From: Julien Grall @ 2020-12-18 13:30 UTC (permalink / raw)
To: xen-devel
Cc: bertrand.marquis, Rahul.Singh, Julien Grall, Andrew Cooper,
George Dunlap, Ian Jackson, Jan Beulich, Julien Grall,
Stefano Stabellini, Wei Liu, Juergen Gross
From: Julien Grall <jgrall@amazon.com>
So far, our implementation of WARN_ON() cannot be used in the following
situation:
if ( WARN_ON() )
...
This is because WARN_ON() doesn't return whether a warning has been
triggered. Such construciton can be handy if you want to print more
information and also dump the stack trace.
Therefore, rework the WARN_ON() implementation to return whether a
warning was triggered. The idea was borrowed from Linux
Signed-off-by: Julien Grall <jgrall@amazon.com>
Reviewed-by: Juergen Gross <jgross@suse.com>
Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
---
Changes in v2:
- Rework the commit message
- Don't use trailing underscore
- Add Bertrand's and Juergen's reviewed-by
---
xen/include/xen/lib.h | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
index 48429b69b8df..5841bd489c35 100644
--- a/xen/include/xen/lib.h
+++ b/xen/include/xen/lib.h
@@ -23,7 +23,13 @@
#include <asm/bug.h>
#define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
-#define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
+#define WARN_ON(p) ({ \
+ bool ret_warn_on_ = (p); \
+ \
+ if ( unlikely(ret_warn_on_) ) \
+ WARN(); \
+ unlikely(ret_warn_on_); \
+})
/* All clang versions supported by Xen have _Static_assert. */
#if defined(__clang__) || \
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] xen: Rework WARN_ON() to return whether a warning was triggered
2020-12-18 13:30 [PATCH v2] xen: Rework WARN_ON() to return whether a warning was triggered Julien Grall
@ 2020-12-18 18:56 ` Stefano Stabellini
2020-12-21 8:47 ` Jan Beulich
1 sibling, 0 replies; 3+ messages in thread
From: Stefano Stabellini @ 2020-12-18 18:56 UTC (permalink / raw)
To: Julien Grall
Cc: xen-devel, bertrand.marquis, Rahul.Singh, Julien Grall,
Andrew Cooper, George Dunlap, Ian Jackson, Jan Beulich,
Stefano Stabellini, Wei Liu, Juergen Gross
On Fri, 18 Dec 2020, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
>
> So far, our implementation of WARN_ON() cannot be used in the following
> situation:
>
> if ( WARN_ON() )
> ...
>
> This is because WARN_ON() doesn't return whether a warning has been
> triggered. Such construciton can be handy if you want to print more
> information and also dump the stack trace.
>
> Therefore, rework the WARN_ON() implementation to return whether a
> warning was triggered. The idea was borrowed from Linux
>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
> Reviewed-by: Juergen Gross <jgross@suse.com>
> Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
Acked-by: Stefano Stabellini <sstabellini@kernel.org>
> ---
> Changes in v2:
> - Rework the commit message
> - Don't use trailing underscore
> - Add Bertrand's and Juergen's reviewed-by
> ---
> xen/include/xen/lib.h | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/xen/include/xen/lib.h b/xen/include/xen/lib.h
> index 48429b69b8df..5841bd489c35 100644
> --- a/xen/include/xen/lib.h
> +++ b/xen/include/xen/lib.h
> @@ -23,7 +23,13 @@
> #include <asm/bug.h>
>
> #define BUG_ON(p) do { if (unlikely(p)) BUG(); } while (0)
> -#define WARN_ON(p) do { if (unlikely(p)) WARN(); } while (0)
> +#define WARN_ON(p) ({ \
> + bool ret_warn_on_ = (p); \
> + \
> + if ( unlikely(ret_warn_on_) ) \
> + WARN(); \
> + unlikely(ret_warn_on_); \
> +})
>
> /* All clang versions supported by Xen have _Static_assert. */
> #if defined(__clang__) || \
> --
> 2.17.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] xen: Rework WARN_ON() to return whether a warning was triggered
2020-12-18 13:30 [PATCH v2] xen: Rework WARN_ON() to return whether a warning was triggered Julien Grall
2020-12-18 18:56 ` Stefano Stabellini
@ 2020-12-21 8:47 ` Jan Beulich
1 sibling, 0 replies; 3+ messages in thread
From: Jan Beulich @ 2020-12-21 8:47 UTC (permalink / raw)
To: Julien Grall
Cc: bertrand.marquis, Rahul.Singh, Julien Grall, Andrew Cooper,
George Dunlap, Ian Jackson, Stefano Stabellini, Wei Liu,
Juergen Gross, xen-devel
On 18.12.2020 14:30, Julien Grall wrote:
> From: Julien Grall <jgrall@amazon.com>
>
> So far, our implementation of WARN_ON() cannot be used in the following
> situation:
>
> if ( WARN_ON() )
> ...
>
> This is because WARN_ON() doesn't return whether a warning has been
> triggered. Such construciton can be handy if you want to print more
> information and also dump the stack trace.
>
> Therefore, rework the WARN_ON() implementation to return whether a
> warning was triggered. The idea was borrowed from Linux
>
> Signed-off-by: Julien Grall <jgrall@amazon.com>
> Reviewed-by: Juergen Gross <jgross@suse.com>
> Reviewed-by: Bertrand Marquis <bertrand.marquis@arm.com>
In particular to clarify my prior concerns have been addressed:
Acked-by: Jan Beulich <jbeulich@suse.com>
Jan
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-21 8:47 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-18 13:30 [PATCH v2] xen: Rework WARN_ON() to return whether a warning was triggered Julien Grall
2020-12-18 18:56 ` Stefano Stabellini
2020-12-21 8:47 ` Jan Beulich
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.