Skip to contentSkip to conversation

arm64: add PAGE_ALIGNED_DATA to linker script

PATCH In review Mark Salter 3 participants 10 messages Oct 8, 2013 – Nov 4, 2013 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: add PAGE_ALIGNED_DATA to linker script

The arm64 linker script doesn't use the PAGE_ALIGNED_DATA macro which leads to a ".data..page_aligned" section being placed between the end of .data and start of .bss:

% readelf -e vmlinux
...
Section to Segment mapping:
Segment Sections...
00 .head.text .text .text.init .rodata __ksymtab __ksymtab_gpl \
__ksymtab_strings __param __modver __ex_table .notes \
.init.text .init.data .data..percpu .data .data..page_aligned .bss

This causes problems for the EFI stub which may have to relocate the kernel image based on stext and _edata symbols.

This patch adds PAGE_ALIGNED_DATA() to the linker script inside the the .data section.

---
 arch/arm64/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/vmlinux.lds.S +1 -0
index f8ab9d8..e441556 100644
@@ -110,6 +110,7 @@ SECTIONS
 		 */
 		INIT_TASK_DATA(THREAD_SIZE)
 		NOSAVE_DATA
+		PAGE_ALIGNED_DATA(PAGE_SIZE)
 		CACHELINE_ALIGNED_DATA(64)
 		READ_MOSTLY_DATA(64)
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 28 lines · Mark Salter

The arm64 linker script doesn't use the PAGE_ALIGNED_DATA macro which leads to a ".data..page_aligned" section being placed between the end of .data and start of .bss:

% readelf -e vmlinux
...
Section to Segment mapping:
Segment Sections...
00 .head.text .text .text.init .rodata __ksymtab __ksymtab_gpl \
__ksymtab_strings __param __modver __ex_table .notes \
.init.text .init.data .data..percpu .data .data..page_aligned .bss

This causes problems for the EFI stub which may have to relocate the kernel image based on stext and _edata symbols.

This patch adds PAGE_ALIGNED_DATA() to the linker script inside the the .data section.

---
 arch/arm64/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/kernel/vmlinux.lds.S +0 -0
index f8ab9d8..e441556 100644

arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 115

Quoted 6 lines
arch/arm64/kernel/vmlinux.lds.S +1 -0
@@ -110,6 +110,7 @@ SECTIONS
 		 */
 		INIT_TASK_DATA(THREAD_SIZE)
 		NOSAVE_DATA
+		PAGE_ALIGNED_DATA(PAGE_SIZE)
 		CACHELINE_ALIGNED_DATA(64)
 		READ_MOSTLY_DATA(64)

Can we just replace this chunk with RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE) instead?

Will

#2 lore raw
Quoted 24 lines · Will Deacon
Quoted 23 lines · Mark Salter

The arm64 linker script doesn't use the PAGE_ALIGNED_DATA macro which leads to a ".data..page_aligned" section being placed between the end of .data and start of .bss:

% readelf -e vmlinux
...
Section to Segment mapping:
Segment Sections...
00 .head.text .text .text.init .rodata __ksymtab __ksymtab_gpl \
__ksymtab_strings __param __modver __ex_table .notes \
.init.text .init.data .data..percpu .data .data..page_aligned .bss

This causes problems for the EFI stub which may have to relocate the kernel image based on stext and _edata symbols.

This patch adds PAGE_ALIGNED_DATA() to the linker script inside the the .data section.

---
 arch/arm64/kernel/vmlinux.lds.S | 1 +
 1 file changed, 1 insertion(+)
Quoted 14 lines

arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 115

Quoted 11 lines
arch/arm64/kernel/vmlinux.lds.S +1 -0
index f8ab9d8..e441556 100644
@@ -110,6 +110,7 @@ SECTIONS
 		 */
 		INIT_TASK_DATA(THREAD_SIZE)
 		NOSAVE_DATA
+		PAGE_ALIGNED_DATA(PAGE_SIZE)
 		CACHELINE_ALIGNED_DATA(64)
 		READ_MOSTLY_DATA(64)

Can we just replace this chunk with RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE) instead?

Possibly. The layout of the included macros is the same. The only difference being the placement of _data, _sdata, and _edata inside .data and the use of __data_loc.

--Mark

#3 lore raw
In reply to Will Deacon
Quoted 11 lines · Will Deacon

arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 115

Quoted 7 lines
arch/arm64/kernel/vmlinux.lds.S +1 -0
@@ -110,6 +110,7 @@ SECTIONS
               */
              INIT_TASK_DATA(THREAD_SIZE)
              NOSAVE_DATA
+             PAGE_ALIGNED_DATA(PAGE_SIZE)
              CACHELINE_ALIGNED_DATA(64)
              READ_MOSTLY_DATA(64)

Can we just replace this chunk with RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE) instead?

I took a look at this. It can be done, but the RW_DATA_SECTION aligns data to PAGE_SIZE where the existing alignment is THREAD_SIZE. So using RW_DATA_SECTION would waste some space if using 64K pagesize.

--Mark

#4 lore raw
Quoted 13 lines · Mark Salter
Quoted 11 lines · Will Deacon

arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 115

Quoted 7 lines
arch/arm64/kernel/vmlinux.lds.S +1 -0
@@ -110,6 +110,7 @@ SECTIONS
               */
              INIT_TASK_DATA(THREAD_SIZE)
              NOSAVE_DATA
