riscv: add RISC-V Svpbmt Standard Extension supports
Subsystems (2)
v3 cover riscv: add RISC-V Svpbmt Standard Extension supports
From: Fu Wei <[email protected]>
This patch follows the RISC-V standard Svpbmt extension in privilege spec to solve the non-coherent SOC DMA synchronization issues.
The svpbmt PTE format:
| 63 | 62-61 | 60-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
N MT RSW D A G U X W R V
^Of the Reserved bits [63:54] in a leaf PTE, the bits [62:61] are used as the MT (aka MemType) field. This field specifies one of three memory types as shown in the following table:
MemType RISC-V Description ---------- ------------------------------------------------ 00 - PMA Normal Cacheable, No change to implied PMA memory type 01 - NC Non-cacheable, idempotent, weakly-ordered Main Memory 10 - IO Non-cacheable, non-idempotent, strongly-ordered I/O memory 11 - Rsvd Reserved for future standard use
The standard protection_map[] needn't be modified because the "PMA" type keeps the highest bits zero.
And the whole modification is limited in the arch/riscv/* and using a global variable(__riscv_svpbmt) as _PAGE_DMA_MASK/IO/NC for pgprot_noncached (&writecombine) in pgtable.h.
We also add _PAGE_CHG_MASK to filter PFN than before.
Enable it in devicetree - (Add "mmu-supports-svpbmt" in cpu node)
- mmu-supports-svpbmt
Wei Fu (2):
dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
riscv: add RISC-V Svpbmt extension supports
.../devicetree/bindings/riscv/cpus.yaml | 5 +++ arch/riscv/include/asm/fixmap.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 8 ++-- arch/riscv/include/asm/pgtable-bits.h | 41 ++++++++++++++++++- arch/riscv/include/asm/pgtable.h | 39 ++++++++++++++---- arch/riscv/kernel/cpufeature.c | 32 +++++++++++++++ arch/riscv/mm/init.c | 5 +++ 7 files changed, 117 insertions(+), 15 deletions(-)
Signature · 1 line
2.25.4
PATCH RESEND v3 1/2 dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
From: Wei Fu <[email protected]>
Previous patch has added svpbmt in arch/riscv and changed the DT mmu-type. Update dt-bindings related property here.
--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 +++++ 1 file changed, 5 insertions(+)
Documentation/devicetree/bindings/riscv/cpus.yaml +5 -0
@@ -59,6 +59,11 @@ properties: - riscv,sv48 - riscv,none + mmu-supports-svpbmt: + description: + Describes the CPU's mmu-supports-svpbmt support + $ref: '/schemas/types.yaml#/definitions/phandle' + riscv,isa: description: Identifies the specific RISC-V instruction set architecture
Signature · 1 line
2.25.4
Re: [RESEND PATCH V3 1/2] dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
Quoted 21 lines · On Mon, Oct 25, 2021 at 9:36 AM <[email protected]> wrote:
From: Wei Fu <[email protected]>
Previous patch has added svpbmt in
arch/riscvand changed the DT mmu-type. Update dt-bindings related property here.Signed-off-by Wei Fu <[email protected]>Co-developed-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>Cc Anup Patel <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Rob Herring <[email protected]>--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 +++++ 1 file changed, 5 insertions(+)Documentation/devicetree/bindings/riscv/cpus.yaml +0
-0
Documentation/devicetree/bindings/riscv/cpus.yaml properties: · line 65
Quoted 7 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +4
-0@@ -59,6 +59,11 @@ properties: - riscv,sv48 - riscv,none + mmu-supports-svpbmt: + description: + Describes the CPU's mmu-supports-svpbmt support + $ref: '/schemas/types.yaml#/definitions/phandle'
There were various proposals from different folks in the previous email threads.
I think most of us were converging on:
1) Don't modify "mmu-type" DT property for backward compatibility
2) Add boolean DT property "riscv,svpmbt" under "mmu" child DT node of each CPU DT node. Same will apply to boolean DT property "riscv,svnapot" as well.
We also have bitmanip and vector broken down into smaller extensions so grouping related extensions as separate DT node under each CPU node will be more readable and easy to parse.
Regards,
Anup
Quoted 7 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +1
-1+ riscv,isa: description: Identifies the specific RISC-V instruction set architecture --2.25.4
Re: [RESEND PATCH V3 1/2] dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
Quoted 34 lines · Anup Patel
Quoted 21 lines · On Mon, Oct 25, 2021 at 9:36 AM <[email protected]> wrote:
From: Wei Fu <[email protected]>
Previous patch has added svpbmt in
arch/riscvand changed the DT mmu-type. Update dt-bindings related property here.Signed-off-by Wei Fu <[email protected]>Co-developed-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>Cc Anup Patel <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Rob Herring <[email protected]>--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 +++++ 1 file changed, 5 insertions(+)Documentation/devicetree/bindings/riscv/cpus.yaml +0
-0Documentation/devicetree/bindings/riscv/cpus.yaml properties: · line 65
Quoted 7 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +4
-0@@ -59,6 +59,11 @@ properties: - riscv,sv48 - riscv,none + mmu-supports-svpbmt: + description: + Describes the CPU's mmu-supports-svpbmt support + $ref: '/schemas/types.yaml#/definitions/phandle'There were various proposals from different folks in the previous email threads.
Quoted 3 lines
I think most of us were converging on:
1) Don't modify "mmu-type" DT property for backward compatibility
I agree. FuWei has followed that in the patch.
Quoted 3 lines
2) Add boolean DT property "riscv,svpmbt" under "mmu" child DT node of each CPU DT node. Same will apply to boolean DT property "riscv,svnapot" as well.
We have various proposals here:
@Philipp suggests firstly, but break the backward compatibility:
cpu@0 {
...
mmu {
type = "riscv,sv39";
supports-svpbmt;
supports-svnapot;
};@guoren suggests reusing the mmu-type, but seems not clean. cpu@0 {
...
mmu-type = "riscv,sv39,svpbmt,svnapot";
@fuwei suggests simple name property in CPU section:
cpu@0 {
...
mmu-type = "riscv,sv39"; mmu-supports-svpbmt; mmu-supports-svnapot;
@Anup suggests:
cpu@0 {
...
mmu-type = "riscv,sv39";
mmu {
supports-svpbmt;
supports-svnapot;
};Any other suggestions? Thx.
Quoted 4 lines
We also have bitmanip and vector broken down into smaller extensions so grouping related extensions as separate DT node under each CPU node will be more readable and easy to parse.
Do you mean combine mmu extensions with them together?
cpu@0 {
...
extensions {
supports-svpbmt;
supports-svnapot;
supports-bitmanip;
supports-vector-v0p7;
};Quoted 11 lines
Regards,
AnupQuoted 7 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +1
-1+ riscv,isa: description: Identifies the specific RISC-V instruction set architecture --2.25.4
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
Re: [RESEND PATCH V3 1/2] dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
Quoted 83 lines · Guo Ren
Quoted 34 lines · Anup Patel
Quoted 21 lines · On Mon, Oct 25, 2021 at 9:36 AM <[email protected]> wrote:
From: Wei Fu <[email protected]>
Previous patch has added svpbmt in
arch/riscvand changed the DT mmu-type. Update dt-bindings related property here.Signed-off-by Wei Fu <[email protected]>Co-developed-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>Cc Anup Patel <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Rob Herring <[email protected]>--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 +++++ 1 file changed, 5 insertions(+)Documentation/devicetree/bindings/riscv/cpus.yaml +0
-0Documentation/devicetree/bindings/riscv/cpus.yaml properties: · line 65
Quoted 7 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +4
-0@@ -59,6 +59,11 @@ properties: - riscv,sv48 - riscv,none + mmu-supports-svpbmt: + description: + Describes the CPU's mmu-supports-svpbmt support + $ref: '/schemas/types.yaml#/definitions/phandle'There were various proposals from different folks in the previous email threads.
Quoted 3 lines
I think most of us were converging on:
1) Don't modify "mmu-type" DT property for backward compatibilityI agree. FuWei has followed that in the patch.
Quoted 3 lines
2) Add boolean DT property "riscv,svpmbt" under "mmu" child DT node of each CPU DT node. Same will apply to boolean DT property "riscv,svnapot" as well.
We have various proposals here:
@Philipp suggests firstly, but break the backward compatibility:cpu@0 { ... mmu { type = "riscv,sv39"; supports-svpbmt; supports-svnapot; };@guoren suggests reusing the mmu-type, but seems not clean.
cpu@0 { ... mmu-type = "riscv,sv39,svpbmt,svnapot";@fuwei suggests simple name property in CPU section:
cpu@0 { ... mmu-type = "riscv,sv39"; mmu-supports-svpbmt; mmu-supports-svnapot;@Anup suggests:
cpu@0 { ... mmu-type = "riscv,sv39"; mmu { supports-svpbmt; supports-svnapot; };Any other suggestions? Thx.
Quoted 4 lines
We also have bitmanip and vector broken down into smaller extensions so grouping related extensions as separate DT node under each CPU node will be more readable and easy to parse.
Do you mean combine mmu extensions with them together?
Quoted 8 lines
cpu@0 {
...
extensions {
supports-svpbmt;
supports-svnapot;
supports-bitmanip;
supports-vector-v0p7;
};I meant separate group nodes like this:
cpu@0 {
...
mmu-type = "riscv,sv39";
mmu { /* Only considered when mmu-type is present and mmu-type !=
"riscv,sv32" */
riscv,svpmbt;
riscv,svnapot;
};
bitmanip { /* Only considered when "B" is present in the ISA string */
...
};vector { /* Only considered when "V" is present in the ISA string */
...
};
...
};Regards,
Anup
Quoted 20 lines
Quoted 12 lines
Regards,
AnupQuoted 7 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +1
-1+ riscv,isa: description: Identifies the specific RISC-V instruction set architecture --2.25.4
--
Best Regards
Guo Ren
Re: [RESEND PATCH V3 1/2] dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
Quoted 96 lines · Anup Patel
Quoted 83 lines · Guo Ren
Quoted 34 lines · Anup Patel
Quoted 21 lines · On Mon, Oct 25, 2021 at 9:36 AM <[email protected]> wrote:
From: Wei Fu <[email protected]>
Previous patch has added svpbmt in
arch/riscvand changed the DT mmu-type. Update dt-bindings related property here.Signed-off-by Wei Fu <[email protected]>Co-developed-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>Cc Anup Patel <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Rob Herring <[email protected]>--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 +++++ 1 file changed, 5 insertions(+)Documentation/devicetree/bindings/riscv/cpus.yaml +0
-0Documentation/devicetree/bindings/riscv/cpus.yaml properties: · line 65
Quoted 7 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +4
-0@@ -59,6 +59,11 @@ properties: - riscv,sv48 - riscv,none + mmu-supports-svpbmt: + description: + Describes the CPU's mmu-supports-svpbmt support + $ref: '/schemas/types.yaml#/definitions/phandle'There were various proposals from different folks in the previous email threads.
Quoted 3 lines
I think most of us were converging on:
1) Don't modify "mmu-type" DT property for backward compatibilityI agree. FuWei has followed that in the patch.
Quoted 3 lines
2) Add boolean DT property "riscv,svpmbt" under "mmu" child DT node of each CPU DT node. Same will apply to boolean DT property "riscv,svnapot" as well.
We have various proposals here:
@Philipp suggests firstly, but break the backward compatibility:cpu@0 { ... mmu { type = "riscv,sv39"; supports-svpbmt; supports-svnapot; };@guoren suggests reusing the mmu-type, but seems not clean.
cpu@0 { ... mmu-type = "riscv,sv39,svpbmt,svnapot";@fuwei suggests simple name property in CPU section:
cpu@0 { ... mmu-type = "riscv,sv39"; mmu-supports-svpbmt; mmu-supports-svnapot;@Anup suggests:
cpu@0 { ... mmu-type = "riscv,sv39"; mmu { supports-svpbmt; supports-svnapot; };Any other suggestions? Thx.
Quoted 4 lines
We also have bitmanip and vector broken down into smaller extensions so grouping related extensions as separate DT node under each CPU node will be more readable and easy to parse.
Do you mean combine mmu extensions with them together?
Quoted 8 lines
cpu@0 { ... extensions { supports-svpbmt; supports-svnapot; supports-bitmanip; supports-vector-v0p7; };I meant separate group nodes like this:
Quoted 12 lines
cpu@0 {
...
mmu-type = "riscv,sv39";
mmu { /* Only considered when mmu-type is present and mmu-type !=
"riscv,sv32" */
riscv,svpmbt;
riscv,svnapot;
};
bitmanip { /* Only considered when "B" is present in the ISA string */
...
};Please disregard this comment regarding bitmanip/B.
The B bit in the misa CSR is not used for any signalling regarding Zb[abcs] (or the other Zb-extensions), so this entire node is not needed and B in the ISA string is not related to any of the Zb* extensions).
All Zb* extensions are directly visible from the ISA string.
Quoted 29 lines
vector { /* Only considered when "V" is present in the ISA string */ ... }; ... };Regards,
AnupQuoted 20 lines
Quoted 12 lines
Regards,
AnupQuoted 7 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +1
-1+ riscv,isa: description: Identifies the specific RISC-V instruction set architecture --2.25.4
--
Best Regards
Guo Ren
Re: [RESEND PATCH V3 1/2] dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
In reply to [email protected]Quoted 21 lines · On Mon, Oct 25, 2021 at 12:06 PM <[email protected]> wrote:
From: Wei Fu <[email protected]>
Previous patch has added svpbmt in
arch/riscvand changed the DT mmu-type. Update dt-bindings related property here.Signed-off-by Wei Fu <[email protected]>Co-developed-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>Cc Anup Patel <[email protected]>Cc Palmer Dabbelt <[email protected]>Cc Rob Herring <[email protected]>--- Documentation/devicetree/bindings/riscv/cpus.yaml | 5 +++++ 1 file changed, 5 insertions(+)Documentation/devicetree/bindings/riscv/cpus.yaml +0
-0
Documentation/devicetree/bindings/riscv/cpus.yaml properties: · line 62
Quoted 4 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +1
-0@@ -59,6 +59,11 @@ properties: - riscv,sv48 - riscv,none + mmu-supports-svpbmt:
We need a "type: boolean" here.
ref: Documentation/devicetree/bindings/serial/8250.yaml
used-by-rtas:
type: boolean
description: |
Set to indicate that the port is in use by the OpenFirmware RTAS and should not be registered.
Quoted 4 lines
Documentation/devicetree/bindings/riscv/cpus.yaml +4
-0+ description: + Describes the CPU's mmu-supports-svpbmt support + $ref: '/schemas/types.yaml#/definitions/phandle' +
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
PATCH RESEND v3 2/2 riscv: add RISC-V Svpbmt extension supports
In reply to [email protected]From: Wei Fu <[email protected]>
This patch follows the standard pure RISC-V Svpbmt extension in privilege spec to solve the non-coherent SOC dma synchronization issues.
Here is the svpbmt PTE format:
| 63 | 62-61 | 60-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0
N MT RSW D A G U X W R V
^Of the Reserved bits [63:54] in a leaf PTE, the high bit is already allocated (as the N bit), so bits [62:61] are used as the MT (aka MemType) field. This field specifies one of three memory types that are close equivalents (or equivalent in effect) to the three main x86 and ARMv8 memory types - as shown in the following table.
RISC-V
Encoding &
MemType RISC-V Description ---------- ------------------------------------------------ 00 - PMA Normal Cacheable, No change to implied PMA memory type 01 - NC Non-cacheable, idempotent, weakly-ordered Main Memory 10 - IO Non-cacheable, non-idempotent, strongly-ordered I/O memory 11 - Rsvd Reserved for future standard use
The standard protection_map[] needn't be modified because the "PMA" type keeps the highest bits zero. And the whole modification is limited in the arch/riscv/* and using a global variable (__riscv_svpbmt) as _PAGE_DMA_MASK/IO/NC for pgprot_noncached (&writecombine) in pgtable.h. We also add _PAGE_CHG_MASK to filter PFN than before.
Enable it in devicetree - (Add "mmu-supports-svpbmt" in cpu node)
- mmu-supports-svpbmt
--- arch/riscv/include/asm/fixmap.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 8 ++++-- arch/riscv/include/asm/pgtable-bits.h | 41 +++++++++++++++++++++++++-- arch/riscv/include/asm/pgtable.h | 39 +++++++++++++++++++------ arch/riscv/kernel/cpufeature.c | 32 +++++++++++++++++++++ arch/riscv/mm/init.c | 5 ++++ 6 files changed, 112 insertions(+), 15 deletions(-)
arch/riscv/include/asm/fixmap.h +1 -1
@@ -43,7 +43,7 @@ enum fixed_addresses { __end_of_fixed_addresses }; -#define FIXMAP_PAGE_IO PAGE_KERNEL +#define FIXMAP_PAGE_IO PAGE_IOREMAP#define __early_set_fixmap __set_fixmap
arch/riscv/include/asm/pgtable-64.h +5 -3
@@ -61,12 +61,14 @@ static inline void pud_clear(pud_t *pudp)static inline pmd_t *pud_pgtable (pud_t pud) { -return (pmd_t *)pfn_to_virt (pud_val (pud) >> _PAGE_PFN_SHIFT); +return (pmd_t *)pfn_to_virt ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT); }static inline struct page *pud_page (pud_t pud) { -return pfn_to_page (pud_val (pud) >> _PAGE_PFN_SHIFT); +return pfn_to_page ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT); }static inline pmd_t pfn_pmd (unsigned long pfn,pgprot_t prot)
@@ -76,7 +78,7 @@ static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot)static inline unsigned long _pmd_pfn (pmd_t pmd) { -return pmd_val (pmd) >> _PAGE_PFN_SHIFT; +return (pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT; }#define mk_pmd (page, prot) pfn_pmd(page_to_pfn(page), prot)
arch/riscv/include/asm/pgtable-bits.h +39 -2
59 lines not on this page · raw message
arch/riscv/include/asm/pgtable.h +30 -9
@@ -136,7 +136,8 @@ | _PAGE_PRESENT \ | _PAGE_ACCESSED \ | _PAGE_DIRTY \ - | _PAGE_GLOBAL) + | _PAGE_GLOBAL \ + | _PAGE_MT_PMA)#define PAGE_KERNEL __pgprot(_PAGE_KERNEL)#define PAGE_KERNEL_READ __pgprot(_PAGE_KERNEL & ~_PAGE_WRITE)
@@ -146,11 +147,9 @@#define PAGE_TABLE __pgprot(_PAGE_TABLE) -/* -* The RISC-V ISA doesn't yet specify how to query or modify PMAs, so we can't -* change the properties of memory regions. -*/ -#define _PAGE_IOREMAP _PAGE_KERNEL +#define _PAGE_IOREMAP ((_PAGE_KERNEL & ~_PAGE_MT_MASK) | _PAGE_MT_IO) + +#define PAGE_IOREMAP __pgprot(_PAGE_IOREMAP)extern pgd_t swapper_pg_dir[];
@@ -230,12 +229,12 @@ static inline unsigned long _pgd_pfn(pgd_t pgd)static inline struct page *pmd_page (pmd_t pmd) { -return pfn_to_page (pmd_val (pmd) >> _PAGE_PFN_SHIFT); +return pfn_to_page ((pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT); }static inline unsigned long pmd_page_vaddr (pmd_t pmd) { -return (unsigned long )pfn_to_virt (pmd_val (pmd) >> _PAGE_PFN_SHIFT); +return (unsigned long )pfn_to_virt ((pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT); }static inline pte_t pmd_pte (pmd_t pmd)
@@ -251,7 +250,7 @@ static inline pte_t pud_pte(pud_t pud)/* Yields the page frame number (PFN) of a page table entry */ static inline unsigned long pte_pfn (pte_t pte) { -return (pte_val (pte) >> _PAGE_PFN_SHIFT); +return ((pte_val (pte) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT); }#define pte_page (x) pfn_to_page(pte_pfn(x))
@@ -490,6 +489,28 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,return ptep_test_and_clear_young (vma, address, ptep); } +#define pgprot_noncached pgprot_noncached +static inline pgprot_t pgprot_noncached (pgprot_t _prot) +{ +unsigned long prot =pgprot_val (_prot); + + prot &= ~_PAGE_MT_MASK; + prot |= _PAGE_MT_IO; + +return __pgprot (prot); +} + +#define pgprot_writecombine pgprot_writecombine +static inline pgprot_t pgprot_writecombine (pgprot_t _prot) +{ +unsigned long prot =pgprot_val (_prot); + + prot &= ~_PAGE_MT_MASK; + prot |= _PAGE_MT_NC; + +return __pgprot (prot); +} +/* * THP functions */
arch/riscv/kernel/cpufeature.c +32 -0
@@ -8,6 +8,7 @@#include <linux/bitmap.h> #include <linux/of.h> +#include <linux/pgtable.h> #include <asm/processor.h> #include <asm/hwcap.h> #include <asm/smp.h>
@@ -59,6 +60,35 @@ bool __riscv_isa_extension_available(const unsigned long *isa_bitmap, int bit) }EXPORT_SYMBOL_GPL (__riscv_isa_extension_available); +static void __init mmu_supports_svpbmt (void ) +{ +#if defined(CONFIG_MMU ) && defined(CONFIG_64BIT ) +struct device_node *node; +const char *str; + +for_each_of_cpu_node (node) { +if (of_property_read_string (node,"mmu-type" , &str)) +continue ; + +if (!strncmp (str +6 ,"none" ,4 )) +continue ; + +if (!of_property_read_bool (node,"mmu-supports-svpbmt" )) +return ; + } + + __riscv_svpbmt.mask = _SVPBMT_MASK; + __riscv_svpbmt.mt_pma = _SVPBMT_PMA; + __riscv_svpbmt.mt_nc = _SVPBMT_NC; + __riscv_svpbmt.mt_io = _SVPBMT_IO; +#endif +} + +static void __init mmu_supports (void ) +{ +mmu_supports_svpbmt (); +} +void __init riscv_fill_hwcap (void ) {struct device_node *node;
@@ -67,6 +97,8 @@ void __init riscv_fill_hwcap(void)size_t i, j, isa_len;static unsigned long isa2hwcap[256 ] = {0 }; +mmu_supports (); + isa2hwcap['i' ] = isa2hwcap['I' ] =COMPAT_HWCAP_ISA_I ; isa2hwcap['m' ] = isa2hwcap['M' ] =COMPAT_HWCAP_ISA_M ; isa2hwcap['a' ] = isa2hwcap['A' ] =COMPAT_HWCAP_ISA_A ;
arch/riscv/mm/init.c +5 -0
@@ -855,3 +855,8 @@ int __meminit vmemmap_populate(unsigned long start, unsigned long end, int node, return vmemmap_populate_basepages(start, end, node, NULL); }#endif + +#ifdef CONFIG_64BIT +struct __riscv_svpbmt_struct __riscv_svpbmt__ro_after_init ; +EXPORT_SYMBOL (__riscv_svpbmt); +#endif
Signature · 1 line
2.25.4
Re: [RESEND PATCH V3 2/2] riscv: add RISC-V Svpbmt extension supports
Quoted 8 lines · On Mon, Oct 25, 2021 at 12:06:07PM +0800, [email protected] wrote:
static inline
pmd_t*pud_pgtable(pud_t pud)
{arch/riscv/include/asm/pgtable-64.h +2
-1-return (pmd_t *)pfn_to_virt (pud_val (pud) >> _PAGE_PFN_SHIFT); +return (pmd_t *)pfn_to_virt ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT); }static inline struct page *pud_page (pud_t pud)
arch/riscv/include/asm/pgtable-64.h static inline void pud_clear(pud_t *pudp)
Quoted 10 lines
arch/riscv/include/asm/pgtable-64.h +3
-2{ -return pfn_to_page (pud_val (pud) >> _PAGE_PFN_SHIFT); +return pfn_to_page ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT);static inline unsigned long _pmd_pfn (pmd_t pmd) { -return pmd_val (pmd) >> _PAGE_PFN_SHIFT; +return (pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT; }
The "(pud_val(pud) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT" expression begs for readable and well-documented helper.
arch/riscv/include/asm/pgtable-bits.h line 41
Quoted 3 lines
arch/riscv/include/asm/pgtable-bits.h +3
-0+#define _SVPBMT_PMA ((unsigned long)0x0 << 61) +#define _SVPBMT_NC ((unsigned long)0x1 << 61) +#define _SVPBMT_IO ((unsigned long)0x2 << 61)
0UL << 61
1UL << 61
...
arch/riscv/include/asm/pgtable-bits.h line 54
Quoted 13 lines
arch/riscv/include/asm/pgtable-bits.h +13
-0+#define _SVPBMT_MASK (_SVPBMT_PMA | _SVPBMT_NC | _SVPBMT_IO) + +extern struct __riscv_svpbmt_struct { +unsigned long mask; +unsigned long mt_pma; +unsigned long mt_nc; +unsigned long mt_io; +} __riscv_svpbmt; + +#define _PAGE_MT_MASK __riscv_svpbmt.mask +#define _PAGE_MT_PMA __riscv_svpbmt.mt_pma +#define _PAGE_MT_NC __riscv_svpbmt.mt_nc +#define _PAGE_MT_IO __riscv_svpbmt.mt_io
Using a struct over individual variables seems a little odd here.
Also why not use the standard names for these _PAGE bits used by most other architectures?
arch/riscv/include/asm/pgtable.h static inline unsigned long _pgd_pfn(pgd_t pgd) · line 237
Quoted 2 lines
arch/riscv/include/asm/pgtable.h +1
-1-return (unsigned long )pfn_to_virt (pmd_val (pmd) >> _PAGE_PFN_SHIFT); +return (unsigned long )pfn_to_virt ((pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT);
Overly long line, could use a helper. Btw, what is the point in having this _PAGE_PFN_SHIFT macro to start with?
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [RESEND PATCH V3 2/2] riscv: add RISC-V Svpbmt extension supports
Hi Christoph,
Great thanks for your review.
Quoted 24 lines · Christoph Hellwig
Quoted 8 lines · On Mon, Oct 25, 2021 at 12:06:07PM +0800, [email protected] wrote:
static inline
pmd_t*pud_pgtable(pud_t pud)
{arch/riscv/include/asm/pgtable-64.h +2
-1-return (pmd_t *)pfn_to_virt (pud_val (pud) >> _PAGE_PFN_SHIFT); +return (pmd_t *)pfn_to_virt ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT); }static inline struct page *pud_page (pud_t pud)arch/riscv/include/asm/pgtable-64.h static inline void pud_clear(pud_t *pudp)
Quoted 10 lines
arch/riscv/include/asm/pgtable-64.h +3
-2{ -return pfn_to_page (pud_val (pud) >> _PAGE_PFN_SHIFT); +return pfn_to_page ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT);static inline unsigned long _pmd_pfn (pmd_t pmd) { -return pmd_val (pmd) >> _PAGE_PFN_SHIFT; +return (pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT; }The "(
pud_val(pud)&_PAGE_CHG_MASK) >>_PAGE_PFN_SHIFT" expression begs for readable and well-documented helper.
Quoted 6 lines
arch/riscv/include/asm/pgtable-bits.h line 41
Quoted 3 lines
arch/riscv/include/asm/pgtable-bits.h +3
-0+#define _SVPBMT_PMA ((unsigned long)0x0 << 61) +#define _SVPBMT_NC ((unsigned long)0x1 << 61) +#define _SVPBMT_IO ((unsigned long)0x2 << 61)0UL << 61
1UL << 61
How about this macro:
#define _SVPBMT_PMA 0x0UL
#define _SVPBMT_NC BIT(61)
#define _SVPBMT_IO BIT(62)
#define _SVPBMT_MASK GENMASK(62, 61)
Quoted 18 lines
...
arch/riscv/include/asm/pgtable-bits.h line 54
Quoted 13 lines
arch/riscv/include/asm/pgtable-bits.h +13
-0+#define _SVPBMT_MASK (_SVPBMT_PMA | _SVPBMT_NC | _SVPBMT_IO) + +extern struct __riscv_svpbmt_struct { +unsigned long mask; +unsigned long mt_pma; +unsigned long mt_nc; +unsigned long mt_io; +} __riscv_svpbmt; + +#define _PAGE_MT_MASK __riscv_svpbmt.mask +#define _PAGE_MT_PMA __riscv_svpbmt.mt_pma +#define _PAGE_MT_NC __riscv_svpbmt.mt_nc +#define _PAGE_MT_IO __riscv_svpbmt.mt_ioUsing a struct over individual variables seems a little odd here.
Quoted 2 lines
Also why not use the standard names for these
_PAGEbits used by most other architectures?
Which names are you suggesting? Would you mind providing an example ?
_PAGE_BIT_ for _PAGE_KERNEL_ ??
Quoted 12 lines
arch/riscv/include/asm/pgtable.h static inline unsigned long _pgd_pfn(pgd_t pgd) · line 237
Quoted 3 lines
arch/riscv/include/asm/pgtable.h +1
-1-return (unsigned long )pfn_to_virt (pmd_val (pmd) >> _PAGE_PFN_SHIFT); +return (unsigned long )pfn_to_virt ((pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT);Overly long line, could use a helper. Btw, what is the point in having this
_PAGE_PFN_SHIFTmacro to start with?_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [RESEND PATCH V3 2/2] riscv: add RISC-V Svpbmt extension supports
Quoted 5 lines · Wei Fu
How about this macro:
#define_SVPBMT_PMA0x0UL
#define_SVPBMT_NCBIT(61)
#define_SVPBMT_IOBIT(62)
#define_SVPBMT_MASKGENMASK(62, 61)
Personally I find these macros highly confusing.
#define _SVPBMT_PMA 0UL
#define _SVPBMT_NC (1UL << 61)
#define _SVPBMT_IO (1UL << 62).
#define _SVPBMT_MASK (_SVPBMT_NC | _SVPBMT_IO)
is much eaier to follow. Note that we can probably just drop _SVPBMT_PMA entirely to make this even more readable.
Quoted 5 lines
Quoted 2 lines
Also why not use the standard names for these
_PAGEbits used by most other architectures?Which names are you suggesting? Would you mind providing an example ?
_PAGE_BIT_ for _PAGE_KERNEL_ ??
Use _PAGE_NOCACHE for _SVPBMT_NC, and _PAGE_IO for _SVPBMT_IO.
Re: [RESEND PATCH V3 2/2] riscv: add RISC-V Svpbmt extension supports
Hi Chistoph,
Quoted 10 lines · Christoph Hellwig
Quoted 5 lines · Wei Fu
How about this macro:
#define_SVPBMT_PMA0x0UL
#define_SVPBMT_NCBIT(61)
#define_SVPBMT_IOBIT(62)
#define_SVPBMT_MASKGENMASK(62, 61)Personally I find these macros highly confusing.
Quoted 7 lines
#define _SVPBMT_PMA 0UL #define _SVPBMT_NC (1UL << 61) #define _SVPBMT_IO (1UL << 62). #define _SVPBMT_MASK (_SVPBMT_NC | _SVPBMT_IO)is much eaier to follow. Note that we can probably just drop
_SVPBMT_PMAentirely to make this even more readable.
sure, I can do this , thanks
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
Also why not use the standard names for these
_PAGEbits used by most other architectures?Which names are you suggesting? Would you mind providing an example ?
_PAGE_BIT_ for _PAGE_KERNEL_ ??Use
_PAGE_NOCACHEfor_SVPBMT_NC, and_PAGE_IOfor_SVPBMT_IO.
OK, Sure , will do
Great thanks
Quoted 1 line
Re: [RESEND PATCH V3 2/2] riscv: add RISC-V Svpbmt extension supports
In reply to Christoph HellwigHi Christoph,
I hope I understand this correctly,
Quoted 15 lines · Christoph Hellwig
Quoted 12 lines · On Mon, Oct 25, 2021 at 12:06:07PM +0800, [email protected] wrote:
static inline
pmd_t*pud_pgtable(pud_t pud)
{arch/riscv/include/asm/pgtable-64.h +4
-2-return (pmd_t *)pfn_to_virt (pud_val (pud) >> _PAGE_PFN_SHIFT); +return (pmd_t *)pfn_to_virt ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT); }static inline struct page *pud_page (pud_t pud) { -return pfn_to_page (pud_val (pud) >> _PAGE_PFN_SHIFT); +return pfn_to_page ((pud_val (pud) & _PAGE_CHG_MASK) + >> _PAGE_PFN_SHIFT);
Quoted 8 lines
arch/riscv/include/asm/pgtable-64.h static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot) · line 82
Quoted 5 lines
static inline unsigned long
_pmd_pfn(pmd_t pmd)
{arch/riscv/include/asm/pgtable-64.h +1
-1-return pmd_val (pmd) >> _PAGE_PFN_SHIFT; +return (pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT; }The "(
pud_val(pud)&_PAGE_CHG_MASK) >>_PAGE_PFN_SHIFT" expression begs for readable and well-documented helper.
How about these:
#define _chg_of_pmd(pmd) (pmd_val(pmd) & _PAGE_CHG_MASK) #define _chg_of_pud(pud) (pud_val(pud) & _PAGE_CHG_MASK)
Quoted 9 lines
arch/riscv/include/asm/pgtable-bits.h line 41
Quoted 4 lines
arch/riscv/include/asm/pgtable-bits.h +3
-0+#define _SVPBMT_PMA ((unsigned long)0x0 << 61) +#define _SVPBMT_NC ((unsigned long)0x1 << 61) +#define _SVPBMT_IO ((unsigned long)0x2 << 61)0UL << 61
1UL << 61
...
Quoted 16 lines
arch/riscv/include/asm/pgtable-bits.h line 54
Quoted 13 lines
arch/riscv/include/asm/pgtable-bits.h +13
-0+#define _SVPBMT_MASK (_SVPBMT_PMA | _SVPBMT_NC | _SVPBMT_IO) + +extern struct __riscv_svpbmt_struct { +unsigned long mask; +unsigned long mt_pma; +unsigned long mt_nc; +unsigned long mt_io; +} __riscv_svpbmt; + +#define _PAGE_MT_MASK __riscv_svpbmt.mask +#define _PAGE_MT_PMA __riscv_svpbmt.mt_pma +#define _PAGE_MT_NC __riscv_svpbmt.mt_nc +#define _PAGE_MT_IO __riscv_svpbmt.mt_ioUsing a struct over individual variables seems a little odd here.
How about :
extern unsigned long _svpbmt_mask extern unsigned long _svpbmt_mt_pma extern unsigned long _svpbmt_mt_nc extern unsigned long _svpbmt_mt_io
#define _PAGE_MT_MASK _svpbmt_mask
#define _PAGE_MT_PMA _svpbmt_mt_pma
#define _PAGE_MT_NC _svpbmt_mt_nc
#define _PAGE_MT_IO _svpbmt_mt_io
Quoted 14 lines
Also why not use the standard names for these
_PAGEbits used by most other architectures?arch/riscv/include/asm/pgtable.h static inline unsigned long _pgd_pfn(pgd_t pgd) · line 237
Quoted 2 lines
arch/riscv/include/asm/pgtable.h +1
-1-return (unsigned long )pfn_to_virt (pmd_val (pmd) >> _PAGE_PFN_SHIFT); +return (unsigned long )pfn_to_virt ((pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT);Overly long line, could use a helper. Btw, what is the point in having this
_PAGE_PFN_SHIFTmacro to start with?_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Re: [RESEND PATCH V3 2/2] riscv: add RISC-V Svpbmt extension supports
Quoted 8 lines · Wei Fu
Quoted 8 lines
Quoted 7 lines
arch/riscv/include/asm/pgtable-64.h +2
-1+ >> _PAGE_PFN_SHIFT);static inline unsigned long _pmd_pfn (pmd_t pmd) { -return pmd_val (pmd) >> _PAGE_PFN_SHIFT; +return (pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT; }
Quoted 6 lines
Quoted 2 lines
The "(
pud_val(pud)&_PAGE_CHG_MASK) >>_PAGE_PFN_SHIFT" expression begs for readable and well-documented helper.How about these:
#define_chg_of_pmd(pmd)(pmd_val(pmd)&_PAGE_CHG_MASK) #define_chg_of_pud(pud)(pud_val(pud)&_PAGE_CHG_MASK)
I'd use inline functions instead of macros if possible, but otherwise yes.
Quoted 11 lines
How about :
extern unsigned long
_svpbmt_maskextern unsigned long_svpbmt_mt_pmaextern unsigned long_svpbmt_mt_ncextern unsigned long_svpbmt_mt_io#define
_PAGE_MT_MASK_svpbmt_mask
#define_PAGE_MT_PMA_svpbmt_mt_pma
#define_PAGE_MT_NC_svpbmt_mt_nc
#define_PAGE_MT_IO_svpbmt_mt_io
Looks much better.
Re: [RESEND PATCH V3 2/2] riscv: add RISC-V Svpbmt extension supports
Hi Christoph,
Great thanks for your review.
Quoted 13 lines · Christoph Hellwig
Quoted 11 lines · Wei Fu
Quoted 10 lines
arch/riscv/include/asm/pgtable-64.h static inline pmd_t pfn_pmd(unsigned long pfn, pgprot_t prot) · line 82
Quoted 7 lines
arch/riscv/include/asm/pgtable-64.h +2
-1+ >> _PAGE_PFN_SHIFT);static inline unsigned long _pmd_pfn (pmd_t pmd) { -return pmd_val (pmd) >> _PAGE_PFN_SHIFT; +return (pmd_val (pmd) & _PAGE_CHG_MASK) >> _PAGE_PFN_SHIFT; }The "(
pud_val(pud)&_PAGE_CHG_MASK) >>_PAGE_PFN_SHIFT" expression begs for readable and well-documented helper.
Quoted 6 lines
Quoted 3 lines
How about these:
#define_chg_of_pmd(pmd)(pmd_val(pmd)&_PAGE_CHG_MASK) #define_chg_of_pud(pud)(pud_val(pud)&_PAGE_CHG_MASK)I'd use inline functions instead of macros if possible, but otherwise yes.
Great thanks for your suggestion, I will change this to inline :-)
Quoted 8 lines
Quoted 8 lines
How about :
extern unsigned long
_svpbmt_maskextern unsigned long_svpbmt_mt_pmaextern unsigned long_svpbmt_mt_ncextern unsigned long_svpbmt_mt_io
Quoted 6 lines
Quoted 4 lines
#define
_PAGE_MT_MASK_svpbmt_mask
#define_PAGE_MT_PMA_svpbmt_mt_pma
#define_PAGE_MT_NC_svpbmt_mt_nc
#define_PAGE_MT_IO_svpbmt_mt_ioLooks much better.
Thanks , will do this way
Quoted 1 line
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 14 lines · On Sun, 24 Oct 2021 21:06:05 PDT (-0700), [email protected] wrote:
From: Fu Wei <[email protected]>
This patch follows the RISC-V standard Svpbmt extension in privilege spec to solve the non-coherent SOC DMA synchronization issues.
The svpbmt PTE format:
| 63 | 62-61 | 60-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 N MT RSW D A G U X W R V ^Of the Reserved bits [63:54] in a leaf PTE, the bits [62:61] are used as the MT (aka MemType) field. This field specifies one of three memory types as shown in the following table:
Quoted 6 lines
MemType RISC-V Description ---------- ------------------------------------------------ 00 - PMA Normal Cacheable, No change to implied PMA memory type 01 - NC Non-cacheable, idempotent, weakly-ordered Main Memory 10 - IO Non-cacheable, non-idempotent, strongly-ordered I/O memory 11 - Rsvd Reserved for future standard use
Do you have a pointer to the spec that contains these? I'm specifically
worried about these page-based attributes being elided when paging is
off (ie, M-mode), which has caused issues in systems I've worked with in
the past. I'm assuming there's something related to this in the specs,
but I'm worried we'll need some sort of ack from M-mode that it's been
setup to work that way. One could imagine an MPRV-like approach working, but I don't see enough in the old specs and I'm having trouble figuring out where the canonical version of this lives.
Quoted 9 lines
The standard protection_map[] needn't be modified because the "PMA" type keeps the highest bits zero.
And the whole modification is limited in thearch/riscv/*and using a globalvariable(__riscv_svpbmt)as _PAGE_DMA_MASK/IO/NC forpgprot_noncached(&writecombine) inpgtable.h.
We also add_PAGE_CHG_MASKto filter PFN than before.Enable it in devicetree - (Add "mmu-supports-svpbmt" in cpu node)
- mmu-supports-svpbmt
Maybe this is enough of an ack, but we'll need to have some pretty
specific documentation if that's the case. It's not described that way in the docs right now, they just talk about CPU support (IMO we could probe that with a trap, but I'm fine with the DT entry as it's a bit simpler).
Quoted 12 lines
Wei Fu (2):
dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
riscv: add RISC-V Svpbmt extension supports.../devicetree/bindings/riscv/cpus.yaml | 5 +++ arch/riscv/include/asm/fixmap.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 8 ++-- arch/riscv/include/asm/pgtable-bits.h | 41 ++++++++++++++++++- arch/riscv/include/asm/pgtable.h | 39 ++++++++++++++---- arch/riscv/kernel/cpufeature.c | 32 +++++++++++++++ arch/riscv/mm/init.c | 5 +++ 7 files changed, 117 insertions(+), 15 deletions(-)
Quoted 22 lines · Palmer Dabbelt
Quoted 11 lines · On Sun, 24 Oct 2021 21:06:05 PDT (-0700), [email protected] wrote:
From: Fu Wei <[email protected]>
This patch follows the RISC-V standard Svpbmt extension in privilege spec to solve the non-coherent SOC DMA synchronization issues.
The svpbmt PTE format:
| 63 | 62-61 | 60-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 N MT RSW D A G U X W R V ^Quoted 9 lines
Of the Reserved bits [63:54] in a leaf PTE, the bits [62:61] are used as the MT (aka MemType) field. This field specifies one of three memory types as shown in the following table:
MemType RISC-V Description
---------- ------------------------------------------------ 00 - PMA Normal Cacheable, No change to implied PMA memory type 01 - NC Non-cacheable, idempotent, weakly-ordered Main Memory 10 - IO Non-cacheable, non-idempotent, strongly-ordered I/O memory 11 - Rsvd Reserved for future standard use
Quoted 6 lines
Do you have a pointer to the spec that contains these? I'm specifically
worried about these page-based attributes being elided when paging is
off (ie, M-mode), which has caused issues in systems I've worked with in
the past. I'm assuming there's something related to this in the specs,
but I'm worried we'll need some sort of ack from M-mode that it's been
setup to work that way. One could imagine an MPRV-like approach working, but I don't see enough in the old specs and I'm having trouble figuring out where the canonical version of this lives.
The draft version of the spec is available in chapter 6, p 87 of
https://raw.githubusercontent.com/riscv/virtual-memory/main/specs/663-Svpbmt.pdf
According to https://groups.google.com/a/groups.riscv.org/g/isa-dev/c/nOrD9t9ImEw/m/tstjm4QbAAAJ review has started Sep 17th.
Best regards
Heinrich
Quoted 26 lines
Quoted 10 lines
The standard protection_map[] needn't be modified because the "PMA" type keeps the highest bits zero.
And the whole modification is limited in thearch/riscv/*and using a globalvariable(__riscv_svpbmt)as _PAGE_DMA_MASK/IO/NC forpgprot_noncached(&writecombine) inpgtable.h.
We also add_PAGE_CHG_MASKto filter PFN than before.Enable it in devicetree - (Add "mmu-supports-svpbmt" in cpu node)
- mmu-supports-svpbmtMaybe this is enough of an ack, but we'll need to have some pretty
specific documentation if that's the case. It's not described that way in the docs right now, they just talk about CPU support (IMO we could probe that with a trap, but I'm fine with the DT entry as it's a bit simpler).Quoted 12 lines
Wei Fu (2):
dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
riscv: add RISC-V Svpbmt extension supports.../devicetree/bindings/riscv/cpus.yaml | 5 +++ arch/riscv/include/asm/fixmap.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 8 ++-- arch/riscv/include/asm/pgtable-bits.h | 41 ++++++++++++++++++- arch/riscv/include/asm/pgtable.h | 39 ++++++++++++++---- arch/riscv/kernel/cpufeature.c | 32 +++++++++++++++ arch/riscv/mm/init.c | 5 +++
7 files changed, 117 insertions(+), 15 deletions(-)
Quoted 23 lines · Palmer Dabbelt
Quoted 14 lines · On Sun, 24 Oct 2021 21:06:05 PDT (-0700), [email protected] wrote:
From: Fu Wei <[email protected]>
This patch follows the RISC-V standard Svpbmt extension in privilege spec to solve the non-coherent SOC DMA synchronization issues.
The svpbmt PTE format:
| 63 | 62-61 | 60-8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 N MT RSW D A G U X W R V ^Of the Reserved bits [63:54] in a leaf PTE, the bits [62:61] are used as the MT (aka MemType) field. This field specifies one of three memory types as shown in the following table:
Quoted 6 lines
MemType RISC-V Description ---------- ------------------------------------------------ 00 - PMA Normal Cacheable, No change to implied PMA memory type 01 - NC Non-cacheable, idempotent, weakly-ordered Main Memory 10 - IO Non-cacheable, non-idempotent, strongly-ordered I/O memory 11 - Rsvd Reserved for future standard use
Quoted 4 lines
Do you have a pointer to the spec that contains these? I'm specifically worried about these page-based attributes being elided when paging is off (ie, M-mode), which has caused issues in systems I've worked with in the past.
Don't worry about that, I've compiled the Linux with the patch and below modification in k210_nommu_defconfig. Passed
(quoted diff) +0 -0
b/arch/riscv/include/asm/pgtable-bits.h
index 3b38fe14f169..b4bb41337fdc 100644
arch/riscv/include/asm/pgtable-bits.h +1 -1
@@ -25,7 +25,7 @@#define _PAGE_SOFT (1 << 8)/* Reserved for software */ #ifndef __ASSEMBLY__ -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT ) && defined(CONFIG_MMU )/* * rv64 PTE format: * | 63 | 62 61 | 60 54 | 53 10 | 9 8 | 7 | 6 | 5 | 4 |
3 | 2 | 1 | 0
arch/riscv/mm/init.c +0 -0
@@ -856,7 +856,7 @@ int __meminit vmemmap_populate(unsigned long
start, unsigned long end, int node,
}
#endif
-#ifdef CONFIG_64BIT
+#if defined(CONFIG_64BIT) && defined(CONFIG_MMU)
struct __riscv_svpbmt_struct __riscv_svpbmt __ro_after_init; EXPORT_SYMBOL(__riscv_svpbmt);
So, I don't think the patch would affect M-mode nommu Linux.
To separate MMU & no-MMU clearly, I suggest fuwei add #if defined(CONFIG_64BIT) && defined(CONFIG_MMU)
Quoted 34 lines
I'm assuming there's something related to this in the specs, but I'm worried we'll need some sort of ack from M-mode that it's been setup to work that way. One could imagine an MPRV-like approach working, but I don't see enough in the old specs and I'm having trouble figuring out where the canonical version of this lives.
Quoted 9 lines
The standard protection_map[] needn't be modified because the "PMA" type keeps the highest bits zero.
And the whole modification is limited in thearch/riscv/*and using a globalvariable(__riscv_svpbmt)as _PAGE_DMA_MASK/IO/NC forpgprot_noncached(&writecombine) inpgtable.h.
We also add_PAGE_CHG_MASKto filter PFN than before.Enable it in devicetree - (Add "mmu-supports-svpbmt" in cpu node)
- mmu-supports-svpbmtMaybe this is enough of an ack, but we'll need to have some pretty specific documentation if that's the case. It's not described that way in the docs right now, they just talk about CPU support (IMO we could probe that with a trap, but I'm fine with the DT entry as it's a bit simpler).
Quoted 12 lines
Wei Fu (2):
dt-bindings: riscv: add mmu-supports-svpbmt for Svpbmt
riscv: add RISC-V Svpbmt extension supports.../devicetree/bindings/riscv/cpus.yaml | 5 +++ arch/riscv/include/asm/fixmap.h | 2 +- arch/riscv/include/asm/pgtable-64.h | 8 ++-- arch/riscv/include/asm/pgtable-bits.h | 41 ++++++++++++++++++- arch/riscv/include/asm/pgtable.h | 39 ++++++++++++++---- arch/riscv/kernel/cpufeature.c | 32 +++++++++++++++ arch/riscv/mm/init.c | 5 +++ 7 files changed, 117 insertions(+), 15 deletions(-)
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
Quoted 3 lines · Guo Ren
To separate MMU & no-MMU clearly, I suggest fuwei add #if
defined(CONFIG_64BIT)&&defined(CONFIG_MMU)
Actually - for documentation purposes a new CONFIG_RISCV_SVPBMT that depends on 64BIT && MMU would probably much better as it clearly documents the intent here.
Thx Christoph,
Quoted 9 lines · Christoph Hellwig
Quoted 3 lines · Guo Ren
To separate MMU & no-MMU clearly, I suggest fuwei add #if
defined(CONFIG_64BIT)&&defined(CONFIG_MMU)Actually - for documentation purposes a new
CONFIG_RISCV_SVPBMTthat depends on 64BIT && MMU would probably much better as it clearly documents the intent here.
Okay
Signature · 4 lines
Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/
HI Guo, Christoph,
Thanks for your suggestion.
Quoted 7 lines · Guo Ren
Thx Christoph,
Quoted 3 lines · Christoph Hellwig
Quoted 1 line · Guo Ren
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
To separate MMU & no-MMU clearly, I suggest fuwei add #if
defined(CONFIG_64BIT)&&defined(CONFIG_MMU)Actually - for documentation purposes a new
CONFIG_RISCV_SVPBMTthat depends on 64BIT && MMU would probably much better as it clearly documents the intent here.Okay
How about
config RISCV_SVPBMT
bool
depends on 64BIT && MMU
default y
Quoted 8 lines
--
Best Regards
Guo Ren
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv
Quoted 6 lines · Wei Fu
How about
config
RISCV_SVPBMT
bool
depends on 64BIT && MMU
default y
Yes. You can shorten this a bit more using def_bool if you want.
Hi Christoph,
Quoted 10 lines · Christoph Hellwig
Quoted 6 lines · Wei Fu
How about
config
RISCV_SVPBMT
bool
depends on 64BIT && MMU
default yYes. You can shorten this a bit more using
def_boolif you want.
Sorry for the late reply, OK, fixing it now
Quoted 1 line
_______________________________________________
linux-riscv mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-riscv