Skip to content

disklayer_ram: add configurable sector size support#2927

Open
jstarks wants to merge 4 commits intomicrosoft:mainfrom
jstarks:ram4096
Open

disklayer_ram: add configurable sector size support#2927
jstarks wants to merge 4 commits intomicrosoft:mainfrom
jstarks:ram4096

Conversation

@jstarks
Copy link
Member

@jstarks jstarks commented Mar 10, 2026

Add support for non-512-byte sector sizes (e.g., 4096) to RamDiskLayer, which was previously hardcoded to 512-byte sectors.

Closes #1492
Supersedes #1892

jstarks added 2 commits March 10, 2026 21:40
Add support for non-512-byte sector sizes (e.g., 4096) to RamDiskLayer,
which was previously hardcoded to 512-byte sectors.

Changes:
- Replace fixed Sector([u8; 512]) with Box<[u8]> per sector
- Add sector_size and sector_shift fields to RamDiskLayer
- Add new_with_sector_size() constructor; existing new() defaults to 512
- Use bitwise shifts for sector/byte conversions in all IO paths
- LazyRamDiskLayer now inherits sector_size from the lower layer
- Add sector_size field to RamDiskLayerHandle and wire through resolver
- Add ram_disk_with_sector_size() convenience function
- Add tests for 4096-byte sectors, validation, and lazy inheritance

All existing callers are backward-compatible (sector_size: None = 512).

Closes microsoft#1492
Supersedes microsoft#1892
@jstarks jstarks requested a review from a team as a code owner March 10, 2026 22:00
Copilot AI review requested due to automatic review settings March 10, 2026 22:00
@jstarks jstarks requested a review from a team as a code owner March 10, 2026 22:00
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds configurable (power-of-two) sector-size support to the disklayer_ram RAM-backed disk layer, enabling 4K-sector ramdisks and propagating sector size through the resource handle/resolver stack for layered disks.

Changes:

  • Extend RamDiskLayer/LazyRamDiskLayer to support configurable sector sizes (defaulting to 512) and update IO math/storage accordingly.
  • Extend RamDiskLayerHandle with an optional sector_size and update relevant call sites to populate the new field.
  • Add unit tests covering 4K read/write behavior, sector count calculation, and invalid sector-size validation.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
vmm_tests/vmm_tests/tests/tests/x86_64/storage.rs Updates ramdisk handle construction to include the new sector_size field.
vmm_tests/vmm_tests/tests/tests/multiarch/openhcl_servicing.rs Updates some ramdisk handle constructions for the new sector_size field (but one remains missing).
vm/devices/storage/disklayer_ram/src/resolver.rs Resolver now always returns a LazyRamDiskLayer configured from handle fields (len/sector_size).
vm/devices/storage/disklayer_ram/src/lib.rs Implements configurable sector sizing, updates read/write/unmap logic, adds ram_disk_with_sector_size, and adds tests.
vm/devices/storage/disk_backend_resources/src/layer.rs Adds sector_size: Option<u32> to RamDiskLayerHandle with documentation.
petri/src/vm/openvmm/mod.rs Updates RAM disk handle literals to include sector_size: None.
openvmm/openvmm_entry/src/lib.rs Updates RAM disk handle literals to include sector_size: None.

You can also share your feedback on Copilot code review. Take the survey.

}

#[async_test]
async fn test_4096_sector_write_read() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot: remind me, where is RMW handled (when the app wants to issue a 512B read to this device). Do we propagate this sector size all the way up to the guest?

(I'm curious to see if I can invoke copilot to reason for me, in pr comments)

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 4k sector / block size support to ramdisk

3 participants