2023-12-03 23:21:06

by Uros Bizjak

[permalink] [raw]
Subject: [PATCH -tip v2 3/3] x86/percpu: Avoid sparse warning with cast to named address space

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 <[email protected]>
Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Cc: Thomas Gleixner <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Borislav Petkov <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: "H. Peter Anvin" <[email protected]>
Signed-off-by: Uros Bizjak <[email protected]>
---
arch/x86/include/asm/percpu.h | 9 +++++++++
1 file changed, 9 insertions(+)

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))
--
2.42.0


2023-12-04 14:03:58

by Uros Bizjak

[permalink] [raw]
Subject: Re: [PATCH -tip v2 3/3] x86/percpu: Avoid sparse warning with cast to named address space

On Mon, Dec 4, 2023 at 12:20 AM Uros Bizjak <[email protected]> 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.