[STORPORT][VIOSTOR] virtio-blk storage path: per-request SCSI contexts, LUN PDOs, and a Storport miniport - #9530
Draft
jr551 wants to merge 6 commits into
Draft
[STORPORT][VIOSTOR] virtio-blk storage path: per-request SCSI contexts, LUN PDOs, and a Storport miniport#9530jr551 wants to merge 6 commits into
jr551 wants to merge 6 commits into
Conversation
added 6 commits
September 11, 2026 13:25
The vendored virtio-win library does not build in-tree as shipped: - VirtIO.h, virtio_ring.h and virtio_pci.h use PHYSICAL_ADDRESS/ULONG without including osdep.h; they only compile when the consumer happens to include a kernel header first. - virtio_pci.h declares virtio_get_queue_descriptor_size() with FORCEINLINE, which is not defined for kernel code in this tree. Guard the additions with __REACTOS__ so the files still match upstream for other consumers.
Replace the stub request path with a real implementation: - PortFdoScsi allocates a per-request STOR_REQUEST_CONTEXT (from a look-aside list) plus the miniport's SrbExtension in one allocation, publishes it in Srb->SrbExtension, marks the IRP pending before calling HwStartIo, and serializes submission with StartIoLock (now actually initialized in PortAddDevice). - StorPortNotification(RequestComplete) finds the context through the SrbExtension back-pointer, maps SrbStatus to NTSTATUS, preserves IoStatus.Information for SRB_STATUS_DATA_OVERRUN, and queues the completion on a 16-byte-aligned SLIST drained by PortCompletionDpc at DISPATCH_LEVEL -- no work items, no single-flight gate, so multiple requests can be in flight. - StorPortNotification(IssueDpc) now sets *Succ and forwards the DPC arguments; miniport DPCs requested from an ISR are deferred through PendingMiniportDpc and queued by the port's interrupt wrapper. - StorPortGetScatterGatherList builds a per-request SG list from the IRP's MDL PFN array; StorPortExtendedFunction gains ExtFunctionPutScatterGatherList to free it. - StorPortGetPhysicalAddress translates addresses inside the SRB data buffer through the MDL PFN array instead of calling MmGetPhysicalAddress on a process-dependent VA. - StorPortSynchronizeAccess is implemented via KeSynchronizeExecution. - PortPdoScsi forwards to PortFdoScsi so SCSI requests sent to a PDO reach the miniport.
- PortFdoQueryBusRelations returns a real DEVICE_RELATIONS list built from the PDO list under PdoListLock, instead of scanning the bus and reporting zero children. - PortPdoPnp implements START_DEVICE, QUERY_ID (hardware/compatible/ instance ids built from the inquiry data), QUERY_DEVICE_TEXT, TargetDeviceRelation, and REMOVE_DEVICE. BusRelations on a PDO are completed without touching IoStatus so partmgr's relations survive. - PortPdoDeviceControl handles the storage IOCTLs a disk PDO receives (STORAGE_QUERY_PROPERTY, IOCTL_DISK_GET_LENGTH_INFO and friends); PortDispatchDeviceControl routes PDO requests to it. - IRP_MN_REMOVE_DEVICE on the FDO drains the request-context look-aside list.
New miniport for PCI\VEN_1AF4&DEV_1001 (transitional/legacy virtio-blk): single split virtqueue, line interrupts, direct descriptors. The request wire format follows the BSD-3-Clause virtio-win viostor sources; the Storport integration is ReactOS-specific. - INQUIRY, READ_CAPACITY(16), MODE_SENSE, TEST_UNIT_READY, VERIFY and REQUEST_SENSE are answered locally; READ/WRITE/FLUSH go on the queue. - Per-request state lives in Srb->SrbExtension; completions are drained from the used ring in the ISR and reported via StorPortNotification(RequestComplete). - Negotiates FLUSH, CONFIG_WCE, SEG_MAX and SIZE_MAX; the transfer and physical-breaks limits reported to the port come from the negotiated device config. - Debug output through the shared virtio kdebugprint sink defaults to off (virtioDebugLevel = 0, bDebugPrint = 0).
The driver answered VPD pages 0x80 and 0x83 with a fixed string
("ROS-VIRTIO-9241-0001"), so every virtio disk reported the same
unique ID. The virtio-blk config space carries no serial field, so
derive a stable serial from the PCI bus/slot and device capacity
instead.
The feature mask dropped VIRTIO_BLK_F_RO, so a read-only virtio disk was presented as writable and writes failed at the device with a generic I/O error. Negotiate the feature, fail write CDBs early with SRB_STATUS_INVALID_REQUEST, and set the WP bit in the MODE_SENSE device-specific parameter byte.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Draft — opening for early review while I finish the last runtime checks.
What this adds
A working virtio-blk storage path for ReactOS, in six commits:
VirtIO.h,virtio_ring.h,virtio_pci.husedPHYSICAL_ADDRESS/ULONGwithout includingosdep.h, andvirtio_pci.hdeclared a functionFORCEINLINEthat isn't defined for kernel code here. Guarded with__REACTOS__so the files still match upstream for other consumers.PortFdoScsiallocates a per-requestSTOR_REQUEST_CONTEXT+ miniportSrbExtensionin one allocation, publishes it inSrb->SrbExtension, and serializes submission withStartIoLock.StorPortNotification(RequestComplete)finds the context via theSrbExtensionback-pointer and queues completions on a 16-byte-aligned SLIST drained byPortCompletionDpcat DISPATCH_LEVEL — no work items, no single-flight gate, so multiple requests can be in flight. Also implementsIssueDpc, per-requestStorPortGetScatterGatherList(built from the IRP's MDL PFN array),StorPortGetPhysicalAddress(translates inside the SRB buffer via the MDL PFNs, not a process-dependent VA), andStorPortSynchronizeAccessviaKeSynchronizeExecution.BusRelationslist,PortPdoPnp(START/QUERY_ID/QUERY_DEVICE_TEXT/TargetDeviceRelation/REMOVE),PortPdoDeviceControlfor the storage IOCTLs a disk PDO receives.PCI\VEN_1AF4&DEV_1001(transitional/legacy virtio-blk): single split virtqueue, line interrupts, direct descriptors. Request wire format follows the BSD-3-Clause virtio-winviostorsources; Storport integration is ReactOS-specific. Per-request state inSrb->SrbExtension; completions drained from the used ring in the ISR. Negotiates FLUSH, CONFIG_WCE, SEG_MAX, SIZE_MAX. Debug output defaults off.SRB_STATUS_INVALID_REQUESTand sets the WP bit in MODE_SENSE.Testing
Built i386 Release; booted the live CD under QEMU (
qemu-system-i386,-M pc) with avirtio-blk-pcibench disk and ran astress.exebattery plus sequential/random throughput benchmarks.Throughput vs the previous single-flight build (transitional virtio): SEQ write 126.97 MB/s (8.2x), SEQ read 233.06 MB/s (14.4x); legacy virtio: SEQ write 170.33 MB/s (11.2x), SEQ read 447.23 MB/s (27.5x). Debug serial log over the run: 2417 completions, 2416 success, 0 errors, 0 busy, 0 duplicate completions, 0 context mismatches, 0 SG leaks, 0 bugchecks.
Stress variants all passed with 0 bugchecks: modern, legacy, packed, twodisk, lowmem, pause, reset.
Notes
StorPortGetScatterGatherListwas anUNIMPLEMENTEDstub andIssueDpcdid not exist).MultipleRequestPerLuis set TRUE — the per-request context + SLIST completion path is what makes that safe.Marked draft pending a final clean re-run of the stress battery on this exact branch.