Skip to content

Commit 2a8a2b7

Browse files
committed
Merge branch 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Thomas Gleixner: - Correct the L1TF fallout on 32bit and the off by one in the 'too much RAM for protection' calculation. - Add a helpful kernel message for the 'too much RAM' case - Unbreak the VDSO in case that the compiler desides to use indirect jumps/calls and emits retpolines which cannot be resolved because the kernel uses its own thunks, which does not work for the VDSO. Make it use the builtin thunks. - Re-export start_thread() which was unexported when the 32/64bit implementation was unified. start_thread() is required by modular binfmt handlers. - Trivial cleanups * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/speculation/l1tf: Suggest what to do on systems with too much RAM x86/speculation/l1tf: Fix off-by-one error when warning that system has too much RAM x86/kvm/vmx: Remove duplicate l1d flush definitions x86/speculation/l1tf: Fix overflow in l1tf_pfn_limit() on 32bit x86/process: Re-export start_thread() x86/mce: Add notifier_block forward declaration x86/vdso: Fix vDSO build if a retpoline is emitted
2 parents de37503 + 6a01228 commit 2a8a2b7

File tree

9 files changed

+19
-10
lines changed

9 files changed

+19
-10
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,9 +507,13 @@ KBUILD_AFLAGS += $(call cc-option, -no-integrated-as)
507507
endif
508508

509509
RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
510+
RETPOLINE_VDSO_CFLAGS_GCC := -mindirect-branch=thunk-inline -mindirect-branch-register
510511
RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
512+
RETPOLINE_VDSO_CFLAGS_CLANG := -mretpoline
511513
RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
514+
RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_VDSO_CFLAGS_CLANG)))
512515
export RETPOLINE_CFLAGS
516+
export RETPOLINE_VDSO_CFLAGS
513517

514518
KBUILD_CFLAGS += $(call cc-option,-fno-PIE)
515519
KBUILD_AFLAGS += $(call cc-option,-fno-PIE)

arch/x86/entry/vdso/Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ $(obj)/vdso-image-%.c: $(obj)/vdso%.so.dbg $(obj)/vdso%.so $(obj)/vdso2c FORCE
6868
CFL := $(PROFILING) -mcmodel=small -fPIC -O2 -fasynchronous-unwind-tables -m64 \
6969
$(filter -g%,$(KBUILD_CFLAGS)) $(call cc-option, -fno-stack-protector) \
7070
-fno-omit-frame-pointer -foptimize-sibling-calls \
71-
-DDISABLE_BRANCH_PROFILING -DBUILD_VDSO
71+
-DDISABLE_BRANCH_PROFILING -DBUILD_VDSO $(RETPOLINE_VDSO_CFLAGS)
7272

73-
$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
73+
$(vobjs): KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS) $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS)) $(CFL)
7474

7575
#
7676
# vDSO code runs in userspace and -pg doesn't help with profiling anyway.
@@ -132,11 +132,13 @@ KBUILD_CFLAGS_32 := $(filter-out -mcmodel=kernel,$(KBUILD_CFLAGS_32))
132132
KBUILD_CFLAGS_32 := $(filter-out -fno-pic,$(KBUILD_CFLAGS_32))
133133
KBUILD_CFLAGS_32 := $(filter-out -mfentry,$(KBUILD_CFLAGS_32))
134134
KBUILD_CFLAGS_32 := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS_32))
135+
KBUILD_CFLAGS_32 := $(filter-out $(RETPOLINE_CFLAGS),$(KBUILD_CFLAGS_32))
135136
KBUILD_CFLAGS_32 += -m32 -msoft-float -mregparm=0 -fpic
136137
KBUILD_CFLAGS_32 += $(call cc-option, -fno-stack-protector)
137138
KBUILD_CFLAGS_32 += $(call cc-option, -foptimize-sibling-calls)
138139
KBUILD_CFLAGS_32 += -fno-omit-frame-pointer
139140
KBUILD_CFLAGS_32 += -DDISABLE_BRANCH_PROFILING
141+
KBUILD_CFLAGS_32 += $(RETPOLINE_VDSO_CFLAGS)
140142
$(obj)/vdso32.so.dbg: KBUILD_CFLAGS = $(KBUILD_CFLAGS_32)
141143

