Skip to contentSkip to conversation

xen/init: Annotate all command line parameter infrastructure as const

PATCH In review Andrew Cooper 4 participants 17 messages Jun 21, 2016 – Jun 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/4 xen/init: Annotate all command line parameter infrastructure as const

There is no reason for any of it to be modified. Additionally, link .init.setup beside the other constant .init data.

While editing this area, correct the types used in the extern declarations for __setup_start and __setup_end to match the types the linker actually produces.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

v2:
* Extra const

---
 xen/arch/arm/xen.lds.S | 11 ++++++-----
 xen/arch/x86/xen.lds.S | 11 ++++++-----
 xen/common/kernel.c    |  6 +++---
 xen/include/xen/init.h |  7 ++++---
 4 files changed, 19 insertions(+), 16 deletions(-)
xen/arch/arm/xen.lds.S +6 -5
index 8320381..2ed7dee 100644
@@ -135,6 +135,12 @@ SECTIONS
        *(.init.rodata)
        *(.init.rodata.rel)
        *(.init.rodata.str*)
+
+       . = ALIGN(POINTER_ALIGN);
+       __setup_start = .;
+       *(.init.setup)
+       __setup_end = .;
+
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
@@ -145,11 +151,6 @@ SECTIONS
        __ctors_end = .;
   } :text
   . = ALIGN(32);
-  .init.setup : {
-       __setup_start = .;
-       *(.init.setup)
-       __setup_end = .;
-  } :text
   .init.proc.info : {
        __proc_info_start = .;
        *(.init.proc.info)
xen/arch/x86/xen.lds.S +6 -5
index dcbb8fe..2443b93 100644
@@ -152,6 +152,12 @@ SECTIONS
        *(.init.rodata)
        *(.init.rodata.rel)
        *(.init.rodata.str*)
+
+       . = ALIGN(POINTER_ALIGN);
+       __setup_start = .;
+       *(.init.setup)
+       __setup_end = .;
+
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
@@ -178,11 +184,6 @@ SECTIONS
        __ctors_end = .;
   } :text
   . = ALIGN(32);
-  .init.setup : {
-       __setup_start = .;
-       *(.init.setup)
-       __setup_end = .;
-  } :text
   .initcall.init : {
        __initcall_start = .;
        *(.initcallpresmp.init)
xen/common/kernel.c +3 -3
index dae7e35..942b042 100644
@@ -27,7 +27,7 @@ int tainted;
 xen_commandline_t saved_cmdline;
 
 static void __init assign_integer_param(
-    struct kernel_param *param, uint64_t val)
+    const struct kernel_param *param, uint64_t val)
 {
     switch ( param->len )
     {
@@ -52,7 +52,7 @@ void __init cmdline_parse(const char *cmdline)
 {
     char opt[100], *optval, *optkey, *q;
     const char *p = cmdline;
-    struct kernel_param *param;
+    const struct kernel_param *param;
     int bool_assert;
 
     if ( cmdline == NULL )
@@ -96,7 +96,7 @@ void __init cmdline_parse(const char *cmdline)
         if ( !bool_assert )
             optkey += 3;
 
-        for ( param = &__setup_start; param < &__setup_end; param++ )
+        for ( param = __setup_start; param < __setup_end; param++ )
         {
             if ( strcmp(param->name, optkey) )
             {
xen/include/xen/init.h +4 -3
index 671ac81..b04bcf9 100644
@@ -86,10 +86,11 @@ struct kernel_param {
     void *var;
 };
 
-extern struct kernel_param __setup_start, __setup_end;
+extern const struct kernel_param __setup_start[], __setup_end[];
 
-#define __setup_str static __initdata __attribute__((__aligned__(1))) char
-#define __kparam static __initsetup \
+#define __setup_str static const  __initconstrel \
+    __attribute__((__aligned__(1))) char
+#define __kparam static const __initsetup \
     __attribute__((__aligned__(sizeof(void *)))) struct kernel_param
 
 #define custom_param(_name, _var) \
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#1 lore raw

PATCH v2 2/4 arm/init: Move .init.proc.info into .init.data

Its contents is constant, and only requires pointer alignment, so move it adacent to .init.setup.

---
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

v2:
* New

---
 xen/arch/arm/xen.lds.S | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
xen/arch/arm/xen.lds.S +4 -5
index 2ed7dee..b00ee81 100644
@@ -141,6 +141,10 @@ SECTIONS
        *(.init.setup)
        __setup_end = .;
 
+       __proc_info_start = .;
+       *(.init.proc.info)
+       __proc_info_end = .;
+
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
@@ -151,11 +155,6 @@ SECTIONS
        __ctors_end = .;
   } :text
   . = ALIGN(32);
-  .init.proc.info : {
-       __proc_info_start = .;
-       *(.init.proc.info)
-       __proc_info_end = .;
-  } :text
   .initcall.init : {
        __initcall_start = .;
        *(.initcallpresmp.init)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v2 2/4
#3 lore raw

Re: [PATCH v2 2/4] arm/init: Move .init.proc.info into .init.data

In reply to Andrew Cooper

Hi Andrew,

Quoted 4 lines · Andrew Cooper

Its contents is constant, and only requires pointer alignment, so move it adacent to .init.setup.

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#4 lore raw

PATCH v2 3/4 xen/init: Move initcall infrastructure into .init.data

In reply to Andrew Cooper

Its contents is constant.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

v2:
* New

---
 xen/arch/arm/xen.lds.S | 14 ++++++--------
 xen/arch/x86/xen.lds.S | 14 ++++++--------
 xen/include/xen/init.h |  4 ++--
 3 files changed, 14 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +6 -8
index b00ee81..b18c9c2 100644
@@ -145,6 +145,12 @@ SECTIONS
        *(.init.proc.info)
        __proc_info_end = .;
 
+       __initcall_start = .;
+       *(.initcallpresmp.init)
+       __presmp_initcall_end = .;
+       *(.initcall1.init)
+       __initcall_end = .;
+
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
@@ -154,14 +160,6 @@ SECTIONS
        *(.init_array)
        __ctors_end = .;
   } :text
-  . = ALIGN(32);
-  .initcall.init : {
-       __initcall_start = .;
-       *(.initcallpresmp.init)
-       __presmp_initcall_end = .;
-       *(.initcall1.init)
-       __initcall_end = .;
-  } :text
   __init_end_efi = .;
   . = ALIGN(STACK_SIZE);
   __init_end = .;
xen/arch/x86/xen.lds.S +6 -8
index 2443b93..a1678d8 100644
@@ -158,6 +158,12 @@ SECTIONS
        *(.init.setup)
        __setup_end = .;
 
+       __initcall_start = .;
+       *(.initcallpresmp.init)
+       __presmp_initcall_end = .;
+       *(.initcall1.init)
+       __initcall_end = .;
+
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
@@ -183,14 +189,6 @@ SECTIONS
        *(.ctors)
        __ctors_end = .;
   } :text
-  . = ALIGN(32);
-  .initcall.init : {
-       __initcall_start = .;
-       *(.initcallpresmp.init)
-       __presmp_initcall_end = .;
-       *(.initcall1.init)
-       __initcall_end = .;
-  } :text
   . = ALIGN(PAGE_SIZE);
   __init_end = .;
 
xen/include/xen/init.h +2 -2
index b04bcf9..0afc430 100644
@@ -61,9 +61,9 @@ typedef int (*initcall_t)(void);
 typedef void (*exitcall_t)(void);
 
 #define presmp_initcall(fn) \
-    static initcall_t __initcall_##fn __init_call("presmp") = fn
+    const static initcall_t __initcall_##fn __init_call("presmp") = fn
 #define __initcall(fn) \
-    static initcall_t __initcall_##fn __init_call("1") = fn
+    const static initcall_t __initcall_##fn __init_call("1") = fn
 #define __exitcall(fn) \
     static exitcall_t __exitcall_##fn __exit_call = fn
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#6 lore raw

Re: [PATCH v2 3/4] xen/init: Move initcall infrastructure into .init.data

Quoted 4 lines · Konrad Rzeszutek Wilk
Quoted 2 lines · Andrew Cooper

Its contents is constant.

Could you mention why you don't need the ALIGN(32).

Because there is no content following it, before a larger alignment.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Reviewed-by on v2 3/4
#7 lore raw

Re: [PATCH v2 3/4] xen/init: Move initcall infrastructure into .init.data

In reply to Andrew Cooper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 21.06.16 at 18:59, <[email protected]> wrote:

Its contents is constant.

Non-ARM part:

Quoted 5 lines
xen/arch/arm/xen.lds.S +0 -1
@@ -154,14 +160,6 @@ SECTIONS
        *(.init_array)
        __ctors_end = .;
   } :text
-  . = ALIGN(32);

xen/arch/arm/xen.lds.S SECTIONS · line 165

Quoted 10 lines
xen/arch/arm/xen.lds.S +0 -7
-  .initcall.init : {
-       __initcall_start = .;
-       *(.initcallpresmp.init)
-       __presmp_initcall_end = .;
-       *(.initcall1.init)
-       __initcall_end = .;
-  } :text
   __init_end_efi = .;
   . = ALIGN(STACK_SIZE);
   __init_end = .;

For this part, other than the x86 side, I think Konrad has a point: You change the alignment guarantees for __init_end_efi. Likely that won't matter, but verifying (and stating so) would still seem necessary / desirable.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#8 lore raw

PATCH v3 3/4 xen/init: Move initcall infrastructure into .init.data

In reply to Andrew Cooper

Its contents is constant.

The ALIGN(32) is also dropped. On x86, there is nothing between it and a larger alignment. On ARM, __init_end_efi is between the two, but its sole use is to fill SizeOfRawData in the PE Section Table, and doesn't require any specific alignment.

---
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>

v3:
* Expand the commit message
v2:
* New

---
 xen/arch/arm/xen.lds.S | 14 ++++++--------
 xen/arch/x86/xen.lds.S | 14 ++++++--------
 xen/include/xen/init.h |  4 ++--
 3 files changed, 14 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +6 -8
index b00ee81..b18c9c2 100644
@@ -145,6 +145,12 @@ SECTIONS
        *(.init.proc.info)
        __proc_info_end = .;
 
+       __initcall_start = .;
+       *(.initcallpresmp.init)
+       __presmp_initcall_end = .;
+       *(.initcall1.init)
+       __initcall_end = .;
+
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
@@ -154,14 +160,6 @@ SECTIONS
        *(.init_array)
        __ctors_end = .;
   } :text
-  . = ALIGN(32);
-  .initcall.init : {
-       __initcall_start = .;
-       *(.initcallpresmp.init)
-       __presmp_initcall_end = .;
-       *(.initcall1.init)
-       __initcall_end = .;
-  } :text
   __init_end_efi = .;
   . = ALIGN(STACK_SIZE);
   __init_end = .;
xen/arch/x86/xen.lds.S +6 -8
index 2443b93..a1678d8 100644
@@ -158,6 +158,12 @@ SECTIONS
        *(.init.setup)
        __setup_end = .;
 
+       __initcall_start = .;
+       *(.initcallpresmp.init)
+       __presmp_initcall_end = .;
+       *(.initcall1.init)
+       __initcall_end = .;
+
        *(.init.data)
        *(.init.data.rel)
        *(.init.data.rel.*)
@@ -183,14 +189,6 @@ SECTIONS
        *(.ctors)
        __ctors_end = .;
   } :text
