Skip to contentSkip to conversation

xen/include: move definition of ASM_INT() to xen/linkage.h

PATCH In review Juergen Gross 4 participants 7 messages Apr 3, 2024 – Apr 11, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/include: move definition of ASM_INT() to xen/linkage.h

ASM_INT() is defined in arch/[arm|x86]/include/asm/asm_defns.h in exactly the same way. Instead of replicating this definition for riscv and ppc, move it to include/xen/linkage.h, where other arch agnostic definitions for assembler code are living already.

Adapt the generation of assembler sources via tools/binfile to include the new home of ASM_INT().

---
 xen/arch/arm/include/asm/asm_defns.h | 3 ---
 xen/arch/x86/include/asm/asm_defns.h | 3 ---
 xen/include/xen/linkage.h            | 2 ++
 xen/tools/binfile                    | 2 +-
 4 files changed, 3 insertions(+), 7 deletions(-)
xen/arch/arm/include/asm/asm_defns.h +0 -3
index c489547d29..47efdf5234 100644
@@ -28,9 +28,6 @@
 label:  .asciz msg;                             \
 .popsection
 
-#define ASM_INT(label, val)                 \
-    DATA(label, 4) .long (val); END(label)
-
 #endif /* __ARM_ASM_DEFNS_H__ */
 /*
  * Local variables:
xen/arch/x86/include/asm/asm_defns.h +0 -3
index a69fae78b1..0a3ff70566 100644
@@ -351,9 +351,6 @@ static always_inline void stac(void)
 4:  .p2align 2                            ; \
     .popsection
 
-#define ASM_INT(label, val)                 \
-    DATA(label, 4) .long (val); END(label)
-
 #define ASM_CONSTANT(name, value)                \
     asm ( ".equ " #name ", %P0; .global " #name  \
           :: "i" ((value)) );
xen/include/xen/linkage.h +2 -0
index 478b1d7287..3d401b88c1 100644
@@ -60,6 +60,8 @@
 #define DATA_LOCAL(name, align...) \
         SYM(name, DATA, LOCAL, LASTARG(DATA_ALIGN, ## align), DATA_FILL)
 
+#define ASM_INT(label, val)    DATA(label, 4) .long (val); END(label)
+
 #endif /*  __ASSEMBLY__ */
 
 #endif /* __LINKAGE_H__ */
xen/tools/binfile +1 -1
index 099d7eda9a..0299326ccc 100755
@@ -25,7 +25,7 @@ binsource=$2
 varname=$3
 
 cat <<EOF >$target
-#include <asm/asm_defns.h>
+#include <xen/linkage.h>
 
         .section $section.rodata, "a", %progbits
 
Signature · 1 line
2.35.3
Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Juergen Gross

ASM_INT() is defined in arch/[arm|x86]/include/asm/asm_defns.h in exactly the same way. Instead of replicating this definition for riscv and ppc, move it to include/xen/linkage.h, where other arch agnostic definitions for assembler code are living already.

Adapt the generation of assembler sources via tools/binfile to include the new home of ASM_INT().

#2 lore raw
In reply to Juergen Gross
Quoted 4 lines · Juergen Gross

ASM_INT() is defined in arch/[arm|x86]/include/asm/asm_defns.h in exactly the same way. Instead of replicating this definition for riscv and ppc, move it to include/xen/linkage.h, where other arch agnostic definitions for assembler code are living already.

And this is why I didn't make a change right away, back when noticing the
duplication: Arch-agnostic really means ...

xen/include/xen/linkage.h line 63

