Skip to content

Commit 18a41b0

Browse files
tjy-zhuopsiff
authored andcommitted
sw64: add HUGE_VMAP support for c4
Enable HAVE_ARCH_HUGE_VMALLOC and HAVE_ARCH_HUGE_VMAP for the sw64 c4 architecture to allow ioremap() and vmalloc() to use huge pages. This significantly reduces TLB pressure and page table memory overhead when mapping large contiguous physical regions like PCIe BARs. Signed-off-by: Jinyu Tang <tjytimi@163.com> Signed-off-by: Gu Yuchen <guyuchen@wxiat.com> Reviewed-by: He Sheng <hesheng@wxiat.com> Signed-off-by: Gu Zitao <guzitao@wxiat.com>
1 parent 87f1b96 commit 18a41b0

4 files changed

Lines changed: 112 additions & 1 deletion

File tree

arch/sw_64/Kconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ config SW64
9393
select HAVE_ARCH_SECCOMP_FILTER
9494
select HAVE_ARCH_TRACEHOOK
9595
select HAVE_ARCH_TRANSPARENT_HUGEPAGE
96+
select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP
97+
select HAVE_ARCH_HUGE_VMAP if SUBARCH_C4
9698
select HAVE_ASM_MODVERSIONS
9799
select HAVE_C_RECORDMCOUNT
98100
select HAVE_DEBUG_BUGVERBOSE

arch/sw_64/include/asm/vmalloc.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,23 @@
22
#ifndef _ASM_SW64_VMALLOC_H
33
#define _ASM_SW64_VMALLOC_H
44

5+
#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
6+
7+
#include <asm/pgtable.h>
8+
9+
#define IOREMAP_MAX_ORDER (PUD_SHIFT)
10+
11+
#define arch_vmap_pud_supported arch_vmap_pud_supported
12+
static inline bool arch_vmap_pud_supported(pgprot_t prot)
13+
{
14+
return true;
15+
}
16+
17+
#define arch_vmap_pmd_supported arch_vmap_pmd_supported
18+
static inline bool arch_vmap_pmd_supported(pgprot_t prot)
19+
{
20+
return true;
21+
}
22+
23+
#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
524
#endif /* _ASM_SW64_VMALLOC_H */

arch/sw_64/mm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#ccflags-y := -Werror
77

8-
obj-y := init.o fault.o physaddr.o mmap.o extable.o
8+
obj-y := init.o fault.o physaddr.o mmap.o extable.o pgtable.o
99

1010
obj-$(CONFIG_SW64_KERNEL_PAGE_TABLE) += pageattr.o
1111
obj-$(CONFIG_NUMA) += numa.o

arch/sw_64/mm/pgtable.c

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
3+
#include <linux/mm.h>
4+
#include <linux/vmalloc.h>
5+
#include <asm/pgtable.h>
6+
#include <asm/tlbflush.h>
7+
8+
#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
9+
10+
int pmd_set_huge(pmd_t *pmd, phys_addr_t phys, pgprot_t prot)
11+
{
12+
pmd_t new_pmd = pfn_pmd(phys >> PAGE_SHIFT, prot);
13+
14+
new_pmd = __pmd(pmd_val(new_pmd) | _PAGE_LEAF);
15+
set_pmd(pmd, new_pmd);
16+
17+
return 1;
18+
}
19+
20+
int pmd_clear_huge(pmd_t *pmd)
21+
{
22+
if (!(pmd_val(*pmd) & _PAGE_LEAF))
23+
return 0;
24+
25+
pmd_clear(pmd);
26+
return 1;
27+
}
28+
29+
int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
30+
{
31+
pte_t *pte;
32+
33+
if (pmd_val(*pmd) & _PAGE_LEAF)
34+
return 0;
35+
36+
pte = (pte_t *)pmd_page_vaddr(*pmd);
37+
38+
pmd_clear(pmd);
39+
40+
flush_tlb_kernel_range(addr, addr + PMD_SIZE);
41+
42+
pte_free_kernel(NULL, pte);
43+
44+
return 1;
45+
}
46+
47+
int pud_set_huge(pud_t *pud, phys_addr_t phys, pgprot_t prot)
48+
{
49+
pud_t new_pud = pfn_pud(phys >> PAGE_SHIFT, prot);
50+
51+
new_pud = __pud(pud_val(new_pud) | _PAGE_LEAF);
52+
53+
set_pud(pud, new_pud);
54+
return 1;
55+
}
56+
57+
int pud_clear_huge(pud_t *pud)
58+
{
59+
if (!(pud_val(*pud) & _PAGE_LEAF))
60+
return 0;
61+
62+
pud_clear(pud);
63+
return 1;
64+
}
65+
66+
int pud_free_pmd_page(pud_t *pud, unsigned long addr)
67+
{
68+
pmd_t *pmd;
69+
int i;
70+
71+
if (pud_val(*pud) & _PAGE_LEAF)
72+
return 0;
73+
74+
pmd = (pmd_t *)pud_page_vaddr(*pud);
75+
pud_clear(pud);
76+
flush_tlb_kernel_range(addr, addr + PUD_SIZE);
77+
78+
for (i = 0; i < PTRS_PER_PMD; i++) {
79+
if (!pmd_none(pmd[i])) {
80+
pte_t *pte = (pte_t *)pmd_page_vaddr(pmd[i]);
81+
82+
pte_free_kernel(NULL, pte);
83+
}
84+
}
85+
86+
pmd_free(NULL, pmd);
87+
88+
return 1;
89+
}
90+
#endif

0 commit comments

Comments
 (0)