[PATCH v8 3/3] riscv: mm: support Svnapot in huge vmap
Andrew Jones
ajones at ventanamicro.com
Tue Nov 29 05:18:39 PST 2022
On Mon, Nov 28, 2022 at 10:27:19AM +0800, panqinglin2020 at iscas.ac.cn wrote:
> From: Qinglin Pan <panqinglin2020 at iscas.ac.cn>
>
> As HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC is supported, we can
> implement arch_vmap_pte_range_map_size and arch_vmap_pte_supported_shift
> for Svnapot to support huge vmap about napot size.
>
> It can be tested by huge vmap used in pci driver. Huge vmalloc with svnapot
> can be tested by changing test_vmalloc module to use vmalloc_huge in it,
> and probe this module to run tests.
It'd be nice to get your changes to test_vmalloc posted where the switch
between vmalloc and vmalloc_huge is controlled by a module parameter.
>
> Signed-off-by: Qinglin Pan <panqinglin2020 at iscas.ac.cn>
>
> diff --git a/arch/riscv/include/asm/vmalloc.h b/arch/riscv/include/asm/vmalloc.h
> index 48da5371f1e9..99b89ab445e2 100644
> --- a/arch/riscv/include/asm/vmalloc.h
> +++ b/arch/riscv/include/asm/vmalloc.h
> @@ -17,6 +17,65 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot)
> return true;
> }
>
> -#endif
> +#ifdef CONFIG_RISCV_ISA_SVNAPOT
> +#include <linux/pgtable.h>
>
> +#define arch_vmap_pte_range_map_size arch_vmap_pte_range_map_size
> +static inline unsigned long arch_vmap_pte_range_map_size(unsigned long addr, unsigned long end,
> + u64 pfn, unsigned int max_page_shift)
> +{
> + unsigned long size, order;
> + unsigned long map_size = PAGE_SIZE;
> +
> + if (!has_svnapot())
> + return map_size;
> +
> + for_each_napot_order_rev(order) {
> + if (napot_cont_shift(order) > max_page_shift)
> + continue;
> +
> + size = napot_cont_size(order);
> + if (end - addr < size)
> + continue;
> +
> + if (!IS_ALIGNED(addr, size))
> + continue;
> +
> + if (!IS_ALIGNED(PFN_PHYS(pfn), size))
> + continue;
> +
> + map_size = size;
> + break;
> + }
> +
> + return map_size;
> +}
> +
> +#define arch_vmap_pte_supported_shift arch_vmap_pte_supported_shift
> +static inline int arch_vmap_pte_supported_shift(unsigned long size)
> +{
> + int shift = PAGE_SHIFT;
> + unsigned long order;
> +
> + if (!has_svnapot())
> + return shift;
> +
> + WARN_ON_ONCE(size >= PMD_SIZE);
> +
> + for_each_napot_order_rev(order) {
> + if (napot_cont_size(order) > size)
> + continue;
> +
> + if (size & napot_cont_mask(order))
> + continue;
> +
> + shift = napot_cont_shift(order);
> + break;
> + }
> +
> + return shift;
> +}
> +
> +#endif /* CONFIG_RISCV_ISA_SVNAPOT */
> +#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
> #endif /* _ASM_RISCV_VMALLOC_H */
> --
> 2.37.4
>
Reviewed-by: Andrew Jones <ajones at ventanamicro.com>
Thanks,
drew
More information about the linux-riscv
mailing list