From: Greg Kroah-Hartman Date: Mon, 2 May 2022 23:05:27 +0000 (+0200) Subject: 5.10-stable patches X-Git-Tag: v5.4.192~35 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=084a425cfecb6d5cfeca1cb200686df17ea505a2;p=thirdparty%2Fkernel%2Fstable-queue.git 5.10-stable patches added patches: perf-symbol-pass-is_kallsyms-to-symbols__fixup_end.patch perf-symbol-update-symbols__fixup_end.patch x86-cpu-load-microcode-during-restore_processor_state.patch --- diff --git a/queue-5.10/perf-symbol-pass-is_kallsyms-to-symbols__fixup_end.patch b/queue-5.10/perf-symbol-pass-is_kallsyms-to-symbols__fixup_end.patch new file mode 100644 index 00000000000..a79de483cda --- /dev/null +++ b/queue-5.10/perf-symbol-pass-is_kallsyms-to-symbols__fixup_end.patch @@ -0,0 +1,99 @@ +From 838425f2defe5262906b698752d28fd2fca1aac2 Mon Sep 17 00:00:00 2001 +From: Namhyung Kim +Date: Fri, 15 Apr 2022 17:40:46 -0700 +Subject: perf symbol: Pass is_kallsyms to symbols__fixup_end() + +From: Namhyung Kim + +commit 838425f2defe5262906b698752d28fd2fca1aac2 upstream. + +The symbol fixup is necessary for symbols in kallsyms since they don't +have size info. So we use the next symbol's address to calculate the +size. Now it's also used for user binaries because sometimes they miss +size for hand-written asm functions. + +There's a arch-specific function to handle kallsyms differently but +currently it cannot distinguish kallsyms from others. Pass this +information explicitly to handle it properly. Note that those arch +functions will be moved to the generic function so I didn't added it to +the arch-functions. + +Fixes: 3cf6a32f3f2a4594 ("perf symbols: Fix symbol size calculation condition") +Signed-off-by: Namhyung Kim +Acked-by: Ian Rogers +Cc: Heiko Carstens +Cc: Ingo Molnar +Cc: Jiri Olsa +Cc: John Garry +Cc: Leo Yan +Cc: Mark Rutland +Cc: Masami Hiramatsu +Cc: Mathieu Poirier +Cc: Michael Ellerman +Cc: Michael Petlan +Cc: Peter Zijlstra +Cc: Song Liu +Cc: Will Deacon +Cc: linux-s390@vger.kernel.org +Cc: linuxppc-dev@lists.ozlabs.org +Link: https://lore.kernel.org/r/20220416004048.1514900-2-namhyung@kernel.org +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman +--- + tools/perf/util/symbol-elf.c | 2 +- + tools/perf/util/symbol.c | 7 ++++--- + tools/perf/util/symbol.h | 2 +- + 3 files changed, 6 insertions(+), 5 deletions(-) + +--- a/tools/perf/util/symbol-elf.c ++++ b/tools/perf/util/symbol-elf.c +@@ -1245,7 +1245,7 @@ int dso__load_sym(struct dso *dso, struc + * For misannotated, zeroed, ASM function sizes. + */ + if (nr > 0) { +- symbols__fixup_end(&dso->symbols); ++ symbols__fixup_end(&dso->symbols, false); + symbols__fixup_duplicate(&dso->symbols); + if (kmap) { + /* +--- a/tools/perf/util/symbol.c ++++ b/tools/perf/util/symbol.c +@@ -217,7 +217,8 @@ again: + } + } + +-void symbols__fixup_end(struct rb_root_cached *symbols) ++void symbols__fixup_end(struct rb_root_cached *symbols, ++ bool is_kallsyms __maybe_unused) + { + struct rb_node *nd, *prevnd = rb_first_cached(symbols); + struct symbol *curr, *prev; +@@ -1456,7 +1457,7 @@ int __dso__load_kallsyms(struct dso *dso + if (kallsyms__delta(kmap, filename, &delta)) + return -1; + +- symbols__fixup_end(&dso->symbols); ++ symbols__fixup_end(&dso->symbols, true); + symbols__fixup_duplicate(&dso->symbols); + + if (dso->kernel == DSO_SPACE__KERNEL_GUEST) +@@ -1651,7 +1652,7 @@ int dso__load_bfd_symbols(struct dso *ds + #undef bfd_asymbol_section + #endif + +- symbols__fixup_end(&dso->symbols); ++ symbols__fixup_end(&dso->symbols, false); + symbols__fixup_duplicate(&dso->symbols); + dso->adjust_symbols = 1; + +--- a/tools/perf/util/symbol.h ++++ b/tools/perf/util/symbol.h +@@ -192,7 +192,7 @@ void __symbols__insert(struct rb_root_ca + bool kernel); + void symbols__insert(struct rb_root_cached *symbols, struct symbol *sym); + void symbols__fixup_duplicate(struct rb_root_cached *symbols); +-void symbols__fixup_end(struct rb_root_cached *symbols); ++void symbols__fixup_end(struct rb_root_cached *symbols, bool is_kallsyms); + void maps__fixup_end(struct maps *maps); + + typedef int (*mapfn_t)(u64 start, u64 len, u64 pgoff, void *data); diff --git a/queue-5.10/perf-symbol-update-symbols__fixup_end.patch b/queue-5.10/perf-symbol-update-symbols__fixup_end.patch new file mode 100644 index 00000000000..06f50ef7b88 --- /dev/null +++ b/queue-5.10/perf-symbol-update-symbols__fixup_end.patch @@ -0,0 +1,85 @@ +From 8799ebce84d672aae1dc3170510f6a3e66f96b11 Mon Sep 17 00:00:00 2001 +From: Namhyung Kim +Date: Fri, 15 Apr 2022 17:40:47 -0700 +Subject: perf symbol: Update symbols__fixup_end() + +From: Namhyung Kim + +commit 8799ebce84d672aae1dc3170510f6a3e66f96b11 upstream. + +Now arch-specific functions all do the same thing. When it fixes the +symbol address it needs to check the boundary between the kernel image +and modules. For the last symbol in the previous region, it cannot +know the exact size as it's discarded already. Thus it just uses a +small page size (4096) and rounds it up like the last symbol. + +Fixes: 3cf6a32f3f2a4594 ("perf symbols: Fix symbol size calculation condition") +Signed-off-by: Namhyung Kim +Acked-by: Ian Rogers +Cc: Heiko Carstens +Cc: Ingo Molnar +Cc: Jiri Olsa +Cc: John Garry +Cc: Leo Yan +Cc: Mark Rutland +Cc: Masami Hiramatsu +Cc: Mathieu Poirier +Cc: Michael Ellerman +Cc: Michael Petlan +Cc: Peter Zijlstra +Cc: Song Liu +Cc: Will Deacon +Cc: linux-s390@vger.kernel.org +Cc: linuxppc-dev@lists.ozlabs.org +Link: https://lore.kernel.org/r/20220416004048.1514900-3-namhyung@kernel.org +Signed-off-by: Arnaldo Carvalho de Melo +Signed-off-by: Greg Kroah-Hartman +--- + tools/perf/util/symbol.c | 29 +++++++++++++++++++++++++---- + 1 file changed, 25 insertions(+), 4 deletions(-) + +--- a/tools/perf/util/symbol.c ++++ b/tools/perf/util/symbol.c +@@ -217,8 +217,8 @@ again: + } + } + +-void symbols__fixup_end(struct rb_root_cached *symbols, +- bool is_kallsyms __maybe_unused) ++/* Update zero-sized symbols using the address of the next symbol */ ++void symbols__fixup_end(struct rb_root_cached *symbols, bool is_kallsyms) + { + struct rb_node *nd, *prevnd = rb_first_cached(symbols); + struct symbol *curr, *prev; +@@ -232,8 +232,29 @@ void symbols__fixup_end(struct rb_root_c + prev = curr; + curr = rb_entry(nd, struct symbol, rb_node); + +- if (prev->end == prev->start || prev->end != curr->start) +- arch__symbols__fixup_end(prev, curr); ++ /* ++ * On some architecture kernel text segment start is located at ++ * some low memory address, while modules are located at high ++ * memory addresses (or vice versa). The gap between end of ++ * kernel text segment and beginning of first module's text ++ * segment is very big. Therefore do not fill this gap and do ++ * not assign it to the kernel dso map (kallsyms). ++ * ++ * In kallsyms, it determines module symbols using '[' character ++ * like in: ++ * ffffffffc1937000 T hdmi_driver_init [snd_hda_codec_hdmi] ++ */ ++ if (prev->end == prev->start) { ++ /* Last kernel/module symbol mapped to end of page */ ++ if (is_kallsyms && (!strchr(prev->name, '[') != ++ !strchr(curr->name, '['))) ++ prev->end = roundup(prev->end + 4096, 4096); ++ else ++ prev->end = curr->start; ++ ++ pr_debug4("%s sym:%s end:%#" PRIx64 "\n", ++ __func__, prev->name, prev->end); ++ } + } + + /* Last entry */ diff --git a/queue-5.10/series b/queue-5.10/series index 828b02e2b3a..cbdcb4d88ce 100644 --- a/queue-5.10/series +++ b/queue-5.10/series @@ -109,3 +109,6 @@ kasan-prevent-cpu_quarantine-corruption-when-cpu-offline-and-cache-shrink-occur- drm-i915-fix-sel_fetch_plane_-pipe_b-register-addresses.patch net-ethernet-stmmac-fix-write-to-sgmii_adapter_base.patch thermal-int340x-fix-attr.show-callback-prototype.patch +x86-cpu-load-microcode-during-restore_processor_state.patch +perf-symbol-pass-is_kallsyms-to-symbols__fixup_end.patch +perf-symbol-update-symbols__fixup_end.patch diff --git a/queue-5.10/x86-cpu-load-microcode-during-restore_processor_state.patch b/queue-5.10/x86-cpu-load-microcode-during-restore_processor_state.patch new file mode 100644 index 00000000000..0c71e77a473 --- /dev/null +++ b/queue-5.10/x86-cpu-load-microcode-during-restore_processor_state.patch @@ -0,0 +1,125 @@ +From f9e14dbbd454581061c736bf70bf5cbb15ac927c Mon Sep 17 00:00:00 2001 +From: Borislav Petkov +Date: Tue, 19 Apr 2022 09:52:41 -0700 +Subject: x86/cpu: Load microcode during restore_processor_state() + +From: Borislav Petkov + +commit f9e14dbbd454581061c736bf70bf5cbb15ac927c upstream. + +When resuming from system sleep state, restore_processor_state() +restores the boot CPU MSRs. These MSRs could be emulated by microcode. +If microcode is not loaded yet, writing to emulated MSRs leads to +unchecked MSR access error: + + ... + PM: Calling lapic_suspend+0x0/0x210 + unchecked MSR access error: WRMSR to 0x10f (tried to write 0x0...0) at rIP: ... (native_write_msr) + Call Trace: + + ? restore_processor_state + x86_acpi_suspend_lowlevel + acpi_suspend_enter + suspend_devices_and_enter + pm_suspend.cold + state_store + kobj_attr_store + sysfs_kf_write + kernfs_fop_write_iter + new_sync_write + vfs_write + ksys_write + __x64_sys_write + do_syscall_64 + entry_SYSCALL_64_after_hwframe + RIP: 0033:0x7fda13c260a7 + +To ensure microcode emulated MSRs are available for restoration, load +the microcode on the boot CPU before restoring these MSRs. + + [ Pawan: write commit message and productize it. ] + +Fixes: e2a1256b17b1 ("x86/speculation: Restore speculation related MSRs during S3 resume") +Reported-by: Kyle D. Pelton +Signed-off-by: Borislav Petkov +Signed-off-by: Pawan Gupta +Tested-by: Kyle D. Pelton +Cc: stable@vger.kernel.org +Link: https://bugzilla.kernel.org/show_bug.cgi?id=215841 +Link: https://lore.kernel.org/r/4350dfbf785cd482d3fafa72b2b49c83102df3ce.1650386317.git.pawan.kumar.gupta@linux.intel.com +Signed-off-by: Greg Kroah-Hartman +--- + arch/x86/include/asm/microcode.h | 2 ++ + arch/x86/kernel/cpu/microcode/core.c | 6 +++--- + arch/x86/power/cpu.c | 10 +++++++++- + 3 files changed, 14 insertions(+), 4 deletions(-) + +--- a/arch/x86/include/asm/microcode.h ++++ b/arch/x86/include/asm/microcode.h +@@ -133,11 +133,13 @@ extern void load_ucode_ap(void); + void reload_early_microcode(void); + extern bool get_builtin_firmware(struct cpio_data *cd, const char *name); + extern bool initrd_gone; ++void microcode_bsp_resume(void); + #else + static inline int __init microcode_init(void) { return 0; }; + static inline void __init load_ucode_bsp(void) { } + static inline void load_ucode_ap(void) { } + static inline void reload_early_microcode(void) { } ++static inline void microcode_bsp_resume(void) { } + static inline bool + get_builtin_firmware(struct cpio_data *cd, const char *name) { return false; } + #endif +--- a/arch/x86/kernel/cpu/microcode/core.c ++++ b/arch/x86/kernel/cpu/microcode/core.c +@@ -775,9 +775,9 @@ static struct subsys_interface mc_cpu_in + }; + + /** +- * mc_bp_resume - Update boot CPU microcode during resume. ++ * microcode_bsp_resume - Update boot CPU microcode during resume. + */ +-static void mc_bp_resume(void) ++void microcode_bsp_resume(void) + { + int cpu = smp_processor_id(); + struct ucode_cpu_info *uci = ucode_cpu_info + cpu; +@@ -789,7 +789,7 @@ static void mc_bp_resume(void) + } + + static struct syscore_ops mc_syscore_ops = { +- .resume = mc_bp_resume, ++ .resume = microcode_bsp_resume, + }; + + static int mc_cpu_starting(unsigned int cpu) +--- a/arch/x86/power/cpu.c ++++ b/arch/x86/power/cpu.c +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + + #ifdef CONFIG_X86_32 + __visible unsigned long saved_context_ebx; +@@ -265,11 +266,18 @@ static void notrace __restore_processor_ + x86_platform.restore_sched_clock_state(); + mtrr_bp_restore(); + perf_restore_debug_store(); +- msr_restore_context(ctxt); + + c = &cpu_data(smp_processor_id()); + if (cpu_has(c, X86_FEATURE_MSR_IA32_FEAT_CTL)) + init_ia32_feat_ctl(c); ++ ++ microcode_bsp_resume(); ++ ++ /* ++ * This needs to happen after the microcode has been updated upon resume ++ * because some of the MSRs are "emulated" in microcode. ++ */ ++ msr_restore_context(ctxt); + } + + /* Needed by apm.c */