Commit 8e5a9d61 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Jason Gunthorpe

ib core: Convert query_idr to XArray

Signed-off-by: default avatarMatthew Wilcox <willy@infradead.org>
Signed-off-by: default avatarJason Gunthorpe <jgg@mellanox.com>
parent ae78ff3a
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/kref.h> #include <linux/kref.h>
#include <linux/idr.h> #include <linux/xarray.h>
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <uapi/linux/if_ether.h> #include <uapi/linux/if_ether.h>
#include <rdma/ib_pack.h> #include <rdma/ib_pack.h>
...@@ -183,8 +183,7 @@ static struct ib_client sa_client = { ...@@ -183,8 +183,7 @@ static struct ib_client sa_client = {
.remove = ib_sa_remove_one .remove = ib_sa_remove_one
}; };
static DEFINE_SPINLOCK(idr_lock); static DEFINE_XARRAY_FLAGS(queries, XA_FLAGS_ALLOC | XA_FLAGS_LOCK_IRQ);
static DEFINE_IDR(query_idr);
static DEFINE_SPINLOCK(tid_lock); static DEFINE_SPINLOCK(tid_lock);
static u32 tid; static u32 tid;
...@@ -1180,14 +1179,14 @@ void ib_sa_cancel_query(int id, struct ib_sa_query *query) ...@@ -1180,14 +1179,14 @@ void ib_sa_cancel_query(int id, struct ib_sa_query *query)
struct ib_mad_agent *agent; struct ib_mad_agent *agent;
struct ib_mad_send_buf *mad_buf; struct ib_mad_send_buf *mad_buf;
spin_lock_irqsave(&idr_lock, flags); xa_lock_irqsave(&queries, flags);
if (idr_find(&query_idr, id) != query) { if (xa_load(&queries, id) != query) {
spin_unlock_irqrestore(&idr_lock, flags); xa_unlock_irqrestore(&queries, flags);
return; return;
} }
agent = query->port->agent; agent = query->port->agent;
mad_buf = query->mad_buf; mad_buf = query->mad_buf;
spin_unlock_irqrestore(&idr_lock, flags); xa_unlock_irqrestore(&queries, flags);
/* /*
* If the query is still on the netlink request list, schedule * If the query is still on the netlink request list, schedule
...@@ -1363,21 +1362,14 @@ static void init_mad(struct ib_sa_query *query, struct ib_mad_agent *agent) ...@@ -1363,21 +1362,14 @@ static void init_mad(struct ib_sa_query *query, struct ib_mad_agent *agent)
static int send_mad(struct ib_sa_query *query, unsigned long timeout_ms, static int send_mad(struct ib_sa_query *query, unsigned long timeout_ms,
gfp_t gfp_mask) gfp_t gfp_mask)
{ {
bool preload = gfpflags_allow_blocking(gfp_mask);
unsigned long flags; unsigned long flags;
int ret, id; int ret, id;
if (preload) xa_lock_irqsave(&queries, flags);
idr_preload(gfp_mask); ret = __xa_alloc(&queries, &id, query, xa_limit_32b, gfp_mask);
spin_lock_irqsave(&idr_lock, flags); xa_unlock_irqrestore(&queries, flags);
if (ret < 0)
id = idr_alloc(&query_idr, query, 0, 0, GFP_NOWAIT); return ret;
spin_unlock_irqrestore(&idr_lock, flags);
if (preload)
idr_preload_end();
if (id < 0)
return id;
query->mad_buf->timeout_ms = timeout_ms; query->mad_buf->timeout_ms = timeout_ms;
query->mad_buf->context[0] = query; query->mad_buf->context[0] = query;
...@@ -1394,9 +1386,9 @@ static int send_mad(struct ib_sa_query *query, unsigned long timeout_ms, ...@@ -1394,9 +1386,9 @@ static int send_mad(struct ib_sa_query *query, unsigned long timeout_ms,
ret = ib_post_send_mad(query->mad_buf, NULL); ret = ib_post_send_mad(query->mad_buf, NULL);
if (ret) { if (ret) {
spin_lock_irqsave(&idr_lock, flags); xa_lock_irqsave(&queries, flags);
idr_remove(&query_idr, id); __xa_erase(&queries, id);
spin_unlock_irqrestore(&idr_lock, flags); xa_unlock_irqrestore(&queries, flags);
} }
/* /*
...@@ -2188,9 +2180,9 @@ static void send_handler(struct ib_mad_agent *agent, ...@@ -2188,9 +2180,9 @@ static void send_handler(struct ib_mad_agent *agent,
break; break;
} }
spin_lock_irqsave(&idr_lock, flags); xa_lock_irqsave(&queries, flags);
idr_remove(&query_idr, query->id); __xa_erase(&queries, query->id);
spin_unlock_irqrestore(&idr_lock, flags); xa_unlock_irqrestore(&queries, flags);
free_mad(query); free_mad(query);
if (query->client) if (query->client)
...@@ -2475,5 +2467,5 @@ void ib_sa_cleanup(void) ...@@ -2475,5 +2467,5 @@ void ib_sa_cleanup(void)
destroy_workqueue(ib_nl_wq); destroy_workqueue(ib_nl_wq);
mcast_cleanup(); mcast_cleanup();
ib_unregister_client(&sa_client); ib_unregister_client(&sa_client);
idr_destroy(&query_idr); WARN_ON(!xa_empty(&queries));
} }
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