* [PATCH] x86/percpu: Use __force to cast from __percpu address space
@ 2024-04-02 17:50 Uros Bizjak
2024-04-03 7:08 ` [tip: x86/percpu] " tip-bot2 for Uros Bizjak
2024-04-05 14:38 ` [PATCH] " Nadav Amit
0 siblings, 2 replies; 4+ messages in thread
From: Uros Bizjak @ 2024-04-02 17:50 UTC (permalink / raw)
To: x86, linux-kernel
Cc: Uros Bizjak, Charlemagne Lasse, Nadav Amit, Luc Van Oostenryck,
Ingo Molnar, Andy Lutomirski, Brian Gerst, Denys Vlasenko,
H . Peter Anvin, Linus Torvalds, Peter Zijlstra, Thomas Gleixner,
Josh Poimboeuf
Fix sparse warning when casting from __percpu address space by using
__force in the cast. x86 named address spaces are not considered to
be subspaces of the generic (flat) address space, so explicit casts
are required to convert pointers between these address spaces and the
generic address space (the application should cast to uintptr_t and
apply the segment base offset). The cast to uintptr_t removes
__percpu address space tag and sparse reports:
warning: cast removes address space '__percpu' of expression
Use __force to inform sparse that the cast is intentional.
Reported-by: Charlemagne Lasse <charlemagnelasse@gmail.com>
Closes: https://lore.kernel.org/lkml/CAFGhKbzev7W4aHwhFPWwMZQEHenVgZUj7=aunFieVqZg3mt14A@mail.gmail.com/
Fixes: 9a462b9eafa6 ("x86/percpu: Use compiler segment prefix qualifier")
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Cc: Nadav Amit <nadav.amit@gmail.com>
Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
---
arch/x86/include/asm/percpu.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 1f6404e0c428..20696df5d567 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -77,7 +77,7 @@
#define arch_raw_cpu_ptr(_ptr) \
({ \
unsigned long tcp_ptr__ = __raw_my_cpu_offset; \
- tcp_ptr__ += (unsigned long)(_ptr); \
+ tcp_ptr__ += (__force unsigned long)(_ptr); \
(typeof(*(_ptr)) __kernel __force *)tcp_ptr__; \
})
#else
@@ -96,8 +96,8 @@
#endif /* CONFIG_SMP */
#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))
+#define __my_cpu_ptr(ptr) (__my_cpu_type(*ptr)*)(__force uintptr_t)(ptr)
+#define __my_cpu_var(var) (*__my_cpu_ptr(&(var)))
#define __percpu_arg(x) __percpu_prefix "%" #x
#define __force_percpu_arg(x) __force_percpu_prefix "%" #x
--
2.42.0
^ permalink raw reply [flat|nested] 4+ messages in thread* [tip: x86/percpu] x86/percpu: Use __force to cast from __percpu address space
2024-04-02 17:50 [PATCH] x86/percpu: Use __force to cast from __percpu address space Uros Bizjak
@ 2024-04-03 7:08 ` tip-bot2 for Uros Bizjak
2024-04-05 14:38 ` [PATCH] " Nadav Amit
1 sibling, 0 replies; 4+ messages in thread
From: tip-bot2 for Uros Bizjak @ 2024-04-03 7:08 UTC (permalink / raw)
To: linux-tip-commits
Cc: Charlemagne Lasse, Uros Bizjak, Ingo Molnar, Linus Torvalds, x86,
linux-kernel
The following commit has been merged into the x86/percpu branch of tip:
Commit-ID: a55c1fdad5f61b4bfe42319694b23671a758cb28
Gitweb: https://git.kernel.org/tip/a55c1fdad5f61b4bfe42319694b23671a758cb28
Author: Uros Bizjak <ubizjak@gmail.com>
AuthorDate: Tue, 02 Apr 2024 19:50:38 +02:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Wed, 03 Apr 2024 08:59:15 +02:00
x86/percpu: Use __force to cast from __percpu address space
Fix Sparse warning when casting from __percpu address space by using
__force in the cast. x86 named address spaces are not considered to
be subspaces of the generic (flat) address space, so explicit casts
are required to convert pointers between these address spaces and the
generic address space (the application should cast to uintptr_t and
apply the segment base offset). The cast to uintptr_t removes
__percpu address space tag and Sparse reports:
warning: cast removes address space '__percpu' of expression
Use __force to inform Sparse that the cast is intentional.
Fixes: 9a462b9eafa6 ("x86/percpu: Use compiler segment prefix qualifier")
Reported-by: Charlemagne Lasse <charlemagnelasse@gmail.com>
Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Link: https://lore.kernel.org/r/20240402175058.52649-1-ubizjak@gmail.com
Closes: https://lore.kernel.org/lkml/CAFGhKbzev7W4aHwhFPWwMZQEHenVgZUj7=aunFieVqZg3mt14A@mail.gmail.com/
---
arch/x86/include/asm/percpu.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
index 1f6404e..20696df 100644
--- a/arch/x86/include/asm/percpu.h
+++ b/arch/x86/include/asm/percpu.h
@@ -77,7 +77,7 @@
#define arch_raw_cpu_ptr(_ptr) \
({ \
unsigned long tcp_ptr__ = __raw_my_cpu_offset; \
- tcp_ptr__ += (unsigned long)(_ptr); \
+ tcp_ptr__ += (__force unsigned long)(_ptr); \
(typeof(*(_ptr)) __kernel __force *)tcp_ptr__; \
})
#else
@@ -96,8 +96,8 @@
#endif /* CONFIG_SMP */
#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))
+#define __my_cpu_ptr(ptr) (__my_cpu_type(*ptr)*)(__force uintptr_t)(ptr)
+#define __my_cpu_var(var) (*__my_cpu_ptr(&(var)))
#define __percpu_arg(x) __percpu_prefix "%" #x
#define __force_percpu_arg(x) __force_percpu_prefix "%" #x
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] x86/percpu: Use __force to cast from __percpu address space
2024-04-02 17:50 [PATCH] x86/percpu: Use __force to cast from __percpu address space Uros Bizjak
2024-04-03 7:08 ` [tip: x86/percpu] " tip-bot2 for Uros Bizjak
@ 2024-04-05 14:38 ` Nadav Amit
2024-04-05 15:16 ` Uros Bizjak
1 sibling, 1 reply; 4+ messages in thread
From: Nadav Amit @ 2024-04-05 14:38 UTC (permalink / raw)
To: Uros Bizjak
Cc: the arch/x86 maintainers, Linux Kernel Mailing List,
Charlemagne Lasse, Luc Van Oostenryck, Ingo Molnar,
Andy Lutomirski, Brian Gerst, Denys Vlasenko, H. Peter Anvin,
Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Josh Poimboeuf
> On 2 Apr 2024, at 20:50, Uros Bizjak <ubizjak@gmail.com> wrote:
>
> Fix sparse warning when casting from __percpu address space by using
> __force in the cast. x86 named address spaces are not considered to
> be subspaces of the generic (flat) address space, so explicit casts
> are required to convert pointers between these address spaces and the
> generic address space (the application should cast to uintptr_t and
> apply the segment base offset). The cast to uintptr_t removes
> __percpu address space tag and sparse reports:
>
> warning: cast removes address space '__percpu' of expression
>
> Use __force to inform sparse that the cast is intentional.
>
> Reported-by: Charlemagne Lasse <charlemagnelasse@gmail.com>
> Closes: https://lore.kernel.org/lkml/CAFGhKbzev7W4aHwhFPWwMZQEHenVgZUj7=aunFieVqZg3mt14A@mail.gmail.com/
> Fixes: 9a462b9eafa6 ("x86/percpu: Use compiler segment prefix qualifier")
> Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> Cc: Nadav Amit <nadav.amit@gmail.com>
> Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Andy Lutomirski <luto@kernel.org>
> Cc: Brian Gerst <brgerst@gmail.com>
> Cc: Denys Vlasenko <dvlasenk@redhat.com>
> Cc: H. Peter Anvin <hpa@zytor.com>
> Cc: Linus Torvalds <torvalds@linux-foundation.org>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> ---
> arch/x86/include/asm/percpu.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
> index 1f6404e0c428..20696df5d567 100644
> --- a/arch/x86/include/asm/percpu.h
> +++ b/arch/x86/include/asm/percpu.h
> @@ -77,7 +77,7 @@
> #define arch_raw_cpu_ptr(_ptr) \
> ({ \
> unsigned long tcp_ptr__ = __raw_my_cpu_offset; \
> - tcp_ptr__ += (unsigned long)(_ptr); \
> + tcp_ptr__ += (__force unsigned long)(_ptr); \
> (typeof(*(_ptr)) __kernel __force *)tcp_ptr__; \
> })
> #else
> @@ -96,8 +96,8 @@
> #endif /* CONFIG_SMP */
>
> #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))
> +#define __my_cpu_ptr(ptr) (__my_cpu_type(*ptr)*)(__force uintptr_t)(ptr)
> +#define __my_cpu_var(var) (*__my_cpu_ptr(&(var)))
If you use "(var)” in __my_cpu_var(),, you might just as well change the first to:
#define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(ptr)
[ not that I think of any real issue it might cause - just for consistency]
Anyhow,
Asked-by: Nadav Amit <nadav.amit@gmail.com>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] x86/percpu: Use __force to cast from __percpu address space
2024-04-05 14:38 ` [PATCH] " Nadav Amit
@ 2024-04-05 15:16 ` Uros Bizjak
0 siblings, 0 replies; 4+ messages in thread
From: Uros Bizjak @ 2024-04-05 15:16 UTC (permalink / raw)
To: Nadav Amit
Cc: the arch/x86 maintainers, Linux Kernel Mailing List,
Charlemagne Lasse, Luc Van Oostenryck, Ingo Molnar,
Andy Lutomirski, Brian Gerst, Denys Vlasenko, H. Peter Anvin,
Linus Torvalds, Peter Zijlstra, Thomas Gleixner, Josh Poimboeuf
On Fri, Apr 5, 2024 at 4:38 PM Nadav Amit <nadav.amit@gmail.com> wrote:
>
>
>
> > On 2 Apr 2024, at 20:50, Uros Bizjak <ubizjak@gmail.com> wrote:
> >
> > Fix sparse warning when casting from __percpu address space by using
> > __force in the cast. x86 named address spaces are not considered to
> > be subspaces of the generic (flat) address space, so explicit casts
> > are required to convert pointers between these address spaces and the
> > generic address space (the application should cast to uintptr_t and
> > apply the segment base offset). The cast to uintptr_t removes
> > __percpu address space tag and sparse reports:
> >
> > warning: cast removes address space '__percpu' of expression
> >
> > Use __force to inform sparse that the cast is intentional.
> >
> > Reported-by: Charlemagne Lasse <charlemagnelasse@gmail.com>
> > Closes: https://lore.kernel.org/lkml/CAFGhKbzev7W4aHwhFPWwMZQEHenVgZUj7=aunFieVqZg3mt14A@mail.gmail.com/
> > Fixes: 9a462b9eafa6 ("x86/percpu: Use compiler segment prefix qualifier")
> > Signed-off-by: Uros Bizjak <ubizjak@gmail.com>
> > Cc: Nadav Amit <nadav.amit@gmail.com>
> > Cc: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
> > Cc: Ingo Molnar <mingo@kernel.org>
> > Cc: Andy Lutomirski <luto@kernel.org>
> > Cc: Brian Gerst <brgerst@gmail.com>
> > Cc: Denys Vlasenko <dvlasenk@redhat.com>
> > Cc: H. Peter Anvin <hpa@zytor.com>
> > Cc: Linus Torvalds <torvalds@linux-foundation.org>
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Thomas Gleixner <tglx@linutronix.de>
> > Cc: Josh Poimboeuf <jpoimboe@redhat.com>
> > ---
> > arch/x86/include/asm/percpu.h | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/arch/x86/include/asm/percpu.h b/arch/x86/include/asm/percpu.h
> > index 1f6404e0c428..20696df5d567 100644
> > --- a/arch/x86/include/asm/percpu.h
> > +++ b/arch/x86/include/asm/percpu.h
> > @@ -77,7 +77,7 @@
> > #define arch_raw_cpu_ptr(_ptr) \
> > ({ \
> > unsigned long tcp_ptr__ = __raw_my_cpu_offset; \
> > - tcp_ptr__ += (unsigned long)(_ptr); \
> > + tcp_ptr__ += (__force unsigned long)(_ptr); \
> > (typeof(*(_ptr)) __kernel __force *)tcp_ptr__; \
> > })
> > #else
> > @@ -96,8 +96,8 @@
> > #endif /* CONFIG_SMP */
> >
> > #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))
> > +#define __my_cpu_ptr(ptr) (__my_cpu_type(*ptr)*)(__force uintptr_t)(ptr)
> > +#define __my_cpu_var(var) (*__my_cpu_ptr(&(var)))
>
> If you use "(var)” in __my_cpu_var(),, you might just as well change the first to:
>
> #define __my_cpu_ptr(ptr) (__my_cpu_type(*(ptr))*)(__force uintptr_t)(ptr)
>
> [ not that I think of any real issue it might cause - just for consistency]
Yes, I have changed it in one of the follow-up percpu patches [1].
[1] https://lore.kernel.org/lkml/20240404094218.448963-2-ubizjak@gmail.com/
Thanks,
Uros.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-04-05 15:17 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-02 17:50 [PATCH] x86/percpu: Use __force to cast from __percpu address space Uros Bizjak
2024-04-03 7:08 ` [tip: x86/percpu] " tip-bot2 for Uros Bizjak
2024-04-05 14:38 ` [PATCH] " Nadav Amit
2024-04-05 15:16 ` Uros Bizjak
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®