Skip to contentSkip to conversation

IB/core: Fix unaligned accesses

PATCH Superseded David Ahern 2 participants 4 messages May 1, 2015 – May 3, 2015 3 messages not in the archive InfiniBand

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 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]

---
v3
- updated definition of IB_CM_COMPARE_SIZE to account for u32 walking per Yann's comment
- added const to src/mask args to cm_mask_copy and removed extra whitespace per Bart's comments
- changed 2 private_data declarations to u32 as suggested by Jason

v2
- updated per Jason's comments

 drivers/infiniband/core/cm.c      | 17 ++++++++---------
 drivers/infiniband/core/cm_msgs.h |  4 ++--
 include/rdma/ib_cm.h              |  7 ++++---
 3 files changed, 14 insertions(+), 14 deletions(-)
drivers/infiniband/core/cm.c +8 -9
index e28a494e2a3a..0c276a53b8a8 100644
@@ -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, const u32 *src, const 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; 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;
@@ -538,7 +537,7 @@ static struct cm_id_private * cm_insert_listen(struct cm_id_private *cm_id_priv)
 
 static struct cm_id_private * cm_find_listen(struct ib_device *device,
 					     __be64 service_id,
-					     u8 *private_data)
+					     u32 *private_data)
 {
 	struct rb_node *node = cm.listen_service_table.rb_node;
 	struct cm_id_private *cm_id_priv;
drivers/infiniband/core/cm_msgs.h +2 -2
index be068f47e47e..8b76f0ef965e 100644
@@ -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 / sizeof(u32)];
 
 } __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 / sizeof(u32)];
 } __attribute__ ((packed));
 
 struct cm_sidr_rep_msg {
include/rdma/ib_cm.h +4 -3
index 0e3ff30647d5..39ed2d2fbd51 100644
@@ -105,7 +105,8 @@ enum ib_cm_data_size {
 	IB_CM_SIDR_REQ_PRIVATE_DATA_SIZE = 216,
 	IB_CM_SIDR_REP_PRIVATE_DATA_SIZE = 136,
 	IB_CM_SIDR_REP_INFO_LENGTH	 = 72,
-	IB_CM_COMPARE_SIZE		 = 64
+	/* compare done u32 at a time */
+	IB_CM_COMPARE_SIZE		 = (64 / sizeof(u32))
 };
 
 struct ib_cm_id;
@@ -337,8 +338,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): 1430515349-183903-1-git-send-email-david.ahern-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org

#2 lore raw

Hi,

The patch is broken - you did not update

Quoted 4 lines

-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of David Ahern
Sent: Saturday, May 02, 2015 12:22 AM

<snipped>

Quoted 12 lines

static int cm_compare_data(struct ib_cm_compare_data *src_data,

drivers/infiniband/core/cm.c +2 -2
 			   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;

drivers/infiniband/core/cm.c static int cm_compare_data(struct · line 460

Quoted 2 lines
drivers/infiniband/core/cm.c +0 -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);

You added a BUG here - you should use (IB_CM_COMPARE_SIZE * sizeof(u32)). Same bug is also appearing at
http://lxr.free-electrons.com/source/drivers/infiniband/core/cm.c#L472
http://lxr.free-electrons.com/source/drivers/infiniband/core/cm.c#L956

It might be better to keep IB_CM_COMPARE_SIZE to the original value, and divide by sizeof(u32) in the uses which iterate over a 32-bit data type.

Thanks,
--Shachar
--
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): AM3PR05MB093528DFDBBA39DD7977CC85DCD30-LOZWmgKjnYgQouBfZGh8ttqRiQSDpxhJvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#4 lore raw
Quoted 3 lines · Shachar Raindel

Hi,

The patch is broken - you did not update

--verbose. I did not update what?

Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of David Ahern
Sent: Saturday, May 02, 2015 12:22 AM

That is filled in by git and the time on the server is proper. So what do you disagree with?

Quoted 12 lines

<snipped>

Quoted 9 lines

static int cm_compare_data(struct ib_cm_compare_data *src_data,
struct ib_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];
Quoted 7 lines

Review static int cm_compare_data(struct · line 460

Quoted 5 lines
  	if (!src_data || !dst_data)
  		return 0;
(quoted diff) +0 -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);

You added a BUG here - you should use (IB_CM_COMPARE_SIZE * sizeof(u32)).

Thank you for pointing that out. Changed those to sizeof(src) and sizeof(compare_data->mask).

--
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]

#6 lore raw
Quoted 11 lines

-----Original Message-----
From: David Ahern [mailto:[email protected]]

Quoted 3 lines · Shachar Raindel

Hi,

The patch is broken - you did not update

--verbose. I did not update what?

Had a slight brain-body sync issue.
Was meaning to point out that IB_CM_COMPARE_SIZE changed, but Some of its users were not updated.

Quoted 10 lines
Quoted 6 lines
Quoted 6 lines

-----Original Message-----
From: [email protected] [mailto:linux-rdma- [email protected]] On Behalf Of David Ahern
Sent: Saturday, May 02, 2015 12:22 AM

That is filled in by git and the time on the server is proper. So what do you disagree with?

No disagreement there, was just meaning to help everyone find the relevant original e-mail without a doubt. My MTA is bit "special."

Quoted 19 lines
Quoted 12 lines

<snipped>

Quoted 9 lines

static int cm_compare_data(struct ib_cm_compare_data *src_data,
struct ib_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];
Quoted 7 lines

Review static int cm_compare_data(struct · line 460

Quoted 5 lines
  	if (!src_data || !dst_data)
  		return 0;
(quoted diff) +0 -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);

You added a BUG here - you should use (IB_CM_COMPARE_SIZE *

Quoted 5 lines

sizeof(u32)).

Thank you for pointing that out. Changed those to sizeof(src) and sizeof(compare_data->mask).

This sounds good.

Thanks,
--Shachar

--
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