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=1796460982; b=pEkEeHzbol4xK+YEDwJBpvRvGc0qVEZjRM/7ySKp695P9nqka9YnXipfw+kMIK9QMTdU LMI8a6hJo5jlSYUhujBx/ATxfKy3UhLXRBpAeMQApxNsDbR8Y6UJ0FVsWhapmj4hcIWHI AmGypbe2/yE+bZmdIJdpimqNja6O5D8eDvGKluQJ9/TOnvzjvy9y56cvMigq0C30zqDVw 9klNmVqCdc6mAIXcNa9+KrYJzt6PKY7b3rjXFogLXtnwYjbLf3+qqDy5L3YCPwrsVPqeh x+Ww0zpYhbFPanMkki0eBHTARMg6tFLz+TE66CM5Z+ZYQ/u2+HN5Qmg1PFOAR1ANuYA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796460982; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=2GJIo+NTS/yPAl9aOOfcHD16PY057aa+VTsC/bXPuSI=; b=S8XH+joffmMur/P6Ane87GRITFy9OaTPmspdlL8eD3EcIF8FZHHgMBotqXwVaa6MTGHE 3EsHHN1wdWcWrR5flb4VEmShWzTgylTONXMyn89+d9C3Iuo/LT10U/8lWn+p886gwLtNa +pXvUbi/9y09OvoVGM5IoY7/9hl/Crtz9nGnWFnYPMm0OuweJGB0hGN+qoICZXTrk2W2Z 49hyeTs692mkax5+bCHnW3RC7Hx/z/HiBEIIlnPG7arjgRhlq8iKNInlzb1wfBOgL5KfX zxLdWZ0g9p05Fw2uiHFfqPt8WwzHbIEQI69TR2mQpa6Quj76DbBXq1jAzburqXPfKfA== 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=aCjIV5Rz; 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 29E0F606A334 for ; Sat, 5 Dec 2026 08:56:21 +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=aCjIV5Rz Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCD5A1F00936; Sat, 5 Dec 2026 08:56:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796460981; bh=2GJIo+NTS/yPAl9aOOfcHD16PY057aa+VTsC/bXPuSI=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=aCjIV5RzeruaP6Wr9hLWhbGa7GQzfbJbnZyFTAVrKii8S0pmdA+j4wEaGjtAICKre TRcUiyMfsTRo+Y9gGLiVAniBpxy0pdkMz7b75pNVMF1HW/k6oP7NvVq50cwLLLPL+e Y6YVrFaVJNnr93G0cTA6K/bpM7SbPWTU+Ce+eAay/psEak0nCiK8UrVkLjpKKnVdB2 nC2HH3zojGcaBu8FLSjGCl8KMhfT82jA/U6DrA6TloEGwZ/apr5QSFCRmhr85widsa Mq/hIo0VWQcaQ9b2QoZcQUUlh8JR0qC/AXSZAzp2x7ySkNZxuyyXOGSmpMUmZfq7hp Dn9MvDIXUTysQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 11/14] thunderbolt: Add platform NHI driver Reply-To: sashiko-reviews@lists.linux.dev To: "Chunfeng Yun" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261205083342.4009278-12-chunfeng.yun@mediatek.com> References: <20261205083342.4009278-1-chunfeng.yun@mediatek.com> <20261205083342.4009278-12-chunfeng.yun@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sat, 05 Dec 2026 08:56:21 +0000 X-Mailing-List: linux-usb@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 5 potential issues to consider: - [High] thunderbolt: tb_nhi_pm_ops noirq callbacks invert ACPI platform PM ordering - [High] thunderbolt: nhi_isr() causes interrupt storm on level-triggered platform IRQs - [Medium] thunderbolt: nhi_platform_do_remove() leaks wakeup_source on teardown - [Medium] thunderbolt: pm_runtime_put_noidle() before pm_runtime_disable() races drvdata - [Low] thunderbolt: nhi_platform_driver assigns .driver.pm without pm_ptr() -- commit b442c5ebfee8bab338c63df36d4eb9041e54f694 Author: Chunfeng Yun thunderbolt: Add platform NHI driver This commit adds a platform driver for ACPI-enumerated Thunderbolt/USB4 NHI controllers matching ACPI0015, including optional dedicated wake IRQ support. > diff --git a/drivers/thunderbolt/platform.c b/drivers/thunderbolt/platfor= m.c > new file mode 100644 > index 0000000000000..ce3bb65543c11 > --- /dev/null > +++ b/drivers/thunderbolt/platform.c > @@ -0,0 +1,155 @@ [ ... ] > + ret =3D platform_get_irq(pdev, 0); > + if (ret < 0) > + return ret; > + > + nhi->irq =3D ret; [Severity: High] Can this cause an interrupt storm on level-triggered platform IRQs? tb_nhi_probe() requests nhi->irq via devm_request_irq() with nhi_isr(), which only calls schedule_work(&nhi->interrupt_work) and returns IRQ_HANDLED without masking or acknowledging the interrupt. REG_RING_NOTIFY_BASE is only read later in nhi_interrupt_work(). Previously nhi->irq came from PCI MSI (edge-triggered), whereas wired platform IRQs on ACPI SoCs are commonly level-triggered. When a level-triggered interrupt fires, returning IRQ_HANDLED with the line still asserted causes the controller to re-deliver the IRQ immediately, starving nhi_interrupt_work() and livelocking the CPU. Masking or acknowledging the interrupt in hardirq context, or using devm_request_threaded_irq() with IRQF_ONESHOT, would avoid this. [ ... ] > +static void nhi_platform_do_remove(struct platform_device *pdev, bool re= set) > +{ > + struct tb *tb =3D platform_get_drvdata(pdev); > + struct device *dev =3D &pdev->dev; > + struct tb_nhi *nhi =3D tb->nhi; > + struct tb_nhi_platform *nhi_plat =3D nhi_to_platform(nhi); > + > + tb_nhi_remove(nhi, reset); > + > + if (nhi_plat->wake_irq) > + dev_pm_clear_wake_irq(dev); > + > + device_set_wakeup_capable(dev, false); [Severity: Medium] Does this leak the wakeup_source registered by tb_nhi_probe()? tb_nhi_probe() calls device_wakeup_enable(dev), which allocates and registers dev->power.wakeup (along with its child wakeupN sysfs device), while tb_nhi_remove() does not call device_wakeup_disable(dev). device_set_wakeup_capable(dev, false) clears dev->power.can_wakeup without detaching dev->power.wakeup. Because device_wakeup_disable() returns early when !dev->power.can_wakeup, even device_pm_remove() cannot free the wakeup_source later, and a subsequent re-probe fails in device_wakeup_enable() with -EEXIST. Calling device_init_wakeup(dev, false) instead avoids the leak. > + pm_runtime_put_noidle(dev); > + pm_runtime_disable(dev); > + pm_runtime_set_suspended(dev); > +} [Severity: Medium] Can calling pm_runtime_put_noidle() before pm_runtime_disable() race with nhi_runtime_suspend() and cause a use-after-free on tb? CPU0 CPU1 nhi_platform_do_remove() tb_nhi_remove() tb_domain_remove(tb) ... kfree(tb) pm_runtime_put_noidle(dev) pm_suspend_timer_fn() nhi_runtime_suspend(dev) tb =3D dev_get_drvdata(dev) tb->nhi <-- use-after-free pm_runtime_disable(dev) tb_nhi_remove() waits for tb_domain_release() to free tb, but dev->driver_data still points to it until device_unbind_cleanup(). Dropping usage_count to zero while runtime PM is still enabled lets an armed autosuspend timer (or a stateless USB3 consumer device link) invoke nhi_runtime_suspend() on freed memory. The same ordering in nhi_platform_probe() under wake_irq_err can trigger a NULL pointer dereference in nhi_runtime_suspend() while dev_get_drvdata(dev) is NULL. Calling pm_runtime_disable(dev) before pm_runtime_put_noidle(dev) closes both windows. [ ... ] > +static struct platform_driver nhi_platform_driver =3D { > + .probe =3D nhi_platform_probe, > + .remove =3D nhi_platform_remove, > + .shutdown =3D nhi_platform_shutdown, > + .driver =3D { > + .name =3D "thunderbolt", > + .acpi_match_table =3D ACPI_PTR(nhi_platform_acpi_match), > + .pm =3D &tb_nhi_pm_ops, > + }, > +}; [Severity: High] Does using tb_nhi_pm_ops invert the power-state ordering under acpi_general_pm_domain? When platform_probe() binds an ACPI platform device, dev_pm_domain_attach() attaches acpi_general_pm_domain. Unlike PCI PM, acpi_general_pm_domain transitions the device to low power in acpi_subsys_suspend_late() (and acpi_subsys_poweroff_late()), before tb_nhi_pm_ops.suspend_noirq (nhi_suspend_noirq()) runs. On resume, acpi_subsys_resume_noirq() runs nhi_resume_noirq() while the device is still powered off, and because tb_nhi_pm_ops.resume_early is NULL, acpi_subsys_resume_early() postpones acpi_dev_resume() until acpi_subsys_resume() (with the same inversion in hibernation restore_noirq vs acpi_subsys_restore_early()). On SoCs whose ACPI power states gate the NHI clocks or power domain, nhi_suspend_noirq() and nhi_resume_noirq() will perform MMIO register accesses and control-channel DMA while the controller is powered off, causing MMIO timeouts, failed tunnel recovery, or bus faults and hangs. [Severity: Low] This isn't a bug, but .pm should be wrapped with pm_ptr(&tb_nhi_pm_ops) so the PM ops pointer evaluates to NULL and can be discarded when CONFIG_PM is disabled. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205083342.4009= 278-1-chunfeng.yun@mediatek.com?part=3D11