linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC
@ 2022-10-08 14:05 Liu Shixin
  2022-10-08 14:05 ` [PATCH v2 1/2] riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT Liu Shixin
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Liu Shixin @ 2022-10-08 14:05 UTC (permalink / raw)
  To: Conor Dooley, Kefeng Wang, Jonathan Corbet, Paul Walmsley,
	Palmer Dabbelt, Albert Ou
  Cc: linux-doc, linux-kernel, linux-riscv, Liu Shixin

Since riscv64 has already support SATP_MODE_57 by default, it is time to
support more hugepage-related features. These two patches will enable
HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC.

v1->v2: Fix the build error reported by kernel-test.

Liu Shixin (2):
  riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT
  riscv: Enable HAVE_ARCH_HUGE_VMALLOC for 64BIT

 .../features/vm/huge-vmap/arch-support.txt    |  2 +-
 arch/riscv/Kconfig                            |  2 +
 arch/riscv/include/asm/vmalloc.h              | 18 ++++
 arch/riscv/mm/Makefile                        |  1 +
 arch/riscv/mm/pgtable.c                       | 83 +++++++++++++++++++
 5 files changed, 105 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/mm/pgtable.c

-- 
2.25.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH v2 1/2] riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT
  2022-10-08 14:05 [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC Liu Shixin
@ 2022-10-08 14:05 ` Liu Shixin
  2022-10-08 14:05 ` [PATCH v2 2/2] riscv: Enable HAVE_ARCH_HUGE_VMALLOC " Liu Shixin
  2022-10-11 12:39 ` [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC Björn Töpel
  2 siblings, 0 replies; 5+ messages in thread
From: Liu Shixin @ 2022-10-08 14:05 UTC (permalink / raw)
  To: Conor Dooley, Kefeng Wang, Jonathan Corbet, Paul Walmsley,
	Palmer Dabbelt, Albert Ou
  Cc: linux-doc, linux-kernel, linux-riscv, Liu Shixin

This sets the HAVE_ARCH_HUGE_VMAP option, and defines the required
page table functions. With this feature, ioremap area will be mapped with
huge page granularity according to its actual size. This feature can be
disabled by kernel parameter "nohugeiomap".

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 .../features/vm/huge-vmap/arch-support.txt    |  2 +-
 arch/riscv/Kconfig                            |  1 +
 arch/riscv/include/asm/vmalloc.h              | 18 ++++
 arch/riscv/mm/Makefile                        |  1 +
 arch/riscv/mm/pgtable.c                       | 83 +++++++++++++++++++
 5 files changed, 104 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/mm/pgtable.c

diff --git a/Documentation/features/vm/huge-vmap/arch-support.txt b/Documentation/features/vm/huge-vmap/arch-support.txt
index 13b4940e0c3a..7274a4b15bcc 100644
--- a/Documentation/features/vm/huge-vmap/arch-support.txt
+++ b/Documentation/features/vm/huge-vmap/arch-support.txt
@@ -21,7 +21,7 @@
     |    openrisc: | TODO |
     |      parisc: | TODO |
     |     powerpc: |  ok  |
-    |       riscv: | TODO |
+    |       riscv: |  ok  |
     |        s390: | TODO |
     |          sh: | TODO |
     |       sparc: | TODO |
diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index 70c1c5010378..a4d597203bd9 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -70,6 +70,7 @@ config RISCV
 	select GENERIC_TIME_VSYSCALL if MMU && 64BIT
 	select GENERIC_VDSO_TIME_NS if HAVE_GENERIC_VDSO
 	select HAVE_ARCH_AUDITSYSCALL
+	select HAVE_ARCH_HUGE_VMAP if MMU && 64BIT && !XIP_KERNEL
 	select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL
 	select HAVE_ARCH_JUMP_LABEL_RELATIVE if !XIP_KERNEL
 	select HAVE_ARCH_KASAN if MMU && 64BIT
diff --git a/arch/riscv/include/asm/vmalloc.h b/arch/riscv/include/asm/vmalloc.h
index ff9abc00d139..48da5371f1e9 100644
--- a/arch/riscv/include/asm/vmalloc.h
+++ b/arch/riscv/include/asm/vmalloc.h
@@ -1,4 +1,22 @@
 #ifndef _ASM_RISCV_VMALLOC_H
 #define _ASM_RISCV_VMALLOC_H
 
+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+
+#define IOREMAP_MAX_ORDER (PUD_SHIFT)
+
+#define arch_vmap_pud_supported arch_vmap_pud_supported
+static inline bool arch_vmap_pud_supported(pgprot_t prot)
+{
+	return true;
+}
+
+#define arch_vmap_pmd_supported arch_vmap_pmd_supported
+static inline bool arch_vmap_pmd_supported(pgprot_t prot)
+{
+	return true;
+}
+
+#endif
+
 #endif /* _ASM_RISCV_VMALLOC_H */
diff --git a/arch/riscv/mm/Makefile b/arch/riscv/mm/Makefile
index d76aabf4b94d..ce7f121ad2dc 100644
--- a/arch/riscv/mm/Makefile
+++ b/arch/riscv/mm/Makefile
@@ -13,6 +13,7 @@ obj-y += extable.o
 obj-$(CONFIG_MMU) += fault.o pageattr.o
 obj-y += cacheflush.o
 obj-y += context.o
+obj-y += pgtable.o
 
 ifeq ($(CONFIG_MMU),y)
 obj-$(CONFIG_SMP) += tlbflush.o
diff --git a/arch/riscv/mm/pgtable.c b/arch/riscv/mm/pgtable.c
new file mode 100644
index 000000000000..6645ead1a7c1
--- /dev/null
+++ b/arch/riscv/mm/pgtable.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <asm/pgalloc.h>
+#include <linux/gfp.h>
+#include <linux/kernel.h>
+#include <linux/pgtable.h>
+
+#ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
+int p4d_set_huge(p4d_t *p4d, phys_addr_t addr, pgprot_t prot)
+{
+	return 0;
+}
+
+void p4d_clear_huge(p4d_t *p4d)
+{
+}
+
+int pud_set_huge(pud_t *pud, phys_addr_t phys, pgprot_t prot)
+{
+	pud_t new_pud = pfn_pud(__phys_to_pfn(phys), prot);
+
+	set_pud(pud, new_pud);
+	return 1;
+}
+
+int pud_clear_huge(pud_t *pud)
+{
+	if (!pud_leaf(READ_ONCE(*pud)))
+		return 0;
+	pud_clear(pud);
+	return 1;
+}
+
+int pud_free_pmd_page(pud_t *pud, unsigned long addr)
+{
+	pmd_t *pmd = pud_pgtable(*pud);
+	int i;
+
+	pud_clear(pud);
+
+	flush_tlb_kernel_range(addr, addr + PUD_SIZE);
+
+	for (i = 0; i < PTRS_PER_PMD; i++) {
+		if (!pmd_none(pmd[i])) {
+			pte_t *pte = (pte_t *)pmd_page_vaddr(pmd[i]);
+
+			pte_free_kernel(NULL, pte);
+		}
+	}
+
+	pmd_free(NULL, pmd);
+
+	return 1;
+}
+
+int pmd_set_huge(pmd_t *pmd, phys_addr_t phys, pgprot_t prot)
+{
+	pmd_t new_pmd = pfn_pmd(__phys_to_pfn(phys), prot);
+
+	set_pmd(pmd, new_pmd);
+	return 1;
+}
+
+int pmd_clear_huge(pmd_t *pmd)
+{
+	if (!pmd_leaf(READ_ONCE(*pmd)))
+		return 0;
+	pmd_clear(pmd);
+	return 1;
+}
+
+int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)
+{
+	pte_t *pte = (pte_t *)pmd_page_vaddr(*pmd);
+
+	pmd_clear(pmd);
+
+	flush_tlb_kernel_range(addr, addr + PMD_SIZE);
+	pte_free_kernel(NULL, pte);
+	return 1;
+}
+
+#endif /* CONFIG_HAVE_ARCH_HUGE_VMAP */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2 2/2] riscv: Enable HAVE_ARCH_HUGE_VMALLOC for 64BIT
  2022-10-08 14:05 [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC Liu Shixin
  2022-10-08 14:05 ` [PATCH v2 1/2] riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT Liu Shixin
@ 2022-10-08 14:05 ` Liu Shixin
  2022-10-11 12:39 ` [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC Björn Töpel
  2 siblings, 0 replies; 5+ messages in thread
From: Liu Shixin @ 2022-10-08 14:05 UTC (permalink / raw)
  To: Conor Dooley, Kefeng Wang, Jonathan Corbet, Paul Walmsley,
	Palmer Dabbelt, Albert Ou
  Cc: linux-doc, linux-kernel, linux-riscv, Liu Shixin

After we support HAVE_ARCH_HUGE_VMAP, we can now enbale HAVE_ARCH_HUGE_VMALLOC
too. This feature has been used in kvmalloc and alloc_large_system_hash
for now. This feature can be disabled by kernel parameters "nohugevmalloc".

Signed-off-by: Liu Shixin <liushixin2@huawei.com>
---
 arch/riscv/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index a4d597203bd9..fded181c9e50 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -70,6 +70,7 @@ config RISCV
 	select GENERIC_TIME_VSYSCALL if MMU && 64BIT
 	select GENERIC_VDSO_TIME_NS if HAVE_GENERIC_VDSO
 	select HAVE_ARCH_AUDITSYSCALL
+	select HAVE_ARCH_HUGE_VMALLOC if HAVE_ARCH_HUGE_VMAP
 	select HAVE_ARCH_HUGE_VMAP if MMU && 64BIT && !XIP_KERNEL
 	select HAVE_ARCH_JUMP_LABEL if !XIP_KERNEL
 	select HAVE_ARCH_JUMP_LABEL_RELATIVE if !XIP_KERNEL
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC
  2022-10-08 14:05 [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC Liu Shixin
  2022-10-08 14:05 ` [PATCH v2 1/2] riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT Liu Shixin
  2022-10-08 14:05 ` [PATCH v2 2/2] riscv: Enable HAVE_ARCH_HUGE_VMALLOC " Liu Shixin
@ 2022-10-11 12:39 ` Björn Töpel
  2022-10-12  2:47   ` Liu Shixin
  2 siblings, 1 reply; 5+ messages in thread
From: Björn Töpel @ 2022-10-11 12:39 UTC (permalink / raw)
  To: Liu Shixin, Conor Dooley, Kefeng Wang, Jonathan Corbet,
	Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: linux-doc, linux-kernel, linux-riscv, Liu Shixin

Liu Shixin <liushixin2@huawei.com> writes:

> Since riscv64 has already support SATP_MODE_57 by default, it is time to
> support more hugepage-related features. These two patches will enable
> HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC.
>

Just a note; The HP support does not require sv57. Pmd/Mega- and
pud/gigapages work for sv39 and sv48 as well.

> v1->v2: Fix the build error reported by kernel-test.
>
> Liu Shixin (2):
>   riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT
>   riscv: Enable HAVE_ARCH_HUGE_VMALLOC for 64BIT
>
>  .../features/vm/huge-vmap/arch-support.txt    |  2 +-
>  arch/riscv/Kconfig                            |  2 +
>  arch/riscv/include/asm/vmalloc.h              | 18 ++++
>  arch/riscv/mm/Makefile                        |  1 +
>  arch/riscv/mm/pgtable.c                       | 83 +++++++++++++++++++
>  5 files changed, 105 insertions(+), 1 deletion(-)
>  create mode 100644 arch/riscv/mm/pgtable.c
>

I've taken this series for a spin, and tested huge pud pages via
ioremap(), and huge pmd pages via vmalloc_huge() on qemu for sv39, sv48,
and sv57.

Patch 2 have a spelling error in the commit message: "enbale" vs
"enable".

Fix up the spelling error in patch 2, and after that feel free to add
for the whole series:

Reviewed-by: Björn Töpel <bjorn@kernel.org>
Tested-by: Björn Töpel <bjorn@kernel.org>


Nice work!
Björn


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC
  2022-10-11 12:39 ` [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC Björn Töpel
@ 2022-10-12  2:47   ` Liu Shixin
  0 siblings, 0 replies; 5+ messages in thread
From: Liu Shixin @ 2022-10-12  2:47 UTC (permalink / raw)
  To: Björn Töpel, Conor Dooley, Kefeng Wang,
	Jonathan Corbet, Paul Walmsley, Palmer Dabbelt, Albert Ou
  Cc: linux-doc, linux-kernel, linux-riscv

On 2022/10/11 20:39, Björn Töpel wrote:
> Liu Shixin <liushixin2@huawei.com> writes:
>
>> Since riscv64 has already support SATP_MODE_57 by default, it is time to
>> support more hugepage-related features. These two patches will enable
>> HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC.
>>
> Just a note; The HP support does not require sv57. Pmd/Mega- and
> pud/gigapages work for sv39 and sv48 as well.
Yes, I didn't explain it clearly. I will rewrite it.
>> v1->v2: Fix the build error reported by kernel-test.
>>
>> Liu Shixin (2):
>>   riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT
>>   riscv: Enable HAVE_ARCH_HUGE_VMALLOC for 64BIT
>>
>>  .../features/vm/huge-vmap/arch-support.txt    |  2 +-
>>  arch/riscv/Kconfig                            |  2 +
>>  arch/riscv/include/asm/vmalloc.h              | 18 ++++
>>  arch/riscv/mm/Makefile                        |  1 +
>>  arch/riscv/mm/pgtable.c                       | 83 +++++++++++++++++++
>>  5 files changed, 105 insertions(+), 1 deletion(-)
>>  create mode 100644 arch/riscv/mm/pgtable.c
>>
> I've taken this series for a spin, and tested huge pud pages via
> ioremap(), and huge pmd pages via vmalloc_huge() on qemu for sv39, sv48,
> and sv57.
>
> Patch 2 have a spelling error in the commit message: "enbale" vs
> "enable".
>
> Fix up the spelling error in patch 2, and after that feel free to add
> for the whole series:
>
> Reviewed-by: Björn Töpel <bjorn@kernel.org>
> Tested-by: Björn Töpel <bjorn@kernel.org>
>
Thanks for your review and test. I will fix the above errors immediately.
> Nice work!
> Björn
>
> .
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-10-12  2:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-08 14:05 [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC Liu Shixin
2022-10-08 14:05 ` [PATCH v2 1/2] riscv: Enable HAVE_ARCH_HUGE_VMAP for 64BIT Liu Shixin
2022-10-08 14:05 ` [PATCH v2 2/2] riscv: Enable HAVE_ARCH_HUGE_VMALLOC " Liu Shixin
2022-10-11 12:39 ` [PATCH v2 0/2] riscv: Support HAVE_ARCH_HUGE_VMAP and HAVE_ARCH_HUGE_VMALLOC Björn Töpel
2022-10-12  2:47   ` Liu Shixin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).