Skip to content

Commit c9f4c69

Browse files
rpearsonhpe-designjgunthorpe
authored andcommitted
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.com Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent 8a1a0be commit c9f4c69

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

drivers/infiniband/sw/rxe/rxe_pool.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,25 @@ static const struct rxe_type_info {
2121
.name = "rxe-uc",
2222
.size = sizeof(struct rxe_ucontext),
2323
.elem_offset = offsetof(struct rxe_ucontext, elem),
24-
.flags = RXE_POOL_NO_ALLOC,
2524
},
2625
[RXE_TYPE_PD] = {
2726
.name = "rxe-pd",
2827
.size = sizeof(struct rxe_pd),
2928
.elem_offset = offsetof(struct rxe_pd, elem),
30-
.flags = RXE_POOL_NO_ALLOC,
3129
},
3230
[RXE_TYPE_AH] = {
3331
.name = "rxe-ah",
3432
.size = sizeof(struct rxe_ah),
3533
.elem_offset = offsetof(struct rxe_ah, elem),
36-
.flags = RXE_POOL_INDEX | RXE_POOL_NO_ALLOC,
34+
.flags = RXE_POOL_INDEX,
3735
.min_index = RXE_MIN_AH_INDEX,
3836
.max_index = RXE_MAX_AH_INDEX,
3937
},
4038
[RXE_TYPE_SRQ] = {
4139
.name = "rxe-srq",
4240
.size = sizeof(struct rxe_srq),
4341
.elem_offset = offsetof(struct rxe_srq, elem),
44-
.flags = RXE_POOL_INDEX | RXE_POOL_NO_ALLOC,
42+
.flags = RXE_POOL_INDEX,
4543
.min_index = RXE_MIN_SRQ_INDEX,
4644
.max_index = RXE_MAX_SRQ_INDEX,
4745
},
@@ -50,23 +48,22 @@ static const struct rxe_type_info {
5048
.size = sizeof(struct rxe_qp),
5149
.elem_offset = offsetof(struct rxe_qp, elem),
5250
.cleanup = rxe_qp_cleanup,
53-
.flags = RXE_POOL_INDEX | RXE_POOL_NO_ALLOC,
51+
.flags = RXE_POOL_INDEX,
5452
.min_index = RXE_MIN_QP_INDEX,
5553
.max_index = RXE_MAX_QP_INDEX,
5654
},
5755
[RXE_TYPE_CQ] = {
5856
.name = "rxe-cq",
5957
.size = sizeof(struct rxe_cq),
6058
.elem_offset = offsetof(struct rxe_cq, elem),
61-
.flags = RXE_POOL_NO_ALLOC,
6259
.cleanup = rxe_cq_cleanup,
6360
},
6461
[RXE_TYPE_MR] = {
6562
.name = "rxe-mr",
6663
.size = sizeof(struct rxe_mr),
6764
.elem_offset = offsetof(struct rxe_mr, elem),
6865
.cleanup = rxe_mr_cleanup,
69-
.flags = RXE_POOL_INDEX,
66+
.flags = RXE_POOL_INDEX | RXE_POOL_ALLOC,
7067
.min_index = RXE_MIN_MR_INDEX,
7168
.max_index = RXE_MAX_MR_INDEX,
7269
},
@@ -75,7 +72,7 @@ static const struct rxe_type_info {
7572
.size = sizeof(struct rxe_mw),
7673
.elem_offset = offsetof(struct rxe_mw, elem),
7774
.cleanup = rxe_mw_cleanup,
78-
.flags = RXE_POOL_INDEX | RXE_POOL_NO_ALLOC,
75+
.flags = RXE_POOL_INDEX,
7976
.min_index = RXE_MIN_MW_INDEX,
8077
.max_index = RXE_MAX_MW_INDEX,
8178
},
@@ -264,6 +261,9 @@ void *rxe_alloc(struct rxe_pool *pool)
264261
struct rxe_pool_elem *elem;
265262
void *obj;
266263

264+
if (WARN_ON(!(pool->flags & RXE_POOL_ALLOC)))
265+
return NULL;
266+
267267
if (atomic_inc_return(&pool->num_elem) > pool->max_elem)
268268
goto out_cnt;
269269

@@ -286,6 +286,9 @@ void *rxe_alloc(struct rxe_pool *pool)
286286

287287
int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem)
288288
{
289+
if (WARN_ON(pool->flags & RXE_POOL_ALLOC))
290+
return -EINVAL;
291+
289292
if (atomic_inc_return(&pool->num_elem) > pool->max_elem)
290293
goto out_cnt;
291294

@@ -310,7 +313,7 @@ void rxe_elem_release(struct kref *kref)
310313
if (pool->cleanup)
311314
pool->cleanup(elem);
312315

313-
if (!(pool->flags & RXE_POOL_NO_ALLOC)) {
316+
if (pool->flags & RXE_POOL_ALLOC) {
314317
obj = elem->obj;
315318
kfree(obj);
316319
}

drivers/infiniband/sw/rxe/rxe_pool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
enum rxe_pool_flags {
1111
RXE_POOL_INDEX = BIT(1),
12-
RXE_POOL_NO_ALLOC = BIT(4),
12+
RXE_POOL_ALLOC = BIT(2),
1313
};
1414

1515
enum rxe_elem_type {

0 commit comments

Comments
 (0)