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

scsi: hpsa: Add an assert to prevent __packed reintroduction

Link: https://lore.kernel.org/r/20210330071958.3788214-3-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
e01a00ff 02ec1442

+12
+12
drivers/scsi/hpsa_cmd.h
··· 22 22 23 23 #include <linux/compiler.h> 24 24 25 + #include <linux/build_bug.h> /* static_assert */ 26 + #include <linux/stddef.h> /* offsetof */ 27 + 25 28 /* general boundary defintions */ 26 29 #define SENSEINFOBYTES 32 /* may vary between hbas */ 27 30 #define SG_ENTRIES_IN_CMD 32 /* Max SG entries excluding chain blocks */ ··· 456 453 struct hpsa_scsi_dev_t *device; 457 454 atomic_t refcount; /* Must be last to avoid memset in hpsa_cmd_init() */ 458 455 } __aligned(COMMANDLIST_ALIGNMENT); 456 + 457 + /* 458 + * Make sure our embedded atomic variable is aligned. Otherwise we break atomic 459 + * operations on architectures that don't support unaligned atomics like IA64. 460 + * 461 + * The assert guards against reintroductin against unwanted __packed to 462 + * the struct CommandList. 463 + */ 464 + static_assert(offsetof(struct CommandList, refcount) % __alignof__(atomic_t) == 0); 459 465 460 466 /* Max S/G elements in I/O accelerator command */ 461 467 #define IOACCEL1_MAXSGENTRIES 24