Skip to contentSkip to conversation

arm64: remove CONFIG_DEBUG_ALIGN_RODATA feature

RFC PATCH In review Ard Biesheuvel 6 participants 19 messages Mar 29, 2020 – May 7, 2020

Subsystems (2)
lore
Share & tools
lore

Ard Biesheuvel

author maintainer
#0 lore raw

RFC PATCH 1/1 arm64: remove CONFIG_DEBUG_ALIGN_RODATA feature

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

---
 arch/arm64/Kconfig.debug                  | 13 -------------
 arch/arm64/include/asm/memory.h           | 12 +-----------
 drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
 3 files changed, 4 insertions(+), 29 deletions(-)
arch/arm64/Kconfig.debug +0 -13
index 1c906d932d6b..a1efa246c9ed 100644
@@ -52,19 +52,6 @@ config DEBUG_WX
 
 	  If in doubt, say "Y".
 
-config DEBUG_ALIGN_RODATA
-	depends on STRICT_KERNEL_RWX
-	bool "Align linker sections up to SECTION_SIZE"
-	help
-	  If this option is enabled, sections that may potentially be marked as
-	  read only or non-executable will be aligned up to the section size of
-	  the kernel. This prevents sections from being split into pages and
-	  avoids a potential TLB penalty. The downside is an increase in
-	  alignment and potentially wasted space. Turn on this option if
-	  performance is more important than memory pressure.
-
-	  If in doubt, say N.
-
 config DEBUG_EFI
 	depends on EFI && DEBUG_INFO
 	bool "UEFI debugging"
arch/arm64/include/asm/memory.h +1 -11
index 4d94676e5a8b..3b34f7bde2f2 100644
@@ -119,22 +119,12 @@
 
 /*
  * Alignment of kernel segments (e.g. .text, .data).
- */
-#if defined(CONFIG_DEBUG_ALIGN_RODATA)
-/*
- *  4 KB granule:   1 level 2 entry
- * 16 KB granule: 128 level 3 entries, with contiguous bit
- * 64 KB granule:  32 level 3 entries, with contiguous bit
- */
-#define SEGMENT_ALIGN		SZ_2M
-#else
-/*
+ *
  *  4 KB granule:  16 level 3 entries, with contiguous bit
  * 16 KB granule:   4 level 3 entries, without contiguous bit
  * 64 KB granule:   1 level 3 entry
  */
 #define SEGMENT_ALIGN		SZ_64K
-#endif
 
 /*
  * Memory types available.
drivers/firmware/efi/libstub/arm64-stub.c +3 -5
index db0c1a9c1699..fc9f8ab533a7 100644
@@ -75,14 +75,12 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
 
 	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && phys_seed != 0) {
 		/*
-		 * If CONFIG_DEBUG_ALIGN_RODATA is not set, produce a
-		 * displacement in the interval [0, MIN_KIMG_ALIGN) that
-		 * doesn't violate this kernel's de-facto alignment
+		 * Produce a displacement in the interval [0, MIN_KIMG_ALIGN)
+		 * that doesn't violate this kernel's de-facto alignment
 		 * constraints.
 		 */
 		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(EFI_KIMG_ALIGN - 1);
