ARM: mm: Refine set_memory_* functions
PATCH 1/1 ARM: mm: Refine set_memory_* functions
set_memory_* functions have same implementation
without memory attribute.
This is a change to reduce code size and enhance
the readability
Signed-off-by Jungseung Lee <[email protected]>
--- arch/arm/mm/mmu.c | 70 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 22 deletions(-)
arch/arm/mm/mmu.c +48 -22
@@ -364,33 +364,59 @@ static int pte_set_##_name(pte_t *ptep, pgtable_t token, unsigned long addr, \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) +static int set_memory_attr (unsigned long addr,pte_fn_t fn,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, fn,NULL ); +flush_tlb_kernel_range (start, end); +return 0 ; +} + +int set_memory_ro (unsigned long addr,int numpages) +{ +int ret; + + ret =set_memory_attr (addr, pte_set_ro, numpages); +return ret; +} + +int set_memory_rw (unsigned long addr,int numpages) +{ +int ret; + + ret =set_memory_attr (addr, pte_set_rw, numpages); +return ret; +} + +int set_memory_x (unsigned long addr,int numpages) +{ +int ret; + + ret =set_memory_attr (addr, pte_set_x, numpages); +return ret; +} + +int set_memory_nx (unsigned long addr,int numpages) +{ +int ret; + + ret =set_memory_attr (addr, pte_set_nx, numpages); +return ret; +}/* * Adjust the PMD section entries according to the CPU in use.
Signature · 1 line
1.9.1
PATCH 1/1 ARM: mm: Refine set_memory_* functions
Quoted 7 lines · Jungseung Lee
set_memory_* functions have same implementation
without memory attribute.This is a change to reduce code size and enhance
the readabilitySigned-off-by Jungseung Lee <[email protected]>
Similar code for arm64 was recently merged. The functions there were pulled out into arch/arm64/mm/pageattr.c. It would be good if arm could match arm64 in that respect.
Thanks,
Laura
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation