All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned
@ 2022-09-16 13:14 Michael Ellerman
  2022-09-16 13:14 ` [PATCH 2/2] powerpc/vmlinux.lds: Add an explicit symbol for the SRWX boundary Michael Ellerman
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Michael Ellerman @ 2022-09-16 13:14 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: npiggin

Add a check that STRICT_ALIGN_SIZE is aligned to at least PAGE_SIZE.

That then makes the alignment to PAGE_SIZE immediately after the
alignment to STRICT_ALIGN_SIZE redundant, so remove it.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/kernel/vmlinux.lds.S | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index fe22d940412f..4e56fc0ee42a 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -32,6 +32,10 @@
 
 #define STRICT_ALIGN_SIZE	(1 << CONFIG_DATA_SHIFT)
 
+#if STRICT_ALIGN_SIZE < PAGE_SIZE
+#error "CONFIG_DATA_SHIFT must be >= PAGE_SIZE"
+#endif
+
 ENTRY(_stext)
 
 PHDRS {
@@ -215,7 +219,6 @@ SECTIONS
  */
 	. = ALIGN(STRICT_ALIGN_SIZE);
 	__init_begin = .;
-	. = ALIGN(PAGE_SIZE);
 	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
 		_sinittext = .;
 		INIT_TEXT
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] powerpc/vmlinux.lds: Add an explicit symbol for the SRWX boundary
  2022-09-16 13:14 [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned Michael Ellerman
@ 2022-09-16 13:14 ` Michael Ellerman
  2022-09-16 13:32 ` [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned Christophe Leroy
  2022-10-04 13:24 ` Michael Ellerman
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2022-09-16 13:14 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: npiggin

Currently __init_begin is used as the boundary for strict RWX between
executable/read-only text and data, and non-executable (after boot) code
and data.

But that's a little subtle, so add an explicit symbol to document that
the SRWX boundary lies there, and add a comment making it clear that
__init_begin must also begin there.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 arch/powerpc/include/asm/sections.h      | 1 +
 arch/powerpc/kernel/vmlinux.lds.S        | 9 +++++++--
 arch/powerpc/mm/book3s32/mmu.c           | 2 +-
 arch/powerpc/mm/book3s64/radix_pgtable.c | 4 ++--
 4 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h
index 183e6b8af392..7ed7273b7baf 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -13,6 +13,7 @@ typedef struct func_desc func_desc_t;
 #include <asm-generic/sections.h>
 
 extern char __head_end[];
+extern char __srwx_boundary[];
 
 /* Patch sites */
 extern s32 patch__call_flush_branch_caches1;
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index 4e56fc0ee42a..24f037f517e0 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -214,11 +214,16 @@ SECTIONS
 	}
 #endif
 
+	/*
+	 * Various code relies on __init_begin being at the strict RWX boundary.
+	 */
+	. = ALIGN(STRICT_ALIGN_SIZE);
+	__srwx_boundary = .;
+	__init_begin = .;
+
 /*
  * Init sections discarded at runtime
  */
-	. = ALIGN(STRICT_ALIGN_SIZE);
-	__init_begin = .;
 	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
 		_sinittext = .;
 		INIT_TEXT
diff --git a/arch/powerpc/mm/book3s32/mmu.c b/arch/powerpc/mm/book3s32/mmu.c
index a96b73006dfb..250d174459d4 100644
--- a/arch/powerpc/mm/book3s32/mmu.c
+++ b/arch/powerpc/mm/book3s32/mmu.c
@@ -158,7 +158,7 @@ static unsigned long __init __mmu_mapin_ram(unsigned long base, unsigned long to
 unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top)
 {
 	unsigned long done;
-	unsigned long border = (unsigned long)__init_begin - PAGE_OFFSET;
+	unsigned long border = (unsigned long)__srwx_boundary - PAGE_OFFSET;
 	unsigned long size;
 
 	size = roundup_pow_of_two((unsigned long)_einittext - PAGE_OFFSET);
diff --git a/arch/powerpc/mm/book3s64/radix_pgtable.c b/arch/powerpc/mm/book3s64/radix_pgtable.c
index 698274109c91..9f880f91f584 100644
--- a/arch/powerpc/mm/book3s64/radix_pgtable.c
+++ b/arch/powerpc/mm/book3s64/radix_pgtable.c
@@ -259,8 +259,8 @@ print_mapping(unsigned long start, unsigned long end, unsigned long size, bool e
 static unsigned long next_boundary(unsigned long addr, unsigned long end)
 {
 #ifdef CONFIG_STRICT_KERNEL_RWX
-	if (addr < __pa_symbol(__init_begin))
-		return __pa_symbol(__init_begin);
+	if (addr < __pa_symbol(__srwx_boundary))
+		return __pa_symbol(__srwx_boundary);
 #endif
 	return end;
 }
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned
  2022-09-16 13:14 [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned Michael Ellerman
  2022-09-16 13:14 ` [PATCH 2/2] powerpc/vmlinux.lds: Add an explicit symbol for the SRWX boundary Michael Ellerman
@ 2022-09-16 13:32 ` Christophe Leroy
  2022-09-17  6:40   ` Michael Ellerman
  2022-10-04 13:24 ` Michael Ellerman
  2 siblings, 1 reply; 5+ messages in thread
From: Christophe Leroy @ 2022-09-16 13:32 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: npiggin



Le 16/09/2022 à 15:14, Michael Ellerman a écrit :
> Add a check that STRICT_ALIGN_SIZE is aligned to at least PAGE_SIZE.

This cannot happen, the definitions in arch/powerpc/Kconfig don't allow 
that.

> 
> That then makes the alignment to PAGE_SIZE immediately after the
> alignment to STRICT_ALIGN_SIZE redundant, so remove it.
> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
> ---
>   arch/powerpc/kernel/vmlinux.lds.S | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
> index fe22d940412f..4e56fc0ee42a 100644
> --- a/arch/powerpc/kernel/vmlinux.lds.S
> +++ b/arch/powerpc/kernel/vmlinux.lds.S
> @@ -32,6 +32,10 @@
>   
>   #define STRICT_ALIGN_SIZE	(1 << CONFIG_DATA_SHIFT)
>   
> +#if STRICT_ALIGN_SIZE < PAGE_SIZE
> +#error "CONFIG_DATA_SHIFT must be >= PAGE_SIZE"

s/PAGE_SIZE/PAGE_SHIFT

> +#endif
> +
>   ENTRY(_stext)
>   
>   PHDRS {
> @@ -215,7 +219,6 @@ SECTIONS
>    */
>   	. = ALIGN(STRICT_ALIGN_SIZE);
>   	__init_begin = .;
> -	. = ALIGN(PAGE_SIZE);
>   	.init.text : AT(ADDR(.init.text) - LOAD_OFFSET) {
>   		_sinittext = .;
>   		INIT_TEXT

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned
  2022-09-16 13:32 ` [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned Christophe Leroy
@ 2022-09-17  6:40   ` Michael Ellerman
  0 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2022-09-17  6:40 UTC (permalink / raw)
  To: Christophe Leroy, linuxppc-dev; +Cc: npiggin

Christophe Leroy <christophe.leroy@csgroup.eu> writes:
> Le 16/09/2022 à 15:14, Michael Ellerman a écrit :
>> Add a check that STRICT_ALIGN_SIZE is aligned to at least PAGE_SIZE.
>
> This cannot happen, the definitions in arch/powerpc/Kconfig don't allow 
> that.

It can't happen yet :)

There's enough combinations of DATA_SHIFT and PAGE_SIZE that it would be
easy to add a new value for either and miss the implications. So I'd
rather have a check.

>> diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
>> index fe22d940412f..4e56fc0ee42a 100644
>> --- a/arch/powerpc/kernel/vmlinux.lds.S
>> +++ b/arch/powerpc/kernel/vmlinux.lds.S
>> @@ -32,6 +32,10 @@
>>   
>>   #define STRICT_ALIGN_SIZE	(1 << CONFIG_DATA_SHIFT)
>>   
>> +#if STRICT_ALIGN_SIZE < PAGE_SIZE
>> +#error "CONFIG_DATA_SHIFT must be >= PAGE_SIZE"
>
> s/PAGE_SIZE/PAGE_SHIFT

Thanks.

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned
  2022-09-16 13:14 [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned Michael Ellerman
  2022-09-16 13:14 ` [PATCH 2/2] powerpc/vmlinux.lds: Add an explicit symbol for the SRWX boundary Michael Ellerman
  2022-09-16 13:32 ` [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned Christophe Leroy
@ 2022-10-04 13:24 ` Michael Ellerman
  2 siblings, 0 replies; 5+ messages in thread
From: Michael Ellerman @ 2022-10-04 13:24 UTC (permalink / raw)
  To: linuxppc-dev, Michael Ellerman; +Cc: npiggin

On Fri, 16 Sep 2022 23:14:21 +1000, Michael Ellerman wrote:
> Add a check that STRICT_ALIGN_SIZE is aligned to at least PAGE_SIZE.
> 
> That then makes the alignment to PAGE_SIZE immediately after the
> alignment to STRICT_ALIGN_SIZE redundant, so remove it.
> 
> 

Applied to powerpc/next.

[1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned
      https://git.kernel.org/powerpc/c/331771e836e6a32c8632d8cf5e2cdd94471258ad
[2/2] powerpc/vmlinux.lds: Add an explicit symbol for the SRWX boundary
      https://git.kernel.org/powerpc/c/b150a4d12b919baf956b807aa305cf78df03d0fe

cheers

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-04 13:50 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-16 13:14 [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned Michael Ellerman
2022-09-16 13:14 ` [PATCH 2/2] powerpc/vmlinux.lds: Add an explicit symbol for the SRWX boundary Michael Ellerman
2022-09-16 13:32 ` [PATCH 1/2] powerpc/vmlinux.lds: Ensure STRICT_ALIGN_SIZE is at least page aligned Christophe Leroy
2022-09-17  6:40   ` Michael Ellerman
2022-10-04 13:24 ` Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.