media: verisilicon: Recover the Rockchip VPUs from faults and timeouts
Subsystems (5)
v2 cover media: verisilicon: Recover the Rockchip VPUs from faults and timeouts
This series makes the Hantro driver recover from a job that times out on the Rockchip VPUs, and stops it from holding a VPU in reset after remove.
On the RK3588, a VEPU121 JPEG encoder core that reads an unmapped IOVA faults in its IOMMU and never becomes idle again: the register-level stop in the encoder reset operation isn't enough, the IOMMU can't be stalled anymore ("Enable stall request timed out"), every later job times out and unbinding the driver can lock up the system. Patch 4 pulses the reset lines of the core on a timeout, and patch 5 reinitializes the IOMMU afterwards the way rkvdec does. Patches 1 and 6 describe the AXI/AHB reset lines of the four VEPU121 cores in the binding and in the RK3588 device tree; the driver already handles optional resets, so device trees without them keep working.
Patch 3 clears the encoder interrupt register at the end of the reset
operation: only the interrupt handler ever clears it, so after a reset that skipped the handler (a timeout) the interrupt stays disabled and every later job on the core times out. On a core with reset lines the reset pulse of patch 4 also clears it, but a VEPU1/VEPU2 core without them (the older SoCs) relies on this.
Patch 2 stops asserting the resets on remove and on the probe error
path: the AV1 decoder resets of the RK3588 also cover the bus interface of its IOMMU, and holding them asserted while the IOMMU driver runtime-suspends hits registers in reset (SError).
Patch 2 leaves the rest of hantro_remove() alone. Since 556ab0b2741d ("media: hantro: release runtime resources when device_run fails"), the runtime suspend that hantro_remove() triggers runs after the driver data was cleared and the clocks were unprepared. "media: verisilicon: suspend the device before unregistering it on remove" from Sergei Khomenkov [1] fixes that. Patch 2 doesn't depend on it, but both change the last lines of hantro_remove(), so the one that is applied second needs a trivial context update.
Patch 6 touches arch/arm64 only and can go through the Rockchip tree independently of the driver patches; it is only useful together with patches 4 and 5.
Tested on an Orange Pi 5 (RK3588S) with the series on a v7.3 based kernel with other out-of-tree Hantro patches, which has neither 556ab0b2741d nor 8e26d4c20ed2 ("media: hantro: disable runtime PM before hardware teardown"), so its hantro_remove() still asserted the resets before the runtime PM teardown. On v7.4-rc1 the series is only build-tested, and I haven't run the unbind path there. The results below are from v1. Unbinding and rebinding the driver with the AV1 decoder bound and a 1 s gap hit the SError before patch 2 and was clean with it. The reset and the IOMMU restore ran on every encoder timeout: a trace of a wedged VEPU121 job shows hantro_watchdog() -> rockchip_vpu2_enc_reset() -> the IOMMU re-attach with no stall or paging timeout, the next jobs on the same core succeed, and the IOMMU runtime-suspends cleanly afterwards; ten JPEG encode jobs with an unmapped input address were each reset by the timeout and the following jobs encoded normally. The reset lines of patches 1 and 6 are present on all four VEPU121 nodes of the live device tree; dt_binding_check and CHECK_DTBS are clean.
The v2 recovery was reorganized from v1 (the IOMMU restore now runs from the encoder hardware reset, the interrupt re-enable is its own patch, the remove path no longer asserts the resets), so it was tested again on the board with v2, on the same v7.3 based kernel: a provoked encoder timeout was reset and the next encode succeeded, a job with an unmapped input address logged an IOMMU page fault, timed out and was recovered the same way, and unbinding and rebinding the driver gave no WARN, BUG or Oops (on that kernel the unbind runs through the out-of-tree teardown).
This series was developed with Claude (Anthropic) as a coding assistant:
it wrote the code and the commit messages, and I reviewed and tested every change as described above.
[1] https://lore.kernel.org/r/[email protected]
---
Changes in v2:
- Patch 2: don't assert the resets on remove or on the probe error path
at all, rather than only for a device behind an IOMMU; the AV1 BIU
resets must not be asserted while the device is not IOMMU-mapped
either (Sashiko). The hantro_reset_assert() helper is gone, and the subject changed with it
- New patch 3: clear the encoder interrupt register at the end of the VEPU1/VEPU2 reset, so a core without reset lines re-enables its
interrupt after a timeout (Sashiko: the H1/VEPU2 reset left the interrupt-disable bit set)
- Patch 5 (was patch 4), IOMMU restore redesigned after the Sashiko
review of the restore path, with a new subject:
- run it from the Rockchip encoder hardware reset, right after the
reset pulse, where the core is known idle, not generically from the watchdog (Sashiko: the watchdog restored the IOMMU without stopping
an AV1 core). It no longer runs on the AV1 decoder and its
vsi-iommu, where Sashiko found a race with concurrent mappings, nor
on the Allwinner H6; rockchip-iommu changes and walks the IOMMU list
of a domain under its iommus_lock
- only with reset lines and a DMA default domain to return to, via iommu_is_dma_domain(); not with an identity or ARM32 dma-iommu
domain (Sashiko: unconditional domain swap, -EBUSY on ARM32, check iommu_is_dma_domain() in hantro_alloc_empty_domain())
- on a failed attach, mark the core so every later job is refused
rather than running through a bypassed IOMMU (Sashiko: a failed
attach left the IOMMU detached)
- Patch 6 (was patch 5): the commit message follows the new subject of patch 2
- Patches 1 and 4 (was patch 3), the bindings and the timeout reset, unchanged
- Not addressed: the NULL match->data dereference in hantro_probe() that Sashiko reported on patch 2 as a pre-existing issue (a forced bind to
a device without a matching OF node); it is independent of this series
- Link to v1: https://patch.msgid.link/[email protected]
---
Arun Iyengar (6):
dt-bindings: media: rockchip,rk3568-vepu: Add the reset lines
media: verisilicon: Don't hold the VPU in reset after remove
media: verisilicon: Enable the Rockchip encoder interrupt again after a reset
media: verisilicon: Reset the Rockchip encoder cores on timeout
media: verisilicon: Reinitialize the IOMMU after resetting an encoder core
arm64: dts: rockchip: Add the reset lines of the RK3588 VEPU121 cores
.../bindings/media/rockchip,rk3568-vepu.yaml | 10 +++ arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 8 +++ drivers/media/platform/verisilicon/hantro.h | 5 ++ drivers/media/platform/verisilicon/hantro_drv.c | 81 ++++++++++++++++++++-- drivers/media/platform/verisilicon/hantro_hw.h | 1 + .../media/platform/verisilicon/rockchip_vpu_hw.c | 46 ++++++++++++ 6 files changed, 144 insertions(+), 7 deletions(-)
---
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4
change-id: 20261110-hantro-robust-6a6c84febb06
Best regards,
Signature · 1 line
Arun Iyengar <[email protected]>
PATCH v2 1/6 dt-bindings: media: rockchip,rk3568-vepu: Add the reset lines
The VEPU121 encoder cores of the RK3588 each have their own AXI and AHB reset lines in the CRU (SRST_A_JPEG_ENCODERx and SRST_H_JPEG_ENCODERx). They are needed to recover a core that is stuck on the bus, which its registers can't stop.
Describe them as optional, so that existing device trees stay valid.
--- .../devicetree/bindings/media/rockchip,rk3568-vepu.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/media/rockchip,rk3568-vepu.yaml +10 -0
@@ -32,6 +32,16 @@ properties: - const: aclk - const: hclk + resets: + items: + - description: AXI reset line + - description: AHB reset line + + reset-names: + items: + - const: axi + - const: ahb + power-domains: maxItems: 1
Signature · 1 line
2.55.0
Re: [PATCH v2 1/6] dt-bindings: media: rockchip,rk3568-vepu: Add the reset lines
Quoted 11 lines · Arun Iyengar
The VEPU121 encoder cores of the RK3588 each have their own AXI and AHB reset lines in the CRU (
SRST_A_JPEG_ENCODERxandSRST_H_JPEG_ENCODERx). They are needed to recover a core that is stuck on the bus, which its registers can't stop.Describe them as optional, so that existing device trees stay valid.
Signed-off-by Arun Iyengar <[email protected]>--- .../devicetree/bindings/media/rockchip,rk3568-vepu.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+)
Best regards,
Krzysztof
PATCH v2 2/6 media: verisilicon: Don't hold the VPU in reset after remove
In reply to Arun IyengarOn the RK3588, the resets of the AV1 decoder include the AXI and APB bus interface resets (SRST_A_AV1_BIU, SRST_P_AV1_BIU), which also cover the Verisilicon IOMMU of the decoder. When the driver is unbound, the driver core runtime resumes the device and, through the runtime PM device link, its IOMMU. hantro_remove() then asserts the resets, and when the IOMMU autosuspends 100 ms later, vsi_iommu_suspend() writes to its registers while they are held in reset, which raises an SError and panics the system:
SError Interrupt on CPU4, code 0x00000000be000411 -- SError
Workqueue: pm pm_runtime_work Call trace: clk_disable+0x30/0x90 (P) clk_bulk_disable+0x44/0x90 vsi_iommu_suspend+0x4c/0xc8 [vsi_iommu] pm_generic_runtime_suspend+0x38/0x80 genpd_runtime_suspend+0xc4/0x348 ... Kernel panic - not syncing: Asynchronous SError Interrupt
This was hit when reloading the module, unless the decoder happened to be probed again within the autosuspend delay of its IOMMU.
The IOMMU is not the only one to access the bus interface after remove. Commit 8e26d4c20ed2 ("media: hantro: disable runtime PM before hardware teardown") moved the assert after the runtime PM teardown because the power domain code faulted on it when powering the domain off. With the resets left asserted, the same domain code runs again when the domain is powered on for the next bind, before hantro_probe() deasserts the resets, and when the domain is powered off after a failed probe.
A runtime suspended VPU has its resets deasserted and its clocks off. Leave it in that state on remove and on the probe error path instead of asserting the resets; hantro_probe() deasserts them anyway.
--- drivers/media/platform/verisilicon/hantro_drv.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/media/platform/verisilicon/hantro_drv.c +1 -7
@@ -1210,7 +1210,7 @@ static int hantro_probe(struct platform_device *pdev) ret =clk_bulk_prepare (vpu->variant->num_clocks, vpu->clocks);if (ret) {dev_err (&pdev->dev,"Failed to prepare clocks\n" ); - goto err_pm_disable_assert_reset; + goto err_pm_disable; } ret =v4l2_device_register (&pdev->dev, &vpu->v4l2_dev);
@@ -1264,11 +1264,6 @@ static int hantro_probe(struct platform_device *pdev)v4l2_device_unregister (&vpu->v4l2_dev); err_clk_unprepare:clk_bulk_unprepare (vpu->variant->num_clocks, vpu->clocks); -err_pm_disable_assert_reset: -pm_runtime_dont_use_autosuspend (vpu->dev); -pm_runtime_disable (vpu->dev); -reset_control_assert (vpu->resets); -return ret; err_pm_disable:pm_runtime_dont_use_autosuspend (vpu->dev);pm_runtime_disable (vpu->dev);
@@ -1290,7 +1285,6 @@ static void hantro_remove(struct platform_device *pdev)clk_bulk_unprepare (vpu->variant->num_clocks, vpu->clocks);pm_runtime_dont_use_autosuspend (vpu->dev);pm_runtime_disable (vpu->dev); -reset_control_assert (vpu->resets); }static int hantro_runtime_resume (struct device *dev)
Signature · 1 line
2.55.0
Philipp Zabel
maintainerRe: [PATCH v2 2/6] media: verisilicon: Don't hold the VPU in reset after remove
Quoted 10 lines · On Do, 2026-11-12 at 08:30 +0000, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
On the RK3588, the resets of the AV1 decoder include the AXI and APB bus interface resets (
SRST_A_AV1_BIU,SRST_P_AV1_BIU), which also cover the Verisilicon IOMMU of the decoder. When the driver is unbound, the driver core runtime resumes the device and, through the runtime PM device link, its IOMMU.hantro_remove()then asserts the resets, and when the IOMMU autosuspends 100 ms later,vsi_iommu_suspend()writes to its registers while they are held in reset, which raises an SError and panics the system:
If vsi-iommu accesses require these bus interface resets to be deasserted at certain points, why doesn't it request its own reset controls?
Depending on implicit assumptions like another driver not asserting its exclusively controlled resets seems fragile.
regards
Philipp
Benjamin Gaignard
maintainerRe: [PATCH v2 2/6] media: verisilicon: Don't hold the VPU in reset after remove
Le 12/11/2026 à 11:19, Philipp Zabel a écrit :
Quoted 11 lines · On Do, 2026-11-12 at 08:30 +0000, Arun Iyengar via B4 Relay wrote:
Quoted 10 lines
From: Arun Iyengar <[email protected]>
On the RK3588, the resets of the AV1 decoder include the AXI and APB bus interface resets (
SRST_A_AV1_BIU,SRST_P_AV1_BIU), which also cover the Verisilicon IOMMU of the decoder. When the driver is unbound, the driver core runtime resumes the device and, through the runtime PM device link, its IOMMU.hantro_remove()then asserts the resets, and when the IOMMU autosuspends 100 ms later,vsi_iommu_suspend()writes to its registers while they are held in reset, which raises an SError and panics the system:
Quoted 6 lines
If vsi-iommu accesses require these bus interface resets to be deasserted at certain points, why doesn't it request its own reset controls?
Depending on implicit assumptions like another driver not asserting its exclusively controlled resets seems fragile.
There is a side note on IOMMU doc saying that once the IOMMU has been enabled it can't be disabled for security reasons.
That means that writing 0 on VSI_MMU_AHB_CONTROL_BASE register in vsi_iommu_disable() could raise an SError so I would suggest to remove this line from IOMMU driver.
Regards,
Benjamin
Quoted 3 lines
regards
Philipp
_______________________________________________
Linux-rockchip mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-rockchip
Re: [PATCH v2 2/6] media: verisilicon: Don't hold the VPU in reset after remove
Quoted 7 lines · Philipp Zabel
Quoted 6 lines
If vsi-iommu accesses require these bus interface resets to be deasserted at certain points, why doesn't it request its own reset controls?
Depending on implicit assumptions like another driver not asserting its exclusively controlled resets seems fragile.
The AV1 node lists these resets for hantro only. vsi-iommu would need them in its own node and binding, and both drivers would have to move to shared reset controls. Device trees without them would still hit the SError. With this patch hantro never asserts the AV1 resets, so vsi-iommu no longer depends on what hantro does with them.
Quoted 4 lines
There is a side note on IOMMU doc saying that once the IOMMU has been enabled it can't be disabled for security reasons.
That means that writing 0 onVSI_MMU_AHB_CONTROL_BASEregister invsi_iommu_disable()could raise an SError so I would suggest to remove this line from IOMMU driver.
I only see the SError after hantro_remove() has asserted the BIU resets. vsi_iommu_suspend() does the same write on every autosuspend in normal use, and that has not faulted here.
I don't think dropping the write is enough on its own. With the resets still asserted, the AV1 domain is powered off when the IOMMU suspends, which is the fault 8e26d4c20ed2 fixed for hantro's own suspend. The next bind then resumes the IOMMU, and vsi_iommu_enable() writes its registers, before hantro_probe() deasserts the resets. I have not tested that.
If you would like the write gone as well, I can send that as a separate vsi-iommu patch.
Arun
Philipp Zabel
maintainerRe: [PATCH v2 2/6] media: verisilicon: Don't hold the VPU in reset after remove
Quoted 10 lines · Arun Iyengar
Quoted 7 lines · Philipp Zabel
Quoted 6 lines
If vsi-iommu accesses require these bus interface resets to be deasserted at certain points, why doesn't it request its own reset controls?
Depending on implicit assumptions like another driver not asserting its exclusively controlled resets seems fragile.
The AV1 node lists these resets for hantro only. vsi-iommu would need them in its own node and binding,
Would that more correctly describe the hardware though?
Quoted 1 line
and both drivers would have to move to shared reset controls.
Worse, shared reset controls don't work if one party temporarily needs full control, for example to issue a reset pulse after timeout. So this likely would require exclusive reset controls with acquire/release.
regards
Philipp
Re: [PATCH v2 2/6] media: verisilicon: Don't hold the VPU in reset after remove
Quoted 1 line
Would that more correctly describe the hardware though?
Yes. The IOMMU is inside the AV1 block and the TRM has no reset for it, only these four. v3 adds them to the vsi-iommu binding and node.
Quoted 2 lines
So this likely would require exclusive reset controls with acquire/release.
v3 does that: both drivers get them as released exclusive controls. vsi-iommu acquires them to deassert on probe, hantro for its probe deassert and for the timeout pulse of the encoder cores. Remove still leaves them deasserted.
v3: https://lore.kernel.org/r/[email protected]
Arun
PATCH v2 3/6 media: verisilicon: Enable the Rockchip encoder interrupt again after a reset
In reply to Arun IyengarThe reset operations of the Rockchip VEPU1 and VEPU2 encoders, which hantro_watchdog() calls when a job times out, disable the encoder interrupt before stopping the encoder. Nothing enables it again: the encoder run functions don't write the interrupt register, only the interrupt handler does, and it no longer runs. Every later job on the encoder then times out as well.
Clear the interrupt register at the end of the reset, as the interrupt handler does after each frame.
--- drivers/media/platform/verisilicon/rockchip_vpu_hw.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/media/platform/verisilicon/rockchip_vpu_hw.c +12 -0
@@ -475,6 +475,12 @@ 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 ); +/* +* The encoder runs don't write the interrupt register, only the +* interrupt handler clears it after each frame. Clear it here too, +* or the interrupt stays disabled and all later jobs time out. +*/ +vepu_write (vpu,0 ,H1_REG_INTERRUPT ); }static void rockchip_vpu2_dec_reset (struct hantro_ctx *ctx)
@@ -493,6 +499,12 @@ static void rockchip_vpu2_enc_reset(struct hantro_ctx *ctx)vepu_write (vpu,VEPU_REG_INTERRUPT_DIS_BIT ,VEPU_REG_INTERRUPT );vepu_write (vpu,0 ,VEPU_REG_ENCODE_START );vepu_write (vpu,0 ,VEPU_REG_AXI_CTRL ); +/* +* The encoder runs don't write the interrupt register, only the +* interrupt handler clears it after each frame. Clear it here too, +* or the interrupt stays disabled and all later jobs time out. +*/ +vepu_write (vpu,0 ,VEPU_REG_INTERRUPT ); }/*
Signature · 1 line
2.55.0
PATCH v2 4/6 media: verisilicon: Reset the Rockchip encoder cores on timeout
In reply to Arun IyengarOn a job timeout, the Rockchip VEPU1 and VEPU2 reset operations mask the interrupt and clear the encode enable and AXI control registers. That only stops a core that is still responsive. On RK3588, when a VEPU121 core reads an IOVA that isn't mapped, the IOMMU reports a page fault and the core never becomes idle again: its AXI transactions stay outstanding, the IOMMU can't be stalled anymore ("Enable stall request timed out", then "Disable paging request timed out" on runtime suspend), every later job times out as well, and unbinding the driver can lock up the system.
The driver already gets the optional reset lines of the device and deasserts them at probe. Pulse them in the encoder reset operations, after stopping the core through its registers, to return it to a clean idle state. The clocks are still enabled at that point, as the job that timed out holds them. This is a no-op on device trees that don't describe the resets, which is the case for all of them so far.
The Rockchip BSP MPP driver resets these cores the same way, through their AXI and AHB reset lines.
--- .../media/platform/verisilicon/rockchip_vpu_hw.c | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+)
drivers/media/platform/verisilicon/rockchip_vpu_hw.c +30 -0
@@ -7,6 +7,7 @@*/ #include <linux/clk.h> +#include <linux/delay.h> #include "hantro.h" #include "hantro_jpeg.h"
@@ -468,6 +469,33 @@ static void rk3066_vpu_dec_reset(struct hantro_ctx *ctx)vdpu_write (vpu,G1_REG_CONFIG_DEC_CLK_GATE_E ,G1_REG_CONFIG ); } +/* +* Stopping the encoder through its registers isn't enough when it is stuck +* on the bus, for instance after a translation fault in its IOMMU: it keeps +* AXI transactions outstanding and never becomes idle, which also prevents +* the IOMMU from stalling. Pulse the reset lines of the core, if the device +* tree describes them, to return it to its idle state. +*/ +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); +} +static void rockchip_vpu1_enc_reset (struct hantro_ctx *ctx) {struct hantro_dev *vpu = ctx->dev;
@@ -475,6 +503,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);/* * The encoder runs don't write the interrupt register, only the * interrupt handler clears it after each frame. Clear it here too,
@@ -499,6 +528,7 @@ static void rockchip_vpu2_enc_reset(struct hantro_ctx *ctx)vepu_write (vpu,VEPU_REG_INTERRUPT_DIS_BIT ,VEPU_REG_INTERRUPT );vepu_write (vpu,0 ,VEPU_REG_ENCODE_START );vepu_write (vpu,0 ,VEPU_REG_AXI_CTRL ); +rockchip_vpu_enc_hw_reset (vpu);/* * The encoder runs don't write the interrupt register, only the * interrupt handler clears it after each frame. Clear it here too,
Signature · 1 line
2.55.0
PATCH v2 5/6 media: verisilicon: Reinitialize the IOMMU after resetting an encoder core
In reply to Arun IyengarA Rockchip encoder core that faulted on an unmapped IOVA leaves its IOMMU with the fault pending, and pulsing the reset lines of the core, as the previous patch does, can leave the IOMMU out of sync with what its driver expects. The IOMMU is only reinitialized when it runtime suspends and resumes, which doesn't happen between back-to-back jobs, so the next jobs can run with a broken IOMMU.
Do like rkvdec: allocate an empty paging domain at probe, and after the reset pulse attach it and detach it again, which returns the device to its default DMA domain. The IOMMU driver reinitializes the IOMMU on each domain change (on Rockchip: stall, force reset, program the directory table and enable paging), and the default domain keeps all the existing mappings. This runs in the watchdog work, right after the core was stopped and reset, while the timed out job still holds the runtime PM reference.
Only do it there, where the core is known to be idle, and only for a device with reset lines whose current domain is a DMA domain, the one the detach returns to: not with an identity domain or with the ARM32 DMA mapping domains. If the attach fails, the IOMMU driver may leave the IOMMU without translation (rockchip-iommu falls back to its identity domain), so refuse all further jobs of the device instead of letting the core access memory with untranslated addresses.
--- drivers/media/platform/verisilicon/hantro.h | 5 ++ drivers/media/platform/verisilicon/hantro_drv.c | 73 ++++++++++++++++++++++ drivers/media/platform/verisilicon/hantro_hw.h | 1 + .../media/platform/verisilicon/rockchip_vpu_hw.c | 6 +- 4 files changed, 84 insertions(+), 1 deletion(-)
drivers/media/platform/verisilicon/hantro.h +5 -0
@@ -193,6 +193,9 @@ hantro_vdev_to_func(struct video_device *vdev)* shared with interrupt handlers. * @variant: Hardware variant-specific parameters. * @watchdog_work: Delayed work for hardware timeout handling. +* @empty_domain: Empty IOMMU domain, used to reinitialize the IOMMU after +* a reset of the core. NULL if not needed. +* @iommu_lost: The IOMMU couldn't be reinitialized, no job can run. */ struct hantro_dev {struct v4l2_device v4l2_dev;
@@ -213,6 +216,8 @@ struct hantro_dev {spinlock_t irqlock;const struct hantro_variant *variant;struct delayed_work watchdog_work; +struct iommu_domain *empty_domain; +bool iommu_lost; };/**
drivers/media/platform/verisilicon/hantro_drv.c +73 -0
103 lines not on this page · raw message
drivers/media/platform/verisilicon/hantro_hw.h +1 -0
@@ -427,6 +427,7 @@ extern const struct hantro_postproc_ops rockchip_vpu981_postproc_ops;extern const u32 hantro_vp8_dec_mc_filter[8 ][6 ];void hantro_watchdog (struct work_struct *work); +void hantro_iommu_restore (struct hantro_dev *vpu);void hantro_irq_done (struct hantro_dev *vpu,enum vb2_buffer_state result);void hantro_start_prepare_run (struct hantro_ctx *ctx);
drivers/media/platform/verisilicon/rockchip_vpu_hw.c +5 -1
@@ -492,8 +492,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); }static void rockchip_vpu1_enc_reset (struct hantro_ctx *ctx)
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 5/6] media: verisilicon: Reinitialize the IOMMU after resetting an encoder core
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] media: verisilicon: missing v4l2_ctrl_request_complete() in device_run() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] media: verisilicon: missing v4l2_ctrl_request_complete() in device_run()
--
commit 9b8b7ddcd6a2f08763d5a6b0f18fb2a01381b678
Author: Arun Iyengar <[email protected]>
media: verisilicon: Reinitialize the IOMMU after resetting an encoder core
This commit allocates an empty IOMMU paging domain at probe and attaches and detaches it after resetting a Rockchip encoder core so the IOMMU is reinitialized, refusing further jobs if the reattachment fails.
Quoted 4 lines
drivers/media/platform/verisilicon/hantro_drv.c +0
-0
[ ... ]
drivers/media/platform/verisilicon/hantro_drv.c static void device_run(void *priv) · line 210
Quoted 8 lines
drivers/media/platform/verisilicon/hantro_drv.c +4
-0@@ -174,6 +204,11 @@ static void device_run(void *priv) src =hantro_get_src_buf (ctx); dst =hantro_get_dst_buf (ctx); +if (unlikely (vpu->iommu_lost)) { +hantro_job_finish_no_pm (ctx,VB2_BUF_STATE_ERROR ); +return ; + }
[Severity: Medium]
Does this leave the control handler's media_request_object incomplete when src was queued with a media_request containing controls?
Normal runs complete the control request object in hantro_end_prepare_run() via v4l2_ctrl_request_complete( src_buf->vb2_buf.req_obj.req, &ctx->ctrl_handler). Returning early via hantro_job_finish_no_pm() calls v4l2_m2m_buf_done_and_job_finish() -> vb2_buffer_done(), which removes src from the m2m queue and clears src->vb2_buf.req_obj.req without completing the control object (as on the adjacent pm_runtime_resume_and_get() error path). The media_request then stays stuck in MEDIA_REQUEST_STATE_QUEUED until the file descriptor is closed.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
PATCH v2 6/6 arm64: dts: rockchip: Add the reset lines of the RK3588 VEPU121 cores
In reply to Arun IyengarDescribe the AXI and AHB reset lines of the four VEPU121 JPEG encoder cores, so that the driver can reset a core that is stuck after a fault of its IOMMU.
The IOMMU of each core sits in the same register block and is clocked by the same clocks, so these resets likely cover its bus interface as well. This relies on the driver not leaving the VPU in reset after remove ("media: verisilicon: Don't hold the VPU in reset after remove").
--- arch/arm64/boot/dts/rockchip/rk3588-base.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm64/boot/dts/rockchip/rk3588-base.dtsi +8 -0
@@ -1325,6 +1325,8 @@ vepu121_0: video-codec@fdba0000 { clock-names = "aclk", "hclk"; iommus = <&vepu121_0_mmu>; power-domains = <&power RK3588_PD_VDPU>; + resets = <&cru SRST_A_JPEG_ENCODER0>, <&cru SRST_H_JPEG_ENCODER0>; + reset-names = "axi", "ahb"; }; vepu121_0_mmu: iommu@fdba0800 {
@@ -1345,6 +1347,8 @@ vepu121_1: video-codec@fdba4000 { clock-names = "aclk", "hclk"; iommus = <&vepu121_1_mmu>; power-domains = <&power RK3588_PD_VDPU>; + resets = <&cru SRST_A_JPEG_ENCODER1>, <&cru SRST_H_JPEG_ENCODER1>; + reset-names = "axi", "ahb"; }; vepu121_1_mmu: iommu@fdba4800 {
@@ -1365,6 +1369,8 @@ vepu121_2: video-codec@fdba8000 { clock-names = "aclk", "hclk"; iommus = <&vepu121_2_mmu>; power-domains = <&power RK3588_PD_VDPU>; + resets = <&cru SRST_A_JPEG_ENCODER2>, <&cru SRST_H_JPEG_ENCODER2>; + reset-names = "axi", "ahb"; }; vepu121_2_mmu: iommu@fdba8800 {
@@ -1385,6 +1391,8 @@ vepu121_3: video-codec@fdbac000 { clock-names = "aclk", "hclk"; iommus = <&vepu121_3_mmu>; power-domains = <&power RK3588_PD_VDPU>; + resets = <&cru SRST_A_JPEG_ENCODER3>, <&cru SRST_H_JPEG_ENCODER3>; + reset-names = "axi", "ahb"; }; vepu121_3_mmu: iommu@fdbac800 {
Signature · 1 line
2.55.0