[PATCH] riscv: mm: check the SV39 rule

Alexandre Ghiti alex at ghiti.fr
Mon Sep 30 00:46:14 PDT 2024


Hi Cheng,

On 28/09/2024 17:52, Cheng Chao wrote:
> SV39 rule: the address of bits[63..39] should be the same as bit[38],
> it is easy to violate if configure PAGE_OFFSET too small.
> for instance, PAGE_OFFSET=0xffffffc0_0000_0000,


Out of curiosity, why do you try to modify the current memory layout?


> the FIXADDR_START will be the 0xfffffffb0_xxxx_xxxx,
> bit[39] == 0'b1, bit[38] == 0'b0, when access the FIXADDR,
> which cause the page fault.
> It's difficult to debug, check it when compile is necessary.
>
> Signed-off-by: Cheng Chao <cs.os.kernel at gmail.com>
> ---
>   arch/riscv/mm/init.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/mm/init.c b/arch/riscv/mm/init.c
> index bfa2dea95354..a5fb3fc2b2db 100644
> --- a/arch/riscv/mm/init.c
> +++ b/arch/riscv/mm/init.c
> @@ -119,7 +119,7 @@ static inline void print_mlt(char *name, unsigned long b, unsigned long t)
>   
>   static inline void print_ml(char *name, unsigned long b, unsigned long t)
>   {
> -	unsigned long diff = t - b;
> +	unsigned long diff = t - b + 1;
>   
>   	if (IS_ENABLED(CONFIG_64BIT) && (diff >> LOG2_SZ_1T) >= 10)
>   		print_mlt(name, b, t);
> @@ -1387,6 +1387,12 @@ static void __init arch_reserve_crashkernel(void)
>   
>   void __init paging_init(void)
>   {
> +#ifdef CONFIG_64BIT
> +	BUILD_BUG_ON_MSG((VA_BITS == VA_BITS_SV39) &&


VA_BITS is determined at runtime, either by setting "noXlvl" on the 
kernel command line or by probing the HW capabilities, so the above 
can't be determined at build time, or am I missing something?


> +			(((FIXADDR_START & BIT(39)) >> 39)
> +			 != ((FIXADDR_START & BIT(38)) >> 38)),
> +			"violate SV39 rule: bits[63..39] should be same as bit[38]");
> +#endif
>   	setup_bootmem();
>   	setup_vm_final();
>   


Thanks,

Alex




More information about the linux-riscv mailing list