Skip to contentSkip to conversation

Proof of concept for rv32 svpbmt support

RFC PATCH New [email protected] 1 participant 5 messages Jul 10, 2022 RISC-V

lore
Share & tools
lore
#0 lore raw

v2 cover Proof of concept for rv32 svpbmt support

From: Guo Ren <[email protected]>

Make rv32 support svpbmt & napot by reducing the PPN witdth (sv32p34 -> sv32p31).

RISC-V 32bit also requires svpbmt in cost-down chip embedded scenarios, and their RAM is limited (No more than 1GB). It is worth mentioning that rv32-Linux currently only supports 1GB of DRAM, and there is no plan for high-memory. So, there seems to be no obstacle to shrinking the physical address space of the rv32 from 16GB to 2GB. We recommend that ISA consider sv32p31 as the recommended configuration for the software ecosystem instead of sv32p34. Then we could merge rv64 & rv32 into one PTE format:

| XLEN-1 | XLEN-2 XLEN-3 | XLEN-4 10 | 9             8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
  N        MT[2]           RSV & PFN   reserved for SW   D   A   G   U   X   W   R   V

We've finished the Linux Proof of concept of the proposal, which contains three parts:
- Qemu rv32 svpbmt & napot support & hw/virt memory layout of 1GB IO range [1]
- Linux rv32 sv32p31 & svpbmt support
- Opensbi needs to compile with FW_TEXT_START=0x40000000

[1] https://github.com/guoren83/qemu/tree/rv32svpbmt

Changes in V2:
- Fixup ALT_SVPBMT_SHIFT definition
- Optimize commit log

Guo Ren (4):
riscv: Optimize satp_mode data type
riscv: Cleanup ERRATA_THEAD_PBMT for rv32 svpbmt compile
riscv: pgtable: Move svpbmt into the common pgtable-bits.h
riscv: Change rv32p34 to rv32p31 for svpbmt

 arch/riscv/Kconfig                    |  2 +-
 arch/riscv/include/asm/errata_list.h  | 17 ++++++++-
 arch/riscv/include/asm/pgtable-32.h   | 20 +---------
 arch/riscv/include/asm/pgtable-64.h   | 55 ---------------------------
 arch/riscv/include/asm/pgtable-bits.h | 53 ++++++++++++++++++++++++++
 arch/riscv/include/asm/pgtable.h      |  7 +++-
 arch/riscv/include/asm/sparsemem.h    |  2 +-
 arch/riscv/mm/init.c                  |  4 +-
 8 files changed, 80 insertions(+), 80 deletions(-)
Signature · 7 lines
2.36.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#1 lore raw

RFC PATCH v2 1/4 riscv: Optimize satp_mode data type

From: Guo Ren <[email protected]>

Fixup satp_mode data type. Use ulong instead of u64 for rv32 compatibility.

---
 arch/riscv/include/asm/pgtable.h | 2 +-
 arch/riscv/mm/init.c             | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)
arch/riscv/include/asm/pgtable.h +1 -1
index 1d1be9d9419c..edc68759b69d 100644
@@ -833,7 +833,7 @@ extern uintptr_t _dtb_early_pa;
 #define dtb_early_va	_dtb_early_va
 #define dtb_early_pa	_dtb_early_pa
 #endif /* CONFIG_XIP_KERNEL */
-extern u64 satp_mode;
+extern ulong satp_mode;
 extern bool pgtable_l4_enabled;
 
 void paging_init(void);
arch/riscv/mm/init.c +2 -2
index d466ec670e1f..eea147b1a617 100644
@@ -38,9 +38,9 @@ EXPORT_SYMBOL(kernel_map);
 #endif
 
 #ifdef CONFIG_64BIT
-u64 satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
+ulong satp_mode __ro_after_init = !IS_ENABLED(CONFIG_XIP_KERNEL) ? SATP_MODE_57 : SATP_MODE_39;
 #else
-u64 satp_mode __ro_after_init = SATP_MODE_32;
+ulong satp_mode __ro_after_init = SATP_MODE_32;
 #endif
 EXPORT_SYMBOL(satp_mode);
 
Signature · 7 lines
2.36.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#2 lore raw

RFC PATCH v2 2/4 riscv: Cleanup ERRATA_THEAD_PBMT for rv32 svpbmt compile

In reply to [email protected]

From: Guo Ren <[email protected]>

Make compile cleaner and don't reference the THEAD_PBMT data struct when CONFIG_ERRATA_THEAD_PBMT=y. Next, we could cleanly make svpbmt to support rv32.

When current CONFIG_ERRATA_THEAD_PBMT is active in the alternative section added to the build.
I.e. that translates to:

.if IS_ENABLED(CONFIG_ERRATA_THEAD_PBMT)
.pushsection .alternative, "a"
...

But, above can't affect the below:

	...
	"I"(prot##_THEAD >> ALT_THEAD_PBMT_SHIFT),
	...
	"I"(ALT_THEAD_PBMT_SHIFT))

CONFIG_ERRATA_THEAD_PBMT is not clean enough, compiler still process the "I"(prot##_THEAD >> ALT_THEAD_PBMT_SHIFT)" & "I"(ALT_THEAD_PBMT_SHIFT).

---
 arch/riscv/include/asm/errata_list.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
arch/riscv/include/asm/errata_list.h +10 -1
index 416ead0f9a65..47175d91773d 100644
@@ -47,6 +47,8 @@ asm(ALTERNATIVE("sfence.vma %0", "sfence.vma", SIFIVE_VENDOR_ID,	\
  * in the default case.
  */
 #define ALT_SVPBMT_SHIFT 61
+
+#ifdef CONFIG_ERRATA_THEAD_PBMT
 #define ALT_THEAD_PBMT_SHIFT 59
 #define ALT_SVPBMT(_val, prot)						\
 asm(ALTERNATIVE_2("li %0, 0\t\nnop",					\
@@ -60,7 +62,6 @@ asm(ALTERNATIVE_2("li %0, 0\t\nnop",					\
 		  "I"(ALT_SVPBMT_SHIFT),				\
 		  "I"(ALT_THEAD_PBMT_SHIFT))
 
-#ifdef CONFIG_ERRATA_THEAD_PBMT
 /*
  * IO/NOCACHE memory types are handled together with svpbmt,
  * so on T-Head chips, check if no other memory type is set,
@@ -90,6 +91,14 @@ asm volatile(ALTERNATIVE(						\
 	  "I"(ALT_THEAD_PBMT_SHIFT)					\
 	: "t3")
 #else
+#define ALT_SVPBMT(_val, prot)						\
+asm(ALTERNATIVE("li %0, 0\t\nnop",					\
+		 "li %0, %1\t\nslli %0,%0,%2", 0,			\
+			CPUFEATURE_SVPBMT, CONFIG_RISCV_ISA_SVPBMT)	\
+		: "=r"(_val)						\
+		: "I"(prot##_SVPBMT >> ALT_SVPBMT_SHIFT),		\
+		  "I"(ALT_SVPBMT_SHIFT))
+
 #define ALT_THEAD_PMA(_val)
 #endif
 
Signature · 7 lines
2.36.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#3 lore raw

RFC PATCH v2 3/4 riscv: pgtable: Move svpbmt into the common pgtable-bits.h

In reply to [email protected]

From: Guo Ren <[email protected]>

This patch is preparation for rv32 svpbmt, which only moves the svpbmt bits definitions into the standard header and no other functionality modification. Here is the list of modification:
- Change u64 to ulong of riscv_page_nocache/mtmask/io functions
- Using __riscv_xlen instead of 64

---
 arch/riscv/include/asm/errata_list.h  |  6 ++-
 arch/riscv/include/asm/pgtable-32.h   | 16 --------
 arch/riscv/include/asm/pgtable-64.h   | 55 ---------------------------
 arch/riscv/include/asm/pgtable-bits.h | 53 ++++++++++++++++++++++++++
 arch/riscv/include/asm/pgtable.h      |  5 +++
 5 files changed, 63 insertions(+), 72 deletions(-)
arch/riscv/include/asm/errata_list.h +5 -1
index 47175d91773d..4cbc6b03b486 100644
@@ -46,7 +46,11 @@ asm(ALTERNATIVE("sfence.vma %0", "sfence.vma", SIFIVE_VENDOR_ID,	\
  * _val is marked as "will be overwritten", so need to set it to 0
  * in the default case.
  */
-#define ALT_SVPBMT_SHIFT 61
+#ifdef CONFIG_64BIT
+#define ALT_SVPBMT_SHIFT (61)
+#else
+#define ALT_SVPBMT_SHIFT (29)
+#endif
 
 #ifdef CONFIG_ERRATA_THEAD_PBMT
 #define ALT_THEAD_PBMT_SHIFT 59
arch/riscv/include/asm/pgtable-32.h +0 -16
index 59ba1fbaf784..63b023bd4845 100644
@@ -7,8 +7,6 @@
 #define _ASM_RISCV_PGTABLE_32_H
 
 #include <asm-generic/pgtable-nopmd.h>
-#include <linux/bits.h>
-#include <linux/const.h>
 
 /* Size of region mapped by a page global directory */
 #define PGDIR_SHIFT     22
@@ -17,20 +15,6 @@
 
 #define MAX_POSSIBLE_PHYSMEM_BITS 34
 
-/*
- * rv32 PTE format:
- * | XLEN-1  10 | 9             8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
- *       PFN      reserved for SW   D   A   G   U   X   W   R   V
- */
 #define _PAGE_PFN_MASK  GENMASK(31, 10)
 
-#define _PAGE_NOCACHE		0
-#define _PAGE_IO		0
-#define _PAGE_MTMASK		0
-
-/* Set of bits to preserve across pte_modify() */
-#define _PAGE_CHG_MASK  (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ |	\
-					  _PAGE_WRITE | _PAGE_EXEC |	\
-					  _PAGE_USER | _PAGE_GLOBAL))
-
 #endif /* _ASM_RISCV_PGTABLE_32_H */
arch/riscv/include/asm/pgtable-64.h +0 -55

75 lines not on this page · raw message

arch/riscv/include/asm/pgtable-bits.h +53 -0

65 lines not on this page · raw message

arch/riscv/include/asm/pgtable.h +5 -0
index edc68759b69d..5d5ba6513c14 100644
@@ -8,7 +8,12 @@
 
 #include <linux/mmzone.h>
 #include <linux/sizes.h>
+#ifndef __ASSEMBLY__
+#include <linux/bits.h>
+#include <linux/const.h>
 
+#include <asm/errata_list.h>
+#endif
 #include <asm/pgtable-bits.h>
 
 #ifndef CONFIG_MMU
Signature · 7 lines
2.36.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
#4 lore raw

RFC PATCH v2 4/4 riscv: Change rv32p34 to rv32p31 for svpbmt

In reply to [email protected]

From: Guo Ren <[email protected]>

Decrease rv32 16GB physical address range to 2GB (rv32p34 -> rv32p31) for svpbmt support. Svpbmt & napot could directly occupy rv32 PPN highest bits. The patch wouldn't reduce the functionality of rv32-Linux, because rv32-Linux only supports 1GB direct mapping (0xc0000000 - 0xffffffff). So 2GB physical address range is enough for current rv32-Linux (1GB for memory, 1GB for IO).

---
 arch/riscv/Kconfig                  | 2 +-
 arch/riscv/include/asm/pgtable-32.h | 4 ++--
 arch/riscv/include/asm/sparsemem.h  | 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)
arch/riscv/Kconfig +1 -1
index 32ffef9f6e5b..0dc1509e7e1c 100644
@@ -360,7 +360,7 @@ config RISCV_ISA_C
 
 config RISCV_ISA_SVPBMT
 	bool "SVPBMT extension support"
-	depends on 64BIT && MMU
+	depends on MMU
 	select RISCV_ALTERNATIVE
 	default y
 	help
arch/riscv/include/asm/pgtable-32.h +2 -2
index 63b023bd4845..aa94f6487670 100644
@@ -13,8 +13,8 @@
 #define PGDIR_SIZE      (_AC(1, UL) << PGDIR_SHIFT)
 #define PGDIR_MASK      (~(PGDIR_SIZE - 1))
 
-#define MAX_POSSIBLE_PHYSMEM_BITS 34
+#define MAX_POSSIBLE_PHYSMEM_BITS 31
 
-#define _PAGE_PFN_MASK  GENMASK(31, 10)
+#define _PAGE_PFN_MASK  GENMASK(28, 10)
 
 #endif /* _ASM_RISCV_PGTABLE_32_H */
arch/riscv/include/asm/sparsemem.h +1 -1
index 63acaecc3374..1fc64bb65996 100644
@@ -7,7 +7,7 @@
 #ifdef CONFIG_64BIT
 #define MAX_PHYSMEM_BITS	56
 #else
-#define MAX_PHYSMEM_BITS	34
+#define MAX_PHYSMEM_BITS	31
 #endif /* CONFIG_64BIT */
 #define SECTION_SIZE_BITS	27
 #endif /* CONFIG_SPARSEMEM */
Signature · 7 lines
2.36.1


_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv