Skip to content

Commit e789286

Browse files
committed
Merge tag 'x86-urgent-2023-09-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Ingo Molnar: "Misc fixes: - Fix an UV boot crash - Skip spurious ENDBR generation on _THIS_IP_ - Fix ENDBR use in putuser() asm methods - Fix corner case boot crashes on 5-level paging - and fix a false positive WARNING on LTO kernels" * tag 'x86-urgent-2023-09-17' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/purgatory: Remove LTO flags x86/boot/compressed: Reserve more memory for page tables x86/ibt: Avoid duplicate ENDBR in __put_user_nocheck*() x86/ibt: Suppress spurious ENDBR x86/platform/uv: Use alternate source for socket to node data
2 parents e5a710d + 75b2f7e commit e789286

File tree

7 files changed

+61
-24
lines changed

7 files changed

+61
-24
lines changed

arch/x86/boot/compressed/ident_map_64.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ static void *alloc_pgt_page(void *context)
5959
return NULL;
6060
}
6161

62+
/* Consumed more tables than expected? */
63+
if (pages->pgt_buf_offset == BOOT_PGT_SIZE_WARN) {
64+
debug_putstr("pgt_buf running low in " __FILE__ "\n");
65+
debug_putstr("Need to raise BOOT_PGT_SIZE?\n");
66+
debug_putaddr(pages->pgt_buf_offset);
67+
debug_putaddr(pages->pgt_buf_size);
68+
}
69+
6270
entry = pages->pgt_buf + pages->pgt_buf_offset;
6371
pages->pgt_buf_offset += PAGE_SIZE;
6472

arch/x86/include/asm/boot.h

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,23 +40,40 @@
4040
#ifdef CONFIG_X86_64
4141
# define BOOT_STACK_SIZE 0x4000
4242

43+
/*
44+
* Used by decompressor's startup_32() to allocate page tables for identity
45+
* mapping of the 4G of RAM in 4-level paging mode:
46+
* - 1 level4 table;
47+
* - 1 level3 table;
48+
* - 4 level2 table that maps everything with 2M pages;
49+
*
50+
* The additional level5 table needed for 5-level paging is allocated from
51+
* trampoline_32bit memory.
52+
*/
4353
# define BOOT_INIT_PGT_SIZE (6*4096)
44-
# ifdef CONFIG_RANDOMIZE_BASE
54+
4555
/*
46-
* Assuming all cross the 512GB boundary:
47-
* 1 page for level4
48-
* (2+2)*4 pages for kernel, param, cmd_line, and randomized kernel
49-
* 2 pages for first 2M (video RAM: CONFIG_X86_VERBOSE_BOOTUP).
50-
* Total is 19 pages.
56+
* Total number of page tables kernel_add_identity_map() can allocate,
57+
* including page tables consumed by startup_32().
58+
*
59+
* Worst-case scenario:
60+
* - 5-level paging needs 1 level5 table;
61+
* - KASLR needs to map kernel, boot_params, cmdline and randomized kernel,
62+
* assuming all of them cross 256T boundary:
63+
* + 4*2 level4 table;
64+
* + 4*2 level3 table;
65+
* + 4*2 level2 table;
66+
* - X86_VERBOSE_BOOTUP needs to map the first 2M (video RAM):
67+
* + 1 level4 table;
68+
* + 1 level3 table;
69+
* + 1 level2 table;
70+
* Total: 28 tables
71+
*
72+
* Add 4 spare table in case decompressor touches anything beyond what is
73+
* accounted above. Warn if it happens.
5174
*/
52-
# ifdef CONFIG_X86_VERBOSE_BOOTUP
53-
# define BOOT_PGT_SIZE (19*4096)
54-
# else /* !CONFIG_X86_VERBOSE_BOOTUP */
55-
# define BOOT_PGT_SIZE (17*4096)
56-
# endif
57-
# else /* !CONFIG_RANDOMIZE_BASE */
58-
# define BOOT_PGT_SIZE BOOT_INIT_PGT_SIZE
59-
# endif
75+
# define BOOT_PGT_SIZE_WARN (28*4096)
76+
# define BOOT_PGT_SIZE (32*4096)
6077

6178
#else /* !CONFIG_X86_64 */
6279
# define BOOT_STACK_SIZE 0x1000

arch/x86/include/asm/linkage.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@
88
#undef notrace
99
#define notrace __attribute__((no_instrument_function))
1010

