Re: [PATCH] irq: Move local_irq_enable/disable() into Rust
From: Boqun Feng
Date: Fri Sep 04 2026 - 11:35:47 EST
[Cc Miguel, Lyude, Alice, Gary]
On Fri, Sep 04, 2026 at 03:26:40PM +0200, Thomas Gleixner wrote:
> After reverting the spinlock conversion and a lengthy discussion it's the
> best to confine the reference counted interrupt disable/enable mechanism to
> Rust which is the only user.
>
> This should become the new norm, but that needs more thoughts and cleaning
> up the confined usage in Rust at some point is way simpler than chasing
> random places which adopt it in the meanwhile.
>
Thank you for doing this! I think the subject should be:
irq: Move local_interrupt_{dis,en}able() into Rust
to be accurate about the name of the functions.
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxx>
> ---
> Resend because I fatfingered the Subject line ... Sorry for the noise in
> case you got the original busted one.
>
> Applies against tip locking/urgent
> ---
> include/linux/spinlock.h | 23 -------
> include/linux/spinlock_api_smp.h | 41 ------------
> include/linux/spinlock_api_up.h | 15 ----
> include/linux/spinlock_rt.h | 18 -----
Seems we are missing a deletion of include/linux/interrupt_rc.h here.
> kernel/irq/refcount_interrupt_test.c | 2
> kernel/locking/spinlock.c | 31 ---------
> kernel/softirq.c | 15 ----
> rust/helpers/interrupt.c | 21 ++++++
> rust/helpers/interrupt_rc.h | 68 ++++++++++++++++++++
> rust/helpers/spinlock.c | 39 +++++++++++
> rust/helpers/spinlock.h | 114 +++++++++++++++++++++++++++++++++++
> 11 files changed, 241 insertions(+), 146 deletions(-)
>
[...]
> --- /dev/null
> +++ b/rust/helpers/spinlock.h
> @@ -0,0 +1,114 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#ifndef __RUST_HELPERS_SPINLOCK_H
> +#define __RUST_HELPERS_SPINLOCK_H
> +
> +#include <linux/spinlock.h>
> +#include "interrupt_rc.h"
> +
> +#ifdef CONFIG_SMP
> +void __lockfunc _raw_spin_lock_irq_disable(raw_spinlock_t *lock) __acquires(lock);
> +void __lockfunc _raw_spin_unlock_irq_enable(raw_spinlock_t *lock) __releases(lock);
> +
> +/* Use the same config as spin_lock_irq() temporarily. */
> +#ifdef CONFIG_INLINE_SPIN_LOCK_IRQ
> +#define _raw_spin_lock_irq_disable(lock) __raw_spin_lock_irq_disable(lock)
> +#endif
> +
> +/* Use the same config as spin_unlock_irq() temporarily. */
> +#ifdef CONFIG_INLINE_SPIN_UNLOCK_IRQ
> +#define _raw_spin_unlock_irq_enable(lock) __raw_spin_unlock_irq_enable(lock)
> +#endif
> +
> +static __always_inline bool _raw_spin_trylock_irq_disable(raw_spinlock_t *lock)
> + __cond_acquires(true, lock)
> +{
> + local_interrupt_disable();
> + if (_raw_spin_trylock(lock))
> + return true;
> + local_interrupt_enable();
> + return false;
> +}
> +
> +static inline void __raw_spin_lock_irq_disable(raw_spinlock_t *lock)
> + __acquires(lock) __no_context_analysis
I think we need to put the
#if !defined(CONFIG_GENERIC_LOCKBREAK) || defined(CONFIG_DEBUG_LOCK_ALLOC)
#endif
around this. Because in the #else branch of rust/helpers/spinlock.c we
have an out-of-line definition of the same function.
Regards,
Boqun
> +{
> + local_interrupt_disable();
> + preempt_disable();
> + spin_acquire(&lock->dep_map, 0, 0, _RET_IP_);
> + LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock);
> +}
> +
> +static inline void __raw_spin_unlock_irq_enable(raw_spinlock_t *lock)
> + __releases(lock)
> +{
> + spin_release(&lock->dep_map, _RET_IP_);
> + do_raw_spin_unlock(lock);
> + local_interrupt_enable();
> + preempt_enable();
> +}
> +
> +#else /* CONFIG_SMP */
> +
> +#define __LOCK_IRQ_DISABLE(lock, ...) \
> + do { local_interrupt_disable(); __LOCK(lock, ##__VA_ARGS__); } while (0)
> +#define __UNLOCK_IRQ_ENABLE(lock, ...) \
> + do { __UNLOCK(lock, ##__VA_ARGS__); local_interrupt_enable(); } while (0)
> +
> +#define _raw_spin_lock_irq_disable(lock) __LOCK_IRQ_DISABLE(lock)
> +#define _raw_spin_unlock_irq_enable(lock) __UNLOCK_IRQ_ENABLE(lock)
> +
> +static __always_inline int _raw_spin_trylock_irq_disable(raw_spinlock_t *lock)
> + __cond_acquires(true, lock)
> +{
> + __LOCK_IRQ_DISABLE(lock);
> + return 1;
> +}
> +
[...]