Skip to content

Commit 6a45a65

Browse files
committed
Merge tag 'x86-urgent-2020-06-11' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull more x86 updates from Thomas Gleixner: "A set of fixes and updates for x86: - Unbreak paravirt VDSO clocks. While the VDSO code was moved into lib for sharing a subtle check for the validity of paravirt clocks got replaced. While the replacement works perfectly fine for bare metal as the update of the VDSO clock mode is synchronous, it fails for paravirt clocks because the hypervisor can invalidate them asynchronously. Bring it back as an optional function so it does not inflict this on architectures which are free of PV damage. - Fix the jiffies to jiffies64 mapping on 64bit so it does not trigger an ODR violation on newer compilers - Three fixes for the SSBD and *IB* speculation mitigation maze to ensure consistency, not disabling of some *IB* variants wrongly and to prevent a rogue cross process shutdown of SSBD. All marked for stable. - Add yet more CPU models to the splitlock detection capable list !@#%$! - Bring the pr_info() back which tells that TSC deadline timer is enabled. - Reboot quirk for MacBook6,1" * tag 'x86-urgent-2020-06-11' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/vdso: Unbreak paravirt VDSO clocks lib/vdso: Provide sanity check for cycles (again) clocksource: Remove obsolete ifdef x86_64: Fix jiffies ODR violation x86/speculation: PR_SPEC_FORCE_DISABLE enforcement for indirect branches. x86/speculation: Prevent rogue cross-process SSBD shutdown x86/speculation: Avoid force-disabling IBPB based on STIBP and enhanced IBRS. x86/cpu: Add Sapphire Rapids CPU model number x86/split_lock: Add Icelake microserver and Tigerlake CPU models x86/apic: Make TSC deadline timer detection message visible x86/reboot/quirks: Add MacBook6,1 reboot quirk
2 parents 92ac971 + 7778d84 commit 6a45a65

File tree

11 files changed

+109
-65
lines changed

11 files changed

+109
-65
lines changed

arch/x86/include/asm/intel-family.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
#define INTEL_FAM6_COMETLAKE 0xA5
9090
#define INTEL_FAM6_COMETLAKE_L 0xA6
9191

92+
#define INTEL_FAM6_SAPPHIRERAPIDS_X 0x8F
93+
9294
/* "Small Core" Processors (Atom) */
9395

9496
#define INTEL_FAM6_ATOM_BONNELL 0x1C /* Diamondville, Pineview */

arch/x86/include/asm/vdso/gettimeofday.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,24 @@ static __always_inline const struct vdso_data *__arch_get_vdso_data(void)
271271
return __vdso_data;
272272
}
273273

274+
static inline bool arch_vdso_clocksource_ok(const struct vdso_data *vd)
275+
{
276+
return true;
277+
}
278+
#define vdso_clocksource_ok arch_vdso_clocksource_ok
279+
280+
/*
281+
* Clocksource read value validation to handle PV and HyperV clocksources
282+
* which can be invalidated asynchronously and indicate invalidation by
283+
* returning U64_MAX, which can be effectively tested by checking for a
284+
* negative value after casting it to s64.
285+
*/
286+
static inline bool arch_vdso_cycles_ok(u64 cycles)
287+
{
288+
return (s64)cycles >= 0;
289+
}
290+
#define vdso_cycles_ok arch_vdso_cycles_ok
291+
274292
/*
275293
* x86 specific delta calculation.
276294
*

arch/x86/kernel/apic/apic.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,7 @@ void __init init_apic_mappings(void)
20602060
unsigned int new_apicid;
20612061

20622062
if (apic_validate_deadline_timer())
2063-
pr_debug("TSC deadline timer available\n");
2063+
pr_info("TSC deadline timer available\n");
20642064

20652065
if (x2apic_mode) {
20662066
boot_cpu_physical_apicid = read_apic_id();

arch/x86/kernel/cpu/bugs.c

Lines changed: 54 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,9 @@ early_param("nospectre_v1", nospectre_v1_cmdline);
588588
static enum spectre_v2_mitigation spectre_v2_enabled __ro_after_init =
589589
SPECTRE_V2_NONE;
590590

591-
static enum spectre_v2_user_mitigation spectre_v2_user __ro_after_init =
591+
static enum spectre_v2_user_mitigation spectre_v2_user_stibp __ro_after_init =
592+
SPECTRE_V2_USER_NONE;
593+
static enum spectre_v2_user_mitigation spectre_v2_user_ibpb __ro_after_init =
592594
SPECTRE_V2_USER_NONE;
593595

594596
#ifdef CONFIG_RETPOLINE
@@ -734,15 +736,6 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
734736
break;
735737
}
736738

737-
/*
738-
* At this point, an STIBP mode other than "off" has been set.
739-
* If STIBP support is not being forced, check if STIBP always-on
740-
* is preferred.
741-
*/
742-
if (mode != SPECTRE_V2_USER_STRICT &&
743-
boot_cpu_has(X86_FEATURE_AMD_STIBP_ALWAYS_ON))
744-
mode = SPECTRE_V2_USER_STRICT_PREFERRED;
745-
746739
/* Initialize Indirect Branch Prediction Barrier */
747740
if (boot_cpu_has(X86_FEATURE_IBPB)) {
748741
setup_force_cpu_cap(X86_FEATURE_USE_IBPB);
@@ -765,23 +758,36 @@ spectre_v2_user_select_mitigation(enum spectre_v2_mitigation_cmd v2_cmd)
765758
pr_info("mitigation: Enabling %s Indirect Branch Prediction Barrier\n",
766759
static_key_enabled(&switch_mm_always_ibpb) ?
767760
"always-on" : "conditional");
761+
762+
spectre_v2_user_ibpb = mode;
768763
}
769764

