Skip to contentSkip to conversation

xen/link: Don't separate .data.read_mostly from .data

PATCH In review Andrew Cooper 5 participants 8 messages Nov 12 – Nov 13 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen/link: Don't separate .data.read_mostly from .data

This appears to be an error in x86 which got copied into all other architectures. .data.read_mostly is an internal detail, and none of the similar sections get exposed externally.

Simply place .data.read_mostly in .data.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Baptiste Le Duc <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Ross Lagerwall <[email protected]>

This is to simplfy the script checking that xen.efi's section attributes/alignments are correct for UEFI SecureBoot.

---
 xen/arch/arm/xen.lds.S   | 8 +++-----
 xen/arch/ppc/xen.lds.S   | 8 +++-----
 xen/arch/riscv/xen.lds.S | 7 ++-----
 xen/arch/x86/xen.lds.S   | 4 +---
 4 files changed, 9 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +3 -5
index d1bb6c62d208..8d0954c90afd 100644
@@ -86,16 +86,14 @@ SECTIONS
       __ro_after_init_end = .;
   } : text
 
-  .data.read_mostly : {
-       *(.data.read_mostly)
-  } :text
-
   . = ALIGN(SMP_CACHE_BYTES);
   .data : {                    /* Data */
-       *(.data.page_aligned)
+       *(.data.read_mostly)
 
        HYPFS_PARAM
 
+       *(.data.page_aligned)
+
        *(.data .data.*)
        CONSTRUCTORS
   } :text
xen/arch/ppc/xen.lds.S +3 -5
index cddb70855307..b2159279169c 100644
@@ -77,16 +77,14 @@ SECTIONS
         __ro_after_init_end = .;
     } :text
 
-    DECL_SECTION(.data.read_mostly) {
-        *(.data.read_mostly)
-    } :text
-
     . = ALIGN(PAGE_SIZE);
     DECL_SECTION(.data) {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
 
         HYPFS_PARAM
 
+        *(.data.page_aligned)
+
         *(.data .data.*)
         CONSTRUCTORS
     } :text
xen/arch/riscv/xen.lds.S +2 -5
index 250ee3f36f4f..d1c5ce59c90d 100644
@@ -84,16 +84,13 @@ SECTIONS
         __ro_after_init_end = .;
     } : text
 
-    .data.read_mostly : {
-        *(.data.read_mostly)
-    } :text
-
     . = ALIGN(PAGE_SIZE);
     .data : {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
 
         HYPFS_PARAM
 
+        *(.data.page_aligned)
         *(.sdata .sdata.*)
         *(.data .data.*)
         CONSTRUCTORS
xen/arch/x86/xen.lds.S +1 -3
index 925848980219..99802aed4e13 100644
@@ -295,13 +295,11 @@ SECTIONS
 
   __2M_rwdata_start = .;       /* Start of 2M superpages, mapped RW. */
   . = ALIGN(SMP_CACHE_BYTES);
-  DECL_SECTION(.data.read_mostly) {
+  DECL_SECTION(.data) {
        *(.data.read_mostly)
 
        HYPFS_PARAM
-  } PHDR(text)
 
-  DECL_SECTION(.data) {
        *(.data.page_aligned)
        *(.data .data.*)
   } PHDR(text)

base-commit: 4263fe42b736596cfa5bfec661f2f55f02759aa7
prerequisite-patch-id: 680071148129321ffaf7bd7435d031904014f556

Signature · 1 line
2.39.5
#1 lore raw

Hi Andrew,

Quoted 42 lines · Andrew Cooper

This appears to be an error in x86 which got copied into all other architectures. .data.read_mostly is an internal detail, and none of the similar sections get exposed externally.

Simply place .data.read_mostly in .data.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Baptiste Le Duc <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Ross Lagerwall <[email protected]>

This is to simplfy the script checking that xen.efi's section attributes/alignments are correct for UEFI SecureBoot.

---
 xen/arch/arm/xen.lds.S   | 8 +++-----
 xen/arch/ppc/xen.lds.S   | 8 +++-----
 xen/arch/riscv/xen.lds.S | 7 ++-----
 xen/arch/x86/xen.lds.S   | 4 +---
 4 files changed, 9 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +0 -2
index d1bb6c62d208..8d0954c90afd 100644
@@ -86,16 +86,14 @@ SECTIONS
       __ro_after_init_end = .;
   } : text
 
-  .data.read_mostly : {
-       *(.data.read_mostly)

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

Quoted 10 lines
xen/arch/arm/xen.lds.S +2 -3
-  } :text
-
   . = ALIGN(SMP_CACHE_BYTES);
   .data : {                    /* Data */
-       *(.data.page_aligned)
+       *(.data.read_mostly)
 
        HYPFS_PARAM
 
+       *(.data.page_aligned)

A small question: why are you moving data.page_aligned? I don't think that this can cause issues, but I want to understand the reason.

Quoted 73 lines
xen/arch/arm/xen.lds.S +1 -0
+
        *(.data .data.*)
        CONSTRUCTORS
   } :text
xen/arch/ppc/xen.lds.S +3 -5
index cddb70855307..b2159279169c 100644
@@ -77,16 +77,14 @@ SECTIONS
         __ro_after_init_end = .;
     } :text
 
