From: Jason Gunthorpe <jgg@nvidia.com>
To: Leon Romanovsky <leon@kernel.org>
Cc: Patrisious Haddad <phaddad@nvidia.com>,
linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org,
Mark Zhang <markzhang@nvidia.com>
Subject: Re: [PATCH rdma-next 1/2] RDMA/core: Add an rb_tree that stores cm_ids sorted by ifindex and remote IP
Date: Tue, 10 May 2022 20:56:37 -0300 [thread overview]
Message-ID: <20220510235637.GA1163656@nvidia.com> (raw)
In-Reply-To: <9594928bfa8c8996bfdb31bc575c289573fa5bfb.1649075034.git.leonro@nvidia.com>
On Mon, Apr 04, 2022 at 03:27:26PM +0300, Leon Romanovsky wrote:
> +static int compare_netdev_and_ip(int ifindex_a, struct sockaddr *sa,
> + int ifindex_b, struct sockaddr *sb)
> +{
> + if (ifindex_a != ifindex_b)
> + return ifindex_a - ifindex_b;
These subtraction tricks don't work if the value can overflow
INT_MAX - INT_MIN == undefined
> +static int cma_add_id_to_tree(struct rdma_id_private *node_id_priv)
> +{
> + struct rb_node **new = &id_table.rb_node, *parent = NULL;
This read of rb_node has to be under the spinlock
> + struct id_table_entry *this, *node;
> + struct rdma_id_private *id_priv;
> + unsigned long flags;
> + int result;
> +
> + node = kzalloc(sizeof(*node), GFP_KERNEL);
> + if (!node)
> + return -ENOMEM;
> +
> + spin_lock_irqsave(&id_table_lock, flags);
> + while (*new) {
> + this = container_of(*new, struct id_table_entry, rb_node);
Because rebalacing can alter the head
> + id_priv = list_first_entry(
> + &this->id_list, struct rdma_id_private, id_list_entry);
> + result = compare_netdev_and_ip(
> + node_id_priv->id.route.addr.dev_addr.bound_dev_if,
> + cma_dst_addr(node_id_priv),
> + id_priv->id.route.addr.dev_addr.bound_dev_if,
> + cma_dst_addr(id_priv));
This pattern keeps repeating, one of the arguments to compare should
just be the id_table_entry * and do the list_first/etc inside the
compare.
Jason
next prev parent reply other threads:[~2022-05-10 23:56 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-04 12:27 [PATCH rdma-next 0/2] Add gratuitous ARP support to RDMA-CM Leon Romanovsky
2022-04-04 12:27 ` [PATCH rdma-next 1/2] RDMA/core: Add an rb_tree that stores cm_ids sorted by ifindex and remote IP Leon Romanovsky
2022-05-10 23:56 ` Jason Gunthorpe [this message]
2022-04-04 12:27 ` [PATCH rdma-next 2/2] RDMA/core: Add a netevent notifier to cma Leon Romanovsky
2022-05-11 0:04 ` Jason Gunthorpe
2022-04-29 16:07 ` [PATCH rdma-next 0/2] Add gratuitous ARP support to RDMA-CM Olga Kornievskaia
2022-04-29 16:23 ` Leon Romanovsky
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=20220510235637.GA1163656@nvidia.com \
--to=jgg@nvidia.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=markzhang@nvidia.com \
--cc=phaddad@nvidia.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.