-		u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
-			     (phys_seed >> 32) & mask : TEXT_OFFSET;
+		u32 offset = (phys_seed >> 32) & mask;
 
 		/*
 		 * With CONFIG_RANDOMIZE_TEXT_OFFSET=y, TEXT_OFFSET may not
Signature · 7 lines
2.17.1


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reviewer Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

Quoted 5 lines

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

No strong feelings either way, but getting rid of code is usually good, so:

Mark.

Quoted 83 lines
---
 arch/arm64/Kconfig.debug                  | 13 -------------
 arch/arm64/include/asm/memory.h           | 12 +-----------
 drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
 3 files changed, 4 insertions(+), 29 deletions(-)
arch/arm64/Kconfig.debug +0 -13
index 1c906d932d6b..a1efa246c9ed 100644
@@ -52,19 +52,6 @@ config DEBUG_WX
 
 	  If in doubt, say "Y".
 
-config DEBUG_ALIGN_RODATA
-	depends on STRICT_KERNEL_RWX
-	bool "Align linker sections up to SECTION_SIZE"
-	help
-	  If this option is enabled, sections that may potentially be marked as
-	  read only or non-executable will be aligned up to the section size of
-	  the kernel. This prevents sections from being split into pages and
-	  avoids a potential TLB penalty. The downside is an increase in
-	  alignment and potentially wasted space. Turn on this option if
-	  performance is more important than memory pressure.
-
-	  If in doubt, say N.
-
 config DEBUG_EFI
 	depends on EFI && DEBUG_INFO
 	bool "UEFI debugging"
arch/arm64/include/asm/memory.h +1 -11
index 4d94676e5a8b..3b34f7bde2f2 100644
@@ -119,22 +119,12 @@
 
 /*
  * Alignment of kernel segments (e.g. .text, .data).
- */
-#if defined(CONFIG_DEBUG_ALIGN_RODATA)
-/*
- *  4 KB granule:   1 level 2 entry
- * 16 KB granule: 128 level 3 entries, with contiguous bit
- * 64 KB granule:  32 level 3 entries, with contiguous bit
- */
-#define SEGMENT_ALIGN		SZ_2M
-#else
-/*
+ *
  *  4 KB granule:  16 level 3 entries, with contiguous bit
  * 16 KB granule:   4 level 3 entries, without contiguous bit
  * 64 KB granule:   1 level 3 entry
  */
 #define SEGMENT_ALIGN		SZ_64K
-#endif
 
 /*
  * Memory types available.
drivers/firmware/efi/libstub/arm64-stub.c +3 -5
index db0c1a9c1699..fc9f8ab533a7 100644
@@ -75,14 +75,12 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
 
 	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && phys_seed != 0) {
 		/*
-		 * If CONFIG_DEBUG_ALIGN_RODATA is not set, produce a
-		 * displacement in the interval [0, MIN_KIMG_ALIGN) that
-		 * doesn't violate this kernel's de-facto alignment
+		 * Produce a displacement in the interval [0, MIN_KIMG_ALIGN)
+		 * that doesn't violate this kernel's de-facto alignment
 		 * constraints.
 		 */
 		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(EFI_KIMG_ALIGN - 1);
