[PATCH v4 1/4] mm: modify pte format for Svnapot
Heiko Stübner
heiko at sntech.de
Wed Aug 24 10:37:51 PDT 2022
Hi,
Am Montag, 22. August 2022, 17:34:10 CEST schrieb panqinglin2020 at iscas.ac.cn:
> From: Qinglin Pan <panqinglin2020 at iscas.ac.cn>
>
> This commit adds two erratas to enable/disable svnapot support, patches code
> dynamicly when "svnapot" is in the "riscv,isa" field of fdt and SVNAPOT
> compile option is set. It will influence the behavior of has_svnapot
> function and pte_pfn function. All code dependent on svnapot should make
> sure that has_svnapot return true firstly.
>
> Also, this commit modifies PTE definition for Svnapot, and creates some
> functions in pgtable.h to mark a PTE as napot and check if it is a Svnapot
> PTE. Until now, only 64KB napot size is supported in draft spec, so some
> macros has only 64KB version.
>
> Signed-off-by: Qinglin Pan <panqinglin2020 at iscas.ac.cn>
>
> diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
> index ed66c31e4655..c43708ae7f38 100644
> --- a/arch/riscv/Kconfig
> +++ b/arch/riscv/Kconfig
> @@ -432,6 +432,13 @@ config FPU
>
> If you don't know what to do here, say Y.
>
> +config SVNAPOT
as Connor already wrote, please make this RISCV_ISA_SVNAPOT,
and maybe also move it upwards a bit so that we get some sorting going
for all the extensions :-) .
> + bool "Svnapot support"
> + default n
> + help
> + Select if your CPU supports Svnapot and you want to enable it when
> + kernel is booting.
please make this a bit more verbose, something like:
Add support to dynamically detect the presence of the SVNAPOT
ISA-extension (Supervisor-mode: NAPOT Translation Contiguity)
and enable its usage.
[plus add a paragraph explaining what SVNAPOT helps with]
> endmenu # "Platform type"
>
> menu "Kernel features"
> diff --git a/arch/riscv/include/asm/errata_list.h b/arch/riscv/include/asm/errata_list.h
> index 19a771085781..f22723174cd9 100644
> --- a/arch/riscv/include/asm/errata_list.h
> +++ b/arch/riscv/include/asm/errata_list.h
> @@ -22,7 +22,8 @@
>
> #define CPUFEATURE_SVPBMT 0
> #define CPUFEATURE_ZICBOM 1
> -#define CPUFEATURE_NUMBER 2
> +#define CPUFEATURE_SVNAPOT 2
> +#define CPUFEATURE_NUMBER 3
>
> #ifdef __ASSEMBLY__
>
> @@ -142,6 +143,27 @@ asm volatile(ALTERNATIVE_2( \
> "r"((unsigned long)(_start) + (_size)) \
> : "a0")
>
> +#define ALT_SVNAPOT(_val) \
> +asm(ALTERNATIVE("li %0, 0", "li %0, 1", 0, \
> + CPUFEATURE_SVNAPOT, CONFIG_SVNAPOT) \
> + : "=r"(_val) :)
> +
> +#define ALT_SVNAPOT_PTE_PFN(_val, _napot_shift, _pfn_mask, _pfn_shift) \
> +asm(ALTERNATIVE("and %0, %1, %2\n\t" \
> + "srli %0, %0, %3\n\t" \
> + "nop\n\tnop\n\tnop", \
using the new-ish __nops macro might make this a tad nicer to read, see
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/arch/riscv/include/asm/errata_list.h#n122
> + "srli t3, %1, %4\n\t" \
> + "and %0, %1, %2\n\t" \
> + "srli %0, %0, %3\n\t" \
> + "sub t4, %0, t3\n\t" \
> + "and %0, %0, t4", \
> + 0, CPUFEATURE_SVNAPOT, CONFIG_SVNAPOT) \
> + : "+r"(_val) \
> + : "r"(_val), \
> + "r"(_pfn_mask), \
> + "i"(_pfn_shift), \
> + "i"(_napot_shift))
> +
> #endif /* __ASSEMBLY__ */
>
> #endif
> diff --git a/arch/riscv/include/asm/hwcap.h b/arch/riscv/include/asm/hwcap.h
> index 6f59ec64175e..e4c7ce5a7e1a 100644
> --- a/arch/riscv/include/asm/hwcap.h
> +++ b/arch/riscv/include/asm/hwcap.h
> @@ -58,6 +58,7 @@ enum riscv_isa_ext_id {
> RISCV_ISA_EXT_ZICBOM,
> RISCV_ISA_EXT_ZIHINTPAUSE,
> RISCV_ISA_EXT_SSTC,
> + RISCV_ISA_EXT_SVNAPOT,
that list is only a kernel-internal list, so we can probably keep some
sorting for extensions.
Heiko
More information about the linux-riscv
mailing list