All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Gunthorpe <jgg@nvidia.com>
To: Bob Pearson <rpearsonhpe@gmail.com>
Cc: zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org
Subject: Re: [PATCH for-next v11 11/11] RDMA/rxe: Convert mca read locking to RCU
Date: Fri, 11 Feb 2022 16:09:38 -0400	[thread overview]
Message-ID: <20220211200938.GA669898@nvidia.com> (raw)
In-Reply-To: <20220208211644.123457-12-rpearsonhpe@gmail.com>

On Tue, Feb 08, 2022 at 03:16:45PM -0600, Bob Pearson wrote:
>  	/* check to see if the qp is already a member of the group */
> -	spin_lock_bh(&rxe->mcg_lock);
> -	list_for_each_entry(mca, &mcg->qp_list, qp_list) {
> +	rcu_read_lock();
> +	list_for_each_entry_rcu(mca, &mcg->qp_list, qp_list) {
>  		if (mca->qp == qp) {

The use of mca->qp protected by RCU isn't Ok..

Look at the free path:

> +static void __rxe_cleanup_mca_rcu(struct rxe_mca *mca, struct rxe_mcg *mcg)
>  {
> +	list_del_rcu(&mca->qp_list);
>  
>  	atomic_dec(&mcg->qp_num);
>  	atomic_dec(&mcg->rxe->mcg_attach);
>  	atomic_dec(&mca->qp->mcg_num);
>  	rxe_drop_ref(mca->qp);
>  
> +	kfree_rcu(mca);

So the mca deref won't segfault but mca->qp is garbage now since it
might have been freed and reallocated due to the rxe_drop_ref()

It looks easy enough to fix, just use a call_rcu to free the thing
instead of kfree_rcu and do the rxe_drop_ref, and maybe others, inside
the call_rcu function.

> diff --git a/drivers/infiniband/sw/rxe/rxe_recv.c b/drivers/infiniband/sw/rxe/rxe_recv.c
> index 9b21cbb22602..c2cab85c6576 100644
> +++ b/drivers/infiniband/sw/rxe/rxe_recv.c
> @@ -265,15 +265,15 @@ static void rxe_rcv_mcast_pkt(struct rxe_dev *rxe, struct sk_buff *skb)
>  	qp_array = kmalloc_array(nmax, sizeof(qp), GFP_KERNEL);
>  	n = 0;
>  
> -	spin_lock_bh(&rxe->mcg_lock);
> -	list_for_each_entry(mca, &mcg->qp_list, qp_list) {
> +	rcu_read_lock();
> +	list_for_each_entry_rcu(mca, &mcg->qp_list, qp_list) {
>  		/* protect the qp pointers in the list */
>  		rxe_add_ref(mca->qp);

And this one could use after free qp

If the mca->qp is guarenteed to have a valid refcount as above then it
is OK.

Jason

  reply	other threads:[~2022-02-11 20:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-08 21:16 [PATCH for-next v11 00/11] Move two object pools to rxe_mcast.c Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 01/11] RDMA/rxe: Move mcg_lock to rxe Bob Pearson
2022-02-11 19:00   ` Jason Gunthorpe
2022-02-11 19:27     ` Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 02/11] RDMA/rxe: Use kzmalloc/kfree for mca Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 03/11] RDMA/rxe: Replace grp by mcg, mce by mca Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 04/11] RDMA/rxe: Replace int num_qp by atomic_t qp_num Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 05/11] RDMA/rxe: Replace pool key by rxe->mcg_tree Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 06/11] RDMA/rxe: Remove key'ed object support Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 07/11] RDMA/rxe: Remove mcg from rxe pools Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 08/11] RDMA/rxe: Add code to cleanup mcast memory Bob Pearson
2022-02-11 18:43   ` Jason Gunthorpe
2022-02-11 19:36     ` Bob Pearson
2022-02-11 19:56       ` Jason Gunthorpe
2022-02-12  0:37         ` Bob Pearson
2022-02-14 17:41           ` Jason Gunthorpe
2022-02-08 21:16 ` [PATCH for-next v11 09/11] RDMA/rxe: Finish cleanup of rxe_mcast.c Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 10/11] RDMA/rxe: For mcast copy qp list to temp array Bob Pearson
2022-02-08 21:16 ` [PATCH for-next v11 11/11] RDMA/rxe: Convert mca read locking to RCU Bob Pearson
2022-02-11 20:09   ` Jason Gunthorpe [this message]
2022-02-11 20:04 ` [PATCH for-next v11 00/11] Move two object pools to rxe_mcast.c 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=20220211200938.GA669898@nvidia.com \
    --to=jgg@nvidia.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.