Skip to content

Commit 8eab6cd

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 Peter Anvin: "This is a collection of minor fixes for x86, plus the IRET information leak fix (forbid the use of 16-bit segments in 64-bit mode)" NOTE! We may have to relax the "forbid the use of 16-bit segments in 64-bit mode" part, since there may be people who still run and depend on 16-bit Windows binaries under Wine. But I'm taking this in the current unconditional form for now to see who (if anybody) screams bloody murder. Maybe nobody cares. And maybe we'll have to update it with some kind of runtime enablement (like our vm.mmap_min_addr tunable that people who run dosemu/qemu/wine already need to tweak). * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86-64, modify_ldt: Ban 16-bit segments on 64-bit kernels efi: Pass correct file handle to efi_file_{read,close} x86/efi: Correct EFI boot stub use of code32_start x86/efi: Fix boot failure with EFI stub x86/platform/hyperv: Handle VMBUS driver being a module x86/apic: Reinstate error IRQ Pentium erratum 3AP workaround x86, CMCI: Add proper detection of end of CMCI storms
2 parents ede1d63 + b3b42ac commit 8eab6cd

9 files changed

Lines changed: 67 additions & 28 deletions

File tree

‎arch/x86/boot/compressed/eboot.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ __file_size64(void *__fh, efi_char16_t *filename_16,
112112
efi_file_info_t *info;
113113
efi_status_t status;
114114
efi_guid_t info_guid = EFI_FILE_INFO_ID;
115-
u32 info_sz;
115+
u64 info_sz;
116116

117117
status = efi_early->call((unsigned long)fh->open, fh, &h, filename_16,
118118
EFI_FILE_MODE_READ, (u64)0);
@@ -167,31 +167,31 @@ efi_file_size(efi_system_table_t *sys_table, void *__fh,
167167
}
168168

169169
static inline efi_status_t
170-
efi_file_read(void *__fh, void *handle, unsigned long *size, void *addr)
170+
efi_file_read(void *handle, unsigned long *size, void *addr)
171171
{
172172
unsigned long func;
173173

174174
if (efi_early->is64) {
175-
efi_file_handle_64_t *fh = __fh;
175+
efi_file_handle_64_t *fh = handle;
176176

177177
func = (unsigned long)fh->read;
178178
return efi_early->call(func, handle, size, addr);
179179
} else {
180-
efi_file_handle_32_t *fh = __fh;
180+
efi_file_handle_32_t *fh = handle;
181181

182182
func = (unsigned long)fh->read;
183183
return efi_early->call(func, handle, size, addr);
184184
}
185185
}
186186

187-
static inline efi_status_t efi_file_close(void *__fh, void *handle)
187+
static inline efi_status_t efi_file_close(void *handle)
188188
{
189189
if (efi_early->is64) {
190-
efi_file_handle_64_t *fh = __fh;
190+
efi_file_handle_64_t *fh = handle;
191191

192192
return efi_early->call((unsigned long)fh->close, handle);
193193
} else {
194-
efi_file_handle_32_t *fh = __fh;
194+
efi_file_handle_32_t *fh = handle;
195195

196196
return efi_early->call((unsigned long)fh->close, handle);
197197
}
@@ -1016,6 +1016,9 @@ void setup_graphics(struct boot_params *boot_params)
10161016
* Because the x86 boot code expects to be passed a boot_params we
10171017
* need to create one ourselves (usually the bootloader would create
10181018
* one for us).
1019+
*
1020+
* The caller is responsible for filling out ->code32_start in the
1021+
* returned boot_params.
10191022
*/
10201023
struct boot_params *make_boot_params(struct efi_config *c)
10211024
{
@@ -1081,8 +1084,6 @@ struct boot_params *make_boot_params(struct efi_config *c)
10811084
hdr->vid_mode = 0xffff;
10821085
hdr->boot_flag = 0xAA55;
10831086

1084-
hdr->code32_start = (__u64)(unsigned long)image->image_base;
1085-
10861087
hdr->type_of_loader = 0x21;
10871088

10881089
/* Convert unicode cmdline to ascii */

‎arch/x86/boot/compressed/head_32.S‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ ENTRY(efi_pe_entry)
5959
call make_boot_params
6060
cmpl $0, %eax
6161
je fail
62+
movl %esi, BP_code32_start(%eax)
6263
popl %ecx
6364
pushl %eax
6465
pushl %ecx
@@ -90,12 +91,7 @@ fail:
9091
hlt
9192
jmp fail
9293
2:
93-
call 3f
94-
3:
95-
popl %eax
96-
subl $3b, %eax
97-
subl BP_pref_address(%esi), %eax
98-
add BP_code32_start(%esi), %eax
94+
movl BP_code32_start(%esi), %eax
9995
leal preferred_addr(%eax), %eax
10096
jmp *%eax
10197

‎arch/x86/boot/compressed/head_64.S‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,8 @@ ENTRY(efi_pe_entry)
261261
cmpq $0,%rax
262262
je fail
263263
mov %rax, %rsi
264+
leaq startup_32(%rip), %rax
265+
movl %eax, BP_code32_start(%rsi)
264266
jmp 2f /* Skip the relocation */
265267

266268
handover_entry:
@@ -284,12 +286,7 @@ fail:
284286
hlt
285287
jmp fail
286288
2:
287-
call 3f
288-
3:
289-
popq %rax
290-
subq $3b, %rax
291-
subq BP_pref_address(%rsi), %rax
292-
add BP_code32_start(%esi), %eax
289+
movl BP_code32_start(%esi), %eax
293290
leaq preferred_addr(%rax), %rax
294291
jmp *%rax
295292

‎arch/x86/kernel/apic/apic.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,8 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19961996
};
19971997

19981998
/* First tickle the hardware, only then report what went on. -- REW */
1999-
apic_write(APIC_ESR, 0);
1999+
if (lapic_get_maxlvt() > 3) /* Due to the Pentium erratum 3AP. */
2000+
apic_write(APIC_ESR, 0);
20002001
v = apic_read(APIC_ESR);
20012002
ack_APIC_irq();
20022003
atomic_inc(&irq_err_count);

‎arch/x86/kernel/cpu/mcheck/mce.c‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ static DECLARE_WAIT_QUEUE_HEAD(mce_chrdev_wait);
8989
static DEFINE_PER_CPU(struct mce, mces_seen);
9090
static int cpu_missing;
9191

92+
/* CMCI storm detection filter */
93+
static DEFINE_PER_CPU(unsigned long, mce_polled_error);
94+
9295
/*
9396
* MCA banks polled by the period polling timer for corrected events.
9497
* With Intel CMCI, this only has MCA banks which do not support CMCI (if any).
@@ -595,6 +598,7 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
595598
{
596599
struct mce m;
597600
int i;
601+
unsigned long *v;
598602

599603
this_cpu_inc(mce_poll_count);
600604

@@ -614,6 +618,8 @@ void machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
614618
if (!(m.status & MCI_STATUS_VAL))
615619
continue;
616620

621+
v = &get_cpu_var(mce_polled_error);
622+
set_bit(0, v);
617623
/*
618624
* Uncorrected or signalled events are handled by the exception
619625
* handler when it is enabled, so don't process those here.
@@ -1278,10 +1284,18 @@ static unsigned long mce_adjust_timer_default(unsigned long interval)
12781284
static unsigned long (*mce_adjust_timer)(unsigned long interval) =
12791285
mce_adjust_timer_default;
12801286

1287+
static int cmc_error_seen(void)
1288+
{
1289+
unsigned long *v = &__get_cpu_var(mce_polled_error);
1290+
1291+
return test_and_clear_bit(0, v);
1292+
}
1293+
12811294
static void mce_timer_fn(unsigned long data)
12821295
{
12831296
struct timer_list *t = &__get_cpu_var(mce_timer);
12841297
unsigned long iv;
1298+
int notify;
12851299

12861300
WARN_ON(smp_processor_id() != data);
12871301

@@ -1296,7 +1310,9 @@ static void mce_timer_fn(unsigned long data)
12961310
* polling interval, otherwise increase the polling interval.
12971311
*/
12981312
iv = __this_cpu_read(mce_next_interval);
1299-
if (mce_notify_irq()) {
1313+
notify = mce_notify_irq();
1314+
notify |= cmc_error_seen();
1315+
if (notify) {
13001316
iv = max(iv / 2, (unsigned long) HZ/100);
13011317
} else {
13021318
iv = min(iv * 2, round_jiffies_relative(check_interval * HZ));

‎arch/x86/kernel/cpu/mcheck/mce_intel.c‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/interrupt.h>
1010
#include <linux/percpu.h>
1111
#include <linux/sched.h>
12+
#include <linux/cpumask.h>
1213
#include <asm/apic.h>
1314
#include <asm/processor.h>
1415
#include <asm/msr.h>
@@ -137,6 +138,22 @@ unsigned long mce_intel_adjust_timer(unsigned long interval)
137138
}
138139
}
139140

141+
static void cmci_storm_disable_banks(void)
142+
{
143+
unsigned long flags, *owned;
144+
int bank;
145+
u64 val;
146+
147+
raw_spin_lock_irqsave(&cmci_discover_lock, flags);
148+
owned = __get_cpu_var(mce_banks_owned);
149+
for_each_set_bit(bank, owned, MAX_NR_BANKS) {
150+
rdmsrl(MSR_IA32_MCx_CTL2(bank), val);
151+
val &= ~MCI_CTL2_CMCI_EN;
152+
wrmsrl(MSR_IA32_MCx_CTL2(bank), val);
153+
}
154+
raw_spin_unlock_irqrestore(&cmci_discover_lock, flags);
155+
}
156+
140157
static bool cmci_storm_detect(void)
141158
{
142159
unsigned int cnt = __this_cpu_read(cmci_storm_cnt);
@@ -158,7 +175,7 @@ static bool cmci_storm_detect(void)
158175
if (cnt <= CMCI_STORM_THRESHOLD)
159176
return false;
160177

161-
cmci_clear();
178+
cmci_storm_disable_banks();
162179
__this_cpu_write(cmci_storm_state, CMCI_STORM_ACTIVE);
163180
r = atomic_add_return(1, &cmci_storm_on_cpus);
164181
mce_timer_kick(CMCI_POLL_INTERVAL);

‎arch/x86/kernel/irq.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int arch_show_interrupts(struct seq_file *p, int prec)
125125
seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
126126
seq_printf(p, " Machine check polls\n");
127127
#endif
128-
#if defined(CONFIG_HYPERV) || defined(CONFIG_XEN)
128+
#if IS_ENABLED(CONFIG_HYPERV) || defined(CONFIG_XEN)
129129
seq_printf(p, "%*s: ", prec, "THR");
130130
for_each_online_cpu(j)
131131
seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);

‎arch/x86/kernel/ldt.c‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
229229
}
230230
}
231231

232+
/*
233+
* On x86-64 we do not support 16-bit segments due to
234+
* IRET leaking the high bits of the kernel stack address.
235+
*/
236+
#ifdef CONFIG_X86_64
237+
if (!ldt_info.seg_32bit) {
238+
error = -EINVAL;
239+
goto out_unlock;
240+
}
241+
#endif
242+
232243
fill_ldt(&ldt, &ldt_info);
233244
if (oldmode)
234245
ldt.avl = 0;

‎drivers/firmware/efi/efi-stub-helper.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
397397
else
398398
chunksize = size;
399399

400-
status = efi_file_read(fh, files[j].handle,
400+
status = efi_file_read(files[j].handle,
401401
&chunksize,
402402
(void *)addr);
403403
if (status != EFI_SUCCESS) {
@@ -408,7 +408,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
408408
size -= chunksize;
409409
}
410410

411-
efi_file_close(fh, files[j].handle);
411+
efi_file_close(files[j].handle);
412412
}
413413

414414
}
@@ -425,7 +425,7 @@ static efi_status_t handle_cmdline_files(efi_system_table_t *sys_table_arg,
425425

426426
close_handles:
427427
for (k = j; k < i; k++)
428-
efi_file_close(fh, files[k].handle);
428+
efi_file_close(files[k].handle);
429429
free_files:
430430
efi_call_early(free_pool, files);
431431
fail:

0 commit comments

Comments
 (0)