riscv: Add HAVE_IOREMAP_PROT support
Subsystems (3)
PATCH 1/1 riscv: Add HAVE_IOREMAP_PROT support
From: Guo Ren <[email protected]>
Add pte_pgprot macro, then riscv could have HAVE_IOREMAP_PROT, which will enable generic_access_phys() code, it is useful for debug, eg, gdb.
Because generic_access_phys() would call ioremap_prot()-> pgprot_nx() to disable excutable attribute, add definition of pgprot_nx() for riscv.
--- .../features/vm/ioremap_prot/arch-support.txt | 2 +- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/pgtable.h | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-)
Documentation/features/vm/ioremap_prot/arch-support.txt +1 -1
@@ -21,7 +21,7 @@ | openrisc: | TODO | | parisc: | TODO | | powerpc: | ok | - | riscv: | TODO | + | riscv: | ok | | s390: | ok | | sh: | ok | | sparc: | TODO |
arch/riscv/Kconfig +1 -0
@@ -117,6 +117,7 @@ config RISCV select HAVE_FUNCTION_ERROR_INJECTION select HAVE_GCC_PLUGINS select HAVE_GENERIC_VDSO if MMU && 64BIT + select HAVE_IOREMAP_PROT select HAVE_IRQ_TIME_ACCOUNTING select HAVE_KPROBES if !XIP_KERNEL select HAVE_KPROBES_ON_FTRACE if !XIP_KERNEL
arch/riscv/include/asm/pgtable.h +15 -0
@@ -415,6 +415,11 @@ static inline pte_t pte_mkhuge(pte_t pte)return pte; } +static inline pgprot_t pte_pgprot (pte_t pte) +{ +return __pgprot (pte_val (pte) & ~_PAGE_PFN_MASK); +} +#ifdef CONFIG_NUMA_BALANCING /* * See the comment in include/asm-generic/pgtable.h
@@ -573,6 +578,16 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,return ptep_test_and_clear_young (vma, address, ptep); } +#define pgprot_nx pgprot_nx +static inline pgprot_t pgprot_nx (pgprot_t _prot) +{ +unsigned long prot =pgprot_val (_prot); + + prot &= ~_PAGE_EXEC; + +return __pgprot (prot); +} +#define pgprot_noncached pgprot_noncachedstatic inline pgprot_t pgprot_noncached (pgprot_t _prot) {
Signature · 1 line
2.36.1
Alexandre Ghiti
reviewerHi Guo,
Quoted 5 lines · On 16/07/2023 17:20, [email protected] wrote:
From: Guo Ren <[email protected]>
Add
pte_pgprotmacro, then riscv could haveHAVE_IOREMAP_PROT, which will enablegeneric_access_phys()code, it is useful for debug, eg, gdb.
I don't understand, we already have the generic ioremap_prot() implementation since we select GENERIC_IOREMAP: shouldn't HAVE_IOREMAP_PROT imply that we have our own implementation?
Thanks,
Alex
Quoted 70 lines
Because
generic_access_phys()would call ioremap_prot()->pgprot_nx()to disable excutable attribute, add definition ofpgprot_nx()for riscv.Signed-off-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>--- .../features/vm/ioremap_prot/arch-support.txt | 2 +- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/pgtable.h | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-)Documentation/features/vm/ioremap_prot/arch-support.txt +1
-1@@ -21,7 +21,7 @@ | openrisc: | TODO | | parisc: | TODO | | powerpc: | ok | - | riscv: | TODO | + | riscv: | ok | | s390: | ok | | sh: | ok | | sparc: | TODO |arch/riscv/Kconfig +1
-0@@ -117,6 +117,7 @@ config RISCV select HAVE_FUNCTION_ERROR_INJECTION select HAVE_GCC_PLUGINS select HAVE_GENERIC_VDSO if MMU && 64BIT + select HAVE_IOREMAP_PROT select HAVE_IRQ_TIME_ACCOUNTING select HAVE_KPROBES if !XIP_KERNEL select HAVE_KPROBES_ON_FTRACE if !XIP_KERNELarch/riscv/include/asm/pgtable.h +15
-0@@ -415,6 +415,11 @@ static inline pte_t pte_mkhuge(pte_t pte)return pte; } +static inline pgprot_t pte_pgprot (pte_t pte) +{ +return __pgprot (pte_val (pte) & ~_PAGE_PFN_MASK); +} +#ifdef CONFIG_NUMA_BALANCING /* * See the comment in include/asm-generic/pgtable.h @@ -573,6 +578,16 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,return ptep_test_and_clear_young (vma, address, ptep); } +#define pgprot_nx pgprot_nx +static inline pgprot_t pgprot_nx (pgprot_t _prot) +{ +unsigned long prot =pgprot_val (_prot); + + prot &= ~_PAGE_EXEC; + +return __pgprot (prot); +} +#define pgprot_noncached pgprot_noncachedstatic inline pgprot_t pgprot_noncached (pgprot_t _prot) {
Quoted 6 lines · Alexandre Ghiti
Hi Guo,
Quoted 2 lines · On 16/07/2023 17:20, [email protected] wrote:
From: Guo Ren <[email protected]>
Quoted 8 lines
Quoted 3 lines
Add
pte_pgprotmacro, then riscv could haveHAVE_IOREMAP_PROT, which will enablegeneric_access_phys()code, it is useful for debug, eg, gdb.I don't understand, we already have the generic
ioremap_prot()implementation since we selectGENERIC_IOREMAP: shouldn'tHAVE_IOREMAP_PROTimply that we have our own implementation?
They are different! See arch/arm64/Kconfig, which selects all of them.
HAVE_IOREMAP_PROT would enable your drivers/char/mem.c generic_access_phys of mmap_mem_ops.
It's a small function enabling.
Quoted 76 lines
Thanks,
Alex
Quoted 70 lines
Because
generic_access_phys()would call ioremap_prot()->pgprot_nx()to disable excutable attribute, add definition ofpgprot_nx()for riscv.Signed-off-by Guo Ren <[email protected]>Signed-off-by Guo Ren <[email protected]>--- .../features/vm/ioremap_prot/arch-support.txt | 2 +- arch/riscv/Kconfig | 1 + arch/riscv/include/asm/pgtable.h | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-)Documentation/features/vm/ioremap_prot/arch-support.txt +1
-1@@ -21,7 +21,7 @@ | openrisc: | TODO | | parisc: | TODO | | powerpc: | ok | - | riscv: | TODO | + | riscv: | ok | | s390: | ok | | sh: | ok | | sparc: | TODO |arch/riscv/Kconfig +1
-0@@ -117,6 +117,7 @@ config RISCV select HAVE_FUNCTION_ERROR_INJECTION select HAVE_GCC_PLUGINS select HAVE_GENERIC_VDSO if MMU && 64BIT + select HAVE_IOREMAP_PROT select HAVE_IRQ_TIME_ACCOUNTING select HAVE_KPROBES if !XIP_KERNEL select HAVE_KPROBES_ON_FTRACE if !XIP_KERNELarch/riscv/include/asm/pgtable.h +15
-0@@ -415,6 +415,11 @@ static inline pte_t pte_mkhuge(pte_t pte)return pte; } +static inline pgprot_t pte_pgprot (pte_t pte) +{ +return __pgprot (pte_val (pte) & ~_PAGE_PFN_MASK); +} +#ifdef CONFIG_NUMA_BALANCING /* * See the comment in include/asm-generic/pgtable.h @@ -573,6 +578,16 @@ static inline int ptep_clear_flush_young(struct vm_area_struct *vma,return ptep_test_and_clear_young (vma, address, ptep); } +#define pgprot_nx pgprot_nx +static inline pgprot_t pgprot_nx (pgprot_t _prot) +{ +unsigned long prot =pgprot_val (_prot); + + prot &= ~_PAGE_EXEC; + +return __pgprot (prot); +} +#define pgprot_noncached pgprot_noncachedstatic inline pgprot_t pgprot_noncached (pgprot_t _prot) {
Signature · 2 lines
Best Regards Guo Ren