From: Bob Pearson <rpearsonhpe@gmail.com>
To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearsonhpe@gmail.com>
Subject: [PATCH for-next 3/6] RDMA/rxe: Save object pointer in pool element
Date: Sun, 10 Oct 2021 18:59:28 -0500 [thread overview]
Message-ID: <20211010235931.24042-4-rpearsonhpe@gmail.com> (raw)
In-Reply-To: <20211010235931.24042-1-rpearsonhpe@gmail.com>
In rxe_pool.c currently there are many cases where it is necessary to
compute the offset from a pool element struct to the object containing
the pool element in a type independent way. By saving a pointer to the
object when they are created extra work can be saved.
Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
---
drivers/infiniband/sw/rxe/rxe_pool.c | 16 +++++++++-------
drivers/infiniband/sw/rxe/rxe_pool.h | 1 +
2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
index e9d74ad3f0b7..4caaecdb0d68 100644
--- a/drivers/infiniband/sw/rxe/rxe_pool.c
+++ b/drivers/infiniband/sw/rxe/rxe_pool.c
@@ -337,6 +337,7 @@ void *rxe_alloc_locked(struct rxe_pool *pool)
elem = (struct rxe_pool_entry *)(obj + pool->elem_offset);
elem->pool = pool;
+ elem->obj = obj;
kref_init(&elem->ref_cnt);
return obj;
@@ -349,7 +350,7 @@ void *rxe_alloc_locked(struct rxe_pool *pool)
void *rxe_alloc(struct rxe_pool *pool)
{
unsigned long flags;
- u8 *obj;
+ void *obj;
write_lock_irqsave(&pool->pool_lock, flags);
obj = rxe_alloc_locked(pool);
@@ -364,6 +365,7 @@ int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_entry *elem)
goto out_cnt;
elem->pool = pool;
+ elem->obj = (u8 *)elem - pool->elem_offset;
kref_init(&elem->ref_cnt);
return 0;
@@ -378,13 +380,13 @@ void rxe_elem_release(struct kref *kref)
struct rxe_pool_entry *elem =
container_of(kref, struct rxe_pool_entry, ref_cnt);
struct rxe_pool *pool = elem->pool;
- u8 *obj;
+ void *obj;
if (pool->cleanup)
pool->cleanup(elem);
if (!(pool->flags & RXE_POOL_NO_ALLOC)) {
- obj = (u8 *)elem - pool->elem_offset;
+ obj = elem->obj;
kfree(obj);
}
@@ -395,7 +397,7 @@ void *rxe_pool_get_index_locked(struct rxe_pool *pool, u32 index)
{
struct rb_node *node;
struct rxe_pool_entry *elem;
- u8 *obj;
+ void *obj;
node = pool->index.tree.rb_node;
@@ -412,7 +414,7 @@ void *rxe_pool_get_index_locked(struct rxe_pool *pool, u32 index)
if (node) {
kref_get(&elem->ref_cnt);
- obj = (u8 *)elem - pool->elem_offset;
+ obj = elem->obj;
} else {
obj = NULL;
}
@@ -436,7 +438,7 @@ void *rxe_pool_get_key_locked(struct rxe_pool *pool, void *key)
{
struct rb_node *node;
struct rxe_pool_entry *elem;
- u8 *obj;
+ void *obj;
int cmp;
node = pool->key.tree.rb_node;
@@ -457,7 +459,7 @@ void *rxe_pool_get_key_locked(struct rxe_pool *pool, void *key)
if (node) {
kref_get(&elem->ref_cnt);
- obj = (u8 *)elem - pool->elem_offset;
+ obj = elem->obj;
} else {
obj = NULL;
}
diff --git a/drivers/infiniband/sw/rxe/rxe_pool.h b/drivers/infiniband/sw/rxe/rxe_pool.h
index cd962dc5de9d..570bda77f4a6 100644
--- a/drivers/infiniband/sw/rxe/rxe_pool.h
+++ b/drivers/infiniband/sw/rxe/rxe_pool.h
@@ -46,6 +46,7 @@ struct rxe_type_info {
struct rxe_pool_entry {
struct rxe_pool *pool;
+ void *obj;
struct kref ref_cnt;
struct list_head list;
--
2.30.2
next prev parent reply other threads:[~2021-10-10 23:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-10 23:59 [PATCH for-next 0/6] RDMA/rxe: Fix potential races Bob Pearson
2021-10-10 23:59 ` [PATCH for-next 1/6] RDMA/rxe: Make rxe_alloc() take pool lock Bob Pearson
2021-10-20 23:16 ` Jason Gunthorpe
2021-10-21 17:46 ` Bob Pearson
2021-10-25 12:43 ` Jason Gunthorpe
2021-10-25 18:48 ` Robert Pearson
2021-10-10 23:59 ` [PATCH for-next 2/6] RDMA/rxe: Copy setup parameters into rxe_pool Bob Pearson
2021-10-10 23:59 ` Bob Pearson [this message]
2021-10-20 23:20 ` [PATCH for-next 3/6] RDMA/rxe: Save object pointer in pool element Jason Gunthorpe
2021-10-21 17:21 ` Bob Pearson
2021-10-25 15:40 ` Jason Gunthorpe
2021-10-10 23:59 ` [PATCH for-next 4/6] RDMA/rxe: Combine rxe_add_index with rxe_alloc Bob Pearson
2021-10-10 23:59 ` [PATCH for-next 5/6] RDMA/rxe: Combine rxe_add_key " Bob Pearson
2021-10-10 23:59 ` [PATCH for-next 6/6] RDMA/rxe: Fix potential race condition in rxe_pool Bob Pearson
2021-10-20 23:23 ` Jason Gunthorpe
2021-10-12 6:34 ` [PATCH for-next 0/6] RDMA/rxe: Fix potential races Leon Romanovsky
2021-10-12 20:19 ` Bob Pearson
2021-10-19 13:07 ` Leon Romanovsky
2021-10-19 16:35 ` Bob Pearson
2021-10-19 18:43 ` Jason Gunthorpe
2021-10-19 22:51 ` Bob Pearson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211010235931.24042-4-rpearsonhpe@gmail.com \
--to=rpearsonhpe@gmail.com \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=zyjzyj2000@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).