11+
#ifdef CONFIG_64BIT
12+
/*
13+
* The generic version tends to create spurious ENDBR instructions under
14+
* certain conditions.
15+
*/
16+
#define _THIS_IP_ ({ unsigned long __here; asm ("lea 0(%%rip), %0" : "=r" (__here)); __here; })
17+
#endif
18+
1119
#ifdef CONFIG_X86_32
1220
#define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
1321
#endif /* CONFIG_X86_32 */

arch/x86/kernel/apic/x2apic_uv_x.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1533,7 +1533,7 @@ static void __init build_socket_tables(void)
15331533
{
15341534
struct uv_gam_range_entry *gre = uv_gre_table;
15351535
int nums, numn, nump;
1536-
int cpu, i, lnid;
1536+
int i, lnid, apicid;
15371537
int minsock = _min_socket;
15381538
int maxsock = _max_socket;
15391539
int minpnode = _min_pnode;
@@ -1584,15 +1584,14 @@ static void __init build_socket_tables(void)
15841584

15851585
/* Set socket -> node values: */
15861586
lnid = NUMA_NO_NODE;
1587-
for_each_possible_cpu(cpu) {
1588-
int nid = cpu_to_node(cpu);
1589-
int apicid, sockid;
1587+
for (apicid = 0; apicid < ARRAY_SIZE(__apicid_to_node); apicid++) {
1588+
int nid = __apicid_to_node[apicid];
1589+
int sockid;
15901590

1591-
if (lnid == nid)
1591+
if ((nid == NUMA_NO_NODE) || (lnid == nid))
15921592
continue;
15931593
lnid = nid;
15941594

1595-
apicid = per_cpu(x86_cpu_to_apicid, cpu);
15961595
sockid = apicid >> uv_cpuid.socketid_shift;
15971596

15981597
if (_socket_to_node[sockid - minsock] == SOCK_EMPTY)

arch/x86/lib/putuser.S

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ SYM_FUNC_END(__put_user_1)
5656
EXPORT_SYMBOL(__put_user_1)
5757

5858
SYM_FUNC_START(__put_user_nocheck_1)
59-
ENDBR
6059
ASM_STAC
6160
2: movb %al,(%_ASM_CX)
6261
xor %ecx,%ecx
@@ -76,7 +75,6 @@ SYM_FUNC_END(__put_user_2)
7675
EXPORT_SYMBOL(__put_user_2)
7776

7877
SYM_FUNC_START(__put_user_nocheck_2)
79-
ENDBR
8078
ASM_STAC
8179
4: movw %ax,(%_ASM_CX)
8280
xor %ecx,%ecx
@@ -96,7 +94,6 @@ SYM_FUNC_END(__put_user_4)
9694
EXPORT_SYMBOL(__put_user_4)
9795

9896
SYM_FUNC_START(__put_user_nocheck_4)
99-
ENDBR
10097
ASM_STAC
10198
6: movl %eax,(%_ASM_CX)
10299
xor %ecx,%ecx
@@ -119,7 +116,6 @@ SYM_FUNC_END(__put_user_8)
119116
EXPORT_SYMBOL(__put_user_8)
120117

121118
SYM_FUNC_START(__put_user_nocheck_8)
122-
ENDBR
123119
ASM_STAC
124120
9: mov %_ASM_AX,(%_ASM_CX)
125121
#ifdef CONFIG_X86_32

arch/x86/purgatory/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ CFLAGS_sha256.o := -D__DISABLE_EXPORTS -D__NO_FORTIFY
1919
# optimization flags.
2020
KBUILD_CFLAGS := $(filter-out -fprofile-sample-use=% -fprofile-use=%,$(KBUILD_CFLAGS))
2121

22+
# When LTO is enabled, llvm emits many text sections, which is not supported
23+
# by kexec. Remove -flto=* flags.
24+
KBUILD_CFLAGS := $(filter-out $(CC_FLAGS_LTO),$(KBUILD_CFLAGS))
25+
2226
# When linking purgatory.ro with -r unresolved symbols are not checked,
2327
# also link a purgatory.chk binary without -r to check for unresolved symbols.
2428
PURGATORY_LDFLAGS := -e purgatory_start -z nodefaultlib

include/linux/instruction_pointer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
#ifndef _LINUX_INSTRUCTION_POINTER_H
33
#define _LINUX_INSTRUCTION_POINTER_H
44

5+
#include <asm/linkage.h>
6+
57
#define _RET_IP_ (unsigned long)__builtin_return_address(0)
8+
9+
#ifndef _THIS_IP_
610
#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
11+
#endif
712

813
#endif /* _LINUX_INSTRUCTION_POINTER_H */

0 commit comments

Comments
 (0)