Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Arun Iyengar" <aiyengar1990@gmail.com>
Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org,
	media-ci@linuxtv.org
Subject: Re: [PATCH v4 09/18] media: verisilicon: Reinitialize the IOMMU after resetting an encoder core
Date: Sun, 06 Dec 2026 06:21:28 +0000	[thread overview]
Message-ID: <sashiko-outbox-252218@kernel.org> (raw)
In-Reply-To: <20261206-hantro-robust-v4-9-b99d33a5ec6d@gmail.com>

Thank you for your contribution! Sashiko AI review found 4 potential
issues to consider:
- [High] media: verisilicon: hantro_alloc_empty_domain() breaks
  Allwinner H6 probe
- [Medium] media: verisilicon: hantro_iommu_restore() runs before reset
  deassert
- [Medium] media: verisilicon: hantro_iommu_restore() misses detach
  re-attach error
- [Medium] media: verisilicon: rockchip_vpu_enc_hw_reset() races with
  IOMMU TLB zaps
--

commit 073ab73b0d27dc2c08cf79b3863b16efe04c5710
Author: Arun Iyengar <aiyengar1990@gmail.com>

media: verisilicon: Reinitialize the IOMMU after resetting an encoder core

This commit allocates an empty IOMMU paging domain at probe and cycles
through it after a Rockchip encoder reset so the IOMMU driver reprograms
the hardware.  If attaching the empty domain fails, further jobs are
refused via vpu->iommu_lost.

> diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
> index 957ed7a59197c..e268858269ff3 100644
> --- a/drivers/media/platform/verisilicon/hantro_drv.c
> +++ b/drivers/media/platform/verisilicon/hantro_drv.c

[ ... ]

> @@ -113,6 +114,31 @@ void hantro_irq_done(struct hantro_dev *vpu,
>  	}
>  }
>  
> +/*
> + * Pulsing the reset lines of a core can reset its IOMMU behind the IOMMU
> + * driver. Attaching and detaching the empty domain makes the driver reprogram
> + * it; the default domain keeps its mappings. A failed attach may leave the
> + * IOMMU without translation, so no further job may run.
> + */
> +int hantro_iommu_restore(struct hantro_dev *vpu)
> +{
> +	int ret;
> +
> +	if (!vpu->empty_domain)
> +		return 0;
> +
> +	ret = iommu_attach_device(vpu->empty_domain, vpu->dev);
> +	if (ret) {
> +		dev_err(vpu->dev, "Failed to reinitialize the IOMMU (%d), refusing further jobs\n",
> +			ret);
> +		vpu->iommu_lost = true;
> +		return ret;
> +	}
> +
> +	iommu_detach_device(vpu->empty_domain, vpu->dev);
> +	return 0;
> +}

[Severity: Medium]
Can iommu_detach_device() silently leave the IOMMU in bypass mode without
setting vpu->iommu_lost?

iommu_detach_device() returns void and re-attaches the default DMA domain
via __iommu_group_set_domain_nofail() -> rk_iommu_attach_device().  If
rk_iommu_enable() fails on that re-attach, rockchip-iommu reverts
iommu->domain to rk_identity_domain and __iommu_group_set_domain_nofail()
only logs a WARN_ON and discards the error.

Once reverted to rk_identity_domain, rk_iommu_resume() never re-enables
paging.  With vpu->iommu_lost still false, subsequent VPU jobs continue
issuing DMA using IOVAs as raw physical addresses.

[ ... ]

