Skip to content

Commit 161bd3b

Browse files
committed
parisc: fix kernel memory layout in vmlinux.ld.S
When building a 64bit kernel sometimes functions in the .init section were not able to reach the standard kernel function. Main reason for this problem is, that the linkage tables (.plt, .opd, .dlt) tend to become pretty huge and thus the distance gets too big for short calls. One option to avoid this is to use the -mlong-calls compiler option, but this increases the binary size and introduces a performance penalty. Instead, with this patch we just lay out the binary differently. Init code is stored first, followed by text, R/O and finally R/W data. This means, that init and text code is now much closer to each other, which is sufficient to reach each other by short calls. Signed-off-by: Helge Deller <deller@gmx.de>
1 parent c790b41 commit 161bd3b

3 files changed

Lines changed: 78 additions & 85 deletions

File tree

‎arch/parisc/kernel/head.S‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ END(boot_args)
4141
.import fault_vector_11,code /* IVA parisc 1.1 32 bit */
4242
.import $global$ /* forward declaration */
4343
#endif /*!CONFIG_64BIT*/
44-
.export _stext,data /* Kernel want it this way! */
45-
_stext:
46-
ENTRY(stext)
44+
ENTRY(parisc_kernel_start)
4745
.proc
4846
.callinfo
4947

@@ -347,7 +345,7 @@ smp_slave_stext:
347345
.procend
348346
#endif /* CONFIG_SMP */
349347

350-
ENDPROC(stext)
348+
ENDPROC(parisc_kernel_start)
351349

352350
#ifndef CONFIG_64BIT
353351
.section .data..read_mostly

‎arch/parisc/kernel/vmlinux.lds.S‎

Lines changed: 60 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,19 @@
66
* Copyright (C) 2000 Michael Ang <mang with subcarrier.org>
77
* Copyright (C) 2002 Randolph Chung <tausq with parisc-linux.org>
88
* Copyright (C) 2003 James Bottomley <jejb with parisc-linux.org>
9-
* Copyright (C) 2006 Helge Deller <deller@gmx.de>
10-
*
11-
*
12-
* This program is free software; you can redistribute it and/or modify
13-
* it under the terms of the GNU General Public License as published by
14-
* the Free Software Foundation; either version 2 of the License, or
15-
* (at your option) any later version.
16-
*
17-
* This program is distributed in the hope that it will be useful,
18-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20-
* GNU General Public License for more details.
21-
*
22-
* You should have received a copy of the GNU General Public License
23-
* along with this program; if not, write to the Free Software
24-
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9+
* Copyright (C) 2006-2013 Helge Deller <deller@gmx.de>
10+
*/
11+
12+
/*
13+
* Put page table entries (swapper_pg_dir) as the first thing in .bss. This
14+
* will ensure that it has .bss alignment (PAGE_SIZE).
2515
*/
16+
#define BSS_FIRST_SECTIONS *(.data..vm0.pmd) \
17+
*(.data..vm0.pgd) \
18+
*(.data..vm0.pte)
19+
2620
#include <asm-generic/vmlinux.lds.h>
21+
2722
/* needed for the processor specific cache alignment size */
2823
#include <asm/cache.h>
2924
#include <asm/page.h>
@@ -39,7 +34,7 @@ OUTPUT_FORMAT("elf64-hppa-linux")
3934
OUTPUT_ARCH(hppa:hppa2.0w)
4035
#endif
4136

42-
ENTRY(_stext)
37+
ENTRY(parisc_kernel_start)
4338
#ifndef CONFIG_64BIT
4439
jiffies = jiffies_64 + 4;
4540
#else
@@ -49,11 +44,29 @@ SECTIONS
4944
{
5045
. = KERNEL_BINARY_TEXT_START;
5146

47+
__init_begin = .;
48+
HEAD_TEXT_SECTION
49+
INIT_TEXT_SECTION(8)
50+
51+
. = ALIGN(PAGE_SIZE);
52+
INIT_DATA_SECTION(PAGE_SIZE)
53+
/* we have to discard exit text and such at runtime, not link time */
54+
.exit.text :
55+
{
56+
EXIT_TEXT
57+
}
58+
.exit.data :
59+
{
60+
EXIT_DATA
61+
}
62+
PERCPU_SECTION(8)
63+
. = ALIGN(PAGE_SIZE);
64+
__init_end = .;
65+
/* freed after init ends here */
66+
5267
_text = .; /* Text and read-only data */
53-
.head ALIGN(16) : {
54-
HEAD_TEXT
55-
} = 0
56-
.text ALIGN(16) : {
68+
_stext = .;
69+
.text ALIGN(PAGE_SIZE) : {
5770
TEXT_TEXT
5871
SCHED_TEXT
5972
LOCK_TEXT
@@ -68,21 +81,28 @@ SECTIONS
6881
*(.lock.text) /* out-of-line lock text */
6982
*(.gnu.warning)
7083
}
71-
/* End of text section */
84+
. = ALIGN(PAGE_SIZE);
7285
_etext = .;
86+
/* End of text section */
7387

7488
/* Start of data section */
7589
_sdata = .;
7690

77-
RODATA
91+
RO_DATA_SECTION(8)
7892

79-
/* writeable */
80-
/* Make sure this is page aligned so
81-
* that we can properly leave these
82-
* as writable
83-
*/
84-
. = ALIGN(PAGE_SIZE);
85-
data_start = .;
93+
#ifdef CONFIG_64BIT
94+
. = ALIGN(16);
95+
/* Linkage tables */
96+
.opd : {
97+
*(.opd)
98+
} PROVIDE (__gp = .);
99+
.plt : {
100+
*(.plt)
101+
}
102+
.dlt : {
103+
*(.dlt)
104+
}
105+
#endif
86106

87107
/* unwind info */
88108
.PARISC.unwind : {
@@ -91,7 +111,15 @@ SECTIONS
91111
__stop___unwind = .;
92112
}
93113

94-
EXCEPTION_TABLE(16)
114+
/* writeable */
115+
/* Make sure this is page aligned so
116+
* that we can properly leave these
117+
* as writable
118+
*/
119+
. = ALIGN(PAGE_SIZE);
120+
data_start = .;
121+
122+
EXCEPTION_TABLE(8)
95123
NOTES
96124

97125
/* Data */
@@ -107,54 +135,8 @@ SECTIONS
107135
_edata = .;
108136

109137
/* BSS */
110-
__bss_start = .;
111-
/* page table entries need to be PAGE_SIZE aligned */
112-
. = ALIGN(PAGE_SIZE);
113-
.data..vmpages : {
114-
*(.data..vm0.pmd)
115-
*(.data..vm0.pgd)
116-
*(.data..vm0.pte)
117-
}
118-
.bss : {
119-
*(.bss)
120-
*(COMMON)
121-
}
122-
__bss_stop = .;
123-
124-
#ifdef CONFIG_64BIT
125-
. = ALIGN(16);
126-
/* Linkage tables */
127-
.opd : {
128-
*(.opd)
129-
} PROVIDE (__gp = .);
130-
.plt : {
131-
*(.plt)
132-
}
133-
.dlt : {
134-
*(.dlt)
135-
}
136-
#endif
138+
BSS_SECTION(PAGE_SIZE, PAGE_SIZE, 8)
137139

138-
/* reserve space for interrupt stack by aligning __init* to 16k */
139-
. = ALIGN(16384);
140-
__init_begin = .;
141-
INIT_TEXT_SECTION(16384)
142-
. = ALIGN(PAGE_SIZE);
143-
INIT_DATA_SECTION(16)
144-
/* we have to discard exit text and such at runtime, not link time */
145-
.exit.text :
146-
{
147-
EXIT_TEXT
148-
}
149-
.exit.data :
150-
{
151-
EXIT_DATA
152-
}
153-
154-
PERCPU_SECTION(L1_CACHE_BYTES)
155-
. = ALIGN(PAGE_SIZE);
156-
__init_end = .;
157-
/* freed after init ends here */
158140
_end = . ;
159141

160142
STABS_DEBUG

‎arch/parisc/mm/init.c‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <asm/sections.h>
3333

3434
extern int data_start;
35+
extern void parisc_kernel_start(void); /* Kernel entry point in head.S */
3536

3637
#if PT_NLEVELS == 3
3738
/* NOTE: This layout exactly conforms to the hybrid L2/L3 page table layout
@@ -324,8 +325,9 @@ static void __init setup_bootmem(void)
324325
reserve_bootmem_node(NODE_DATA(0), 0UL,
325326
(unsigned long)(PAGE0->mem_free +
326327
PDC_CONSOLE_IO_IODC_SIZE), BOOTMEM_DEFAULT);
327-
reserve_bootmem_node(NODE_DATA(0), __pa((unsigned long)_text),
328-
(unsigned long)(_end - _text), BOOTMEM_DEFAULT);
328+
reserve_bootmem_node(NODE_DATA(0), __pa(KERNEL_BINARY_TEXT_START),
329+
(unsigned long)(_end - KERNEL_BINARY_TEXT_START),
330+
BOOTMEM_DEFAULT);
329331
reserve_bootmem_node(NODE_DATA(0), (bootmap_start_pfn << PAGE_SHIFT),
330332
((bootmap_pfn - bootmap_start_pfn) << PAGE_SHIFT),
331333
BOOTMEM_DEFAULT);
@@ -378,6 +380,17 @@ static void __init setup_bootmem(void)
378380
request_resource(&sysram_resources[0], &pdcdata_resource);
379381
}
380382

383+
static int __init parisc_text_address(unsigned long vaddr)
384+
{
385+
static unsigned long head_ptr __initdata;
386+
387+
if (!head_ptr)
388+
head_ptr = PAGE_MASK & (unsigned long)
389+
dereference_function_descriptor(&parisc_kernel_start);
390+
391+
return core_kernel_text(vaddr) || vaddr == head_ptr;
392+
}
393+
381394
static void __init map_pages(unsigned long start_vaddr,
382395
unsigned long start_paddr, unsigned long size,
383396
pgprot_t pgprot, int force)
@@ -466,7 +479,7 @@ static void __init map_pages(unsigned long start_vaddr,
466479
*/
467480
if (force)
468481
pte = __mk_pte(address, pgprot);
469-
else if (core_kernel_text(vaddr) &&
482+
else if (parisc_text_address(vaddr) &&
470483
address != fv_addr)
471484
pte = __mk_pte(address, PAGE_KERNEL_EXEC);
472485
else

0 commit comments

Comments
 (0)