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: <CAFULd4ZNi7eONVu8syiWyA5ek2TgHTf6jTM+Pf7SaSG6WyHoNw@mail.gmail.com>
Date: Tue, 2 Apr 2024 11:43:02 +0200
From: Uros Bizjak <ubizjak@...il.com>
To: Charlemagne Lasse <charlemagnelasse@...il.com>
Cc: x86@...nel.org, LKML <linux-kernel@...r.kernel.org>, 
	Luc Van Oostenryck <lucvoo@...nel.org>, Andy Lutomirski <luto@...nel.org>, Ingo Molnar <mingo@...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>, 
	Borislav Petkov <bp@...en8.de>, Josh Poimboeuf <jpoimboe@...hat.com>
Subject: Re: warning: cast removes address space '__percpu' of expression

On Tue, Apr 2, 2024 at 9:56 AM Charlemagne Lasse
<charlemagnelasse@...il.com> wrote:
>
> Am Mo., 1. Apr. 2024 um 21:16 Uhr schrieb Uros Bizjak <ubizjak@...il.com>:
> > > I would even go as far as saying that 1ca3683cc6d2 ("x86/percpu:
> > > Enable named address spaces with known compiler version") together
> > > with 3a1d3829e193 ("x86/percpu: Avoid sparse warning with cast to
> > > named address space") triggered this problem
>
> I think 1ca3683cc6d2 was wrong and is the last working one.
>
>
> Just switch to 1ca3683cc6d2c2ce4204df519c4e4730d037905a and you won't
> see the messages.
>
> ```
> git reset --hard 1ca3683cc6d2c2ce4204df519c4e4730d037905a
> git clean -dfx
> make allnoconfig -j$(nproc)
> make kvm_guest.config
> make prepare -j$(nproc)
> touch include/linux/netdevice.h
> make C=1 net/core/dev.o CHECK="sparse -Wcast-from-as"
> ```
>
> Go to 9a462b9eafa6dda16ea8429b151edb1fb535d744 and cherry-pick
> 3a1d3829e193c091475ceab481c5f8deab385023 and you would see the error.
> On amd64  with 12.2.0, this would look like this:
>
> ```
> git reset --hard 9a462b9eafa6dda16ea8429b151edb1fb535d744
> git cherry-pick 3a1d3829e193c091475ceab481c5f8deab385023
> git clean -dfx
> make allnoconfig -j$(nproc)
> make kvm_guest.config
> make prepare -j$(nproc)
> touch include/linux/netdevice.h
> make C=1 net/core/dev.o CHECK="sparse -Wcast-from-as"
> ```
>
> I would recommend to use `-Wsparse-all` for testing but for this
> demonstration, it is easier to use `-Wcast-from-as` to reduce the
> amount of noise in the demonstrator.

Oh, I see the problem now. We *do* cast away from __percpu space, this
is how we switch between GCC's named address spaces [1]:

--q--
6.17.5 x86 Named Address Spaces

..

The respective segment base must be set via some method specific to
the operating system. Rather than require an expensive system call to
retrieve the segment base, these address spaces are not considered to
be subspaces of the generic (flat) address space. This means that
explicit casts are required to convert pointers between these address
spaces and the generic address space. In practice the application
should cast to uintptr_t and apply the segment base offset that it
installed previously.
--/q--

Please try the attached patch that informs sparse about this action.

BTW: Please also note recent discussion about different checks for
__percpu name space that can be implemented using GCC's named address
spaces feature [2].

[1] https://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html
[2[ https://lore.kernel.org/lkml/87bk7ux4e9.ffs@tglx/#t

Thanks,
Uros.

View attachment "p.diff.txt" of type "text/plain" (1236 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