mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00

Several architectures support text patching, but they name the header files that declare patching functions differently. Make all such headers consistently named text-patching.h and add an empty header in asm-generic for architectures that do not support text patching. Link: https://lkml.kernel.org/r/20241023162711.2579610-4-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Acked-by: Geert Uytterhoeven <geert@linux-m68k.org> # m68k Acked-by: Arnd Bergmann <arnd@arndb.de> Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Tested-by: kdevops <kdevops@lists.linux.dev> Cc: Andreas Larsson <andreas@gaisler.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Borislav Petkov (AMD) <bp@alien8.de> Cc: Brian Cain <bcain@quicinc.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Christophe Leroy <christophe.leroy@csgroup.eu> Cc: Dave Hansen <dave.hansen@linux.intel.com> Cc: Dinh Nguyen <dinguyen@kernel.org> Cc: Guo Ren <guoren@kernel.org> Cc: Helge Deller <deller@gmx.de> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: Liam R. Howlett <Liam.Howlett@Oracle.com> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Masami Hiramatsu (Google) <mhiramat@kernel.org> Cc: Matt Turner <mattst88@gmail.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Richard Weinberger <richard@nod.at> Cc: Russell King <linux@armlinux.org.uk> Cc: Song Liu <song@kernel.org> Cc: Stafford Horne <shorne@gmail.com> Cc: Steven Rostedt (Google) <rostedt@goodmis.org> Cc: Suren Baghdasaryan <surenb@google.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Uladzislau Rezki (Sony) <urezki@gmail.com> Cc: Vineet Gupta <vgupta@kernel.org> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
127 lines
3.2 KiB
C
127 lines
3.2 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* Copyright (C) 2021 Sifive.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/memory.h>
|
|
#include <linux/module.h>
|
|
#include <linux/string.h>
|
|
#include <linux/bug.h>
|
|
#include <asm/text-patching.h>
|
|
#include <asm/alternative.h>
|
|
#include <asm/vendorid_list.h>
|
|
#include <asm/errata_list.h>
|
|
#include <asm/vendor_extensions.h>
|
|
|
|
struct errata_info_t {
|
|
char name[32];
|
|
bool (*check_func)(unsigned long arch_id, unsigned long impid);
|
|
};
|
|
|
|
static bool errata_cip_453_check_func(unsigned long arch_id, unsigned long impid)
|
|
{
|
|
/*
|
|
* Affected cores:
|
|
* Architecture ID: 0x8000000000000007
|
|
* Implement ID: 0x20181004 <= impid <= 0x20191105
|
|
*/
|
|
if (arch_id != 0x8000000000000007 ||
|
|
(impid < 0x20181004 || impid > 0x20191105))
|
|
return false;
|
|
return true;
|
|
}
|
|
|
|
static bool errata_cip_1200_check_func(unsigned long arch_id, unsigned long impid)
|
|
{
|
|
/*
|
|
* Affected cores:
|
|
* Architecture ID: 0x8000000000000007 or 0x1
|
|
* Implement ID: mimpid[23:0] <= 0x200630 and mimpid != 0x01200626
|
|
*/
|
|
if (arch_id != 0x8000000000000007 && arch_id != 0x1)
|
|
return false;
|
|
if ((impid & 0xffffff) > 0x200630 || impid == 0x1200626)
|
|
return false;
|
|
|
|
#ifdef CONFIG_MMU
|
|
tlb_flush_all_threshold = 0;
|
|
#endif
|
|
|
|
return true;
|
|
}
|
|
|
|
static struct errata_info_t errata_list[ERRATA_SIFIVE_NUMBER] = {
|
|
{
|
|
.name = "cip-453",
|
|
.check_func = errata_cip_453_check_func
|
|
},
|
|
{
|
|
.name = "cip-1200",
|
|
.check_func = errata_cip_1200_check_func
|
|
},
|
|
};
|
|
|
|
static u32 __init_or_module sifive_errata_probe(unsigned long archid,
|
|
unsigned long impid)
|
|
{
|
|
int idx;
|
|
u32 cpu_req_errata = 0;
|
|
|
|
for (idx = 0; idx < ERRATA_SIFIVE_NUMBER; idx++)
|
|
if (errata_list[idx].check_func(archid, impid))
|
|
cpu_req_errata |= (1U << idx);
|
|
|
|
return cpu_req_errata;
|
|
}
|
|
|
|
static void __init_or_module warn_miss_errata(u32 miss_errata)
|
|
{
|
|
int i;
|
|
|
|
pr_warn("----------------------------------------------------------------\n");
|
|
pr_warn("WARNING: Missing the following errata may cause potential issues\n");
|
|
for (i = 0; i < ERRATA_SIFIVE_NUMBER; i++)
|
|
if (miss_errata & 0x1 << i)
|
|
pr_warn("\tSiFive Errata[%d]:%s\n", i, errata_list[i].name);
|
|
pr_warn("Please enable the corresponding Kconfig to apply them\n");
|
|
pr_warn("----------------------------------------------------------------\n");
|
|
}
|
|
|
|
void sifive_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
|
|
unsigned long archid, unsigned long impid,
|
|
unsigned int stage)
|
|
{
|
|
struct alt_entry *alt;
|
|
u32 cpu_req_errata;
|
|
u32 cpu_apply_errata = 0;
|
|
u32 tmp;
|
|
|
|
BUILD_BUG_ON(ERRATA_SIFIVE_NUMBER >= RISCV_VENDOR_EXT_ALTERNATIVES_BASE);
|
|
|
|
if (stage == RISCV_ALTERNATIVES_EARLY_BOOT)
|
|
return;
|
|
|
|
cpu_req_errata = sifive_errata_probe(archid, impid);
|
|
|
|
for (alt = begin; alt < end; alt++) {
|
|
if (alt->vendor_id != SIFIVE_VENDOR_ID)
|
|
continue;
|
|
if (alt->patch_id >= ERRATA_SIFIVE_NUMBER) {
|
|
WARN(1, "This errata id:%d is not in kernel errata list", alt->patch_id);
|
|
continue;
|
|
}
|
|
|
|
tmp = (1U << alt->patch_id);
|
|
if (cpu_req_errata & tmp) {
|
|
mutex_lock(&text_mutex);
|
|
patch_text_nosync(ALT_OLD_PTR(alt), ALT_ALT_PTR(alt),
|
|
alt->alt_len);
|
|
mutex_unlock(&text_mutex);
|
|
cpu_apply_errata |= tmp;
|
|
}
|
|
}
|
|
if (stage != RISCV_ALTERNATIVES_MODULE &&
|
|
cpu_apply_errata != cpu_req_errata)
|
|
warn_miss_errata(cpu_req_errata - cpu_apply_errata);
|
|
}
|