From: Bob Pearson <rpearsonhpe@gmail.com>
To: jgg@nvidia.com, zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org
Cc: Bob Pearson <rpearson@hpe.com>,
syzbot+ec2fd72374785d0e558e@syzkaller.appspotmail.com
Subject: [PATCH for-next 1/5] RDMA/rxe: Fix bug in rxe_alloc
Date: Thu, 21 Jan 2021 22:23:09 -0600 [thread overview]
Message-ID: <20210122042313.3336-2-rpearson@hpe.com> (raw)
In-Reply-To: <20210122042313.3336-1-rpearson@hpe.com>
A recent patch which added an 'unlocked' version of rxe_alloc
introduced a bug causing kzalloc(..., GFP_KERNEL) to be called
while holding a spin lock. This patch corrects that error.
rxe_alloc_nl() should always be called while holding the pool->pool_lock
so the 2nd argument to kzalloc there should be GFP_ATOMIC.
rxe_alloc() prior to the change only locked the code around checking
that pool->state is RXE_POOL_STATE_VALID to avoid races between
working threads and a thread shutting down the rxe driver. This patch
reverts rxe_alloc() to this behavior so the lock is not held when
kzalloc() is called.
Reported-by: syzbot+ec2fd72374785d0e558e@syzkaller.appspotmail.com
Fixes: 3853c35e243d ("RDMA/rxe: Add unlocked versions of pool APIs")
Signed-off-by: Bob Pearson <rpearson@hpe.com>
---
drivers/infiniband/sw/rxe/rxe_pool.c | 41 ++++++++++++++++++++++++----
1 file changed, 35 insertions(+), 6 deletions(-)
diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
index d26730eec720..cfcd55175572 100644
--- a/drivers/infiniband/sw/rxe/rxe_pool.c
+++ b/drivers/infiniband/sw/rxe/rxe_pool.c
@@ -343,8 +343,6 @@ void *rxe_alloc_nl(struct rxe_pool *pool)
struct rxe_pool_entry *elem;
u8 *obj;
- might_sleep_if(!(pool->flags & RXE_POOL_ATOMIC));
-
if (pool->state != RXE_POOL_STATE_VALID)
return NULL;
@@ -356,8 +354,7 @@ void *rxe_alloc_nl(struct rxe_pool *pool)
if (atomic_inc_return(&pool->num_elem) > pool->max_elem)
goto out_cnt;
- obj = kzalloc(info->size, (pool->flags & RXE_POOL_ATOMIC) ?
- GFP_ATOMIC : GFP_KERNEL);
+ obj = kzalloc(info->size, GFP_ATOMIC);
if (!obj)
goto out_cnt;
@@ -378,14 +375,46 @@ void *rxe_alloc_nl(struct rxe_pool *pool)
void *rxe_alloc(struct rxe_pool *pool)
{
- u8 *obj;
unsigned long flags;
+ struct rxe_type_info *info = &rxe_type_info[pool->type];
+ struct rxe_pool_entry *elem;
+ u8 *obj;
+
+ might_sleep_if(!(pool->flags & RXE_POOL_ATOMIC));
read_lock_irqsave(&pool->pool_lock, flags);
- obj = rxe_alloc_nl(pool);
+ if (pool->state != RXE_POOL_STATE_VALID) {
+ read_unlock_irqrestore(&pool->pool_lock, flags);
+ return NULL;
+ }
+
+ kref_get(&pool->ref_cnt);
read_unlock_irqrestore(&pool->pool_lock, flags);
+ if (!ib_device_try_get(&pool->rxe->ib_dev))
+ goto out_put_pool;
+
+ if (atomic_inc_return(&pool->num_elem) > pool->max_elem)
+ goto out_cnt;
+
+ obj = kzalloc(info->size, (pool->flags & RXE_POOL_ATOMIC) ?
+ GFP_ATOMIC : GFP_KERNEL);
+ if (!obj)
+ goto out_cnt;
+
+ elem = (struct rxe_pool_entry *)(obj + info->elem_offset);
+
+ elem->pool = pool;
+ kref_init(&elem->ref_cnt);
+
return obj;
+
+out_cnt:
+ atomic_dec(&pool->num_elem);
+ ib_device_put(&pool->rxe->ib_dev);
+out_put_pool:
+ rxe_pool_put(pool);
+ return NULL;
}
int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_entry *elem)
--
2.27.0
next prev parent reply other threads:[~2021-01-22 4:24 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-22 4:23 [PATCH for-next 0/5] RDMA/rxe: Fix rxe_alloc() bug Bob Pearson
2021-01-22 4:23 ` Bob Pearson [this message]
2021-01-22 4:23 ` [PATCH for-next 2/5] RDMA/rxe: Fix misleading comments and names Bob Pearson
2021-01-22 19:27 ` Jason Gunthorpe
2021-01-22 21:48 ` Pearson, Robert B
2021-01-25 15:15 ` Jason Gunthorpe
2021-01-22 4:23 ` [PATCH for-next 3/5] RDMA/rxe: Remove RXE_POOL_ATOMIC Bob Pearson
2021-01-22 4:23 ` [PATCH for-next 4/5] RDMA/rxe: Remove calls to ib_device_try_get/put Bob Pearson
2021-01-22 4:23 ` [PATCH for-next 5/5] RDMA/rxe: Remove unneeded pool->flag 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=20210122042313.3336-2-rpearson@hpe.com \
--to=rpearsonhpe@gmail.com \
--cc=jgg@nvidia.com \
--cc=linux-rdma@vger.kernel.org \
--cc=rpearson@hpe.com \
--cc=syzbot+ec2fd72374785d0e558e@syzkaller.appspotmail.com \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.