+             PAGE_ALIGNED_DATA(PAGE_SIZE)
              CACHELINE_ALIGNED_DATA(64)
              READ_MOSTLY_DATA(64)

Can we just replace this chunk with RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE) instead?

Quoted 5 lines

I took a look at this. It can be done, but the RW_DATA_SECTION aligns data to PAGE_SIZE where the existing alignment is THREAD_SIZE. So using RW_DATA_SECTION would waste some space if using 64K pagesize.

--Mark

So where do we stand with this one?

#5 lore raw
Quoted 14 lines · Mark Salter
Quoted 13 lines · Mark Salter
Quoted 11 lines · Will Deacon

arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 115

Quoted 7 lines
arch/arm64/kernel/vmlinux.lds.S +1 -0
@@ -110,6 +110,7 @@ SECTIONS
               */
              INIT_TASK_DATA(THREAD_SIZE)
              NOSAVE_DATA
+             PAGE_ALIGNED_DATA(PAGE_SIZE)
              CACHELINE_ALIGNED_DATA(64)
              READ_MOSTLY_DATA(64)

Can we just replace this chunk with RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE) instead?

Quoted 7 lines
Quoted 5 lines

I took a look at this. It can be done, but the RW_DATA_SECTION aligns data to PAGE_SIZE where the existing alignment is THREAD_SIZE. So using RW_DATA_SECTION would waste some space if using 64K pagesize.

--Mark

So where do we stand with this one?

I'd probably go for using the generic macro, but I don't have strong preferences either way.

Will

maintainer
#6 lore raw
In reply to Mark Salter
Quoted 13 lines · Mark Salter
Quoted 11 lines · Will Deacon

arch/arm64/kernel/vmlinux.lds.S SECTIONS · line 115

Quoted 7 lines
arch/arm64/kernel/vmlinux.lds.S +1 -0
@@ -110,6 +110,7 @@ SECTIONS
               */
              INIT_TASK_DATA(THREAD_SIZE)
              NOSAVE_DATA
+             PAGE_ALIGNED_DATA(PAGE_SIZE)
              CACHELINE_ALIGNED_DATA(64)
              READ_MOSTLY_DATA(64)

Can we just replace this chunk with RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE) instead?

Quoted 3 lines

I took a look at this. It can be done, but the RW_DATA_SECTION aligns data to PAGE_SIZE where the existing alignment is THREAD_SIZE. So using RW_DATA_SECTION would waste some space if using 64K pagesize.

I think that's ok, especially since we may get security patches in the future to create more restrictive page table attributes (well, with the drawback of more TLB pressure). So I'm for more cleanup in the vmlinux file by using the generic defines.

Signature · 1 line
Catalin
#7 lore raw

PATCH 1/1 arm64: use generic RW_DATA_SECTION macro in linker script

The .data section in the arm64 linker script currently lacks a definition for page-aligned data. This leads to a .page_aligned section being placed between the end of data and start of bss. This patch corrects that by using the generic RW_DATA_SECTION macro which includes support for page-aligned data.

---
 arch/arm64/kernel/vmlinux.lds.S | 31 +++++++------------------------
 1 file changed, 7 insertions(+), 24 deletions(-)
arch/arm64/kernel/vmlinux.lds.S +7 -24
index f8ab9d8..4ff9dcf 100644
@@ -97,30 +97,13 @@ SECTIONS
 	PERCPU_SECTION(64)
 
 	__init_end = .;
-	. = ALIGN(THREAD_SIZE);
-	__data_loc = .;
-
-	.data : AT(__data_loc) {
-		_data = .;		/* address in memory */
-		_sdata = .;
-
-		/*
-		 * first, the init task union, aligned
-		 * to an 8192 byte boundary.
-		 */
-		INIT_TASK_DATA(THREAD_SIZE)
-		NOSAVE_DATA
-		CACHELINE_ALIGNED_DATA(64)
-		READ_MOSTLY_DATA(64)
-
-		/*
-		 * and the usual data section
-		 */
-		DATA_DATA
-		CONSTRUCTORS
-
-		_edata = .;
-	}
+
+	. = ALIGN(PAGE_SIZE);
+	_data = .;
+	__data_loc = _data - LOAD_OFFSET;
+	_sdata = .;
+	RW_DATA_SECTION(64, PAGE_SIZE, THREAD_SIZE)
+	_edata = .;
 	_edata_loc = __data_loc + SIZEOF(.data);
 
 	BSS_SECTION(0, 0, 0)
Signature · 1 line
1.8.3.1
Acked-by on v1 1/1
#8 lore raw

Re: [PATCH] arm64: use generic RW_DATA_SECTION macro in linker script

Quoted 7 lines · Mark Salter

The .data section in the arm64 linker script currently lacks a definition for page-aligned data. This leads to a .page_aligned section being placed between the end of data and start of bss. This patch corrects that by using the generic RW_DATA_SECTION macro which includes support for page-aligned data.

Cheers Mark!

Will

maintainer
#9 lore raw

Re: [PATCH] arm64: use generic RW_DATA_SECTION macro in linker script

In reply to Mark Salter
Quoted 7 lines · Mark Salter

The .data section in the arm64 linker script currently lacks a definition for page-aligned data. This leads to a .page_aligned section being placed between the end of data and start of bss. This patch corrects that by using the generic RW_DATA_SECTION macro which includes support for page-aligned data.

Thanks. Applied.

Signature · 1 line
Catalin