linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] arm64: Align .text section to PAGE_SIZE
@ 2015-10-23 14:22 Jeremy Linton
  2015-10-23 15:34 ` Ard Biesheuvel
  0 siblings, 1 reply; 6+ messages in thread
From: Jeremy Linton @ 2015-10-23 14:22 UTC (permalink / raw)
  To: linux-arm-kernel

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..bf7b972 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -92,7 +92,7 @@ SECTIONS
 		HEAD_TEXT
 	}
 	ALIGN_DEBUG_RO
-	.text : {			/* Real text segment		*/
+	.text ALIGN(PAGE_SIZE) : {	/* Real text segment		*/
 		_stext = .;		/* Text and read-only data	*/
 			__exception_text_start = .;
 			*(.exception.text)
-- 
2.4.3

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

* [PATCH] arm64: Align .text section to PAGE_SIZE
  2015-10-23 14:22 [PATCH] arm64: Align .text section to PAGE_SIZE Jeremy Linton
@ 2015-10-23 15:34 ` Ard Biesheuvel
  2015-10-23 16:32   ` Jeremy Linton
  0 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2015-10-23 15:34 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Jeremy,

On 23 October 2015 at 16:22, Jeremy Linton <jeremy.linton@arm.com> wrote:
> It appears that 64k page kernel's die early, in a somewhat random set

nit: kernels

> of locations when built without KVM. Most likely during memblock
> manipulations (depending on kernel debug options).
>

It looks like fixup_executable() [with DEBUG_RODATA enabled] is the
culprit here: it calls create mapping() with a size that gets rounded
up to a multiple of PAGE_SIZE, which means the region that ends up
getting its exec bits cleared is larger than it should. Perhaps it is
better to fix that instead?

> 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..bf7b972 100644
> --- a/arch/arm64/kernel/vmlinux.lds.S
> +++ b/arch/arm64/kernel/vmlinux.lds.S
> @@ -92,7 +92,7 @@ SECTIONS
>                 HEAD_TEXT
>         }
>         ALIGN_DEBUG_RO
> -       .text : {                       /* Real text segment            */
> +       .text ALIGN(PAGE_SIZE) : {      /* Real text segment            */
>                 _stext = .;             /* Text and read-only data      */
>                         __exception_text_start = .;
>                         *(.exception.text)
> --
> 2.4.3
>
>

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

* [PATCH] arm64: Align .text section to PAGE_SIZE
  2015-10-23 15:34 ` Ard Biesheuvel
@ 2015-10-23 16:32   ` Jeremy Linton
  2015-10-23 16:49     ` Ard Biesheuvel
  0 siblings, 1 reply; 6+ messages in thread
From: Jeremy Linton @ 2015-10-23 16:32 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/23/2015 10:34 AM, Ard Biesheuvel wrote:
> It looks like fixup_executable() [with DEBUG_RODATA enabled] is the
> culprit here: it calls create mapping() with a size that gets rounded
> up to a multiple of PAGE_SIZE, which means the region that ends up
> getting its exec bits cleared is larger than it should. Perhaps it is
> better to fix that instead?

Ard,
	Thanks for taking a look at this!

	Your probably right.

	But AFAIK, with just that fix text/ro sections can be partially mapped 
without ro. It seems to me that putting a little padding in so that they 
are on separate pages is a good idea, especially since it seems the 
remaining sections of interest are page aligned, either explicitly in 
the linker script or via assembly directives in assorted places.

	Maybe a clearer fix is an additional ifdef in the DEBUG_ALIGN_RODATA 
stanza which sets ALIGN_DEBUG_RO to align to pagesize if DEBUG_RODATA is 
set, that way it only takes affect for RODATA.

Thanks,
	Jeremy

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

