mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/nouveau/intr: do not unmask hardware interrupts while unarmed
@ 2026-11-29  5:30 Pufan Jin
  2026-12-04  2:05 ` Lyude Paul
  0 siblings, 1 reply; 3+ messages in thread
From: Pufan Jin @ 2026-11-29  5:30 UTC (permalink / raw)
  To: Danilo Krummrich, David Airlie, Lyude Paul, Maarten Lankhorst,
	Maxime Ripard, Simona Vetter, Thomas Zimmermann
  Cc: dri-devel, linux-kernel, nouveau

During device initialization in nvkm_device_init(), nvkm_intr_rearm()
iterates through all legacy subdevices and calls nvkm_intr_subdev_add(),
which in turn calls nvkm_inth_allow() -> nvkm_intr_allow_locked().

nvkm_intr_allow_locked() directly writes to the hardware interrupt
enable registers (e.g. PMC register 0x160 on GP100/GP10B) to unmask the
subdevice's interrupt, and nvkm_inth_allow() then restores local CPU
interrupts via spin_unlock_irqrestore().

However, at this point, device->intr.armed is still false because arming
is performed only at the end of nvkm_intr_rearm(). On platforms where
the GPU interrupt is level-triggered and directly wired to an interrupt
controller (such as Tegra GP10B using GIC SPI 70), any pending interrupt
assertion immediately triggers the top-level interrupt handler
nvkm_intr().

In nvkm_intr(), because device->intr.armed is false, the handler bails
out early and returns IRQ_NONE without reading, acknowledging, or
masking the interrupt source:

  spin_lock(&device->intr.lock);
  if (!device->intr.armed)
      goto done_unlock;

Because the interrupt line remains continuously asserted, this causes an
immediate, tight interrupt storm (100,000 unhandled interrupts), leading
the kernel to disable the IRQ line with "nobody cared":

  irq 142: nobody cared (try booting with the "irqpoll" option)
  CPU: 0 UID: 0 PID: 361 Comm: (udev-worker)
  Hardware name: NVIDIA Jetson TX2 Developer Kit (DT)
  Call trace:
   ...
   handle_fasteoi_irq+0xe0/0x180
   gic_handle_irq+0x3c/0xc0
   _raw_spin_unlock_irqrestore+0x18/0x40 (P)
   nvkm_intr_subdev_add_dev+0x6c/0x88 [nouveau]
   nvkm_intr_rearm+0x138/0x1f8 [nouveau]
   nvkm_device_init+0x118/0x290 [nouveau]
  handlers:
  [<...>] nvkm_intr [nouveau]
  Disabling IRQ #142

Fix this issue by:
1. Only writing to the hardware allow/block registers in
   nvkm_intr_allow_locked() and nvkm_intr_block_locked() when
   device->intr.armed is true. While unarmed, only the software interest
   mask (intr->mask) is updated, and nvkm_intr_rearm() will program the
   accumulated mask under spin_lock_irq() when arming the device.
   
2. If an unexpected interrupt arrives while unarmed, explicitly calling
   nvkm_intr_unarm_locked() in nvkm_intr() to silence top-level
   interrupt generation immediately.
3. Marking ret = IRQ_HANDLED when unhandled interrupts are blocked by the
   IRQ storm mitigation logic in nvkm_intr().

Signed-off-by: Pufan Jin <cyan2254650260@gmail.com>
---
 drivers/gpu/drm/nouveau/nvkm/core/intr.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nvkm/core/intr.c b/drivers/gpu/drm/nouveau/nvkm/core/intr.c
index f31aca949..0397a630a 100644
--- a/drivers/gpu/drm/nouveau/nvkm/core/intr.c
+++ b/drivers/gpu/drm/nouveau/nvkm/core/intr.c
@@ -91,7 +91,7 @@ static void
 nvkm_intr_allow_locked(struct nvkm_intr *intr, int leaf, u32 mask)
 {
 	intr->mask[leaf] |= mask;
-	if (intr->func->allow) {
+	if (intr->subdev->device->intr.armed && intr->func->allow) {
 		if (intr->func->reset)
 			intr->func->reset(intr, leaf, mask);
 		intr->func->allow(intr, leaf, mask);
@@ -120,7 +120,7 @@ static void
 nvkm_intr_block_locked(struct nvkm_intr *intr, int leaf, u32 mask)
 {
 	intr->mask[leaf] &= ~mask;
-	if (intr->func->block)
+	if (intr->subdev->device->intr.armed && intr->func->block)
 		intr->func->block(intr, leaf, mask);
 }
 
@@ -172,8 +172,10 @@ nvkm_intr(int irq, void *arg)
 
 	/* Disable all top-level interrupt sources, and re-arm MSI interrupts. */
 	spin_lock(&device->intr.lock);
-	if (!device->intr.armed)
+	if (!device->intr.armed) {
+		nvkm_intr_unarm_locked(device);
 		goto done_unlock;
+	}
 
 	nvkm_intr_unarm_locked(device);
 	nvkm_pci_msi_rearm(device);
@@ -215,6 +217,7 @@ nvkm_intr(int irq, void *arg)
 					nvkm_debug(intr->subdev, "intr%d: %08x\n",
 						   leaf, intr->stat[leaf]);
 					nvkm_intr_block_locked(intr, leaf, intr->stat[leaf]);
+					ret = IRQ_HANDLED;
 				}
 			}
 		}
-- 
2.56.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/nouveau/intr: do not unmask hardware interrupts while unarmed
  2026-11-29  5:30 [PATCH] drm/nouveau/intr: do not unmask hardware interrupts while unarmed Pufan Jin
@ 2026-12-04  2:05 ` Lyude Paul
  2026-12-04  6:38   ` Pufan Jin
  0 siblings, 1 reply; 3+ messages in thread
From: Lyude Paul @ 2026-12-04  2:05 UTC (permalink / raw)
  To: Pufan Jin, Danilo Krummrich, David Airlie, Maarten Lankhorst,
	Maxime Ripard, Simona Vetter, Thomas Zimmermann
  Cc: dri-devel, linux-kernel, nouveau

Reviewed-by: Lyude Paul <lyude.paul@maintainer.cc>

Will push to drm-misc-fixes in a bit

On Sun, 2026-11-29 at 13:30 +0800, Pufan Jin wrote:
> During device initialization in nvkm_device_init(), nvkm_intr_rearm()
> iterates through all legacy subdevices and calls
> nvkm_intr_subdev_add(),
> which in turn calls nvkm_inth_allow() -> nvkm_intr_allow_locked().
> 
> nvkm_intr_allow_locked() directly writes to the hardware interrupt
> enable registers (e.g. PMC register 0x160 on GP100/GP10B) to unmask
> the
> subdevice's interrupt, and nvkm_inth_allow() then restores local CPU
> interrupts via spin_unlock_irqrestore().
> 
> However, at this point, device->intr.armed is still false because
> arming
> is performed only at the end of nvkm_intr_rearm(). On platforms where
> the GPU interrupt is level-triggered and directly wired to an
> interrupt
> controller (such as Tegra GP10B using GIC SPI 70), any pending
> interrupt
> assertion immediately triggers the top-level interrupt handler
> nvkm_intr().
> 
> In nvkm_intr(), because device->intr.armed is false, the handler
> bails
> out early and returns IRQ_NONE without reading, acknowledging, or
> masking the interrupt source:
> 
>   spin_lock(&device->intr.lock);
>   if (!device->intr.armed)
>       goto done_unlock;
> 
> Because the interrupt line remains continuously asserted, this causes
> an
> immediate, tight interrupt storm (100,000 unhandled interrupts),
> leading
> the kernel to disable the IRQ line with "nobody cared":
> 
>   irq 142: nobody cared (try booting with the "irqpoll" option)
>   CPU: 0 UID: 0 PID: 361 Comm: (udev-worker)
>   Hardware name: NVIDIA Jetson TX2 Developer Kit (DT)
>   Call trace:
>    ...
>    handle_fasteoi_irq+0xe0/0x180
>    gic_handle_irq+0x3c/0xc0
>    _raw_spin_unlock_irqrestore+0x18/0x40 (P)
>    nvkm_intr_subdev_add_dev+0x6c/0x88 [nouveau]
>    nvkm_intr_rearm+0x138/0x1f8 [nouveau]
>    nvkm_device_init+0x118/0x290 [nouveau]
>   handlers:
>   [<...>] nvkm_intr [nouveau]
>   Disabling IRQ #142
> 
> Fix this issue by:
> 1. Only writing to the hardware allow/block registers in
>    nvkm_intr_allow_locked() and nvkm_intr_block_locked() when
>    device->intr.armed is true. While unarmed, only the software
> interest
>    mask (intr->mask) is updated, and nvkm_intr_rearm() will program
> the
>    accumulated mask under spin_lock_irq() when arming the device.
>    
> 2. If an unexpected interrupt arrives while unarmed, explicitly
> calling
>    nvkm_intr_unarm_locked() in nvkm_intr() to silence top-level
>    interrupt generation immediately.
> 3. Marking ret = IRQ_HANDLED when unhandled interrupts are blocked by
> the
>    IRQ storm mitigation logic in nvkm_intr().
> 
> Signed-off-by: Pufan Jin <cyan2254650260@gmail.com>
> ---
>  drivers/gpu/drm/nouveau/nvkm/core/intr.c | 9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/nouveau/nvkm/core/intr.c
> b/drivers/gpu/drm/nouveau/nvkm/core/intr.c
> index f31aca949..0397a630a 100644
> --- a/drivers/gpu/drm/nouveau/nvkm/core/intr.c
> +++ b/drivers/gpu/drm/nouveau/nvkm/core/intr.c
> @@ -91,7 +91,7 @@ static void
>  nvkm_intr_allow_locked(struct nvkm_intr *intr, int leaf, u32 mask)
>  {
>  	intr->mask[leaf] |= mask;
> -	if (intr->func->allow) {
> +	if (intr->subdev->device->intr.armed && intr->func->allow) {
>  		if (intr->func->reset)
>  			intr->func->reset(intr, leaf, mask);
>  		intr->func->allow(intr, leaf, mask);
> @@ -120,7 +120,7 @@ static void
>  nvkm_intr_block_locked(struct nvkm_intr *intr, int leaf, u32 mask)
>  {
>  	intr->mask[leaf] &= ~mask;
> -	if (intr->func->block)
> +	if (intr->subdev->device->intr.armed && intr->func->block)
>  		intr->func->block(intr, leaf, mask);
>  }
>  
> @@ -172,8 +172,10 @@ nvkm_intr(int irq, void *arg)
>  
>  	/* Disable all top-level interrupt sources, and re-arm MSI
> interrupts. */
>  	spin_lock(&device->intr.lock);
> -	if (!device->intr.armed)
> +	if (!device->intr.armed) {
> +		nvkm_intr_unarm_locked(device);
>  		goto done_unlock;
> +	}
>  
>  	nvkm_intr_unarm_locked(device);
>  	nvkm_pci_msi_rearm(device);
> @@ -215,6 +217,7 @@ nvkm_intr(int irq, void *arg)
>  					nvkm_debug(intr->subdev,
> "intr%d: %08x\n",
>  						   leaf, intr-
> >stat[leaf]);
>  					nvkm_intr_block_locked(intr,
> leaf, intr->stat[leaf]);
> +					ret = IRQ_HANDLED;
>  				}
>  			}
>  		}

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] drm/nouveau/intr: do not unmask hardware interrupts while unarmed
  2026-12-04  2:05 ` Lyude Paul
