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 08/18] media: verisilicon: Reset the Rockchip encoder cores on timeout
Date: Sun, 06 Dec 2026 06:23:12 +0000	[thread overview]
Message-ID: <sashiko-outbox-252220@kernel.org> (raw)
In-Reply-To: <20261206-hantro-robust-v4-8-b99d33a5ec6d@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] media: verisilicon: rockchip_vpu_enc_hw_reset() races with VEPU
  IRQ MMIO
- [High] media: verisilicon: IOMMU MMIO race during
  rockchip_vpu_enc_hw_reset()
--

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

media: verisilicon: Reset the Rockchip encoder cores on timeout

This commit adds a rockchip_vpu_enc_hw_reset() helper that pulses the
optional reset lines for 5 us and calls it from the Rockchip VEPU1 and
VEPU2 timeout reset handlers.

> diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> index d54ba36d44495..2ec25d6dac866 100644
> --- a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c
> +++ b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c

[ ... ]

> @@ -469,6 +470,31 @@ static void rk3066_vpu_dec_reset(struct hantro_ctx *ctx)
>  	vdpu_write(vpu, G1_REG_CONFIG_DEC_CLK_GATE_E, G1_REG_CONFIG);
>  }
>  
> +/*
> + * A core stuck on the bus, e.g. after an IOMMU fault, can't be stopped
> + * through its registers and keeps the IOMMU from stalling. Pulse its reset
> + * lines, if any.
> + */
> +static void rockchip_vpu_enc_hw_reset(struct hantro_dev *vpu)
> +{
> +	int ret;
> +
> +	if (!vpu->resets)
> +		return;
> +
> +	ret = reset_control_assert(vpu->resets);
> +	if (ret) {
> +		dev_warn(vpu->dev, "Failed to assert resets: %d\n", ret);
> +		return;
> +	}
> +
> +	udelay(5);
> +
> +	ret = reset_control_deassert(vpu->resets);
> +	if (ret)
> +		dev_err(vpu->dev, "Failed to deassert resets: %d\n", ret);
> +}

[Severity: High]
Can concurrent IOMMU MMIO accesses race with asserting vpu->resets on
RK3588?

On RK3588, the VEPU121 encoder cores share their AHB/AXI reset lines with
the paired Rockchip IOMMU.  When hantro_watchdog() runs, the timed-out job
still holds the runtime PM reference on vpu->dev (and via the device link
on iommu->dev), vpu->dev stays attached to its default DMA domain, and
vpu->vpu_mutex is not held.

CPU0 (kworker)                  CPU1 (other V4L2 context)
hantro_watchdog()
  rockchip_vpu2_enc_reset()
    rockchip_vpu_enc_hw_reset()
      reset_control_assert(...)
                                VIDIOC_QBUF / VIDIOC_REQBUFS
                                  rk_iommu_map()
                                    rk_iommu_zap_iova()
                                      rk_iommu_zap_lines() <-- MMIO in reset
      udelay(5)
      reset_control_deassert(...)

rk_iommu_zap_iova() sees pm_runtime_get_if_in_use(iommu->dev) succeed and
writes RK_MMU_ZAP_ONE_LINE while the shared reset is asserted;
rk_iommu_irq() can also read and write IOMMU registers under the same
check.  MMIO accesses to a block held in reset can hang the bus or trigger
a fatal SError on RK3588.

[ ... ]

> @@ -476,6 +502,7 @@ static void rockchip_vpu1_enc_reset(struct hantro_ctx *ctx)
>  	vepu_write(vpu, H1_REG_INTERRUPT_DIS_BIT, H1_REG_INTERRUPT);
>  	vepu_write(vpu, 0, H1_REG_ENC_CTRL);
>  	vepu_write(vpu, 0, H1_REG_AXI_CTRL);
> +	rockchip_vpu_enc_hw_reset(vpu);
>  	/* Only the interrupt handler writes this register: enable the interrupt again. */
>  	vepu_write(vpu, 0, H1_REG_INTERRUPT);
>  }

[Severity: High]
Can rockchip_vpu1_vepu_irq() access encoder registers while
rockchip_vpu_enc_hw_reset() holds vpu->resets asserted?

hantro_watchdog() runs in workqueue context with interrupts enabled and no
shared lock, and hantro_irq_done() expects the hard IRQ handler to race
with the watchdog around timeout expiration.  Writing
H1_REG_INTERRUPT_DIS_BIT is a posted MMIO write and does not stop an
already-pending interrupt or an IRQ handler already running on another CPU.

CPU0 (kworker)                  CPU1 (<hardirq>)
hantro_watchdog()
  rockchip_vpu1_enc_reset()
    vepu_write(..., DIS_BIT)
    rockchip_vpu_enc_hw_reset()
      reset_control_assert(...)
                                rockchip_vpu1_vepu_irq()
                                  vepu_read(..., H1_REG_INTERRUPT)
                                    <-- MMIO in reset
      udelay(5)
      reset_control_deassert(...)

The same race applies to rockchip_vpu2_enc_reset() and
rockchip_vpu2_vepu_irq().  MMIO accesses while the AHB/AXI reset lines are
asserted can hang the bus or trigger a fatal SError on Rockchip SoCs such
as RK3588; disabling or synchronizing the encoder IRQ before asserting
vpu->resets would avoid this.

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

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