[-tip,v2,3/3] x86/percpu: Avoid sparse warning with cast to named address space

Message ID 20231203232017.994963-3-ubizjak@gmail.com
State New
Headers
Series [-tip,v2,1/3] x86/percpu: Fix "const_pcpu_hot" version generation failure |

Commit Message

Uros Bizjak Dec. 3, 2023, 11:19 p.m. UTC
  Currently sparse does not know about __seg_fs and __seg_fs named
address space qualifiers. Avoid thousands of warnings about unexpected
keyword at the end of cast operator by removing named address space
qualifier from __my_cpu_type() when __CHECKER__ is defined.

Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202310080853.UhMe5iWa-lkp@intel.com/
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
---
 arch/x86/include/asm/percpu.h | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Comments

Uros Bizjak Dec. 4, 2023, 2:03 p.m. UTC | #1
On Mon, Dec 4, 2023 at 12:20 AM Uros Bizjak <ubizjak@gmail.com> wrote:
>
> Currently sparse does not know about __seg_fs and __seg_fs named
> address space qualifiers. Avoid thousands of warnings about unexpected
> keyword at the end of cast operator by removing named address space
> qualifier from __my_cpu_type() when __CHECKER__ is defined.

We have discussed this issue a bit on the linux-sparse ML [1], and the
proposed solution is to define:

+#define __seg_gs __attribute__((address_space(__seg_gs)))
+#define __seg_fs __attribute__((address_space(__seg_fs)))

as done in the attached patch.

[1] https://lore.kernel.org/linux-sparse/CAFULd4YMcHhkSR4P5tq3ghLQyUCkiTOKS6PQd1Bec-2NicUiwQ@mail.gmail.com/T/#md048c918cd2145c822727e3aa401326e1660842f

Uros.
  

Patch

diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 3859abad19ec..cc4212d1491e 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -96,6 +96,15 @@ 
 
 #endif /* CONFIG_SMP */
 
+/*
+ * FIXME: Drop this hack once sparse learns how to ignore
+ * __seg_fs and __seg_gs named address space qualifiers.
+ */
+#ifdef __CHECKER__
+#undef __percpu_seg_override
+#define __percpu_seg_override
+#endif
+
 #define __my_cpu_type(var)	typeof(var) __percpu_seg_override
 #define __my_cpu_ptr(ptr)	(__my_cpu_type(*ptr) *)(uintptr_t)(ptr)
 #define __my_cpu_var(var)	(*__my_cpu_ptr(&var))