Skip to content

Commit 295dad1

Browse files
committed
Merge tag 'x86_urgent_for_v6.0_rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 fixes from Borislav Petkov: "As usually the case, right after a major release, the tip urgent branches accumulate a couple more fixes than normal. And here is the x86, a bit bigger, urgent pile. - Use the correct CPU capability clearing function on the error path in Intel perf LBR - A CFI fix to ftrace along with a simplification - Adjust handling of zero capacity bit mask for resctrl cache allocation on AMD - A fix to the AMD microcode loader to attempt patch application on every logical thread - A couple of topology fixes to handle CPUID leaf 0x1f enumeration info properly - Drop a -mabi=ms compiler option check as both compilers support it now anyway - A couple of fixes to how the initial, statically allocated FPU buffer state is setup and its interaction with dynamic states at runtime" * tag 'x86_urgent_for_v6.0_rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: x86/fpu: Fix copy_xstate_to_uabi() to copy init states correctly perf/x86/intel/lbr: Use setup_clear_cpu_cap() instead of clear_cpu_cap() ftrace,kcfi: Separate ftrace_stub() and ftrace_stub_graph() x86/ftrace: Remove ftrace_epilogue() x86/resctrl: Fix min_cbm_bits for AMD x86/microcode/AMD: Apply the patch early on every logical thread x86/topology: Fix duplicated core ID within a package x86/topology: Fix multiple packages shown on a single-package system hwmon/coretemp: Handle large core ID value x86/Kconfig: Drop check for -mabi=ms for CONFIG_EFI_STUB x86/fpu: Exclude dynamic states from init_fpstate x86/fpu: Fix the init_fpstate size check with the actual size x86/fpu: Configure init_fpstate attributes orderly
2 parents 942e01a + 471f0aa commit 295dad1

File tree

11 files changed

+122
-86
lines changed

11 files changed

+122
-86
lines changed

arch/arm64/kernel/entry-ftrace.S

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
#include <linux/linkage.h>
10+
#include <linux/cfi_types.h>
1011
#include <asm/asm-offsets.h>
1112
#include <asm/assembler.h>
1213
#include <asm/ftrace.h>
@@ -294,10 +295,14 @@ SYM_FUNC_END(ftrace_graph_caller)
294295
#endif /* CONFIG_FUNCTION_GRAPH_TRACER */
295296
#endif /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */
296297

297-
SYM_FUNC_START(ftrace_stub)
298+
SYM_TYPED_FUNC_START(ftrace_stub)
298299
ret
299300
SYM_FUNC_END(ftrace_stub)
300301

302+
SYM_TYPED_FUNC_START(ftrace_stub_graph)
303+
ret
304+
SYM_FUNC_END(ftrace_stub_graph)
305+
301306
#ifdef CONFIG_FUNCTION_GRAPH_TRACER
302307
/*
303308
* void return_to_handler(void)

arch/x86/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1973,7 +1973,6 @@ config EFI
19731973
config EFI_STUB
19741974
bool "EFI stub support"
19751975
depends on EFI
1976-
depends on $(cc-option,-mabi=ms) || X86_32
19771976
select RELOCATABLE
19781977
help
19791978
This kernel feature allows a bzImage to be loaded directly

arch/x86/events/intel/lbr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1596,7 +1596,7 @@ void __init intel_pmu_arch_lbr_init(void)
15961596
return;
15971597

15981598
clear_arch_lbr:
1599-
clear_cpu_cap(&boot_cpu_data, X86_FEATURE_ARCH_LBR);
1599+
setup_clear_cpu_cap(X86_FEATURE_ARCH_LBR);
16001600
}
16011601

16021602
/**

arch/x86/kernel/cpu/microcode/amd.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,13 @@ apply_microcode_early_amd(u32 cpuid_1_eax, void *ucode, size_t size, bool save_p
440440
return ret;
441441

442442
native_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
443-
if (rev >= mc->hdr.patch_id)
443+
444+
/*
445+
* Allow application of the same revision to pick up SMT-specific
446+
* changes even if the revision of the other SMT thread is already
447+
* up-to-date.
448+
*/
449+
if (rev > mc->hdr.patch_id)
444450
return ret;
445451

446452
if (!__apply_microcode_amd(mc)) {
@@ -528,8 +534,12 @@ void load_ucode_amd_ap(unsigned int cpuid_1_eax)
528534

529535
native_rdmsr(MSR_AMD64_PATCH_LEVEL, rev, dummy);
530536

531-
/* Check whether we have saved a new patch already: */
532-
if (*new_rev && rev < mc->hdr.patch_id) {
537+
/*
538+
* Check whether a new patch has been saved already. Also, allow application of
539+
* the same revision in order to pick up SMT-thread-specific configuration even
540+
* if the sibling SMT thread already has an up-to-date revision.
541+
*/
542+
if (*new_rev && rev <= mc->hdr.patch_id) {
533543
if (!__apply_microcode_amd(mc)) {
534544
*new_rev = mc->hdr.patch_id;
535545
return;

arch/x86/kernel/cpu/resctrl/core.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ struct rdt_hw_resource rdt_resources_all[] = {
6666
.rid = RDT_RESOURCE_L3,
6767
.name = "L3",
6868
.cache_level = 3,
69-
.cache = {
70-
.min_cbm_bits = 1,
71-
},
7269
.domains = domain_init(RDT_RESOURCE_L3),
7370
.parse_ctrlval = parse_cbm,
7471
.format_str = "%d=%0*x",
@@ -83,9 +80,6 @@ struct rdt_hw_resource rdt_resources_all[] = {
8380
.rid = RDT_RESOURCE_L2,
8481
.name = "L2",
8582
.cache_level = 2,
86-
.cache = {
87-
.min_cbm_bits = 1,
88-
},
8983
.domains = domain_init(RDT_RESOURCE_L2),
9084
.parse_ctrlval = parse_cbm,
9185
.format_str = "%d=%0*x",
@@ -836,6 +830,7 @@ static __init void rdt_init_res_defs_intel(void)
836830
r->cache.arch_has_sparse_bitmaps = false;
837831
r->cache.arch_has_empty_bitmaps = false;
838832
r->cache.arch_has_per_cpu_cfg = false;
833+
r->cache.min_cbm_bits = 1;
839834
} else if (r->rid == RDT_RESOURCE_MBA) {
840835
hw_res->msr_base = MSR_IA32_MBA_THRTL_BASE;
841836
hw_res->msr_update = mba_wrmsr_intel;
@@ -856,6 +851,7 @@ static __init void rdt_init_res_defs_amd(void)
856851
r->cache.arch_has_sparse_bitmaps = true;
857852
r->cache.arch_has_empty_bitmaps = true;
858853
r->cache.arch_has_per_cpu_cfg = true;
854+
r->cache.min_cbm_bits = 0;
859855
} else if (r->rid == RDT_RESOURCE_MBA) {
860856
hw_res->msr_base = MSR_IA32_MBA_BW_BASE;
861857
hw_res->msr_update = mba_wrmsr_amd;

arch/x86/kernel/cpu/topology.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
9696
unsigned int ht_mask_width, core_plus_mask_width, die_plus_mask_width;
9797
unsigned int core_select_mask, core_level_siblings;
9898
unsigned int die_select_mask, die_level_siblings;
99+
unsigned int pkg_mask_width;
99100
bool die_level_present = false;
100101
int leaf;
101102

@@ -111,10 +112,10 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
111112
core_level_siblings = smp_num_siblings = LEVEL_MAX_SIBLINGS(ebx);
112113
core_plus_mask_width = ht_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
113114
die_level_siblings = LEVEL_MAX_SIBLINGS(ebx);
114-
die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
115+
pkg_mask_width = die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
115116

116117
sub_index = 1;
117-
do {
118+
while (true) {
118119
cpuid_count(leaf, sub_index, &eax, &ebx, &ecx, &edx);
119120

120121
/*
@@ -132,10 +133,15 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
132133
die_plus_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
133134
}
134135

136+
if (LEAFB_SUBTYPE(ecx) != INVALID_TYPE)
137+
pkg_mask_width = BITS_SHIFT_NEXT_LEVEL(eax);
138+
else
139+
break;
140+
135141
sub_index++;
136-
} while (LEAFB_SUBTYPE(ecx) != INVALID_TYPE);
142+
}
137143

138-
core_select_mask = (~(-1 << core_plus_mask_width)) >> ht_mask_width;
144+
core_select_mask = (~(-1 << pkg_mask_width)) >> ht_mask_width;
139145
die_select_mask = (~(-1 << die_plus_mask_width)) >>
140146
core_plus_mask_width;
141147

@@ -148,7 +154,7 @@ int detect_extended_topology(struct cpuinfo_x86 *c)
148154
}
149155

150156
c->phys_proc_id = apic->phys_pkg_id(c->initial_apicid,
151-
die_plus_mask_width);
157+
pkg_mask_width);
152158
/*
153159
* Reinit the apicid, now that we have extended initial_apicid.
154160
*/

arch/x86/kernel/fpu/init.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,6 @@ static void __init fpu__init_system_xstate_size_legacy(void)
210210
fpstate_reset(&current->thread.fpu);
211211
}
212212

213-
static void __init fpu__init_init_fpstate(void)
214-
{
215-
/* Bring init_fpstate size and features up to date */
216-
init_fpstate.size = fpu_kernel_cfg.max_size;
217-
init_fpstate.xfeatures = fpu_kernel_cfg.max_features;
218-
}
219-
220213
/*
221214
* Called on the boot CPU once per system bootup, to set up the initial
222215
* FPU state that is later cloned into all processes:
@@ -236,5 +229,4 @@ void __init fpu__init_system(struct cpuinfo_x86 *c)
236229
fpu__init_system_xstate_size_legacy();
237230
fpu__init_system_xstate(fpu_kernel_cfg.max_size);
238231
fpu__init_task_struct_size();
239-
fpu__init_init_fpstate();
240232
}

arch/x86/kernel/fpu/xstate.c

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ static void __init setup_init_fpu_buf(void)
360360

361361
print_xstate_features();
362362

363-
xstate_init_xcomp_bv(&init_fpstate.regs.xsave, fpu_kernel_cfg.max_features);
363+
xstate_init_xcomp_bv(&init_fpstate.regs.xsave, init_fpstate.xfeatures);
364364

365365
/*
366366
* Init all the features state with header.xfeatures being 0x0
@@ -678,20 +678,6 @@ static unsigned int __init get_xsave_size_user(void)
678678
return ebx;
679679
}
680680

681-
/*
682-
* Will the runtime-enumerated 'xstate_size' fit in the init
683-
* task's statically-allocated buffer?
684-
*/
685-
static bool __init is_supported_xstate_size(unsigned int test_xstate_size)
686-
{
687-
if (test_xstate_size <= sizeof(init_fpstate.regs))
688-
return true;
689-
690-
pr_warn("x86/fpu: xstate buffer too small (%zu < %d), disabling xsave\n",
691-
sizeof(init_fpstate.regs), test_xstate_size);
692-
return false;
693-
}
694-
695681
static int __init init_xstate_size(void)
696682
{
697683
/* Recompute the context size for enabled features: */
@@ -717,10 +703,6 @@ static int __init init_xstate_size(void)
717703
kernel_default_size =
718704
xstate_calculate_size(fpu_kernel_cfg.default_features, compacted);
719705

720-
/* Ensure we have the space to store all default enabled features. */
721-
if (!is_supported_xstate_size(kernel_default_size))
722-
return -EINVAL;
723-
724706
if (!paranoid_xstate_size_valid(kernel_size))
725707
return -EINVAL;
726708

@@ -875,6 +857,19 @@ void __init fpu__init_system_xstate(unsigned int legacy_size)
875857
update_regset_xstate_info(fpu_user_cfg.max_size,
876858
fpu_user_cfg.max_features);
877859

860+
/*
861+
* init_fpstate excludes dynamic states as they are large but init
862+
* state is zero.
863+
*/
864+
init_fpstate.size = fpu_kernel_cfg.default_size;
865+
init_fpstate.xfeatures = fpu_kernel_cfg.default_features;
866+
867+
if (init_fpstate.size > sizeof(init_fpstate.regs)) {
868+
pr_warn("x86/fpu: init_fpstate buffer too small (%zu < %d), disabling XSAVE\n",
869+
sizeof(init_fpstate.regs), init_fpstate.size);
870+
goto out_disable;
871+
}
872+
878873
setup_init_fpu_buf();
879874

880875
/*
@@ -1130,6 +1125,15 @@ void __copy_xstate_to_uabi_buf(struct membuf to, struct fpstate *fpstate,
11301125
*/
11311126
mask = fpstate->user_xfeatures;
11321127

1128+
/*
1129+
* Dynamic features are not present in init_fpstate. When they are
1130+
* in an all zeros init state, remove those from 'mask' to zero
1131+
* those features in the user buffer instead of retrieving them
1132+
* from init_fpstate.
1133+
*/
1134+
if (fpu_state_size_dynamic())
1135+
mask &= (header.xfeatures | xinit->header.xcomp_bv);
1136+
11331137
for_each_extended_xfeature(i, mask) {
11341138
/*
11351139
* If there was a feature or alignment gap, zero the space

arch/x86/kernel/ftrace_64.S

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
*/
55

66
#include <linux/linkage.h>
7+
#include <linux/cfi_types.h>
78
#include <asm/ptrace.h>
89
#include <asm/ftrace.h>
910
#include <asm/export.h>
@@ -129,6 +130,14 @@
129130

130131
.endm
131132

133+
SYM_TYPED_FUNC_START(ftrace_stub)
134+
RET
135+
SYM_FUNC_END(ftrace_stub)
136+
137+
SYM_TYPED_FUNC_START(ftrace_stub_graph)
138+
RET
139+
SYM_FUNC_END(ftrace_stub_graph)
140+
132141
#ifdef CONFIG_DYNAMIC_FTRACE
133142

134143
SYM_FUNC_START(__fentry__)
@@ -172,21 +181,10 @@ SYM_INNER_LABEL(ftrace_call, SYM_L_GLOBAL)
172181
*/
173182
SYM_INNER_LABEL(ftrace_caller_end, SYM_L_GLOBAL)
174183
ANNOTATE_NOENDBR
175-
176-
jmp ftrace_epilogue
184+
RET
177185
SYM_FUNC_END(ftrace_caller);
178186
STACK_FRAME_NON_STANDARD_FP(ftrace_caller)
179187

180-
SYM_FUNC_START(ftrace_epilogue)
181-
/*
182-
* This is weak to keep gas from relaxing the jumps.
183-
*/
184-
SYM_INNER_LABEL_ALIGN(ftrace_stub, SYM_L_WEAK)
185-
UNWIND_HINT_FUNC
186-
ENDBR
187-
RET
188-
SYM_FUNC_END(ftrace_epilogue)
189-
190188
SYM_FUNC_START(ftrace_regs_caller)
191189
/* Save the current flags before any operations that can change them */
192190
pushfq
@@ -262,14 +260,11 @@ SYM_INNER_LABEL(ftrace_regs_caller_jmp, SYM_L_GLOBAL)
262260
popfq
263261

264262
/*
265-
* As this jmp to ftrace_epilogue can be a short jump
266-
* it must not be copied into the trampoline.
267-
* The trampoline will add the code to jump
268-
* to the return.
263+
* The trampoline will add the return.
269264
*/
270265
SYM_INNER_LABEL(ftrace_regs_caller_end, SYM_L_GLOBAL)
271266
ANNOTATE_NOENDBR
272-
jmp ftrace_epilogue
267+
RET
273268

274269
/* Swap the flags with orig_rax */
275270
1: movq MCOUNT_REG_SIZE(%rsp), %rdi
@@ -280,7 +275,7 @@ SYM_INNER_LABEL(ftrace_regs_caller_end, SYM_L_GLOBAL)
280275
/* Restore flags */
281276
popfq
282277
UNWIND_HINT_FUNC
283-
jmp ftrace_epilogue
278+
RET
284279

285280
SYM_FUNC_END(ftrace_regs_caller)
286281
STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller)
@@ -291,9 +286,6 @@ STACK_FRAME_NON_STANDARD_FP(ftrace_regs_caller)
291286
SYM_FUNC_START(__fentry__)
292287
cmpq $ftrace_stub, ftrace_trace_function
293288
jnz trace
294-
295-
SYM_INNER_LABEL(ftrace_stub, SYM_L_GLOBAL)
296-
ENDBR
297289
RET
298290

299291
trace:

0 commit comments

Comments
 (0)