Skip to content

Commit 338a508

Browse files
[viostor] Fix SRB Extension struct member alignment
Refactors to fix a struct member misalignment: 1. Creates a new _SRB_EXTENSION_FLAGS struct of 32 bits length 2. The first bit is fua (Forced Unit Access) 3. The other bits are unused padding 4. Replaces the _SRB_EXTENSION member fua with new flags member 5. Updates references to srbExt->fua to use srbExt->flags.fua 6. Enforces 1-byte alignment of structs _SRB_EXTENSION and _SRB_EXTENSION_FLAGS Signed-off-by: benyamin-codez <115509179+benyamin-codez@users.noreply.github.com>
1 parent 8f73d3a commit 338a508

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

viostor/virtio_stor.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1467,7 +1467,7 @@ VirtIoBuildIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
14671467
srbExt->vbr.out_hdr.sector = lba;
14681468
srbExt->vbr.out_hdr.ioprio = 0;
14691469
srbExt->vbr.req = (PVOID)Srb;
1470-
srbExt->fua = CHECKBIT(adaptExt->features, VIRTIO_BLK_F_FLUSH) ? (cdb->CDB10.ForceUnitAccess == 1) : FALSE;
1470+
srbExt->flags.fua = CHECKBIT(adaptExt->features, VIRTIO_BLK_F_FLUSH) ? (cdb->CDB10.ForceUnitAccess == 1) : FALSE;
14711471

14721472
if (SRB_FLAGS(Srb) & SRB_FLAGS_DATA_OUT)
14731473
{
@@ -2205,14 +2205,14 @@ VOID VioStorCompleteRequest(IN PVOID DeviceExtension, IN ULONG MessageID, IN BOO
22052205
Srb,
22062206
QueueNumber,
22072207
MessageID);
2208-
if (srbExt && srbExt->fua == TRUE)
2208+
if (srbExt && srbExt->flags.fua == TRUE)
22092209
{
22102210
SRB_SET_SRB_STATUS(Srb, SRB_STATUS_PENDING);
22112211
if (!RhelDoFlush(DeviceExtension, Srb, TRUE, bIsr))
22122212
{
22132213
CompleteRequestWithStatus(DeviceExtension, (PSRB_TYPE)Srb, SRB_STATUS_ERROR);
22142214
}
2215-
srbExt->fua = FALSE;
2215+
srbExt->flags.fua = FALSE;
22162216
}
22172217
else
22182218
{

viostor/virtio_stor.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,17 +271,27 @@ typedef struct _VRING_DESC_ALIAS
271271
} u;
272272
} VRING_DESC_ALIAS;
273273

274+
#pragma pack(1)
275+
typedef struct _SRB_EXTENSION_FLAGS
276+
{
277+
BOOLEAN fua;
278+
BOOLEAN unused1[3];
279+
} SRB_EXTENSION_FLAGS, *PSRB_EXTENSION_FLAGS;
280+
#pragma pack()
281+
282+
#pragma pack(1)
274283
typedef struct _SRB_EXTENSION
275284
{
276285
blk_req vbr;
286+
ULONG_PTR id;
277287
ULONG out;
278288
ULONG in;
279289
ULONG MessageID;
280-
BOOLEAN fua;
281-
ULONG_PTR id;
290+
SRB_EXTENSION_FLAGS flags;
282291
VIO_SG sg[VIRTIO_MAX_SG];
283292
VRING_DESC_ALIAS desc[VIRTIO_MAX_SG];
284293
} SRB_EXTENSION, *PSRB_EXTENSION;
294+
#pragma pack()
285295

286296
BOOLEAN
287297
VirtIoInterrupt(IN PVOID DeviceExtension);

0 commit comments

Comments
 (0)