-    DECL_SECTION(.data.read_mostly) {
-        *(.data.read_mostly)
-    } :text
-
     . = ALIGN(PAGE_SIZE);
     DECL_SECTION(.data) {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
 
         HYPFS_PARAM
 
+        *(.data.page_aligned)
+
         *(.data .data.*)
         CONSTRUCTORS
     } :text
xen/arch/riscv/xen.lds.S +2 -5
index 250ee3f36f4f..d1c5ce59c90d 100644
@@ -84,16 +84,13 @@ SECTIONS
         __ro_after_init_end = .;
     } : text
 
-    .data.read_mostly : {
-        *(.data.read_mostly)
-    } :text
-
     . = ALIGN(PAGE_SIZE);
     .data : {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
 
         HYPFS_PARAM
 
+        *(.data.page_aligned)
         *(.sdata .sdata.*)
         *(.data .data.*)
         CONSTRUCTORS
xen/arch/x86/xen.lds.S +1 -3
index 925848980219..99802aed4e13 100644
@@ -295,13 +295,11 @@ SECTIONS
 
   __2M_rwdata_start = .;       /* Start of 2M superpages, mapped RW. */
   . = ALIGN(SMP_CACHE_BYTES);
-  DECL_SECTION(.data.read_mostly) {
+  DECL_SECTION(.data) {
        *(.data.read_mostly)
 
        HYPFS_PARAM
-  } PHDR(text)
 
-  DECL_SECTION(.data) {
        *(.data.page_aligned)
        *(.data .data.*)
   } PHDR(text)

base-commit: 4263fe42b736596cfa5bfec661f2f55f02759aa7
prerequisite-patch-id: 680071148129321ffaf7bd7435d031904014f556

Signature · 1 line
WBR, Volodymyr
#2 lore raw
Quoted 21 lines · Volodymyr Babchuk

Hi Andrew,

Quoted 17 lines · Andrew Cooper
xen/arch/arm/xen.lds.S +1 -5
index d1bb6c62d208..8d0954c90afd 100644
@@ -86,16 +86,14 @@ SECTIONS
       __ro_after_init_end = .;
   } : text
 
-  .data.read_mostly : {
-       *(.data.read_mostly)
-  } :text
-
   . = ALIGN(SMP_CACHE_BYTES);
   .data : {                    /* Data */
-       *(.data.page_aligned)
+       *(.data.read_mostly)
 
Quoted 5 lines

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

Quoted 3 lines
xen/arch/arm/xen.lds.S +1 -0
        HYPFS_PARAM
 
+       *(.data.page_aligned)

A small question: why are you moving data.page_aligned? I don't think that this can cause issues, but I want to understand the reason.

Because HYPFS_DATA is read_mostly too.

~Andrew

Reviewed-by on v1 1/1
#3 lore raw
In reply to Andrew Cooper
Quoted 3 lines · Andrew Cooper

This appears to be an error in x86 which got copied into all other architectures. .data.read_mostly is an internal detail, and none of the similar sections get exposed externally.

Why "error" though? Our linking scripts were, aiui, originally derived from Linux'es, where the section (and many others) was also separate back at the time. It just so happened that folding of various output sections never has gone as far as also dealing with this one.

Quoted 5 lines

Simply place .data.read_mostly in .data.

No functional change.

Preferably with the description adjusted a little:

Jan

#4 lore raw
In reply to Andrew Cooper
Quoted 112 lines · Andrew Cooper

This appears to be an error in x86 which got copied into all other architectures. .data.read_mostly is an internal detail, and none of the similar sections get exposed externally.

Simply place .data.read_mostly in .data.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Baptiste Le Duc <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Ross Lagerwall <[email protected]>

This is to simplfy the script checking that xen.efi's section attributes/alignments are correct for UEFI SecureBoot.

---
  xen/arch/arm/xen.lds.S   | 8 +++-----
  xen/arch/ppc/xen.lds.S   | 8 +++-----
  xen/arch/riscv/xen.lds.S | 7 ++-----
  xen/arch/x86/xen.lds.S   | 4 +---
  4 files changed, 9 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +3 -5
index d1bb6c62d208..8d0954c90afd 100644
@@ -86,16 +86,14 @@ SECTIONS
        __ro_after_init_end = .;
    } : text
 
-  .data.read_mostly : {
-       *(.data.read_mostly)
-  } :text
-
    . = ALIGN(SMP_CACHE_BYTES);
    .data : {                    /* Data */
-       *(.data.page_aligned)
+       *(.data.read_mostly)
 
         HYPFS_PARAM
 
+       *(.data.page_aligned)
+
         *(.data .data.*)
         CONSTRUCTORS
    } :text
xen/arch/ppc/xen.lds.S +3 -5
index cddb70855307..b2159279169c 100644
@@ -77,16 +77,14 @@ SECTIONS
          __ro_after_init_end = .;
      } :text
 
