Commit c9f4c695 authored by Bob Pearson's avatar Bob Pearson Committed by Jason Gunthorpe

RDMA/rxe: Reverse the sense of RXE_POOL_NO_ALLOC

There is only one remaining object type that allocates its own memory,
that is mr. So the sense of RXE_POOL_NO_ALLOC is changed to
RXE_POOL_ALLOC. Add checks to rxe_alloc() and rxe_add_to_pool() to make
sure the correct call is used for the setting of this flag.

Link: https://lore.kernel.org/r/20220304000808.225811-4-rpearsonhpe@gmail.comSigned-off-by: default avatarBob Pearson <rpearsonhpe@gmail.com>
Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
parent 8a1a0be8
...@@ -21,19 +21,17 @@ static const struct rxe_type_info { ...@@ -21,19 +21,17 @@ static const struct rxe_type_info {
.name = "rxe-uc", .name = "rxe-uc",
.size = sizeof(struct rxe_ucontext), .size = sizeof(struct rxe_ucontext),
.elem_offset = offsetof(struct rxe_ucontext, elem), .elem_offset = offsetof(struct rxe_ucontext, elem),
.flags = RXE_POOL_NO_ALLOC,
}, },
[RXE_TYPE_PD] = { [RXE_TYPE_PD] = {
.name = "rxe-pd", .name = "rxe-pd",
.size = sizeof(struct rxe_pd), .size = sizeof(struct rxe_pd),
.elem_offset = offsetof(struct rxe_pd, elem), .elem_offset = offsetof(struct rxe_pd, elem),
.flags = RXE_POOL_NO_ALLOC,
}, },
[RXE_TYPE_AH] = { [RXE_TYPE_AH] = {
.name = "rxe-ah", .name = "rxe-ah",
.size = sizeof(struct rxe_ah), .size = sizeof(struct rxe_ah),
.elem_offset = offsetof(struct rxe_ah, elem), .elem_offset = offsetof(struct rxe_ah, elem),
.flags = RXE_POOL_INDEX | RXE_POOL_NO_ALLOC, .flags = RXE_POOL_INDEX,
.min_index = RXE_MIN_AH_INDEX, .min_index = RXE_MIN_AH_INDEX,
.max_index = RXE_MAX_AH_INDEX, .max_index = RXE_MAX_AH_INDEX,
}, },
...@@ -41,7 +39,7 @@ static const struct rxe_type_info { ...@@ -41,7 +39,7 @@ static const struct rxe_type_info {
.name = "rxe-srq", .name = "rxe-srq",
.size = sizeof(struct rxe_srq), .size = sizeof(struct rxe_srq),
.elem_offset = offsetof(struct rxe_srq, elem), .elem_offset = offsetof(struct rxe_srq, elem),
.flags = RXE_POOL_INDEX | RXE_POOL_NO_ALLOC, .flags = RXE_POOL_INDEX,
.min_index = RXE_MIN_SRQ_INDEX, .min_index = RXE_MIN_SRQ_INDEX,
.max_index = RXE_MAX_SRQ_INDEX, .max_index = RXE_MAX_SRQ_INDEX,
}, },
...@@ -50,7 +48,7 @@ static const struct rxe_type_info { ...@@ -50,7 +48,7 @@ static const struct rxe_type_info {
.size = sizeof(struct rxe_qp), .size = sizeof(struct rxe_qp),
.elem_offset = offsetof(struct rxe_qp, elem), .elem_offset = offsetof(struct rxe_qp, elem),
.cleanup = rxe_qp_cleanup, .cleanup = rxe_qp_cleanup,
.flags = RXE_POOL_INDEX | RXE_POOL_NO_ALLOC, .flags = RXE_POOL_INDEX,
.min_index = RXE_MIN_QP_INDEX, .min_index = RXE_MIN_QP_INDEX,
.max_index = RXE_MAX_QP_INDEX, .max_index = RXE_MAX_QP_INDEX,
}, },
...@@ -58,7 +56,6 @@ static const struct rxe_type_info { ...@@ -58,7 +56,6 @@ static const struct rxe_type_info {
.name = "rxe-cq", .name = "rxe-cq",
.size = sizeof(struct rxe_cq), .size = sizeof(struct rxe_cq),
.elem_offset = offsetof(struct rxe_cq, elem), .elem_offset = offsetof(struct rxe_cq, elem),
.flags = RXE_POOL_NO_ALLOC,
.cleanup = rxe_cq_cleanup, .cleanup = rxe_cq_cleanup,
}, },
[RXE_TYPE_MR] = { [RXE_TYPE_MR] = {
...@@ -66,7 +63,7 @@ static const struct rxe_type_info { ...@@ -66,7 +63,7 @@ static const struct rxe_type_info {
.size = sizeof(struct rxe_mr), .size = sizeof(struct rxe_mr),
.elem_offset = offsetof(struct rxe_mr, elem), .elem_offset = offsetof(struct rxe_mr, elem),
.cleanup = rxe_mr_cleanup, .cleanup = rxe_mr_cleanup,
.flags = RXE_POOL_INDEX, .flags = RXE_POOL_INDEX | RXE_POOL_ALLOC,
.min_index = RXE_MIN_MR_INDEX, .min_index = RXE_MIN_MR_INDEX,
.max_index = RXE_MAX_MR_INDEX, .max_index = RXE_MAX_MR_INDEX,
}, },
...@@ -75,7 +72,7 @@ static const struct rxe_type_info { ...@@ -75,7 +72,7 @@ static const struct rxe_type_info {
.size = sizeof(struct rxe_mw), .size = sizeof(struct rxe_mw),
.elem_offset = offsetof(struct rxe_mw, elem), .elem_offset = offsetof(struct rxe_mw, elem),
.cleanup = rxe_mw_cleanup, .cleanup = rxe_mw_cleanup,
.flags = RXE_POOL_INDEX | RXE_POOL_NO_ALLOC, .flags = RXE_POOL_INDEX,
.min_index = RXE_MIN_MW_INDEX, .min_index = RXE_MIN_MW_INDEX,
.max_index = RXE_MAX_MW_INDEX, .max_index = RXE_MAX_MW_INDEX,
}, },
...@@ -264,6 +261,9 @@ void *rxe_alloc(struct rxe_pool *pool) ...@@ -264,6 +261,9 @@ void *rxe_alloc(struct rxe_pool *pool)
struct rxe_pool_elem *elem; struct rxe_pool_elem *elem;
void *obj; void *obj;
if (WARN_ON(!(pool->flags & RXE_POOL_ALLOC)))
return NULL;
if (atomic_inc_return(&pool->num_elem) > pool->max_elem) if (atomic_inc_return(&pool->num_elem) > pool->max_elem)
goto out_cnt; goto out_cnt;
...@@ -286,6 +286,9 @@ void *rxe_alloc(struct rxe_pool *pool) ...@@ -286,6 +286,9 @@ void *rxe_alloc(struct rxe_pool *pool)
int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem) int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem)
{ {
if (WARN_ON(pool->flags & RXE_POOL_ALLOC))
return -EINVAL;
if (atomic_inc_return(&pool->num_elem) > pool->max_elem) if (atomic_inc_return(&pool->num_elem) > pool->max_elem)
goto out_cnt; goto out_cnt;
...@@ -310,7 +313,7 @@ void rxe_elem_release(struct kref *kref) ...@@ -310,7 +313,7 @@ void rxe_elem_release(struct kref *kref)
if (pool->cleanup) if (pool->cleanup)
pool->cleanup(elem); pool->cleanup(elem);
if (!(pool->flags & RXE_POOL_NO_ALLOC)) { if (pool->flags & RXE_POOL_ALLOC) {
obj = elem->obj; obj = elem->obj;
kfree(obj); kfree(obj);
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
enum rxe_pool_flags { enum rxe_pool_flags {
RXE_POOL_INDEX = BIT(1), RXE_POOL_INDEX = BIT(1),
RXE_POOL_NO_ALLOC = BIT(4), RXE_POOL_ALLOC = BIT(2),
}; };
enum rxe_elem_type { enum rxe_elem_type {
......
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