diff mbox series

[v1,1/2] xen: introduce common macros for per-CPU sections defintion

Message ID ed94ad588dd91733178cf505a49b82f4cf031268.1726746877.git.oleksii.kurochko@gmail.com (mailing list archive)
State Superseded
Headers show
Series Move percpu code to common | expand

Commit Message

Oleksii Kurochko Sept. 19, 2024, 3:59 p.m. UTC
Introduce PERCPU_SECTION macro which manages:
 * Alignment of the section start
 * Insertion of per-CPU data sections
 * Alignment and start/end markers for per-CPU data
This change simplifies the linker script maintenance and ensures a unified
approach for per-CPU sections across different architectures.

Refactor the linker scripts for Arm, PPC, and x86 architectures by using
the common macro PERCPU_SECTION defined in xen/xen.lds.h to handle
per-CPU data sections.

No functional changes.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
 xen/arch/arm/xen.lds.S    |  9 +--------
 xen/arch/ppc/xen.lds.S    |  9 +--------
 xen/arch/x86/xen.lds.S    |  9 +--------
 xen/include/xen/xen.lds.h | 10 ++++++++++
 4 files changed, 13 insertions(+), 24 deletions(-)

Comments

Julien Grall Sept. 22, 2024, 7:58 a.m. UTC | #1
Hi,

On 19/09/2024 17:59, Oleksii Kurochko wrote:
> Introduce PERCPU_SECTION macro which manages:
>   * Alignment of the section start
>   * Insertion of per-CPU data sections
>   * Alignment and start/end markers for per-CPU data
> This change simplifies the linker script maintenance and ensures a unified
> approach for per-CPU sections across different architectures.
> 
> Refactor the linker scripts for Arm, PPC, and x86 architectures by using
> the common macro PERCPU_SECTION defined in xen/xen.lds.h to handle
> per-CPU data sections.
> 
> No functional changes.
> 
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

Acked-by: Julien Grall <jgrall@amazon.com>

Cheers,

