Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions arch/riscv/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ config RISCV
select PCI_ECAM if (ACPI && PCI)
select PCI_MSI if PCI
select RELOCATABLE if !MMU && !PHYS_RAM_BASE_FIXED
select RISCV_ALTERNATIVE
select RISCV_ALTERNATIVE_EARLY if 64BIT
select RISCV_APLIC
select RISCV_IMSIC
select RISCV_INTC
Expand Down Expand Up @@ -539,17 +539,8 @@ config RISCV_COMBO_SPINLOCKS

endchoice

config RISCV_ALTERNATIVE
bool
help
This Kconfig allows the kernel to automatically patch the
erratum or cpufeature required by the execution platform at run
time. The code patching overhead is minimal, as it's only done
once at boot and once on each module load.

config RISCV_ALTERNATIVE_EARLY
bool
depends on RISCV_ALTERNATIVE
help
Allows early patching of the kernel for special errata

Expand Down Expand Up @@ -578,7 +569,6 @@ config RISCV_ISA_SUPM
config RISCV_ISA_SVNAPOT
bool "Svnapot extension support for supervisor mode NAPOT pages"
depends on 64BIT && MMU
depends on RISCV_ALTERNATIVE
default y
help
Enable support for the Svnapot ISA-extension when it is detected
Expand Down Expand Up @@ -612,10 +602,33 @@ config RISCV_ISA_SSQOSID
cache partitioning scheme and use the MCID to track how much
cache a process, or a group of processes, is using.

config RISCV_ISA_SV48
bool "Page-Based 48-bit Virtual-Memory System"
depends on 64BIT
default y
help
Add support for the Page-Based 48-bit Virtual-Memory System.

Enable this option for systems for which a 39-bit virtual address
space is insufficient. But if 39-bit is enough, disabling this
option will result in smaller kernel size and slighly better
performance.

config RISCV_ISA_SV57
bool "Page-Based 57-bit Virtual-Memory System"
depends on 64BIT
default y
help
Add support for the Page-Based 57-bit Virtual-Memory System.

Enable this option for systems for which a 48-bit virtual address
space is insufficient. But if 48-bit is enough, disabling this
option will result in smaller kernel size and slighly better
performance.

