From: Leon Romanovsky <leonro@xxxxxxxxxxxx> Conversion to XArray allows us to mark specific entry with custom flags, in our case we need to distinguish between user vs. kernel entries, so drop custom boolean flag used before in favour of XAarray mark feature. Signed-off-by: Leon Romanovsky <leonro@xxxxxxxxxxxx> --- drivers/infiniband/core/restrack.c | 46 ++++++++++++++++++------------ include/rdma/restrack.h | 9 +----- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/drivers/infiniband/core/restrack.c b/drivers/infiniband/core/restrack.c index 5df8e4607f09..c50e95a82915 100644 --- a/drivers/infiniband/core/restrack.c +++ b/drivers/infiniband/core/restrack.c @@ -232,42 +232,29 @@ static void rdma_restrack_add(struct rdma_restrack_entry *res) { struct ib_device *dev = res_to_dev(res); struct xarray *xa = rdma_dev_to_xa(dev, res->type); - unsigned long id; int ret; - if (!dev) - return; - - if (res->type != RDMA_RESTRACK_CM_ID || rdma_is_kernel_res(res)) - res->task = NULL; - - if (!rdma_is_kernel_res(res)) { - if (!res->task) - rdma_restrack_set_task(res, NULL); - res->kern_name = NULL; - } else { - set_kern_name(res); - } - kref_init(&res->kref); init_completion(&res->comp); res->valid = true; - id = res_to_id(res); - ret = xa_insert(xa, id, res, GFP_KERNEL); + ret = xa_insert(xa, res_to_id(res), res, GFP_KERNEL); WARN_ONCE(ret == -EEXIST, "Tried to add non-unique type %d entry\n", res->type); if (ret) res->valid = false; } +#define RES_USER_ENTRY XA_MARK_1 + /** * rdma_restrack_kadd() - add kernel object to the reource tracking database * @res: resource entry */ void rdma_restrack_kadd(struct rdma_restrack_entry *res) { - res->user = false; + res->task = NULL; + set_kern_name(res); rdma_restrack_add(res); } EXPORT_SYMBOL(rdma_restrack_kadd); @@ -278,11 +265,32 @@ EXPORT_SYMBOL(rdma_restrack_kadd); */ void rdma_restrack_uadd(struct rdma_restrack_entry *res) { - res->user = true; + struct ib_device *dev = res_to_dev(res); + struct xarray *xa = rdma_dev_to_xa(dev, res->type); + + if (res->type != RDMA_RESTRACK_CM_ID) + res->task = NULL; + + if (!res->task) + rdma_restrack_set_task(res, NULL); + res->kern_name = NULL; + rdma_restrack_add(res); + xa_set_mark(xa, res_to_id(res), RES_USER_ENTRY); } EXPORT_SYMBOL(rdma_restrack_uadd); +bool rdma_is_kernel_res(struct rdma_restrack_entry *res) +{ + struct ib_device *dev = res_to_dev(res); + struct xarray *xa; + + xa = rdma_dev_to_xa(dev, res->type); + + return !xa_get_mark(xa, res_to_id(res), RES_USER_ENTRY); +} +EXPORT_SYMBOL(rdma_is_kernel_res); + int __must_check rdma_restrack_get(struct rdma_restrack_entry *res) { return kref_get_unless_zero(&res->kref); diff --git a/include/rdma/restrack.h b/include/rdma/restrack.h index dbbce1b29b12..09cc4eff3f9d 100644 --- a/include/rdma/restrack.h +++ b/include/rdma/restrack.h @@ -89,10 +89,6 @@ struct rdma_restrack_entry { * @type: various objects in restrack database */ enum rdma_restrack_type type; - /** - * @user: user resource - */ - bool user; }; /** @@ -133,10 +129,7 @@ void rdma_restrack_del(struct rdma_restrack_entry *res); * rdma_is_kernel_res() - check the owner of resource * @res: resource entry */ -static inline bool rdma_is_kernel_res(struct rdma_restrack_entry *res) -{ - return !res->user; -} +bool rdma_is_kernel_res(struct rdma_restrack_entry *res); /** * rdma_restrack_get() - grab to protect resource from release -- 2.19.1