net/rds: fix unaligned memory access
Subsystems (3)
PATCH 1/1 net/rds: fix unaligned memory access
From: shamir rabinovitch <[email protected]>
rdma_conn_param private data is copied using memcpy after headers such as cma_hdr (see cma_resolve_ib_udp as example). so the start of the private data is aligned to the end of the structure that come before. if this structure end with u32 the meaning is that the start of the private data will be 4 bytes aligned. structures that use u8/u16/u32/u64 are naturally aligned but in case the structure start is not 8 bytes aligned, all u64 members of this structure will not be aligned. to solve this issue we must use special macros that allow unaligned access to those unaligned members.
Addresses the following kernel log seen when attempting to use RDMA:
Kernel unaligned access at TPC[10507a88] rds_ib_cm_connect_complete+0x1bc/0x1e0 [rds_rdma]
--- net/rds/ib_cm.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-)
net/rds/ib_cm.c +11 -2
@@ -183,8 +183,17 @@ void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even/* If the peer gave us the last packet it saw, process this as if * we had received a regular ACK. */ -if (dp && dp->dp_ack_seq) -rds_send_drop_acked (conn,be64_to_cpu (dp->dp_ack_seq),NULL ); +if (dp) { +/* dp structure start is not guaranteed to be 8 bytes aligned +* so on SPARC we get trap for nu-aligned access. we solve +* this by using the macros for unaligned memory access +*/ +u64 dp_ack_seq =get_unaligned (&dp->dp_ack_seq); + +if (dp_ack_seq) +rds_send_drop_acked (conn,be64_to_cpu (dp_ack_seq), +NULL ); + }rds_connect_complete (conn); }
Signature · 1 line
1.7.1
From: David Ahern
Quoted 14 lines
Sent: 30 April 2015 15:28
rdma_conn_paramprivate data is copied using memcpy after headers such ascma_hdr(seecma_resolve_ib_udpas example). so the start of the private data is aligned to the end of the structure that come before. if this structure end with u32 the meaning is that the start of the private data will be 4 bytes aligned. structures that use u8/u16/u32/u64 are naturally aligned but in case the structure start is not 8 bytes aligned, all u64 members of this structure will not be aligned. to solve this issue we must use special macros that allow unaligned access to those unaligned members.Addresses the following kernel log seen when attempting to use RDMA:
Kernel unaligned access at TPC[10507a88]
rds_ib_cm_connect_complete+0x1bc/0x1e0[rds_rdma]
...
net/rds/ib_cm.c void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even · line 187
Quoted 10 lines
net/rds/ib_cm.c +0
-2@@ -183,8 +183,17 @@ void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even/* If the peer gave us the last packet it saw, process this as if * we had received a regular ACK. */ -if (dp && dp->dp_ack_seq) -rds_send_drop_acked (conn,be64_to_cpu (dp->dp_ack_seq),NULL );
Or just mark 'dp_ack_seq' with __attribute((aligned(4))). Then the compiler will generate two 32bit loads. (provided be64_to_cpu() doesn't do anything stupid.)
David
David Miller
maintainerFrom: David Ahern <[email protected]>
Date: Thu, 30 Apr 2015 10:27:53 -0400
net/rds/ib_cm.c void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even · line 190
Quoted 11 lines
net/rds/ib_cm.c +5
-2@@ -183,8 +183,17 @@ void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even/* If the peer gave us the last packet it saw, process this as if * we had received a regular ACK. */ -if (dp && dp->dp_ack_seq) -rds_send_drop_acked (conn,be64_to_cpu (dp->dp_ack_seq),NULL ); +if (dp) { +/* dp structure start is not guaranteed to be 8 bytes aligned +* so on SPARC we get trap for nu-aligned access. we solve +* this by using the macros for unaligned memory access +*/
"nu-aligned" is misspelled, and Mentioning sparc specifically is completely inappropriate because this is not a sparc specific problem.
David Miller
maintainerFrom: David Laight <[email protected]>
Date: Thu, 30 Apr 2015 15:23:39 +0000
Quoted 22 lines
From: David Ahern
Quoted 14 lines
Sent: 30 April 2015 15:28
rdma_conn_paramprivate data is copied using memcpy after headers such ascma_hdr(seecma_resolve_ib_udpas example). so the start of the private data is aligned to the end of the structure that come before. if this structure end with u32 the meaning is that the start of the private data will be 4 bytes aligned. structures that use u8/u16/u32/u64 are naturally aligned but in case the structure start is not 8 bytes aligned, all u64 members of this structure will not be aligned. to solve this issue we must use special macros that allow unaligned access to those unaligned members.Addresses the following kernel log seen when attempting to use RDMA:
Kernel unaligned access at TPC[10507a88]
rds_ib_cm_connect_complete+0x1bc/0x1e0[rds_rdma]...
Quoted 6 lines
net/rds/ib_cm.c +0
-0@@ -183,8 +183,17 @@ void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even
Quoted 8 lines
net/rds/ib_cm.c void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even · line 187
Quoted 4 lines
net/rds/ib_cm.c +0
-2/* If the peer gave us the last packet it saw, process this as if * we had received a regular ACK. */ -if (dp && dp->dp_ack_seq) -rds_send_drop_acked (conn,be64_to_cpu (dp->dp_ack_seq),NULL );Or just mark '
dp_ack_seq' with __attribute((aligned(4))). Then the compiler will generate two 32bit loads. (providedbe64_to_cpu()doesn't do anything stupid.)
It's a __be64 which already requires 8 byte alignment.
That's not what is causing the problem here. It's the opaque area that this structure can end up being placed afterwards.
Quoted 5 lines · David Miller
From: David Ahern <[email protected]>
Date: Thu, 30 Apr 2015 10:27:53 -0400Quoted 2 lines
(quoted diff) +0
-0@@ -183,8 +183,17 @@ void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even
Quoted 13 lines
net/rds/ib_cm.c void rds_ib_cm_connect_complete(struct rds_connection *conn, struct rdma_cm_even · line 190
Quoted 9 lines
net/rds/ib_cm.c +5
-2/* If the peer gave us the last packet it saw, process this as if * we had received a regular ACK. */ -if (dp && dp->dp_ack_seq) -rds_send_drop_acked (conn,be64_to_cpu (dp->dp_ack_seq),NULL ); +if (dp) { +/* dp structure start is not guaranteed to be 8 bytes aligned +* so on SPARC we get trap for nu-aligned access. we solve +* this by using the macros for unaligned memory access +*/ "nu-aligned" is misspelled, and Mentioning sparc specifically is completely inappropriate because this is not a sparc specific problem.
oops meant to take that out. Will fix and resubmit.