err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions
Subsystems (2)
PATCH 1/2 err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions
Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions that operate on pointers in the percpu address space.
These functions remove the need for (__force void *) function argument casts (to avoid sparse -Wcast-from-as warnings).
The patch will also avoid future build errors due to pointer address space mismatch with enabled strict percpu address space checks.
--- include/linux/err.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)
include/linux/err.h +38 -0
@@ -6,6 +6,7 @@#include <linux/types.h> #include <asm/errno.h> +#include <asm/percpu.h> /* * Kernel pointers have redundant information, so we can use a
@@ -41,6 +42,22 @@ static inline void * __must_check ERR_PTR(long error)return (void *) error; } +/** +* ERR_PTR_PCPU - Create an error pointer in the percpu address space. +* @error: A negative error code. +* +* Encodes @error into a pointer value in the percpu address space. +* Users should consider the result opaque and not assume anything +* about how the error is encoded. +* +* Return: A pointer in the percpu address space with @error encoded +* within its value. +*/ +static inline void __percpu *__must_check ERR_PTR_PCPU (long error) +{ +return (void __percpu *) error; +} +/** * PTR_ERR - Extract the error code from an error pointer. * @ptr: An error pointer.
@@ -51,6 +68,17 @@ static inline long __must_check PTR_ERR(__force const void *ptr)return (long ) ptr; } +/** +* PTR_ERR_PCPU - Extract the error code from an error pointer in the +* percpu address space. +* @ptr: An error pointer in the percpu address space. +* Return: The error code within @ptr. +*/ +static inline long __must_check PTR_ERR_PCPU (const void __percpu *ptr) +{ +return (__force long ) ptr; +} +/** * IS_ERR - Detect an error pointer. * @ptr: The pointer to check.
@@ -61,6 +89,16 @@ static inline bool __must_check IS_ERR(__force const void *ptr)return IS_ERR_VALUE ((unsigned long )ptr); } +/** +* IS_ERR_PCPU - Detect an error pointer in the percpu address space. +* @ptr: The pointer in the percpu address space to check. +* Return: true if @ptr is an error pointer, false otherwise. +*/ +static inline bool __must_check IS_ERR_PCPU (const void __percpu *ptr) +{ +return IS_ERR_VALUE ((__force unsigned long )ptr); +} +/** * IS_ERR_OR_NULL - Detect an error pointer or a null pointer. * @ptr: The pointer to check.
Signature · 1 line
2.42.0
PATCH 2/2 mm/kmemleak: Use IS_ERR_PCPU() for pointer in the percpu address space
Use IS_ERR_PCPU() instead of IS_ERR() for pointers in the percpu address space. The patch also fixes following sparse warnings:
kmemleak.c:1063:39: warning: cast removes address space '__percpu' of expression kmemleak.c:1138:37: warning: cast removes address space '__percpu' of expression
--- mm/kmemleak.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
mm/kmemleak.c +4 -4
@@ -1059,8 +1059,8 @@ void __ref kmemleak_alloc_percpu(const void __percpu *ptr, size_t size,* Percpu allocations are only scanned and not reported as leaks * (min_count is set to 0). */ -if (kmemleak_enabled && ptr && !IS_ERR (ptr)) -create_object_percpu ((unsigned long )ptr, size,0 , gfp); +if (kmemleak_enabled && ptr && !IS_ERR_PCPU (ptr)) +create_object_percpu ((__force unsigned long )ptr, size,0 , gfp); }EXPORT_SYMBOL_GPL (kmemleak_alloc_percpu);
@@ -1134,8 +1134,8 @@ void __ref kmemleak_free_percpu(const void __percpu *ptr) {pr_debug ("%s(0x%px)\n" , __func__, ptr); -if (kmemleak_free_enabled && ptr && !IS_ERR (ptr)) -delete_object_full ((unsigned long )ptr,OBJECT_PERCPU ); +if (kmemleak_free_enabled && ptr && !IS_ERR_PCPU (ptr)) +delete_object_full ((__force unsigned long )ptr,OBJECT_PERCPU ); }EXPORT_SYMBOL_GPL (kmemleak_free_percpu);
Signature · 1 line
2.42.0
Re: [PATCH 2/2] mm/kmemleak: Use IS_ERR_PCPU() for pointer in the percpu address space
Quoted 9 lines · Uros Bizjak
Use
IS_ERR_PCPU()instead ofIS_ERR()for pointers in the percpu address space. The patch also fixes following sparse warnings:kmemleak.c:1063:39: warning: cast removes address space '
__percpu' of expression kmemleak.c:1138:37: warning: cast removes address space '__percpu' of expressionSigned-off-by Uros Bizjak <[email protected]>Cc Catalin Marinas <[email protected]>Cc Andrew Morton <[email protected]>
Quoted 6 lines · Uros Bizjak
Add
ERR_PTR_PCPU(),PTR_ERR_PCPU()andIS_ERR_PCPU()functions that operate on pointers in the percpu address space.These functions remove the need for (
__forcevoid *) function argument casts (to avoid sparse -Wcast-from-as warnings).
Quoted 6 lines
The patch will also avoid future build errors due to pointer address space mismatch with enabled strict percpu address space checks.
Signed-off-by Uros Bizjak <[email protected]>Cc Catalin Marinas <[email protected]>Cc Andrew Morton <[email protected]>
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Uros,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.11-rc3 next-20240814]
[cannot apply to akpm-mm/mm-everything]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Uros-Bizjak/mm-kmemleak-Use-IS_ERR_PCPU-for-pointer-in-the-percpu-address-space/20240814-223016 base: linus/master patch link: https://lore.kernel.org/r/20240813172543.38411-1-ubizjak%40gmail.com patch subject: [PATCH 1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions config: powerpc-allnoconfig (https://download.01.org/0day-ci/archive/20240815/[email protected]/config) compiler: powerpc-linux-gcc (GCC) 14.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
arch/powerpc/include/asm/paca.h: Assembler messages:
>> arch/powerpc/include/asm/paca.h:293: Error: unrecognized opcode: `static'
arch/powerpc/include/asm/paca.h:294: Error: unrecognized opcode: `static'
vim +293 arch/powerpc/include/asm/paca.h
1426d5a3bd0758 Michael Ellerman 2010-01-28 292
6c6fdbb2b7002a Chengyang Fan 2021-01-25 @293 static inline void allocate_paca(int cpu) { }
6c6fdbb2b7002a Chengyang Fan 2021-01-25 294 static inline void free_unused_pacas(void) { }1426d5a3bd0758 Michael Ellerman 2010-01-28 295
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Uros,
kernel test robot noticed the following build errors:
[auto build test ERROR on linus/master]
[also build test ERROR on v6.11-rc3 next-20240814]
[cannot apply to akpm-mm/mm-everything]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Uros-Bizjak/mm-kmemleak-Use-IS_ERR_PCPU-for-pointer-in-the-percpu-address-space/20240814-223016 base: linus/master patch link: https://lore.kernel.org/r/20240813172543.38411-1-ubizjak%40gmail.com patch subject: [PATCH 1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions config: powerpc-sequoia_defconfig (https://download.01.org/0day-ci/archive/20240815/[email protected]/config) compiler: clang version 20.0.0git (https://github.com/llvm/llvm-project f86594788ce93b696675c94f54016d27a6c21d18) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> arch/powerpc/include/asm/paca.h:293:15: error: unexpected token
static inline void allocate_paca(int cpu) { }
^
arch/powerpc/include/asm/paca.h:294:15: error: unexpected token
static inline void free_unused_pacas(void) { }
^vim +293 arch/powerpc/include/asm/paca.h
1426d5a3bd0758 Michael Ellerman 2010-01-28 292
6c6fdbb2b7002a Chengyang Fan 2021-01-25 @293 static inline void allocate_paca(int cpu) { }
6c6fdbb2b7002a Chengyang Fan 2021-01-25 294 static inline void free_unused_pacas(void) { }1426d5a3bd0758 Michael Ellerman 2010-01-28 295
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki