Skip to contentSkip to conversation

RDMA/core: Fix WARNING in gid_table_release_one

PATCH Superseded Zhu Yanjun 3 participants 4 messages Nov 4, 2025 – Nov 5, 2025 InfiniBand

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zhu Yanjun

author
#0 lore raw

PATCH 1/1 RDMA/core: Fix WARNING in gid_table_release_one

From: "Zhu Yanjun" <[email protected]>

GID entry ref leak for dev syz1 index 2 ref=615
...

Call Trace:
 <TASK>
 ib_device_release+0xd2/0x1c0 drivers/infiniband/core/device.c:509
 device_release+0x99/0x1c0 drivers/base/core.c:-1
 kobject_cleanup lib/kobject.c:689 [inline]
 kobject_release lib/kobject.c:720 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x228/0x480 lib/kobject.c:737
 process_one_work kernel/workqueue.c:3263 [inline]
 process_scheduled_works+0xae1/0x17b0 kernel/workqueue.c:3346
 worker_thread+0x8a0/0xda0 kernel/workqueue.c:3427
 kthread+0x711/0x8a0 kernel/kthread.c:463
 ret_from_fork+0x47c/0x820 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>

When the state of a GID is GID_TABLE_ENTRY_PENDING_DEL, it indicates that the GID is about to be released soon. Therefore, it does not appear to be a leak.

The release_gid_table() function also waits for a short period; if the GID still exists after that, a GID leak warning will be triggered.

Fixes b150c3862d21 ("IB/core: Introduce GID entry reference counts")
Reported-by [email protected]
---
 drivers/infiniband/core/cache.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)
