diff options
author | Laura Abbott <labbott@redhat.com> | 2017-05-08 18:57:59 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-08 20:15:13 -0400 |
commit | 299878bac326c890699c696ebba26f56fe93fc75 (patch) | |
tree | e9f9ba4a5deef3486e0a4371edc6ecccbe6d63f5 | |
parent | 8ac1ed791401790968fd00ca63ca4fa814677199 (diff) |
treewide: move set_memory_* functions away from cacheflush.h
Patch series "set_memory_* functions header refactor", v3.
The set_memory_* APIs came out of a desire to have a better way to
change memory attributes. Many of these attributes were linked to cache
functionality so the prototypes were put in cacheflush.h. These days,
the APIs have grown and have a much wider use than just cache APIs. To
support this growth, split off set_memory_* and friends into a separate
header file to avoid growing cacheflush.h for APIs that have nothing to
do with caches.
Link: http://lkml.kernel.org/r/1488920133-27229-2-git-send-email-labbott@redhat.com
Signed-off-by: Laura Abbott <labbott@redhat.com>
Acked-by: Russell King <rmk+kernel@armlinux.org.uk>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | arch/arm/include/asm/cacheflush.h | 21 | ||||
-rw-r--r-- | arch/arm/include/asm/set_memory.h | 32 | ||||
-rw-r--r-- | arch/arm64/include/asm/Kbuild | 1 | ||||
-rw-r--r-- | arch/arm64/include/asm/cacheflush.h | 5 | ||||
-rw-r--r-- | arch/s390/include/asm/cacheflush.h | 28 | ||||
-rw-r--r-- | arch/s390/include/asm/set_memory.h | 31 | ||||
-rw-r--r-- | arch/x86/include/asm/cacheflush.h | 86 | ||||
-rw-r--r-- | arch/x86/include/asm/set_memory.h | 87 | ||||
-rw-r--r-- | include/asm-generic/set_memory.h | 12 |
9 files changed, 167 insertions, 136 deletions
diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h index 02454fa15d2c..1cb9d118bb16 100644 --- a/arch/arm/include/asm/cacheflush.h +++ b/arch/arm/include/asm/cacheflush.h | |||
@@ -16,6 +16,7 @@ | |||
16 | #include <asm/shmparam.h> | 16 | #include <asm/shmparam.h> |
17 | #include <asm/cachetype.h> | 17 | #include <asm/cachetype.h> |
18 | #include <asm/outercache.h> | 18 | #include <asm/outercache.h> |
19 | #include <asm/set_memory.h> | ||
19 | 20 | ||
20 | #define CACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT) | 21 | #define CACHE_COLOUR(vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT) |
21 | 22 | ||
@@ -478,26 +479,6 @@ static inline void __sync_cache_range_r(volatile void *p, size_t size) | |||
478 | : : : "r0","r1","r2","r3","r4","r5","r6","r7", \ | 479 | : : : "r0","r1","r2","r3","r4","r5","r6","r7", \ |
479 | "r9","r10","lr","memory" ) | 480 | "r9","r10","lr","memory" ) |
480 | 481 | ||
481 | #ifdef CONFIG_MMU | ||
482 | int set_memory_ro(unsigned long addr, int numpages); | ||
483 | int set_memory_rw(unsigned long addr, int numpages); | ||
484 | int set_memory_x(unsigned long addr, int numpages); | ||
485 | int set_memory_nx(unsigned long addr, int numpages); | ||
486 | #else | ||
487 | static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } | ||
488 | static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; } | ||
489 | static inline int set_memory_x(unsigned long addr, int numpages) { return 0; } | ||
490 | static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } | ||
491 | #endif | ||
492 | |||
493 | #ifdef CONFIG_STRICT_KERNEL_RWX | ||
494 | void set_kernel_text_rw(void); | ||
495 | void set_kernel_text_ro(void); | ||
496 | #else | ||
497 | static inline void set_kernel_text_rw(void) { } | ||
498 | static inline void set_kernel_text_ro(void) { } | ||
499 | #endif | ||
500 | |||
501 | void flush_uprobe_xol_access(struct page *page, unsigned long uaddr, | 482 | void flush_uprobe_xol_access(struct page *page, unsigned long uaddr, |
502 | void *kaddr, unsigned long len); | 483 | void *kaddr, unsigned long len); |
503 | 484 | ||
diff --git a/arch/arm/include/asm/set_memory.h b/arch/arm/include/asm/set_memory.h new file mode 100644 index 000000000000..5aa4315abe91 --- /dev/null +++ b/arch/arm/include/asm/set_memory.h | |||
@@ -0,0 +1,32 @@ | |||
1 | /* | ||
2 | * Copyright (C) 1999-2002 Russell King | ||
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 as | ||
6 | * published by the Free Software Foundation. | ||
7 | */ | ||
8 | |||
9 | #ifndef _ASMARM_SET_MEMORY_H | ||
10 | #define _ASMARM_SET_MEMORY_H | ||
11 | |||
12 | #ifdef CONFIG_MMU | ||
13 | int set_memory_ro(unsigned long addr, int numpages); | ||
14 | int set_memory_rw(unsigned long addr, int numpages); | ||
15 | int set_memory_x(unsigned long addr, int numpages); | ||
16 | int set_memory_nx(unsigned long addr, int numpages); | ||
17 | #else | ||
18 | static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } | ||
19 | static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; } | ||
20 | static inline int set_memory_x(unsigned long addr, int numpages) { return 0; } | ||
21 | static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } | ||
22 | #endif | ||
23 | |||
24 | #ifdef CONFIG_STRICT_KERNEL_RWX | ||
25 | void set_kernel_text_rw(void); | ||
26 | void set_kernel_text_ro(void); | ||
27 | #else | ||
28 | static inline void set_kernel_text_rw(void) { } | ||
29 | static inline void set_kernel_text_ro(void) { } | ||
30 | #endif | ||
31 | |||
32 | #endif | ||
diff --git a/arch/arm64/include/asm/Kbuild b/arch/arm64/include/asm/Kbuild index a12f1afc95a3..a7a97a608033 100644 --- a/arch/arm64/include/asm/Kbuild +++ b/arch/arm64/include/asm/Kbuild | |||
@@ -29,6 +29,7 @@ generic-y += rwsem.h | |||
29 | generic-y += segment.h | 29 | generic-y += segment.h |
30 | generic-y += sembuf.h | 30 | generic-y += sembuf.h |
31 | generic-y += serial.h | 31 | generic-y += serial.h |
32 | generic-y += set_memory.h | ||
32 | generic-y += shmbuf.h | 33 | generic-y += shmbuf.h |
33 | generic-y += simd.h | 34 | generic-y += simd.h |
34 | generic-y += sizes.h | 35 | generic-y += sizes.h |
diff --git a/arch/arm64/include/asm/cacheflush.h b/arch/arm64/include/asm/cacheflush.h index 728f933cef8c..0927f47607e2 100644 --- a/arch/arm64/include/asm/cacheflush.h +++ b/arch/arm64/include/asm/cacheflush.h | |||
@@ -20,6 +20,7 @@ | |||
20 | #define __ASM_CACHEFLUSH_H | 20 | #define __ASM_CACHEFLUSH_H |
21 | 21 | ||
22 | #include <linux/mm.h> | 22 | #include <linux/mm.h> |
23 | #include <asm/set_memory.h> | ||
23 | 24 | ||
24 | /* | 25 | /* |
25 | * This flag is used to indicate that the page pointed to by a pte is clean | 26 | * This flag is used to indicate that the page pointed to by a pte is clean |
@@ -150,10 +151,6 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end) | |||
150 | { | 151 | { |
151 | } | 152 | } |
152 | 153 | ||
153 | int set_memory_ro(unsigned long addr, int numpages); | ||
154 | int set_memory_rw(unsigned long addr, int numpages); | ||
155 | int set_memory_x(unsigned long addr, int numpages); | ||
156 | int set_memory_nx(unsigned long addr, int numpages); | ||
157 | int set_memory_valid(unsigned long addr, unsigned long size, int enable); | 154 | int set_memory_valid(unsigned long addr, unsigned long size, int enable); |
158 | 155 | ||
159 | #endif | 156 | #endif |
diff --git a/arch/s390/include/asm/cacheflush.h b/arch/s390/include/asm/cacheflush.h index 0499334f9473..afe296515f76 100644 --- a/arch/s390/include/asm/cacheflush.h +++ b/arch/s390/include/asm/cacheflush.h | |||
@@ -3,32 +3,6 @@ | |||
3 | 3 | ||
4 | /* Caches aren't brain-dead on the s390. */ | 4 | /* Caches aren't brain-dead on the s390. */ |
5 | #include <asm-generic/cacheflush.h> | 5 | #include <asm-generic/cacheflush.h> |
6 | 6 | #include <asm/set_memory.h> | |
7 | #define SET_MEMORY_RO 1UL | ||
8 | #define SET_MEMORY_RW 2UL | ||
9 | #define SET_MEMORY_NX 4UL | ||
10 | #define SET_MEMORY_X 8UL | ||
11 | |||
12 | int __set_memory(unsigned long addr, int numpages, unsigned long flags); | ||
13 | |||
14 | static inline int set_memory_ro(unsigned long addr, int numpages) | ||
15 | { | ||
16 | return __set_memory(addr, numpages, SET_MEMORY_RO); | ||
17 | } | ||
18 | |||
19 | static inline int set_memory_rw(unsigned long addr, int numpages) | ||
20 | { | ||
21 | return __set_memory(addr, numpages, SET_MEMORY_RW); | ||
22 | } | ||
23 | |||
24 | static inline int set_memory_nx(unsigned long addr, int numpages) | ||
25 | { | ||
26 | return __set_memory(addr, numpages, SET_MEMORY_NX); | ||
27 | } | ||
28 | |||
29 | static inline int set_memory_x(unsigned long addr, int numpages) | ||
30 | { | ||
31 | return __set_memory(addr, numpages, SET_MEMORY_X); | ||
32 | } | ||
33 | 7 | ||
34 | #endif /* _S390_CACHEFLUSH_H */ | 8 | #endif /* _S390_CACHEFLUSH_H */ |
diff --git a/arch/s390/include/asm/set_memory.h b/arch/s390/include/asm/set_memory.h new file mode 100644 index 000000000000..46a4db44c47a --- /dev/null +++ b/arch/s390/include/asm/set_memory.h | |||
@@ -0,0 +1,31 @@ | |||
1 | #ifndef _ASMS390_SET_MEMORY_H | ||
2 | #define _ASMS390_SET_MEMORY_H | ||
3 | |||
4 | #define SET_MEMORY_RO 1UL | ||
5 | #define SET_MEMORY_RW 2UL | ||
6 | #define SET_MEMORY_NX 4UL | ||
7 | #define SET_MEMORY_X 8UL | ||
8 | |||
9 | int __set_memory(unsigned long addr, int numpages, unsigned long flags); | ||
10 | |||
11 | static inline int set_memory_ro(unsigned long addr, int numpages) | ||
12 | { | ||
13 | return __set_memory(addr, numpages, SET_MEMORY_RO); | ||
14 | } | ||
15 | |||
16 | static inline int set_memory_rw(unsigned long addr, int numpages) | ||
17 | { | ||
18 | return __set_memory(addr, numpages, SET_MEMORY_RW); | ||
19 | } | ||
20 | |||
21 | static inline int set_memory_nx(unsigned long addr, int numpages) | ||
22 | { | ||
23 | return __set_memory(addr, numpages, SET_MEMORY_NX); | ||
24 | } | ||
25 | |||
26 | static inline int set_memory_x(unsigned long addr, int numpages) | ||
27 | { | ||
28 | return __set_memory(addr, numpages, SET_MEMORY_X); | ||
29 | } | ||
30 | |||
31 | #endif | ||
diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h index e7e1942edff7..3d7db6f35aeb 100644 --- a/arch/x86/include/asm/cacheflush.h +++ b/arch/x86/include/asm/cacheflush.h | |||
@@ -4,94 +4,10 @@ | |||
4 | /* Caches aren't brain-dead on the intel. */ | 4 | /* Caches aren't brain-dead on the intel. */ |
5 | #include <asm-generic/cacheflush.h> | 5 | #include <asm-generic/cacheflush.h> |
6 | #include <asm/special_insns.h> | 6 | #include <asm/special_insns.h> |
7 | 7 | #include <asm/set_memory.h> | |
8 | /* | ||
9 | * The set_memory_* API can be used to change various attributes of a virtual | ||
10 | * address range. The attributes include: | ||
11 | * Cachability : UnCached, WriteCombining, WriteThrough, WriteBack | ||
12 | * Executability : eXeutable, NoteXecutable | ||
13 | * Read/Write : ReadOnly, ReadWrite | ||
14 | * Presence : NotPresent | ||
15 | * | ||
16 | * Within a category, the attributes are mutually exclusive. | ||
17 | * | ||
18 | * The implementation of this API will take care of various aspects that | ||
19 | * are associated with changing such attributes, such as: | ||
20 | * - Flushing TLBs | ||
21 | * - Flushing CPU caches | ||
22 | * - Making sure aliases of the memory behind the mapping don't violate | ||
23 | * coherency rules as defined by the CPU in the system. | ||
24 | * | ||
25 | * What this API does not do: | ||
26 | * - Provide exclusion between various callers - including callers that | ||
27 | * operation on other mappings of the same physical page | ||
28 | * - Restore default attributes when a page is freed | ||
29 | * - Guarantee that mappings other than the requested one are | ||
30 | * in any state, other than that these do not violate rules for | ||
31 | * the CPU you have. Do not depend on any effects on other mappings, | ||
32 | * CPUs other than the one you have may have more relaxed rules. | ||
33 | * The caller is required to take care of these. | ||
34 | */ | ||
35 | |||
36 | int _set_memory_uc(unsigned long addr, int numpages); | ||
37 | int _set_memory_wc(unsigned long addr, int numpages); | ||
38 | int _set_memory_wt(unsigned long addr, int numpages); | ||
39 | int _set_memory_wb(unsigned long addr, int numpages); | ||
40 | int set_memory_uc(unsigned long addr, int numpages); | ||
41 | int set_memory_wc(unsigned long addr, int numpages); | ||
42 | int set_memory_wt(unsigned long addr, int numpages); | ||
43 | int set_memory_wb(unsigned long addr, int numpages); | ||
44 | int set_memory_x(unsigned long addr, int numpages); | ||
45 | int set_memory_nx(unsigned long addr, int numpages); | ||
46 | int set_memory_ro(unsigned long addr, int numpages); | ||
47 | int set_memory_rw(unsigned long addr, int numpages); | ||
48 | int set_memory_np(unsigned long addr, int numpages); | ||
49 | int set_memory_4k(unsigned long addr, int numpages); | ||
50 | |||
51 | int set_memory_array_uc(unsigned long *addr, int addrinarray); | ||
52 | int set_memory_array_wc(unsigned long *addr, int addrinarray); | ||
53 | int set_memory_array_wt(unsigned long *addr, int addrinarray); | ||
54 | int set_memory_array_wb(unsigned long *addr, int addrinarray); | ||
55 | |||
56 | int set_pages_array_uc(struct page **pages, int addrinarray); | ||
57 | int set_pages_array_wc(struct page **pages, int addrinarray); | ||
58 | int set_pages_array_wt(struct page **pages, int addrinarray); | ||
59 | int set_pages_array_wb(struct page **pages, int addrinarray); | ||
60 | |||
61 | /* | ||
62 | * For legacy compatibility with the old APIs, a few functions | ||
63 | * are provided that work on a "struct page". | ||
64 | * These functions operate ONLY on the 1:1 kernel mapping of the | ||
65 | * memory that the struct page represents, and internally just | ||
66 | * call the set_memory_* function. See the description of the | ||
67 | * set_memory_* function for more details on conventions. | ||
68 | * | ||
69 | * These APIs should be considered *deprecated* and are likely going to | ||
70 | * be removed in the future. | ||
71 | * The reason for this is the implicit operation on the 1:1 mapping only, | ||
72 | * making this not a generally useful API. | ||
73 | * | ||
74 | * Specifically, many users of the old APIs had a virtual address, | ||
75 | * called virt_to_page() or vmalloc_to_page() on that address to | ||
76 | * get a struct page* that the old API required. | ||
77 | * To convert these cases, use set_memory_*() on the original | ||
78 | * virtual address, do not use these functions. | ||
79 | */ | ||
80 | |||
81 | int set_pages_uc(struct page *page, int numpages); | ||
82 | int set_pages_wb(struct page *page, int numpages); | ||
83 | int set_pages_x(struct page *page, int numpages); | ||
84 | int set_pages_nx(struct page *page, int numpages); | ||
85 | int set_pages_ro(struct page *page, int numpages); | ||
86 | int set_pages_rw(struct page *page, int numpages); | ||
87 | |||
88 | 8 | ||
89 | void clflush_cache_range(void *addr, unsigned int size); | 9 | void clflush_cache_range(void *addr, unsigned int size); |
90 | 10 | ||
91 | #define mmio_flush_range(addr, size) clflush_cache_range(addr, size) | 11 | #define mmio_flush_range(addr, size) clflush_cache_range(addr, size) |
92 | 12 | ||
93 | extern int kernel_set_to_readonly; | ||
94 | void set_kernel_text_rw(void); | ||
95 | void set_kernel_text_ro(void); | ||
96 | |||
97 | #endif /* _ASM_X86_CACHEFLUSH_H */ | 13 | #endif /* _ASM_X86_CACHEFLUSH_H */ |
diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h new file mode 100644 index 000000000000..eaec6c364e42 --- /dev/null +++ b/arch/x86/include/asm/set_memory.h | |||
@@ -0,0 +1,87 @@ | |||
1 | #ifndef _ASM_X86_SET_MEMORY_H | ||
2 | #define _ASM_X86_SET_MEMORY_H | ||
3 | |||
4 | #include <asm/page.h> | ||
5 | #include <asm-generic/set_memory.h> | ||
6 | |||
7 | /* | ||
8 | * The set_memory_* API can be used to change various attributes of a virtual | ||
9 | * address range. The attributes include: | ||
10 | * Cachability : UnCached, WriteCombining, WriteThrough, WriteBack | ||
11 | * Executability : eXeutable, NoteXecutable | ||
12 | * Read/Write : ReadOnly, ReadWrite | ||
13 | * Presence : NotPresent | ||
14 | * | ||
15 | * Within a category, the attributes are mutually exclusive. | ||
16 | * | ||
17 | * The implementation of this API will take care of various aspects that | ||
18 | * are associated with changing such attributes, such as: | ||
19 | * - Flushing TLBs | ||
20 | * - Flushing CPU caches | ||
21 | * - Making sure aliases of the memory behind the mapping don't violate | ||
22 | * coherency rules as defined by the CPU in the system. | ||
23 | * | ||
24 | * What this API does not do: | ||
25 | * - Provide exclusion between various callers - including callers that | ||
26 | * operation on other mappings of the same physical page | ||
27 | * - Restore default attributes when a page is freed | ||
28 | * - Guarantee that mappings other than the requested one are | ||
29 | * in any state, other than that these do not violate rules for | ||
30 | * the CPU you have. Do not depend on any effects on other mappings, | ||
31 | * CPUs other than the one you have may have more relaxed rules. | ||
32 | * The caller is required to take care of these. | ||
33 | */ | ||
34 | |||
35 | int _set_memory_uc(unsigned long addr, int numpages); | ||
36 | int _set_memory_wc(unsigned long addr, int numpages); | ||
37 | int _set_memory_wt(unsigned long addr, int numpages); | ||
38 | int _set_memory_wb(unsigned long addr, int numpages); | ||
39 | int set_memory_uc(unsigned long addr, int numpages); | ||
40 | int set_memory_wc(unsigned long addr, int numpages); | ||
41 | int set_memory_wt(unsigned long addr, int numpages); | ||
42 | int set_memory_wb(unsigned long addr, int numpages); | ||
43 | int set_memory_np(unsigned long addr, int numpages); | ||
44 | int set_memory_4k(unsigned long addr, int numpages); | ||
45 | |||
46 | int set_memory_array_uc(unsigned long *addr, int addrinarray); | ||
47 | int set_memory_array_wc(unsigned long *addr, int addrinarray); | ||
48 | int set_memory_array_wt(unsigned long *addr, int addrinarray); | ||
49 | int set_memory_array_wb(unsigned long *addr, int addrinarray); | ||
50 | |||
51 | int set_pages_array_uc(struct page **pages, int addrinarray); | ||
52 | int set_pages_array_wc(struct page **pages, int addrinarray); | ||
53 | int set_pages_array_wt(struct page **pages, int addrinarray); | ||
54 | int set_pages_array_wb(struct page **pages, int addrinarray); | ||
55 | |||
56 | /* | ||
57 | * For legacy compatibility with the old APIs, a few functions | ||
58 | * are provided that work on a "struct page". | ||
59 | * These functions operate ONLY on the 1:1 kernel mapping of the | ||
60 | * memory that the struct page represents, and internally just | ||
61 | * call the set_memory_* function. See the description of the | ||
62 | * set_memory_* function for more details on conventions. | ||
63 | * | ||
64 | * These APIs should be considered *deprecated* and are likely going to | ||
65 | * be removed in the future. | ||
66 | * The reason for this is the implicit operation on the 1:1 mapping only, | ||
67 | * making this not a generally useful API. | ||
68 | * | ||
69 | * Specifically, many users of the old APIs had a virtual address, | ||
70 | * called virt_to_page() or vmalloc_to_page() on that address to | ||
71 | * get a struct page* that the old API required. | ||
72 | * To convert these cases, use set_memory_*() on the original | ||
73 | * virtual address, do not use these functions. | ||
74 | */ | ||
75 | |||
76 | int set_pages_uc(struct page *page, int numpages); | ||
77 | int set_pages_wb(struct page *page, int numpages); | ||
78 | int set_pages_x(struct page *page, int numpages); | ||
79 | int set_pages_nx(struct page *page, int numpages); | ||
80 | int set_pages_ro(struct page *page, int numpages); | ||
81 | int set_pages_rw(struct page *page, int numpages); | ||
82 | |||
83 | extern int kernel_set_to_readonly; | ||
84 | void set_kernel_text_rw(void); | ||
85 | void set_kernel_text_ro(void); | ||
86 | |||
87 | #endif /* _ASM_X86_SET_MEMORY_H */ | ||
diff --git a/include/asm-generic/set_memory.h b/include/asm-generic/set_memory.h new file mode 100644 index 000000000000..83e81f8996b2 --- /dev/null +++ b/include/asm-generic/set_memory.h | |||
@@ -0,0 +1,12 @@ | |||
1 | #ifndef __ASM_SET_MEMORY_H | ||
2 | #define __ASM_SET_MEMORY_H | ||
3 | |||
4 | /* | ||
5 | * Functions to change memory attributes. | ||
6 | */ | ||
7 | int set_memory_ro(unsigned long addr, int numpages); | ||
8 | int set_memory_rw(unsigned long addr, int numpages); | ||
9 | int set_memory_x(unsigned long addr, int numpages); | ||
10 | int set_memory_nx(unsigned long addr, int numpages); | ||
11 | |||
12 | #endif | ||