linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] arm64: Align .text section to PAGE_SIZE
@ 2015-10-26 18:09 Jeremy Linton
  2015-10-26 20:16 ` Mark Rutland
  0 siblings, 1 reply; 5+ messages in thread
From: Jeremy Linton @ 2015-10-26 18:09 UTC (permalink / raw)
  To: linux-arm-kernel

v2:
Use ALIGN_DEBUG_RO_MIN() instead of ALIGN() directly.

v1:
It appears that 64k page kernel's die early, in a somewhat random set
of locations when built without KVM. Most likely during memblock
manipulations (depending on kernel debug options).

Normally when KVM is built into the kernel it has an explicit
PAGE_SIZE alignment requirement and that forces the text section to be
aligned to PAGE_SIZE. Without it, the alignment granularity is likely to
be 4k.

This updates the linker script to assure that the the text section is
aligned to a minimum of PAGE_SIZE regardless of build options.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
 arch/arm64/kernel/vmlinux.lds.S | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 8a5d97b..f3fc966 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -91,7 +91,7 @@ SECTIONS
 		_text = .;
 		HEAD_TEXT
 	}
-	ALIGN_DEBUG_RO
+	ALIGN_DEBUG_RO_MIN(PAGE_SIZE)
 	.text : {			/* Real text segment		*/
 		_stext = .;		/* Text and read-only data	*/
 			__exception_text_start = .;
-- 
2.4.3

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

* [PATCH v2] arm64: Align .text section to PAGE_SIZE
  2015-10-26 18:09 [PATCH v2] arm64: Align .text section to PAGE_SIZE Jeremy Linton
@ 2015-10-26 20:16 ` Mark Rutland
  2015-10-26 20:26   ` Mark Rutland
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Rutland @ 2015-10-26 20:16 UTC (permalink / raw)
  To: linux-arm-kernel

Hi,

On Mon, Oct 26, 2015 at 01:09:49PM -0500, Jeremy Linton wrote:
> v2:
> Use ALIGN_DEBUG_RO_MIN() instead of ALIGN() directly.
> 
> v1:

Move the v* stuff below the ---, there's no need for that in the
permanent commit message.

> It appears that 64k page kernel's die early, in a somewhat random set
> of locations when built without KVM. Most likely during memblock
> manipulations (depending on kernel debug options).
> 
> Normally when KVM is built into the kernel it has an explicit
> PAGE_SIZE alignment requirement and that forces the text section to be
> aligned to PAGE_SIZE. Without it, the alignment granularity is likely to
> be 4k.

Please replace these with a description of the issue as an effect of
CONFIG_DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA, now that Ard figured
that out for us, so we don't have to figure it out again in future.

e.g.

A kernel built with DEBUG_RO_DATA && !CONFIG_DEBUG_ALIGN_RODATA doesn't
have .text aligned to a page boundary, though fixup_executable works at
page-genularity thanks to its use of create_mapping. If .text is not
page-aligned, the first page it exists in may be marked non-executable,
leading to failures when an attempt is made to execute code in said
page.

> This updates the linker script to assure that the the text section is

Nit: s/assure/ensure/

> aligned to a minimum of PAGE_SIZE regardless of build options.
> 
> Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
> ---
>  arch/arm64/kernel/vmlinux.lds.S | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
> index 8a5d97b..f3fc966 100644
> --- a/arch/arm64/kernel/vmlinux.lds.S
> +++ b/arch/arm64/kernel/vmlinux.lds.S
> @@ -91,7 +91,7 @@ SECTIONS
>  		_text = .;
>  		HEAD_TEXT
>  	}
> -	ALIGN_DEBUG_RO
> +	ALIGN_DEBUG_RO_MIN(PAGE_SIZE)

I'm in two minds about having a separate macro, as you suggested to save
space when !DEBUG_RO_DATA. I won't strongly push for it, though it would
be nice to not waste memory here if we don't have to.

Also, couldn't the same issue happen for other sections (e.g. rodata)?

Perhaps it would be better to have something like the following (with
PAGE_SHIFT sorted out to be includable in a linker script), so any
ALIGN_DEBUG_RO* correctly aligns things to whatever boundary is
required, and we don't need to over-align things in the !DEBUG_RO_DATA
case.

Thanks,
Mark.

---->8----
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index 9807333..4d77757 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -60,9 +60,12 @@ PECOFF_FILE_ALIGNMENT = 0x200;
 #define PECOFF_EDATA_PADDING
 #endif
 
-#ifdef CONFIG_DEBUG_ALIGN_RODATA
+#if defined(CONFIG_DEBUG_ALIGN_RODATA)
 #define ALIGN_DEBUG_RO                 . = ALIGN(1<<SECTION_SHIFT);
 #define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
+#elif defined(CONFIG_DEBUG_RODATA)
+#define ALIGN_DEBUG_RO                 . = ALIGN(1<<PAGE_SHIFT);
+#define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
 #else
 #define ALIGN_DEBUG_RO
 #define ALIGN_DEBUG_RO_MIN(min)                . = ALIGN(min);

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

* [PATCH v2] arm64: Align .text section to PAGE_SIZE
  2015-10-26 20:16 ` Mark Rutland
@ 2015-10-26 20:26   ` Mark Rutland
  2015-10-26 21:09     ` Laura Abbott
  0 siblings, 1 reply; 5+ messages in thread
From: Mark Rutland @ 2015-10-26 20:26 UTC (permalink / raw)
  To: linux-arm-kernel

> Perhaps it would be better to have something like the following (with
> PAGE_SHIFT sorted out to be includable in a linker script), so any
> ALIGN_DEBUG_RO* correctly aligns things to whatever boundary is
> required, and we don't need to over-align things in the !DEBUG_RO_DATA
> case.

Ignore the bit about PAGE_SHIFT and linker script. I'd got confused as I
had a local typo breaking the build.

With the below diff applied I can boot a defconfig +CONFIG_DEBUG_RODATA
+CONFIG_ARM64_64K_PAGES v4.3-rc7 kernel on Juno

Thanks,
Mark.

> ---->8----
> diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
> index 9807333..4d77757 100644
> --- a/arch/arm64/kernel/vmlinux.lds.S
> +++ b/arch/arm64/kernel/vmlinux.lds.S
> @@ -60,9 +60,12 @@ PECOFF_FILE_ALIGNMENT = 0x200;
>  #define PECOFF_EDATA_PADDING
>  #endif
>  
> -#ifdef CONFIG_DEBUG_ALIGN_RODATA
> +#if defined(CONFIG_DEBUG_ALIGN_RODATA)
>  #define ALIGN_DEBUG_RO                 . = ALIGN(1<<SECTION_SHIFT);
>  #define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
> +#elif defined(CONFIG_DEBUG_RODATA)
> +#define ALIGN_DEBUG_RO                 . = ALIGN(1<<PAGE_SHIFT);
> +#define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
>  #else
>  #define ALIGN_DEBUG_RO
>  #define ALIGN_DEBUG_RO_MIN(min)                . = ALIGN(min);

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

* [PATCH v2] arm64: Align .text section to PAGE_SIZE
  2015-10-26 20:26   ` Mark Rutland
@ 2015-10-26 21:09     ` Laura Abbott
  2015-10-26 21:35       ` Mark Rutland
  0 siblings, 1 reply; 5+ messages in thread
From: Laura Abbott @ 2015-10-26 21:09 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/26/15 1:26 PM, Mark Rutland wrote:
>> Perhaps it would be better to have something like the following (with
>> PAGE_SHIFT sorted out to be includable in a linker script), so any
>> ALIGN_DEBUG_RO* correctly aligns things to whatever boundary is
>> required, and we don't need to over-align things in the !DEBUG_RO_DATA
>> case.
>
> Ignore the bit about PAGE_SHIFT and linker script. I'd got confused as I
> had a local typo breaking the build.
>
> With the below diff applied I can boot a defconfig +CONFIG_DEBUG_RODATA
> +CONFIG_ARM64_64K_PAGES v4.3-rc7 kernel on Juno
>

Most of the alignment was found by trial and error so I suspect it was
just getting lucky before. I think this should be covering all the
cases. Hopefully the protections will make it more restrictive instead
of less to catch any more corner cases. For whoever ends up submitting
the patch,

Reviewed-by: Laura Abbott <laura@labbott.name>

> Thanks,
> Mark.
>
>> ---->8----
>> diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
>> index 9807333..4d77757 100644
>> --- a/arch/arm64/kernel/vmlinux.lds.S
>> +++ b/arch/arm64/kernel/vmlinux.lds.S
>> @@ -60,9 +60,12 @@ PECOFF_FILE_ALIGNMENT = 0x200;
>>   #define PECOFF_EDATA_PADDING
>>   #endif
>>
>> -#ifdef CONFIG_DEBUG_ALIGN_RODATA
>> +#if defined(CONFIG_DEBUG_ALIGN_RODATA)
>>   #define ALIGN_DEBUG_RO                 . = ALIGN(1<<SECTION_SHIFT);
>>   #define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
>> +#elif defined(CONFIG_DEBUG_RODATA)
>> +#define ALIGN_DEBUG_RO                 . = ALIGN(1<<PAGE_SHIFT);
>> +#define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
>>   #else
>>   #define ALIGN_DEBUG_RO
>>   #define ALIGN_DEBUG_RO_MIN(min)                . = ALIGN(min);

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

* [PATCH v2] arm64: Align .text section to PAGE_SIZE
  2015-10-26 21:09     ` Laura Abbott
@ 2015-10-26 21:35       ` Mark Rutland
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Rutland @ 2015-10-26 21:35 UTC (permalink / raw)
  To: linux-arm-kernel

On Mon, Oct 26, 2015 at 02:09:58PM -0700, Laura Abbott wrote:
> On 10/26/15 1:26 PM, Mark Rutland wrote:
> >>Perhaps it would be better to have something like the following (with
> >>PAGE_SHIFT sorted out to be includable in a linker script), so any
> >>ALIGN_DEBUG_RO* correctly aligns things to whatever boundary is
> >>required, and we don't need to over-align things in the !DEBUG_RO_DATA
> >>case.
> >
> >Ignore the bit about PAGE_SHIFT and linker script. I'd got confused as I
> >had a local typo breaking the build.
> >
> >With the below diff applied I can boot a defconfig +CONFIG_DEBUG_RODATA
> >+CONFIG_ARM64_64K_PAGES v4.3-rc7 kernel on Juno
> >
> 
> Most of the alignment was found by trial and error so I suspect it was
> just getting lucky before. I think this should be covering all the
> cases. Hopefully the protections will make it more restrictive instead
> of less to catch any more corner cases.

Hopefully!

On a somewhat related note, we should probably move .rodata away from
.text; currently we give everything between _stext and _etext
PAGE_KERNEL_EXEC permissions (i.e. !PXN), and .rodata has no reason to
be executable.

Doing so would also make it simpler to add .rodata to the mem_init
notice, which I've been meaning to do for a while.

I can take a look at shuffling sections for that tomorrow.

> For whoever ends up submitting the patch,
> 
> Reviewed-by: Laura Abbott <laura@labbott.name>

Cheers; I'll spin this as a full patch momentarily.

Thanks,
Mark.

> >>---->8----
> >>diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
> >>index 9807333..4d77757 100644
> >>--- a/arch/arm64/kernel/vmlinux.lds.S
> >>+++ b/arch/arm64/kernel/vmlinux.lds.S
> >>@@ -60,9 +60,12 @@ PECOFF_FILE_ALIGNMENT = 0x200;
> >>  #define PECOFF_EDATA_PADDING
> >>  #endif
> >>
> >>-#ifdef CONFIG_DEBUG_ALIGN_RODATA
> >>+#if defined(CONFIG_DEBUG_ALIGN_RODATA)
> >>  #define ALIGN_DEBUG_RO                 . = ALIGN(1<<SECTION_SHIFT);
> >>  #define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
> >>+#elif defined(CONFIG_DEBUG_RODATA)
> >>+#define ALIGN_DEBUG_RO                 . = ALIGN(1<<PAGE_SHIFT);
> >>+#define ALIGN_DEBUG_RO_MIN(min)                ALIGN_DEBUG_RO
> >>  #else
> >>  #define ALIGN_DEBUG_RO
> >>  #define ALIGN_DEBUG_RO_MIN(min)                . = ALIGN(min);
> 

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

end of thread, other threads:[~2015-10-26 21:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-26 18:09 [PATCH v2] arm64: Align .text section to PAGE_SIZE Jeremy Linton
2015-10-26 20:16 ` Mark Rutland
2015-10-26 20:26   ` Mark Rutland
2015-10-26 21:09     ` Laura Abbott
2015-10-26 21:35       ` Mark Rutland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).