-    DECL_SECTION(.data.read_mostly) {
-        *(.data.read_mostly)
-    } :text
-
      . = ALIGN(PAGE_SIZE);
      DECL_SECTION(.data) {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
 
          HYPFS_PARAM
 
+        *(.data.page_aligned)
+
          *(.data .data.*)
          CONSTRUCTORS
      } :text
xen/arch/riscv/xen.lds.S +2 -5
index 250ee3f36f4f..d1c5ce59c90d 100644
@@ -84,16 +84,13 @@ SECTIONS
          __ro_after_init_end = .;
      } : text
 
-    .data.read_mostly : {
-        *(.data.read_mostly)
-    } :text
-
      . = ALIGN(PAGE_SIZE);
      .data : {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
 
          HYPFS_PARAM
 
+        *(.data.page_aligned)
          *(.sdata .sdata.*)
          *(.data .data.*)
          CONSTRUCTORS
xen/arch/x86/xen.lds.S +0 -1
index 925848980219..99802aed4e13 100644
@@ -295,13 +295,11 @@ SECTIONS
 
    __2M_rwdata_start = .;       /* Start of 2M superpages, mapped RW. */
    . = ALIGN(SMP_CACHE_BYTES);
-  DECL_SECTION(.data.read_mostly) {

xen/arch/x86/xen.lds.S SECTIONS · line 305

Quoted 10 lines
xen/arch/x86/xen.lds.S +1 -2
+  DECL_SECTION(.data) {
         *(.data.read_mostly)
 
         HYPFS_PARAM
-  } PHDR(text)
 
-  DECL_SECTION(.data) {
         *(.data.page_aligned)
         *(.data .data.*)
    } PHDR(text)

The ordering is preserved, but the alignment between the two isn't. Today the ALIGN() before .data sits between .data.read_mostly and regular .data. After this patch it sits before .data.read_mostly, and the only thing separating it from *(.sdata/.data) is *(.data.page_aligned), which has no inputs on RISC-V, PPC or Arm with CONFIG_MPU. So the tail of .data.read_mostly will share a cache line with ordinary .data, which is the false sharing __read_mostly is meant to avoid (IIUC).

Could you add ". = ALIGN(SMP_CACHE_BYTES);" after HYPFS_PARAM, so the separation doesn't depend on whether an arch has any .data.page_aligned?

~ Oleksii

#5 lore raw
Quoted 115 lines · Oleksii Kurochko
Quoted 103 lines · Andrew Cooper

This appears to be an error in x86 which got copied into all other architectures.  .data.read_mostly is an internal detail, and none of the similar sections get exposed externally.

Simply place .data.read_mostly in .data.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Baptiste Le Duc <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Ross Lagerwall <[email protected]>

This is to simplfy the script checking that xen.efi's section attributes/alignments are correct for UEFI SecureBoot.
---
  xen/arch/arm/xen.lds.S   | 8 +++----- xen/arch/ppc/xen.lds.S   | 8 +++----- xen/arch/riscv/xen.lds.S | 7 ++----- xen/arch/x86/xen.lds.S   | 4 +---

  4 files changed, 9 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +0 -3
index d1bb6c62d208..8d0954c90afd 100644
@@ -86,16 +86,14 @@ SECTIONS
         __ro_after_init_end = .;
     } : text
   -  .data.read_mostly : {
-       *(.data.read_mostly)
-  } :text
-
     . = ALIGN(SMP_CACHE_BYTES);

    .data : {                    /* Data */
-       *(.data.page_aligned)
+       *(.data.read_mostly)
           HYPFS_PARAM
  +       *(.data.page_aligned)
+
         *(.data .data.*)
         CONSTRUCTORS
    } :text

xen/arch/ppc/xen.lds.S +0 -3
index cddb70855307..b2159279169c 100644
@@ -77,16 +77,14 @@ SECTIONS
           __ro_after_init_end = .;
       } :text
   -    DECL_SECTION(.data.read_mostly) {
-        *(.data.read_mostly)
-    } :text
-
       . = ALIGN(PAGE_SIZE);

      DECL_SECTION(.data) {                    /* Data */ -        *(.data.page_aligned)
+        *(.data.read_mostly)
            HYPFS_PARAM
  +        *(.data.page_aligned)
+
          *(.data .data.*)
          CONSTRUCTORS
      } :text

xen/arch/riscv/xen.lds.S +0 -3
index 250ee3f36f4f..d1c5ce59c90d 100644
@@ -84,16 +84,13 @@ SECTIONS
           __ro_after_init_end = .;
       } : text
   -    .data.read_mostly : {
-        *(.data.read_mostly)
-    } :text
-
       . = ALIGN(PAGE_SIZE);

      .data : {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
            HYPFS_PARAM
  +        *(.data.page_aligned)
          *(.sdata .sdata.*)
          *(.data .data.*)
          CONSTRUCTORS

xen/arch/x86/xen.lds.S +0 -0
index 925848980219..99802aed4e13 100644
@@ -295,13 +295,11 @@ SECTIONS

      __2M_rwdata_start = .;       /* Start of 2M superpages, mapped RW. */
    . = ALIGN(SMP_CACHE_BYTES);
-  DECL_SECTION(.data.read_mostly) {

Quoted 8 lines

+  DECL_SECTION(.data) {
         *(.data.read_mostly)
           HYPFS_PARAM
-  } PHDR(text)
  -  DECL_SECTION(.data) {
         *(.data.page_aligned)
         *(.data .data.*)
    } PHDR(text)

Quoted 8 lines

The ordering is preserved, but the alignment between the two isn't. Today the ALIGN() before .data sits between .data.read_mostly and regular .data.  After this patch it sits before .data.read_mostly, and the only thing separating it from *(.sdata/.data) is *(.data.page_aligned), which has no inputs on RISC-V, PPC or Arm with CONFIG_MPU. So the tail of .data.read_mostly will share a cache line with ordinary .data, which is the false sharing __read_mostly is meant to avoid (IIUC).

__read_mostly is indeed meant to reduce false sharing, but this patch does not introduce any.

HYPFS_PARAM should have been read_mostly to begin with, and page alignment is greater th cache alignment so there's no sharing there either.

~Andrew

Reviewed-by
#6 lore raw
Quoted 125 lines · Andrew Cooper
Quoted 115 lines · Oleksii Kurochko
Quoted 103 lines · Andrew Cooper

This appears to be an error in x86 which got copied into all other architectures.  .data.read_mostly is an internal detail, and none of the similar sections get exposed externally.

Simply place .data.read_mostly in .data.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Teddy Astie <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Baptiste Le Duc <[email protected]>
CC: Timothy Pearson <[email protected]>
CC: Ross Lagerwall <[email protected]>

This is to simplfy the script checking that xen.efi's section attributes/alignments are correct for UEFI SecureBoot.

---
   xen/arch/arm/xen.lds.S   | 8 +++-----
   xen/arch/ppc/xen.lds.S   | 8 +++-----
   xen/arch/riscv/xen.lds.S | 7 ++-----
   xen/arch/x86/xen.lds.S   | 4 +---
   4 files changed, 9 insertions(+), 18 deletions(-)
xen/arch/arm/xen.lds.S +2 -4
index d1bb6c62d208..8d0954c90afd 100644
@@ -86,16 +86,14 @@ SECTIONS
         __ro_after_init_end = .;
     } : text
   -  .data.read_mostly : {
-       *(.data.read_mostly)
-  } :text
-
     . = ALIGN(SMP_CACHE_BYTES);
     .data : {                    /* Data */
-       *(.data.page_aligned)
+       *(.data.read_mostly)
            HYPFS_PARAM
   +       *(.data.page_aligned)
+
          *(.data .data.*)
          CONSTRUCTORS
     } :text
xen/arch/ppc/xen.lds.S +2 -4
index cddb70855307..b2159279169c 100644
@@ -77,16 +77,14 @@ SECTIONS
           __ro_after_init_end = .;
       } :text
   -    DECL_SECTION(.data.read_mostly) {
-        *(.data.read_mostly)
-    } :text
-
       . = ALIGN(PAGE_SIZE);
       DECL_SECTION(.data) {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
             HYPFS_PARAM
   +        *(.data.page_aligned)
+
           *(.data .data.*)
           CONSTRUCTORS
       } :text