770-
/* If enhanced IBRS is enabled no STIBP required */
771-
if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
765+
/*
766+
* If enhanced IBRS is enabled or SMT impossible, STIBP is not
767+
* required.
768+
*/
769+
if (!smt_possible || spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
772770
return;
773771

774772
/*
775-
* If SMT is not possible or STIBP is not available clear the STIBP
776-
* mode.
773+
* At this point, an STIBP mode other than "off" has been set.
774+
* If STIBP support is not being forced, check if STIBP always-on
775+
* is preferred.
777776
*/
778-
if (!smt_possible || !boot_cpu_has(X86_FEATURE_STIBP))
777+
if (mode != SPECTRE_V2_USER_STRICT &&
778+
boot_cpu_has(X86_FEATURE_AMD_STIBP_ALWAYS_ON))
779+
mode = SPECTRE_V2_USER_STRICT_PREFERRED;
780+
781+
/*
782+
* If STIBP is not available, clear the STIBP mode.
783+
*/
784+
if (!boot_cpu_has(X86_FEATURE_STIBP))
779785
mode = SPECTRE_V2_USER_NONE;
786+
787+
spectre_v2_user_stibp = mode;
788+
780789
set_mode:
781-
spectre_v2_user = mode;
782-
/* Only print the STIBP mode when SMT possible */
783-
if (smt_possible)
784-
pr_info("%s\n", spectre_v2_user_strings[mode]);
790+
pr_info("%s\n", spectre_v2_user_strings[mode]);
785791
}
786792

787793
static const char * const spectre_v2_strings[] = {
@@ -1014,7 +1020,7 @@ void cpu_bugs_smt_update(void)
10141020
{
10151021
mutex_lock(&spec_ctrl_mutex);
10161022

1017-
switch (spectre_v2_user) {
1023+
switch (spectre_v2_user_stibp) {
10181024
case SPECTRE_V2_USER_NONE:
10191025
break;
10201026
case SPECTRE_V2_USER_STRICT:
@@ -1257,14 +1263,19 @@ static int ib_prctl_set(struct task_struct *task, unsigned long ctrl)
12571263
{
12581264
switch (ctrl) {
12591265
case PR_SPEC_ENABLE:
1260-
if (spectre_v2_user == SPECTRE_V2_USER_NONE)
1266+
if (spectre_v2_user_ibpb == SPECTRE_V2_USER_NONE &&
1267+
spectre_v2_user_stibp == SPECTRE_V2_USER_NONE)
12611268
return 0;
12621269
/*
12631270
* Indirect branch speculation is always disabled in strict
1264-
* mode.
1271+
* mode. It can neither be enabled if it was force-disabled
1272+
* by a previous prctl call.
1273+
12651274
*/
1266-
if (spectre_v2_user == SPECTRE_V2_USER_STRICT ||
1267-
spectre_v2_user == SPECTRE_V2_USER_STRICT_PREFERRED)
1275+
if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT ||
1276+
spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT ||
1277+
spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED ||
1278+
task_spec_ib_force_disable(task))
12681279
return -EPERM;
12691280
task_clear_spec_ib_disable(task);
12701281
task_update_spec_tif(task);
@@ -1275,10 +1286,12 @@ static int ib_prctl_set(struct task_struct *task, unsigned long ctrl)
12751286
* Indirect branch speculation is always allowed when
12761287
* mitigation is force disabled.
12771288
*/
1278-
if (spectre_v2_user == SPECTRE_V2_USER_NONE)
1289+
if (spectre_v2_user_ibpb == SPECTRE_V2_USER_NONE &&
1290+
spectre_v2_user_stibp == SPECTRE_V2_USER_NONE)
12791291
return -EPERM;
1280-
if (spectre_v2_user == SPECTRE_V2_USER_STRICT ||
1281-
spectre_v2_user == SPECTRE_V2_USER_STRICT_PREFERRED)
1292+
if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT ||
1293+
spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT ||
1294+
spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED)
12821295
return 0;
12831296
task_set_spec_ib_disable(task);
12841297
if (ctrl == PR_SPEC_FORCE_DISABLE)
@@ -1309,7 +1322,8 @@ void arch_seccomp_spec_mitigate(struct task_struct *task)
13091322
{
13101323
if (ssb_mode == SPEC_STORE_BYPASS_SECCOMP)
13111324
ssb_prctl_set(task, PR_SPEC_FORCE_DISABLE);
1312-
if (spectre_v2_user == SPECTRE_V2_USER_SECCOMP)
1325+
if (spectre_v2_user_ibpb == SPECTRE_V2_USER_SECCOMP ||
1326+
spectre_v2_user_stibp == SPECTRE_V2_USER_SECCOMP)
13131327
ib_prctl_set(task, PR_SPEC_FORCE_DISABLE);
13141328
}
13151329
#endif
@@ -1340,22 +1354,24 @@ static int ib_prctl_get(struct task_struct *task)
13401354
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2))
13411355
return PR_SPEC_NOT_AFFECTED;
13421356

1343-
switch (spectre_v2_user) {
1344-
case SPECTRE_V2_USER_NONE:
1357+
if (spectre_v2_user_ibpb == SPECTRE_V2_USER_NONE &&
1358+
spectre_v2_user_stibp == SPECTRE_V2_USER_NONE)
13451359
return PR_SPEC_ENABLE;
1346-
case SPECTRE_V2_USER_PRCTL:
1347-
case SPECTRE_V2_USER_SECCOMP:
1360+
else if (spectre_v2_user_ibpb == SPECTRE_V2_USER_STRICT ||
1361+
spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT ||
1362+
spectre_v2_user_stibp == SPECTRE_V2_USER_STRICT_PREFERRED)
1363+
return PR_SPEC_DISABLE;
1364+
else if (spectre_v2_user_ibpb == SPECTRE_V2_USER_PRCTL ||
1365+
spectre_v2_user_ibpb == SPECTRE_V2_USER_SECCOMP ||
1366+
spectre_v2_user_stibp == SPECTRE_V2_USER_PRCTL ||
1367+
spectre_v2_user_stibp == SPECTRE_V2_USER_SECCOMP) {
13481368
if (task_spec_ib_force_disable(task))
13491369
return PR_SPEC_PRCTL | PR_SPEC_FORCE_DISABLE;
13501370
if (task_spec_ib_disable(task))
13511371
return PR_SPEC_PRCTL | PR_SPEC_DISABLE;
13521372
return PR_SPEC_PRCTL | PR_SPEC_ENABLE;
1353-
case SPECTRE_V2_USER_STRICT:
1354-
case SPECTRE_V2_USER_STRICT_PREFERRED:
1355-
return PR_SPEC_DISABLE;
1356-
default:
1373+
} else
13571374
return PR_SPEC_NOT_AFFECTED;
1358-
}
13591375
}
13601376

13611377
int arch_prctl_spec_ctrl_get(struct task_struct *task, unsigned long which)
@@ -1594,7 +1610,7 @@ static char *stibp_state(void)
15941610
if (spectre_v2_enabled == SPECTRE_V2_IBRS_ENHANCED)
15951611
return "";
15961612

1597-
switch (spectre_v2_user) {
1613+
switch (spectre_v2_user_stibp) {
15981614
case SPECTRE_V2_USER_NONE:
15991615
return ", STIBP: disabled";
16001616
case SPECTRE_V2_USER_STRICT:

arch/x86/kernel/cpu/intel.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,9 +1142,12 @@ void switch_to_sld(unsigned long tifn)
11421142
static const struct x86_cpu_id split_lock_cpu_ids[] __initconst = {
11431143
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_X, 0),
11441144
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_L, 0),
1145+
X86_MATCH_INTEL_FAM6_MODEL(ICELAKE_D, 0),
11451146
X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT, 1),
11461147
X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_D, 1),
11471148
X86_MATCH_INTEL_FAM6_MODEL(ATOM_TREMONT_L, 1),
1149+
X86_MATCH_INTEL_FAM6_MODEL(TIGERLAKE_L, 1),
1150+
X86_MATCH_INTEL_FAM6_MODEL(TIGERLAKE, 1),
11481151
{}
11491152
};
11501153

arch/x86/kernel/process.c

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -545,28 +545,20 @@ static __always_inline void __speculation_ctrl_update(unsigned long tifp,
545545

546546
lockdep_assert_irqs_disabled();
547547

548-
/*
549-
* If TIF_SSBD is different, select the proper mitigation
550-
* method. Note that if SSBD mitigation is disabled or permanentely
551-
* enabled this branch can't be taken because nothing can set
552-
* TIF_SSBD.
553-
*/
554-
if (tif_diff & _TIF_SSBD) {
555-
if (static_cpu_has(X86_FEATURE_VIRT_SSBD)) {
548+
/* Handle change of TIF_SSBD depending on the mitigation method. */
549+
if (static_cpu_has(X86_FEATURE_VIRT_SSBD)) {
550+
if (tif_diff & _TIF_SSBD)
556551
amd_set_ssb_virt_state(tifn);
557-
} else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD)) {
552+
} else if (static_cpu_has(X86_FEATURE_LS_CFG_SSBD)) {
553+
if (tif_diff & _TIF_SSBD)
558554
amd_set_core_ssb_state(tifn);
559-
} else if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) ||
560-
static_cpu_has(X86_FEATURE_AMD_SSBD)) {
561-
msr |= ssbd_tif_to_spec_ctrl(tifn);
562-
updmsr = true;
563-
}
555+
} else if (static_cpu_has(X86_FEATURE_SPEC_CTRL_SSBD) ||
556+
static_cpu_has(X86_FEATURE_AMD_SSBD)) {
557+
updmsr |= !!(tif_diff & _TIF_SSBD);
558+
msr |= ssbd_tif_to_spec_ctrl(tifn);
564559
}
565560

566-
/*
567-
* Only evaluate TIF_SPEC_IB if conditional STIBP is enabled,
568-
* otherwise avoid the MSR write.
569-
*/
561+
/* Only evaluate TIF_SPEC_IB if conditional STIBP is enabled. */
570562
if (IS_ENABLED(CONFIG_SMP) &&
571563
static_branch_unlikely(&switch_to_cond_stibp)) {
572564
updmsr |= !!(tif_diff & _TIF_SPEC_IB);

arch/x86/kernel/reboot.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ static const struct dmi_system_id reboot_dmi_table[] __initconst = {
197197
DMI_MATCH(DMI_PRODUCT_NAME, "MacBook5"),
198198
},
199199
},
200+
{ /* Handle problems with rebooting on Apple MacBook6,1 */
201+
.callback = set_pci_reboot,
202+
.ident = "Apple MacBook6,1",
203+
.matches = {
204+
DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
205+
DMI_MATCH(DMI_PRODUCT_NAME, "MacBook6,1"),
206+
},
207+
},
200208
{ /* Handle problems with rebooting on Apple MacBookPro5 */
201209
.callback = set_pci_reboot,
202210
.ident = "Apple MacBookPro5",

arch/x86/kernel/time.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
#include <asm/hpet.h>
2626
#include <asm/time.h>
2727

28-
#ifdef CONFIG_X86_64
29-
__visible volatile unsigned long jiffies __cacheline_aligned_in_smp = INITIAL_JIFFIES;
30-
#endif
31-
3228
unsigned long profile_pc(struct pt_regs *regs)
3329
{
3430
unsigned long pc = instruction_pointer(regs);

arch/x86/kernel/vmlinux.lds.S

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ OUTPUT_FORMAT(CONFIG_OUTPUT_FORMAT)
4040
#ifdef CONFIG_X86_32
4141
OUTPUT_ARCH(i386)
4242
ENTRY(phys_startup_32)
43-
jiffies = jiffies_64;
4443
#else
4544
OUTPUT_ARCH(i386:x86-64)
4645
ENTRY(phys_startup_64)
47-
jiffies_64 = jiffies;
4846
#endif
4947

48+
jiffies = jiffies_64;
49+
5050
#if defined(CONFIG_X86_64)
5151
/*
5252
* On 64-bit, align RODATA to 2MB so we retain large page mappings for

kernel/time/clocksource.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -928,14 +928,12 @@ int __clocksource_register_scale(struct clocksource *cs, u32 scale, u32 freq)
928928

929929
clocksource_arch_init(cs);
930930

931-
#ifdef CONFIG_GENERIC_VDSO_CLOCK_MODE
932931
if (cs->vdso_clock_mode < 0 ||
933932
cs->vdso_clock_mode >= VDSO_CLOCKMODE_MAX) {
934933
pr_warn("clocksource %s registered with invalid VDSO mode %d. Disabling VDSO support.\n",
935934
cs->name, cs->vdso_clock_mode);
936935
cs->vdso_clock_mode = VDSO_CLOCKMODE_NONE;
937936
}
938-
#endif
939937

940938
/* Initialize mult/shift and max_idle_ns */
941939
__clocksource_update_freq_scale(cs, scale, freq);

0 commit comments

Comments
 (0)