> @@ -1121,6 +1150,42 @@ static void hantro_disable_runtime_pm(struct hantro_dev *vpu)
>  	}
>  }
>  
> +static void hantro_free_empty_domain(void *data)
> +{
> +	iommu_domain_free(data);
> +}
> +
> +static int hantro_alloc_empty_domain(struct hantro_dev *vpu)
> +{
> +	struct iommu_domain *domain;
> +	int ret;
> +
> +	/*
> +	 * Only needed if the core can be reset, and only possible with a DMA
> +	 * domain to return to.
> +	 */
> +	if (!vpu->resets)
> +		return 0;
> +
> +	domain = iommu_get_domain_for_dev(vpu->dev);
> +	if (!domain || !iommu_is_dma_domain(domain))
> +		return 0;
> +
> +	domain = iommu_paging_domain_alloc(vpu->dev);
> +	if (IS_ERR(domain))
> +		return PTR_ERR(domain);
> +
> +	vpu->empty_domain = domain;
> +
> +	ret = devm_add_action_or_reset(vpu->dev, hantro_free_empty_domain,
> +				       domain);
> +	if (ret)
> +		return ret;
> +
> +	/* A failed restore before a rebind can have left the IOMMU in bypass. */
> +	return hantro_iommu_restore(vpu);
> +}

[Severity: High]
Does hantro_alloc_empty_domain() break hantro_probe() on Allwinner H6?

In sun50i-h6.dtsi, video-codec-g2 has both resets and iommus = <&iommu 5>,
sharing sun50i-iommu with mixer0 and video-codec.  Because sun50i-iommu
uses generic_single_device_group, iommu_attach_device() fails with -EINVAL
on the multi-device group and aborts probe.

Even if the VPU were alone in the group, sun50i-iommu initializes
sun50i_domain->refcnt to 1 and never drops it to 0 on detach, leaking DMA
mappings and clock enable counts.  Since sunxi_vpu_reset() never calls
hantro_iommu_restore(), this should only run on variants that use it.

> @@ -1172,6 +1237,10 @@ static int hantro_probe(struct platform_device *pdev)
>  	if (IS_ERR(vpu->resets))
>  		return PTR_ERR(vpu->resets);
>  
> +	ret = hantro_alloc_empty_domain(vpu);
> +	if (ret)
> +		return ret;
> +
>  	vpu->reg_base = devm_platform_ioremap_resource(pdev, 0);
>  	if (IS_ERR(vpu->reg_base))
>  		return PTR_ERR(vpu->reg_base);

[Severity: Medium]
Can hantro_alloc_empty_domain() touch IOMMU registers while shared reset
lines are still asserted?

reset_control_deassert(vpu->resets) does not run until much later in
hantro_probe().  On platforms whose VPU bus-interface resets also reset
the IOMMU (such as RK3588 AV1 with vsi-iommu, or RK3588 VEPU121 on rebind
after a failed reset deassert), hantro_iommu_restore() can issue IOMMU
MMIO writes while the hardware is still in reset.

On vsi-iommu, vsi_iommu_attach_device() unconditionally resumes the IOMMU
and writes VSI_MMU_FLUSH_BASE, which can cause an SError panic; on an
active rockchip-iommu, rk_iommu_enable() can stall or time out and fail
probe.  Moving this call after reset_control_deassert() avoids the hazard.

[ ... ]

> diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> index 2ec25d6dac866..02fcd74e5ee0b 100644
> --- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> +++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> @@ -491,8 +491,12 @@ static void rockchip_vpu_enc_hw_reset(struct hantro_dev *vpu)
>  	udelay(5);
>  
>  	ret = reset_control_deassert(vpu->resets);
> -	if (ret)
> +	if (ret) {
>  		dev_err(vpu->dev, "Failed to deassert resets: %d\n", ret);
> +		return;
> +	}
> +
> +	hantro_iommu_restore(vpu);
>  }

[Severity: Medium]
Can rockchip_vpu_enc_hw_reset() race with concurrent IOMMU TLB zaps while
vpu->resets is asserted?

hantro_watchdog() runs without vpu->vpu_mutex while the timed-out job
still holds the runtime PM reference keeping the linked IOMMU active.
While the IOMMU stays attached to the default DMA domain, another V4L2
context freeing or mapping buffers can zap TLBs during the reset:

