From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796538772; b=YVStv99K8mp8jW47PM1rDg10Gde4D09mdyp6v3DYAoqRfjPKxrJsiVLnfDMu4wAS2Z07 Ka+nw292Is7YIziSK7k2Wo1CeC/eSd/uTodw9TKLqkxsj2RoFOcHPFZu4IIhJtDIRf7J6 NjHQnkqmZCIBE68PSc3Mq2ukw1YqqywovoSxblkCZszqEMumOmPYZ+g3gTWu7j/KsP5aA hfvfUwTXY0E/9Y7o1bp8HZGN6hQvkRkzoJzBws0snbZizdzkdQgV3WqOMqk1JaBjKiJBl RBg1yRWXg8z0dlYz2pUSTDUTs4iY73bvrDQR9phFnAlkqQc9Ntdt2pkVGJkH+eFubGA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796538772; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=sTm6egIIJ6FMTWrFt24O8ZkNJLVk5xlPLLdidHjDJUg=; b=XfXrut/yccAyGqCq9Sq53TAXRqv4NEKtw/yyDUb7KQ6LijVncBRkHHsDq4l7+aJg1ah9 YoW02ZJ9KCfzyyhR1K9PQ9hP5WsKuAncK9+FAFYgFePclvYCFui0FTsOzmco5wu4S6HE9 BvLjxdkDwga8FMRi4lST3RkhqnZEmdhmsRXoS6RFkNEicJJjsRyvU9x/rfOCgdobVeJ6k dxH96qIGiVavQmR2OQ+0yLR06/XUcH3dQtv1gitrct6lYxCbVh81KifwB7wI219wkLrMc GN86byRNTiRFsESuEN0yfdVd05rsx5UpgcjXxZepybs99qzacCaxD1H5GMLez/f1YdQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TIONhqNJ; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E03B8606A697 for ; Sun, 6 Dec 2026 06:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=TIONhqNJ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 380B71F00A18; Sun, 6 Dec 2026 06:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796538771; bh=sTm6egIIJ6FMTWrFt24O8ZkNJLVk5xlPLLdidHjDJUg=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=TIONhqNJWDjWQgPFE0LhnPuBrsQ8MZr1YzIlk2BxUU2GOEI1Gtnzihb/e0TwDI9My 7b2gusLfyXPqB/wg1V9NNSA1jGZbc/J2LbiACVJ+z3UFo3wCy9lCto/7tXsNWuYFBY NSNdMGVpR/ESsCyA0gsk0R66c20w6T6805PD4II1r7bo0afTXnVJRE6Oxi2Oq0qK+P O3LeUY2Da98kPtHF+kzICkBubCtkx0rtflIr7mkEAL3Stwv5UnCfO/r16WzspWwmYm SECprkiAwA83AbOwjY6CAr4Z88erav+e8sl3FvM+1zLv9+aRyUupMpspAUjLM+S3rL wgzn2umJcD9lA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 17/18] media: verisilicon: Reset the RK3588 AV1 decoder after an error Reply-To: sashiko-reviews@lists.linux.dev To: "Arun Iyengar" Cc: devicetree@vger.kernel.org, robh@kernel.org, conor+dt@kernel.org, media-ci@linuxtv.org In-Reply-To: <20261206-hantro-robust-v4-17-b99d33a5ec6d@gmail.com> References: <20261206-hantro-robust-v4-0-b99d33a5ec6d@gmail.com> <20261206-hantro-robust-v4-17-b99d33a5ec6d@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 06:32:50 +0000 X-Mailing-List: devicetree@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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/me= dia/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 i= t and ends the job. */ > +void hantro_irq_reset(struct hantro_dev *vpu) > +{ > + if (cancel_delayed_work(&vpu->watchdog_work)) { > + vpu->error_reset =3D 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 =3D domain; > =20 > ret =3D 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) !=3D 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/drive= rs/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_ct= x *ctx) [ ... ] > + status =3D 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 =3D 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 =3D rockchip_pmu_idle_reset(vpu->dev, rockchip_vpu981_core_reset, v= pu); [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 =3D=3D -ETIMEDOUT) { > + vpu->iommu_lost =3D true; > + goto release; > + } > + } [Severity: Medium] Does runtime PM autosuspend still call vsi_iommu_suspend() after either fatal failure path sets vpu->iommu_lost =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206-hantro-rob= ust-v4-0-b99d33a5ec6d@gmail.com?part=3D17