* [PATCH] arm64: Align .text section to PAGE_SIZE
  2015-10-23 16:32   ` Jeremy Linton
@ 2015-10-23 16:49     ` Ard Biesheuvel
  2015-10-23 18:13       ` Jeremy Linton
  0 siblings, 1 reply; 6+ messages in thread
From: Ard Biesheuvel @ 2015-10-23 16:49 UTC (permalink / raw)
  To: linux-arm-kernel

(+ Laura)

http://thread.gmane.org/gmane.linux.ports.arm.kernel/450513

On 23 October 2015 at 18:32, Jeremy Linton <jeremy.linton@arm.com> wrote:
> On 10/23/2015 10:34 AM, Ard Biesheuvel wrote:
>>
>> It looks like fixup_executable() [with DEBUG_RODATA enabled] is the
>> culprit here: it calls create mapping() with a size that gets rounded
>> up to a multiple of PAGE_SIZE, which means the region that ends up
>> getting its exec bits cleared is larger than it should. Perhaps it is
>> better to fix that instead?
>
>
> Ard,
>         Thanks for taking a look at this!
>
>         Your probably right.
>
>         But AFAIK, with just that fix text/ro sections can be partially
> mapped without ro.

Yes.

> It seems to me that putting a little padding in so that
> they are on separate pages is a good idea, especially since it seems the
> remaining sections of interest are page aligned, either explicitly in the
> linker script or via assembly directives in assorted places.
>

This should do the trick then, I think:
------8<----------
diff --git a/arch/arm64/kernel/vmlinux.lds.S b/arch/arm64/kernel/vmlinux.lds.S
index e9b8276ca079..db834a464986 100644
--- a/arch/arm64/kernel/vmlinux.lds.S
+++ b/arch/arm64/kernel/vmlinux.lds.S
@@ -104,7 +104,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 = .;
------8<----------

>         Maybe a clearer fix is an additional ifdef in the DEBUG_ALIGN_RODATA
> stanza which sets ALIGN_DEBUG_RO to align to pagesize if DEBUG_RODATA is
> set, that way it only takes affect for RODATA.
>

I think the diff does what you mean here.

-- 
Ard.

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

* [PATCH] arm64: Align .text section to PAGE_SIZE
  2015-10-23 16:49     ` Ard Biesheuvel
@ 2015-10-23 18:13       ` Jeremy Linton
  2015-10-24  2:29         ` Ard Biesheuvel
  0 siblings, 1 reply; 6+ messages in thread
From: Jeremy Linton @ 2015-10-23 18:13 UTC (permalink / raw)
  To: linux-arm-kernel

On 10/23/2015 11:49 AM, Ard Biesheuvel wrote:
> On 23 October 2015 at 18:32, Jeremy Linton <jeremy.linton@arm.com> wrote:
...
>>          Maybe a clearer fix is an additional ifdef in the DEBUG_ALIGN_RODATA
>> stanza which sets ALIGN_DEBUG_RO to align to pagesize if DEBUG_RODATA is
>> set, that way it only takes affect for RODATA.
>
> I think the diff does what you mean here.
...

This solves the problem I have. But, my comment about was trying to be a 
little more creative and allow it to align at less than page size if 
DEBUG_RODATA isn't set, as it does today. Sort of a packed kernel if you 
will...

But I will re-post shortly with just the ALIGN_DEBUG_RO change you suggest.

Thanks,

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

* [PATCH] arm64: Align .text section to PAGE_SIZE
  2015-10-23 18:13       ` Jeremy Linton
@ 2015-10-24  2:29         ` Ard Biesheuvel
  0 siblings, 0 replies; 6+ messages in thread
From: Ard Biesheuvel @ 2015-10-24  2:29 UTC (permalink / raw)
  To: linux-arm-kernel

(+ Laura, correct email this time)

http://thread.gmane.org/gmane.linux.ports.arm.kernel/450513

On 23 October 2015 at 20:13, Jeremy Linton <jeremy.linton@arm.com> wrote:
> On 10/23/2015 11:49 AM, Ard Biesheuvel wrote:
>>
>> On 23 October 2015 at 18:32, Jeremy Linton <jeremy.linton@arm.com> wrote:
>
> ...
>>>
>>>          Maybe a clearer fix is an additional ifdef in the
>>> DEBUG_ALIGN_RODATA
>>> stanza which sets ALIGN_DEBUG_RO to align to pagesize if DEBUG_RODATA is
>>> set, that way it only takes affect for RODATA.
>>
>>
>> I think the diff does what you mean here.
>
> ...
>
> This solves the problem I have. But, my comment about was trying to be a
> little more creative and allow it to align at less than page size if
> DEBUG_RODATA isn't set, as it does today. Sort of a packed kernel if you
> will...
>

OK, I didn't catch that. Not sure if the average waste of 32 KB is
worth the trouble, though. Especially since, in my opinion,
CONFIG_DEBUG_RODATA should be promoted to a non-debug 'default y'
option.

-- 
Ard.

> But I will re-post shortly with just the ALIGN_DEBUG_RO change you suggest.
>
> Thanks,
>
>

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

end of thread, other threads:[~2015-10-24  2:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-23 14:22 [PATCH] arm64: Align .text section to PAGE_SIZE Jeremy Linton
2015-10-23 15:34 ` Ard Biesheuvel
2015-10-23 16:32   ` Jeremy Linton
2015-10-23 16:49     ` Ard Biesheuvel
2015-10-23 18:13       ` Jeremy Linton
2015-10-24  2:29         ` Ard Biesheuvel

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).