Quoted 7 lines
xen/include/xen/linkage.h +1 -0
@@ -60,6 +60,8 @@
 #define DATA_LOCAL(name, align...) \
         SYM(name, DATA, LOCAL, LASTARG(DATA_ALIGN, ## align), DATA_FILL)
 
+#define ASM_INT(label, val)    DATA(label, 4) .long (val); END(label)

... to avoid .long [1]. There's no arch-independent aspect guaranteeing that what .long emits matches "unsigned int" as used e.g. in the declaration of xen_config_data_size. The arch-agnostic directives are .dc.l and friends. Sadly Clang looks to support this only starting with version 4.

Nevertheless, seeing that Andrew ack-ed the change already, it's perhaps good enough for the moment. If an obscure port appeared, the further abstraction could be taken care of by them.

Jan

[1] Note how in gas doc .long refers to .int, .int says "32-bit", just to then have a special case of H8/300 emitting 16-bit values. Things must have been confusing enough for someone to come and add .dc.?.

#3 lore raw
Quoted 14 lines · Jan Beulich
Quoted 4 lines · Juergen Gross

ASM_INT() is defined in arch/[arm|x86]/include/asm/asm_defns.h in exactly the same way. Instead of replicating this definition for riscv and ppc, move it to include/xen/linkage.h, where other arch agnostic definitions for assembler code are living already.

And this is why I didn't make a change right away, back when noticing the
duplication: Arch-agnostic really means ...

Quoted 6 lines
xen/include/xen/linkage.h +0 -0
@@ -60,6 +60,8 @@
 #define DATA_LOCAL(name, align...) \
         SYM(name, DATA, LOCAL, LASTARG(DATA_ALIGN, ## align), DATA_FILL)
 
Quoted 4 lines

xen/include/xen/linkage.h line 63

Quoted 1 line
xen/include/xen/linkage.h +1 -0
+#define ASM_INT(label, val)    DATA(label, 4) .long (val); END(label)

... to avoid .long [1]. There's no arch-independent aspect guaranteeing that what .long emits matches "unsigned int" as used e.g. in the declaration of xen_config_data_size.

I'd forgotten that point, but I don't think it's a good reason force every architecture to implement the same thing.

Borrowing a trick from the alternatives, what about this as a sanity check?

xen/tools/binfile +0 -0
index 0299326ccc3f..21593debc872 100755
@@ -35,4 +35,10 @@ DATA($varname, 1 << $align)

 END($varname)

         ASM_INT(${varname}_size, .Lend - $varname) +.Lsize_end:
+
+        .section .discard
+        # Build assert sizeof(ASM_INT) == 4
+        .byte 0xff - ((.Lsize_end - ${varname}_size) == 4) +
 EOF

Ideally we'd want BYTES_PER_INT here but it turns out that doesn't exist in Xen.  If we find an architecture where .long isn't the right thing, we can make ASM_INT optionally arch-specific.

~Andrew

#4 lore raw
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 4 lines · Juergen Gross

ASM_INT() is defined in arch/[arm|x86]/include/asm/asm_defns.h in exactly the same way. Instead of replicating this definition for riscv and ppc, move it to include/xen/linkage.h, where other arch agnostic definitions for assembler code are living already.

And this is why I didn't make a change right away, back when noticing the
duplication: Arch-agnostic really means ...

Quoted 6 lines
xen/include/xen/linkage.h +0 -0
@@ -60,6 +60,8 @@
 #define DATA_LOCAL(name, align...) \
         SYM(name, DATA, LOCAL, LASTARG(DATA_ALIGN, ## align), DATA_FILL)
 
Quoted 7 lines
Quoted 4 lines

xen/include/xen/linkage.h line 63

Quoted 1 line
xen/include/xen/linkage.h +1 -0
+#define ASM_INT(label, val)    DATA(label, 4) .long (val); END(label)

... to avoid .long [1]. There's no arch-independent aspect guaranteeing that what .long emits matches "unsigned int" as used e.g. in the declaration of xen_config_data_size.

I'd forgotten that point, but I don't think it's a good reason force every architecture to implement the same thing.

Of course.

Quoted 16 lines

Borrowing a trick from the alternatives, what about this as a sanity check?

xen/tools/binfile +0 -0
index 0299326ccc3f..21593debc872 100755
@@ -35,4 +35,10 @@ DATA($varname, 1 << $align)
  END($varname)


         ASM_INT(${varname}_size, .Lend - $varname) +.Lsize_end:

xen/tools/binfile +5 -0
+
+        .section .discard
+        # Build assert sizeof(ASM_INT) == 4
+        .byte 0xff - ((.Lsize_end - ${varname}_size) == 4)
+
Quoted 1 line

 EOF

Hmm, tools/binfile may not be involved in a build, yet ASM_INT() may still be used. Since there may not be any good place, I think we're okay-ish for now without such a check.

Quoted 3 lines

Ideally we'd want BYTES_PER_INT here but it turns out that doesn't exist in Xen.  If we find an architecture where .long isn't the right thing, we can make ASM_INT optionally arch-specific.

We don't even need to go this far - merely introducing an abstraction for .long would suffice, and then also allow using that in bug.h.

Jan

#5 lore raw
Quoted 45 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
Quoted 14 lines · Jan Beulich
Quoted 4 lines · Juergen Gross

ASM_INT() is defined in arch/[arm|x86]/include/asm/asm_defns.h in exactly the same way. Instead of replicating this definition for riscv and ppc, move it to include/xen/linkage.h, where other arch agnostic definitions for assembler code are living already.

And this is why I didn't make a change right away, back when noticing the
duplication: Arch-agnostic really means ...

Quoted 6 lines
xen/include/xen/linkage.h +0 -0
@@ -60,6 +60,8 @@
 #define DATA_LOCAL(name, align...) \
         SYM(name, DATA, LOCAL, LASTARG(DATA_ALIGN, ## align), DATA_FILL)
 
Quoted 6 lines
Quoted 4 lines

xen/include/xen/linkage.h line 63

Quoted 1 line
xen/include/xen/linkage.h +1 -0
+#define ASM_INT(label, val)    DATA(label, 4) .long (val); END(label)

... to avoid .long [1]. There's no arch-independent aspect guaranteeing that what .long emits matches "unsigned int" as used e.g. in the declaration of xen_config_data_size.

I'd forgotten that point, but I don't think it's a good reason force every architecture to implement the same thing.

Of course.

Quoted 16 lines

Borrowing a trick from the alternatives, what about this as a sanity check?

xen/tools/binfile +0 -0
index 0299326ccc3f..21593debc872 100755
@@ -35,4 +35,10 @@ DATA($varname, 1 << $align)
  END($varname)


         ASM_INT(${varname}_size, .Lend - $varname) +.Lsize_end:

xen/tools/binfile +5 -0
+
+        .section .discard
+        # Build assert sizeof(ASM_INT) == 4
+        .byte 0xff - ((.Lsize_end - ${varname}_size) == 4)
+
Quoted 1 line

 EOF

Hmm, tools/binfile may not be involved in a build, yet ASM_INT() may still be used. Since there may not be any good place, I think we're okay-ish for now without such a check.

Quoted 5 lines
Quoted 3 lines

Ideally we'd want BYTES_PER_INT here but it turns out that doesn't exist in Xen.  If we find an architecture where .long isn't the right thing, we can make ASM_INT optionally arch-specific.

We don't even need to go this far - merely introducing an abstraction for .long would suffice, and then also allow using that in bug.h.

Ok.  I'll take this patch as-is for now.  We can abstract away .long later.

~Andrew

Acked-by on v1 1/1
#6 lore raw
In reply to Juergen Gross
Quoted 11 lines · Juergen Gross

ASM_INT() is defined in arch/[arm|x86]/include/asm/asm_defns.h in exactly the same way. Instead of replicating this definition for riscv and ppc, move it to include/xen/linkage.h, where other arch agnostic definitions for assembler code are living already.

Adapt the generation of assembler sources via tools/binfile to include the new home of ASM_INT().

~Michal