treewide: Move set_memory_* functions away from cacheflush.h
Subsystems (5)
RFC PATCH 1/1 treewide: Move set_memory_* functions away from cacheflush.h
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.
---
This came out of a comment Russell made while reviewing RODATA test cases
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/480855.html
While the final result of that series was the rodata code was refactored into its own header file, the set_memory_* APIs are still out of place.
This is a simple attempt at moving all the API stubs to their own file. Another idea I had was throwing set_memory_{x,nx,ro,rw} in an asm-generic file since those are commonly used for module setting across all arches.
This is an RFC to see if this is actually beneficial. The diffstat is not negative unfortunately due to header guards in newer files.
I have patches to convert call sites over to set_memory.h instead of cacheflush.h if there is sufficient interest.
--- arch/arm/include/asm/cacheflush.h | 21 +------- arch/arm/include/asm/set_memory.h | 32 ++++++++++++ arch/arm64/include/asm/cacheflush.h | 6 +-- arch/arm64/include/asm/set_memory.h | 26 ++++++++++ arch/s390/include/asm/cacheflush.h | 6 +-- arch/s390/include/asm/set_memory.h | 9 ++++ arch/x86/include/asm/cacheflush.h | 96 +--------------------------------- arch/x86/include/asm/set_memory.h | 100 ++++++++++++++++++++++++++++++++++++ 8 files changed, 171 insertions(+), 125 deletions(-) create mode 100644 arch/arm/include/asm/set_memory.h create mode 100644 arch/arm64/include/asm/set_memory.h create mode 100644 arch/s390/include/asm/set_memory.h create mode 100644 arch/x86/include/asm/set_memory.h
arch/arm/include/asm/cacheflush.h +1 -20
@@ -16,6 +16,7 @@#include <asm/shmparam.h> #include <asm/cachetype.h> #include <asm/outercache.h> +#include <asm/set_memory.h> #define CACHE_COLOUR (vaddr) ((vaddr & (SHMLBA - 1)) >> PAGE_SHIFT)
@@ -478,26 +479,6 @@ static inline void __sync_cache_range_r(volatile void *p, size_t size) : : : "r0","r1","r2","r3","r4","r5","r6","r7", \ "r9","r10","lr","memory" ) -#ifdef CONFIG_MMU -int set_memory_ro (unsigned long addr,int numpages); -int set_memory_rw (unsigned long addr,int numpages); -int set_memory_x (unsigned long addr,int numpages); -int set_memory_nx (unsigned long addr,int numpages); -#else -static inline int set_memory_ro (unsigned long addr,int numpages) {return 0 ; } -static inline int set_memory_rw (unsigned long addr,int numpages) {return 0 ; } -static inline int set_memory_x (unsigned long addr,int numpages) {return 0 ; } -static inline int set_memory_nx (unsigned long addr,int numpages) {return 0 ; } -#endif - -#ifdef CONFIG_STRICT_KERNEL_RWX -void set_kernel_text_rw (void ); -void set_kernel_text_ro (void ); -#else -static inline void set_kernel_text_rw (void ) { } -static inline void set_kernel_text_ro (void ) { } -#endif -void flush_uprobe_xol_access (struct page *page,unsigned long uaddr,void *kaddr,unsigned long len);
arch/arm/include/asm/set_memory.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 1999-2002 Russell King +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef _ASMARM_SET_MEMORY_H +#define _ASMARM_SET_MEMORY_H + +#ifdef CONFIG_MMU +int set_memory_ro (unsigned long addr,int numpages); +int set_memory_rw (unsigned long addr,int numpages); +int set_memory_x (unsigned long addr,int numpages); +int set_memory_nx (unsigned long addr,int numpages); +#else +static inline int set_memory_ro (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_rw (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_x (unsigned long addr,int numpages) {return 0 ; } +static inline int set_memory_nx (unsigned long addr,int numpages) {return 0 ; } +#endif + +#ifdef CONFIG_STRICT_KERNEL_RWX +void set_kernel_text_rw (void ); +void set_kernel_text_ro (void ); +#else +static inline void set_kernel_text_rw (void ) { } +static inline void set_kernel_text_ro (void ) { } +#endif + +#endif
arch/arm64/include/asm/cacheflush.h +1 -5
@@ -20,6 +20,7 @@#define __ASM_CACHEFLUSH_H#include <linux/mm.h> +#include <asm/set_memory.h> /* * This flag is used to indicate that the page pointed to by a pte is clean
@@ -150,9 +151,4 @@ static inline void flush_cache_vunmap(unsigned long start, unsigned long end) { } -int set_memory_ro (unsigned long addr,int numpages); -int set_memory_rw (unsigned long addr,int numpages); -int set_memory_x (unsigned long addr,int numpages); -int set_memory_nx (unsigned long addr,int numpages); -#endif
arch/arm64/include/asm/set_memory.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (C) 1999-2002 Russell King. +* Copyright (C) 2012 ARM Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +*/ + +#ifndef __ARM64_ASM_SET_MEMORY_H +#define __ARM64_ASM_SET_MEMORY_H + +int set_memory_ro (unsigned long addr,int numpages); +int set_memory_rw (unsigned long addr,int numpages); +int set_memory_x (unsigned long addr,int numpages); +int set_memory_nx (unsigned long addr,int numpages); + +#endif
arch/s390/include/asm/cacheflush.h +1 -5
@@ -3,10 +3,6 @@/* Caches aren't brain-dead on the s390. */ #include <asm-generic/cacheflush.h> - -int set_memory_ro (unsigned long addr,int numpages); -int set_memory_rw (unsigned long addr,int numpages); -int set_memory_nx (unsigned long addr,int numpages); -int set_memory_x (unsigned long addr,int numpages); +#include <asm/set_memory.h> #endif /* _S390_CACHEFLUSH_H */
arch/s390/include/asm/set_memory.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _S390_SET_MEMORY_H +#define _S390_SET_MEMORY_H + +int set_memory_ro (unsigned long addr,int numpages); +int set_memory_rw (unsigned long addr,int numpages); +int set_memory_nx (unsigned long addr,int numpages); +int set_memory_x (unsigned long addr,int numpages); + +#endif /* _S390_SET_MEMORY_H */
arch/x86/include/asm/cacheflush.h +1 -95
105 lines not on this page · raw message
arch/x86/include/asm/set_memory.h new file +100 -0
100 lines not on this page · raw message
Signature · 1 line
2.7.4
Quoted 8 lines · Laura Abbott
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 growingcacheflush.hfor APIs that have nothing to do with caches.
Quoted 6 lines
Signed-off-by Laura Abbott <[email protected]>---
This came out of a comment Russell made while reviewing RODATA test cases
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/480855.html
While the final result of that series was the rodata code was refactored into its own header file, the set_memory_* APIs are still out of place.
Yeah, this is a nice clean up to start on.
Quoted 3 lines
This is a simple attempt at moving all the API stubs to their own file. Another idea I had was throwing set_memory_{x,nx,ro,rw} in an asm-generic file since those are commonly used for module setting across all arches.
It seems like asm-generic would be cleaner, yes? Only a few archs have anything "special" happening in the resulting header files.
-Kees
Signature · 2 lines
Kees Cook Pixel Security
Quoted 23 lines · Laura Abbott
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 growingcacheflush.hfor APIs that have nothing to do with caches.Signed-off-by Laura Abbott <[email protected]>---
This came out of a comment Russell made while reviewing RODATA test cases
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/480855.html
While the final result of that series was the rodata code was refactored into its own header file, the set_memory_* APIs are still out of place.This is a simple attempt at moving all the API stubs to their own file. Another idea I had was throwing set_memory_{x,nx,ro,rw} in an asm-generic file since those are commonly used for module setting across all arches.
This is an RFC to see if this is actually beneficial. The diffstat is not negative unfortunately due to header guards in newer files.
I have patches to convert call sites over toset_memory.hinstead ofcacheflush.hif there is sufficient interest.
Quoted 14 lines
--- arch/arm/include/asm/cacheflush.h | 21 +------- arch/arm/include/asm/set_memory.h | 32 ++++++++++++ arch/arm64/include/asm/cacheflush.h | 6 +-- arch/arm64/include/asm/set_memory.h | 26 ++++++++++ arch/s390/include/asm/cacheflush.h | 6 +-- arch/s390/include/asm/set_memory.h | 9 ++++ arch/x86/include/asm/cacheflush.h | 96 +--------------------------------- arch/x86/include/asm/set_memory.h | 100 ++++++++++++++++++++++++++++++++++++ 8 files changed, 171 insertions(+), 125 deletions(-) create mode 100644 arch/arm/include/asm/set_memory.h create mode 100644 arch/arm64/include/asm/set_memory.h create mode 100644 arch/s390/include/asm/set_memory.h create mode 100644 arch/x86/include/asm/set_memory.h
LGTM:
Thanks,
Ingo
Quoted 16 lines · Kees Cook
Quoted 8 lines · Laura Abbott
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 growingcacheflush.hfor APIs that have nothing to do with caches.Quoted 6 lines
Signed-off-by Laura Abbott <[email protected]>---
This came out of a comment Russell made while reviewing RODATA test cases
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/480855.html
While the final result of that series was the rodata code was refactored into its own header file, the set_memory_* APIs are still out of place.
Quoted 8 lines
Yeah, this is a nice clean up to start on.
Quoted 3 lines
This is a simple attempt at moving all the API stubs to their own file. Another idea I had was throwing set_memory_{x,nx,ro,rw} in an asm-generic file since those are commonly used for module setting across all arches.
It seems like asm-generic would be cleaner, yes? Only a few archs have anything "special" happening in the resulting header files.
I'd also prefer the asm-generic approach if it makes the arch part a simple addition to asm/Kbuild.
Will
Quoted 23 lines · Laura Abbott
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 growingcacheflush.hfor APIs that have nothing to do with caches.Signed-off-by Laura Abbott <[email protected]>---
This came out of a comment Russell made while reviewing RODATA test cases
http://lists.infradead.org/pipermail/linux-arm-kernel/2017-January/480855.html
While the final result of that series was the rodata code was refactored into its own header file, the set_memory_* APIs are still out of place.This is a simple attempt at moving all the API stubs to their own file. Another idea I had was throwing set_memory_{x,nx,ro,rw} in an asm-generic file since those are commonly used for module setting across all arches.
This is an RFC to see if this is actually beneficial. The diffstat is not negative unfortunately due to header guards in newer files.
I have patches to convert call sites over toset_memory.hinstead ofcacheflush.hif there is sufficient interest.
Quoted 14 lines
--- arch/arm/include/asm/cacheflush.h | 21 +------- arch/arm/include/asm/set_memory.h | 32 ++++++++++++ arch/arm64/include/asm/cacheflush.h | 6 +-- arch/arm64/include/asm/set_memory.h | 26 ++++++++++ arch/s390/include/asm/cacheflush.h | 6 +-- arch/s390/include/asm/set_memory.h | 9 ++++ arch/x86/include/asm/cacheflush.h | 96 +--------------------------------- arch/x86/include/asm/set_memory.h | 100 ++++++++++++++++++++++++++++++++++++ 8 files changed, 171 insertions(+), 125 deletions(-) create mode 100644 arch/arm/include/asm/set_memory.h create mode 100644 arch/arm64/include/asm/set_memory.h create mode 100644 arch/s390/include/asm/set_memory.h create mode 100644 arch/x86/include/asm/set_memory.h
For s390: