Skip to content

Commit 1d966eb

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 Ingo Molnar: "Misc fixes: - A rather involved set of memory hardware encryption fixes to support the early loading of microcode files via the initrd. These are larger than what we normally take at such a late -rc stage, but there are two mitigating factors: 1) much of the changes are limited to the SME code itself 2) being able to early load microcode has increased importance in the post-Meltdown/Spectre era. - An IRQ vector allocator fix - An Intel RDT driver use-after-free fix - An APIC driver bug fix/revert to make certain older systems boot again - A pkeys ABI fix - TSC calibration fixes - A kdump fix" * 'x86-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/apic/vector: Fix off by one in error path x86/intel_rdt/cqm: Prevent use after free x86/mm: Encrypt the initrd earlier for BSP microcode update x86/mm: Prepare sme_encrypt_kernel() for PAGE aligned encryption x86/mm: Centralize PMD flags in sme_encrypt_kernel() x86/mm: Use a struct to reduce parameters for SME PGD mapping x86/mm: Clean up register saving in the __enc_copy() assembly code x86/idt: Mark IDT tables __initconst Revert "x86/apic: Remove init_bsp_APIC()" x86/mm/pkeys: Fix fill_sig_info_pkey x86/tsc: Print tsc_khz, when it differs from cpu_khz x86/tsc: Fix erroneous TSC rate on Skylake Xeon x86/tsc: Future-proof native_calibrate_tsc() kdump: Write the correct address of mem_section into vmcoreinfo
2 parents 9a4ba2a + 45d55e7 commit 1d966eb

File tree

13 files changed

+388
-162
lines changed

13 files changed

+388
-162
lines changed

arch/x86/include/asm/apic.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ extern void disconnect_bsp_APIC(int virt_wire_setup);
136136
extern void disable_local_APIC(void);
137137
extern void lapic_shutdown(void);
138138
extern void sync_Arb_IDs(void);
139+
extern void init_bsp_APIC(void);
139140
extern void apic_intr_mode_init(void);
140141
extern void setup_local_APIC(void);
141142
extern void init_apic_mappings(void);

arch/x86/include/asm/mem_encrypt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ void __init sme_unmap_bootdata(char *real_mode_data);
3939

4040
void __init sme_early_init(void);
4141

42-
void __init sme_encrypt_kernel(void);
42+
void __init sme_encrypt_kernel(struct boot_params *bp);
4343
void __init sme_enable(struct boot_params *bp);
4444

4545
int __init early_set_memory_decrypted(unsigned long vaddr, unsigned long size);
@@ -67,7 +67,7 @@ static inline void __init sme_unmap_bootdata(char *real_mode_data) { }
6767

6868
static inline void __init sme_early_init(void) { }
6969

70-
static inline void __init sme_encrypt_kernel(void) { }
70+
static inline void __init sme_encrypt_kernel(struct boot_params *bp) { }
7171
static inline void __init sme_enable(struct boot_params *bp) { }
7272

7373
static inline bool sme_active(void) { return false; }

arch/x86/kernel/apic/apic.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1286,6 +1286,55 @@ static int __init apic_intr_mode_select(void)
12861286
return APIC_SYMMETRIC_IO;
12871287
}
12881288

