Skip to content

Commit 15426ca

Browse files
Vasily GorbikMartin Schwidefsky
authored andcommitted
s390: rescue initrd as early as possible
To avoid multi-stage initrd rescue operation and to simplify assumptions during early memory allocations move initrd at some final safe destination as early as possible. This would also allow us to drop .bss usage restrictions for some files. Reviewed-by: Martin Schwidefsky <schwidefsky@de.ibm.com> Signed-off-by: Vasily Gorbik <gor@linux.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
1 parent 3b076dc commit 15426ca

5 files changed

Lines changed: 40 additions & 38 deletions

File tree

‎arch/s390/boot/compressed/decompressor.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ static inline void *decompress_kernel(void) {}
77
#else
88
void *decompress_kernel(void);
99
#endif
10+
unsigned long mem_safe_offset(void);
1011

1112
struct vmlinux_info {
1213
unsigned long default_lma;
1314
void (*entry)(void);
1415
unsigned long image_size; /* does not include .bss */
16+
unsigned long bss_size; /* uncompressed image .bss size */
1517
};
1618

1719
extern char _vmlinux_info[];

‎arch/s390/boot/compressed/misc.c‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,22 @@ static void error(char *x)
8383
asm volatile("lpsw %0" : : "Q" (psw));
8484
}
8585

86-
void *decompress_kernel(void)
87-
{
88-
void *output, *kernel_end;
89-
90-
output = (void *) ALIGN((unsigned long) _end + HEAP_SIZE, PAGE_SIZE);
91-
kernel_end = output + vmlinux.image_size;
86+
#define decompress_offset ALIGN((unsigned long)_end + HEAP_SIZE, PAGE_SIZE)
9287

93-
#ifdef CONFIG_BLK_DEV_INITRD
88+
unsigned long mem_safe_offset(void)
89+
{
9490
/*
95-
* Move the initrd right behind the end of the decompressed
96-
* kernel image. This also prevents initrd corruption caused by
97-
* bss clearing since kernel_end will always be located behind the
98-
* current bss section..
91+
* due to 4MB HEAD_SIZE for bzip2
92+
* 'decompress_offset + vmlinux.image_size' could be larger than
93+
* kernel at final position + its .bss, so take the larger of two
9994
*/
100-
if (INITRD_START && INITRD_SIZE && kernel_end > (void *) INITRD_START) {
101-
memmove(kernel_end, (void *) INITRD_START, INITRD_SIZE);
102-
INITRD_START = (unsigned long) kernel_end;
103-
}
104-
#endif
95+
return max(decompress_offset + vmlinux.image_size,
96+
vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size);
97+
}
98+
99+
void *decompress_kernel(void)
100+
{
101+
void *output = (void *)decompress_offset;
105102

106103
__decompress(_compressed_start, _compressed_end - _compressed_start,
107104
NULL, NULL, output, 0, NULL, error);

‎arch/s390/boot/startup.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <linux/string.h>
3+
#include <asm/setup.h>
34
#include "compressed/decompressor.h"
45
#include "boot.h"
56

7+
#ifdef CONFIG_KERNEL_UNCOMPRESSED
8+
unsigned long mem_safe_offset(void)
9+
{
10+
return vmlinux.default_lma + vmlinux.image_size + vmlinux.bss_size;
11+
}
12+
#endif
13+
14+
static void rescue_initrd(void)
15+
{
16+
unsigned long min_initrd_addr;
17+
18+
if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD))
19+
return;
20+
if (!INITRD_START || !INITRD_SIZE)
21+
return;
22+
min_initrd_addr = mem_safe_offset();
23+
if (min_initrd_addr <= INITRD_START)
24+
return;
25+
memmove((void *)min_initrd_addr, (void *)INITRD_START, INITRD_SIZE);
26+
INITRD_START = min_initrd_addr;
27+
}
28+
629
void startup_kernel(void)
730
{
831
void *img;
932

33+
rescue_initrd();
1034
if (!IS_ENABLED(CONFIG_KERNEL_UNCOMPRESSED)) {
1135
img = decompress_kernel();
1236
memmove((void *)vmlinux.default_lma, img, vmlinux.image_size);

‎arch/s390/kernel/early_nobss.c‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <linux/string.h>
1414
#include <asm/sections.h>
1515
#include <asm/lowcore.h>
16-
#include <asm/setup.h>
1716
#include <asm/timex.h>
1817
#include "entry.h"
1918

@@ -32,26 +31,6 @@ static void __init reset_tod_clock(void)
3231
S390_lowcore.last_update_clock = TOD_UNIX_EPOCH;
3332
}
3433

35-
static void __init rescue_initrd(void)
36-
{
37-
unsigned long min_initrd_addr = (unsigned long) _end + (4UL << 20);
38-
39-
/*
40-
* Just like in case of IPL from VM reader we make sure there is a
41-
* gap of 4MB between end of kernel and start of initrd.
42-
* That way we can also be sure that saving an NSS will succeed,
43-
* which however only requires different segments.
44-
*/
45-
if (!IS_ENABLED(CONFIG_BLK_DEV_INITRD))
46-
return;
47-
if (!INITRD_START || !INITRD_SIZE)
48-
return;
49-
if (INITRD_START >= min_initrd_addr)
50-
return;
51-
memmove((void *) min_initrd_addr, (void *) INITRD_START, INITRD_SIZE);
52-
INITRD_START = min_initrd_addr;
53-
}
54-
5534
static void __init clear_bss_section(void)
5635
{
5736
memset(__bss_start, 0, __bss_stop - __bss_start);
@@ -60,6 +39,5 @@ static void __init clear_bss_section(void)
6039
void __init startup_init_nobss(void)
6140
{
6241
reset_tod_clock();
63-
rescue_initrd();
6442
clear_bss_section();
6543
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ SECTIONS
154154
QUAD(_stext) /* default_lma */
155155
QUAD(startup_continue) /* entry */
156156
QUAD(__bss_start - _stext) /* image_size */
157+
QUAD(__bss_stop - __bss_start) /* bss_size */
157158
}
158159

159160
/* Debugging sections. */

0 commit comments

Comments
 (0)