-  . = ALIGN(32);
-  .initcall.init : {
-       __initcall_start = .;
-       *(.initcallpresmp.init)
-       __presmp_initcall_end = .;
-       *(.initcall1.init)
-       __initcall_end = .;
-  } :text
   . = ALIGN(PAGE_SIZE);
   __init_end = .;
 
xen/include/xen/init.h +2 -2
index b04bcf9..0afc430 100644
@@ -61,9 +61,9 @@ typedef int (*initcall_t)(void);
 typedef void (*exitcall_t)(void);
 
 #define presmp_initcall(fn) \
-    static initcall_t __initcall_##fn __init_call("presmp") = fn
+    const static initcall_t __initcall_##fn __init_call("presmp") = fn
 #define __initcall(fn) \
-    static initcall_t __initcall_##fn __init_call("1") = fn
+    const static initcall_t __initcall_##fn __init_call("1") = fn
 #define __exitcall(fn) \
     static exitcall_t __exitcall_##fn __exit_call = fn
 
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Acked-by on v3 3/4
#9 lore raw

Re: [PATCH v3 3/4] xen/init: Move initcall infrastructure into .init.data

Hi Andrew,

Quoted 9 lines · Andrew Cooper

Its contents is constant.

The ALIGN(32) is also dropped. On x86, there is nothing between it and a larger alignment. On ARM, __init_end_efi is between the two, but its sole use is to fill SizeOfRawData in the PE Section Table, and doesn't require any specific alignment.

