Skip to content

Commit

Permalink
RDMA/siw: Fabricate a GID on tun and loopback devices
Browse files Browse the repository at this point in the history
[ Upstream commit bad5b6e ]

LOOPBACK and NONE (tunnel) devices have all-zero MAC addresses.
Currently, siw_device_create() falls back to copying the IB device's
name in those cases, because an all-zero MAC address breaks the RDMA
core address resolution mechanism.

However, at the point when siw_device_create() constructs a GID, the
ib_device::name field is uninitialized, leaving the MAC address to
remain in an all-zero state.

Fabricate a random artificial GID for such devices, and ensure this
artificial GID is returned for all device query operations.

Link: https://lore.kernel.org/r/168960673260.3007.12378736853793339110.stgit@manet.1015granger.net
Reported-by: Tom Talpey <tom@talpey.com>
Fixes: a2d36b0 ("RDMA/siw: Enable siw on tunnel devices")
Reviewed-by: Bernard Metzler <bmt@zurich.ibm.com>
Reviewed-by: Tom Talpey <tom@talpey.com>
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
chucklever authored and gregkh committed Sep 13, 2023
1 parent a96892a commit 79a1a8f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
1 change: 1 addition & 0 deletions drivers/infiniband/sw/siw/siw.h
Expand Up @@ -74,6 +74,7 @@ struct siw_device {

u32 vendor_part_id;
int numa_node;
char raw_gid[ETH_ALEN];

/* physical port state (only one port per device) */
enum ib_port_state state;
Expand Down
22 changes: 8 additions & 14 deletions drivers/infiniband/sw/siw/siw_main.c
Expand Up @@ -75,8 +75,7 @@ static int siw_device_register(struct siw_device *sdev, const char *name)
return rv;
}

siw_dbg(base_dev, "HWaddr=%pM\n", sdev->netdev->dev_addr);

siw_dbg(base_dev, "HWaddr=%pM\n", sdev->raw_gid);
return 0;
}

Expand Down Expand Up @@ -313,24 +312,19 @@ static struct siw_device *siw_device_create(struct net_device *netdev)
return NULL;

base_dev = &sdev->base_dev;

sdev->netdev = netdev;

if (netdev->type != ARPHRD_LOOPBACK && netdev->type != ARPHRD_NONE) {
addrconf_addr_eui48((unsigned char *)&base_dev->node_guid,
netdev->dev_addr);
if (netdev->addr_len) {
memcpy(sdev->raw_gid, netdev->dev_addr,
min_t(unsigned int, netdev->addr_len, ETH_ALEN));
} else {
/*
* This device does not have a HW address,
* but connection mangagement lib expects gid != 0
* This device does not have a HW address, but
* connection mangagement requires a unique gid.
*/
size_t len = min_t(size_t, strlen(base_dev->name), 6);
char addr[6] = { };

memcpy(addr, base_dev->name, len);
addrconf_addr_eui48((unsigned char *)&base_dev->node_guid,
addr);
eth_random_addr(sdev->raw_gid);
}
addrconf_addr_eui48((u8 *)&base_dev->node_guid, sdev->raw_gid);

base_dev->uverbs_cmd_mask |= BIT_ULL(IB_USER_VERBS_CMD_POST_SEND);

Expand Down
4 changes: 2 additions & 2 deletions drivers/infiniband/sw/siw/siw_verbs.c
Expand Up @@ -157,7 +157,7 @@ int siw_query_device(struct ib_device *base_dev, struct ib_device_attr *attr,
attr->vendor_part_id = sdev->vendor_part_id;

addrconf_addr_eui48((u8 *)&attr->sys_image_guid,
sdev->netdev->dev_addr);
sdev->raw_gid);

return 0;
}
Expand Down Expand Up @@ -218,7 +218,7 @@ int siw_query_gid(struct ib_device *base_dev, u32 port, int idx,

/* subnet_prefix == interface_id == 0; */
memset(gid, 0, sizeof(*gid));
memcpy(&gid->raw[0], sdev->netdev->dev_addr, 6);
memcpy(gid->raw, sdev->raw_gid, ETH_ALEN);

return 0;
}
Expand Down

0 comments on commit 79a1a8f

Please sign in to comment.