Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions vm/vmcore/guestmem/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,23 @@ impl GuestMemory {
})
}

/// Check if a given PagedRange is readable or not.
pub fn probe_gpn_readable_range(&self, range: &PagedRange<'_>) -> Result<(), GuestMemoryError> {
Comment on lines +1903 to +1904
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

[nitpick] The documentation could be more descriptive. Consider expanding it to clarify what "readable" means in this context and what errors might be returned. For example:

/// Checks if all pages in the given PagedRange are readable.
///
/// This probes each page in the range by attempting to read a single byte.
/// Returns an error if any page in the range is not accessible or is outside
/// the guest's physical address space.
///
/// # Errors
/// Returns `GuestMemoryError` if any page is inaccessible or invalid.
pub fn probe_gpn_readable_range(&self, range: &PagedRange<'_>) -> Result<(), GuestMemoryError>

The same applies to probe_gpn_writable_range.

Copilot uses AI. Check for mistakes.
self.op_range(GuestMemoryOperation::Probe, range, move |addr, _r| {
let mut b = [0];
self.read_at_inner(addr, &mut b)
Copy link
Member

Choose a reason for hiding this comment

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

Use read_plain_inner, it's more efficient.

})
}

/// Check if a given PagedRange is writable or not.
Copy link

Copilot AI Nov 19, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding similar documentation to probe_gpn_writable_range as suggested for probe_gpn_readable_range. The documentation should clarify that this checks writability by attempting a compare-exchange operation.

Suggested change
/// Check if a given PagedRange is writable or not.
/// Check if a given PagedRange is writable or not.
///
/// This checks writability by attempting a compare-exchange operation at each address in the range.
/// If the compare-exchange succeeds, the page is considered writable; otherwise, an error is returned.

Copilot uses AI. Check for mistakes.
pub fn probe_gpn_writable_range(&self, range: &PagedRange<'_>) -> Result<(), GuestMemoryError> {
self.op_range(GuestMemoryOperation::Probe, range, move |addr, _r| {
self.compare_exchange(addr, 0u8, 0)
.map(|_| ())
.map_err(|err| GuestMemoryBackingError::other(addr, err))
})
}

/// Check if a given GPA is readable or not.
pub fn probe_gpa_readable(&self, gpa: u64) -> Result<(), GuestMemoryErrorKind> {
let mut b = [0];
Expand Down