Commit 771addf6 authored by Matan Barak's avatar Matan Barak Committed by Doug Ledford

IB/core: Refactor idr to be per uverbs_file

The current code creates an idr per type. Since types are currently
common for all drivers and known in advance, this was good enough.
However, the proposed ioctl based infrastructure allows each driver
to declare only some of the common types and declare its own specific
types.

Thus, we decided to implement idr to be per uverbs_file.
Signed-off-by: default avatarMatan Barak <matanb@mellanox.com>
Signed-off-by: default avatarLeon Romanovsky <leonro@mellanox.com>
Signed-off-by: default avatarHaggai Eran <haggaie@mellanox.com>
Reviewed-by: default avatarSean Hefty <sean.hefty@intel.com>
Signed-off-by: default avatarDoug Ledford <dledford@redhat.com>
parent 97da3854
...@@ -123,6 +123,10 @@ struct ib_uverbs_file { ...@@ -123,6 +123,10 @@ struct ib_uverbs_file {
struct ib_uverbs_event_file *async_file; struct ib_uverbs_event_file *async_file;
struct list_head list; struct list_head list;
int is_closed; int is_closed;
struct idr idr;
/* spinlock protects write access to idr */
spinlock_t idr_lock;
}; };
struct ib_uverbs_event { struct ib_uverbs_event {
...@@ -176,20 +180,7 @@ struct ib_ucq_object { ...@@ -176,20 +180,7 @@ struct ib_ucq_object {
u32 async_events_reported; u32 async_events_reported;
}; };
extern spinlock_t ib_uverbs_idr_lock; void idr_remove_uobj(struct ib_uobject *uobj);
extern struct idr ib_uverbs_pd_idr;
extern struct idr ib_uverbs_mr_idr;
extern struct idr ib_uverbs_mw_idr;
extern struct idr ib_uverbs_ah_idr;
extern struct idr ib_uverbs_cq_idr;
extern struct idr ib_uverbs_qp_idr;
extern struct idr ib_uverbs_srq_idr;
extern struct idr ib_uverbs_xrcd_idr;
extern struct idr ib_uverbs_rule_idr;
extern struct idr ib_uverbs_wq_idr;
extern struct idr ib_uverbs_rwq_ind_tbl_idr;
void idr_remove_uobj(struct idr *idp, struct ib_uobject *uobj);
struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file, struct file *ib_uverbs_alloc_event_file(struct ib_uverbs_file *uverbs_file,
struct ib_device *ib_dev, struct ib_device *ib_dev,
......
This diff is collapsed.
...@@ -67,19 +67,6 @@ enum { ...@@ -67,19 +67,6 @@ enum {
static struct class *uverbs_class; static struct class *uverbs_class;
DEFINE_SPINLOCK(ib_uverbs_idr_lock);
DEFINE_IDR(ib_uverbs_pd_idr);
DEFINE_IDR(ib_uverbs_mr_idr);
DEFINE_IDR(ib_uverbs_mw_idr);
DEFINE_IDR(ib_uverbs_ah_idr);
DEFINE_IDR(ib_uverbs_cq_idr);
DEFINE_IDR(ib_uverbs_qp_idr);
DEFINE_IDR(ib_uverbs_srq_idr);
DEFINE_IDR(ib_uverbs_xrcd_idr);
DEFINE_IDR(ib_uverbs_rule_idr);
DEFINE_IDR(ib_uverbs_wq_idr);
DEFINE_IDR(ib_uverbs_rwq_ind_tbl_idr);
static DEFINE_SPINLOCK(map_lock); static DEFINE_SPINLOCK(map_lock);
static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES); static DECLARE_BITMAP(dev_map, IB_UVERBS_MAX_DEVICES);
...@@ -236,7 +223,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -236,7 +223,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) { list_for_each_entry_safe(uobj, tmp, &context->ah_list, list) {
struct ib_ah *ah = uobj->object; struct ib_ah *ah = uobj->object;
idr_remove_uobj(&ib_uverbs_ah_idr, uobj); idr_remove_uobj(uobj);
ib_destroy_ah(ah); ib_destroy_ah(ah);
ib_rdmacg_uncharge(&uobj->cg_obj, context->device, ib_rdmacg_uncharge(&uobj->cg_obj, context->device,
RDMACG_RESOURCE_HCA_OBJECT); RDMACG_RESOURCE_HCA_OBJECT);
...@@ -247,7 +234,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -247,7 +234,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
list_for_each_entry_safe(uobj, tmp, &context->mw_list, list) { list_for_each_entry_safe(uobj, tmp, &context->mw_list, list) {
struct ib_mw *mw = uobj->object; struct ib_mw *mw = uobj->object;
idr_remove_uobj(&ib_uverbs_mw_idr, uobj); idr_remove_uobj(uobj);
uverbs_dealloc_mw(mw); uverbs_dealloc_mw(mw);
ib_rdmacg_uncharge(&uobj->cg_obj, context->device, ib_rdmacg_uncharge(&uobj->cg_obj, context->device,
RDMACG_RESOURCE_HCA_OBJECT); RDMACG_RESOURCE_HCA_OBJECT);
...@@ -257,7 +244,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -257,7 +244,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
list_for_each_entry_safe(uobj, tmp, &context->rule_list, list) { list_for_each_entry_safe(uobj, tmp, &context->rule_list, list) {
struct ib_flow *flow_id = uobj->object; struct ib_flow *flow_id = uobj->object;
idr_remove_uobj(&ib_uverbs_rule_idr, uobj); idr_remove_uobj(uobj);
ib_destroy_flow(flow_id); ib_destroy_flow(flow_id);
ib_rdmacg_uncharge(&uobj->cg_obj, context->device, ib_rdmacg_uncharge(&uobj->cg_obj, context->device,
RDMACG_RESOURCE_HCA_OBJECT); RDMACG_RESOURCE_HCA_OBJECT);
...@@ -269,7 +256,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -269,7 +256,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
struct ib_uqp_object *uqp = struct ib_uqp_object *uqp =
container_of(uobj, struct ib_uqp_object, uevent.uobject); container_of(uobj, struct ib_uqp_object, uevent.uobject);
idr_remove_uobj(&ib_uverbs_qp_idr, uobj); idr_remove_uobj(uobj);
if (qp == qp->real_qp) if (qp == qp->real_qp)
ib_uverbs_detach_umcast(qp, uqp); ib_uverbs_detach_umcast(qp, uqp);
ib_destroy_qp(qp); ib_destroy_qp(qp);
...@@ -283,7 +270,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -283,7 +270,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
struct ib_rwq_ind_table *rwq_ind_tbl = uobj->object; struct ib_rwq_ind_table *rwq_ind_tbl = uobj->object;
struct ib_wq **ind_tbl = rwq_ind_tbl->ind_tbl; struct ib_wq **ind_tbl = rwq_ind_tbl->ind_tbl;
idr_remove_uobj(&ib_uverbs_rwq_ind_tbl_idr, uobj); idr_remove_uobj(uobj);
ib_destroy_rwq_ind_table(rwq_ind_tbl); ib_destroy_rwq_ind_table(rwq_ind_tbl);
kfree(ind_tbl); kfree(ind_tbl);
kfree(uobj); kfree(uobj);
...@@ -294,7 +281,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -294,7 +281,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
struct ib_uwq_object *uwq = struct ib_uwq_object *uwq =
container_of(uobj, struct ib_uwq_object, uevent.uobject); container_of(uobj, struct ib_uwq_object, uevent.uobject);
idr_remove_uobj(&ib_uverbs_wq_idr, uobj); idr_remove_uobj(uobj);
ib_destroy_wq(wq); ib_destroy_wq(wq);
ib_uverbs_release_uevent(file, &uwq->uevent); ib_uverbs_release_uevent(file, &uwq->uevent);
kfree(uwq); kfree(uwq);
...@@ -305,7 +292,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -305,7 +292,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
struct ib_uevent_object *uevent = struct ib_uevent_object *uevent =
container_of(uobj, struct ib_uevent_object, uobject); container_of(uobj, struct ib_uevent_object, uobject);
idr_remove_uobj(&ib_uverbs_srq_idr, uobj); idr_remove_uobj(uobj);
ib_destroy_srq(srq); ib_destroy_srq(srq);
ib_rdmacg_uncharge(&uobj->cg_obj, context->device, ib_rdmacg_uncharge(&uobj->cg_obj, context->device,
RDMACG_RESOURCE_HCA_OBJECT); RDMACG_RESOURCE_HCA_OBJECT);
...@@ -319,7 +306,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -319,7 +306,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
struct ib_ucq_object *ucq = struct ib_ucq_object *ucq =
container_of(uobj, struct ib_ucq_object, uobject); container_of(uobj, struct ib_ucq_object, uobject);
idr_remove_uobj(&ib_uverbs_cq_idr, uobj); idr_remove_uobj(uobj);
ib_destroy_cq(cq); ib_destroy_cq(cq);
ib_rdmacg_uncharge(&uobj->cg_obj, context->device, ib_rdmacg_uncharge(&uobj->cg_obj, context->device,
RDMACG_RESOURCE_HCA_OBJECT); RDMACG_RESOURCE_HCA_OBJECT);
...@@ -330,7 +317,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -330,7 +317,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) { list_for_each_entry_safe(uobj, tmp, &context->mr_list, list) {
struct ib_mr *mr = uobj->object; struct ib_mr *mr = uobj->object;
idr_remove_uobj(&ib_uverbs_mr_idr, uobj); idr_remove_uobj(uobj);
ib_dereg_mr(mr); ib_dereg_mr(mr);
ib_rdmacg_uncharge(&uobj->cg_obj, context->device, ib_rdmacg_uncharge(&uobj->cg_obj, context->device,
RDMACG_RESOURCE_HCA_OBJECT); RDMACG_RESOURCE_HCA_OBJECT);
...@@ -343,7 +330,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -343,7 +330,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
struct ib_uxrcd_object *uxrcd = struct ib_uxrcd_object *uxrcd =
container_of(uobj, struct ib_uxrcd_object, uobject); container_of(uobj, struct ib_uxrcd_object, uobject);
idr_remove_uobj(&ib_uverbs_xrcd_idr, uobj); idr_remove_uobj(uobj);
ib_uverbs_dealloc_xrcd(file->device, xrcd); ib_uverbs_dealloc_xrcd(file->device, xrcd);
kfree(uxrcd); kfree(uxrcd);
} }
...@@ -352,7 +339,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file, ...@@ -352,7 +339,7 @@ static int ib_uverbs_cleanup_ucontext(struct ib_uverbs_file *file,
list_for_each_entry_safe(uobj, tmp, &context->pd_list, list) { list_for_each_entry_safe(uobj, tmp, &context->pd_list, list) {
struct ib_pd *pd = uobj->object; struct ib_pd *pd = uobj->object;
idr_remove_uobj(&ib_uverbs_pd_idr, uobj); idr_remove_uobj(uobj);
ib_dealloc_pd(pd); ib_dealloc_pd(pd);
ib_rdmacg_uncharge(&uobj->cg_obj, context->device, ib_rdmacg_uncharge(&uobj->cg_obj, context->device,
RDMACG_RESOURCE_HCA_OBJECT); RDMACG_RESOURCE_HCA_OBJECT);
...@@ -986,6 +973,8 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp) ...@@ -986,6 +973,8 @@ static int ib_uverbs_open(struct inode *inode, struct file *filp)
} }
file->device = dev; file->device = dev;
spin_lock_init(&file->idr_lock);
idr_init(&file->idr);
file->ucontext = NULL; file->ucontext = NULL;
file->async_file = NULL; file->async_file = NULL;
kref_init(&file->ref); kref_init(&file->ref);
...@@ -1023,6 +1012,7 @@ static int ib_uverbs_close(struct inode *inode, struct file *filp) ...@@ -1023,6 +1012,7 @@ static int ib_uverbs_close(struct inode *inode, struct file *filp)
file->ucontext = NULL; file->ucontext = NULL;
} }
mutex_unlock(&file->cleanup_mutex); mutex_unlock(&file->cleanup_mutex);
idr_destroy(&file->idr);
mutex_lock(&file->device->lists_mutex); mutex_lock(&file->device->lists_mutex);
if (!file->is_closed) { if (!file->is_closed) {
...@@ -1396,13 +1386,6 @@ static void __exit ib_uverbs_cleanup(void) ...@@ -1396,13 +1386,6 @@ static void __exit ib_uverbs_cleanup(void)
unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES); unregister_chrdev_region(IB_UVERBS_BASE_DEV, IB_UVERBS_MAX_DEVICES);
if (overflow_maj) if (overflow_maj)
unregister_chrdev_region(overflow_maj, IB_UVERBS_MAX_DEVICES); unregister_chrdev_region(overflow_maj, IB_UVERBS_MAX_DEVICES);
idr_destroy(&ib_uverbs_pd_idr);
idr_destroy(&ib_uverbs_mr_idr);
idr_destroy(&ib_uverbs_mw_idr);
idr_destroy(&ib_uverbs_ah_idr);
idr_destroy(&ib_uverbs_cq_idr);
idr_destroy(&ib_uverbs_qp_idr);
idr_destroy(&ib_uverbs_srq_idr);
} }
module_init(ib_uverbs_init); module_init(ib_uverbs_init);
......
...@@ -1365,6 +1365,7 @@ struct ib_rdmacg_object { ...@@ -1365,6 +1365,7 @@ struct ib_rdmacg_object {
struct ib_ucontext { struct ib_ucontext {
struct ib_device *device; struct ib_device *device;
struct ib_uverbs_file *ufile;
struct list_head pd_list; struct list_head pd_list;
struct list_head mr_list; struct list_head mr_list;
struct list_head mw_list; struct list_head mw_list;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment