You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ttrpc: attach Windows physical and virtual disks via registered handles - #5158
This PR adds support for attaching a host disk opened by the client, either a physical disk such as \\.\PhysicalDriveN or a VHD/VHDX, to a VM through the ttrpc/gRPC interface on Windows. Because OpenVMM uses the client's handle instead of opening a path itself, the disk is accessed with the client's rights rather than OpenVMM's own.
Callers open the disk, register the handle through the resource-passing protocol, and reference it by name with a DiskHandle in DiskBackend.physical_disk or DiskBackend.virtual_disk. Physical disks must be opened for synchronous I/O. Virtual disks must be opened with OpenVirtualDisk and attached for raw access with ATTACH_VIRTUAL_DISK_FLAG_NO_LOCAL_HOST, matching how OpenVMM opens VHDs by path. OpenVMM duplicates the handle while processing the request, so the name can be deregistered once the RPC succeeds. Either kind can also be used as the read-only lower disk of a memory_diff overlay.
The new disk_physical crate queries the disk's size and logical and physical sector sizes from the device and fails if the reported geometry is invalid. Overlapped handles are rejected, since I/O is issued through FileDisk using blocking reads and writes. To support handles opened with FILE_FLAG_NO_BUFFERING, FileDisk can now opt into 4 KiB-aligned I/O buffers. Disks whose logical sector size, or whose buffer alignment requirement as reported by FileAlignmentInfo, exceeds 4 KiB are rejected. Ordinary file disks keep their existing allocation behavior.
Virtual disk handles are wrapped as VHDMP disks, so I/O, discard, and read-only handling match VHDs that OpenVMM opens by path. VhdmpDisk now rejects handles that are not attached for raw access with a specific error rather than a failed metadata query.
Add an RPC disk backend for handles duplicated into the VMM process. Duplicate the supplied handle for owned lifetime management and obtain block-device length and sector geometry when regular file metadata is unavailable. Existing file-backed disks retain their behavior.
Source-commit: 6f71c4b
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 72311522-f27a-4daa-988b-80d159a42ac7
Preserve main's disk backend field numbers and move HandleDisk to field 4. Adapt handle dispatch to the refactored disk builder.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: c16a3c47-a7cc-4ff1-b115-8e4fc71c0627
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The physical-disk test lacks an elevation requirement or default opt-out, and accepted unbuffered disk handles can cause guest I/O failures because read/write buffers are not guaranteed to be sector-aligned.
Adds Windows physical-disk passthrough through the existing FileDisk backend. Privileged clients can register an opened disk handle for NVMe or virtio-blk devices without requiring OpenVMM itself to run elevated.
Changes:
Queries device capacity and sector geometry when file metadata is unavailable.
Adds HandleDisk configuration, registered-handle resolution, and API documentation.
Adds handle-resolution tests and a physical-disk integration test.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The new writable NVMe path can acknowledge FUA writes without ensuring durability, and image-initialization failures can leave VHDs attached to the host.
If Mount-DiskImage succeeds but Get-Disk, either Set-Disk, or parsing the returned disk number fails, this function returns before constructing MountedImage. Its Drop cleanup therefore never runs, leaving the VHD attached to the host and preventing removal of its backing temporary file. Please establish a cleanup guard immediately after mounting (or explicitly dismount on every subsequent error), and retain it until initialization succeeds.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Physical-disk passthrough changes Windows I/O and alignment guarantees, but elevated runtime validation for native 4Kn and unbuffered handles was unavailable, requiring human review of platform-specific evidence.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human review is needed to confirm elevated integration testing and representative 4Kn/unbuffered disk behavior because Windows physical-device I/O and geometry queries cannot be runtime-validated here.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The shared byte view can coexist with atomic access to the same storage, allowing safe callers to violate immutable-reference guarantees and cause cross-thread data races.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Windows runtime validation is unavailable, so writable raw-disk passthrough requires human verification of geometry fallback and sector-aligned I/O on representative 512e/4Kn disks, including unbuffered handles, to address data-integrity risks.
Fail on invalid disk geometry, move the aligned-buffer sector size check into FileDisk, rename the proto HandleDisk to PhysicalDisk, allow a physical disk under memory_diff, attach the test VHD with virtdisk instead of PowerShell, and share pipette setup helpers across the ttrpc VMM tests.
Daman Mulye (damanm24)
changed the title
disk_file: support Windows physical disk passthrough via registered handles
disk_physical: support Windows physical disk passthrough via registered handles
Nov 20, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The geometry check allows physical sector sizes above BounceBuffer’s 4096-byte alignment, which can cause Windows unbuffered I/O to fail on devices enforcing physical-sector alignment.
Add DiskBackend.virtual_disk, which references a VHD or VHDX handle that
the client opened with OpenVirtualDisk and attached for raw access, and
registered through the resource-passing protocol. OpenVMM wraps the
handle as a VHDMP disk, so the image is accessed with the client's
rights rather than OpenVMM's own, and I/O, discard and read-only
handling match disks that OpenVMM opens by path.
Physical and virtual disks now share a DiskHandle message, with the
DiskBackend field determining the kind of handle, and are resolved,
layered under memory diff overlays and rejected outside storage devices
through the same code. VhdmpDisk rejects handles that are not attached
for raw access with a specific error instead of a failed metadata
query. The handle-passing VMM test covers both kinds; the virtual disk
case does not require elevation.
Windows recommends aligning unbuffered I/O buffers to the physical sector
size, but only fails I/O whose buffers violate the device's alignment
requirement, which is often smaller. Query that requirement with
FileAlignmentInfo and reject disks that need more alignment than the
I/O buffers provide, instead of rejecting disks by physical sector size,
which would refuse disks that report large physical sectors but accept
4 KiB-aligned buffers.
Daman Mulye (damanm24)
changed the title
disk_physical: support Windows physical disk passthrough via registered handles
ttrpc: attach Windows physical and virtual disks via registered handles
Nov 21, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The current ID assertion cannot detect reversed layers or write-through, so behavioral tests for both disk kinds and nested overlays are needed to verify reads and backing-disk isolation.
Move physical disk passthrough (disk_physical, FileDisk aligned buffers, and its VMM test) to a separate follow-up change, since physical and virtual disks have different requirements. Registered disk handles can no longer be the lower disk of a memory diff overlay. VirtualDisk is now its own proto message, and VhdmpDisk rejects a writable disk whose handle was attached read-only.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Bindings to the same registered disk lack shared I/O serialization, allowing unsafe concurrent operations on one Windows file object, while advertised physical-disk and memory-diff support is also missing.
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
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.
This PR adds support for attaching a host disk opened by the client, either a physical disk such as
\\.\PhysicalDriveNor a VHD/VHDX, to a VM through the ttrpc/gRPC interface on Windows. Because OpenVMM uses the client's handle instead of opening a path itself, the disk is accessed with the client's rights rather than OpenVMM's own.Callers open the disk, register the handle through the resource-passing protocol, and reference it by name with a
DiskHandleinDiskBackend.physical_diskorDiskBackend.virtual_disk. Physical disks must be opened for synchronous I/O. Virtual disks must be opened withOpenVirtualDiskand attached for raw access withATTACH_VIRTUAL_DISK_FLAG_NO_LOCAL_HOST, matching how OpenVMM opens VHDs by path. OpenVMM duplicates the handle while processing the request, so the name can be deregistered once the RPC succeeds. Either kind can also be used as the read-only lower disk of amemory_diffoverlay.The new
disk_physicalcrate queries the disk's size and logical and physical sector sizes from the device and fails if the reported geometry is invalid. Overlapped handles are rejected, since I/O is issued throughFileDiskusing blocking reads and writes. To support handles opened withFILE_FLAG_NO_BUFFERING,FileDiskcan now opt into 4 KiB-aligned I/O buffers. Disks whose logical sector size, or whose buffer alignment requirement as reported byFileAlignmentInfo, exceeds 4 KiB are rejected. Ordinary file disks keep their existing allocation behavior.Virtual disk handles are wrapped as VHDMP disks, so I/O, discard, and read-only handling match VHDs that OpenVMM opens by path.
VhdmpDisknow rejects handles that are not attached for raw access with a specific error rather than a failed metadata query.