diff mbox series

[1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions

Message ID 20240813172543.38411-1-ubizjak@gmail.com (mailing list archive)
State New
Headers show
Series [1/2] err.h: Add ERR_PTR_PCPU(), PTR_ERR_PCPU() and IS_ERR_PCPU() functions | expand

Commit Message

Uros Bizjak Aug. 13, 2024, 5:25 p.m. UTC
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.

Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 include/linux/err.h | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

Catalin Marinas Aug. 14, 2024, 12:15 p.m. UTC | #1
On Tue, Aug 13, 2024 at 07:25:10PM +0200, Uros Bizjak wrote:
> 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.
> 
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Catalin Marinas <catalin.marinas@arm.com>
> Cc: Andrew Morton <akpm@linux-foundation.org>

Acked-by: Catalin Marinas <catalin.marinas@arm.com>
kernel test robot Aug. 15, 2024, 1:52 a.m. UTC | #2
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/202408150948.jjcISdEv-lkp@intel.com/config)
compiler: powerpc-linux-gcc (GCC) 14.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240815/202408150948.jjcISdEv-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408150948.jjcISdEv-lkp@intel.com/

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
kernel test robot Aug. 15, 2024, 4:29 a.m. UTC | #3
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/202408151256.8zNulgGN-lkp@intel.com/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/202408151256.8zNulgGN-lkp@intel.com/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 <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202408151256.8zNulgGN-lkp@intel.com/

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
diff mbox series

Patch

diff --git a/include/linux/err.h b/include/linux/err.h
index b5d9bb2a2349..997fd6fe1d0c 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -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.