Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: hpsa: Use __packed on individual structs, not header-wide

The hpsa driver uses data structures which contain a combination of driver
internals and commands sent directly to the hardware. To manage alignment
for the hardware portions the driver used #pragma pack(1).

Commit f749d8b7a989 ("scsi: hpsa: Correct dev cmds outstanding for retried
cmds") switched an existing variable from int to bool. Due to the pragma an
atomic_t in the same data structure ended up being misaligned and broke
boot on ia64.

Add __packed to every struct and union in the header file. Subsequent
commits will address the actual atomic_t misalignment regression.

The commit is a no-op at least on ia64:
$ diff -u <(objdump -d -r old.o) <(objdump -d -r new.o)

Link: https://lore.kernel.org/r/20210330071958.3788214-1-slyfox@gentoo.org
Fixes: f749d8b7a989 ("scsi: hpsa: Correct dev cmds outstanding for retried cmds")
CC: linux-ia64@vger.kernel.org
CC: storagedev@microchip.com
CC: linux-scsi@vger.kernel.org
CC: Joe Szczypek <jszczype@redhat.com>
CC: Scott Benesh <scott.benesh@microchip.com>
CC: Scott Teel <scott.teel@microchip.com>
CC: Tomas Henzl <thenzl@redhat.com>
CC: "Martin K. Petersen" <martin.petersen@oracle.com>
CC: Don Brace <don.brace@microchip.com>
Reported-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>
Suggested-by: Don Brace <don.brace@microchip.com>
Reviewed-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Sergei Trofimovich and committed by
Martin K. Petersen
5482a9a1 9e67600e

+34 -34
+34 -34
drivers/scsi/hpsa_cmd.h
··· 20 20 #ifndef HPSA_CMD_H 21 21 #define HPSA_CMD_H 22 22 23 + #include <linux/compiler.h> 24 + 23 25 /* general boundary defintions */ 24 26 #define SENSEINFOBYTES 32 /* may vary between hbas */ 25 27 #define SG_ENTRIES_IN_CMD 32 /* Max SG entries excluding chain blocks */ ··· 202 200 MAX_EXT_TARGETS + 1) /* + 1 is for the controller itself */ 203 201 204 202 /* SCSI-3 Commands */ 205 - #pragma pack(1) 206 - 207 203 #define HPSA_INQUIRY 0x12 208 204 struct InquiryData { 209 205 u8 data_byte[36]; 210 - }; 206 + } __packed; 211 207 212 208 #define HPSA_REPORT_LOG 0xc2 /* Report Logical LUNs */ 213 209 #define HPSA_REPORT_PHYS 0xc3 /* Report Physical LUNs */ ··· 221 221 u8 xor_mult[2]; /**< XOR multipliers for this position, 222 222 * valid for data disks only */ 223 223 u8 reserved[2]; 224 - }; 224 + } __packed; 225 225 226 226 struct raid_map_data { 227 227 __le32 structure_size; /* Size of entire structure in bytes */ ··· 247 247 __le16 dekindex; /* Data encryption key index. */ 248 248 u8 reserved[16]; 249 249 struct raid_map_disk_data data[RAID_MAP_MAX_ENTRIES]; 250 - }; 250 + } __packed; 251 251 252 252 struct ReportLUNdata { 253 253 u8 LUNListLength[4]; 254 254 u8 extended_response_flag; 255 255 u8 reserved[3]; 256 256 u8 LUN[HPSA_MAX_LUN][8]; 257 - }; 257 + } __packed; 258 258 259 259 struct ext_report_lun_entry { 260 260 u8 lunid[8]; ··· 269 269 u8 lun_count; /* multi-lun device, how many luns */ 270 270 u8 redundant_paths; 271 271 u32 ioaccel_handle; /* ioaccel1 only uses lower 16 bits */ 272 - }; 272 + } __packed; 273 273 274 274 struct ReportExtendedLUNdata { 275 275 u8 LUNListLength[4]; 276 276 u8 extended_response_flag; 277 277 u8 reserved[3]; 278 278 struct ext_report_lun_entry LUN[HPSA_MAX_PHYS_LUN]; 279 - }; 279 + } __packed; 280 280 281 281 struct SenseSubsystem_info { 282 282 u8 reserved[36]; 283 283 u8 portname[8]; 284 284 u8 reserved1[1108]; 285 - }; 285 + } __packed; 286 286 287 287 /* BMIC commands */ 288 288 #define BMIC_READ 0x26 ··· 317 317 u8 Targ:6; 318 318 u8 Mode:2; /* b10 */ 319 319 } LogUnit; 320 - }; 320 + } __packed; 321 321 322 322 struct PhysDevAddr { 323 323 u32 TargetId:24; ··· 325 325 u32 Mode:2; 326 326 /* 2 level target device addr */ 327 327 union SCSI3Addr Target[2]; 328 - }; 328 + } __packed; 329 329 330 330 struct LogDevAddr { 331 331 u32 VolId:30; 332 332 u32 Mode:2; 333 333 u8 reserved[4]; 334 - }; 334 + } __packed; 335 335 336 336 union LUNAddr { 337 337 u8 LunAddrBytes[8]; 338 338 union SCSI3Addr SCSI3Lun[4]; 339 339 struct PhysDevAddr PhysDev; 340 340 struct LogDevAddr LogDev; 341 - }; 341 + } __packed; 342 342 343 343 struct CommandListHeader { 344 344 u8 ReplyQueue; ··· 346 346 __le16 SGTotal; 347 347 __le64 tag; 348 348 union LUNAddr LUN; 349 - }; 349 + } __packed; 350 350 351 351 struct RequestBlock { 352 352 u8 CDBLen; ··· 365 365 #define GET_DIR(tad) (((tad) >> 6) & 0x03) 366 366 u16 Timeout; 367 367 u8 CDB[16]; 368 - }; 368 + } __packed; 369 369 370 370 struct ErrDescriptor { 371 371 __le64 Addr; 372 372 __le32 Len; 373 - }; 373 + } __packed; 374 374 375 375 struct SGDescriptor { 376 376 __le64 Addr; 377 377 __le32 Len; 378 378 __le32 Ext; 379 - }; 379 + } __packed; 380 380 381 381 union MoreErrInfo { 382 382 struct { ··· 390 390 u8 offense_num; /* byte # of offense 0-base */ 391 391 u32 offense_value; 392 392 } Invalid_Cmd; 393 - }; 393 + } __packed; 394 + 394 395 struct ErrorInfo { 395 396 u8 ScsiStatus; 396 397 u8 SenseLen; ··· 399 398 u32 ResidualCnt; 400 399 union MoreErrInfo MoreErrInfo; 401 400 u8 SenseInfo[SENSEINFOBYTES]; 402 - }; 401 + } __packed; 403 402 /* Command types */ 404 403 #define CMD_IOCTL_PEND 0x01 405 404 #define CMD_SCSI 0x03 ··· 452 451 bool retry_pending; 453 452 struct hpsa_scsi_dev_t *device; 454 453 atomic_t refcount; /* Must be last to avoid memset in hpsa_cmd_init() */ 455 - } __aligned(COMMANDLIST_ALIGNMENT); 454 + } __packed __aligned(COMMANDLIST_ALIGNMENT); 456 455 457 456 /* Max S/G elements in I/O accelerator command */ 458 457 #define IOACCEL1_MAXSGENTRIES 24 ··· 490 489 __le64 host_addr; /* 0x70 - 0x77 */ 491 490 u8 CISS_LUN[8]; /* 0x78 - 0x7F */ 492 491 struct SGDescriptor SG[IOACCEL1_MAXSGENTRIES]; 493 - } __aligned(IOACCEL1_COMMANDLIST_ALIGNMENT); 492 + } __packed __aligned(IOACCEL1_COMMANDLIST_ALIGNMENT); 494 493 495 494 #define IOACCEL1_FUNCTION_SCSIIO 0x00 496 495 #define IOACCEL1_SGLOFFSET 32 ··· 520 519 u8 chain_indicator; 521 520 #define IOACCEL2_CHAIN 0x80 522 521 #define IOACCEL2_LAST_SG 0x40 523 - }; 522 + } __packed; 524 523 525 524 /* 526 525 * SCSI Response Format structure for IO Accelerator Mode 2 ··· 560 559 u8 sense_data_len; /* sense/response data length */ 561 560 u8 resid_cnt[4]; /* residual count */ 562 561 u8 sense_data_buff[32]; /* sense/response data buffer */ 563 - }; 562 + } __packed; 564 563 565 564 /* 566 565 * Structure for I/O accelerator (mode 2 or m2) commands. ··· 593 592 __le32 tweak_upper; /* Encryption tweak, upper 4 bytes */ 594 593 struct ioaccel2_sg_element sg[IOACCEL2_MAXSGENTRIES]; 595 594 struct io_accel2_scsi_response error_data; 596 - } __aligned(IOACCEL2_COMMANDLIST_ALIGNMENT); 595 + } __packed __aligned(IOACCEL2_COMMANDLIST_ALIGNMENT); 597 596 598 597 /* 599 598 * defines for Mode 2 command struct ··· 619 618 __le64 abort_tag; /* cciss tag of SCSI cmd or TMF to abort */ 620 619 __le64 error_ptr; /* Error Pointer */ 621 620 __le32 error_len; /* Error Length */ 622 - } __aligned(IOACCEL2_COMMANDLIST_ALIGNMENT); 621 + } __packed __aligned(IOACCEL2_COMMANDLIST_ALIGNMENT); 623 622 624 623 /* Configuration Table Structure */ 625 624 struct HostWrite { ··· 627 626 __le32 command_pool_addr_hi; 628 627 __le32 CoalIntDelay; 629 628 __le32 CoalIntCount; 630 - }; 629 + } __packed; 631 630 632 631 #define SIMPLE_MODE 0x02 633 632 #define PERFORMANT_MODE 0x04 ··· 676 675 #define HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_STATE_CHANGE (1 << 30) 677 676 #define HPSA_EVENT_NOTIFY_ACCEL_IO_PATH_CONFIG_CHANGE (1 << 31) 678 677 __le32 clear_event_notify; 679 - }; 678 + } __packed; 680 679 681 680 #define NUM_BLOCKFETCH_ENTRIES 8 682 681 struct TransTable_struct { ··· 687 686 __le32 RepQCtrAddrHigh32; 688 687 #define MAX_REPLY_QUEUES 64 689 688 struct vals32 RepQAddr[MAX_REPLY_QUEUES]; 690 - }; 689 + } __packed; 691 690 692 691 struct hpsa_pci_info { 693 692 unsigned char bus; 694 693 unsigned char dev_fn; 695 694 unsigned short domain; 696 695 u32 board_id; 697 - }; 696 + } __packed; 698 697 699 698 struct bmic_identify_controller { 700 699 u8 configured_logical_drive_count; /* offset 0 */ ··· 703 702 u8 pad2[136]; 704 703 u8 controller_mode; /* offset 292 */ 705 704 u8 pad3[32]; 706 - }; 705 + } __packed; 707 706 708 707 709 708 struct bmic_identify_physical_device { ··· 846 845 u8 max_link_rate[256]; 847 846 u8 neg_phys_link_rate[256]; 848 847 u8 box_conn_name[8]; 849 - } __attribute((aligned(512))); 848 + } __packed __attribute((aligned(512))); 850 849 851 850 struct bmic_sense_subsystem_info { 852 851 u8 primary_slot_number; ··· 859 858 u8 secondary_array_serial_number[32]; 860 859 u8 secondary_cache_serial_number[32]; 861 860 u8 pad[332]; 862 - }; 861 + } __packed; 863 862 864 863 struct bmic_sense_storage_box_params { 865 864 u8 reserved[36]; ··· 871 870 u8 reserver_3[84]; 872 871 u8 phys_connector[2]; 873 872 u8 reserved_4[296]; 874 - }; 873 + } __packed; 875 874 876 - #pragma pack() 877 875 #endif /* HPSA_CMD_H */