> ---
>   xen/arch/arm/xen.lds.S    |  9 +--------
>   xen/arch/ppc/xen.lds.S    |  9 +--------
>   xen/arch/x86/xen.lds.S    |  9 +--------
>   xen/include/xen/xen.lds.h | 10 ++++++++++
>   4 files changed, 13 insertions(+), 24 deletions(-)
> 
> diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S
> index bd884664ad..669a882455 100644
> --- a/xen/arch/arm/xen.lds.S
> +++ b/xen/arch/arm/xen.lds.S
> @@ -198,14 +198,7 @@ SECTIONS
>          __bss_start = .;
>          *(.bss.stack_aligned)
>          *(.bss.page_aligned)
> -       . = ALIGN(PAGE_SIZE);
> -       __per_cpu_start = .;
> -       *(.bss.percpu.page_aligned)
> -       *(.bss.percpu)
> -       . = ALIGN(SMP_CACHE_BYTES);
> -       *(.bss.percpu.read_mostly)
> -       . = ALIGN(SMP_CACHE_BYTES);
> -       __per_cpu_data_end = .;
> +       PERCPU_SECTION
>          *(.bss .bss.*)
>          . = ALIGN(POINTER_ALIGN);
>          __bss_end = .;
> diff --git a/xen/arch/ppc/xen.lds.S b/xen/arch/ppc/xen.lds.S
> index 38cd857187..0833d80479 100644
> --- a/xen/arch/ppc/xen.lds.S
> +++ b/xen/arch/ppc/xen.lds.S
> @@ -148,14 +148,7 @@ SECTIONS
>           __bss_start = .;
>           *(.bss.stack_aligned)
>           *(.bss.page_aligned)
> -        . = ALIGN(PAGE_SIZE);
> -        __per_cpu_start = .;
> -        *(.bss.percpu.page_aligned)
> -        *(.bss.percpu)
> -        . = ALIGN(SMP_CACHE_BYTES);
> -        *(.bss.percpu.read_mostly)
> -        . = ALIGN(SMP_CACHE_BYTES);
> -        __per_cpu_data_end = .;
> +        PERCPU_SECTION
>           *(.bss .bss.*)
>           . = ALIGN(POINTER_ALIGN);
>           __bss_end = .;
> diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
> index d48de67cfd..eea8edc02b 100644
> --- a/xen/arch/x86/xen.lds.S
> +++ b/xen/arch/x86/xen.lds.S
> @@ -321,14 +321,7 @@ SECTIONS
>     DECL_SECTION(.bss) {
>          __bss_start = .;
>          *(.bss.page_aligned*)
> -       . = ALIGN(PAGE_SIZE);
> -       __per_cpu_start = .;
> -       *(.bss.percpu.page_aligned)
> -       *(.bss.percpu)
> -       . = ALIGN(SMP_CACHE_BYTES);
> -       *(.bss.percpu.read_mostly)
> -       . = ALIGN(SMP_CACHE_BYTES);
> -       __per_cpu_data_end = .;
> +       PERCPU_SECTION
>          *(.bss .bss.*)
>          . = ALIGN(POINTER_ALIGN);
>          __bss_end = .;
> diff --git a/xen/include/xen/xen.lds.h b/xen/include/xen/xen.lds.h
> index a17810bb28..f043c7b6c0 100644
> --- a/xen/include/xen/xen.lds.h
> +++ b/xen/include/xen/xen.lds.h
> @@ -151,6 +151,16 @@
>   #define LOCK_PROFILE_DATA
>   #endif
>   
> +#define PERCPU_SECTION              \
> +       . = ALIGN(PAGE_SIZE);        \
> +       __per_cpu_start = .;         \
> +       *(.bss.percpu.page_aligned)  \
> +       *(.bss.percpu)               \
> +       . = ALIGN(SMP_CACHE_BYTES);  \
> +       *(.bss.percpu.read_mostly)   \
> +       . = ALIGN(SMP_CACHE_BYTES);  \
> +       __per_cpu_data_end = .;      \
> +
>   #ifdef CONFIG_HAS_VPCI
>   #define VPCI_ARRAY               \
>          . = ALIGN(POINTER_ALIGN); \
Jan Beulich Sept. 23, 2024, 10:56 a.m. UTC | #2
On 19.09.2024 17:59, Oleksii Kurochko wrote:
> --- a/xen/arch/x86/xen.lds.S
> +++ b/xen/arch/x86/xen.lds.S
> @@ -321,14 +321,7 @@ SECTIONS
>    DECL_SECTION(.bss) {
>         __bss_start = .;
>         *(.bss.page_aligned*)
> -       . = ALIGN(PAGE_SIZE);
> -       __per_cpu_start = .;
> -       *(.bss.percpu.page_aligned)
> -       *(.bss.percpu)
> -       . = ALIGN(SMP_CACHE_BYTES);
> -       *(.bss.percpu.read_mostly)
> -       . = ALIGN(SMP_CACHE_BYTES);
> -       __per_cpu_data_end = .;
> +       PERCPU_SECTION
>         *(.bss .bss.*)
>         . = ALIGN(POINTER_ALIGN);
>         __bss_end = .;

Like the _SEC in the other patch I question _SECTION here, albeit for a different
reason: This is no separate output section, and it's more than one kind of input
ones. Perhaps PERCPU_DATA? With that
Acked-by: Jan Beulich <jbeulich@suse.com>

Jan
Oleksii Kurochko Sept. 23, 2024, 11:48 a.m. UTC | #3
On Mon, 2024-09-23 at 12:56 +0200, Jan Beulich wrote:
> On 19.09.2024 17:59, Oleksii Kurochko wrote:
> > --- a/xen/arch/x86/xen.lds.S
> > +++ b/xen/arch/x86/xen.lds.S
> > @@ -321,14 +321,7 @@ SECTIONS
> >    DECL_SECTION(.bss) {
> >         __bss_start = .;
> >         *(.bss.page_aligned*)
> > -       . = ALIGN(PAGE_SIZE);
> > -       __per_cpu_start = .;
> > -       *(.bss.percpu.page_aligned)
> > -       *(.bss.percpu)
> > -       . = ALIGN(SMP_CACHE_BYTES);
> > -       *(.bss.percpu.read_mostly)
> > -       . = ALIGN(SMP_CACHE_BYTES);
> > -       __per_cpu_data_end = .;
> > +       PERCPU_SECTION
> >         *(.bss .bss.*)
> >         . = ALIGN(POINTER_ALIGN);
> >         __bss_end = .;
> 
> Like the _SEC in the other patch I question _SECTION here, albeit for
> a different
> reason: This is no separate output section, and it's more than one
> kind of input
> ones. Perhaps PERCPU_DATA? With that
> Acked-by: Jan Beulich <jbeulich@suse.com>
Sure, I will drop _SECTION here too. Thanks.

~ Oleksii
Andrew Cooper Sept. 23, 2024, 11:53 a.m. UTC | #4
On 23/09/2024 12:48 pm, oleksii.kurochko@gmail.com wrote:
> On Mon, 2024-09-23 at 12:56 +0200, Jan Beulich wrote:
>> On 19.09.2024 17:59, Oleksii Kurochko wrote:
>>> --- a/xen/arch/x86/xen.lds.S
>>> +++ b/xen/arch/x86/xen.lds.S
>>> @@ -321,14 +321,7 @@ SECTIONS
>>>    DECL_SECTION(.bss) {
>>>         __bss_start = .;
>>>         *(.bss.page_aligned*)
>>> -       . = ALIGN(PAGE_SIZE);
>>> -       __per_cpu_start = .;
>>> -       *(.bss.percpu.page_aligned)
>>> -       *(.bss.percpu)
>>> -       . = ALIGN(SMP_CACHE_BYTES);
>>> -       *(.bss.percpu.read_mostly)
>>> -       . = ALIGN(SMP_CACHE_BYTES);
>>> -       __per_cpu_data_end = .;
>>> +       PERCPU_SECTION
>>>         *(.bss .bss.*)
>>>         . = ALIGN(POINTER_ALIGN);
>>>         __bss_end = .;
>> Like the _SEC in the other patch I question _SECTION here, albeit for
>> a different
>> reason: This is no separate output section, and it's more than one
>> kind of input
>> ones. Perhaps PERCPU_DATA? With that
>> Acked-by: Jan Beulich <jbeulich@suse.com>
> Sure, I will drop _SECTION here too. Thanks.

Can we call it PERCPU_BSS?  Just to highlight the fact that it really is
BSS, and not initialised DATA.

~Andrew
Jan Beulich Sept. 23, 2024, 11:55 a.m. UTC | #5
On 23.09.2024 13:53, Andrew Cooper wrote:
> On 23/09/2024 12:48 pm, oleksii.kurochko@gmail.com wrote:
>> On Mon, 2024-09-23 at 12:56 +0200, Jan Beulich wrote:
>>> On 19.09.2024 17:59, Oleksii Kurochko wrote:
>>>> --- a/xen/arch/x86/xen.lds.S
>>>> +++ b/xen/arch/x86/xen.lds.S
>>>> @@ -321,14 +321,7 @@ SECTIONS
>>>>    DECL_SECTION(.bss) {
>>>>         __bss_start = .;
>>>>         *(.bss.page_aligned*)
>>>> -       . = ALIGN(PAGE_SIZE);
>>>> -       __per_cpu_start = .;
>>>> -       *(.bss.percpu.page_aligned)
>>>> -       *(.bss.percpu)
>>>> -       . = ALIGN(SMP_CACHE_BYTES);
>>>> -       *(.bss.percpu.read_mostly)
>>>> -       . = ALIGN(SMP_CACHE_BYTES);
>>>> -       __per_cpu_data_end = .;
>>>> +       PERCPU_SECTION
>>>>         *(.bss .bss.*)
>>>>         . = ALIGN(POINTER_ALIGN);
>>>>         __bss_end = .;
>>> Like the _SEC in the other patch I question _SECTION here, albeit for
>>> a different
>>> reason: This is no separate output section, and it's more than one
>>> kind of input
>>> ones. Perhaps PERCPU_DATA? With that
>>> Acked-by: Jan Beulich <jbeulich@suse.com>
>> Sure, I will drop _SECTION here too. Thanks.
> 
> Can we call it PERCPU_BSS?  Just to highlight the fact that it really is
> BSS, and not initialised DATA.

Fine with me.

Jan
diff mbox series

Patch

diff --git a/xen/arch/arm/xen.lds.S b/xen/arch/arm/xen.lds.S
index bd884664ad..669a882455 100644
--- a/xen/arch/arm/xen.lds.S
+++ b/xen/arch/arm/xen.lds.S
@@ -198,14 +198,7 @@  SECTIONS
        __bss_start = .;
        *(.bss.stack_aligned)
        *(.bss.page_aligned)
-       . = ALIGN(PAGE_SIZE);
-       __per_cpu_start = .;
-       *(.bss.percpu.page_aligned)
-       *(.bss.percpu)
-       . = ALIGN(SMP_CACHE_BYTES);
-       *(.bss.percpu.read_mostly)
-       . = ALIGN(SMP_CACHE_BYTES);
-       __per_cpu_data_end = .;
+       PERCPU_SECTION
        *(.bss .bss.*)
        . = ALIGN(POINTER_ALIGN);
        __bss_end = .;
diff --git a/xen/arch/ppc/xen.lds.S b/xen/arch/ppc/xen.lds.S
index 38cd857187..0833d80479 100644
--- a/xen/arch/ppc/xen.lds.S
+++ b/xen/arch/ppc/xen.lds.S
@@ -148,14 +148,7 @@  SECTIONS
         __bss_start = .;
         *(.bss.stack_aligned)
         *(.bss.page_aligned)
-        . = ALIGN(PAGE_SIZE);
-        __per_cpu_start = .;
-        *(.bss.percpu.page_aligned)
-        *(.bss.percpu)
-        . = ALIGN(SMP_CACHE_BYTES);
-        *(.bss.percpu.read_mostly)
-        . = ALIGN(SMP_CACHE_BYTES);
-        __per_cpu_data_end = .;
+        PERCPU_SECTION
         *(.bss .bss.*)
         . = ALIGN(POINTER_ALIGN);
         __bss_end = .;
diff --git a/xen/arch/x86/xen.lds.S b/xen/arch/x86/xen.lds.S
index d48de67cfd..eea8edc02b 100644
--- a/xen/arch/x86/xen.lds.S
+++ b/xen/arch/x86/xen.lds.S
@@ -321,14 +321,7 @@  SECTIONS
   DECL_SECTION(.bss) {
        __bss_start = .;
        *(.bss.page_aligned*)
-       . = ALIGN(PAGE_SIZE);
-       __per_cpu_start = .;
-       *(.bss.percpu.page_aligned)
-       *(.bss.percpu)
-       . = ALIGN(SMP_CACHE_BYTES);
-       *(.bss.percpu.read_mostly)
-       . = ALIGN(SMP_CACHE_BYTES);
-       __per_cpu_data_end = .;
+       PERCPU_SECTION
        *(.bss .bss.*)
        . = ALIGN(POINTER_ALIGN);
        __bss_end = .;
diff --git a/xen/include/xen/xen.lds.h b/xen/include/xen/xen.lds.h
index a17810bb28..f043c7b6c0 100644
--- a/xen/include/xen/xen.lds.h
+++ b/xen/include/xen/xen.lds.h
@@ -151,6 +151,16 @@ 
 #define LOCK_PROFILE_DATA
 #endif
 
+#define PERCPU_SECTION              \
+       . = ALIGN(PAGE_SIZE);        \
+       __per_cpu_start = .;         \
+       *(.bss.percpu.page_aligned)  \
+       *(.bss.percpu)               \
+       . = ALIGN(SMP_CACHE_BYTES);  \
+       *(.bss.percpu.read_mostly)   \
+       . = ALIGN(SMP_CACHE_BYTES);  \
+       __per_cpu_data_end = .;      \
+
 #ifdef CONFIG_HAS_VPCI
 #define VPCI_ARRAY               \
        . = ALIGN(POINTER_ALIGN); \