RDMA/cma: resolve to first active ib port
authorJack Wang <jinpu.wang@profitbricks.com>
Mon, 2 Jan 2017 12:20:44 +0000 (13:20 +0100)
committerDoug Ledford <dledford@redhat.com>
Fri, 13 Jan 2017 04:00:04 +0000 (23:00 -0500)
When we try to resolve a dest addr, if we don't give src addr,
cma core will try to resolve to our source ib device automatically.
The current logic only checks if a given port has the same
subnet_prefix as our dest, which is not enough if we use default
well known subnet_prefix on our active port, as it will be the same
as the subnet_prefix on inactive ports and we might match against
an inactive port by accident.  To resolve this, we should also check
if port is active before we resolve it as a suitable src address for
a given dest.

Signed-off-by: Jack Wang <jinpu.wang@profitbricks.com>
Reviewed-by: Michael Wang <yun.wang@profitbricks.com>
Acked-by: Sean Hefty <sean.hefty@intel.com>
Signed-off-by: Doug Ledford <dledford@redhat.com>
drivers/infiniband/core/cma.c

index e7dcfac877ca2eb7b86601a9115b4c2fc27f4c01..40e2b726aa0268caf5b4dce62b65bdca36694797 100644 (file)
@@ -709,6 +709,7 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
        union ib_gid gid, sgid, *dgid;
        u16 pkey, index;
        u8 p;
+       enum ib_port_state port_state;
        int i;
 
        cma_dev = NULL;
@@ -724,6 +725,8 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
                        if (ib_find_cached_pkey(cur_dev->device, p, pkey, &index))
                                continue;
 
+                       if (ib_get_cached_port_state(cur_dev->device, p, &port_state))
+                               continue;
                        for (i = 0; !ib_get_cached_gid(cur_dev->device, p, i,
                                                       &gid, NULL);
                             i++) {
@@ -735,7 +738,8 @@ static int cma_resolve_ib_dev(struct rdma_id_private *id_priv)
                                }
 
                                if (!cma_dev && (gid.global.subnet_prefix ==
-                                                dgid->global.subnet_prefix)) {
+                                   dgid->global.subnet_prefix) &&
+                                   port_state == IB_PORT_ACTIVE) {
                                        cma_dev = cur_dev;
                                        sgid = gid;
                                        id_priv->id.port_num = p;