142144
$(obj)/vdso32.so.dbg: FORCE \

arch/x86/include/asm/mce.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ enum mce_notifier_prios {
148148
MCE_PRIO_LOWEST = 0,
149149
};
150150

151+
struct notifier_block;
151152
extern void mce_register_decode_chain(struct notifier_block *nb);
152153
extern void mce_unregister_decode_chain(struct notifier_block *nb);
153154

arch/x86/include/asm/processor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ extern const struct seq_operations cpuinfo_op;
181181

182182
extern void cpu_detect(struct cpuinfo_x86 *c);
183183

184-
static inline unsigned long l1tf_pfn_limit(void)
184+
static inline unsigned long long l1tf_pfn_limit(void)
185185
{
186-
return BIT(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT) - 1;
186+
return BIT_ULL(boot_cpu_data.x86_phys_bits - 1 - PAGE_SHIFT);
187187
}
188188

189189
extern void early_cpu_init(void);

arch/x86/kernel/cpu/bugs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,10 @@ static void __init l1tf_select_mitigation(void)
702702
half_pa = (u64)l1tf_pfn_limit() << PAGE_SHIFT;
703703
if (e820__mapped_any(half_pa, ULLONG_MAX - half_pa, E820_TYPE_RAM)) {
704704
pr_warn("System has more than MAX_PA/2 memory. L1TF mitigation not effective.\n");
705+
pr_info("You may make it effective by booting the kernel with mem=%llu parameter.\n",
706+
half_pa);
707+
pr_info("However, doing so will make a part of your RAM unusable.\n");
708+
pr_info("Reading https://www.kernel.org/doc/html/latest/admin-guide/l1tf.html might help you decide.\n");
705709
return;
706710
}
707711

arch/x86/kernel/process_64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,7 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp)
384384
start_thread_common(regs, new_ip, new_sp,
385385
__USER_CS, __USER_DS, 0);
386386
}
387+
EXPORT_SYMBOL_GPL(start_thread);
387388

388389
#ifdef CONFIG_COMPAT
389390
void compat_start_thread(struct pt_regs *regs, u32 new_ip, u32 new_sp)

arch/x86/kvm/vmx.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10131,9 +10131,6 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
1013110131
* information but as all relevant affected CPUs have 32KiB L1D cache size
1013210132
* there is no point in doing so.
1013310133
*/
10134-
#define L1D_CACHE_ORDER 4
10135-
static void *vmx_l1d_flush_pages;
10136-
1013710134
static void vmx_l1d_flush(struct kvm_vcpu *vcpu)
1013810135
{
1013910136
int size = PAGE_SIZE << L1D_CACHE_ORDER;

arch/x86/mm/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -930,15 +930,15 @@ unsigned long max_swapfile_size(void)
930930

931931
if (boot_cpu_has_bug(X86_BUG_L1TF)) {
932932
/* Limit the swap file size to MAX_PA/2 for L1TF workaround */
933-
unsigned long l1tf_limit = l1tf_pfn_limit() + 1;
933+
unsigned long long l1tf_limit = l1tf_pfn_limit();
934934
/*
935935
* We encode swap offsets also with 3 bits below those for pfn
936936
* which makes the usable limit higher.
937937
*/
938938
#if CONFIG_PGTABLE_LEVELS > 2
939939
l1tf_limit <<= PAGE_SHIFT - SWP_OFFSET_FIRST_BIT;
940940
#endif
941-
pages = min_t(unsigned long, l1tf_limit, pages);
941+
pages = min_t(unsigned long long, l1tf_limit, pages);
942942
}
943943
return pages;
944944
}

arch/x86/mm/mmap.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ bool pfn_modify_allowed(unsigned long pfn, pgprot_t prot)
257257
/* If it's real memory always allow */
258258
if (pfn_valid(pfn))
259259
return true;
260-
if (pfn > l1tf_pfn_limit() && !capable(CAP_SYS_ADMIN))
260+
if (pfn >= l1tf_pfn_limit() && !capable(CAP_SYS_ADMIN))
261261
return false;
262262
return true;
263263
}

0 commit comments

Comments
 (0)