arm: Introduce {set,clear}_pte_bit
PATCH RESEND 1/2 arm: Introduce {set,clear}_pte_bit
Introduce helper functions for pte_mk* functions and it would be used to change individual bits in ptes at times.
Signed-off-by Jungseung Lee <[email protected]>
--- arch/arm/include/asm/pgtable.h | 62 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 11 deletions(-)
arch/arm/include/asm/pgtable.h +51 -11
@@ -252,17 +252,57 @@ static inline void set_pte_at(struct mm_struct *mm, unsigned long addr,set_pte_ext (ptep, pteval, ext); } -#define PTE_BIT_FUNC (fn,op) \ -static inline pte_t pte_##fn(pte_t pte) { pte_val(pte) op; return pte; } - -PTE_BIT_FUNC(wrprotect, |= L_PTE_RDONLY); -PTE_BIT_FUNC(mkwrite, &= ~L_PTE_RDONLY); -PTE_BIT_FUNC(mkclean, &= ~L_PTE_DIRTY); -PTE_BIT_FUNC(mkdirty, |= L_PTE_DIRTY); -PTE_BIT_FUNC(mkold, &= ~L_PTE_YOUNG); -PTE_BIT_FUNC(mkyoung, |= L_PTE_YOUNG); -PTE_BIT_FUNC(mkexec, &= ~L_PTE_XN); -PTE_BIT_FUNC(mknexec, |= L_PTE_XN); +static inline pte_t clear_pte_bit (pte_t pte,pgprot_t prot) +{ +pte_val (pte) &= ~pgprot_val (prot); +return pte; +} + +static inline pte_t set_pte_bit (pte_t pte,pgprot_t prot) +{ +pte_val (pte) |=pgprot_val (prot); +return pte; +} + +static inline pte_t pte_wrprotect (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (L_PTE_RDONLY )); +} + +static inline pte_t pte_mkwrite (pte_t pte) +{ +return clear_pte_bit (pte,__pgprot (L_PTE_RDONLY )); +} + +static inline pte_t pte_mkclean (pte_t pte) +{ +return clear_pte_bit (pte,__pgprot (L_PTE_DIRTY )); +} + +static inline pte_t pte_mkdirty (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (L_PTE_DIRTY )); +} + +static inline pte_t pte_mkold (pte_t pte) +{ +return clear_pte_bit (pte,__pgprot (L_PTE_YOUNG )); +} + +static inline pte_t pte_mkyoung (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (L_PTE_YOUNG )); +} + +static inline pte_t pte_mkexec (pte_t pte) +{ +return clear_pte_bit (pte,__pgprot (L_PTE_XN )); +} + +static inline pte_t pte_mknexec (pte_t pte) +{ +return set_pte_bit (pte,__pgprot (L_PTE_XN )); +}static inline pte_t pte_modify (pte_t pte,pgprot_t newprot) {
Signature · 1 line
1.9.1
PATCH RESEND 2/2 arm: mm: Refine set_memory_* functions
set_memory_* functions have same implementation
except memory attribute.
This patch makes to use common function for these, and pull out the functions into arch/arm/mm/pageattr.c like arm64 did. It will reduce code size and enhance the readability.
Signed-off-by Jungseung Lee <[email protected]>
--- arch/arm/mm/Makefile | 2 +- arch/arm/mm/mmu.c | 38 --------------------- arch/arm/mm/pageattr.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 92 insertions(+), 39 deletions(-) create mode 100644 arch/arm/mm/pageattr.c
arch/arm/mm/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-y := dma-mapping.o extable.o fault.o init.o \ iomap.o obj-$(CONFIG_MMU) += fault-armv.o flush.o idmap.o ioremap.o \ - mmap.o pgd.o mmu.o + mmap.o pgd.o mmu.o pageattr.o ifneq ($(CONFIG_MMU),y) obj-y += nommu.o
arch/arm/mm/mmu.c +0 -38
@@ -354,44 +354,6 @@ const struct mem_type *get_mem_type(unsigned int type) }EXPORT_SYMBOL (get_mem_type); -#define PTE_SET_FN (_name, pteop) \ -static int pte_set_##_name(pte_t *ptep, pgtable_t token, unsigned long addr, \ - void *data) \ -{ \ - pte_t pte = pteop(*ptep); \ -\ - set_pte_ext(ptep, pte, 0); \ - return 0; \ -} \ - -#define SET_MEMORY_FN (_name, callback) \ -int set_memory_##_name(unsigned long addr, int numpages) \ -{ \ - unsigned long start = addr; \ - unsigned long size = PAGE_SIZE*numpages; \ - unsigned end = start + size; \ -\ - if (start < MODULES_VADDR || start >= MODULES_END) \ - return -EINVAL;\ -\ - if (end < MODULES_VADDR || end >= MODULES_END) \ - return -EINVAL; \ -\ - apply_to_page_range(&init_mm, start, size, callback, NULL); \ - flush_tlb_kernel_range(start, end); \ - return 0;\ -} - -PTE_SET_FN(ro, pte_wrprotect) -PTE_SET_FN(rw, pte_mkwrite) -PTE_SET_FN(x, pte_mkexec) -PTE_SET_FN(nx, pte_mknexec) - -SET_MEMORY_FN(ro, pte_set_ro) -SET_MEMORY_FN(rw, pte_set_rw) -SET_MEMORY_FN(x, pte_set_x) -SET_MEMORY_FN (nx, pte_set_nx) -/* * Adjust the PMD section entries according to the CPU in use. */
arch/arm/mm/pageattr.c new file +91 -0
91 lines not on this page · raw message
Signature · 1 line
1.9.1