IB/core: Fix unaligned accesses
PATCH v2 1/1 IB/core: Fix unaligned accesses
Addresses the following kernel logs seen during boot of sparc systems:
Kernel unaligned access at TPC[103bce50] cm_find_listen+0x34/0xf8 [ib_cm] Kernel unaligned access at TPC[103bce50] cm_find_listen+0x34/0xf8 [ib_cm] Kernel unaligned access at TPC[103bce50] cm_find_listen+0x34/0xf8 [ib_cm] Kernel unaligned access at TPC[103bce50] cm_find_listen+0x34/0xf8 [ib_cm] Kernel unaligned access at TPC[103bce50] cm_find_listen+0x34/0xf8 [ib_cm]
Changed signature of cm_mask_copy from u8 to u32 as suggested by Jason Gunthorpe.
---
v2
- updated per Jason's comments
drivers/infiniband/core/cm.c | 17 ++++++++--------- include/rdma/ib_cm.h | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-)
drivers/infiniband/core/cm.c +8 -9
@@ -437,20 +437,19 @@ static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id)return cm_id_priv; } -static void cm_mask_copy (u8 *dst,u8 *src,u8 *mask) +static void cm_mask_copy (u32 *dst,u32 *src,u32 *mask) {int i; -for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (unsigned long ); i++) - ((unsigned long *) dst)[i] = ((unsigned long *) src)[i] & - ((unsigned long *) mask)[i]; +for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (u32); i++) + dst[i] = src[i] & mask[i]; }static int cm_compare_data (struct ib_cm_compare_data *src_data,struct ib_cm_compare_data *dst_data) { -u8 src[IB_CM_COMPARE_SIZE ]; -u8 dst[IB_CM_COMPARE_SIZE ]; +u32 src[IB_CM_COMPARE_SIZE ]; +u32 dst[IB_CM_COMPARE_SIZE ];if (!src_data || !dst_data)return 0 ;
@@ -460,10 +459,10 @@ static int cm_compare_data(struct ib_cm_compare_data *src_data,return memcmp (src, dst,IB_CM_COMPARE_SIZE ); } -static int cm_compare_private_data (u8 *private_data, +static int cm_compare_private_data (u32 *private_data,struct ib_cm_compare_data *dst_data) { -u8 src[IB_CM_COMPARE_SIZE ]; +u32 src[IB_CM_COMPARE_SIZE ];if (!dst_data)return 0 ;
@@ -546,7 +545,7 @@ static struct cm_id_private * cm_find_listen(struct ib_device *device,while (node) { cm_id_priv = rb_entry(node, struct cm_id_private, service_node); - data_cmp =cm_compare_private_data (private_data, + data_cmp =cm_compare_private_data ((u32 *) private_data, cm_id_priv->compare_data); if ((cm_id_priv->id.service_mask & service_id) == cm_id_priv->id.service_id &&
include/rdma/ib_cm.h +2 -2
@@ -337,8 +337,8 @@ void ib_destroy_cm_id(struct ib_cm_id *cm_id);#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)struct ib_cm_compare_data { -u8 data[IB_CM_COMPARE_SIZE ]; -u8 mask[IB_CM_COMPARE_SIZE ]; +u32 data[IB_CM_COMPARE_SIZE ]; +u32 mask[IB_CM_COMPARE_SIZE ]; };/**
Signature · 6 lines
2.3.0 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1430448168-38479-1-git-send-email-david.ahern-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org
Hi,
Quoted 38 lines · David Ahern
Addresses the following kernel logs seen during boot of sparc systems:
Kernel unaligned access at TPC[103bce50]
cm_find_listen+0x34/0xf8[ib_cm] Kernel unaligned access at TPC[103bce50]cm_find_listen+0x34/0xf8[ib_cm] Kernel unaligned access at TPC[103bce50]cm_find_listen+0x34/0xf8[ib_cm] Kernel unaligned access at TPC[103bce50]cm_find_listen+0x34/0xf8[ib_cm] Kernel unaligned access at TPC[103bce50]cm_find_listen+0x34/0xf8[ib_cm]Changed signature of
cm_mask_copyfrom u8 to u32 as suggested by Jason Gunthorpe.Signed-off-by David Ahern <[email protected]>---
v2
- updated per Jason's commentsdrivers/infiniband/core/cm.c | 17 ++++++++--------- include/rdma/ib_cm.h | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-)drivers/infiniband/core/cm.c +3
-4@@ -437,20 +437,19 @@ static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id)return cm_id_priv; } -static void cm_mask_copy (u8 *dst,u8 *src,u8 *mask) +static void cm_mask_copy (u32 *dst,u32 *src,u32 *mask) {int i; -for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (unsigned long ); i++) - ((unsigned long *) dst)[i] = ((unsigned long *) src)[i] & - ((unsigned long *) mask)[i]; +for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (u32); i++) + dst[i] = src[i] & mask[i];
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 453
Quoted 10 lines
drivers/infiniband/core/cm.c +2
-2}static int cm_compare_data (struct ib_cm_compare_data *src_data,struct ib_cm_compare_data *dst_data) { -u8 src[IB_CM_COMPARE_SIZE ]; -u8 dst[IB_CM_COMPARE_SIZE ]; +u32 src[IB_CM_COMPARE_SIZE ]; +u32 dst[IB_CM_COMPARE_SIZE ];
You have to change IB_CM_COMPARE_SIZE, as it's going to allocate more bytes than necessary.
Perhaps renaming IB_CM_COMPARE_SIZE to IB_CM_COMPARE_COUNT would be good, then remove the division by sizeof(u32).
Quoted 29 lines
drivers/infiniband/core/cm.c +3
-3if (!src_data || !dst_data)return 0 ;@@ -460,10 +459,10 @@ static int cm_compare_data(struct ib_cm_compare_data *src_data,return memcmp (src, dst,IB_CM_COMPARE_SIZE ); } -static int cm_compare_private_data (u8 *private_data, +static int cm_compare_private_data (u32 *private_data,struct ib_cm_compare_data *dst_data) { -u8 src[IB_CM_COMPARE_SIZE ]; +u32 src[IB_CM_COMPARE_SIZE ];if (!dst_data)return 0 ;@@ -546,7 +545,7 @@ static struct cm_id_private * cm_find_listen(struct ib_device *device,while (node) { cm_id_priv = rb_entry(node, struct cm_id_private, service_node); - data_cmp =cm_compare_private_data (private_data, + data_cmp =cm_compare_private_data ((u32 *) private_data, cm_id_priv->compare_data); if ((cm_id_priv->id.service_mask & service_id) == cm_id_priv->id.service_id &&include/rdma/ib_cm.h +0
-0
include/rdma/ib_cm.h void ib_destroy_cm_id(struct ib_cm_id *cm_id); · line 344
Quoted 10 lines
include/rdma/ib_cm.h +2
-2@@ -337,8 +337,8 @@ void ib_destroy_cm_id(struct ib_cm_id *cm_id);#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)struct ib_cm_compare_data { -u8 data[IB_CM_COMPARE_SIZE ]; -u8 mask[IB_CM_COMPARE_SIZE ]; +u32 data[IB_CM_COMPARE_SIZE ]; +u32 mask[IB_CM_COMPARE_SIZE ]; };/**
Anyway, you might want to compile this part of the kernel with -Wcast-align and ignore the false positive (in particular every other use of container_of()).
Regards.
Signature · 8 lines
Yann Droneaud OPTEYA -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 11 lines · Yann Droneaud
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 452
Quoted 8 lines
static int cm_compare_data(struct
ib_cm_compare_data*src_data,
structib_cm_compare_data*dst_data)
{drivers/infiniband/core/cm.c +2
-2-u8 src[IB_CM_COMPARE_SIZE ]; -u8 dst[IB_CM_COMPARE_SIZE ]; +u32 src[IB_CM_COMPARE_SIZE ]; +u32 dst[IB_CM_COMPARE_SIZE ];You have to change
IB_CM_COMPARE_SIZE, as it's going to allocate more bytes than necessary.
d'oh. yes, oversight. Thanks for pointing out.
Quoted 3 lines
Perhaps renaming
IB_CM_COMPARE_SIZEtoIB_CM_COMPARE_COUNTwould be good, then remove the division by sizeof(u32).
I feel like I stepped into a tar pit... It's a bit odd that IB_CM_COMPARE_SIZE is part of an enum rather than a #define.
It seems like the number of bytes being compared is what is relevant here; comparing by u32's or unsigned long's is the optimization. So, I'd prefer to leave it as SIZE.
If there are no objections I think the better thing to do is pull it out as:
/* compare's are done u32 at a time */
#define IB_CM_COMPARE_SIZE 64/sizeof(u32)
Quoted 14 lines
Quoted 14 lines
include/rdma/ib_cm.h +2
-2@@ -337,8 +337,8 @@ void ib_destroy_cm_id(struct ib_cm_id *cm_id);#define IB_SDP_SERVICE_ID_MASK cpu_to_be64(0xFFFFFFFFFFFF0000ULL)struct ib_cm_compare_data { -u8 data[IB_CM_COMPARE_SIZE ]; -u8 mask[IB_CM_COMPARE_SIZE ]; +u32 data[IB_CM_COMPARE_SIZE ]; +u32 mask[IB_CM_COMPARE_SIZE ]; };
Quoted 5 lines
include/rdma/ib_cm.h void ib_destroy_cm_id(struct ib_cm_id *cm_id); · line 344
Quoted 1 line
include/rdma/ib_cm.h +0
-0/** Anyway, you might want to compile this part of the kernel with -Wcast-align and ignore the false positive (in particular every other use of
container_of()).
Why?
David
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
In addition to Yann's comments:
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 440
Quoted 2 lines · David Ahern
drivers/infiniband/core/cm.c +1
-1-static void cm_mask_copy (u8 *dst,u8 *src,u8 *mask) +static void cm_mask_copy (u32 *dst,u32 *src,u32 *mask)
Please consider to constify the src and mask arguments.
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 445
Quoted 5 lines
drivers/infiniband/core/cm.c +2
-3-for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (unsigned long ); i++) - ((unsigned long *) dst)[i] = ((unsigned long *) src)[i] & - ((unsigned long *) mask)[i]; +for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (u32); i++) + dst[i] = src[i] & mask[i];
A single space after the equals sign is sufficient.
Thanks,
Bart.
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 8 lines · Bart Van Assche
In addition to Yann's comments:
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 440
Quoted 2 lines · David Ahern
drivers/infiniband/core/cm.c +1
-1-static void cm_mask_copy (u8 *dst,u8 *src,u8 *mask) +static void cm_mask_copy (u32 *dst,u32 *src,u32 *mask)Please consider to constify the src and mask arguments.
Quoted 8 lines
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 445
Quoted 5 lines
drivers/infiniband/core/cm.c +2
-3-for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (unsigned long ); i++) - ((unsigned long *) dst)[i] = ((unsigned long *) src)[i] & - ((unsigned long *) mask)[i]; +for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (u32); i++) + dst[i] = src[i] & mask[i];A single space after the equals sign is sufficient.
ack
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · David Ahern
Addresses the following kernel logs seen during boot of sparc systems:
Kernel unaligned access at TPC[103bce50]
cm_find_listen+0x34/0xf8[ib_cm] Kernel unaligned access at TPC[103bce50]cm_find_listen+0x34/0xf8[ib_cm] Kernel unaligned access at TPC[103bce50]cm_find_listen+0x34/0xf8[ib_cm] Kernel unaligned access at TPC[103bce50]cm_find_listen+0x34/0xf8[ib_cm] Kernel unaligned access at TPC[103bce50]cm_find_listen+0x34/0xf8[ib_cm]Changed signature of
cm_mask_copyfrom u8 to u32 as suggested by Jason Gunthorpe.
+1 to everyone elses comments..
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 440
Quoted 2 lines
drivers/infiniband/core/cm.c +1
-1-static void cm_mask_copy (u8 *dst,u8 *src,u8 *mask) +static void cm_mask_copy (u32 *dst,u32 *src,u32 *mask)
masy as well add the const while here
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 445
Quoted 5 lines
drivers/infiniband/core/cm.c +2
-3-for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (unsigned long ); i++) - ((unsigned long *) dst)[i] = ((unsigned long *) src)[i] & - ((unsigned long *) mask)[i]; +for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (u32); i++) + dst[i] = src[i] & mask[i];
for (i = 0; i < IB_CM_COMPARE_SIZE / sizeof(*dst); i++)
Is a little more idiomatic
drivers/infiniband/core/cm.c static struct cm_id_private * cm_find_listen(struct ib_device *device, · line 549
Quoted 3 lines
drivers/infiniband/core/cm.c +1
-1- data_cmp =cm_compare_private_data (private_data, + data_cmp =cm_compare_private_data ((u32 *) private_data, cm_id_priv->compare_data);
I'd be happier without this cast, at the worst move it up one more layer, at the best, fix the two impacted structures as well.
Quoted 2 lines
I feel like I stepped into a tar pit... It's a bit odd that
IB_CM_COMPARE_SIZEis part of an enum rather than a #define.
This is, again, idiomatic. '#define CONSTANT' is often frowned upon, the semantics of enum are much cleaner/safer, eg what you trivially posted:
Quoted 1 line
#define
IB_CM_COMPARE_SIZE64/sizeof(u32)
Is wrong, missing brackets.
Quoted 5 lines
Quoted 3 lines
Anyway, you might want to compile this part of the kernel with -Wcast-align and ignore the false positive (in particular every other use of
container_of()).Why?
To look for more sketchy things that might impact SPARC, ARM, etc.
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20150501162413.GC8531-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org
Quoted 4 lines · Jason Gunthorpe
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 440
Quoted 2 lines
drivers/infiniband/core/cm.c +1
-1-static void cm_mask_copy (u8 *dst,u8 *src,u8 *mask) +static void cm_mask_copy (u32 *dst,u32 *src,u32 *mask)masy as well add the const while here
noted by Bart.
Quoted 10 lines
drivers/infiniband/core/cm.c static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id) · line 445
Quoted 6 lines
drivers/infiniband/core/cm.c +2
-3-for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (unsigned long ); i++) - ((unsigned long *) dst)[i] = ((unsigned long *) src)[i] & - ((unsigned long *) mask)[i]; +for (i =0 ; i <IB_CM_COMPARE_SIZE /sizeof (u32); i++) + dst[i] = src[i] & mask[i];for (i = 0; i <
IB_CM_COMPARE_SIZE/sizeof(*dst); i++)Is a little more idiomatic
Sizing of the array using some macro / enum that accounts for u32 walking versus u8 walking means the sizeof goes away.
Quoted 7 lines
drivers/infiniband/core/cm.c static struct cm_id_private * cm_find_listen(struct ib_device *device, · line 549
Quoted 4 lines
drivers/infiniband/core/cm.c +1
-1- data_cmp =cm_compare_private_data (private_data, + data_cmp =cm_compare_private_data ((u32 *) private_data, cm_id_priv->compare_data);I'd be happier without this cast, at the worst move it up one more layer, at the best, fix the two impacted structures as well.
I tried to fix private_data and it blows the patch up.
Quoted 6 lines
Quoted 3 lines
I feel like I stepped into a tar pit... It's a bit odd that
IB_CM_COMPARE_SIZEis part of an enum rather than a #define.This is, again, idiomatic. '#define CONSTANT' is often frowned upon, the semantics of enum are much cleaner/safer,
'#define NAME VALUE' is used throughout the kernel. Why does ib_rdma need to be different?
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Anyway, you might want to compile this part of the kernel with -Wcast-align and ignore the false positive (in particular every other use of
container_of()).Why?
To look for more sketchy things that might impact SPARC, ARM, etc.
Seems like a topic for another patch.
David
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 9 lines · David Ahern
Quoted 6 lines · Jason Gunthorpe
Review
Quoted 3 lines
(quoted diff) +1
-1- data_cmp = cm_compare_private_data(private_data, + data_cmp = cm_compare_private_data((u32 *) private_data, cm_id_priv->compare_data);I'd be happier without this cast, at the worst move it up one more layer, at the best, fix the two impacted structures as well.
I tried to fix
private_dataand it blows the patch up.
Add this:
drivers/infiniband/core/cm_msgs.h +2 -2
@@ -103,7 +103,7 @@ struct cm_req_msg {/* local ACK timeout:5, rsvd:3 */ u8 alt_offset139; -u8 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE ]; +u32 private_data[IB_CM_REQ_PRIVATE_DATA_SIZE /4 ]; } __attribute__ ((packed));
@@ -801,7 +801,7 @@ struct cm_sidr_req_msg {__be16 rsvd;__be64 service_id; -u8 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE ]; +u32 private_data[IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE /4 ]; } __attribute__ ((packed));struct cm_sidr_rep_msg {
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I feel like I stepped into a tar pit... It's a bit odd that
IB_CM_COMPARE_SIZEis part of an enum rather than a #define.This is, again, idiomatic. '#define CONSTANT' is often frowned upon, the semantics of enum are much cleaner/safer,
'#define NAME VALUE' is used throughout the kernel. Why does
ib_rdmaneed to be different?
There is a mix, the style guide endorses both options.
Quoted 3 lines
Quoted 1 line
To look for more sketchy things that might impact SPARC, ARM, etc.
Seems like a topic for another patch.
Yep
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html