@ 2026-12-04  6:38   ` Pufan Jin
  0 siblings, 0 replies; 3+ messages in thread
From: Pufan Jin @ 2026-12-04  6:38 UTC (permalink / raw)
  To: Lyude Paul, Danilo Krummrich, David Airlie, Maarten Lankhorst,
	Maxime Ripard, Simona Vetter, Thomas Zimmermann
  Cc: dri-devel, linux-kernel, nouveau

Hi Lyude,

Thanks for taking a look! If you haven't pushed this yet, could you hold
off on v1 for a moment?

After sending it, it turned out that the two extra changes in nvkm_intr()
actually have some issues (flagged by the Sashiko bot): calling
nvkm_intr_unarm_locked() when !device->intr.armed can hit BAR0 MMIO on
a shared IRQ while the GPU is suspended in D3, and can also race with
nvkm_intr_dtor(). And returning IRQ_HANDLED in the storm path would
defeat spurious IRQ detection on older cards that don't have a .block
callback.

Neither of those two hunks is actually needed to fix the TX2 IRQ storm
anyway. Only guarding the allow/block register writes on
device->intr.armed is enough, and I should add a Fixes tag too.

I'll test the trimmed-down v2 on my TX2 and send it out soon. If v1
already went in, no problem at all, I can just send a follow-up patch
to revert those two bits.

Thanks,
Pufan


On 12/4/26 10:05 AM, Lyude Paul wrote:
> Reviewed-by: Lyude Paul <lyude.paul@maintainer.cc>
>
> Will push to drm-misc-fixes in a bit
>
> On Sun, 2026-11-29 at 13:30 +0800, Pufan Jin wrote:
>> During device initialization in nvkm_device_init(), nvkm_intr_rearm()
>> iterates through all legacy subdevices and calls
>> nvkm_intr_subdev_add(),
>> which in turn calls nvkm_inth_allow() -> nvkm_intr_allow_locked().
>>
>> nvkm_intr_allow_locked() directly writes to the hardware interrupt
>> enable registers (e.g. PMC register 0x160 on GP100/GP10B) to unmask
>> the
>> subdevice's interrupt, and nvkm_inth_allow() then restores local CPU
>> interrupts via spin_unlock_irqrestore().
>>
>> However, at this point, device->intr.armed is still false because
>> arming
>> is performed only at the end of nvkm_intr_rearm(). On platforms where
>> the GPU interrupt is level-triggered and directly wired to an
>> interrupt
>> controller (such as Tegra GP10B using GIC SPI 70), any pending
>> interrupt
>> assertion immediately triggers the top-level interrupt handler
>> nvkm_intr().
>>
>> In nvkm_intr(), because device->intr.armed is false, the handler
>> bails
>> out early and returns IRQ_NONE without reading, acknowledging, or
>> masking the interrupt source:
>>
>>    spin_lock(&device->intr.lock);
>>    if (!device->intr.armed)
>>        goto done_unlock;
>>
>> Because the interrupt line remains continuously asserted, this causes
>> an
>> immediate, tight interrupt storm (100,000 unhandled interrupts),
>> leading
>> the kernel to disable the IRQ line with "nobody cared":
>>
>>    irq 142: nobody cared (try booting with the "irqpoll" option)
>>    CPU: 0 UID: 0 PID: 361 Comm: (udev-worker)
>>    Hardware name: NVIDIA Jetson TX2 Developer Kit (DT)
>>    Call trace:
>>     ...
>>     handle_fasteoi_irq+0xe0/0x180
>>     gic_handle_irq+0x3c/0xc0
>>     _raw_spin_unlock_irqrestore+0x18/0x40 (P)
>>     nvkm_intr_subdev_add_dev+0x6c/0x88 [nouveau]
>>     nvkm_intr_rearm+0x138/0x1f8 [nouveau]
>>     nvkm_device_init+0x118/0x290 [nouveau]
>>    handlers:
>>    [<...>] nvkm_intr [nouveau]
>>    Disabling IRQ #142
>>
>> Fix this issue by:
>> 1. Only writing to the hardware allow/block registers in
>>     nvkm_intr_allow_locked() and nvkm_intr_block_locked() when
>>     device->intr.armed is true. While unarmed, only the software
>> interest
>>     mask (intr->mask) is updated, and nvkm_intr_rearm() will program
>> the
>>     accumulated mask under spin_lock_irq() when arming the device.
>>     
>> 2. If an unexpected interrupt arrives while unarmed, explicitly
>> calling
>>     nvkm_intr_unarm_locked() in nvkm_intr() to silence top-level
>>     interrupt generation immediately.
>> 3. Marking ret = IRQ_HANDLED when unhandled interrupts are blocked by
>> the
>>     IRQ storm mitigation logic in nvkm_intr().
>>
>> Signed-off-by: Pufan Jin <cyan2254650260@gmail.com>
>> ---
>>   drivers/gpu/drm/nouveau/nvkm/core/intr.c | 9 ++++++---
>>   1 file changed, 6 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/nouveau/nvkm/core/intr.c
>> b/drivers/gpu/drm/nouveau/nvkm/core/intr.c
>> index f31aca949..0397a630a 100644
>> --- a/drivers/gpu/drm/nouveau/nvkm/core/intr.c
>> +++ b/drivers/gpu/drm/nouveau/nvkm/core/intr.c
>> @@ -91,7 +91,7 @@ static void
>>   nvkm_intr_allow_locked(struct nvkm_intr *intr, int leaf, u32 mask)
>>   {
>>   	intr->mask[leaf] |= mask;
>> -	if (intr->func->allow) {
>> +	if (intr->subdev->device->intr.armed && intr->func->allow) {
>>   		if (intr->func->reset)
>>   			intr->func->reset(intr, leaf, mask);
>>   		intr->func->allow(intr, leaf, mask);
>> @@ -120,7 +120,7 @@ static void
>>   nvkm_intr_block_locked(struct nvkm_intr *intr, int leaf, u32 mask)
>>   {
>>   	intr->mask[leaf] &= ~mask;
>> -	if (intr->func->block)
>> +	if (intr->subdev->device->intr.armed && intr->func->block)
>>   		intr->func->block(intr, leaf, mask);
>>   }
>>   
>> @@ -172,8 +172,10 @@ nvkm_intr(int irq, void *arg)
>>   
>>   	/* Disable all top-level interrupt sources, and re-arm MSI
>> interrupts. */
>>   	spin_lock(&device->intr.lock);
>> -	if (!device->intr.armed)
>> +	if (!device->intr.armed) {
>> +		nvkm_intr_unarm_locked(device);
>>   		goto done_unlock;
>> +	}
>>   
>>   	nvkm_intr_unarm_locked(device);
>>   	nvkm_pci_msi_rearm(device);
>> @@ -215,6 +217,7 @@ nvkm_intr(int irq, void *arg)
>>   					nvkm_debug(intr->subdev,
>> "intr%d: %08x\n",
>>   						   leaf, intr-
>>> stat[leaf]);
>>   					nvkm_intr_block_locked(intr,
>> leaf, intr->stat[leaf]);
>> +					ret = IRQ_HANDLED;
>>   				}
>>   			}
>>   		}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-12-04  6:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-29  5:30 [PATCH] drm/nouveau/intr: do not unmask hardware interrupts while unarmed Pufan Jin
2026-12-04  2:05 ` Lyude Paul
2026-12-04  6:38   ` Pufan Jin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®