From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=103.209.128.245 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796004865; b=X6cxZzoF+3BYvy0+U5Brbs9HM7PzyQhB4uaeHkVeWKazxzptb21ycAHLGflE2W+TmdsW Zfv7RSnr+tsVqx/bbqgZK5nbSyHKkukCLdOy2fWbjNw8mxsn7HVDACpZwN8V5fvMb0+Fy 5i/EOmJzSn40tTjzmRSCegPDgOhG9zxiwE/midOQ9+FuBmhc4J4ZUKRjv9wW6+9QjyqRI NF19uLTYQR/tTuHrU2HdoXAUOI6xcDIOFbLG4Vfh+FB1X9/CQzr3AEcM73Kjwjh8n0U6R T+PP2h7B70hyY+qRXh81V2NNu+nwPdFrixXuK/I9pfNXt6cgsIBrdklv/Kh8tpKUwvg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796004865; h=DMARC-Filter:Received:Message-ID:Date:MIME-Version:User-Agent: Subject:To:Cc:References:From:In-Reply-To:Content-Type: Content-Transfer-Encoding:X-HM-Tid:X-HM-MType:X-HM-Spam-Status: DKIM-Signature; bh=orgqrgchu2JLCTTXnh28YUxPzm55J+VHJ97RzneTqM4=; b=R/cjjpBFk3XamJdTZE0dDYAA+tF197CLYzQCupgZK58rRTc8u+mt+RdH27s0KpcPwnhV MdqKt/qLbGc6Jkli0L2fr+BcV9RP2sn0R94M9jBk8sEOo9jfmupjx+MpfpDA7ZSBNr/jj Fh3HzSsbmJMHTzv/FBrwI91+rpEIe3dtbaZIWqkYMvsuTLr3hEYkEMyXPdjC+jvV/+XkF meIeDdukokLzYud5hkpfmmkBAhspHWPb0I1/4SKm8GGRzAtkhZupN8h4Z2Xp3SE0YdaDO KttLJUSvMVl4RKv3vqTb1/zchIXenqktczK9O06KQXO8MVZ0/GZT/F1gFCJ3cLqJmxw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=rock-chips.com; spf=pass smtp.mailfrom=rock-chips.com; dkim=pass header.d=rock-chips.com header.i=@rock-chips.com header.a=rsa-sha256 header.s=default header.b=QAwXOd2a; arc=none smtp.remote-ip=103.209.128.245 Received: from mail-m128245.netease.com (mail-m128245.netease.com [103.209.128.245]) (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 5F1B3606A31C; Mon, 30 Nov 2026 02:14:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5F1B3606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=rock-chips.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rock-chips.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=rock-chips.com header.i=@rock-chips.com header.a=rsa-sha256 header.s=default header.b=QAwXOd2a Received: from [192.168.31.31] (gyproxy-mailtls3-entmail-gy2-virt38.gy.ntes [61.154.14.86]) by smtp.qiye.163.com (Hmail) with ESMTP id 566da19f6; Mon, 30 Nov 2026 10:14:09 +0800 (GMT+08:00) Message-ID: Date: Mon, 30 Nov 2026 10:14:09 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] iommu/rockchip: do not walk the page tables of a disabled MMU To: Heiko Stuebner , "Joerg Roedel (AMD)" , Will Deacon , "open list:IOMMU SUBSYSTEM" , "moderated list:ARM/Rockchip SoC support" , "open list:ARM/Rockchip SoC support" , open list , Lucas Tanure , Robin Murphy Cc: stable@vger.kernel.org References: <20261114133738.52817-1-tanure@linux.com> From: Simon Xue In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-HM-Tid: 0aa22a3b25f009d3kunm486adc2da01ff3 X-HM-MType: 1 X-HM-Spam-Status: e1kfGhgUHx5ZQUpXWQgPGg8OCBgUHx5ZQUlOS1dZFg8aDwILHllBWSg2Ly tZV1koWUFITzdXWRgWCB1ZQUpXWS1ZQUlXWQ8JGhUIEh9ZQVlDQ0JJVktLSUJCQklLSEpNH1YVFA kWGhdVEwETFhoSFyQUDg9ZV1kYEgtZQVlNSlVKTk9VSk9VQ01ZV1kWGg8SFR0UWUFZT0tIVUpLSE pKQkxVSktLVUpCS0tZBg++ DKIM-Signature: a=rsa-sha256; b=QAwXOd2a8lPapGOrdk+m6oFARPS/tm9OzqTx8RXqNGBQzeb1bsqpdXuzad1YWVE7CtbSJGQn1EfZTrHAIBNWHr4akDJ38s4K9eAoQiH1LjoBrTCque54jvIKxNxbUf/zx678VO17Vdl6O00Rm2J+LbgS8FdJ/2rOIbHHInUWNrI=; c=relaxed/relaxed; s=default; d=rock-chips.com; v=1; bh=orgqrgchu2JLCTTXnh28YUxPzm55J+VHJ97RzneTqM4=; h=date:mime-version:subject:message-id:from; 在 2026/11/30 1:04, Heiko Stuebner 写道: > Am Samstag, 14. November 2026, 14:37:37 Mitteleuropäische Normalzeit schrieb Lucas Tanure: >> A page fault handler running while another CPU detaches the same IOMMU >> can read a cleared RK_MMU_DTE_ADDR, turn it into a linear-map pointer >> and dereference it, which panics the machine. A dummy or firmware-left >> address is as unsafe. > Adding Simon Xue from Rockchip who has worked on the iommu before, because > my iommu-foo is definitly not enough ;-) . > > > Heiko > > > >> Seen on PX30 at reboot: the display controller still fetched an >> unmapped framebuffer, its IOMMU sat in a page fault, ignored the stall >> and paging-disable commands, and had RK_MMU_DTE_ADDR cleared during >> the handler's second run. >> >> No wait works: the master shares the line, the RK3588 NPU driver >> detaches from its interrupt thread, where synchronize_irq() deadlocks, >> and synchronize_hardirq() skips a force-threaded handler. A spinlock >> orders the walk against the register clear. >> >> 6.1 vendor kernel log, rk_pagefault_done is the walk, per CPU: >> >> CPU 1, init, reboot path: >> [ 1069.789374][ T1] rk_iommu ff460f00.iommu: Enable stall request timed out, retry_count = 0, status: 0x0002cb >> [ 1069.791314][ T1] rk_iommu ff460f00.iommu: Disable paging request timed out, retry_count = 0, status: 0x0002cb >> [ 1069.830197][ T1] Call trace: >> [ 1069.830922][ T1] iommu_detach_device+0xd0/0xdc >> [ 1069.831483][ T1] rockchip_drm_dma_detach_device+0x1c/0x34 >> [ 1069.832033][ T1] vop_crtc_atomic_disable+0xb0c/0xc44 >> [ 1069.832751][ T1] drm_atomic_helper_commit_modeset_disables+0x348/0x690 >> ... >> [ 1069.836601][ T1] drm_atomic_helper_shutdown+0xa0/0x158 >> [ 1069.837152][ T1] rockchip_drm_platform_shutdown+0x18/0x2c >> [ 1069.837870][ T1] platform_shutdown+0x3c/0x54 >> [ 1069.838599][ T1] device_shutdown+0x194/0x260 >> [ 1069.839160][ T1] kernel_restart+0x40/0x128 >> >> CPU 0, page fault handler: >> [ 1069.790364][ C0] rk_iommu ff460f00.iommu: Page fault at 0x00000000ffee0000 of type read >> [ 1069.792129][ C0] rk_iommu ff460f00.iommu: Page fault while iommu not attached to domain? >> [ 1069.792184][ C0] rk_iommu ff460f00.iommu: Page fault at 0x00000000ffee0280 of type read >> [ 1069.794604][ C0] Unable to handle kernel paging request at virtual address ffffff8000000ffc >> [ 1069.805998][ C0] Internal error: Oops: 0000000096000006 [#1] PREEMPT SMP >> [ 1069.809484][ C0] pc : rk_pagefault_done+0x1b4/0x3c8 >> [ 1069.810548][ C0] lr : rk_pagefault_done+0x19c/0x3c8 >> [ 1069.832390][ C0] Call trace: >> [ 1069.833116][ C0] rk_pagefault_done+0x1b4/0x3c8 >> [ 1069.833844][ C0] rk_iommu_irq+0x64/0xc8 >> [ 1069.834395][ C0] __handle_irq_event_percpu+0xe8/0x2ac >> [ 1069.834945][ C0] handle_irq_event+0x40/0xbc >> [ 1069.835675][ C0] handle_fasteoi_irq+0x118/0x28c >> [ 1069.836404][ C0] generic_handle_domain_irq+0x44/0x6c >> [ 1069.836954][ C0] gic_handle_irq+0x60/0xf0 >> [ 1069.837505][ C0] call_on_irq_stack+0x3c/0x5c >> [ 1069.838235][ C0] do_interrupt_handler+0x4c/0x94 >> [ 1069.838963][ C0] el1_interrupt+0x44/0xa8 >> [ 1069.839446][ C0] el1h_64_irq_handler+0x18/0x2c >> [ 1069.839997][ C0] el1h_64_irq+0x78/0x7c >> [ 1071.215224][ C0] Kernel panic - not syncing: Oops: Fatal exception in interrupt >> >> Fixes: c68a292152d3 ("iommu/rockchip: rk3288 iommu driver") >> Cc: stable@vger.kernel.org >> Signed-off-by: Lucas Tanure >> --- >> drivers/iommu/rockchip-iommu.c | 28 ++++++++++++++++++++++------ >> 1 file changed, 22 insertions(+), 6 deletions(-) >> >> diff --git a/drivers/iommu/rockchip-iommu.c b/drivers/iommu/rockchip-iommu.c >> index 1fa3110b142a..0f40d9678344 100644 >> --- a/drivers/iommu/rockchip-iommu.c >> +++ b/drivers/iommu/rockchip-iommu.c >> @@ -115,6 +115,7 @@ struct rk_iommu { >> struct iommu_device iommu; >> struct list_head node; /* entry in rk_iommu_domain.iommus */ >> struct iommu_domain *domain; /* domain to which iommu is attached */ >> + spinlock_t lock; >> const struct rk_iommu_ops *rk_ops; >> }; >> >> @@ -543,7 +544,8 @@ static int rk_iommu_force_reset(struct rk_iommu *iommu) >> return 0; >> } >> >> -static void log_iova(struct rk_iommu *iommu, int index, dma_addr_t iova) >> +static void log_iova(struct rk_iommu *iommu, struct iommu_domain *domain, >> + int index, dma_addr_t iova) >> { >> void __iomem *base = iommu->bases[index]; >> u32 dte_index, pte_index, page_offset; >> @@ -563,6 +565,12 @@ static void log_iova(struct rk_iommu *iommu, int index, dma_addr_t iova) >> >> mmu_dte_addr = rk_iommu_read(base, RK_MMU_DTE_ADDR); >> mmu_dte_addr_phys = iommu->rk_ops->pt_address(mmu_dte_addr); >> + if (domain == &rk_identity_domain || >> + mmu_dte_addr_phys != to_rk_domain(domain)->dt_dma) { >> + dev_err(iommu->dev, "iova = %pad: page directory %#x is not the attached domain's, not walked\n", >> + &iova, mmu_dte_addr); >> + return; >> + } >> >> dte_addr_phys = mmu_dte_addr_phys + (4 * dte_index); >> dte_addr = phys_to_virt(dte_addr_phys); >> @@ -593,6 +601,7 @@ static void log_iova(struct rk_iommu *iommu, int index, dma_addr_t iova) >> static irqreturn_t rk_iommu_irq(int irq, void *dev_id) >> { >> struct rk_iommu *iommu = dev_id; >> + struct iommu_domain *domain; >> u32 status; >> u32 int_status; >> dma_addr_t iova; >> @@ -606,6 +615,8 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id) >> if (WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks))) >> goto out; >> >> + spin_lock(&iommu->lock); >> + domain = READ_ONCE(iommu->domain); >> for (i = 0; i < iommu->num_mmu; i++) { >> int_status = rk_iommu_read(iommu->bases[i], RK_MMU_INT_STATUS); >> if (int_status == 0) >> @@ -625,15 +636,15 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id) >> &iova, >> str_write_read(flags == IOMMU_FAULT_WRITE)); >> >> - log_iova(iommu, i, iova); >> + log_iova(iommu, domain, i, iova); >> >> /* >> * Report page fault to any installed handlers. >> * Ignore the return code, though, since we always zap cache >> * and clear the page fault anyway. >> */ >> - if (iommu->domain != &rk_identity_domain) >> - report_iommu_fault(iommu->domain, iommu->dev, iova, >> + if (domain != &rk_identity_domain) >> + report_iommu_fault(domain, iommu->dev, iova, >> flags); >> else >> dev_err(iommu->dev, "Page fault while iommu not attached to domain?\n"); >> @@ -651,6 +662,7 @@ static irqreturn_t rk_iommu_irq(int irq, void *dev_id) >> >> rk_iommu_write(iommu->bases[i], RK_MMU_INT_CLEAR, int_status); >> } >> + spin_unlock(&iommu->lock); >> >> clk_bulk_disable(iommu->num_clocks, iommu->clocks); >> >> @@ -921,16 +933,19 @@ static struct rk_iommu *rk_iommu_from_dev(struct device *dev) >> /* Must be called with iommu powered on and attached */ >> static void rk_iommu_disable(struct rk_iommu *iommu) >> { >> + unsigned long flags; >> int i; >> >> /* Ignore error while disabling, just keep going */ >> WARN_ON(clk_bulk_enable(iommu->num_clocks, iommu->clocks)); >> rk_iommu_enable_stall(iommu); >> rk_iommu_disable_paging(iommu); >> + spin_lock_irqsave(&iommu->lock, flags); >> for (i = 0; i < iommu->num_mmu; i++) { >> rk_iommu_write(iommu->bases[i], RK_MMU_INT_MASK, 0); >> rk_iommu_write(iommu->bases[i], RK_MMU_DTE_ADDR, 0); >> } >> + spin_unlock_irqrestore(&iommu->lock, flags); >> rk_iommu_disable_stall(iommu); >> clk_bulk_disable(iommu->num_clocks, iommu->clocks); >> } >> @@ -997,7 +1012,7 @@ static int rk_iommu_identity_attach(struct iommu_domain *identity_domain, >> if (iommu->domain == identity_domain) >> return 0; >> >> - iommu->domain = identity_domain; >> + WRITE_ONCE(iommu->domain, identity_domain); >> >> spin_lock_irqsave(&rk_domain->iommus_lock, flags); >> list_del_init(&iommu->node); >> @@ -1051,7 +1066,7 @@ static int rk_iommu_attach_device(struct iommu_domain *domain, >> if (ret) >> return ret; >> >> - iommu->domain = domain; >> + WRITE_ONCE(iommu->domain, domain); >> >> spin_lock_irqsave(&rk_domain->iommus_lock, flags); >> list_add_tail(&iommu->node, &rk_domain->iommus); >> @@ -1227,6 +1242,7 @@ static int rk_iommu_probe(struct platform_device *pdev) >> return -ENOMEM; >> >> iommu->domain = &rk_identity_domain; >> + spin_lock_init(&iommu->lock); >> >> platform_set_drvdata(pdev, iommu); >> iommu->dev = dev; >> Looks good to me, Thanks. Reviewed-by: Simon Xue