aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJungseung Lee <js07.lee@gmail.com>2014-11-28 21:02:11 -0500
committerRussell King <rmk+kernel@arm.linux.org.uk>2014-12-03 11:00:05 -0500
commit4e802cfd74e6351cb937997996de9ca2e67df9f2 (patch)
tree247b20f6c8b42bf3dc5fc9aeaa0ff52af96f5e6c
parent12e669b4874274caaefd20d3c729471b8ebe8d93 (diff)
ARM: 8238/1: 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 <js07.lee@gmail.com> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
-rw-r--r--arch/arm/mm/Makefile2
-rw-r--r--arch/arm/mm/mmu.c38
-rw-r--r--arch/arm/mm/pageattr.c91
3 files changed, 92 insertions, 39 deletions
diff --git a/arch/arm/mm/Makefile b/arch/arm/mm/Makefile
index 91da64de440f..d3afdf9eb65a 100644
--- a/arch/arm/mm/Makefile
+++ b/arch/arm/mm/Makefile
@@ -6,7 +6,7 @@ obj-y := dma-mapping.o extable.o fault.o init.o \
6 iomap.o 6 iomap.o
7 7
8obj-$(CONFIG_MMU) += fault-armv.o flush.o idmap.o ioremap.o \ 8obj-$(CONFIG_MMU) += fault-armv.o flush.o idmap.o ioremap.o \
9 mmap.o pgd.o mmu.o 9 mmap.o pgd.o mmu.o pageattr.o
10 10
11ifneq ($(CONFIG_MMU),y) 11ifneq ($(CONFIG_MMU),y)
12obj-y += nommu.o 12obj-y += nommu.o
diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
index b590a4c92462..f86ce1a9f525 100644
--- a/arch/arm/mm/mmu.c
+++ b/arch/arm/mm/mmu.c
@@ -356,44 +356,6 @@ const struct mem_type *get_mem_type(unsigned int type)
356} 356}
357EXPORT_SYMBOL(get_mem_type); 357EXPORT_SYMBOL(get_mem_type);
358 358
359#define PTE_SET_FN(_name, pteop) \
360static int pte_set_##_name(pte_t *ptep, pgtable_t token, unsigned long addr, \
361 void *data) \
362{ \
363 pte_t pte = pteop(*ptep); \
364\
365 set_pte_ext(ptep, pte, 0); \
366 return 0; \
367} \
368
369#define SET_MEMORY_FN(_name, callback) \
370int set_memory_##_name(unsigned long addr, int numpages) \
371{ \
372 unsigned long start = addr; \
373 unsigned long size = PAGE_SIZE*numpages; \
374 unsigned end = start + size; \
375\
376 if (start < MODULES_VADDR || start >= MODULES_END) \
377 return -EINVAL;\
378\
379 if (end < MODULES_VADDR || end >= MODULES_END) \
380 return -EINVAL; \
381\
382 apply_to_page_range(&init_mm, start, size, callback, NULL); \
383 flush_tlb_kernel_range(start, end); \
384 return 0;\
385}
386
387PTE_SET_FN(ro, pte_wrprotect)
388PTE_SET_FN(rw, pte_mkwrite)
389PTE_SET_FN(x, pte_mkexec)
390PTE_SET_FN(nx, pte_mknexec)
391
392SET_MEMORY_FN(ro, pte_set_ro)
393SET_MEMORY_FN(rw, pte_set_rw)
394SET_MEMORY_FN(x, pte_set_x)
395SET_MEMORY_FN(nx, pte_set_nx)
396
397/* 359/*
398 * Adjust the PMD section entries according to the CPU in use. 360 * Adjust the PMD section entries according to the CPU in use.
399 */ 361 */
diff --git a/arch/arm/mm/pageattr.c b/arch/arm/mm/pageattr.c
new file mode 100644
index 000000000000..004e35cdcfff
--- /dev/null
+++ b/arch/arm/mm/pageattr.c
@@ -0,0 +1,91 @@
1/*
2 * Copyright (c) 2014, The Linux Foundation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 and
6 * only version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13#include <linux/mm.h>
14#include <linux/module.h>
15
16#include <asm/pgtable.h>
17#include <asm/tlbflush.h>
18
19struct page_change_data {
20 pgprot_t set_mask;
21 pgprot_t clear_mask;
22};
23
24static int change_page_range(pte_t *ptep, pgtable_t token, unsigned long addr,
25 void *data)
26{
27 struct page_change_data *cdata = data;
28 pte_t pte = *ptep;
29
30 pte = clear_pte_bit(pte, cdata->clear_mask);
31 pte = set_pte_bit(pte, cdata->set_mask);
32
33 set_pte_ext(ptep, pte, 0);
34 return 0;
35}
36
37static int change_memory_common(unsigned long addr, int numpages,
38 pgprot_t set_mask, pgprot_t clear_mask)
39{
40 unsigned long start = addr;
41 unsigned long size = PAGE_SIZE*numpages;
42 unsigned long end = start + size;
43 int ret;
44 struct page_change_data data;
45
46 if (!IS_ALIGNED(addr, PAGE_SIZE)) {
47 start &= PAGE_MASK;
48 end = start + size;
49 WARN_ON_ONCE(1);
50 }
51
52 if (!is_module_address(start) || !is_module_address(end - 1))
53 return -EINVAL;
54
55 data.set_mask = set_mask;
56 data.clear_mask = clear_mask;
57
58 ret = apply_to_page_range(&init_mm, start, size, change_page_range,
59 &data);
60
61 flush_tlb_kernel_range(start, end);
62 return ret;
63}
64
65int set_memory_ro(unsigned long addr, int numpages)
66{
67 return change_memory_common(addr, numpages,
68 __pgprot(L_PTE_RDONLY),
69 __pgprot(0));
70}
71
72int set_memory_rw(unsigned long addr, int numpages)
73{
74 return change_memory_common(addr, numpages,
75 __pgprot(0),
76 __pgprot(L_PTE_RDONLY));
77}
78
79int set_memory_nx(unsigned long addr, int numpages)
80{
81 return change_memory_common(addr, numpages,
82 __pgprot(L_PTE_XN),
83 __pgprot(0));
84}
85
86int set_memory_x(unsigned long addr, int numpages)
87{
88 return change_memory_common(addr, numpages,
89 __pgprot(0),
90 __pgprot(L_PTE_XN));
91}