CPU0 (hantro_watchdog)             CPU1 (other V4L2 context)
rockchip_vpu_enc_hw_reset()
  reset_control_assert(vpu->resets)
                                   vb2_dc_put() -> dma_free_attrs()
                                     rk_iommu_unmap() -> rk_iommu_zap_iova()
                                       pm_runtime_get_if_in_use(iommu->dev)
                                       rk_iommu_zap_lines()
                                         writel(..., RK_MMU_ZAP_ONE_LINE)
                                         <-- MMIO while IOMMU in reset
  udelay(5)
  reset_control_deassert(vpu->resets)
  hantro_iommu_restore(vpu)

On SoCs where vpu->resets also resets the co-located IOMMU bus interface
(such as RK3588 VEPU121), an MMIO write during reset can trigger an
unrecoverable SError panic or hang the IOMMU.

Additionally, when hantro_iommu_restore() re-attaches the default domain,
rk_iommu_attach_device() adds iommu->node back to rk_domain->iommus before
rk_iommu_enable() finishes, exposing rk_iommu_force_reset() and DTE
programming to concurrent zaps as well.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261206-hantro-robust-v4-0-b99d33a5ec6d@gmail.com?part=9

  reply	other threads:[~2026-12-06  6:21 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-06  5:57 [PATCH v4 00/18] media: verisilicon: Recover the Rockchip VPUs from faults and timeouts Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 01/18] dt-bindings: media: rockchip,rk3568-vepu: Add the reset lines Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 02/18] media: verisilicon: Check the match data in hantro_probe() Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 03/18] media: verisilicon: Complete the request when the VPU can't resume Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 04/18] media: verisilicon: Copy the buffer metadata before a job can fail Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 05/18] media: verisilicon: Don't hold the VPU in reset after remove Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 06/18] media: verisilicon: Disable runtime PM before unpreparing the clocks on probe failure Arun Iyengar via B4 Relay
2026-12-06  6:11   ` sashiko-bot
2026-12-06  5:57 ` [PATCH v4 07/18] media: verisilicon: Enable the Rockchip encoder interrupt again after a reset Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 08/18] media: verisilicon: Reset the Rockchip encoder cores on timeout Arun Iyengar via B4 Relay
2026-12-06  6:23   ` sashiko-bot
2026-12-06  5:57 ` [PATCH v4 09/18] media: verisilicon: Reinitialize the IOMMU after resetting an encoder core Arun Iyengar via B4 Relay
2026-12-06  6:21   ` sashiko-bot [this message]
2026-12-06  5:57 ` [PATCH v4 10/18] media: verisilicon: Acquire the reset lines only while using them Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 11/18] dt-bindings: iommu: verisilicon: Add the reset lines Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 12/18] iommu/vsi: Deassert the reset lines on probe Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 13/18] arm64: dts: rockchip: Add the reset lines of the RK3588 VEPU121 cores Arun Iyengar via B4 Relay
2026-12-06  6:26   ` sashiko-bot
2026-12-06  5:57 ` [PATCH v4 14/18] arm64: dts: rockchip: Add the reset lines of the RK3588 AV1 IOMMU Arun Iyengar via B4 Relay
2026-12-06  6:21   ` sashiko-bot
2026-12-06  5:57 ` [PATCH v4 15/18] pmdomain: rockchip: Add rockchip_pmu_idle_reset() Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 16/18] dt-bindings: media: rockchip-vpu: Add reset-names Arun Iyengar via B4 Relay
2026-12-06  5:57 ` [PATCH v4 17/18] media: verisilicon: Reset the RK3588 AV1 decoder after an error Arun Iyengar via B4 Relay
2026-12-06  6:32   ` sashiko-bot
2026-12-06  5:57 ` [PATCH v4 18/18] arm64: dts: rockchip: Name the RK3588 AV1 decoder resets Arun Iyengar via B4 Relay

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-252218@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=aiyengar1990@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=media-ci@linuxtv.org \
    --cc=robh@kernel.org \
    --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