Linux kernel and device drivers for NXP i.MX platforms
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Peng Fan" <peng.fan@linux.dev>
Cc: imx@lists.linux.dev, Frank.Li@kernel.org
Subject: Re: [PATCH v2 2/8] irqchip/imx-intmux: Dispose IRQ mappings on remove
Date: Thu, 03 Dec 2026 09:53:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-247507@kernel.org> (raw)
In-Reply-To: <20261203-imx-intmux-v2-2-a6db1eed3b5f@nxp.com>

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] irqchip/imx-intmux: lazy disable_irq() leaves race in
  imx_intmux_remove()
- [Medium] irqchip/imx-intmux: lazy disable_irq() leaves parent IRQ
  unmasked on remove
- [Low] irqchip/imx-intmux: commit message cites old
  irq_of_parse_and_map()
--

commit ba79cdc897e9950cf9db9d3877c7ec4b69f3800c
Author: Peng Fan <peng.fan@nxp.com>

irqchip/imx-intmux: Dispose IRQ mappings on remove

This commit masks and unchains each INTMUX channel's parent interrupt,
disposes the 32 child IRQ mappings before removing the channel domain,
and releases the parent IRQ mapping on driver removal.

> The driver removes its IRQ domains without disposing the mappings
> created for their 32 input lines, and it never releases the parent
> IRQ mappings obtained with irq_of_parse_and_map().

[Severity: Low]
Commit "irqchip/imx-intmux: Don't create parent mappings while counting
channels" already replaced irq_of_parse_and_map() with of_irq_get() in
imx_intmux_probe().  Should this refer to of_irq_get() instead?

> diff --git a/drivers/irqchip/irq-imx-intmux.c b/drivers/irqchip/irq-imx-intmux.c
> index 7552a3d0c3695..3b4eb9bd6678b 100644
> --- a/drivers/irqchip/irq-imx-intmux.c
> +++ b/drivers/irqchip/irq-imx-intmux.c
> @@ -296,10 +296,19 @@ static void imx_intmux_remove(struct platform_device *pdev)
>  		/* disable all interrupt sources of this channel */
>  		if (ret >= 0)
>  			writel_relaxed(0, data->regs + CHANIER(i));
> +		/*
> +		 * Mask the parent interrupt and wait for a handler that is
> +		 * already running to finish before its data and mappings are
> +		 * torn down.
> +		 */
> +		disable_irq(data->irqchip_data[i].irq);
>  		irq_set_chained_handler_and_data(data->irqchip_data[i].irq,
>  						 NULL, NULL);
> -
> +		for (unsigned int hwirq = 0; hwirq < 32; hwirq++)
> +			irq_dispose_mapping(irq_find_mapping(data->irqchip_data[i].domain,
> +							     hwirq));
>  		irq_domain_remove(data->irqchip_data[i].domain);
> +		irq_dispose_mapping(data->irqchip_data[i].irq);

[Severity: Medium]
Can disable_irq() leave the parent GICv3 interrupt unmasked in hardware
and allow imx_intmux_irq_handler() to race with teardown?

On i.MX8 platforms using this driver, the parent controller is GICv3,
where neither gic_chip nor gic_eoimode1_chip implements .irq_disable.
Without IRQ_DISABLE_UNLAZY, disable_irq() calls __irq_disable(desc,
false), which only sets IRQD_IRQ_DISABLED in software and skips
mask_irq().

CPU0                              CPU1
imx_intmux_remove()
  disable_irq(irq)
    __irq_disable(desc, false)
    synchronize_irq(irq)
  irq_set_chained_handler_and_data(...)
    ...handler_data = NULL
                                  <hardirq>
                                  imx_intmux_irq_handler()
                                    irqchip_data = ...handler_data
                                    idx = irqchip_data->chanidx
                                      <-- NULL pointer dereference
    __irq_do_set_handler(..., NULL)

Because imx_intmux_irq_handler() is a chained handler, it runs without
desc->lock or checking irqd_irq_disabled().  If a parent SPI fires after
disable_irq() returns (for example when pm_runtime_resume_and_get()
fails so CHANIER(i) is not cleared, or while writel_relaxed(0, ...) is
still posted), CPU1 can dereference a NULL irqchip_data or continue
running against the freed irq_domain after irq_domain_remove().

irq_set_chained_handler_and_data(..., NULL, NULL) masks the parent line
only after clearing handler_data and does not synchronize afterward, and
the trailing irq_dispose_mapping() installs no_irq_chip before its
synchronize_irq(), losing the GIC active-state check.

Setting IRQ_DISABLE_UNLAZY on the parent IRQ before disable_irq() would
force __irq_disable() to mask the GICv3 line in hardware before
synchronize_irq() runs.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-imx-intmux-v2-0-a6db1eed3b5f@nxp.com?part=2

  reply	other threads:[~2026-12-03  9:53 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  9:29 [PATCH v2 0/8] irqchip/imx-intmux: Fix and modernize resource management Peng Fan
2026-12-03  9:29 ` [PATCH v2 1/8] irqchip/imx-intmux: Don't create parent mappings while counting channels Peng Fan
2026-12-03  9:52   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 2/8] irqchip/imx-intmux: Dispose IRQ mappings on remove Peng Fan
2026-12-03  9:53   ` sashiko-bot [this message]
2026-12-03  9:29 ` [PATCH v2 3/8] irqchip/imx-intmux: Fix probe error path Peng Fan
2026-12-03  9:50   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 4/8] irqchip/imx-intmux: Reject zero channel count Peng Fan
2026-12-03  9:29 ` [PATCH v2 5/8] irqchip/imx-intmux: Mark input interrupts as level-triggered Peng Fan
2026-12-03  9:40   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 6/8] irqchip/imx-intmux: Don't WARN on malformed interrupt specifiers Peng Fan
2026-12-03  9:46   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 7/8] irqchip/imx-intmux: Use devm_irq_domain_create_linear() Peng Fan
2026-12-03  9:55   ` sashiko-bot
2026-12-03  9:29 ` [PATCH v2 8/8] irqchip/imx-intmux: Factor out imx_intmux_teardown_channel() Peng Fan
2026-12-03 10:01   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=sashiko-outbox-247507@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=Frank.Li@kernel.org \
    --cc=imx@lists.linux.dev \
    --cc=peng.fan@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox