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 17/18] media: verisilicon: Reset the RK3588 AV1 decoder after an error
Date: Sun, 06 Dec 2026 06:32:50 +0000	[thread overview]
Message-ID: <sashiko-outbox-252224@kernel.org> (raw)
In-Reply-To: <20261206-hantro-robust-v4-17-b99d33a5ec6d@gmail.com>

Thank you for your contribution! Sashiko AI review found 6 potential
issues to consider:
- [High] media: verisilicon: IOMMU park in AV1 reset races with
  vsi-iommu TLB flush
- [High] media: verisilicon: probe IOMMU restore breaks Allwinner H6
  sun50i-iommu
- [Medium] media: verisilicon: unsynchronized vsi_iommu_irq() during AV1
  bus idle reset
- [Medium] media: verisilicon: AV1 IRQ left masked after non-ETIMEDOUT
  reset failure
- [Medium] media: verisilicon: autosuspend disables AV1 IOMMU on fatal
  reset failure
- [Medium] media: verisilicon: hantro_irq_done() can cancel queued error
  reset
--

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

media: verisilicon: Reset the RK3588 AV1 decoder after an error

This commit adds error and timeout reset handling for the RK3588 AV1
decoder using rockchip_pmu_idle_reset() and parks the IOMMU on an empty
domain during the reset.

> diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c
> index 26b273cd339d0..bb611b414e75d 100644
> --- a/drivers/media/platform/verisilicon/hantro_drv.c
> +++ b/drivers/media/platform/verisilicon/hantro_drv.c

[ ... ]

> @@ -132,29 +134,55 @@ int hantro_iommu_restore(struct hantro_dev *vpu)

[ ... ]

> +/* For a failed job whose core needs a reset: the watchdog work resets it and ends the job. */
> +void hantro_irq_reset(struct hantro_dev *vpu)
> +{
> +	if (cancel_delayed_work(&vpu->watchdog_work)) {
> +		vpu->error_reset = true;
> +		schedule_delayed_work(&vpu->watchdog_work, 0);
> +	}
> +}

[Severity: Medium]
Can hantro_irq_done() cancel a queued error reset if a second interrupt
arrives before hantro_watchdog() starts?

rk3588_vpu981_irq() clears AV1_REG_INTERRUPT to 0 without setting
AV1_REG_INTERRUPT_DEC_IRQ_DIS, and hantro_irq_reset() re-arms
vpu->watchdog_work into the pending state.  If a DEC_RDY_INT interrupt
arrives before a kworker dequeues watchdog_work, hantro_irq_done() calls
cancel_delayed_work(&vpu->watchdog_work) without checking
vpu->error_reset.

That drops rockchip_vpu981_av1_dec_reset(), finishes the errored job as
VB2_BUF_STATE_DONE (running hantro_av1_update_prob() on errored state),
and leaves vpu->error_reset true until a later timeout suppresses its
timeout log.  Checking vpu->error_reset in hantro_irq_done() or using a
separate work item for error resets would avoid this.

[ ... ]

> @@ -1178,7 +1211,7 @@ static int hantro_alloc_empty_domain(struct hantro_dev *vpu)
>  	vpu->empty_domain = domain;
>  
>  	ret = devm_add_action_or_reset(vpu->dev, hantro_free_empty_domain,
> -				       domain);
> +				       vpu);
>  	if (ret)
>  		return ret;

[Severity: High]
Does the unconditional hantro_iommu_restore() call at the end of
hantro_alloc_empty_domain() break probing on Allwinner H6?

In arch/arm64/boot/dts/allwinner/sun50i-h6.dtsi, video-codec-g2@1c00000
(sunxi_vpu_variant) has both resets and a DMA domain on sun50i-iommu, so
hantro_alloc_empty_domain() (added in commit "media: verisilicon:
Reinitialize the IOMMU after resetting an encoder core") calls
hantro_iommu_restore() -> iommu_attach_device() during probe.

Because sun50i-iommu uses generic_single_device_group, video-codec-g2
shares its IOMMU group with mixer0 and video-codec@1c0e000, so
iommu_attach_device() fails list_count_nodes(&group->devices) != 1 and
hantro_probe() fails with -EINVAL.  Even with a single device in the
group, sun50i_iommu_attach_device() increments sun50i_domain->refcnt
(initialized to 1), preventing sun50i_iommu_detach_domain() from running
during domain swaps and leaking DMA mappings and clock references.

> diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> index f04d3cc0c1a85..6bb85ccbf4601 100644
> --- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> +++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c

[ ... ]

> @@ -540,6 +555,73 @@ static void rockchip_vpu2_enc_reset(struct hantro_ctx *ctx)

[ ... ]

> +	status = vdpu_read(vpu, AV1_REG_INTERRUPT);
> +	if (status & AV1_REG_INTERRUPT_DEC_E) {
> +		vdpu_write(vpu, status | AV1_REG_INTERRUPT_DEC_ABORT_E |
> +			   AV1_REG_INTERRUPT_DEC_IRQ_DIS, AV1_REG_INTERRUPT);
> +		if (readl_poll_timeout(vpu->dec_base + AV1_REG_INTERRUPT, status,
> +				       !(status & AV1_REG_INTERRUPT_DEC_E), 100, 100000)) {
> +			dev_err(vpu->dev, "The core does not stop, refusing further jobs\n");
> +			hantro_iommu_park(vpu);
> +			vpu->iommu_lost = true;
> +			goto release;
> +		}
> +	}
> +
> +	if (hantro_iommu_park(vpu))
> +		goto out;

[Severity: High]
Can hantro_iommu_park() race with concurrent DMA maps or unmaps on
another decoder context in vsi-iommu?

CPU0 (kworker)                    CPU1 (other decoder context)
rockchip_vpu981_av1_dec_reset()   vsi_iommu_unmap()
  hantro_iommu_park()               spin_lock(&default_domain->lock)
    vsi_iommu_attach_device()       vsi_iommu_flush_tlb(default_domain)
      spin_lock(&empty->lock)         list_for_each_entry(iommu, ...)
      spin_lock(&iommu->lock)           pm_runtime_get(iommu->dev)
      list_del_init(&iommu->node)
      list_add_tail(&iommu->node,
                    &empty->iommus)
      spin_unlock(&iommu->lock)
  rockchip_pmu_idle_reset()             spin_lock(&iommu->lock)
    [bus stopped]                       writel(..., VSI_MMU_FLUSH_BASE)
                                          <-- write on stopped bus
                                      list_next_entry(iommu, node)
                                        <-- walks onto &empty->iommus

vsi_iommu_attach_device() ignores the old domain parameter and never
takes default_domain->lock, while vsi_iommu_flush_tlb() iterates
default_domain->iommus and drops iommu->lock around pm_runtime_get() and
pm_runtime_put_autosuspend().

Moving iommu->node onto empty_domain->iommus mid-loop makes
list_for_each_entry() miss the &default_domain->iommus sentinel and
compute an out-of-bounds container_of() pointer before empty_domain,
corrupting adjacent slab memory.  Because vsi_iommu_attach_device() also
leaves iommu->enable set, an in-flight vsi_iommu_flush_tlb() can still
write VSI_MMU_FLUSH_BASE after rockchip_pmu_idle_reset() stops the
RK3588_PD_AV1 bus, raising an SError.

> +	ret = rockchip_pmu_idle_reset(vpu->dev, rockchip_vpu981_core_reset, vpu);

[Severity: Medium]
Can vsi_iommu_irq() still access av1d_mmu registers while
rockchip_pmu_idle_reset() has the RK3588_PD_AV1 bus stopped?

av1d_mmu shares RK3588_PD_AV1 with av1d but uses a separate interrupt
(GIC_SPI 109).  rockchip_vpu981_av1_dec_reset() only disables av1d's IRQ,
and hantro_iommu_park() does not clear VSI_MMU_STATUS_BASE or synchronize
av1d_mmu's IRQ.

If a failing decode raises an IOMMU page fault right before
AV1_REG_INTERRUPT_DEC_E clears, vsi_iommu_irq() on another CPU can pass
pm_runtime_resume_and_get(), take iommu->lock after
vsi_iommu_attach_device() drops it, and read/write VSI_MMU_STATUS_BASE on
the stopped bus, causing the idle handshake to time out or raising an
SError.

> +	if (ret) {
> +		dev_err(vpu->dev, "Failed to reset the core: %d\n", ret);
> +		/* Bus state unknown: keep the IOMMU and the handler off it. */
> +		if (ret == -ETIMEDOUT) {
> +			vpu->iommu_lost = true;
> +			goto release;
> +		}
> +	}

[Severity: Medium]
Does runtime PM autosuspend still call vsi_iommu_suspend() after either
fatal failure path sets vpu->iommu_lost = true?

After rockchip_vpu981_av1_dec_reset() returns on the -ETIMEDOUT or
core-did-not-stop path, hantro_watchdog() calls hantro_job_finish() ->
pm_runtime_put_autosuspend(vpu->dev).  Once av1d suspends, its runtime PM
device link drops av1d_mmu's reference and vsi_iommu_suspend() calls
vsi_iommu_disable(), writing 0 to VSI_MMU_AHB_CONTROL_BASE before gating
the shared ACLK_AV1 and PCLK_AV1 clocks.

On the -ETIMEDOUT path, that MMIO write hits the unknown-state bus and
can raise an SError; on the core-did-not-stop path, it disables IOMMU
translation while the unstopped core is still clocked.  Holding a runtime
PM reference on these fatal paths would keep av1d_mmu from autosuspending.

> +	hantro_iommu_unpark(vpu);
> +out:
> +	enable_irq(irq);

[Severity: Medium]
Is AV1_REG_INTERRUPT_DEC_IRQ_DIS left set in hardware if
rockchip_pmu_idle_reset() fails with an error other than -ETIMEDOUT?

When a timeout aborts a running core, AV1_REG_INTERRUPT_DEC_IRQ_DIS is
written to AV1_REG_INTERRUPT.  If rockchip_pmu_idle_reset() then returns
a non-ETIMEDOUT error (for example -EOPNOTSUPP when
CONFIG_ROCKCHIP_PM_DOMAINS is disabled), the core is not reset and
vpu->iommu_lost stays false, yet AV1_REG_INTERRUPT is never cleared.

Because rockchip_vpu981_av1_dec_run() only updates bits 0, 5, and 7 via
hantro_reg_write(), bit 4 stays latched and every subsequent AV1 job
times out until the power domain is power-cycled.

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

  reply	other threads:[~2026-12-06  6:32 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
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 [this message]
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-252224@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