From: Jason Gunthorpe <jgg@nvidia.com>
To: Bob Pearson <rpearsonhpe@gmail.com>
Cc: zyjzyj2000@gmail.com, frank.zago@hpe.com, ian.ziemba@hpe.com,
jhack@hpe.com, linux-rdma@vger.kernel.org
Subject: Re: [PATCH for-next] RDMA/rxe: Fix potential race in rxe_pool_get_index
Date: Thu, 29 Jun 2023 20:18:53 -0300 [thread overview]
Message-ID: <ZJ4RXctDIYEhjnQ9@nvidia.com> (raw)
In-Reply-To: <20230629223023.84008-1-rpearsonhpe@gmail.com>
On Thu, Jun 29, 2023 at 05:30:24PM -0500, Bob Pearson wrote:
> Currently the lookup of an object from its index and taking a
> reference to the object are incorrectly protected by an rcu_read_lock
> but this does not make the xa_load and the kref_get combination an
> atomic operation.
>
> The various write operations need to share the xarray state in a
> mixture of user, soft irq and hard irq contexts so the xa_locking
> must support that.
>
> This patch replaces the xa locks with xa_lock_irqsave.
>
> Fixes: 3225717f6dfa ("RDMA/rxe: Replace red-black trees by xarrays")
> Signed-off-by: Bob Pearson <rpearsonhpe@gmail.com>
> ---
> drivers/infiniband/sw/rxe/rxe_pool.c | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/infiniband/sw/rxe/rxe_pool.c b/drivers/infiniband/sw/rxe/rxe_pool.c
> index 6215c6de3a84..f2b586249793 100644
> --- a/drivers/infiniband/sw/rxe/rxe_pool.c
> +++ b/drivers/infiniband/sw/rxe/rxe_pool.c
> @@ -119,8 +119,10 @@ void rxe_pool_cleanup(struct rxe_pool *pool)
> int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem,
> bool sleepable)
> {
> - int err;
> + struct xarray *xa = &pool->xa;
> + unsigned long flags;
> gfp_t gfp_flags;
> + int err;
>
> if (atomic_inc_return(&pool->num_elem) > pool->max_elem)
> goto err_cnt;
> @@ -138,8 +140,10 @@ int __rxe_add_to_pool(struct rxe_pool *pool, struct rxe_pool_elem *elem,
>
> if (sleepable)
> might_sleep();
> - err = xa_alloc_cyclic(&pool->xa, &elem->index, NULL, pool->limit,
> + xa_lock_irqsave(xa, flags);
> + err = __xa_alloc_cyclic(xa, &elem->index, NULL, pool->limit,
> &pool->next, gfp_flags);
> + xa_unlock_irqrestore(xa, flags);
This stuff doesn't make any sense, the non __ versions already take
the xa_lock internally.
Or is this because you need the save/restore version for some reason?
But that seems unrelated and there should be a lockdep oops to go
along with it showing the backtrace??
> @@ -154,15 +158,16 @@ void *rxe_pool_get_index(struct rxe_pool *pool, u32 index)
> {
> struct rxe_pool_elem *elem;
> struct xarray *xa = &pool->xa;
> + unsigned long flags;
> void *obj;
>
> - rcu_read_lock();
> + xa_lock_irqsave(xa, flags);
> elem = xa_load(xa, index);
> if (elem && kref_get_unless_zero(&elem->ref_cnt))
> obj = elem->obj;
> else
> obj = NULL;
> - rcu_read_unlock();
> + xa_unlock_irqrestore(xa, flags);
And this should be safe as long as the object is freed via RCU, so
what are you trying to fix?
Jason
next prev parent reply other threads:[~2023-06-29 23:19 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-29 22:30 [PATCH for-next] RDMA/rxe: Fix potential race in rxe_pool_get_index Bob Pearson
2023-06-29 23:18 ` Jason Gunthorpe [this message]
2023-06-30 15:33 ` Bob Pearson
2023-07-10 16:47 ` Jason Gunthorpe
2023-07-10 18:11 ` Bob Pearson
2023-07-10 18:15 ` Jason Gunthorpe
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=ZJ4RXctDIYEhjnQ9@nvidia.com \
--to=jgg@nvidia.com \
--cc=frank.zago@hpe.com \
--cc=ian.ziemba@hpe.com \
--cc=jhack@hpe.com \
--cc=linux-rdma@vger.kernel.org \
--cc=rpearsonhpe@gmail.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.