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: <CAADnVQLz=+FN8-B_QmmT-eg7PB7jGHiah=9B-s5WpfmQbAF3eg@mail.gmail.com>
Date: Wed, 14 May 2025 17:46:43 -0700
From: Alexei Starovoitov <alexei.starovoitov@...il.com>
To: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
Cc: LKML <linux-kernel@...r.kernel.org>, linux-rt-devel@...ts.linux.dev, 
	Thomas Gleixner <tglx@...utronix.de>, Peter Zijlstra <peterz@...radead.org>, 
	Ingo Molnar <mingo@...hat.com>, Will Deacon <will@...nel.org>, Waiman Long <longman@...hat.com>, 
	Boqun Feng <boqun.feng@...il.com>
Subject: Re: [PATCH 1/2] local_lock: Move this_cpu_ptr() notation from
 internal to main header.

On Wed, May 14, 2025 at 4:07 AM Sebastian Andrzej Siewior
<bigeasy@...utronix.de> wrote:
>
> The local_lock.h is the main entry for the local_lock_t type and
> provides wrappers around internal functions prefixed with __ in
> local_lock_internal.h.
>
> Move the this_cpu_ptr() dereference of the variable from the internal to
> the main header. Since it is all macro implemented, this_cpu_ptr() will
> still happen within the preempt/ IRQ disabled section.
> This will free the internal implementation (__) to be used on
> local_lock_t types which are local variables and must not be accessed
> via this_cpu_ptr().
>
> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
> ---
>  include/linux/local_lock.h          | 20 +++++++++----------
>  include/linux/local_lock_internal.h | 30 ++++++++++++++---------------
>  2 files changed, 25 insertions(+), 25 deletions(-)
>
> diff --git a/include/linux/local_lock.h b/include/linux/local_lock.h
> index 16a2ee4f8310b..2ba8464195244 100644
> --- a/include/linux/local_lock.h
> +++ b/include/linux/local_lock.h
> @@ -13,13 +13,13 @@
>   * local_lock - Acquire a per CPU local lock
>   * @lock:      The lock variable
>   */
> -#define local_lock(lock)               __local_lock(lock)
> +#define local_lock(lock)               __local_lock(this_cpu_ptr(lock))
>
>  /**
>   * local_lock_irq - Acquire a per CPU local lock and disable interrupts
>   * @lock:      The lock variable
>   */
> -#define local_lock_irq(lock)           __local_lock_irq(lock)
> +#define local_lock_irq(lock)           __local_lock_irq(this_cpu_ptr(lock))
>
>  /**
>   * local_lock_irqsave - Acquire a per CPU local lock, save and disable
> @@ -28,19 +28,19 @@
>   * @flags:     Storage for interrupt flags
>   */
>  #define local_lock_irqsave(lock, flags)                                \
> -       __local_lock_irqsave(lock, flags)
> +       __local_lock_irqsave(this_cpu_ptr(lock), flags)
>
>  /**
>   * local_unlock - Release a per CPU local lock
>   * @lock:      The lock variable
>   */
> -#define local_unlock(lock)             __local_unlock(lock)
> +#define local_unlock(lock)             __local_unlock(this_cpu_ptr(lock))
>
>  /**
>   * local_unlock_irq - Release a per CPU local lock and enable interrupts
>   * @lock:      The lock variable
>   */
> -#define local_unlock_irq(lock)         __local_unlock_irq(lock)
> +#define local_unlock_irq(lock)         __local_unlock_irq(this_cpu_ptr(lock))
>
>  /**
>   * local_unlock_irqrestore - Release a per CPU local lock and restore
> @@ -49,7 +49,7 @@
>   * @flags:      Interrupt flags to restore
>   */
>  #define local_unlock_irqrestore(lock, flags)                   \
> -       __local_unlock_irqrestore(lock, flags)
> +       __local_unlock_irqrestore(this_cpu_ptr(lock), flags)
>
>  /**
>   * local_lock_init - Runtime initialize a lock instance
> @@ -64,7 +64,7 @@
>   * locking constrains it will _always_ fail to acquire the lock in NMI or
>   * HARDIRQ context on PREEMPT_RT.
>   */
> -#define local_trylock(lock)            __local_trylock(lock)
> +#define local_trylock(lock)            __local_trylock(this_cpu_ptr(lock))
>
>  /**
>   * local_trylock_irqsave - Try to acquire a per CPU local lock, save and disable
> @@ -77,7 +77,7 @@
>   * HARDIRQ context on PREEMPT_RT.
>   */
>  #define local_trylock_irqsave(lock, flags)                     \
> -       __local_trylock_irqsave(lock, flags)
> +       __local_trylock_irqsave(this_cpu_ptr(lock), flags)
>
>  DEFINE_GUARD(local_lock, local_lock_t __percpu*,
>              local_lock(_T),
> @@ -91,10 +91,10 @@ DEFINE_LOCK_GUARD_1(local_lock_irqsave, local_lock_t __percpu,
>                     unsigned long flags)
>
>  #define local_lock_nested_bh(_lock)                            \
> -       __local_lock_nested_bh(_lock)
> +       __local_lock_nested_bh(this_cpu_ptr(_lock))
>
>  #define local_unlock_nested_bh(_lock)                          \
> -       __local_unlock_nested_bh(_lock)
> +       __local_unlock_nested_bh(this_cpu_ptr(_lock))
>
>  DEFINE_GUARD(local_lock_nested_bh, local_lock_t __percpu*,
>              local_lock_nested_bh(_T),
> diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h
> index 8d5ac16a9b179..b4d7b24882835 100644
> --- a/include/linux/local_lock_internal.h
> +++ b/include/linux/local_lock_internal.h
> @@ -99,14 +99,14 @@ do {                                                                \
>                 local_trylock_t *tl;                                    \
>                 local_lock_t *l;                                        \
>                                                                         \
> -               l = (local_lock_t *)this_cpu_ptr(lock);                 \
> +               l = (local_lock_t *)(lock);                     \
>                 tl = (local_trylock_t *)l;                              \
>                 _Generic((lock),                                        \
> -                       __percpu local_trylock_t *: ({                  \
> +                       local_trylock_t *: ({                   \
>                                 lockdep_assert(tl->acquired == 0);      \
>                                 WRITE_ONCE(tl->acquired, 1);            \
>                         }),                                             \
> -                       __percpu local_lock_t *: (void)0);              \
> +                       local_lock_t *: (void)0);               \

Are you sure this is correct?
Have you tested with gcc 14 or higher?

It looks to me that moving this_cpu_ptr() up one level should
still preserve __seg_gs modifier.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