Skip to contentSkip to conversation

RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert()

PATCH Applied lirongqing 3 participants 3 messages Sep 16 – Sep 18 InfiniBand

lore
Share & tools
lore

lirongqing

author
#0 lore raw

PATCH 1/1 RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert()

From: Li RongQing <[email protected]>

When adding a QP to the restrack xarray, rdma_restrack_add() does:

	ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL);
	if (ret)
		res->id = 0;

	if (qp->qp_type >= IB_QPT_DRIVER)
		xa_set_mark(&rt->xa, res->id, RESTRACK_DD);

The xa_set_mark() call is not guarded by "!ret". When xa_insert() fails (possible on a qp_num collision or memory pressure), res->id is reset to 0, yet the mark is still applied to index 0. If a legitimate QP whose qp_num is 0 already occupies that slot - e.g. a normal QP or the SMI QP
- it is spuriously tagged as driver-private (RESTRACK_DD), and the netlink dump path res_get_common_dumpit() then hides it from "rdma res" output whenever the caller does not request driver details.

Only set the mark when the insertion actually succeeded by folding the mark into the non-failure branch.

Fixes e18fa0bbcedf8 ("RDMA/core: Add an option to display driver-specific QPs in the rdmatool")
---
 drivers/infiniband/core/restrack.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/infiniband/core/restrack.c +1 -2
index f89a81d..a8b838f 100644
@@ -250,8 +250,7 @@ void rdma_restrack_add(struct rdma_restrack_entry *res)
 		ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL);
 		if (ret)
 			res->id = 0;
-
-		if (qp->qp_type >= IB_QPT_DRIVER)
+		else if (qp->qp_type >= IB_QPT_DRIVER)
 			xa_set_mark(&rt->xa, res->id, RESTRACK_DD);
 	} else if (res->type == RDMA_RESTRACK_COUNTER) {
 		/* Special case to ensure that cntn points to right counter */
Signature · 1 line
2.9.4
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 19 lines

From: Li RongQing <[email protected]>

When adding a QP to the restrack xarray, rdma_restrack_add() does:

	ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL);
	if (ret)
		res->id = 0;

	if (qp->qp_type >= IB_QPT_DRIVER)
		xa_set_mark(&rt->xa, res->id, RESTRACK_DD);

The xa_set_mark() call is not guarded by "!ret". When xa_insert() fails (possible on a qp_num collision or memory pressure), res->id is reset to 0, yet the mark is still applied to index 0. If a legitimate QP whose qp_num is 0 already occupies that slot - e.g. a normal QP or the SMI QP
- it is spuriously tagged as driver-private (RESTRACK_DD), and the netlink dump path res_get_common_dumpit() then hides it from "rdma res" output whenever the caller does not request driver details.

Quoted 5 lines

Only set the mark when the insertion actually succeeded by folding the mark into the non-failure branch.

Fixes e18fa0bbcedf8 ("RDMA/core: Add an option to display driver-specific QPs in the rdmatool")

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to lirongqing
Quoted 10 lines · lirongqing

When adding a QP to the restrack xarray, rdma_restrack_add() does:

	ret = xa_insert(&rt->xa, res->id, res, GFP_KERNEL);
	if (ret)
		res->id = 0;

	if (qp->qp_type >= IB_QPT_DRIVER)
		xa_set_mark(&rt->xa, res->id, RESTRACK_DD);

[...]

Applied, thanks!

[1/1] RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert()

      https://git.kernel.org/rdma/rdma/c/391c5d826fd0a5

Best regards,

Signature · 1 line
Leon Romanovsky <[email protected]>