-		u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
-			     (phys_seed >> 32) & mask : TEXT_OFFSET;
+		u32 offset = (phys_seed >> 32) & mask;
 
 		/*
 		 * With CONFIG_RANDOMIZE_TEXT_OFFSET=y, TEXT_OFFSET may not
Signature · 1 line
2.17.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author maintainer
#2 lore raw
Quoted 18 lines · Mark Rutland
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 7 lines
Quoted 1 line

No strong feelings either way, but getting rid of code is usually good, so:

Thanks Mark.

This is related to [0], which increases the PE/COFF section alignment to 64k so that a KASLR enabled kernel always lands at an address at which it can execute without being moved around first. This is an improvement in itself, but also provides 5 bits (log2(2M / 64k)) of wiggle room for the virtual as well as the physical placement of the kernel. CONFIG_DEBUG_ALIGN_RODATA kind of interferes with that, so I'd like to get rid of it.

Catalin, Will: if you have no objections, I can include this in my series for v5.8 and take it via the EFI tree.

Thanks,
Ard.

[0] https://lore.kernel.org/linux-efi/[email protected]/

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Ard Biesheuvel
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 6 lines
---
 arch/arm64/Kconfig.debug                  | 13 -------------
 arch/arm64/include/asm/memory.h           | 12 +-----------
 drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
 3 files changed, 4 insertions(+), 29 deletions(-)

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author maintainer
#4 lore raw
Quoted 25 lines · Will Deacon
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 6 lines
---
 arch/arm64/Kconfig.debug                  | 13 -------------
 arch/arm64/include/asm/memory.h           | 12 +-----------
 drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
 3 files changed, 4 insertions(+), 29 deletions(-)
Quoted 7 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Acked-by on v1 1/1
#16 lore raw
In reply to Ard Biesheuvel
Quoted 7 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

Quoted 9 lines

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

This was supposed to avoid potential performance inconsistencies with some memory being in pages vs other in block. It was always a minor concern so if it's preventing other work:

Quoted 72 lines
---
  arch/arm64/Kconfig.debug                  | 13 -------------
  arch/arm64/include/asm/memory.h           | 12 +-----------
  drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
  3 files changed, 4 insertions(+), 29 deletions(-)
arch/arm64/Kconfig.debug +0 -13
index 1c906d932d6b..a1efa246c9ed 100644
@@ -52,19 +52,6 @@ config DEBUG_WX
 
  	  If in doubt, say "Y".
 
-config DEBUG_ALIGN_RODATA
-	depends on STRICT_KERNEL_RWX
-	bool "Align linker sections up to SECTION_SIZE"
-	help
-	  If this option is enabled, sections that may potentially be marked as
-	  read only or non-executable will be aligned up to the section size of
-	  the kernel. This prevents sections from being split into pages and
-	  avoids a potential TLB penalty. The downside is an increase in
-	  alignment and potentially wasted space. Turn on this option if
-	  performance is more important than memory pressure.
-
-	  If in doubt, say N.
-
  config DEBUG_EFI
  	depends on EFI && DEBUG_INFO
  	bool "UEFI debugging"
arch/arm64/include/asm/memory.h +1 -11
index 4d94676e5a8b..3b34f7bde2f2 100644
@@ -119,22 +119,12 @@
 
  /*
   * Alignment of kernel segments (e.g. .text, .data).
- */
-#if defined(CONFIG_DEBUG_ALIGN_RODATA)
-/*
- *  4 KB granule:   1 level 2 entry
- * 16 KB granule: 128 level 3 entries, with contiguous bit
- * 64 KB granule:  32 level 3 entries, with contiguous bit
- */
-#define SEGMENT_ALIGN		SZ_2M
-#else
-/*
+ *
   *  4 KB granule:  16 level 3 entries, with contiguous bit
   * 16 KB granule:   4 level 3 entries, without contiguous bit
   * 64 KB granule:   1 level 3 entry
   */
  #define SEGMENT_ALIGN		SZ_64K
-#endif
 
  /*
   * Memory types available.
drivers/firmware/efi/libstub/arm64-stub.c +1 -3
index db0c1a9c1699..fc9f8ab533a7 100644
@@ -75,14 +75,12 @@ efi_status_t handle_kernel_image(unsigned long *image_addr,
 
  	if (IS_ENABLED(CONFIG_RANDOMIZE_BASE) && phys_seed != 0) {
  		/*
-		 * If CONFIG_DEBUG_ALIGN_RODATA is not set, produce a
-		 * displacement in the interval [0, MIN_KIMG_ALIGN) that
-		 * doesn't violate this kernel's de-facto alignment
+		 * Produce a displacement in the interval [0, MIN_KIMG_ALIGN)

drivers/firmware/efi/libstub/arm64-stub.c efi_status_t handle_kernel_image(unsigned long *image_addr, · line 86

Quoted 10 lines
drivers/firmware/efi/libstub/arm64-stub.c +2 -2
+		 * that doesn't violate this kernel's de-facto alignment
  		 * constraints.
  		 */
  		u32 mask = (MIN_KIMG_ALIGN - 1) & ~(EFI_KIMG_ALIGN - 1);
-		u32 offset = !IS_ENABLED(CONFIG_DEBUG_ALIGN_RODATA) ?
-			     (phys_seed >> 32) & mask : TEXT_OFFSET;
+		u32 offset = (phys_seed >> 32) & mask;
 
  		/*
  		 * With CONFIG_RANDOMIZE_TEXT_OFFSET=y, TEXT_OFFSET may not

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw
In reply to Ard Biesheuvel
Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · Will Deacon
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 6 lines
---
  arch/arm64/Kconfig.debug                  | 13 -------------
  arch/arm64/include/asm/memory.h           | 12 +-----------
  drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
  3 files changed, 4 insertions(+), 29 deletions(-)
Quoted 8 lines
Quoted 5 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

Yikes, I hope not!

The concern there is about block entries in the linear map; I'd assume kernel text/data means not-linear-map, and is thus a different kettle of fish anyway.

Robin.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#6 lore raw
In reply to Ard Biesheuvel
Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · Will Deacon
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 6 lines
---
 arch/arm64/Kconfig.debug                  | 13 -------------
 arch/arm64/include/asm/memory.h           | 12 +-----------
 drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
 3 files changed, 4 insertions(+), 29 deletions(-)
Quoted 8 lines
Quoted 5 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

Sorry, it's not directly related to your patch, just that if we're removing options relating to kernel mappings then I'd be quite keen on effectively forcing page-granularity on the linear map, as is currently done by default thanks to RODATA_FULL_DEFAULT_ENABLED, so that we can nobble cacheable aliases for non-coherent streaming DMA mappings by hooking into Christoph's series above.

This series just reminded me of it because it's another "off-by-default-behaviour-for-block-mappings-probably-because-of-performance- but-never-actually-measured" type of thing which really just gets in the way.

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author maintainer
#7 lore raw
Quoted 39 lines · Will Deacon
Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · Will Deacon
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 6 lines
---
 arch/arm64/Kconfig.debug                  | 13 -------------
 arch/arm64/include/asm/memory.h           | 12 +-----------
 drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
 3 files changed, 4 insertions(+), 29 deletions(-)
Quoted 8 lines
Quoted 5 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

Quoted 7 lines

Sorry, it's not directly related to your patch, just that if we're removing options relating to kernel mappings then I'd be quite keen on effectively forcing page-granularity on the linear map, as is currently done by default thanks to RODATA_FULL_DEFAULT_ENABLED, so that we can nobble cacheable aliases for non-coherent streaming DMA mappings by hooking into Christoph's series above.

Right. I don't remember seeing any complaints about RODATA_FULL_DEFAULT_ENABLED, but maybe it's too early for that.

Quoted 5 lines

This series just reminded me of it because it's another "off-by-default-behaviour-for-block-mappings-probably-because-of-performance- but-never-actually-measured" type of thing which really just gets in the way.

Well, even though I agree that the lack of actual numbers is a bit disturbing here, I'd hate to penalize all systems even more than they already are (due to ARCH_KMALLOC_MINALIGN == ARCH_DMA_MINALIGN) by adding another workaround that is only needed on devices that have non-coherent masters.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#8 lore raw
Quoted 57 lines · Ard Biesheuvel
Quoted 39 lines · Will Deacon
Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · Will Deacon
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 6 lines
---
 arch/arm64/Kconfig.debug                  | 13 -------------
 arch/arm64/include/asm/memory.h           | 12 +-----------
 drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
 3 files changed, 4 insertions(+), 29 deletions(-)
Quoted 8 lines
Quoted 5 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

Quoted 7 lines

Sorry, it's not directly related to your patch, just that if we're removing options relating to kernel mappings then I'd be quite keen on effectively forcing page-granularity on the linear map, as is currently done by default thanks to RODATA_FULL_DEFAULT_ENABLED, so that we can nobble cacheable aliases for non-coherent streaming DMA mappings by hooking into Christoph's series above.

Right. I don't remember seeing any complaints about RODATA_FULL_DEFAULT_ENABLED, but maybe it's too early for that.

Quoted 5 lines

This series just reminded me of it because it's another "off-by-default-behaviour-for-block-mappings-probably-because-of-performance- but-never-actually-measured" type of thing which really just gets in the way.

Quoted 5 lines

Well, even though I agree that the lack of actual numbers is a bit disturbing here, I'd hate to penalize all systems even more than they already are (due to ARCH_KMALLOC_MINALIGN == ARCH_DMA_MINALIGN) by adding another workaround that is only needed on devices that have non-coherent masters.

Fair enough, but I'd still like to see some numbers. If they're compelling, then we could explore something like CONFIG_OF_DMA_DEFAULT_COHERENT, but that doesn't really help the kconfig maze :(

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author maintainer
#9 lore raw
Quoted 65 lines · Will Deacon
Quoted 57 lines · Ard Biesheuvel
Quoted 39 lines · Will Deacon
Quoted 28 lines · Ard Biesheuvel
Quoted 27 lines · Will Deacon
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 6 lines
---
 arch/arm64/Kconfig.debug                  | 13 -------------
 arch/arm64/include/asm/memory.h           | 12 +-----------
 drivers/firmware/efi/libstub/arm64-stub.c |  8 +++-----
 3 files changed, 4 insertions(+), 29 deletions(-)
Quoted 8 lines
Quoted 5 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

Quoted 7 lines

Sorry, it's not directly related to your patch, just that if we're removing options relating to kernel mappings then I'd be quite keen on effectively forcing page-granularity on the linear map, as is currently done by default thanks to RODATA_FULL_DEFAULT_ENABLED, so that we can nobble cacheable aliases for non-coherent streaming DMA mappings by hooking into Christoph's series above.

Right. I don't remember seeing any complaints about RODATA_FULL_DEFAULT_ENABLED, but maybe it's too early for that.

Quoted 5 lines

This series just reminded me of it because it's another "off-by-default-behaviour-for-block-mappings-probably-because-of-performance- but-never-actually-measured" type of thing which really just gets in the way.

Quoted 5 lines

Well, even though I agree that the lack of actual numbers is a bit disturbing here, I'd hate to penalize all systems even more than they already are (due to ARCH_KMALLOC_MINALIGN == ARCH_DMA_MINALIGN) by adding another workaround that is only needed on devices that have non-coherent masters.

Quoted 4 lines

Fair enough, but I'd still like to see some numbers. If they're compelling, then we could explore something like CONFIG_OF_DMA_DEFAULT_COHERENT, but that doesn't really help the kconfig maze :(

Could we make this a runtime thing? E.g., remap the entire linear region down to pages under stop_machine() the first time we probe a device that uses non-coherent DMA?

(/me ducks)

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#17 lore raw
In reply to Ard Biesheuvel
Quoted 12 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

Quoted 5 lines

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Happy to take this patch via the arm64 tree for 5.7 (no new functionality), unless you want it to go with your other relocation login in the EFI stub patches.

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author maintainer
#18 lore raw
Quoted 18 lines · Catalin Marinas
Quoted 16 lines · Ard Biesheuvel

When CONFIG_DEBUG_ALIGN_RODATA is enabled, kernel segments mapped with different permissions (r-x for .text, r-- for .rodata, rw- for .data, etc) are rounded up to 2 MiB so they can be mapped more efficiently. In particular, it permits the segments to be mapped using level 2 block entries when using 4k pages, which is expected to result in less TLB pressure.

However, the mappings for the bulk of the kernel will use level 2 entries anyway, and the misaligned fringes are organized such that they can take advantage of the contiguous bit, and use far fewer level 3 entries than would be needed otherwise.

This makes the value of this feature dubious at best, and since it is not enabled in defconfig or in the distro configs, it does not appear to be in wide use either. So let's just remove it.

Quoted 6 lines
Quoted 1 line

Happy to take this patch via the arm64 tree for 5.7 (no new functionality), unless you want it to go with your other relocation login in the EFI stub patches.

If you don't mind taking it for v5.7, please go ahead.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#10 lore raw
In reply to Ard Biesheuvel
Quoted 12 lines · Ard Biesheuvel
Quoted 11 lines · Will Deacon
Quoted 11 lines · Will Deacon
Quoted 10 lines · Ard Biesheuvel
Quoted 8 lines · Will Deacon
Quoted 4 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Sorry, it's not directly related to your patch, just that if we're removing options relating to kernel mappings then I'd be quite keen on effectively forcing page-granularity on the linear map, as is currently done by default thanks to RODATA_FULL_DEFAULT_ENABLED, so that we can nobble cacheable aliases for non-coherent streaming DMA mappings by hooking into Christoph's series above.

Have we ever hit this issue in practice? At least from the CPU perspective, we've assumed that a non-cacheable access would not hit in the cache. Reading the ARM ARM rules, it doesn't seem to state this explicitly but we can ask for clarification (I dug out an email from 2015, left unanswered).

Assuming that the CPU is behaving as we'd expect, are there other issues with peripherals/SMMU?

Quoted 3 lines
Quoted 3 lines

Fair enough, but I'd still like to see some numbers. If they're compelling, then we could explore something like CONFIG_OF_DMA_DEFAULT_COHERENT, but that doesn't really help the kconfig maze :(

I'd prefer not to have a config option, we could easily break single Image at some point.

Quoted 3 lines

Could we make this a runtime thing? E.g., remap the entire linear region down to pages under stop_machine() the first time we probe a device that uses non-coherent DMA?

That could be pretty expensive at run-time. With the ARMv8.4-TTRem feature, I wonder whether we could do this lazily when allocating non-coherent DMA buffers.

(I still hope there isn't a problem at all with this mismatch ;)).

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
reviewer
#11 lore raw
Quoted 8 lines · Catalin Marinas
Quoted 3 lines · Ard Biesheuvel

Could we make this a runtime thing? E.g., remap the entire linear region down to pages under stop_machine() the first time we probe a device that uses non-coherent DMA?

That could be pretty expensive at run-time. With the ARMv8.4-TTRem feature, I wonder whether we could do this lazily when allocating non-coherent DMA buffers.

It's worth noting that ARMv8.4-TTRem is optional and the "level 1" and "level 2" behaviours still allows non-fatal faults to be taken while nT is set (or until you perform the TLB invalidation). We can only safely use it where we could use a full BBM sequence today.

Effectively TTRem is an optimized, where the CPU *might* be able to use entries during the break stage, but is not guaranteed to do so.

Thanksm
Mark.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#12 lore raw
In reply to Catalin Marinas
Quoted 20 lines · Catalin Marinas
Quoted 12 lines · Ard Biesheuvel
Quoted 11 lines · Will Deacon
Quoted 11 lines · Will Deacon
Quoted 10 lines · Ard Biesheuvel
Quoted 8 lines · Will Deacon
Quoted 4 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Sorry, it's not directly related to your patch, just that if we're removing options relating to kernel mappings then I'd be quite keen on effectively forcing page-granularity on the linear map, as is currently done by default thanks to RODATA_FULL_DEFAULT_ENABLED, so that we can nobble cacheable aliases for non-coherent streaming DMA mappings by hooking into Christoph's series above.

Quoted 8 lines

Have we ever hit this issue in practice? At least from the CPU perspective, we've assumed that a non-cacheable access would not hit in the cache. Reading the ARM ARM rules, it doesn't seem to state this explicitly but we can ask for clarification (I dug out an email from 2015, left unanswered).

Assuming that the CPU is behaving as we'd expect, are there other issues with peripherals/SMMU?

Any clarification would need to be architectural, I think, and not specific to the CPU. Worth asking again though.

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author maintainer
#13 lore raw
In reply to Catalin Marinas
Quoted 21 lines · Catalin Marinas
Quoted 12 lines · Ard Biesheuvel
Quoted 11 lines · Will Deacon
Quoted 11 lines · Will Deacon
Quoted 10 lines · Ard Biesheuvel
Quoted 8 lines · Will Deacon
Quoted 4 lines

But I would really like to go a step further and rip out the block mapping support altogether so that we can fix non-coherent DMA aliases:

https://lore.kernel.org/lkml/[email protected]

I'm not sure I follow - is this about mapping parts of the static kernel Image for non-coherent DMA?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

Sorry, it's not directly related to your patch, just that if we're removing options relating to kernel mappings then I'd be quite keen on effectively forcing page-granularity on the linear map, as is currently done by default thanks to RODATA_FULL_DEFAULT_ENABLED, so that we can nobble cacheable aliases for non-coherent streaming DMA mappings by hooking into Christoph's series above.

Quoted 6 lines

Have we ever hit this issue in practice? At least from the CPU perspective, we've assumed that a non-cacheable access would not hit in the cache. Reading the ARM ARM rules, it doesn't seem to state this explicitly but we can ask for clarification (I dug out an email from 2015, left unanswered).

There is some wording in D4.4.5 (Behavior of caches at reset) that suggests that implementations may permit cache hits in regions that are mapped Non-cacheable (although the paragraph in question talks about global controls and not page table attributes)

Quoted 3 lines

Assuming that the CPU is behaving as we'd expect, are there other issues with peripherals/SMMU?

There is the NoSnoop PCIe issue as well: PCIe masters that are DMA coherent in general can generate transactions with non-cacheable attributes. I guess this is mostly orthogonal, but I'm sure it would be much easier to reason about correctness if it is guaranteed that no mappings with mismatched attributes exist anywhere.

Quoted 11 lines
Quoted 3 lines
Quoted 3 lines

Fair enough, but I'd still like to see some numbers. If they're compelling, then we could explore something like CONFIG_OF_DMA_DEFAULT_COHERENT, but that doesn't really help the kconfig maze :(

I'd prefer not to have a config option, we could easily break single Image at some point.

Quoted 3 lines

Could we make this a runtime thing? E.g., remap the entire linear region down to pages under stop_machine() the first time we probe a device that uses non-coherent DMA?

Quoted 6 lines

That could be pretty expensive at run-time. With the ARMv8.4-TTRem feature, I wonder whether we could do this lazily when allocating non-coherent DMA buffers.

(I still hope there isn't a problem at all with this mismatch ;)).

Now that we have the pieces to easily remap the linear region down to pages, and [apparently] some generic infrastructure to manage the linear aliases, the only downside is the alleged performance hit resulting from increased TLB pressure. This is obviously highly micro-architecture dependent, but with Xgene1 and ThunderX1 out of the picture, I wonder if the tradeoffs are different now. Maybe by now, we should just suck it up (Note that we had no complaints afaik regarding the fact that we map the linear map down to pages by default now)

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#14 lore raw
Quoted 21 lines · Ard Biesheuvel
Quoted 13 lines · Catalin Marinas
Quoted 4 lines · Ard Biesheuvel
Quoted 3 lines · Will Deacon

Fair enough, but I'd still like to see some numbers. If they're compelling, then we could explore something like CONFIG_OF_DMA_DEFAULT_COHERENT, but that doesn't really help the kconfig maze :(

I'd prefer not to have a config option, we could easily break single Image at some point.

Quoted 3 lines

Could we make this a runtime thing? E.g., remap the entire linear region down to pages under stop_machine() the first time we probe a device that uses non-coherent DMA?

Quoted 6 lines

That could be pretty expensive at run-time. With the ARMv8.4-TTRem feature, I wonder whether we could do this lazily when allocating non-coherent DMA buffers.

(I still hope there isn't a problem at all with this mismatch ;)).

Quoted 8 lines

Now that we have the pieces to easily remap the linear region down to pages, and [apparently] some generic infrastructure to manage the linear aliases, the only downside is the alleged performance hit resulting from increased TLB pressure. This is obviously highly micro-architecture dependent, but with Xgene1 and ThunderX1 out of the picture, I wonder if the tradeoffs are different now. Maybe by now, we should just suck it up (Note that we had no complaints afaik regarding the fact that we map the linear map down to pages by default now)

I'd be in favour of that fwiw.

Catalin -- did you get anything back from the architects about the cache hit behaviour?

Will

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#15 lore raw
Quoted 2 lines · Will Deacon

Catalin -- did you get anything back from the architects about the cache hit behaviour?

Any read from a non-cacheable alias would be coherent with writes using the same non-cacheable attributes, irrespective of other cacheable aliases (of course, subject to the cache lines having been previously cleaned/invalidated to avoid dirty lines evictions).

So as long as the hardware works as per the ARM ARM (B2.8), we don't need to unmap the non-cacheable DMA buffers from the linear map.

Signature · 6 lines
Catalin

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel