Skip to content

Commit cade4cb

Browse files
benyamin-codezkostyanf14
authored andcommitted
[vioscsi] Fix for clobbered SRB Extension IDs
Refactors SRB Extension ID assignment: 1. Moves assignment from VioScsiStartIo() in vioscsi.c to SendSRB() in helper.c 2. Moves ULONG_PTR from _ADAPTER_EXTENSION stuct to _REQUEST_LIST struct 3. Renames ULONG_PTR from last_srb_id to next_id 4. Refactors conditional checks into while loop for efficiency and readability The refactor solves the problem because the assignment now occurs under spinlock. Resolves #1453 Labelled as Patch 4 in the issue. Credits: @iops-hunter Signed-off-by: benyamin-codez <115509179+benyamin-codez@users.noreply.github.com>
1 parent 8f73d3a commit cade4cb

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

vioscsi/helper.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,19 @@ VOID SendSRB(IN PVOID DeviceExtension, IN PSRB_TYPE Srb)
120120
vq_req_idx = QueueNumber - VIRTIO_SCSI_REQUEST_QUEUE_0;
121121

122122
VioScsiVQLock(DeviceExtension, MessageId, &LockHandle, FALSE);
123+
124+
element = &adaptExt->processing_srbs[vq_req_idx];
125+
126+
ULONG_PTR id = element->next_id;
127+
128+
while ((adaptExt->tmf_cmd.SrbExtension && id == (ULONG_PTR)&adaptExt->tmf_cmd.SrbExtension->cmd) || (id == 0))
129+
{
130+
id++;
131+
}
132+
133+
srbExt->id = id;
134+
element->next_id = ++id;
135+
123136
SET_VA_PA();
124137
add_buffer_req_status = virtqueue_add_buf(adaptExt->vq[QueueNumber],
125138
srbExt->psgl,

vioscsi/vioscsi.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ VioScsiFindAdapter(IN PVOID DeviceExtension,
360360
RtlZeroMemory(adaptExt, sizeof(ADAPTER_EXTENSION));
361361

362362
adaptExt->dump_mode = IsCrashDumpMode;
363-
adaptExt->last_srb_id = 1;
364363
adaptExt->hba_id = HBA_ID;
365364
ConfigInfo->Master = TRUE;
366365
ConfigInfo->ScatterGather = TRUE;
@@ -839,17 +838,6 @@ VioScsiStartIo(IN PVOID DeviceExtension, IN PSCSI_REQUEST_BLOCK Srb)
839838
}
840839
else
841840
{
842-
PADAPTER_EXTENSION adaptExt = (PADAPTER_EXTENSION)DeviceExtension;
843-
PSRB_EXTENSION srbExt = SRB_EXTENSION(Srb);
844-
845-
srbExt->id = adaptExt->last_srb_id;
846-
adaptExt->last_srb_id++;
847-
if (adaptExt->last_srb_id == 0 || (adaptExt->tmf_cmd.SrbExtension &&
848-
adaptExt->last_srb_id == (ULONG_PTR)&adaptExt->tmf_cmd.SrbExtension->cmd))
849-
{
850-
adaptExt->last_srb_id++;
851-
}
852-
853841
SendSRB(DeviceExtension, (PSRB_TYPE)Srb);
854842
}
855843
EXIT_FN_SRB();

vioscsi/vioscsi.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ typedef struct _REQUEST_LIST
276276
{
277277
LIST_ENTRY srb_list;
278278
ULONG srb_cnt;
279+
ULONG_PTR next_id;
279280
} REQUEST_LIST, *PREQUEST_LIST;
280281

281282
typedef struct virtio_bar
@@ -353,7 +354,6 @@ typedef struct _ADAPTER_EXTENSION
353354
ULONGLONG fw_ver;
354355
ULONG resp_time;
355356
BOOLEAN bRemoved;
356-
ULONG_PTR last_srb_id;
357357
} ADAPTER_EXTENSION, *PADAPTER_EXTENSION;
358358

359359
#ifndef PCIX_TABLE_POINTER

0 commit comments

Comments
 (0)