xen/arch/riscv/xen.lds.S +1 -4
index 250ee3f36f4f..d1c5ce59c90d 100644
@@ -84,16 +84,13 @@ SECTIONS
           __ro_after_init_end = .;
       } : text
   -    .data.read_mostly : {
-        *(.data.read_mostly)
-    } :text
-
       . = ALIGN(PAGE_SIZE);
       .data : {                    /* Data */
-        *(.data.page_aligned)
+        *(.data.read_mostly)
             HYPFS_PARAM
   +        *(.data.page_aligned)
           *(.sdata .sdata.*)
           *(.data .data.*)
           CONSTRUCTORS
xen/arch/x86/xen.lds.S +0 -0
index 925848980219..99802aed4e13 100644
@@ -295,13 +295,11 @@ SECTIONS
       __2M_rwdata_start = .;       /* Start of 2M superpages, mapped

RW. */
    . = ALIGN(SMP_CACHE_BYTES);
-  DECL_SECTION(.data.read_mostly) {

Quoted 8 lines

+  DECL_SECTION(.data) {
         *(.data.read_mostly)
           HYPFS_PARAM
-  } PHDR(text)
  -  DECL_SECTION(.data) {
         *(.data.page_aligned)
         *(.data .data.*)
    } PHDR(text)

Quoted 8 lines

The ordering is preserved, but the alignment between the two isn't. Today the ALIGN() before .data sits between .data.read_mostly and regular .data.  After this patch it sits before .data.read_mostly, and the only thing separating it from *(.sdata/.data) is *(.data.page_aligned), which has no inputs on RISC-V, PPC or Arm with CONFIG_MPU. So the tail of .data.read_mostly will share a cache line with ordinary .data, which is the false sharing __read_mostly is meant to avoid (IIUC).

Quoted 5 lines

__read_mostly is indeed meant to reduce false sharing, but this patch does not introduce any.

HYPFS_PARAM should have been read_mostly to begin with, and page alignment is greater th cache alignment so there's no sharing there either.

Thanks for clarifying. Then:

~ Oleksii

Reviewed-by on v1 1/1
#7 lore raw
In reply to Andrew Cooper
Quoted 6 lines · Andrew Cooper

This appears to be an error in x86 which got copied into all other architectures. .data.read_mostly is an internal detail, and none of the similar sections get exposed externally.

Simply place .data.read_mostly in .data.

Quoted 8 lines

No functional change.

---

This is to simplfy the script checking that xen.efi's section attributes/alignments are correct for UEFI SecureBoot.

This is worth moving to the commit message to explain why the change is made. Also "simplify". Also, also stating the rearrangement of .data.page_aligned and HYPFS_PARAM is worth adding.

With that:

Thanks,
Jason