1289+
/*
1290+
* An initial setup of the virtual wire mode.
1291+
*/
1292+
void __init init_bsp_APIC(void)
1293+
{
1294+
unsigned int value;
1295+
1296+
/*
1297+
* Don't do the setup now if we have a SMP BIOS as the
1298+
* through-I/O-APIC virtual wire mode might be active.
1299+
*/
1300+
if (smp_found_config || !boot_cpu_has(X86_FEATURE_APIC))
1301+
return;
1302+
1303+
/*
1304+
* Do not trust the local APIC being empty at bootup.
1305+
*/
1306+
clear_local_APIC();
1307+
1308+
/*
1309+
* Enable APIC.
1310+
*/
1311+
value = apic_read(APIC_SPIV);
1312+
value &= ~APIC_VECTOR_MASK;
1313+
value |= APIC_SPIV_APIC_ENABLED;
1314+
1315+
#ifdef CONFIG_X86_32
1316+
/* This bit is reserved on P4/Xeon and should be cleared */
1317+
if ((boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) &&
1318+
(boot_cpu_data.x86 == 15))
1319+
value &= ~APIC_SPIV_FOCUS_DISABLED;
1320+
else
1321+
#endif
1322+
value |= APIC_SPIV_FOCUS_DISABLED;
1323+
value |= SPURIOUS_APIC_VECTOR;
1324+
apic_write(APIC_SPIV, value);
1325+
1326+
/*
1327+
* Set up the virtual wire mode.
1328+
*/
1329+
apic_write(APIC_LVT0, APIC_DM_EXTINT);
1330+
value = APIC_DM_NMI;
1331+
if (!lapic_is_integrated()) /* 82489DX */
1332+
value |= APIC_LVT_LEVEL_TRIGGER;
1333+
if (apic_extnmi == APIC_EXTNMI_NONE)
1334+
value |= APIC_LVT_MASKED;
1335+
apic_write(APIC_LVT1, value);
1336+
}
1337+
12891338
/* Init the interrupt delivery mode for the BSP */
12901339
void __init apic_intr_mode_init(void)
12911340
{

arch/x86/kernel/apic/vector.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,14 +542,17 @@ static int x86_vector_alloc_irqs(struct irq_domain *domain, unsigned int virq,
542542

543543
err = assign_irq_vector_policy(irqd, info);
544544
trace_vector_setup(virq + i, false, err);
545-
if (err)
545+
if (err) {
546+
irqd->chip_data = NULL;
547+
free_apic_chip_data(apicd);
546548
goto error;
549+
}
547550
}
548551

549552
return 0;
550553

551554
error:
552-
x86_vector_free_irqs(domain, virq, i + 1);
555+
x86_vector_free_irqs(domain, virq, i);
553556
return err;
554557
}
555558

arch/x86/kernel/cpu/intel_rdt.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,6 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
525525
*/
526526
if (static_branch_unlikely(&rdt_mon_enable_key))
527527
rmdir_mondata_subdir_allrdtgrp(r, d->id);
528-
kfree(d->ctrl_val);
529-
kfree(d->rmid_busy_llc);
530-
kfree(d->mbm_total);
531-
kfree(d->mbm_local);
532528
list_del(&d->list);
533529
if (is_mbm_enabled())
534530
cancel_delayed_work(&d->mbm_over);
@@ -545,6 +541,10 @@ static void domain_remove_cpu(int cpu, struct rdt_resource *r)
545541
cancel_delayed_work(&d->cqm_limbo);
546542
}
547543

544+
kfree(d->ctrl_val);
545+
kfree(d->rmid_busy_llc);
546+
kfree(d->mbm_total);
547+
kfree(d->mbm_local);
548548
kfree(d);
549549
return;
550550
}

arch/x86/kernel/head64.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ unsigned long __head __startup_64(unsigned long physaddr,
157157
p = fixup_pointer(&phys_base, physaddr);
158158
*p += load_delta - sme_get_me_mask();
159159

160-
/* Encrypt the kernel (if SME is active) */
161-
sme_encrypt_kernel();
160+
/* Encrypt the kernel and related (if SME is active) */
161+
sme_encrypt_kernel(bp);
162162

163163
/*
164164
* Return the SME encryption mask (if SME is active) to be used as a

arch/x86/kernel/idt.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ struct idt_data {
5656
* Early traps running on the DEFAULT_STACK because the other interrupt
5757
* stacks work only after cpu_init().
5858
*/
59-
static const __initdata struct idt_data early_idts[] = {
59+
static const __initconst struct idt_data early_idts[] = {
6060
INTG(X86_TRAP_DB, debug),
6161
SYSG(X86_TRAP_BP, int3),
6262
#ifdef CONFIG_X86_32
@@ -70,7 +70,7 @@ static const __initdata struct idt_data early_idts[] = {
7070
* the traps which use them are reinitialized with IST after cpu_init() has
7171
* set up TSS.
7272
*/
73-
static const __initdata struct idt_data def_idts[] = {
73+
static const __initconst struct idt_data def_idts[] = {
7474
INTG(X86_TRAP_DE, divide_error),
7575
INTG(X86_TRAP_NMI, nmi),
7676
INTG(X86_TRAP_BR, bounds),
@@ -108,7 +108,7 @@ static const __initdata struct idt_data def_idts[] = {
108108
/*
109109
* The APIC and SMP idt entries
110110
*/
111-
static const __initdata struct idt_data apic_idts[] = {
111+
static const __initconst struct idt_data apic_idts[] = {
112112
#ifdef CONFIG_SMP
113113
INTG(RESCHEDULE_VECTOR, reschedule_interrupt),
114114
INTG(CALL_FUNCTION_VECTOR, call_function_interrupt),
@@ -150,15 +150,15 @@ static const __initdata struct idt_data apic_idts[] = {
150150
* Early traps running on the DEFAULT_STACK because the other interrupt
151151
* stacks work only after cpu_init().
152152
*/
153-
static const __initdata struct idt_data early_pf_idts[] = {
153+
static const __initconst struct idt_data early_pf_idts[] = {
154154
INTG(X86_TRAP_PF, page_fault),
155155
};
156156

157157
/*
158158
* Override for the debug_idt. Same as the default, but with interrupt
159159
* stack set to DEFAULT_STACK (0). Required for NMI trap handling.
160160
*/
161-
static const __initdata struct idt_data dbg_idts[] = {
161+
static const __initconst struct idt_data dbg_idts[] = {
162162
INTG(X86_TRAP_DB, debug),
163163
INTG(X86_TRAP_BP, int3),
164164
};
@@ -180,7 +180,7 @@ gate_desc debug_idt_table[IDT_ENTRIES] __page_aligned_bss;
180180
* The exceptions which use Interrupt stacks. They are setup after
181181
* cpu_init() when the TSS has been initialized.
182182
*/
183-
static const __initdata struct idt_data ist_idts[] = {
183+
static const __initconst struct idt_data ist_idts[] = {
184184
ISTG(X86_TRAP_DB, debug, DEBUG_STACK),
185185
ISTG(X86_TRAP_NMI, nmi, NMI_STACK),
186186
SISTG(X86_TRAP_BP, int3, DEBUG_STACK),

arch/x86/kernel/irqinit.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ void __init init_ISA_irqs(void)
6161
struct irq_chip *chip = legacy_pic->chip;
6262
int i;
6363

64+
#if defined(CONFIG_X86_64) || defined(CONFIG_X86_LOCAL_APIC)
65+
init_bsp_APIC();
66+
#endif
6467
legacy_pic->init(0);
6568

6669
for (i = 0; i < nr_legacy_irqs(); i++)

arch/x86/kernel/setup.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,6 @@ static void __init reserve_initrd(void)
364364
!ramdisk_image || !ramdisk_size)
365365
return; /* No initrd provided by bootloader */
366366

367-
/*
368-
* If SME is active, this memory will be marked encrypted by the
369-
* kernel when it is accessed (including relocation). However, the
370-
* ramdisk image was loaded decrypted by the bootloader, so make
371-
* sure that it is encrypted before accessing it. For SEV the
372-
* ramdisk will already be encrypted, so only do this for SME.
373-
*/
374-
if (sme_active())
375-
sme_early_encrypt(ramdisk_image, ramdisk_end - ramdisk_image);
376-
377367
initrd_start = 0;
378368

379369
mapped_size = memblock_mem_size(max_pfn_mapped);

arch/x86/kernel/tsc.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ unsigned long native_calibrate_tsc(void)
602602
case INTEL_FAM6_KABYLAKE_DESKTOP:
603603
crystal_khz = 24000; /* 24.0 MHz */
604604
break;
605-
case INTEL_FAM6_SKYLAKE_X:
606605
case INTEL_FAM6_ATOM_DENVERTON:
607606
crystal_khz = 25000; /* 25.0 MHz */
608607
break;
@@ -612,6 +611,8 @@ unsigned long native_calibrate_tsc(void)
612611
}
613612
}
614613

614+
if (crystal_khz == 0)
615+
return 0;
615616
/*
616617
* TSC frequency determined by CPUID is a "hardware reported"
617618
* frequency and is the most accurate one so far we have. This
@@ -1315,6 +1316,12 @@ void __init tsc_init(void)
13151316
(unsigned long)cpu_khz / 1000,
13161317
(unsigned long)cpu_khz % 1000);
13171318

1319+
if (cpu_khz != tsc_khz) {
1320+
pr_info("Detected %lu.%03lu MHz TSC",
1321+
(unsigned long)tsc_khz / 1000,
1322+
(unsigned long)tsc_khz % 1000);
1323+
}
1324+
13181325
/* Sanitize TSC ADJUST before cyc2ns gets initialized */
13191326
tsc_store_and_check_tsc_adjust(true);
13201327

0 commit comments

Comments
 (0)