All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert()
@ 2026-09-16  7:30 lirongqing
  2026-09-16  7:36 ` sashiko-bot
  2026-09-18 12:49 ` Leon Romanovsky
  0 siblings, 2 replies; 3+ messages in thread
From: lirongqing @ 2026-09-16  7:30 UTC (permalink / raw)
  To: Jason Gunthorpe, Leon Romanovsky, Li RongQing, Patrisious Haddad,
	Kees Cook, Yonatan Nachum, Kalesh AP, Chiara Meiohas, linux-rdma,
	linux-kernel

From: Li RongQing <lirongqing@baidu.com>

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")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 drivers/infiniband/core/restrack.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c
index f89a81d..a8b838f 100644
--- a/drivers/infiniband/core/restrack.c
+++ b/drivers/infiniband/core/restrack.c
@@ -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 */
-- 
2.9.4


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

* Re: [PATCH] RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert()
  2026-09-16  7:30 [PATCH] RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert() lirongqing
@ 2026-09-16  7:36 ` sashiko-bot
  2026-09-18 12:49 ` Leon Romanovsky
  1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-09-16  7:36 UTC (permalink / raw)
  To: lirongqing; +Cc: linux-rdma

> From: Li RongQing <lirongqing@baidu.com>
> 
> 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")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>

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

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260916073042.1746-1-lirongqing@baidu.com?part=1


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

* Re: [PATCH] RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert()
  2026-09-16  7:30 [PATCH] RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert() lirongqing
  2026-09-16  7:36 ` sashiko-bot
@ 2026-09-18 12:49 ` Leon Romanovsky
  1 sibling, 0 replies; 3+ messages in thread
From: Leon Romanovsky @ 2026-09-18 12:49 UTC (permalink / raw)
  To: Jason Gunthorpe, Patrisious Haddad, Kees Cook, Yonatan Nachum,
	Kalesh AP, Chiara Meiohas, linux-rdma, linux-kernel, lirongqing


On Wed, 16 Sep 2026 15:30:42 +0800, lirongqing wrote:
> 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,
-- 
Leon Romanovsky <leon@kernel.org>


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

end of thread, other threads:[~2026-09-18 12:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-16  7:30 [PATCH] RDMA/restrack: Don't set RESTRACK_DD mark after a failed xa_insert() lirongqing
2026-09-16  7:36 ` sashiko-bot
2026-09-18 12:49 ` Leon Romanovsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.