Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH 1/2] RDMA/cxgb4: Cancel reg_work before freeing device on remove
@ 2026-08-06 13:01 Fan Wu
  2026-08-06 13:01 ` [PATCH 2/2] RDMA/cxgb4: Free debugfs on registration failure Fan Wu
  2026-08-11 20:02 ` [PATCH 1/2] RDMA/cxgb4: Cancel reg_work before freeing device on remove Jason Gunthorpe
  0 siblings, 2 replies; 3+ messages in thread
From: Fan Wu @ 2026-08-06 13:01 UTC (permalink / raw)
  To: linux-rdma
  Cc: bharat, larrystevenwise, jgg, leon, dledford, linux-kernel,
	Fan Wu, stable

c4iw_uld_state_change() queues reg_work to register the RDMA device.
c4iw_remove() can free ctx->dev while this work is pending or running,
leaving c4iw_register_device() accessing the freed device.

Cancel reg_work before removing the device.  The registration work can
tear down ctx->dev when registration fails, so do not unregister or
deallocate it again in that case.

This issue was found by an in-house static analysis tool.

Fixes: 1c8f1da5d851 ("iw_cxgb4: Fix possible circular dependency locking warning")
Cc: stable@vger.kernel.org
Assisted-by: Codex:gpt-5.6
Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
---
 drivers/infiniband/hw/cxgb4/device.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c
index 102c5646b..c1815972a 100644
--- a/drivers/infiniband/hw/cxgb4/device.c
+++ b/drivers/infiniband/hw/cxgb4/device.c
@@ -951,6 +951,12 @@ void c4iw_dealloc(struct uld_ctx *ctx)
 static void c4iw_remove(struct uld_ctx *ctx)
 {
 	pr_debug("c4iw_dev %p\n", ctx->dev);
+
+	/* c4iw_register_device() may still be using ctx->dev. */
+	cancel_work_sync(&ctx->reg_work);
+	if (!ctx->dev)
+		return;
+
 	debugfs_remove_recursive(ctx->dev->debugfs_root);
 	c4iw_unregister_device(ctx->dev);
 	c4iw_dealloc(ctx);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] RDMA/cxgb4: Free debugfs on registration failure
  2026-08-06 13:01 [PATCH 1/2] RDMA/cxgb4: Cancel reg_work before freeing device on remove Fan Wu
@ 2026-08-06 13:01 ` Fan Wu
  2026-08-11 20:02 ` [PATCH 1/2] RDMA/cxgb4: Cancel reg_work before freeing device on remove Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Fan Wu @ 2026-08-06 13:01 UTC (permalink / raw)
  To: linux-rdma
  Cc: bharat, larrystevenwise, jgg, leon, dledford, linux-kernel,
	Fan Wu

c4iw_alloc() creates the per-device debugfs tree (dev->debugfs_root via
setup_debugfs()), but it is removed only in c4iw_remove(), not in
c4iw_dealloc().  When RDMA device registration fails, the registration
worker's err_dealloc_ctx path calls c4iw_dealloc() directly, bypassing
c4iw_remove(), so the debugfs dentries leak and outlive the freed
c4iw_dev.

Move debugfs_remove_recursive() into c4iw_dealloc() so every path that
frees ctx->dev also removes its debugfs tree.

Fixes: 49ea0c036ede ("RDMA/iw_cxgb4: cleanup device debugfs entries on ULD remove")
Assisted-by: Codex:gpt-5.6
Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
---
 drivers/infiniband/hw/cxgb4/device.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c
index c1815972a..24ac9871c 100644
--- a/drivers/infiniband/hw/cxgb4/device.c
+++ b/drivers/infiniband/hw/cxgb4/device.c
@@ -933,6 +933,7 @@ static void c4iw_rdev_close(struct c4iw_rdev *rdev)
 
 void c4iw_dealloc(struct uld_ctx *ctx)
 {
+	debugfs_remove_recursive(ctx->dev->debugfs_root);
 	c4iw_rdev_close(&ctx->dev->rdev);
 	WARN_ON(!xa_empty(&ctx->dev->cqs));
 	WARN_ON(!xa_empty(&ctx->dev->qps));
@@ -957,7 +958,6 @@ static void c4iw_remove(struct uld_ctx *ctx)
 	if (!ctx->dev)
 		return;
 
-	debugfs_remove_recursive(ctx->dev->debugfs_root);
 	c4iw_unregister_device(ctx->dev);
 	c4iw_dealloc(ctx);
 }
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] RDMA/cxgb4: Cancel reg_work before freeing device on remove
  2026-08-06 13:01 [PATCH 1/2] RDMA/cxgb4: Cancel reg_work before freeing device on remove Fan Wu
  2026-08-06 13:01 ` [PATCH 2/2] RDMA/cxgb4: Free debugfs on registration failure Fan Wu
@ 2026-08-11 20:02 ` Jason Gunthorpe
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Gunthorpe @ 2026-08-11 20:02 UTC (permalink / raw)
  To: Fan Wu
  Cc: linux-rdma, bharat, larrystevenwise, leon, dledford, linux-kernel,
	stable

On Thu, Aug 06, 2026 at 01:01:27PM +0000, Fan Wu wrote:
> c4iw_uld_state_change() queues reg_work to register the RDMA device.
> c4iw_remove() can free ctx->dev while this work is pending or running,
> leaving c4iw_register_device() accessing the freed device.
> 
> Cancel reg_work before removing the device.  The registration work can
> tear down ctx->dev when registration fails, so do not unregister or
> deallocate it again in that case.
> 
> This issue was found by an in-house static analysis tool.
> 
> Fixes: 1c8f1da5d851 ("iw_cxgb4: Fix possible circular dependency locking warning")
> Cc: stable@vger.kernel.org
> Assisted-by: Codex:gpt-5.6
> Signed-off-by: Fan Wu <fanwu01@zju.edu.cn>
> ---
>  drivers/infiniband/hw/cxgb4/device.c | 6 ++++++
>  1 file changed, 6 insertions(+)

applied thanks, the sashiko review also noted a number of pre-existing
issues that seem easy to fix

Jason

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-08-11 20:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-06 13:01 [PATCH 1/2] RDMA/cxgb4: Cancel reg_work before freeing device on remove Fan Wu
2026-08-06 13:01 ` [PATCH 2/2] RDMA/cxgb4: Free debugfs on registration failure Fan Wu
2026-08-11 20:02 ` [PATCH 1/2] RDMA/cxgb4: Cancel reg_work before freeing device on remove Jason Gunthorpe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox