Re: [PATCH 05/24] irq & spin_lock: Add counted interrupt disabling/enabling

Peter Zijlstra <[email protected]> Tue, 4 Aug 2026 09:26:40 +0200
Newsgroups org.kernel.vger.rust-for-linux,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Mon, Aug 03, 2026 at 09:41:02PM -0700, Boqun Feng wrote:

> > +#ifndef MODULE
> >  /* Per-cpu interrupt disabling state for local_interrupt_{disable,enable}() */
> > -struct interrupt_disable_state {
> > +DECLARE_PER_CPU(unsigned long, local_interrupt_disable_state);
> > +
> > +static __always_inline void __local_interrupt_disable(void)
> > +{
> >  	unsigned long flags;
> > -};
> >  
> > -DECLARE_PER_CPU(struct interrupt_disable_state, local_interrupt_disable_state);
> > +	local_irq_save(flags);
> > +	raw_cpu_write(local_interrupt_disable_state, flags);
> > +}
> > +
> > +static __always_inline void __local_interrupt_enable(void)
> > +{
> > +	unsigned long flags = raw_cpu_read(local_interrupt_disable_state);
> > +	local_irq_restore(flags);
> > +}
> > +
> > +#ifndef INSTANTIATE_EXPORTED_INTERRUPT_DISABLE
> > +static __always_inline void _local_interrupt_disable(void)
> > +{
> > +	__local_interrupt_disable();
> > +}
> > +
> > +static __always_inline void _local_interrupt_enable(void)
> > +{
> > +	__local_interrupt_enable();
> > +}
> > +#else
> > +extern void _local_interrupt_disable(void);
> > +extern void _local_interrupt_enable(void);
> > +#endif
> > +
> > +#else /* !MODULE */
> > +extern void _local_interrupt_disable(void);
> > +extern void _local_interrupt_enable(void);
> 
> I think the "extern" keywords are not necessary and ..

Probably, but I like them (and I know that other people hate on then).
To me it makes it clear the definition is not here and should be sought
elsewhere.

The extern really is needed for variables, but I also use it with
functions for the same.

> > +#endif /* !MODULE */
> >  

> > --- a/kernel/softirq.c
> > +++ b/kernel/softirq.c
> > @@ -9,6 +9,7 @@
> >  
> >  #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> >  
> > +#define INSTANTIATE_EXPORTED_INTERRUPT_DISABLE
> >  #include <linux/export.h>
> >  #include <linux/kernel_stat.h>
> >  #include <linux/interrupt.h>
> > @@ -88,8 +89,17 @@ EXPORT_PER_CPU_SYMBOL_GPL(hardirqs_enabl
> >  EXPORT_PER_CPU_SYMBOL_GPL(hardirq_context);
> >  #endif
> >  
> > -DEFINE_PER_CPU(struct interrupt_disable_state, local_interrupt_disable_state);
> > -EXPORT_PER_CPU_SYMBOL_GPL(local_interrupt_disable_state);
> > +DEFINE_PER_CPU(unsigned long, local_interrupt_disable_state);
> > +
> > +void _local_interrupt_disable(void)
> > +{
> > +	__local_interrupt_disable();
> > +}
> > +
> > +void _local_interrupt_enable(void)
> > +{
> > +	__local_interrupt_enable();
> > +}
> >  
> 
> We need to EXPORT_SYMBOL_GPL() for these two functions.
> 
> Right?

Quite so.