* [PATCH 0/2] local_lock: Move this_cpu_ptr() notation from internal to main header
@ 2025-05-14 11:07 Sebastian Andrzej Siewior
2025-05-14 11:07 ` [PATCH 1/2] " Sebastian Andrzej Siewior
2025-05-14 11:07 ` [PATCH 2/2] cryptd: Use nested-BH locking for cryptd_cpu_queue Sebastian Andrzej Siewior
0 siblings, 2 replies; 6+ messages in thread
From: Sebastian Andrzej Siewior @ 2025-05-14 11:07 UTC (permalink / raw)
To: linux-kernel, linux-rt-devel
Cc: tglx, Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long,
Boqun Feng, Alexei Starovoitov, Sebastian Andrzej Siewior
While looking at what needs extra locks for PREEMPT_RT in order to rid
of the lock in local_bh_disable() I stumbled uppon two users which need
to lock the structure but the pointer is no longer per_cpu.
Patch #1 moves this_cpu_ptr() from the internal header to the main on in
order to free the name space and have the __ prefix function to
do the same but without the this_cpu_ptr(). So
local_lock_nested_bh() -> on per-CPU memory
__local_lock_nested_bh() -> on local memory.
This change has been made to all local_lock*() functions.
Patch #2 is an example why it is needed. In a nutshell the per-CPU
memory is allocated via alloc_percpu() and then the memory is
passed to queue_work_on(). The worker then retrieves the
structure via container_of(). No more per-CPU memory.
I attached #2 as an example and would route via crypto once #1 is
accepted. The user user I identified is nf_set_pipapo which is doing
something similar. This makes two users in total.
Sebastian Andrzej Siewior (2):
local_lock: Move this_cpu_ptr() notation from internal to main header.
cryptd: Use nested-BH locking for cryptd_cpu_queue
crypto/cryptd.c | 6 ++++++
include/linux/local_lock.h | 20 +++++++++----------
include/linux/local_lock_internal.h | 30 ++++++++++++++---------------
3 files changed, 31 insertions(+), 25 deletions(-)
--
2.49.0
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] local_lock: Move this_cpu_ptr() notation from internal to main header. 2025-05-14 11:07 [PATCH 0/2] local_lock: Move this_cpu_ptr() notation from internal to main header Sebastian Andrzej Siewior @ 2025-05-14 11:07 ` Sebastian Andrzej Siewior 2025-05-15 0:46 ` Alexei Starovoitov 2025-05-14 11:07 ` [PATCH 2/2] cryptd: Use nested-BH locking for cryptd_cpu_queue Sebastian Andrzej Siewior 1 sibling, 1 reply; 6+ messages in thread From: Sebastian Andrzej Siewior @ 2025-05-14 11:07 UTC (permalink / raw) To: linux-kernel, linux-rt-devel Cc: tglx, Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng, Alexei Starovoitov, Sebastian Andrzej Siewior 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@linutronix.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); \ local_lock_acquire(l); \ } while (0) @@ -133,7 +133,7 @@ do { \ local_trylock_t *tl; \ \ preempt_disable(); \ - tl = this_cpu_ptr(lock); \ + tl = (lock); \ if (READ_ONCE(tl->acquired)) { \ preempt_enable(); \ tl = NULL; \ @@ -150,7 +150,7 @@ do { \ local_trylock_t *tl; \ \ local_irq_save(flags); \ - tl = this_cpu_ptr(lock); \ + tl = (lock); \ if (READ_ONCE(tl->acquired)) { \ local_irq_restore(flags); \ tl = NULL; \ @@ -167,15 +167,15 @@ 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; \ local_lock_release(l); \ _Generic((lock), \ - __percpu local_trylock_t *: ({ \ + local_trylock_t *: ({ \ lockdep_assert(tl->acquired == 1); \ WRITE_ONCE(tl->acquired, 0); \ }), \ - __percpu local_lock_t *: (void)0); \ + local_lock_t *: (void)0); \ } while (0) #define __local_unlock(lock) \ @@ -199,11 +199,11 @@ do { \ #define __local_lock_nested_bh(lock) \ do { \ lockdep_assert_in_softirq(); \ - local_lock_acquire(this_cpu_ptr(lock)); \ + local_lock_acquire((lock)); \ } while (0) #define __local_unlock_nested_bh(lock) \ - local_lock_release(this_cpu_ptr(lock)) + local_lock_release((lock)) #else /* !CONFIG_PREEMPT_RT */ @@ -227,7 +227,7 @@ typedef spinlock_t local_trylock_t; #define __local_lock(__lock) \ do { \ migrate_disable(); \ - spin_lock(this_cpu_ptr((__lock))); \ + spin_lock((__lock)); \ } while (0) #define __local_lock_irq(lock) __local_lock(lock) @@ -241,7 +241,7 @@ typedef spinlock_t local_trylock_t; #define __local_unlock(__lock) \ do { \ - spin_unlock(this_cpu_ptr((__lock))); \ + spin_unlock((__lock)); \ migrate_enable(); \ } while (0) @@ -252,12 +252,12 @@ typedef spinlock_t local_trylock_t; #define __local_lock_nested_bh(lock) \ do { \ lockdep_assert_in_softirq_func(); \ - spin_lock(this_cpu_ptr(lock)); \ + spin_lock((lock)); \ } while (0) #define __local_unlock_nested_bh(lock) \ do { \ - spin_unlock(this_cpu_ptr((lock))); \ + spin_unlock((lock)); \ } while (0) #define __local_trylock(lock) \ @@ -268,7 +268,7 @@ do { \ __locked = 0; \ } else { \ migrate_disable(); \ - __locked = spin_trylock(this_cpu_ptr((lock))); \ + __locked = spin_trylock((lock)); \ if (!__locked) \ migrate_enable(); \ } \ -- 2.49.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] local_lock: Move this_cpu_ptr() notation from internal to main header. 2025-05-14 11:07 ` [PATCH 1/2] " Sebastian Andrzej Siewior @ 2025-05-15 0:46 ` Alexei Starovoitov 2025-05-18 9:42 ` Sebastian Andrzej Siewior 0 siblings, 1 reply; 6+ messages in thread From: Alexei Starovoitov @ 2025-05-15 0:46 UTC (permalink / raw) To: Sebastian Andrzej Siewior Cc: LKML, linux-rt-devel, Thomas Gleixner, Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng On Wed, May 14, 2025 at 4:07 AM Sebastian Andrzej Siewior <bigeasy@linutronix.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@linutronix.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. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] local_lock: Move this_cpu_ptr() notation from internal to main header. 2025-05-15 0:46 ` Alexei Starovoitov @ 2025-05-18 9:42 ` Sebastian Andrzej Siewior 0 siblings, 0 replies; 6+ messages in thread From: Sebastian Andrzej Siewior @ 2025-05-18 9:42 UTC (permalink / raw) To: Alexei Starovoitov Cc: LKML, linux-rt-devel, Thomas Gleixner, Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng On 2025-05-14 17:46:43 [-0700], Alexei Starovoitov wrote: > > Are you sure this is correct? I hope so. > Have you tested with gcc 14 or higher? gcc version 14.2.0 (Debian 14.2.0-19) > It looks to me that moving this_cpu_ptr() up one level should > still preserve __seg_gs modifier. If I compile mm/memcontrol.o as-is I get no warnings. Adding diff --git a/include/linux/local_lock_internal.h b/include/linux/local_lock_internal.h index b4d7b24882835..112324bc362c1 100644 --- a/include/linux/local_lock_internal.h +++ b/include/linux/local_lock_internal.h @@ -102,11 +102,11 @@ do { \ l = (local_lock_t *)(lock); \ tl = (local_trylock_t *)l; \ _Generic((lock), \ - local_trylock_t *: ({ \ + __percpu local_trylock_t *: ({ \ lockdep_assert(tl->acquired == 0); \ WRITE_ONCE(tl->acquired, 1); \ }), \ - local_lock_t *: (void)0); \ + __percpu local_lock_t *: (void)0); \ local_lock_acquire(l); \ } while (0) @@ -171,11 +171,11 @@ do { \ tl = (local_trylock_t *)l; \ local_lock_release(l); \ _Generic((lock), \ - local_trylock_t *: ({ \ + __percpu local_trylock_t *: ({ \ lockdep_assert(tl->acquired == 1); \ WRITE_ONCE(tl->acquired, 0); \ }), \ - local_lock_t *: (void)0); \ + __percpu local_lock_t *: (void)0); \ } while (0) #define __local_unlock(lock) \ which I assume is what you mean, results in | In file included from include/linux/preempt.h:11, | from include/linux/spinlock.h:56, | from include/linux/swait.h:7, | from include/linux/completion.h:12, | from include/linux/crypto.h:15, | from arch/x86/kernel/asm-offsets.c:9: | include/linux/local_lock.h: In function ‘class_local_lock_destructor’: | include/linux/local_lock_internal.h:173:26: error: ‘_Generic’ selector of type ‘struct <anonymous> *’ is not compatible with any association | 173 | _Generic((lock), \ | | ^ | include/linux/cleanup.h:246:18: note: in definition of macro ‘DEFINE_CLASS’ | 246 | { _type _T = *p; _exit; } \ | | ^~~~~ | include/linux/local_lock.h:82:1: note: in expansion of macro ‘DEFINE_GUARD’ | 82 | DEFINE_GUARD(local_lock, local_lock_t __percpu*, | | ^~~~~~~~~~~~ | include/linux/local_lock_internal.h:183:17: note: in expansion of macro ‘__local_lock_release’ | 183 | __local_lock_release(lock); \ | | ^~~~~~~~~~~~~~~~~~~~ | include/linux/local_lock.h:37:41: note: in expansion of macro ‘__local_unlock’ | 37 | #define local_unlock(lock) __local_unlock(this_cpu_ptr(lock)) | | ^~~~~~~~~~~~~~ | include/linux/local_lock.h:84:14: note: in expansion of macro ‘local_unlock’ | 84 | local_unlock(_T)) | | ^~~~~~~~~~~~ | include/linux/local_lock.h: In function ‘class_local_lock_constructor’: | include/linux/local_lock_internal.h:104:26: error: ‘_Generic’ selector of type ‘struct <anonymous> *’ is not compatible with any association | 104 | _Generic((lock), \ | | ^ | include/linux/cleanup.h:248:13: note: in definition of macro ‘DEFINE_CLASS’ | 248 | { _type t = _init; return t; } | | ^~~~~ | include/linux/local_lock.h:82:1: note: in expansion of macro ‘DEFINE_GUARD’ | 82 | DEFINE_GUARD(local_lock, local_lock_t __percpu*, | | ^~~~~~~~~~~~ | include/linux/local_lock_internal.h:116:17: note: in expansion of macro ‘__local_lock_acquire’ | 116 | __local_lock_acquire(lock); \ | | ^~~~~~~~~~~~~~~~~~~~ | include/linux/local_lock.h:16:41: note: in expansion of macro ‘__local_lock’ | 16 | #define local_lock(lock) __local_lock(this_cpu_ptr(lock)) … Sebastian ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] cryptd: Use nested-BH locking for cryptd_cpu_queue 2025-05-14 11:07 [PATCH 0/2] local_lock: Move this_cpu_ptr() notation from internal to main header Sebastian Andrzej Siewior 2025-05-14 11:07 ` [PATCH 1/2] " Sebastian Andrzej Siewior @ 2025-05-14 11:07 ` Sebastian Andrzej Siewior 2025-05-14 11:09 ` Sebastian Andrzej Siewior 1 sibling, 1 reply; 6+ messages in thread From: Sebastian Andrzej Siewior @ 2025-05-14 11:07 UTC (permalink / raw) To: linux-kernel, linux-rt-devel Cc: tglx, Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng, Alexei Starovoitov, Sebastian Andrzej Siewior, David S. Miller, Herbert Xu, linux-crypto cryptd_queue::cryptd_cpu_queue is a per-CPU variable and relies on disabled BH for its locking. Without per-CPU locking in local_bh_disable() on PREEMPT_RT this data structure requires explicit locking. Add a local_lock_t to the struct cryptd_cpu_queue and use local_lock_nested_bh() for locking. This change adds only lockdep coverage and does not alter the functional behaviour for !PREEMPT_RT. Cc: "David S. Miller" <davem@davemloft.net> Cc: Herbert Xu <herbert@gondor.apana.org.au> Cc: linux-crypto@vger.kernel.org Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> --- crypto/cryptd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/crypto/cryptd.c b/crypto/cryptd.c index 31d022d47f7a0..39c9e83a3a5b8 100644 --- a/crypto/cryptd.c +++ b/crypto/cryptd.c @@ -34,6 +34,7 @@ MODULE_PARM_DESC(cryptd_max_cpu_qlen, "Set cryptd Max queue depth"); static struct workqueue_struct *cryptd_wq; struct cryptd_cpu_queue { + local_lock_t bh_lock; struct crypto_queue queue; struct work_struct work; }; @@ -110,6 +111,7 @@ static int cryptd_init_queue(struct cryptd_queue *queue, cpu_queue = per_cpu_ptr(queue->cpu_queue, cpu); crypto_init_queue(&cpu_queue->queue, max_cpu_qlen); INIT_WORK(&cpu_queue->work, cryptd_queue_worker); + local_lock_init(&cpu_queue->bh_lock); } pr_info("cryptd: max_cpu_qlen set to %d\n", max_cpu_qlen); return 0; @@ -135,6 +137,7 @@ static int cryptd_enqueue_request(struct cryptd_queue *queue, refcount_t *refcnt; local_bh_disable(); + local_lock_nested_bh(&queue->cpu_queue->bh_lock); cpu_queue = this_cpu_ptr(queue->cpu_queue); err = crypto_enqueue_request(&cpu_queue->queue, request); @@ -151,6 +154,7 @@ static int cryptd_enqueue_request(struct cryptd_queue *queue, refcount_inc(refcnt); out: + local_unlock_nested_bh(&queue->cpu_queue->bh_lock); local_bh_enable(); return err; @@ -169,8 +173,10 @@ static void cryptd_queue_worker(struct work_struct *work) * Only handle one request at a time to avoid hogging crypto workqueue. */ local_bh_disable(); + __local_lock_nested_bh(&cpu_queue->bh_lock); backlog = crypto_get_backlog(&cpu_queue->queue); req = crypto_dequeue_request(&cpu_queue->queue); + __local_unlock_nested_bh(&cpu_queue->bh_lock); local_bh_enable(); if (!req) -- 2.49.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] cryptd: Use nested-BH locking for cryptd_cpu_queue 2025-05-14 11:07 ` [PATCH 2/2] cryptd: Use nested-BH locking for cryptd_cpu_queue Sebastian Andrzej Siewior @ 2025-05-14 11:09 ` Sebastian Andrzej Siewior 0 siblings, 0 replies; 6+ messages in thread From: Sebastian Andrzej Siewior @ 2025-05-14 11:09 UTC (permalink / raw) To: linux-kernel, linux-rt-devel Cc: tglx, Peter Zijlstra, Ingo Molnar, Will Deacon, Waiman Long, Boqun Feng, Alexei Starovoitov, David S. Miller, Herbert Xu, linux-crypto On 2025-05-14 13:07:50 [+0200], To linux-kernel@vger.kernel.org wrote: > cryptd_queue::cryptd_cpu_queue is a per-CPU variable and relies on > disabled BH for its locking. Without per-CPU locking in > local_bh_disable() on PREEMPT_RT this data structure requires explicit > locking. > > Add a local_lock_t to the struct cryptd_cpu_queue and use > local_lock_nested_bh() for locking. This change adds only lockdep > coverage and does not alter the functional behaviour for !PREEMPT_RT. > > Cc: "David S. Miller" <davem@davemloft.net> > Cc: Herbert Xu <herbert@gondor.apana.org.au> > Cc: linux-crypto@vger.kernel.org > Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> This is meant as an example for #1 and should not be applied. Sebastian ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-05-18 9:42 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-05-14 11:07 [PATCH 0/2] local_lock: Move this_cpu_ptr() notation from internal to main header Sebastian Andrzej Siewior 2025-05-14 11:07 ` [PATCH 1/2] " Sebastian Andrzej Siewior 2025-05-15 0:46 ` Alexei Starovoitov 2025-05-18 9:42 ` Sebastian Andrzej Siewior 2025-05-14 11:07 ` [PATCH 2/2] cryptd: Use nested-BH locking for cryptd_cpu_queue Sebastian Andrzej Siewior 2025-05-14 11:09 ` Sebastian Andrzej Siewior
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox