Skip to content

Commit ce17347

Browse files
PanQLpalmer-dabbelt
authored andcommitted
riscv: mm: support Svnapot in huge vmap
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 test_vmalloc with [1] applied, and probe this module to run fix_size_alloc_test with use_huge true. [1]https://lore.kernel.org/all/20221212055657.698420-1-panqinglin2020@iscas.ac.cn/ Signed-off-by: Qinglin Pan <panqinglin00@gmail.com> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Acked-by: Conor Dooley <conor.dooley@microchip.com> Link: https://lore.kernel.org/r/20230209131647.17245-4-panqinglin00@gmail.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent 82a1a1f commit ce17347

1 file changed

Lines changed: 60 additions & 1 deletion

File tree

arch/riscv/include/asm/vmalloc.h

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,65 @@ static inline bool arch_vmap_pmd_supported(pgprot_t prot)
1717
return true;
1818
}
1919

20-
#endif
20+
#ifdef CONFIG_RISCV_ISA_SVNAPOT
21+
#include <linux/pgtable.h>
2122

23+
#define arch_vmap_pte_range_map_size arch_vmap_pte_range_map_size
24+
static inline unsigned long arch_vmap_pte_range_map_size(unsigned long addr, unsigned long end,
25+
u64 pfn, unsigned int max_page_shift)
26+
{
27+
unsigned long map_size = PAGE_SIZE;
28+
unsigned long size, order;
29+
30+
if (!has_svnapot())
31+
return map_size;
32+
33+
for_each_napot_order_rev(order) {
34+
if (napot_cont_shift(order) > max_page_shift)
35+
continue;
36+
37+
size = napot_cont_size(order);
38+
if (end - addr < size)
39+
continue;
40+
41+
if (!IS_ALIGNED(addr, size))
42+
continue;
43+
44+
if (!IS_ALIGNED(PFN_PHYS(pfn), size))
45+
continue;
46+
47+
map_size = size;
48+
break;
49+
}
50+
51+
return map_size;
52+
}
53+
54+
#define arch_vmap_pte_supported_shift arch_vmap_pte_supported_shift
55+
static inline int arch_vmap_pte_supported_shift(unsigned long size)
56+
{
57+
int shift = PAGE_SHIFT;
58+
unsigned long order;
59+
60+
if (!has_svnapot())
61+
return shift;
62+
63+
WARN_ON_ONCE(size >= PMD_SIZE);
64+
65+
for_each_napot_order_rev(order) {
66+
if (napot_cont_size(order) > size)
67+
continue;
68+
69+
if (!IS_ALIGNED(size, napot_cont_size(order)))
70+
continue;
71+
72+
shift = napot_cont_shift(order);
73+
break;
74+
}
75+
76+
return shift;
77+
}
78+
79+
#endif /* CONFIG_RISCV_ISA_SVNAPOT */
80+
#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
2281
#endif /* _ASM_RISCV_VMALLOC_H */

0 commit comments

Comments
 (0)