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=1796538089; b=bQfvHJgEG1DKz91+5zAnlpAO3KFweHKvoqzoyVQ9qclv09z61qkBoAraYDvgdGZKRo9/ rFbf58KqeGJTA4fx6BYcQmSQFZv39tFoIdQCImIw5qacAJC/4WIefT82SLBeUPnvdEpNi VDSeW9Ss6zsSyq8PS7y21kwMVacM6xGqL6VfCBA2dfqc527UWqnhwX3dLuVCD8lPoku4C KrI5DUN88UE3ggrexvEjCw4wwd5IrDrGPWJTHROG7Z8Wt/M62yr22Ibr515fvSQr+zbsu mRdkrujTUw2FINq0mkyLVcHA52/Krd/I1HAc5dKy/qFq9V+VxONHUsTwXP/d6RefTDg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796538089; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=5ATGLG5TPgEyrHVi/ePPEsD97nuvGeHYBgBQVfMKYYA=; b=cCEg9qUlZ8TpoMsVgdJ4jU3E0BMoacS4srxt+ySCGblH2Q60XboEfYVbnRdoA+JMc7qT t0ws7UJOBENwk1kDPaAnoxzdwt6B3V3kkvTrvd6Ytpdkz+oHjSFn43V9EH/0Q21UGHySK PRIggvsNtuegELu7xQ4/EoXKemU4TZKwkkW1VynkohbRtqog/Ij4UIdiCMHyCRQl0pBHq oU2Z8o6PQvH3ST10tr6aNqyKPsjbMyo5OXGR25s1lk8WTbM3Kv1Z+me1sZGg+ePx3lU+O zdz5zIC8X64A6mePT38g3JRo+0hksg8eNQ0wWYWuJtV6aiSWvpH2LLceDO91jGqmzgQ== 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=ofUjcs1X; 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 85C61606A31F for ; Sun, 6 Dec 2026 06:21:29 +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=ofUjcs1X Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1C4C41F0092B; Sun, 6 Dec 2026 06:21:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796538089; bh=5ATGLG5TPgEyrHVi/ePPEsD97nuvGeHYBgBQVfMKYYA=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=ofUjcs1X+Ob7Sjb439kUq8n4K0itpr9NaupE3oZESUyyto8LfDeh/1e+LlQaj7x78 zc4i88YxrQw0TUuJKKgr4Ggy1LmnY3QxUKoKz+4CmGBFsw+N0BAnfCZaJICg4h8i2M kXsvXgv/C362ba6sJX894iuJ/SIViWmkv8qNakFNLQE2EuUVjR5Esd/5Wk28wS4b08 tYEdXSADwFmVfLsLM18TabuWw3ACOJVXYRwJVncqdGmgN1SVAL54O1+/NUzfp/030k 2i04lQ5j+emBlUiOOrWoc+iRHtrQYLrITIlZ1gxU4GA3vbNZQnA1ivxeP/unjNAZYH jNvSnqtFOsxQQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 09/18] media: verisilicon: Reinitialize the IOMMU after resetting an encoder core 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-9-b99d33a5ec6d@gmail.com> References: <20261206-hantro-robust-v4-0-b99d33a5ec6d@gmail.com> <20261206-hantro-robust-v4-9-b99d33a5ec6d@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 06:21:28 +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 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 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/me= dia/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, > } > } > =20 > +/* > + * Pulsing the reset lines of a core can reset its IOMMU behind the IOMMU > + * driver. Attaching and detaching the empty domain makes the driver rep= rogram > + * 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 =3D iommu_attach_device(vpu->empty_domain, vpu->dev); > + if (ret) { > + dev_err(vpu->dev, "Failed to reinitialize the IOMMU (%d), refusing fur= ther jobs\n", > + ret); > + vpu->iommu_lost =3D 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 hantr= o_dev *vpu) > } > } > =20 > +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 =3D iommu_get_domain_for_dev(vpu->dev); > + if (!domain || !iommu_is_dma_domain(domain)) > + return 0; > + > + domain =3D iommu_paging_domain_alloc(vpu->dev); > + if (IS_ERR(domain)) > + return PTR_ERR(domain); > + > + vpu->empty_domain =3D domain; > + > + ret =3D 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 =3D <&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 *pd= ev) > if (IS_ERR(vpu->resets)) > return PTR_ERR(vpu->resets); > =20 > + ret =3D hantro_alloc_empty_domain(vpu); > + if (ret) > + return ret; > + > vpu->reg_base =3D 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/drive= rs/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); > =20 > ret =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261206-hantro-rob= ust-v4-0-b99d33a5ec6d@gmail.com?part=3D9