qemu with hax to log dma reads & writes jcs.org/2018/11/12/vfio

hw/s390x/ioinst: Fix alignment problem in struct SubchDev

struct SubchDev embeds several other structures which are marked with
QEMU_PACKED. This causes the compiler to not care for proper alignment
of these structures. When we later pass around pointers to the unaligned
struct members during migration, this causes problems on host architectures
like Sparc that can not do unaligned memory access.

Most of the structs in ioinst.h are naturally aligned, so we can fix
most of the problem by removing the QEMU_PACKED statements (and use
QEMU_BUILD_BUG_MSG() statements instead to make sure that there is no
padding). However, for the struct SCHIB, we have to keep the QEMU_PACKED
since the compiler adds some padding here otherwise. Move this struct
to the beginning of struct SubchDev instead to fix the alignment problem
here, too.

Signed-off-by: Thomas Huth <thuth@redhat.com>
Message-Id: <1538036615-32542-4-git-send-email-thuth@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Cornelia Huck <cohuck@redhat.com>

authored by

Thomas Huth and committed by
Cornelia Huck
cb89b349 729315eb

+16 -9
+2 -2
include/hw/s390x/css.h
··· 118 118 typedef struct SubchDev SubchDev; 119 119 struct SubchDev { 120 120 /* channel-subsystem related things: */ 121 + SCHIB curr_status; /* Needs alignment and thus must come first */ 122 + ORB orb; 121 123 uint8_t cssid; 122 124 uint8_t ssid; 123 125 uint16_t schid; 124 126 uint16_t devno; 125 - SCHIB curr_status; 126 127 uint8_t sense_data[32]; 127 128 hwaddr channel_prog; 128 129 CCW1 last_cmd; ··· 131 132 bool thinint_active; 132 133 uint8_t ccw_no_data_cnt; 133 134 uint16_t migrated_schid; /* used for missmatch detection */ 134 - ORB orb; 135 135 CcwDataStream cds; 136 136 /* transport-provided data: */ 137 137 int (*ccw_cb) (SubchDev *, CCW1);
+14 -7
include/hw/s390x/ioinst.h
··· 25 25 uint8_t dstat; 26 26 uint8_t cstat; 27 27 uint16_t count; 28 - } QEMU_PACKED SCSW; 28 + } SCSW; 29 + QEMU_BUILD_BUG_MSG(sizeof(SCSW) != 12, "size of SCSW is wrong"); 29 30 30 31 #define SCSW_FLAGS_MASK_KEY 0xf000 31 32 #define SCSW_FLAGS_MASK_SCTL 0x0800 ··· 94 95 uint8_t pam; 95 96 uint8_t chpid[8]; 96 97 uint32_t chars; 97 - } QEMU_PACKED PMCW; 98 + } PMCW; 99 + QEMU_BUILD_BUG_MSG(sizeof(PMCW) != 28, "size of PMCW is wrong"); 98 100 99 101 #define PMCW_FLAGS_MASK_QF 0x8000 100 102 #define PMCW_FLAGS_MASK_W 0x4000 ··· 127 129 uint32_t esw[5]; 128 130 uint32_t ecw[8]; 129 131 uint32_t emw[8]; 130 - } QEMU_PACKED IRB; 132 + } IRB; 133 + QEMU_BUILD_BUG_MSG(sizeof(IRB) != 96, "size of IRB is wrong"); 131 134 132 135 /* operation request block */ 133 136 typedef struct ORB { ··· 136 139 uint8_t lpm; 137 140 uint8_t ctrl1; 138 141 uint32_t cpa; 139 - } QEMU_PACKED ORB; 142 + } ORB; 143 + QEMU_BUILD_BUG_MSG(sizeof(ORB) != 12, "size of ORB is wrong"); 140 144 141 145 #define ORB_CTRL0_MASK_KEY 0xf000 142 146 #define ORB_CTRL0_MASK_SPND 0x0800 ··· 165 169 uint8_t flags; 166 170 uint8_t reserved; 167 171 uint16_t count; 168 - } QEMU_PACKED CCW0; 172 + } CCW0; 173 + QEMU_BUILD_BUG_MSG(sizeof(CCW0) != 8, "size of CCW0 is wrong"); 169 174 170 175 /* channel command word (type 1) */ 171 176 typedef struct CCW1 { ··· 173 178 uint8_t flags; 174 179 uint16_t count; 175 180 uint32_t cda; 176 - } QEMU_PACKED CCW1; 181 + } CCW1; 182 + QEMU_BUILD_BUG_MSG(sizeof(CCW1) != 8, "size of CCW1 is wrong"); 177 183 178 184 #define CCW_FLAG_DC 0x80 179 185 #define CCW_FLAG_CC 0x40 ··· 192 198 typedef struct CRW { 193 199 uint16_t flags; 194 200 uint16_t rsid; 195 - } QEMU_PACKED CRW; 201 + } CRW; 202 + QEMU_BUILD_BUG_MSG(sizeof(CRW) != 4, "size of CRW is wrong"); 196 203 197 204 #define CRW_FLAGS_MASK_S 0x4000 198 205 #define CRW_FLAGS_MASK_R 0x2000