Skip to content

Commit 6dc2649

Browse files
bvanasschejgunthorpe
authored andcommitted
RDMA/srp: Apply the __packed attribute to members instead of structures
Applying the __packed attribute to an entire data structure results in suboptimal code on architectures that do not support unaligned accesses. Hence apply the __packed attribute only to those data members that are not naturally aligned. Link: https://lore.kernel.org/r/[email protected] Cc: Nicolas Morey-Chaisemartin <[email protected]> Signed-off-by: Bart Van Assche <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent c838de1 commit 6dc2649

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

include/scsi/srp.h

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ struct srp_direct_buf {
107107
* having the 20-byte structure padded to 24 bytes on 64-bit architectures.
108108
*/
109109
struct srp_indirect_buf {
110-
struct srp_direct_buf table_desc;
110+
struct srp_direct_buf table_desc __packed __aligned(4);
111111
__be32 len;
112-
struct srp_direct_buf desc_list[];
113-
} __attribute__((packed));
112+
struct srp_direct_buf desc_list[] __packed __aligned(4);
113+
};
114114

115115
/* Immediate data buffer descriptor as defined in SRP2. */
116116
struct srp_imm_buf {
@@ -175,13 +175,13 @@ struct srp_login_rsp {
175175
u8 opcode;
176176
u8 reserved1[3];
177177
__be32 req_lim_delta;
178-
u64 tag;
178+
u64 tag __packed __aligned(4);
179179
__be32 max_it_iu_len;
180180
__be32 max_ti_iu_len;
181181
__be16 buf_fmt;
182182
u8 rsp_flags;
183183
u8 reserved2[25];
184-
} __attribute__((packed));
184+
};
185185

186186
struct srp_login_rej {
187187
u8 opcode;
@@ -207,10 +207,6 @@ struct srp_t_logout {
207207
u64 tag;
208208
};
209209

210-
/*
211-
* We need the packed attribute because the SRP spec only aligns the
212-
* 8-byte LUN field to 4 bytes.
213-
*/
214210
struct srp_tsk_mgmt {
215211
u8 opcode;
216212
u8 sol_not;
@@ -225,10 +221,6 @@ struct srp_tsk_mgmt {
225221
u8 reserved5[8];
226222
};
227223

228-
/*
229-
* We need the packed attribute because the SRP spec only aligns the
230-
* 8-byte LUN field to 4 bytes.
231-
*/
232224
struct srp_cmd {
233225
u8 opcode;
234226
u8 sol_not;
@@ -266,7 +258,7 @@ struct srp_rsp {
266258
u8 sol_not;
267259
u8 reserved1[2];
268260
__be32 req_lim_delta;
269-
u64 tag;
261+
u64 tag __packed __aligned(4);
270262
u8 reserved2[2];
271263
u8 flags;
272264
u8 status;
@@ -275,7 +267,7 @@ struct srp_rsp {
275267
__be32 sense_data_len;
276268
__be32 resp_data_len;
277269
u8 data[];
278-
} __attribute__((packed));
270+
};
279271

280272
struct srp_cred_req {
281273
u8 opcode;
@@ -301,13 +293,13 @@ struct srp_aer_req {
301293
u8 sol_not;
302294
u8 reserved[2];
303295
__be32 req_lim_delta;
304-
u64 tag;
296+
u64 tag __packed __aligned(4);
305297
u32 reserved2;
306298
struct scsi_lun lun;
307299
__be32 sense_data_len;
308300
u32 reserved3;
309301
u8 sense_data[];
310-
} __attribute__((packed));
302+
};
311303

312304
struct srp_aer_rsp {
313305
u8 opcode;

0 commit comments

Comments
 (0)