[openib-general] [PATCH] ib_addr: fix get/set gid alignment issues
Sean Hefty
sean.hefty at intel.com
Tue Jun 27 17:21:53 PDT 2006
The device address contains unsigned character arrays, which contain raw
GID addresses. The GIDs may not be naturally aligned, so do not cast
them to structures or unions.
Signed-off-by: Sean Hefty <sean.hefty at intel.com>
---
This fixes an alignment issue pointed out by Michael when adding MGID
support to the ib_addr module.
Index: include/rdma/ib_addr.h
===================================================================
--- include/rdma/ib_addr.h (revision 8224)
+++ include/rdma/ib_addr.h (working copy)
@@ -89,14 +89,16 @@ static inline void ib_addr_set_pkey(stru
dev_addr->broadcast[9] = (unsigned char) pkey;
}
-static inline union ib_gid *ib_addr_get_mgid(struct rdma_dev_addr *dev_addr)
+static inline void ib_addr_get_mgid(struct rdma_dev_addr *dev_addr,
+ union ib_gid *gid)
{
- return (union ib_gid *) (dev_addr->broadcast + 4);
+ memcpy(gid, dev_addr->broadcast + 4, sizeof *gid);
}
-static inline union ib_gid *ib_addr_get_sgid(struct rdma_dev_addr *dev_addr)
+static inline void ib_addr_get_sgid(struct rdma_dev_addr *dev_addr,
+ union ib_gid *gid)
{
- return (union ib_gid *) (dev_addr->src_dev_addr + 4);
+ memcpy(gid, dev_addr->src_dev_addr + 4, sizeof *gid);
}
static inline void ib_addr_set_sgid(struct rdma_dev_addr *dev_addr,
@@ -105,9 +107,10 @@ static inline void ib_addr_set_sgid(stru
memcpy(dev_addr->src_dev_addr + 4, gid, sizeof *gid);
}
-static inline union ib_gid *ib_addr_get_dgid(struct rdma_dev_addr *dev_addr)
+static inline void ib_addr_get_dgid(struct rdma_dev_addr *dev_addr,
+ union ib_gid *gid)
{
- return (union ib_gid *) (dev_addr->dst_dev_addr + 4);
+ memcpy(gid, dev_addr->dst_dev_addr + 4, sizeof *gid);
}
static inline void ib_addr_set_dgid(struct rdma_dev_addr *dev_addr,
Index: core/ucma_ib.c
===================================================================
--- core/ucma_ib.c (revision 8224)
+++ core/ucma_ib.c (working copy)
@@ -40,27 +40,27 @@ static int ucma_get_paths(struct rdma_cm
struct ib_sa_cursor *cursor;
struct ib_sa_path_rec *path;
struct ib_user_path_rec user_path;
- union ib_gid *gid;
+ union ib_gid gid;
int left, ret = 0;
u16 pkey;
if (!id->device)
return -ENODEV;
- gid = ib_addr_get_dgid(&id->route.addr.dev_addr);
+ ib_addr_get_dgid(&id->route.addr.dev_addr, &gid);
pkey = ib_addr_get_pkey(&id->route.addr.dev_addr);
- cursor = ib_create_path_cursor(id->device, id->port_num, gid);
+ cursor = ib_create_path_cursor(id->device, id->port_num, &gid);
if (IS_ERR(cursor))
return PTR_ERR(cursor);
- gid = ib_addr_get_sgid(&id->route.addr.dev_addr);
+ ib_addr_get_sgid(&id->route.addr.dev_addr, &gid);
left = *len;
*len = 0;
for (path = ib_get_next_sa_attr(&cursor); path;
path = ib_get_next_sa_attr(&cursor)) {
if (pkey == path->pkey &&
- !memcmp(gid, path->sgid.raw, sizeof *gid)) {
+ !memcmp(&gid, path->sgid.raw, sizeof gid)) {
if (paths) {
ib_copy_path_rec_to_user(&user_path, path);
if (copy_to_user(paths, &user_path,
Index: core/cma.c
===================================================================
--- core/cma.c (revision 8224)
+++ core/cma.c (working copy)
@@ -278,14 +278,14 @@ static void cma_detach_from_dev(struct r
static int cma_acquire_ib_dev(struct rdma_id_private *id_priv)
{
struct cma_device *cma_dev;
- union ib_gid *gid;
+ union ib_gid gid;
int ret = -ENODEV;
- gid = ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr);
+ ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid),
mutex_lock(&lock);
list_for_each_entry(cma_dev, &dev_list, list) {
- ret = ib_find_cached_gid(cma_dev->device, gid,
+ ret = ib_find_cached_gid(cma_dev->device, &gid,
&id_priv->id.port_num, NULL);
if (!ret) {
cma_attach_to_dev(id_priv, cma_dev);
@@ -1266,8 +1266,8 @@ static int cma_query_ib_route(struct rdm
struct ib_sa_path_rec path_rec;
memset(&path_rec, 0, sizeof path_rec);
- path_rec.sgid = *ib_addr_get_sgid(addr);
- path_rec.dgid = *ib_addr_get_dgid(addr);
+ ib_addr_get_sgid(addr, &path_rec.sgid);
+ ib_addr_get_dgid(addr, &path_rec.dgid);
path_rec.pkey = cpu_to_be16(ib_addr_get_pkey(addr));
path_rec.numb_path = 1;
@@ -1326,8 +1326,10 @@ static int cma_resolve_ib_route(struct r
goto err1;
}
+ ib_addr_get_sgid(addr, &route->path_rec->sgid);
+ ib_addr_get_dgid(addr, &route->path_rec->dgid);
ret = ib_get_path_rec(id_priv->id.device, id_priv->id.port_num,
- ib_addr_get_sgid(addr), ib_addr_get_dgid(addr),
+ &route->path_rec->sgid, &route->path_rec->dgid,
ib_addr_get_pkey(addr), route->path_rec);
if (!ret) {
route->num_paths = 1;
@@ -1463,7 +1465,7 @@ static int cma_bind_loopback(struct rdma
{
struct cma_device *cma_dev;
struct ib_port_attr port_attr;
- union ib_gid *gid;
+ union ib_gid gid;
u16 pkey;
int ret;
u8 p;
@@ -1484,8 +1486,7 @@ static int cma_bind_loopback(struct rdma
}
port_found:
- gid = ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr);
- ret = ib_get_cached_gid(cma_dev->device, p, 0, gid);
+ ret = ib_get_cached_gid(cma_dev->device, p, 0, &gid);
if (ret)
goto out;
@@ -1493,6 +1494,7 @@ port_found:
if (ret)
goto out;
+ ib_addr_set_sgid(&id_priv->id.route.addr.dev_addr, &gid);
ib_addr_set_pkey(&id_priv->id.route.addr.dev_addr, pkey);
id_priv->id.port_num = p;
cma_attach_to_dev(id_priv, cma_dev);
@@ -1539,6 +1541,7 @@ static int cma_resolve_loopback(struct r
{
struct cma_work *work;
struct sockaddr_in *src_in, *dst_in;
+ union ib_gid gid;
int ret;
work = kzalloc(sizeof *work, GFP_KERNEL);
@@ -1551,8 +1554,8 @@ static int cma_resolve_loopback(struct r
goto err;
}
- ib_addr_set_dgid(&id_priv->id.route.addr.dev_addr,
- ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr));
+ ib_addr_get_sgid(&id_priv->id.route.addr.dev_addr, &gid);
+ ib_addr_set_dgid(&id_priv->id.route.addr.dev_addr, &gid);
if (cma_zero_addr(&id_priv->id.route.addr.src_addr)) {
src_in = (struct sockaddr_in *)&id_priv->id.route.addr.src_addr;
@@ -2153,8 +2156,9 @@ static int cma_join_ib_multicast(struct
ib_sa_comp_mask comp_mask;
int ret;
+ ib_addr_get_mgid(dev_addr, &rec.mgid);
ret = ib_get_mcmember_rec(id_priv->id.device, id_priv->id.port_num,
- ib_addr_get_mgid(dev_addr), &rec);
+ &rec.mgid, &rec);
if (ret)
return ret;
@@ -2163,8 +2167,8 @@ static int cma_join_ib_multicast(struct
mc_map[8] = ib_addr_get_pkey(dev_addr) >> 8;
mc_map[9] = (unsigned char) ib_addr_get_pkey(dev_addr);
- rec.mgid = *(union ib_gid *) (mc_map + 4);
- rec.port_gid = *ib_addr_get_sgid(dev_addr);
+ memcpy(&rec.mgid.raw, mc_map + 4, sizeof rec.mgid);
+ ib_addr_get_sgid(dev_addr, &rec.port_gid);
rec.pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr));
rec.join_state = 1;
rec.qkey = sin->sin_addr.s_addr;
Index: core/ucma.c
===================================================================
--- core/ucma.c (revision 8224)
+++ core/ucma.c (working copy)
@@ -453,10 +453,10 @@ static void ucma_copy_ib_route(struct rd
switch (route->num_paths) {
case 0:
dev_addr = &route->addr.dev_addr;
- memcpy(&resp->ib_route[0].dgid, ib_addr_get_dgid(dev_addr),
- sizeof(union ib_gid));
- memcpy(&resp->ib_route[0].sgid, ib_addr_get_sgid(dev_addr),
- sizeof(union ib_gid));
+ ib_addr_get_dgid(dev_addr,
+ (union ib_gid *) &resp->ib_route[0].dgid);
+ ib_addr_get_sgid(dev_addr,
+ (union ib_gid *) &resp->ib_route[0].sgid);
resp->ib_route[0].pkey = cpu_to_be16(ib_addr_get_pkey(dev_addr));
break;
case 2:
More information about the general
mailing list