For ARM bits:

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#10 lore raw

PATCH v2 4/4 x86/boot: copy/clear sections more efficiently

In reply to Andrew Cooper

Both the trampoline copy and BSS initialise can be performed more efficiently by using 4-byte variants of the string operations.

On Intel systems with ERMSB (efficient rep movsb), this is no practical difference. On all other systems, this is 4 times more efficient.

---
v2:
* Alter spacing after rep prefix

---
 xen/arch/x86/boot/head.S | 9 +++++----
 xen/arch/x86/xen.lds.S   | 5 +++++
 2 files changed, 10 insertions(+), 4 deletions(-)
xen/arch/x86/boot/head.S +5 -4
index 0999997..85770e8 100644
@@ -128,7 +128,8 @@ __start:
         mov     $sym_phys(__bss_end),%ecx
         sub     %edi,%ecx
         xor     %eax,%eax
-        rep     stosb
+        shr     $2,%ecx
+        rep stosl
 
         /* Interrogate CPU extended features via CPUID. */
         mov     $0x80000000,%eax
@@ -192,8 +193,8 @@ __start:
 
         /* Copy bootstrap trampoline to low memory, below 1MB. */
         mov     $sym_phys(trampoline_start),%esi
-        mov     $trampoline_end - trampoline_start,%ecx
-        rep     movsb
+        mov     $((trampoline_end - trampoline_start) / 4),%ecx
+        rep movsl
 
         /* Jump into the relocated trampoline. */
         lret
@@ -205,6 +206,6 @@ reloc:
 
 ENTRY(trampoline_start)
 #include "trampoline.S"
-GLOBAL(trampoline_end)
+ENTRY(trampoline_end)
 
 #include "x86_64.S"
xen/arch/x86/xen.lds.S +5 -0
index a1678d8..d620e7a 100644
@@ -314,3 +314,8 @@ ASSERT(IS_ALIGNED(cpu0_stack, STACK_SIZE), "cpu0_stack misaligned")
 
 ASSERT(IS_ALIGNED(__init_begin, PAGE_SIZE), "__init_begin misaligned")
 ASSERT(IS_ALIGNED(__init_end,   PAGE_SIZE), "__init_end misaligned")
+
+ASSERT(IS_ALIGNED(trampoline_start, 4), "trampoline_start misaligned")
+ASSERT(IS_ALIGNED(trampoline_end,   4), "trampoline_end misaligned")
+ASSERT(IS_ALIGNED(__bss_start,      4), "__bss_start misaligned")
+ASSERT(IS_ALIGNED(__bss_end,        4), "__bss_end misaligned")
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Reviewed-by on v2 1/4
#11 lore raw
In reply to Andrew Cooper
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 21.06.16 at 18:59, <[email protected]> wrote:

There is no reason for any of it to be modified. Additionally, link .init.setup beside the other constant .init data.

While editing this area, correct the types used in the extern declarations for __setup_start and __setup_end to match the types the linker actually produces.

No functional change.

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

Acked-by on v2 1/4
#12 lore raw
In reply to Andrew Cooper

Hi Andrew,

Quoted 10 lines · Andrew Cooper

There is no reason for any of it to be modified. Additionally, link .init.setup beside the other constant .init data.

While editing this area, correct the types used in the extern declarations for __setup_start and __setup_end to match the types the linker actually produces.

No functional change.

For the ARM bits:

Regards,

Signature · 6 lines
Julien Grall

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
#13 lore raw
In reply to Andrew Cooper
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 21.06.16 at 18:59, <[email protected]> wrote:

