Skip to content

guestmem, scsi_buffers: clarify PagedRange and RequestBuffers documentation#2845

Merged
jstarks merged 3 commits intomicrosoft:mainfrom
jstarks:clarify
Feb 27, 2026
Merged

guestmem, scsi_buffers: clarify PagedRange and RequestBuffers documentation#2845
jstarks merged 3 commits intomicrosoft:mainfrom
jstarks:clarify

Conversation

@jstarks
Copy link
Member

@jstarks jstarks commented Feb 26, 2026

Improve the documentation on PagedRange and RequestBuffers to make their memory model constraints explicit:

  • PagedRange: add module-level and struct-level docs with ASCII diagrams explaining that interior pages are always fully covered. Only the first and last pages may be partial. This means multiple guest memory regions with arbitrary GPAs cannot always be combined into a single PagedRange.

  • RequestBuffers: explain the single-range limitation and its implications for scatter-gather IO (e.g., virtio descriptor chains). Document what is_aligned() actually checks and when bounce buffering is needed.

  • BounceBuffer: explain the read vs write copy direction and page-alignment guarantee.

These constraints are particularly relevant for virtio device implementations, where the guest controls descriptor shapes and a descriptor chain may split at arbitrary (non-sector-aligned) byte boundaries.

…tation

Improve the documentation on PagedRange and RequestBuffers to make their
memory model constraints explicit:

- PagedRange: add module-level and struct-level docs with ASCII diagrams
  explaining that interior pages are always fully covered. Only the first
  and last pages may be partial. This means multiple guest memory regions
  with arbitrary GPAs cannot always be combined into a single PagedRange.

- RequestBuffers: explain the single-range limitation and its implications
  for scatter-gather IO (e.g., virtio descriptor chains). Document what
  is_aligned() actually checks and when bounce buffering is needed.

- BounceBuffer: explain the read vs write copy direction and page-alignment
  guarantee.

These constraints are particularly relevant for virtio device
implementations, where the guest controls descriptor shapes and a
descriptor chain may split at arbitrary (non-sector-aligned) byte
boundaries.
@jstarks jstarks requested a review from a team as a code owner February 26, 2026 02:05
Copilot AI review requested due to automatic review settings February 26, 2026 02:05
@jstarks jstarks requested a review from a team as a code owner February 26, 2026 02:05
@github-actions github-actions bot added the unsafe Related to unsafe code label Feb 26, 2026
@github-actions
Copy link

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

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

This PR improves developer-facing documentation for guest memory buffer abstractions used across the storage/virtio stacks, clarifying the memory model constraints of PagedRange and the implications for RequestBuffers/bounce buffering.

Changes:

  • Add module- and type-level docs to guestmem::ranges describing the PagedRange memory model and its “interior pages must be fully covered” constraint.
  • Expand scsi_buffers crate docs to explain RequestBuffers single-range limitations, alignment checking semantics, and when bounce buffering is required.
  • Clarify BounceBuffer behavior and intended copy direction for read vs write paths.

Reviewed changes

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

File Description
vm/vmcore/guestmem/src/ranges.rs Adds detailed documentation and diagrams describing PagedRange’s memory model and constraints.
vm/devices/storage/scsi_buffers/src/lib.rs Expands crate/type/method docs around request buffers, alignment requirements, and bounce buffering.

Copy link
Member

@chris-oo chris-oo left a comment

Choose a reason for hiding this comment

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

LGTM but fix the typo flagged?

Copy link
Contributor

@mattkur mattkur left a comment

Choose a reason for hiding this comment

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

Agree with the copilot comments. (I also wonder what led you to feel the need to be quite so ... forceful ... in documenting the internal contiguity guarantee :), but I agree this helps clarify the semantics here quite a lot).

@jstarks
Copy link
Member Author

jstarks commented Feb 27, 2026

Claude kept getting confused about the contract. If Claude is confused, probably everyone else is, too.

jstarks and others added 2 commits February 26, 2026 22:33
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jstarks jstarks merged commit 723a3e8 into microsoft:main Feb 27, 2026
56 checks passed
@jstarks jstarks deleted the clarify branch February 27, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants