Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

s390/set_memory: add __set_memory() variant

Add a __set_memory_yy() variant for all set_memory_yy()
implementations. The new variant takes start and end void pointers,
which allows them to be used without the usual unsigned long cast.

However more important: the new variant can be used for areas larger
than 8TB. The old variant comes with an "int numpages" parameter, which
overflows with more than 8TB. Given that for debug_pagealloc
set_memory_4k() is used on the whole kernel mapping this is not only a
theoretical problem, but must be fixed.

Changing all set_memory_yy() variants only on s390 to take an "unsigned
long numpages" parameter is not possible, since the common module code
requires an int parameter from all architectures on these functions.
See module_set_memory().

Therefore change/fix this on s390 only with a new interface, and address
common code later.

Reviewed-by: Alexander Gordeev <agordeev@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>

+24 -6
+23 -5
arch/s390/include/asm/set_memory.h
··· 24 24 #define SET_MEMORY_INV BIT(_SET_MEMORY_INV_BIT) 25 25 #define SET_MEMORY_DEF BIT(_SET_MEMORY_DEF_BIT) 26 26 27 - int __set_memory(unsigned long addr, int numpages, unsigned long flags); 27 + int __set_memory(unsigned long addr, unsigned long numpages, unsigned long flags); 28 28 29 29 #define set_memory_rox set_memory_rox 30 30 31 - #define __SET_MEMORY_FUNC(fname, flags) \ 32 - static inline int fname(unsigned long addr, int numpages) \ 33 - { \ 34 - return __set_memory(addr, numpages, (flags)); \ 31 + /* 32 + * Generate two variants of each set_memory() function: 33 + * 34 + * set_memory_yy(unsigned long addr, int numpages); 35 + * __set_memory_yy(void *start, void *end); 36 + * 37 + * The second variant exists for both convenience to avoid the usual 38 + * (unsigned long) casts, but unlike the first variant it can also be used 39 + * for areas larger than 8TB, which may happen at memory initialization. 40 + */ 41 + #define __SET_MEMORY_FUNC(fname, flags) \ 42 + static inline int fname(unsigned long addr, int numpages) \ 43 + { \ 44 + return __set_memory(addr, numpages, (flags)); \ 45 + } \ 46 + \ 47 + static inline int __##fname(void *start, void *end) \ 48 + { \ 49 + unsigned long numpages; \ 50 + \ 51 + numpages = (end - start) >> PAGE_SHIFT; \ 52 + return __set_memory((unsigned long)start, numpages, (flags)); \ 35 53 } 36 54 37 55 __SET_MEMORY_FUNC(set_memory_ro, SET_MEMORY_RO)
+1 -1
arch/s390/mm/pageattr.c
··· 373 373 return rc; 374 374 } 375 375 376 - int __set_memory(unsigned long addr, int numpages, unsigned long flags) 376 + int __set_memory(unsigned long addr, unsigned long numpages, unsigned long flags) 377 377 { 378 378 unsigned long end; 379 379 int rc;