diff mbox

[v4,06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks.

Message ID 20160322153942.GA20062@char.us.oracle.com (mailing list archive)
State New, archived
Headers show

Commit Message

Konrad Rzeszutek Wilk March 22, 2016, 3:39 p.m. UTC
On Mon, Mar 21, 2016 at 06:49:03AM -0600, Jan Beulich wrote:
> >>> On 18.03.16 at 20:59, <konrad.wilk@oracle.com> wrote:
> > I know I copied and pasted it and I must have done something uncanny.
> > 
> > Anyhow this is what the change looks like now (I've retained the Reviewed
> > and Ack as I think this change is mostly cosmetical in nature?)
> 
> I think that's okay.
> 
> > v5: Add Acks, make BUILD_BUG_ON checks look correct. Position the
> >     BUGFRAME_NR properly.
> 
> Almost, that is.
> 
> > --- a/xen/include/asm-x86/bug.h
> > +++ b/xen/include/asm-x86/bug.h
> > @@ -10,6 +10,7 @@
> >  #define BUGFRAME_bug    2
> >  #define BUGFRAME_assert 3
> >  
> > +#define BUGFRAME_NR     4
> >  #ifndef __ASSEMBLY__
> 
> The insertion wants to go _before_ the blank line. (And in the
> ARM case you then may consider removing the preceding blank
> line too; in any event the ARM and x86 ones should look similar
> in the end.)
> 

Here it is. Last call :-)

From f97548200461b9eb4d8187eb9e1f021c74160759 Mon Sep 17 00:00:00 2001
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Date: Thu, 10 Mar 2016 16:45:31 -0500
Subject: [PATCH] x86/arm: Add BUGFRAME_NR define and BUILD checks.

So that we have a nice mechansim to figure out the upper
bounds of bug.frames and also catch compiler errors in case
one tries to use a higher frame number.

Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
Acked-by: Julien Grall <julien.grall@arm.com>

---
Cc: Stefano Stabellini <stefano.stabellini@citrix.com>
Cc: Julien Grall <julien.grall@arm.com>
Cc: Keir Fraser <keir@xen.org>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>

v3: First time included.
v4: Add BUG_FRAME check also in the assembler version of the macro.
v5: Add Acks, make BUILD_BUG_ON checks look correct. Position the
    BUGFRAME_NR properly. Reposition the BUGFRAME_NR again.
---
---
 xen/include/asm-arm/bug.h | 3 +++
 xen/include/asm-x86/bug.h | 8 ++++++++
 2 files changed, 11 insertions(+)

Comments

Jan Beulich March 22, 2016, 3:58 p.m. UTC | #1
>>> On 22.03.16 at 16:39, <konrad.wilk@oracle.com> wrote:
> On Mon, Mar 21, 2016 at 06:49:03AM -0600, Jan Beulich wrote:
>> >>> On 18.03.16 at 20:59, <konrad.wilk@oracle.com> wrote:
>> > I know I copied and pasted it and I must have done something uncanny.
>> > 
>> > Anyhow this is what the change looks like now (I've retained the Reviewed
>> > and Ack as I think this change is mostly cosmetical in nature?)
>> 
>> I think that's okay.
>> 
>> > v5: Add Acks, make BUILD_BUG_ON checks look correct. Position the
>> >     BUGFRAME_NR properly.
>> 
>> Almost, that is.
>> 
>> > --- a/xen/include/asm-x86/bug.h
>> > +++ b/xen/include/asm-x86/bug.h
>> > @@ -10,6 +10,7 @@
>> >  #define BUGFRAME_bug    2
>> >  #define BUGFRAME_assert 3
>> >  
>> > +#define BUGFRAME_NR     4
>> >  #ifndef __ASSEMBLY__
>> 
>> The insertion wants to go _before_ the blank line. (And in the
>> ARM case you then may consider removing the preceding blank
>> line too; in any event the ARM and x86 ones should look similar
>> in the end.)
>> 
> 
> Here it is. Last call :-)

Thanks, looks fine now.

Jan
diff mbox

Patch

diff --git a/xen/include/asm-arm/bug.h b/xen/include/asm-arm/bug.h
index ab9e811..68353e1 100644
--- a/xen/include/asm-arm/bug.h
+++ b/xen/include/asm-arm/bug.h
@@ -32,6 +32,8 @@  struct bug_frame {
 #define BUGFRAME_bug    1
 #define BUGFRAME_assert 2
 
+#define BUGFRAME_NR     3
+
 /* Many versions of GCC doesn't support the asm %c parameter which would
  * be preferable to this unpleasantness. We use mergeable string
  * sections to avoid multiple copies of the string appearing in the
@@ -39,6 +41,7 @@  struct bug_frame {
  */
 #define BUG_FRAME(type, line, file, has_msg, msg) do {                      \
     BUILD_BUG_ON((line) >> 16);                                             \
+    BUILD_BUG_ON((type) >= BUGFRAME_NR);                                    \
     asm ("1:"BUG_INSTR"\n"                                                  \
          ".pushsection .rodata.str, \"aMS\", %progbits, 1\n"                \
          "2:\t.asciz " __stringify(file) "\n"                               \
diff --git a/xen/include/asm-x86/bug.h b/xen/include/asm-x86/bug.h
index e868e85..c5d2d4c 100644
--- a/xen/include/asm-x86/bug.h
+++ b/xen/include/asm-x86/bug.h
@@ -10,6 +10,8 @@ 
 #define BUGFRAME_bug    2
 #define BUGFRAME_assert 3
 
+#define BUGFRAME_NR     4
+
 #ifndef __ASSEMBLY__
 
 struct bug_frame {
@@ -51,6 +53,7 @@  struct bug_frame {
 
 #define BUG_FRAME(type, line, ptr, second_frame, msg) do {                   \
     BUILD_BUG_ON((line) >> (BUG_LINE_LO_WIDTH + BUG_LINE_HI_WIDTH));         \
+    BUILD_BUG_ON((type) >= BUGFRAME_NR);                                     \
     asm volatile ( _ASM_BUGFRAME_TEXT(second_frame)                          \
                    :: _ASM_BUGFRAME_INFO(type, line, ptr, msg) );            \
 } while (0)
@@ -83,6 +86,11 @@  extern const struct bug_frame __start_bug_frames[],
  * in .rodata
  */
     .macro BUG_FRAME type, line, file_str, second_frame, msg
+
+    .if \type >= BUGFRAME_NR
+        .error "Invalid BUGFRAME index"
+    .endif
+
     .L\@ud: ud2a
 
     .pushsection .rodata.str1, "aMS", @progbits, 1