xen/include/xen/init.h struct kernel_param { · line 92

Quoted 10 lines
xen/include/xen/init.h +3 -3
@@ -86,10 +86,11 @@ struct kernel_param {
     void *var;
 };
 
-extern struct kernel_param __setup_start, __setup_end;
+extern const struct kernel_param __setup_start[], __setup_end[];
 
-#define __setup_str static __initdata __attribute__((__aligned__(1))) char
-#define __kparam static __initsetup \
+#define __setup_str static const  __initconstrel \
+    __attribute__((__aligned__(1))) char

This slipped my attention during review, but causes build failure with some gcc versions now: Why __initconstrel rather than __initconst?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#14 lore raw
Quoted 10 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 21.06.16 at 18:59, <[email protected]> wrote:
xen/include/xen/init.h +1 -1
@@ -86,10 +86,11 @@ struct kernel_param {
     void *var;
 };
 
-extern struct kernel_param __setup_start, __setup_end;
+extern const struct kernel_param __setup_start[], __setup_end[];
 
Quoted 7 lines

xen/include/xen/init.h struct kernel_param { · line 92

Quoted 4 lines
xen/include/xen/init.h +2 -2
-#define __setup_str static __initdata __attribute__((__aligned__(1))) char
-#define __kparam static __initsetup \
+#define __setup_str static const  __initconstrel \
+    __attribute__((__aligned__(1))) char

This slipped my attention during review, but causes build failure with some gcc versions now: Why __initconstrel rather than __initconst?

Because this was previously __initconst and you reverted it for breaking on older GCC. Message ID <[email protected]>

I can't replicate any build failures with any GCC or clang combination to hand. Are you able to find some solution which GCC is happy with?

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#15 lore raw

PATCH 1/1 init: fix build with older gcc

__setup_str is used on arrays of char, so there aren't any relocatable items. Hence __initconst has to be used here, not __initconstrel.

Whatever led to the revert of commit 59b151d2c0 (the original version of a6066af5b1 "xen/init: Annotate all command line parameter infrastructure as const" must have got addressed meanwhile - with the patch here I can't see that old gcc (4.3ish) report a section type conflict anymore.

xen/include/xen/init.h +1 -1
@@ -88,7 +88,7 @@ struct kernel_param {
 
 extern const struct kernel_param __setup_start[], __setup_end[];
 
-#define __setup_str static const  __initconstrel \
+#define __setup_str static const __initconst \
     __attribute__((__aligned__(1))) char
 #define __kparam static const __initsetup \
     __attribute__((__aligned__(sizeof(void *)))) struct kernel_param

init: fix build with older gcc

__setup_str is used on arrays of char, so there aren't any relocatable items. Hence __initconst has to be used here, not __initconstrel.

Whatever led to the revert of commit 59b151d2c0 (the original version of a6066af5b1 "xen/init: Annotate all command line parameter infrastructure as const" must have got addressed meanwhile - with the patch here I can't see that old gcc (4.3ish) report a section type conflict anymore.

xen/include/xen/init.h +1 -1
@@ -88,7 +88,7 @@ struct kernel_param {
 
 extern const struct kernel_param __setup_start[], __setup_end[];
 
-#define __setup_str static const  __initconstrel \
+#define __setup_str static const __initconst \
     __attribute__((__aligned__(1))) char
 #define __kparam static const __initsetup \
     __attribute__((__aligned__(sizeof(void *)))) struct kernel_param

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

author Acked-by on v1 1/1
#16 lore raw

Re: [PATCH] init: fix build with older gcc

Quoted 10 lines · Jan Beulich

__setup_str is used on arrays of char, so there aren't any relocatable items. Hence __initconst has to be used here, not __initconstrel.

Whatever led to the revert of commit 59b151d2c0 (the original version of a6066af5b1 "xen/init: Annotate all command line parameter infrastructure as const" must have got addressed meanwhile - with the patch here I can't see that old gcc (4.3ish) report a section type conflict anymore.

Quoted 7 lines

xen/include/xen/init.h struct kernel_param { · line 94

Quoted 8 lines
xen/include/xen/init.h +1 -1
@@ -88,7 +88,7 @@ struct kernel_param {
 
 extern const struct kernel_param __setup_start[], __setup_end[];
 
-#define __setup_str static const  __initconstrel \
+#define __setup_str static const __initconst \
     __attribute__((__aligned__(1))) char
 #define __kparam static const __initsetup \
     __attribute__((__aligned__(sizeof(void *)))) struct kernel_param

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel