[PATCH 4/4] irqchip/riscv-imsic: Remove irq_desc lookup from hot path

Thomas Gleixner tglx at linutronix.de
Thu Oct 16 03:01:53 PDT 2025


On Wed, Oct 15 2025 at 12:55, Samuel Holland wrote:
> The IMSIC driver uses the IRQ matrix allocator, so there is an arbitrary
> mapping from the per-CPU interrupt identity to the global irq number. As
> a result, the driver maintains a table of vectors so it can look up the
> virq number during interrupt handling. The driver uses the virq for one
> main purpose: it gets passed to generic_handle_irq(), which then uses it
> to look up the irq_desc in the sparse_irqs tree.
>
> Taking inspiration from the loongarch AVEC irqchip driver, skip the tree

which got the idea from x86 :)

> -struct imsic_vector *imsic_vector_alloc(unsigned int irq, const struct cpumask *mask)
> +struct imsic_vector *imsic_vector_alloc(struct irq_desc *desc, const struct cpumask *mask)
>  {
>  	struct imsic_vector *vec = NULL;
>  	struct imsic_local_priv *lpriv;
> @@ -450,7 +451,7 @@ struct imsic_vector *imsic_vector_alloc(unsigned int irq, const struct cpumask *
>  
>  	lpriv = per_cpu_ptr(imsic->lpriv, cpu);
>  	vec = &lpriv->vectors[local_id];
> -	vec->irq = irq;
> +	vec->desc = desc;
>  	vec->enable = false;
>  	vec->move_next = NULL;
>  	vec->move_prev = NULL;
> @@ -463,7 +464,7 @@ void imsic_vector_free(struct imsic_vector *vec)
>  	unsigned long flags;
>  
>  	raw_spin_lock_irqsave(&imsic->matrix_lock, flags);
> -	vec->irq = 0;
> +	vec->desc = NULL;
>  	irq_matrix_free(imsic->matrix, vec->cpu, vec->local_id, false);
>  	raw_spin_unlock_irqrestore(&imsic->matrix_lock, flags);

This is only correct when it is guaranteed that the interrupt can't be
raised in the CPU _before_ a interrupt allocation completed throughout
the hierarchy and _after_ the freeing hierarchy walk started. Otherwise
this might end up accessing a half initialized or half torn down
descriptor.

If it is, then please add a comment describing it. If not then you need
to implement the activate/deactivate callbacks for your interrupt domain
and do the store/clear of vec->desc there.

Thanks,

        tglx



More information about the linux-riscv mailing list