Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/panfrost: level-triggered IRQ storm in
  panfrost_jm_suspend_irq()
--

commit f6cf958c59f482f84481acc7413188e321156153
Author: Arun Iyengar <[email protected]>

drm/panfrost: Keep the job interrupts masked during a reset

This commit replaces the open-coded JOB_INT_MASK masking and
synchronize_irq() in panfrost_reset() with panfrost_jm_suspend_irq(), and
adds a second write to JOB_INT_MASK after synchronize_irq().

> diff --git a/drivers/gpu/drm/panfrost/panfrost_job.c 
> b/drivers/gpu/drm/panfrost/panfrost_job.c
> index 74cc3dd025336..7a2503f4e5a40 100644
> --- a/drivers/gpu/drm/panfrost/panfrost_job.c
> +++ b/drivers/gpu/drm/panfrost/panfrost_job.c
> @@ -459,6 +459,7 @@ void panfrost_jm_suspend_irq(struct panfrost_device 
> *pfdev)
>  
>       job_write(pfdev, JOB_INT_MASK, 0);
>       synchronize_irq(pfdev->js->irq);
> +     job_write(pfdev, JOB_INT_MASK, 0);
>  }
>  
>  static void panfrost_job_handle_err(struct panfrost_device *pfdev,
> @@ -696,8 +697,7 @@ panfrost_reset(struct panfrost_device *pfdev,
>       /* Mask job interrupts and synchronize to make sure we won't be
>        * interrupted during our reset.
>        */
> -     job_write(pfdev, JOB_INT_MASK, 0);
> -     synchronize_irq(pfdev->js->irq);
> +     panfrost_jm_suspend_irq(pfdev);

[Severity: High]
Can calling panfrost_jm_suspend_irq() while GPU jobs are still active
trigger a level-triggered hardirq storm on pfdev->js->irq?

Unlike runtime suspend, panfrost_reset() calls panfrost_jm_suspend_irq()
before issuing JS_COMMAND_SOFT_STOP, so running jobs can still complete or
fault and assert JOB_INT_RAWSTAT.  When PANFROST_COMP_BIT_JOB is set,
panfrost_jm_irq_handler() returns IRQ_NONE without masking JOB_INT_MASK:

drivers/gpu/drm/panfrost/panfrost_job.c:panfrost_jm_irq_handler() {
        if (test_bit(PANFROST_COMP_BIT_JOB, pfdev->is_suspended))
                return IRQ_NONE;
    ...
        job_write(pfdev, JOB_INT_MASK, 0);
        return IRQ_WAKE_THREAD;
}

In the race that the second job_write(pfdev, JOB_INT_MASK, 0) is meant to
handle, JOB_INT_MASK is re-enabled while PANFROST_COMP_BIT_JOB is already
set:

CPU0                              CPU1
panfrost_jm_irq_handler_thread()  panfrost_reset()
  panfrost_jm_handle_irqs()         panfrost_jm_suspend_irq()
  if (!test_bit(COMP_BIT_JOB, ...))
                                      set_bit(COMP_BIT_JOB, ...)
                                      job_write(pfdev, JOB_INT_MASK, 0)
                                      synchronize_irq(pfdev->js->irq)
    job_write(pfdev, JOB_INT_MASK,
              ALL_JS_INT_MASK)
    <hardirq: job completes>
      panfrost_jm_irq_handler()
        if (test_bit(COMP_BIT_JOB))
          return IRQ_NONE;        <-- level-triggered IRQ storm

The same window exists in panfrost_jm_suspend_irq() between set_bit() and
the first job_write(pfdev, JOB_INT_MASK, 0).  Because the Mali job IRQ is
level-triggered, returning IRQ_NONE with JOB_INT_MASK unmasked causes the
interrupt to immediately re-fire, starving the interrupted CPU (including
CPU0 before the IRQ thread can finish and release synchronize_irq(), or
CPU1 before the second mask write) until note_interrupt() disables the IRQ
line.

-- 
Sashiko AI review ยท 
https://sashiko.dev/#/patchset/[email protected]?part=15

Reply via email to