diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 67e72bf4f91a..467a877445a8 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -602,6 +602,30 @@ 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 diff --git a/arch/riscv/include/asm/pgtable-64.h b/arch/riscv/include/asm/pgtable-64.h index 7407e36fbf7d..caf8458b344c 100644 --- a/arch/riscv/include/asm/pgtable-64.h +++ b/arch/riscv/include/asm/pgtable-64.h @@ -16,21 +16,33 @@ extern bool _pgtable_l5_enabled; #ifdef USE_EARLY_PGTABLE_LEVELS static __always_inline bool pgtable_l5_enabled(void) { + if (!IS_ENABLED(CONFIG_RISCV_ISA_SV57)) + return false; + return _pgtable_l5_enabled; } static __always_inline bool pgtable_l4_enabled(void) { + if (!IS_ENABLED(CONFIG_RISCV_ISA_SV48)) + return false; + return _pgtable_l4_enabled; } #else static __always_inline bool pgtable_l5_enabled(void) { + if (!IS_ENABLED(CONFIG_RISCV_ISA_SV57)) + return false; + return riscv_has_extension_likely(RISCV_ISA_EXT_SV57); } static __always_inline bool pgtable_l4_enabled(void) { + if (!IS_ENABLED(CONFIG_RISCV_ISA_SV48)) + return false; + return riscv_has_extension_likely(RISCV_ISA_EXT_SV48); } #endif diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c index 19e8ebf95c0c..6dd8b92fc2d6 100644 --- a/arch/riscv/mm/init.c +++ b/arch/riscv/mm/init.c @@ -844,6 +844,14 @@ static __init void set_satp_mode(uintptr_t dtb_pa) kernel_map.page_offset = PAGE_OFFSET_L5; + /* Fall back to SV48 if RISCV_ISA_SV57 isn't enabled */ + if (!IS_ENABLED(CONFIG_RISCV_ISA_SV57) && satp_mode_limit == 0) + satp_mode_limit = SATP_MODE_48; + + /* Fall back to SV39 if RISCV_ISA_SV48 isn't enabled */ + if (!IS_ENABLED(CONFIG_RISCV_ISA_SV48) && satp_mode_limit == SATP_MODE_48) + satp_mode_limit = SATP_MODE_39; + if (satp_mode_limit == SATP_MODE_48) { disable_pgtable_l5(); } else if (satp_mode_limit == SATP_MODE_39) {