Skip to contentSkip to conversation

IB/core: Fix unaligned accesses

PATCH Superseded David Ahern 2 participants 9 messages Apr 29, 2015 8 messages not in the archive InfiniBand

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

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

---
 drivers/infiniband/core/cm.c |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)
drivers/infiniband/core/cm.c +15 -3
index e28a494..5102cfe 100644
@@ -439,11 +439,23 @@ static struct cm_id_private * cm_acquire_id(__be32 local_id, __be32 remote_id)
 
 static void cm_mask_copy(u8 *dst, u8 *src, u8 *mask)
 {
+	unsigned long *plsrc, *plmask, *pldst;
 	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];
+	/* unsigned longs can use extended load operations which
+	 * can require 8-byte alignments. dst, src and mask are
+	 * not guaranteed to be aligned.
+	 */
+	pldst = (unsigned long *) dst;
+	plsrc = (unsigned long *) src;
+	plmask = (unsigned long *) mask;
+	for (i = 0; i < IB_CM_COMPARE_SIZE / sizeof(unsigned long); i++) {
+		unsigned long lsrc, lmask;
+
+		lsrc = get_unaligned(&plsrc[i]);
+		lmask = get_unaligned(&plmask[i]);
+		put_unaligned(lsrc & lmask, &pldst[i]);
+	}
 }
 
 static int cm_compare_data(struct ib_cm_compare_data *src_data,
Signature · 6 lines
1.7.1

--
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
#2 lore raw
In reply to a message not in the archive
Quoted 2 lines · David Ahern

static void cm_mask_copy(u8 *dst, u8 *src, u8 *mask) {

Do you know what call site is unaligned? A quick audit suggests that fixing a few possibly troublesome callers to be guaranteed 32 bit aligned should be fairly straight foward.

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

#4 lore raw
In reply to a message not in the archive
Quoted 8 lines · Jason Gunthorpe
Quoted 2 lines · David Ahern
  static void cm_mask_copy(u8 *dst, u8 *src, u8 *mask)
  {

Do you know what call site is unaligned? A quick audit suggests that fixing a few possibly troublesome callers to be guaranteed 32 bit aligned should be fairly straight foward.

I believe this case is

cm_find_listen() -> cm_compare_private_data() -> cm_mask_copy() --
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

#6 lore raw
In reply to a message not in the archive
Quoted 6 lines · David Ahern
Quoted 5 lines · Jason Gunthorpe
Quoted 2 lines · David Ahern

static void cm_mask_copy(u8 *dst, u8 *src, u8 *mask) {

Quoted 8 lines
Quoted 3 lines

Do you know what call site is unaligned? A quick audit suggests that fixing a few possibly troublesome callers to be guaranteed 32 bit aligned should be fairly straight foward.

I believe this case is

cm_find_listen() -> cm_compare_private_data() -> cm_mask_copy()

Right, I'm pretty sure that is the main place that would have the 32 bit alignment limitation since it is a on the wire message.

I suggest changing the signature to:

cm_mask_copy(u32 *dst, const u32 *src, const u32 *mask)

And dealing with the fairly few resulting changes..

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

#8 lore raw
In reply to a message not in the archive
Quoted 16 lines · Jason Gunthorpe
Quoted 6 lines · David Ahern
Quoted 5 lines · Jason Gunthorpe
Quoted 2 lines · David Ahern
  static void cm_mask_copy(u8 *dst, u8 *src, u8 *mask)
  {
Quoted 8 lines
Quoted 3 lines

Do you know what call site is unaligned? A quick audit suggests that fixing a few possibly troublesome callers to be guaranteed 32 bit aligned should be fairly straight foward.

I believe this case is

cm_find_listen() -> cm_compare_private_data() -> cm_mask_copy()

Quoted 8 lines

Right, I'm pretty sure that is the main place that would have the 32 bit alignment limitation since it is a on the wire message.

I suggest changing the signature to:

cm_mask_copy(u32 *dst, const u32 *src, const u32 *mask)

And dealing with the fairly few resulting changes..

Confused. That does not deal with the alignment problem. Internal to cm_mask_copy unsigned longs are used (8-bytes), so why change the signature to u32?

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

#10 lore raw
In reply to a message not in the archive
Quoted 5 lines · David Ahern
Quoted 1 line

And dealing with the fairly few resulting changes..

Confused. That does not deal with the alignment problem. Internal to cm_mask_copy unsigned longs are used (8-bytes), so why change the signature to u32?

You'd change the loop stride to by u32 as well.

This whole thing is just an attempted optimization, but doing copy and mask 8 bytes at a time on unaligned data is not very efficient, even on x86.

So either drop the optimization and use u8 as the stride.

Or keep the optimization and guarentee alignment, the best we can do is u32.

Since this is an optimization, get_unaligned should be avoided, looping over u8 would be faster.

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

#12 lore raw
In reply to a message not in the archive
Quoted 14 lines · Jason Gunthorpe
Quoted 5 lines · David Ahern
Quoted 1 line

And dealing with the fairly few resulting changes..

Confused. That does not deal with the alignment problem. Internal to cm_mask_copy unsigned longs are used (8-bytes), so why change the signature to u32?

You'd change the loop stride to by u32 as well.

This whole thing is just an attempted optimization, but doing copy and mask 8 bytes at a time on unaligned data is not very efficient, even on x86.

Quoted 7 lines

So either drop the optimization and use u8 as the stride.

Or keep the optimization and guarentee alignment, the best we can do is u32.

Since this is an optimization, get_unaligned should be avoided, looping over u8 would be faster.

Sorry, to be dense on this but I still don't see how your proposal addresses the underlying problem -- guarantee of 8 byte alignment. Be it a u8 or u32 for the input arguments the cast to unsigned long says that an extended load operation can be used for access. For that to work the address (src, dst, mask) must all be 8-byte aligned.

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

#14 lore raw
In reply to a message not in the archive
Quoted 23 lines · David Ahern
Quoted 14 lines · Jason Gunthorpe
Quoted 5 lines · David Ahern
Quoted 1 line

And dealing with the fairly few resulting changes..

Confused. That does not deal with the alignment problem. Internal to cm_mask_copy unsigned longs are used (8-bytes), so why change the signature to u32?

You'd change the loop stride to by u32 as well.

This whole thing is just an attempted optimization, but doing copy and mask 8 bytes at a time on unaligned data is not very efficient, even on x86.

Quoted 7 lines

So either drop the optimization and use u8 as the stride.

Or keep the optimization and guarentee alignment, the best we can do is u32.

Since this is an optimization, get_unaligned should be avoided, looping over u8 would be faster.

Quoted 6 lines

Sorry, to be dense on this but I still don't see how your proposal addresses the underlying problem -- guarantee of 8 byte alignment. Be it a u8 or u32 for the input arguments the cast to unsigned long says that an extended load operation can be used for access. For that to work the address (src, dst, mask) must all be 8-byte aligned.

Read carefully:

Quoted 1 line
Quoted 1 line

You'd change the loop stride to by u32 as well.

which means this:

static void cm_mask_copy(u32 *dst, const u32 *src, const u32 *mask)

{
	int i;

	for (i = 0; i < IB_CM_COMPARE_SIZE; i++)
		dst[i] = src[i] & mask[i];
}

Divide IB_CM_COMPARE_SIZE by 4, adjust all users.

Make other related type changes the compiler tells you about.

Do not add casts.

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

#16 lore raw
In reply to a message not in the archive
Quoted 13 lines · Jason Gunthorpe

Read carefully:

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

You'd change the loop stride to by u32 as well.

which means this:

static void cm_mask_copy(u32 *dst, const u32 *src, const u32 *mask)

{
	int i;

	for (i = 0; i < IB_CM_COMPARE_SIZE; i++)
		dst[i] = src[i] & mask[i];
}
Quoted 5 lines

Divide IB_CM_COMPARE_SIZE by 4, adjust all users.

Make other related type changes the compiler tells you about.

Do not add casts.

got it. that was a lot clearer.
--
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