Skip to content

Commit ae1a411

Browse files
committed
Merge tag 'x86-boot-2020-06-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 boot updates from Ingo Molnar: "Misc updates: - Add the initrdmem= boot option to specify an initrd embedded in RAM (flash most likely) - Sanitize the CS value earlier during boot, which also fixes SEV-ES - Various fixes and smaller cleanups" * tag 'x86-boot-2020-06-01' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/boot: Correct relocation destination on old linkers x86/boot/compressed/64: Switch to __KERNEL_CS after GDT is loaded x86/boot: Fix -Wint-to-pointer-cast build warning x86/boot: Add kstrtoul() from lib/ x86/tboot: Mark tboot static x86/setup: Add an initrdmem= option to specify initrd physical address
2 parents d861f6e + 5214028 commit ae1a411

File tree

10 files changed

+90
-17
lines changed

10 files changed

+90
-17
lines changed

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,13 @@
17481748

17491749
initrd= [BOOT] Specify the location of the initial ramdisk
17501750

1751+
initrdmem= [KNL] Specify a physical address and size from which to
1752+
load the initrd. If an initrd is compiled in or
1753+
specified in the bootparams, it takes priority over this
1754+
setting.
1755+
Format: ss[KMG],nn[KMG]
1756+
Default is 0, 0
1757+
17511758
init_on_alloc= [MM] Fill newly allocated pages and heap objects with
17521759
zeroes.
17531760
Format: 0 | 1

arch/x86/boot/compressed/acpi.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ acpi_physical_address get_rsdp_addr(void)
280280
*/
281281
#define MAX_ADDR_LEN 19
282282

283-
static acpi_physical_address get_cmdline_acpi_rsdp(void)
283+
static unsigned long get_cmdline_acpi_rsdp(void)
284284
{
285-
acpi_physical_address addr = 0;
285+
unsigned long addr = 0;
286286

287287
#ifdef CONFIG_KEXEC
288288
char val[MAX_ADDR_LEN] = { };
@@ -292,7 +292,7 @@ static acpi_physical_address get_cmdline_acpi_rsdp(void)
292292
if (ret < 0)
293293
return 0;
294294

295-
if (kstrtoull(val, 16, &addr))
295+
if (boot_kstrtoul(val, 16, &addr))
296296
return 0;
297297
#endif
298298
return addr;
@@ -314,7 +314,6 @@ static unsigned long get_acpi_srat_table(void)
314314
* different ideas about whether to trust a command-line parameter.
315315
*/
316316
rsdp = (struct acpi_table_rsdp *)get_cmdline_acpi_rsdp();
317-
318317
if (!rsdp)
319318
rsdp = (struct acpi_table_rsdp *)(long)
320319
boot_params->acpi_rsdp_addr;

arch/x86/boot/compressed/head_32.S

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@
4949
* Position Independent Executable (PIE) so that linker won't optimize
5050
* R_386_GOT32X relocation to its fixed symbol address. Older
5151
* linkers generate R_386_32 relocations against locally defined symbols,
52-
* _bss, _ebss, _got and _egot, in PIE. It isn't wrong, just less
52+
* _bss, _ebss, _got, _egot and _end, in PIE. It isn't wrong, just less
5353
* optimal than R_386_RELATIVE. But the x86 kernel fails to properly handle
5454
* R_386_32 relocations when relocating the kernel. To generate
55-
* R_386_RELATIVE relocations, we mark _bss, _ebss, _got and _egot as
55+
* R_386_RELATIVE relocations, we mark _bss, _ebss, _got, _egot and _end as
5656
* hidden:
5757
*/
5858
.hidden _bss
5959
.hidden _ebss
6060
.hidden _got
6161
.hidden _egot
62+
.hidden _end
6263

6364
__HEAD
6465
SYM_FUNC_START(startup_32)

arch/x86/boot/compressed/head_64.S

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
.hidden _ebss
4343
.hidden _got
4444
.hidden _egot
45+
.hidden _end
4546

4647
__HEAD
4748
.code32
@@ -393,6 +394,14 @@ SYM_CODE_START(startup_64)
393394
addq %rax, 2(%rax)
394395
lgdt (%rax)
395396

397+
/* Reload CS so IRET returns to a CS actually in the GDT */
398+
pushq $__KERNEL_CS
399+
leaq .Lon_kernel_cs(%rip), %rax
400+
pushq %rax
401+
lretq
402+
403+
.Lon_kernel_cs:
404+
396405
/*
397406
* paging_prepare() sets up the trampoline and checks if we need to
398407
* enable 5-level paging.

arch/x86/boot/string.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,6 @@ static unsigned int simple_guess_base(const char *cp)
117117
* @endp: A pointer to the end of the parsed string will be placed here
118118
* @base: The number base to use
119119
*/
120-
121120
unsigned long long simple_strtoull(const char *cp, char **endp, unsigned int base)
122121
{
123122
unsigned long long result = 0;
@@ -335,3 +334,45 @@ int kstrtoull(const char *s, unsigned int base, unsigned long long *res)
335334
s++;
336335
return _kstrtoull(s, base, res);
337336
}
337+
338+
static int _kstrtoul(const char *s, unsigned int base, unsigned long *res)
339+
{
340+
unsigned long long tmp;
341+
int rv;
342+
343+
rv = kstrtoull(s, base, &tmp);
344+
if (rv < 0)
345+
return rv;
346+
if (tmp != (unsigned long)tmp)
347+
return -ERANGE;
348+
*res = tmp;
349+
return 0;
350+
}
351+
352+
/**
353+
* kstrtoul - convert a string to an unsigned long
354+
* @s: The start of the string. The string must be null-terminated, and may also
355+
* include a single newline before its terminating null. The first character
356+
* may also be a plus sign, but not a minus sign.
357+
* @base: The number base to use. The maximum supported base is 16. If base is
358+
* given as 0, then the base of the string is automatically detected with the
359+
* conventional semantics - If it begins with 0x the number will be parsed as a
360+
* hexadecimal (case insensitive), if it otherwise begins with 0, it will be
361+
* parsed as an octal number. Otherwise it will be parsed as a decimal.
362+
* @res: Where to write the result of the conversion on success.
363+
*
364+
* Returns 0 on success, -ERANGE on overflow and -EINVAL on parsing error.
365+
* Used as a replacement for the simple_strtoull.
366+
*/
367+
int boot_kstrtoul(const char *s, unsigned int base, unsigned long *res)
368+
{
369+
/*
370+
* We want to shortcut function call, but
371+
* __builtin_types_compatible_p(unsigned long, unsigned long long) = 0.
372+
*/
373+
if (sizeof(unsigned long) == sizeof(unsigned long long) &&
374+
__alignof__(unsigned long) == __alignof__(unsigned long long))
375+
return kstrtoull(s, base, (unsigned long long *)res);
376+
else
377+
return _kstrtoul(s, base, res);
378+
}

arch/x86/boot/string.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,5 @@ extern unsigned long long simple_strtoull(const char *cp, char **endp,
3030
unsigned int base);
3131

3232
int kstrtoull(const char *s, unsigned int base, unsigned long long *res);
33+
int boot_kstrtoul(const char *s, unsigned int base, unsigned long *res);
3334
#endif /* BOOT_STRING_H */

arch/x86/kernel/setup.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ static u64 __init get_ramdisk_image(void)
237237

238238
ramdisk_image |= (u64)boot_params.ext_ramdisk_image << 32;
239239

240+
if (ramdisk_image == 0)
241+
ramdisk_image = phys_initrd_start;
242+
240243
return ramdisk_image;
241244
}
242245
static u64 __init get_ramdisk_size(void)
@@ -245,6 +248,9 @@ static u64 __init get_ramdisk_size(void)
245248

246249
ramdisk_size |= (u64)boot_params.ext_ramdisk_size << 32;
247250

251+
if (ramdisk_size == 0)
252+
ramdisk_size = phys_initrd_size;
253+
248254
return ramdisk_size;
249255
}
250256

arch/x86/kernel/tboot.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
#include "../realmode/rm/wakeup.h"
3636

3737
/* Global pointer to shared data; NULL means no measured launch. */
38-
struct tboot *tboot __read_mostly;
39-
EXPORT_SYMBOL(tboot);
38+
static struct tboot *tboot __read_mostly;
4039

4140
/* timeout for APs (in secs) to enter wait-for-SIPI state during shutdown */
4241
#define AP_WAIT_TIMEOUT 1
@@ -46,6 +45,11 @@ EXPORT_SYMBOL(tboot);
4645

4746
static u8 tboot_uuid[16] __initdata = TBOOT_UUID;
4847

48+
bool tboot_enabled(void)
49+
{
50+
return tboot != NULL;
51+
}
52+
4953
void __init tboot_probe(void)
5054
{
5155
/* Look for valid page-aligned address for shared page. */

include/linux/tboot.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,7 @@ struct tboot {
121121
#define TBOOT_UUID {0xff, 0x8d, 0x3c, 0x66, 0xb3, 0xe8, 0x82, 0x4b, 0xbf,\
122122
0xaa, 0x19, 0xea, 0x4d, 0x5, 0x7a, 0x8}
123123

124-
extern struct tboot *tboot;
125-
126-
static inline int tboot_enabled(void)
127-
{
128-
return tboot != NULL;
129-
}
130-
124+
bool tboot_enabled(void);
131125
extern void tboot_probe(void);
132126
extern void tboot_shutdown(u32 shutdown_type);
133127
extern struct acpi_table_header *tboot_get_dmar_table(

init/do_mounts_initrd.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ static int __init no_initrd(char *str)
2828

2929
__setup("noinitrd", no_initrd);
3030

31-
static int __init early_initrd(char *p)
31+
static int __init early_initrdmem(char *p)
3232
{
3333
phys_addr_t start;
3434
unsigned long size;
@@ -43,6 +43,17 @@ static int __init early_initrd(char *p)
4343
}
4444
return 0;
4545
}
46+
early_param("initrdmem", early_initrdmem);
47+
48+
/*
49+
* This is here as the initrd keyword has been in use since 11/2018
50+
* on ARM, PowerPC, and MIPS.
51+
* It should not be; it is reserved for bootloaders.
52+
*/
53+
static int __init early_initrd(char *p)
54+
{
55+
return early_initrdmem(p);
56+
}
4657
early_param("initrd", early_initrd);
4758

4859
static int init_linuxrc(struct subprocess_info *info, struct cred *new)

0 commit comments

Comments
 (0)