From: Jason Gunthorpe <jgg@nvidia.com>
To: Bob Pearson <rpearsonhpe@gmail.com>
Cc: zyjzyj2000@gmail.com, linux-rdma@vger.kernel.org
Subject: Re: [PATCH v13 for-next 5/6] RDMA/rxe: For mcast copy qp list to temp array
Date: Wed, 23 Feb 2022 20:26:06 -0400 [thread overview]
Message-ID: <20220224002606.GB409228@nvidia.com> (raw)
In-Reply-To: <20220223230706.50332-6-rpearsonhpe@gmail.com>
On Wed, Feb 23, 2022 at 05:07:07PM -0600, Bob Pearson wrote:
> + /* this is the current number of qp's attached to mcg plus a
> + * little room in case new qp's are attached between here
> + * and when we finish walking the qp list. If someone can
> + * attach more than 4 new qp's we will miss forwarding
> + * packets to those qp's. This is actually OK since UD is
> + * a unreliable service.
> + */
> + nmax = atomic_read(&mcg->qp_num) + 4;
> + qp_array = kmalloc_array(nmax, sizeof(qp), GFP_KERNEL);
Check for allocation failure?
> + n = 0;
> spin_lock_bh(&rxe->mcg_lock);
> -
> - /* this is unreliable datagram service so we let
> - * failures to deliver a multicast packet to a
> - * single QP happen and just move on and try
> - * the rest of them on the list
> - */
> list_for_each_entry(mca, &mcg->qp_list, qp_list) {
> - qp = mca->qp;
> + /* protect the qp pointers in the list */
> + rxe_add_ref(mca->qp);
> + qp_array[n++] = mca->qp;
> + if (n == nmax)
> + break;
> + }
> + spin_unlock_bh(&rxe->mcg_lock);
So the issue here is this needs to iterate over the list, but doesn't
want to hold a spinlock while it does the actions?
Perhaps the better pattern is switch the qp list to an xarray (and
delete the mca entirely), then you can use xa_for_each here and avoid
the allocation. The advantage of xarray is that iteration is
safely restartable, so the locks can be dropped.
xa_lock()
xa_for_each(...) {
qp = mca->qp;
rxe_add_ref(qp);
xa_unlock();
[.. stuff without lock ..]
rxe_put_ref(qp)
xa_lock();
}
This would eliminate the rxe_mca entirely as the qp can be stored
directly in the xarray.
In most cases I suppose a mcg will have a small number of QP so this
should be much faster than the linked list, and especially than the
allocation.
And when I write it like the above you can see the RCU failure you
mentioned before is just symptom of a larger bug, ie if RXE is doing
the above and replicating packets at the same instant that close
happens it will hit that WARN_ON as well since the qp ref is
temporarily elevated.
The only way to fully fix that bug is to properly wait for all
transient users of the QP to be finished before allowing the QP to be
destroyed.
But at least this version would make it not happen so reliably and
things can move on.
Jason
next prev parent reply other threads:[~2022-02-24 0:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-23 23:07 [PATCH for-next v13 0/6] Move two object pools to rxe_mcast.c Bob Pearson
2022-02-23 23:07 ` [PATCH for-next v13 1/6] RDMA/rxe: Warn if mcast memory is not freed Bob Pearson
2022-02-23 23:07 ` [PATCH v13 for-next 2/6] RDMA/rxe: Collect mca init code in a subroutine Bob Pearson
2022-02-23 23:07 ` [PATCH for-next v13 3/6] RDMA/rxe: Collect cleanup mca " Bob Pearson
2022-02-23 23:07 ` [PATCH v13 for-next 4/6] RDMA/rxe: Cleanup rxe_mcast.c Bob Pearson
2022-02-23 23:07 ` [PATCH v13 for-next 5/6] RDMA/rxe: For mcast copy qp list to temp array Bob Pearson
2022-02-24 0:26 ` Jason Gunthorpe [this message]
2022-02-24 17:29 ` Bob Pearson
2022-02-23 23:07 ` [PATCH for-next v13 6/6] RDMA/rxe: Convert mca read locking to RCU Bob Pearson
2022-02-24 0:28 ` Jason Gunthorpe
2022-02-24 0:32 ` [PATCH for-next v13 0/6] 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=20220224002606.GB409228@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.