drivers/infiniband/core/cache.c +14 -3
index 81cf3c902e81..451325ce6fa5 100644
@@ -800,13 +800,24 @@ static void release_gid_table(struct ib_device *device,
 		return;
 
 	for (i = 0; i < table->sz; i++) {
+		int cnt = 200;
+
 		if (is_gid_entry_free(table->data_vec[i]))
 			continue;
 
-		WARN_ONCE(true,
-			  "GID entry ref leak for dev %s index %d ref=%u\n",
+		WARN_ONCE(table->data_vec[i]->state != GID_TABLE_ENTRY_PENDING_DEL,
+			  "GID entry ref leak for dev %s index %d ref=%u, state: %d\n",
 			  dev_name(&device->dev), i,
-			  kref_read(&table->data_vec[i]->kref));
+			  kref_read(&table->data_vec[i]->kref), table->data_vec[i]->state);
+
+		while ((kref_read(&table->data_vec[i]->kref) > 0) && (cnt > 0)) {
+			cnt--;
+			msleep(10);
+		}
+
+		if (cnt <= 0)
+			pr_warn_ratelimited("Possibly kref leak, ref:%u, state: %d\n",
+				kref_read(&table->data_vec[i]->kref), table->data_vec[i]->state);
 	}
 
 	mutex_destroy(&table->lock);
Signature · 1 line
2.51.0
#1 lore raw
Quoted 11 lines · Zhu Yanjun
(quoted diff) +2 -2
@@ -800,13 +800,24 @@ static void release_gid_table(struct ib_device *device,
 		return;
 
 	for (i = 0; i < table->sz; i++) {
+		int cnt = 200;
+
 		if (is_gid_entry_free(table->data_vec[i]))
 			continue;
 
-		WARN_ONCE(true,
-			  "GID entry ref leak for dev %s index %d ref=%u\n",

Review static void release_gid_table(struct ib_device *device, · line 816

Quoted 10 lines
(quoted diff) +8 -1
+		WARN_ONCE(table->data_vec[i]->state != GID_TABLE_ENTRY_PENDING_DEL,
+			  "GID entry ref leak for dev %s index %d ref=%u, state: %d\n",
 			  dev_name(&device->dev), i,
-			  kref_read(&table->data_vec[i]->kref));
+			  kref_read(&table->data_vec[i]->kref), table->data_vec[i]->state);
+
+		while ((kref_read(&table->data_vec[i]->kref) > 0) && (cnt > 0)) {
+			cnt--;
+			msleep(10);
+		}

Definately don't want to see this looping.

If it is waiting for the work queue then maybe this should flush the work queue.

Something like this?

drivers/infiniband/core/cache.c +13 -0
@@ -799,7 +799,19 @@ static void release_gid_table(struct ib_device *device,
        if (!table)
                return;
 
+       mutex_lock(&table->lock);
        for (i = 0; i < table->sz; i++) {
+               if (is_gid_entry_free(table->data_vec[i]))
+                       continue;
+
+               /*
+                * The entry may be sitting in the WQ waiting for
+                * free_gid_work(), flush it to try to clean it.
+                */
+               mutex_unlock(&table->lock);
+               flush_workqueue(ib_wq);
+               mutex_lock(&table->lock);
+
                if (is_gid_entry_free(table->data_vec[i]))
                        continue;
 
@@ -808,6 +820,7 @@ static void release_gid_table(struct ib_device *device,
                          dev_name(&device->dev), i,
                          kref_read(&table->data_vec[i]->kref));
        }
+       mutex_unlock(&table->lock);
 
        mutex_destroy(&table->lock);
        kfree(table->data_vec);
author
#2 lore raw
Quoted 24 lines · Jason Gunthorpe
Quoted 11 lines · Zhu Yanjun
(quoted diff) +2 -2
@@ -800,13 +800,24 @@ static void release_gid_table(struct ib_device *device,
  		return;
 
  	for (i = 0; i < table->sz; i++) {
+		int cnt = 200;
+
  		if (is_gid_entry_free(table->data_vec[i]))
  			continue;
 
-		WARN_ONCE(true,
-			  "GID entry ref leak for dev %s index %d ref=%u\n",

Review static void release_gid_table(struct ib_device *device, · line 816

Quoted 10 lines
(quoted diff) +8 -1
+		WARN_ONCE(table->data_vec[i]->state != GID_TABLE_ENTRY_PENDING_DEL,
+			  "GID entry ref leak for dev %s index %d ref=%u, state: %d\n",
  			  dev_name(&device->dev), i,
-			  kref_read(&table->data_vec[i]->kref));
+			  kref_read(&table->data_vec[i]->kref), table->data_vec[i]->state);
+
+		while ((kref_read(&table->data_vec[i]->kref) > 0) && (cnt > 0)) {
+			cnt--;
+			msleep(10);
+		}

Definately don't want to see this looping.

Quoted 2 lines

If it is waiting for the work queue then maybe this should flush the work queue.

Thanks a lot, Jason. I will delve into your suggestions and follow your advice to send a new patch for this problem.

Yanjun.Zhu

Quoted 35 lines

Something like this?

drivers/infiniband/core/cache.c +13 -0
@@ -799,7 +799,19 @@ static void release_gid_table(struct ib_device *device,
         if (!table)
                 return;
 
+       mutex_lock(&table->lock);
         for (i = 0; i < table->sz; i++) {
+               if (is_gid_entry_free(table->data_vec[i]))
+                       continue;
+
+               /*
+                * The entry may be sitting in the WQ waiting for
+                * free_gid_work(), flush it to try to clean it.
+                */
+               mutex_unlock(&table->lock);
+               flush_workqueue(ib_wq);
+               mutex_lock(&table->lock);
+
                 if (is_gid_entry_free(table->data_vec[i]))
                         continue;
 
@@ -808,6 +820,7 @@ static void release_gid_table(struct ib_device *device,
                           dev_name(&device->dev), i,
                           kref_read(&table->data_vec[i]->kref));
         }
+       mutex_unlock(&table->lock);
 
         mutex_destroy(&table->lock);
         kfree(table->data_vec);
Signature · 2 lines
Best Regards,
Yanjun.Zhu
#3 lore raw
In reply to Jason Gunthorpe
Quoted 38 lines · Jason Gunthorpe
Quoted 11 lines · Zhu Yanjun
(quoted diff) +2 -2
@@ -800,13 +800,24 @@ static void release_gid_table(struct ib_device *device,
 		return;
 
 	for (i = 0; i < table->sz; i++) {
+		int cnt = 200;
+
 		if (is_gid_entry_free(table->data_vec[i]))
 			continue;
 
-		WARN_ONCE(true,
-			  "GID entry ref leak for dev %s index %d ref=%u\n",

Review static void release_gid_table(struct ib_device *device, · line 816

Quoted 10 lines
(quoted diff) +8 -1
+		WARN_ONCE(table->data_vec[i]->state != GID_TABLE_ENTRY_PENDING_DEL,
+			  "GID entry ref leak for dev %s index %d ref=%u, state: %d\n",
 			  dev_name(&device->dev), i,
-			  kref_read(&table->data_vec[i]->kref));
+			  kref_read(&table->data_vec[i]->kref), table->data_vec[i]->state);
+
+		while ((kref_read(&table->data_vec[i]->kref) > 0) && (cnt > 0)) {
+			cnt--;
+			msleep(10);
+		}

Definately don't want to see this looping.

If it is waiting for the work queue then maybe this should flush the work queue.

Something like this?

drivers/infiniband/core/cache.c +1 -0
@@ -799,7 +799,19 @@ static void release_gid_table(struct ib_device *device,
        if (!table)
                return;
 
+       mutex_lock(&table->lock);
        for (i = 0; i < table->sz; i++) {

drivers/infiniband/core/cache.c static void release_gid_table(struct ib_device *device, · line 813

Quoted 10 lines
drivers/infiniband/core/cache.c +10 -0
+               if (is_gid_entry_free(table->data_vec[i]))
+                       continue;
+
+               /*
+                * The entry may be sitting in the WQ waiting for
+                * free_gid_work(), flush it to try to clean it.
+                */
+               mutex_unlock(&table->lock);
+               flush_workqueue(ib_wq);
+               mutex_lock(&table->lock);

I don't think that this is right thing to do. If you want, you can call to flush_workqueue(ib_wq) in ib_cache_release_one().

Thanks

Quoted 15 lines
drivers/infiniband/core/cache.c +2 -0
+
                if (is_gid_entry_free(table->data_vec[i]))
                        continue;
 
@@ -808,6 +820,7 @@ static void release_gid_table(struct ib_device *device,
                          dev_name(&device->dev), i,
                          kref_read(&table->data_vec[i]->kref));
        }
+       mutex_unlock(&table->lock);
 
        mutex_destroy(&table->lock);
        kfree(table->data_vec);