From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1150F606A322 for ; Sun, 6 Dec 2026 05:58:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=fNE8JI1T; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=iVk3hCtM DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Cc:To:In-Reply-To:References:Message-Id: Content-Type:MIME-Version:Subject:Date:From:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=AjF2xdZ3UITXABDPN8pAu5QLKfDOcPgYLo/6nS9whVU=; b=fNE8JI1TxLDEGDwONUQbMMph69 A7E+vIbaD0yJo0IWaJD7eKM2AcTkNvRnySNYMSOS9nfbEHcGzw1vohD2ulpLPUiHadaFXWAkJVyJT yegfpRl0Al1BOcZVl9tm4TF47/ZHFAaW9QvfNdrRZdx7UuLTfGJI2KwO+DCjfi7oSb9wEWRp1N6H2 1B7F8RJFeI5Vyy6QUdsNJDEmQxQdV3mbcwUt6Ylz6yxJiubUMhtZT0OBNLue71I/SVGzGid6REVVE pmpZ4k8eDJr0FSWvceJwVSbLyrpD4iH7jTJd00LSYezps79NPleBcu4b9sqm76Ej6uAX8ctg/zETE zzHBNbyA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xa5GF-00000003HcJ-3MmY; Sun, 06 Dec 2026 05:58:12 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xa5Fn-00000003GoE-49pX; Sun, 06 Dec 2026 05:57:44 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B056D4530D; Sun, 6 Dec 2026 05:57:43 +0000 (UTC) Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796536663; b=mZGbFWuwVPhqcPo/NNgceHahCISFYRY2a2EB0dbSDxMJAz2CGA4kwrDbetqP+taetqqF /rNf74ioekqE3fqjA9KHCXtKNTixHhWBEHLJp2W0axsvF4Oepwg5stHkwHn2lRAgWbjmA iu4ejFCg6GnyGGFgw5+Rri8HyqgS4AL027YfD+RHv62hu9zpqVqDajY07eqryLbdf9SkC u02CWbY8CoBpiitAbcjelK8RtzjFbC7YK5v3joAo+Yc5eWKqyd77qQ41kCLrS0xrIGl2B MNyFIS/EUK1m8Rw+5znppXLBmFpyKRjsNU4N8QsBLFJYpGmlhtjM/ZtqyZ6+xHmcpUQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796536663; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=AjF2xdZ3UITXABDPN8pAu5QLKfDOcPgYLo/6nS9whVU=; b=euTH+ViQDU1+QOtWgt3UsIS/Q3fSJyFFJpPPBQNr/LMg0UogcNm85VJ/0EX9GXwZAHPH 5phjzk10QcMcsgXjWgWjN9Djg6vjYoeV5If+jmhfXor+/VFi43RM+Azc9XYZnEwM+gu1b 41tPxG64lHr2FlNuTYMjamOMqFrzn5FrXhapFvdpDFRDN1buuIQcDmsjulQD/wYwFo2nQ Nuozv6Qp5+2tOLLmU0e0Jm18eDiOUgLOlpgps2rKX8ofVolgNwUZpFpFLMFWo27Beyo10 jIWSkgbpp+RVjbCpoEQ07gBuJVdXZx2+k31JlXIgWqNEY6H6NnDtAQSkA4ubMMPvolw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 65FCA1F0092B; Sun, 6 Dec 2026 05:57:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796536663; bh=AjF2xdZ3UITXABDPN8pAu5QLKfDOcPgYLo/6nS9whVU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=iVk3hCtMA2X+tgx1lYbMq0x/VD3ur+FMguohlr94pfR6zvQ1e44p8GcvMdMSkTJRG y1cMw/ZqZtIJflGNmM1F1YUVBDkYc5gPVfqhIDpJwtwAJIAZvrJxXKCIu4k39vghPM wmSnI/o7jVqm3xxCcOzRLmIdN3kTBGI134d4FDIuOzer2PFtxkg9YR2gxzJZCdaIRf 6OorYzd5t6yLnXY356if/3YxqYE3PX1S/4IuYNvga0Ue3F48tcvrCDtODflbbzzqtK TUJApg3g8dnOebGpS4YFqopPhyVc5WMMsRJsEaGxKFKk88A5O8cNq28tbqBUTh03qD U8Jw9DlouhA5w== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 7ADEA5062F; Sun, 6 Dec 2026 05:57:39 +0000 (UTC) From: Arun Iyengar via B4 Relay Date: Sun, 06 Dec 2026 05:57:44 +0000 Subject: [PATCH v4 09/18] media: verisilicon: Reinitialize the IOMMU after resetting an encoder core X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261206-hantro-robust-v4-9-b99d33a5ec6d@gmail.com> References: <20261206-hantro-robust-v4-0-b99d33a5ec6d@gmail.com> In-Reply-To: <20261206-hantro-robust-v4-0-b99d33a5ec6d@gmail.com> To: Nicolas Dufresne , Benjamin Gaignard , Philipp Zabel , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiko Stuebner , Nicolas Frattaroli , Andrzej Pietrasiewicz , Ezequiel Garcia , Hans Verkuil , Boris Brezillon , Jernej Skrabec , "Joerg Roedel (AMD)" , Will Deacon , Robin Murphy , Ulf Hansson Cc: linux-media@vger.kernel.org, iommu@lists.linux.dev, linux-rockchip@lists.infradead.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Sergei Khomenkov , Tharit Tangkijwanichakul , Sascha Hauer , Arun Iyengar X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796536657; l=6366; i=aiyengar1990@gmail.com; s=20261110; h=from:subject:message-id; bh=PkYm74IRWax5uGIXgR0A1+lyrB4dAM0aCpEi/VhCV9c=; b=OPN58d4xzk+i6Ygmx593S9GlRmRZfPnWMxVPGimGMbtDZVQxkX+fmhudvf2CbsF1J8F2U9nAf s91gWsmc5e2DbHbIt/uTQlzPaYqGcUOYemfisCW6ibGvXRdzH9MFxvd X-Developer-Key: i=aiyengar1990@gmail.com; a=ed25519; pk=zXpRgUTrhaFe6jLyPqbBy3ccfkj04w0g2690Wv3mg+0= X-Endpoint-Received: by B4 Relay for aiyengar1990@gmail.com/20261110 with auth_id=1480 X-Original-From: Arun Iyengar Content-Transfer-Encoding: 7bit X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: aiyengar1990@gmail.com Sender: "linux-arm-kernel" X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, FREEMAIL_REPLYTO_END_DIGIT,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Arun Iyengar A Rockchip encoder core that faulted on an unmapped IOVA leaves its IOMMU with the fault pending, and the reset pulse of the previous patch can reset the IOMMU behind its driver. The IOMMU is only reprogrammed on runtime resume, which doesn't happen between back-to-back jobs. Do like rkvdec: allocate an empty paging domain at probe and, after the reset pulse, attach and detach it. The IOMMU driver reprograms the IOMMU on each domain change, and the default domain keeps its mappings. Only do this for a device with reset lines whose domain is a DMA domain. If the attach fails, the IOMMU may be left without translation (rockchip-iommu falls back to its identity domain), so refuse all further jobs. Also attach and detach it at probe, so that a rebind repairs the IOMMU after such a failure. Signed-off-by: Arun Iyengar --- drivers/media/platform/verisilicon/hantro.h | 5 ++ drivers/media/platform/verisilicon/hantro_drv.c | 69 ++++++++++++++++++++++ drivers/media/platform/verisilicon/hantro_hw.h | 1 + .../media/platform/verisilicon/rockchip_vpu_hw.c | 6 +- 4 files changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/verisilicon/hantro.h b/drivers/media/platform/verisilicon/hantro.h index 1efa032506e1..5a9acc8c82a8 100644 --- a/drivers/media/platform/verisilicon/hantro.h +++ b/drivers/media/platform/verisilicon/hantro.h @@ -188,6 +188,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; @@ -207,6 +210,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; }; /** diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index 957ed7a59197..e268858269ff 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -113,6 +114,31 @@ void hantro_irq_done(struct hantro_dev *vpu, } } +/* + * Pulsing the reset lines of a core can reset its IOMMU behind the IOMMU + * driver. Attaching and detaching the empty domain makes the driver reprogram + * 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 = iommu_attach_device(vpu->empty_domain, vpu->dev); + if (ret) { + dev_err(vpu->dev, "Failed to reinitialize the IOMMU (%d), refusing further jobs\n", + ret); + vpu->iommu_lost = true; + return ret; + } + + iommu_detach_device(vpu->empty_domain, vpu->dev); + return 0; +} + void hantro_watchdog(struct work_struct *work) { struct hantro_dev *vpu; @@ -204,6 +230,9 @@ static void device_run(void *priv) v4l2_m2m_buf_copy_metadata(src, dst); + if (unlikely(vpu->iommu_lost)) + goto err_cancel_job; + ret = pm_runtime_resume_and_get(vpu->dev); if (ret < 0) goto err_cancel_job; @@ -1121,6 +1150,42 @@ static void hantro_disable_runtime_pm(struct hantro_dev *vpu) } } +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 = iommu_get_domain_for_dev(vpu->dev); + if (!domain || !iommu_is_dma_domain(domain)) + return 0; + + domain = iommu_paging_domain_alloc(vpu->dev); + if (IS_ERR(domain)) + return PTR_ERR(domain); + + vpu->empty_domain = domain; + + ret = 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); +} + static int hantro_probe(struct platform_device *pdev) { struct hantro_dev *vpu; @@ -1172,6 +1237,10 @@ static int hantro_probe(struct platform_device *pdev) if (IS_ERR(vpu->resets)) return PTR_ERR(vpu->resets); + ret = hantro_alloc_empty_domain(vpu); + if (ret) + return ret; + vpu->reg_base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(vpu->reg_base)) return PTR_ERR(vpu->reg_base); diff --git a/drivers/media/platform/verisilicon/hantro_hw.h b/drivers/media/platform/verisilicon/hantro_hw.h index 2d12e605cb55..d3c36948208d 100644 --- a/drivers/media/platform/verisilicon/hantro_hw.h +++ b/drivers/media/platform/verisilicon/hantro_hw.h @@ -431,6 +431,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); +int 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); diff --git a/drivers/media/platform/verisilicon/rockchip_vpu_hw.c b/drivers/media/platform/verisilicon/rockchip_vpu_hw.c index 2ec25d6dac86..02fcd74e5ee0 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); 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) -- 2.55.0