Skip to content

Commit 7225a44

Browse files
committed
Merge branch 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86/pti fixes from Thomas Gleixner: "Three fixes related to melted spectrum: - Sync the cpu_entry_area page table to initial_page_table on 32 bit. Otherwise suspend/resume fails because resume uses initial_page_table and triggers a triple fault when accessing the cpu entry area. - Zero the SPEC_CTL MRS on XEN before suspend to address a shortcoming in the hypervisor. - Fix another switch table detection issue in objtool" * 'x86-pti-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/cpu_entry_area: Sync cpu_entry_area to initial_page_table objtool: Fix another switch table detection issue x86/xen: Zero MSR_IA32_SPEC_CTRL before suspend
2 parents 4c4ce30 + 945fd17 commit 7225a44

File tree

8 files changed

+53
-26
lines changed

8 files changed

+53
-26
lines changed

arch/x86/include/asm/pgtable_32.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ extern pmd_t initial_pg_pmd[];
3232
static inline void pgtable_cache_init(void) { }
3333
static inline void check_pgt_cache(void) { }
3434
void paging_init(void);
35+
void sync_initial_page_table(void);
3536

3637
/*
3738
* Define this if things work differently on an i386 and an i486:

arch/x86/include/asm/pgtable_64.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ extern pgd_t init_top_pgt[];
2828
#define swapper_pg_dir init_top_pgt
2929

3030
extern void paging_init(void);
31+
static inline void sync_initial_page_table(void) { }
3132

3233
#define pte_ERROR(e) \
3334
pr_err("%s:%d: bad pte %p(%016lx)\n", \

arch/x86/kernel/setup.c

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,20 +1204,13 @@ void __init setup_arch(char **cmdline_p)
12041204

12051205
kasan_init();
12061206

1207-
#ifdef CONFIG_X86_32
1208-
/* sync back kernel address range */
1209-
clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
1210-
swapper_pg_dir + KERNEL_PGD_BOUNDARY,
1211-
KERNEL_PGD_PTRS);
1212-
12131207
/*
1214-
* sync back low identity map too. It is used for example
1215-
* in the 32-bit EFI stub.
1208+
* Sync back kernel address range.
1209+
*
1210+
* FIXME: Can the later sync in setup_cpu_entry_areas() replace
1211+
* this call?
12161212
*/
1217-
clone_pgd_range(initial_page_table,
1218-
swapper_pg_dir + KERNEL_PGD_BOUNDARY,
1219-
min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
1220-
#endif
1213+
sync_initial_page_table();
12211214

12221215
tboot_probe();
12231216

arch/x86/kernel/setup_percpu.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,24 +287,15 @@ void __init setup_per_cpu_areas(void)
287287
/* Setup cpu initialized, callin, callout masks */
288288
setup_cpu_local_masks();
289289

290-
#ifdef CONFIG_X86_32
291290
/*
292291
* Sync back kernel address range again. We already did this in
293292
* setup_arch(), but percpu data also needs to be available in
294293
* the smpboot asm. We can't reliably pick up percpu mappings
295294
* using vmalloc_fault(), because exception dispatch needs
296295
* percpu data.
296+
*
297+
* FIXME: Can the later sync in setup_cpu_entry_areas() replace
298+
* this call?
297299
*/
298-
clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
299-
swapper_pg_dir + KERNEL_PGD_BOUNDARY,
300-
KERNEL_PGD_PTRS);
301-
302-
/*
303-
* sync back low identity map too. It is used for example
304-
* in the 32-bit EFI stub.
305-
*/
306-
clone_pgd_range(initial_page_table,
307-
swapper_pg_dir + KERNEL_PGD_BOUNDARY,
308-
min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
309-
#endif
300+
sync_initial_page_table();
310301
}

arch/x86/mm/cpu_entry_area.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,4 +163,10 @@ void __init setup_cpu_entry_areas(void)
163163

164164
for_each_possible_cpu(cpu)
165165
setup_cpu_entry_area(cpu);
166+
167+
/*
168+
* This is the last essential update to swapper_pgdir which needs
169+
* to be synchronized to initial_page_table on 32bit.
170+
*/
171+
sync_initial_page_table();
166172
}

arch/x86/mm/init_32.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,21 @@ static inline void permanent_kmaps_init(pgd_t *pgd_base)
453453
}
454454
#endif /* CONFIG_HIGHMEM */
455455

456+
void __init sync_initial_page_table(void)
457+
{
458+
clone_pgd_range(initial_page_table + KERNEL_PGD_BOUNDARY,
459+
swapper_pg_dir + KERNEL_PGD_BOUNDARY,
460+
KERNEL_PGD_PTRS);
461+
462+
/*
463+
* sync back low identity map too. It is used for example
464+
* in the 32-bit EFI stub.
465+
*/
466+
clone_pgd_range(initial_page_table,
467+
swapper_pg_dir + KERNEL_PGD_BOUNDARY,
468+
min(KERNEL_PGD_PTRS, KERNEL_PGD_BOUNDARY));
469+
}
470+
456471
void __init native_pagetable_init(void)
457472
{
458473
unsigned long pfn, va;

arch/x86/xen/suspend.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
// SPDX-License-Identifier: GPL-2.0
22
#include <linux/types.h>
33
#include <linux/tick.h>
4+
#include <linux/percpu-defs.h>
45

56
#include <xen/xen.h>
67
#include <xen/interface/xen.h>
78
#include <xen/grant_table.h>
89
#include <xen/events.h>
910

11+
#include <asm/cpufeatures.h>
12+
#include <asm/msr-index.h>
1013
#include <asm/xen/hypercall.h>
1114
#include <asm/xen/page.h>
1215
#include <asm/fixmap.h>
@@ -15,6 +18,8 @@
1518
#include "mmu.h"
1619
#include "pmu.h"
1720

21+
static DEFINE_PER_CPU(u64, spec_ctrl);
22+
1823
void xen_arch_pre_suspend(void)
1924
{
2025
xen_save_time_memory_area();
@@ -35,6 +40,9 @@ void xen_arch_post_suspend(int cancelled)
3540

3641
static void xen_vcpu_notify_restore(void *data)
3742
{
43+
if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL))
44+
wrmsrl(MSR_IA32_SPEC_CTRL, this_cpu_read(spec_ctrl));
45+
3846
/* Boot processor notified via generic timekeeping_resume() */
3947
if (smp_processor_id() == 0)
4048
return;
@@ -44,7 +52,15 @@ static void xen_vcpu_notify_restore(void *data)
4452

4553
static void xen_vcpu_notify_suspend(void *data)
4654
{
55+
u64 tmp;
56+
4757
tick_suspend_local();
58+
59+
if (xen_pv_domain() && boot_cpu_has(X86_FEATURE_SPEC_CTRL)) {
60+
rdmsrl(MSR_IA32_SPEC_CTRL, tmp);
61+
this_cpu_write(spec_ctrl, tmp);
62+
wrmsrl(MSR_IA32_SPEC_CTRL, 0);
63+
}
4864
}
4965

5066
void xen_arch_resume(void)

tools/objtool/check.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,11 @@ static struct rela *find_switch_table(struct objtool_file *file,
925925
if (find_symbol_containing(file->rodata, text_rela->addend))
926926
continue;
927927

928-
return find_rela_by_dest(file->rodata, text_rela->addend);
928+
rodata_rela = find_rela_by_dest(file->rodata, text_rela->addend);
929+
if (!rodata_rela)
930+
continue;
931+
932+
return rodata_rela;
929933
}
930934

931935
return NULL;

0 commit comments

Comments
 (0)