lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <0F9CDB7B-E8DD-43E5-9394-233A9289B3E0@gmail.com>
Date: Fri, 5 Apr 2024 17:38:13 +0300
From: Nadav Amit <nadav.amit@...il.com>
To: Uros Bizjak <ubizjak@...il.com>
Cc: the arch/x86 maintainers <x86@...nel.org>,
 Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
 Charlemagne Lasse <charlemagnelasse@...il.com>,
 Luc Van Oostenryck <luc.vanoostenryck@...il.com>,
 Ingo Molnar <mingo@...nel.org>,
 Andy Lutomirski <luto@...nel.org>,
 Brian Gerst <brgerst@...il.com>,
 Denys Vlasenko <dvlasenk@...hat.com>,
 "H. Peter Anvin" <hpa@...or.com>,
 Linus Torvalds <torvalds@...ux-foundation.org>,
 Peter Zijlstra <peterz@...radead.org>,
 Thomas Gleixner <tglx@...utronix.de>,
 Josh Poimboeuf <jpoimboe@...hat.com>
Subject: Re: [PATCH] x86/percpu: Use __force to cast from __percpu address
 space



> On 2 Apr 2024, at 20:50, Uros Bizjak <ubizjak@...il.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@...il.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@...il.com>
> Cc: Nadav Amit <nadav.amit@...il.com>
> Cc: Luc Van Oostenryck <luc.vanoostenryck@...il.com>
> Cc: Ingo Molnar <mingo@...nel.org>
> Cc: Andy Lutomirski <luto@...nel.org>
> Cc: Brian Gerst <brgerst@...il.com>
> Cc: Denys Vlasenko <dvlasenk@...hat.com>
> Cc: H. Peter Anvin <hpa@...or.com>
> Cc: Linus Torvalds <torvalds@...ux-foundation.org>
> Cc: Peter Zijlstra <peterz@...radead.org>
> Cc: Thomas Gleixner <tglx@...utronix.de>
> Cc: Josh Poimboeuf <jpoimboe@...hat.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@...il.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