config RISCV_ISA_SVPBMT
bool "Svpbmt extension support for supervisor mode page-based memory types"
depends on 64BIT && MMU
depends on RISCV_ALTERNATIVE
default y
help
Add support for the Svpbmt ISA-extension (Supervisor-mode:
Expand Down Expand Up @@ -685,7 +698,6 @@ config RISCV_ISA_V_PREEMPTIVE

config RISCV_ISA_ZAWRS
bool "Zawrs extension support for more efficient busy waiting"
depends on RISCV_ALTERNATIVE
default y
help
The Zawrs extension defines instructions to be used in polling loops
Expand All @@ -704,7 +716,6 @@ config TOOLCHAIN_HAS_ZABHA
config RISCV_ISA_ZABHA
bool "Zabha extension support for atomic byte/halfword operations"
depends on TOOLCHAIN_HAS_ZABHA
depends on RISCV_ALTERNATIVE
default y
help
Enable the use of the Zabha ISA-extension to implement kernel
Expand All @@ -721,7 +732,6 @@ config TOOLCHAIN_HAS_ZACAS

config RISCV_ISA_ZACAS
bool "Zacas extension support for atomic CAS"
depends on RISCV_ALTERNATIVE
default y
help
Enable the use of the Zacas ISA-extension to implement kernel atomic
Expand Down Expand Up @@ -766,7 +776,6 @@ config RISCV_ISA_ZBA

config RISCV_ISA_ZBB
bool "Zbb extension support for bit manipulation instructions"
depends on RISCV_ALTERNATIVE
default y
help
Add support for enabling optimisations in the kernel when the
Expand All @@ -791,7 +800,6 @@ config RISCV_ISA_ZBC
bool "Zbc extension support for carry-less multiplication instructions"
depends on TOOLCHAIN_HAS_ZBC
depends on MMU
depends on RISCV_ALTERNATIVE
default y
help
Adds support to dynamically detect the presence of the Zbc
Expand All @@ -813,7 +821,6 @@ config TOOLCHAIN_HAS_ZBKB
config RISCV_ISA_ZBKB
bool "Zbkb extension support for bit manipulation instructions"
depends on TOOLCHAIN_HAS_ZBKB
depends on RISCV_ALTERNATIVE
default y
help
Adds support to dynamically detect the presence of the ZBKB
Expand All @@ -827,7 +834,6 @@ config RISCV_ISA_ZBKB
config RISCV_ISA_ZICBOM
bool "Zicbom extension support for non-coherent DMA operation"
depends on MMU
depends on RISCV_ALTERNATIVE
default y
select RISCV_DMA_NONCOHERENT
select DMA_DIRECT_REMAP
Expand All @@ -843,7 +849,6 @@ config RISCV_ISA_ZICBOM

config RISCV_ISA_ZICBOZ
bool "Zicboz extension support for faster zeroing of memory"
depends on RISCV_ALTERNATIVE
default y
help
Enable the use of the Zicboz extension (cbo.zero instruction)
Expand All @@ -856,7 +861,6 @@ config RISCV_ISA_ZICBOZ
config RISCV_ISA_ZICBOP
bool "Zicbop extension support for cache block prefetch"
depends on MMU
depends on RISCV_ALTERNATIVE
default y
help
Adds support to dynamically detect the presence of the ZICBOP
Expand All @@ -871,7 +875,6 @@ config RISCV_ISA_ZICBOP
config RISCV_ISA_SVRSW60T59B
bool "Svrsw60t59b extension support for using PTE bits 60 and 59"
depends on MMU && 64BIT
depends on RISCV_ALTERNATIVE
default y
help
Adds support to dynamically detect the presence of the Svrsw60t59b
Expand Down Expand Up @@ -1204,7 +1207,6 @@ config RISCV_USER_CFI
bool "riscv userspace control flow integrity"
depends on 64BIT && MMU && \
$(cc-option,-mabi=lp64 -march=rv64ima_zicfiss_zicfilp -fcf-protection=full)
depends on RISCV_ALTERNATIVE
select RISCV_SBI
select ARCH_HAS_USER_SHADOW_STACK
select ARCH_USES_HIGH_VMA_FLAGS
Expand Down
5 changes: 1 addition & 4 deletions arch/riscv/Kconfig.errata
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ menu "CPU errata selection"

config ERRATA_ANDES
bool "Andes AX45MP errata"
depends on RISCV_ALTERNATIVE && RISCV_SBI
depends on RISCV_SBI
help
All Andes errata Kconfig depend on this Kconfig. Disabling
this Kconfig will disable all Andes errata. Please say "Y"
Expand All @@ -23,7 +23,6 @@ config ERRATA_ANDES_CMO

config ERRATA_MIPS
bool "MIPS errata"
depends on RISCV_ALTERNATIVE
help
All MIPS errata Kconfig depend on this Kconfig. Disabling
this Kconfig will disable all MIPS errata. Please say "Y"
Expand All @@ -46,7 +45,6 @@ config ERRATA_MIPS_P8700_PAUSE_OPCODE

config ERRATA_SIFIVE
bool "SiFive errata"
depends on RISCV_ALTERNATIVE
help
All SiFive errata Kconfig depend on this Kconfig. Disabling
this Kconfig will disable all SiFive errata. Please say "Y"
Expand Down Expand Up @@ -98,7 +96,6 @@ config ERRATA_STARFIVE_JH7100

config ERRATA_THEAD
bool "T-HEAD errata"
depends on RISCV_ALTERNATIVE
help
All T-HEAD errata Kconfig depend on this Kconfig. Disabling
this Kconfig will disable all T-HEAD errata. Please say "Y"
Expand Down
24 changes: 0 additions & 24 deletions arch/riscv/include/asm/alternative-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
#ifndef __ASM_ALTERNATIVE_MACROS_H
#define __ASM_ALTERNATIVE_MACROS_H

#ifdef CONFIG_RISCV_ALTERNATIVE

#ifdef __ASSEMBLER__

.macro ALT_ENTRY oldptr newptr vendor_id patch_id new_len
Expand Down Expand Up @@ -108,28 +106,6 @@
__ALTERNATIVE_CFG_2(old_c, new_c_1, vendor_id_1, patch_id_1, IS_ENABLED(CONFIG_k_1), \
new_c_2, vendor_id_2, patch_id_2, IS_ENABLED(CONFIG_k_2))

#else /* CONFIG_RISCV_ALTERNATIVE */
#ifdef __ASSEMBLER__

.macro ALTERNATIVE_CFG old_c
\old_c
.endm

#define __ALTERNATIVE_CFG(old_c, ...) ALTERNATIVE_CFG old_c
#define __ALTERNATIVE_CFG_2(old_c, ...) ALTERNATIVE_CFG old_c

#else /* !__ASSEMBLER__ */

#define __ALTERNATIVE_CFG(old_c, ...) old_c "\n"
#define __ALTERNATIVE_CFG_2(old_c, ...) old_c "\n"

#endif /* __ASSEMBLER__ */

#define _ALTERNATIVE_CFG(old_c, ...) __ALTERNATIVE_CFG(old_c)
#define _ALTERNATIVE_CFG_2(old_c, ...) __ALTERNATIVE_CFG_2(old_c)

#endif /* CONFIG_RISCV_ALTERNATIVE */

/*
* Usage:
* ALTERNATIVE(old_content, new_content, vendor_id, patch_id, CONFIG_k)
Expand Down
12 changes: 1 addition & 11 deletions arch/riscv/include/asm/alternative.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

#ifndef __ASSEMBLER__

#ifdef CONFIG_RISCV_ALTERNATIVE

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/types.h>
Expand All @@ -35,7 +33,7 @@ void __init apply_early_boot_alternatives(void);
void apply_module_alternatives(void *start, size_t length);

void riscv_alternative_fix_offsets(void *alt_ptr, unsigned int len,
int patch_offset);
int patch_offset, bool early);

struct alt_entry {
s32 old_offset; /* offset relative to original instruction or data */
Expand All @@ -61,13 +59,5 @@ void thead_errata_patch_func(struct alt_entry *begin, struct alt_entry *end,
void riscv_cpufeature_patch_func(struct alt_entry *begin, struct alt_entry *end,
unsigned int stage);

#else /* CONFIG_RISCV_ALTERNATIVE */

static inline void apply_boot_alternatives(void) { }
static inline void apply_early_boot_alternatives(void) { }
static inline void apply_module_alternatives(void *start, size_t length) { }

#endif /* CONFIG_RISCV_ALTERNATIVE */

#endif
#endif
10 changes: 2 additions & 8 deletions arch/riscv/include/asm/cpufeature-macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,14 @@ static __always_inline bool riscv_has_extension_unlikely(const unsigned long ext
{
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");

if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE))
return __riscv_has_extension_unlikely(STANDARD_EXT, ext);

return __riscv_isa_extension_available(NULL, ext);
return __riscv_has_extension_unlikely(STANDARD_EXT, ext);
}

static __always_inline bool riscv_has_extension_likely(const unsigned long ext)
{
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");

if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE))
return __riscv_has_extension_likely(STANDARD_EXT, ext);

return __riscv_isa_extension_available(NULL, ext);
return __riscv_has_extension_likely(STANDARD_EXT, ext);
}

#endif /* _ASM_CPUFEATURE_MACROS_H */
8 changes: 4 additions & 4 deletions arch/riscv/include/asm/cpufeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ extern const struct seq_operations cpuinfo_op;
/* Per-cpu ISA extensions. */
extern struct riscv_isainfo hart_isa[NR_CPUS];

extern DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX);

extern u32 thead_vlenb_of;

void __init riscv_user_isa_enable(void);
Expand Down Expand Up @@ -134,8 +136,7 @@ static __always_inline bool riscv_cpu_has_extension_likely(int cpu, const unsign
{
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");

if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) &&
__riscv_has_extension_likely(STANDARD_EXT, ext))
if (__riscv_has_extension_likely(STANDARD_EXT, ext))
return true;

return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
Expand All @@ -145,8 +146,7 @@ static __always_inline bool riscv_cpu_has_extension_unlikely(int cpu, const unsi
{
compiletime_assert(ext < RISCV_ISA_EXT_MAX, "ext must be < RISCV_ISA_EXT_MAX");

if (IS_ENABLED(CONFIG_RISCV_ALTERNATIVE) &&
__riscv_has_extension_unlikely(STANDARD_EXT, ext))
if (__riscv_has_extension_unlikely(STANDARD_EXT, ext))
return true;

return __riscv_isa_extension_available(hart_isa[cpu].isa, ext);
Expand Down
2 changes: 2 additions & 0 deletions arch/riscv/include/asm/hwcap.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
#define RISCV_ISA_EXT_ZICCAMOA 113
#define RISCV_ISA_EXT_ZICCIF 114
#define RISCV_ISA_EXT_ZA64RS 115
#define RISCV_ISA_EXT_SV48 116
#define RISCV_ISA_EXT_SV57 117

#define RISCV_ISA_EXT_XLINUXENVCFG 127

Expand Down
14 changes: 7 additions & 7 deletions arch/riscv/include/asm/pgalloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)

static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)
{
if (pgtable_l4_enabled) {
if (pgtable_l4_enabled()) {
unsigned long pfn = virt_to_pfn(pud);

set_p4d(p4d, __p4d((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE));
Expand All @@ -51,7 +51,7 @@ static inline void p4d_populate(struct mm_struct *mm, p4d_t *p4d, pud_t *pud)
static inline void p4d_populate_safe(struct mm_struct *mm, p4d_t *p4d,
pud_t *pud)
{
if (pgtable_l4_enabled) {
if (pgtable_l4_enabled()) {
unsigned long pfn = virt_to_pfn(pud);

set_p4d_safe(p4d,
Expand All @@ -61,7 +61,7 @@ static inline void p4d_populate_safe(struct mm_struct *mm, p4d_t *p4d,

static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, p4d_t *p4d)
{
if (pgtable_l5_enabled) {
if (pgtable_l5_enabled()) {
unsigned long pfn = virt_to_pfn(p4d);

set_pgd(pgd, __pgd((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE));
Expand All @@ -71,7 +71,7 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, p4d_t *p4d)
static inline void pgd_populate_safe(struct mm_struct *mm, pgd_t *pgd,
p4d_t *p4d)
{
if (pgtable_l5_enabled) {
if (pgtable_l5_enabled()) {
unsigned long pfn = virt_to_pfn(p4d);

set_pgd_safe(pgd,
Expand All @@ -82,21 +82,21 @@ static inline void pgd_populate_safe(struct mm_struct *mm, pgd_t *pgd,
#define pud_free pud_free
static inline void pud_free(struct mm_struct *mm, pud_t *pud)
{
if (pgtable_l4_enabled)
if (pgtable_l4_enabled())
__pud_free(mm, pud);
}

static inline void __pud_free_tlb(struct mmu_gather *tlb, pud_t *pud,
unsigned long addr)
{
if (pgtable_l4_enabled)
if (pgtable_l4_enabled())
tlb_remove_ptdesc(tlb, virt_to_ptdesc(pud));
}

static inline void __p4d_free_tlb(struct mmu_gather *tlb, p4d_t *p4d,
unsigned long addr)
{
if (pgtable_l5_enabled)
if (pgtable_l5_enabled())
tlb_remove_ptdesc(tlb, virt_to_ptdesc(p4d));
}
#endif /* __PAGETABLE_PMD_FOLDED */
Expand Down
4 changes: 2 additions & 2 deletions arch/riscv/include/asm/pgtable-32.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
_PAGE_WRITE | _PAGE_EXEC | \
_PAGE_USER | _PAGE_GLOBAL))

static const __maybe_unused int pgtable_l4_enabled;
static const __maybe_unused int pgtable_l5_enabled;
static inline bool pgtable_l4_enabled(void) { return false; }
static inline bool pgtable_l5_enabled(void) { return false; }

#endif /* _ASM_RISCV_PGTABLE_32_H */
Loading
Loading