Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pin Vtl2 memory if its being carve out by itself #169

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bhargavshah1988
Copy link

Pin VTL2 memory if it is being carved out independently. In the current implementation, specifically in add-on mode, the host ensures that VTL2 memory is physically backed. This change enhances that mechanism by explicitly pinning the VTL2 memory when it is carved out.

@bhargavshah1988 bhargavshah1988 requested a review from a team as a code owner October 21, 2024 19:05
use hvdef::hypercall::HvInputVtl;
use hvdef::HV_PAGE_SIZE;
use memory_range::MemoryRange;
use minimal_rt::arch::hypercall::invoke_hypercall;
use zerocopy::AsBytes;

const PIN_REQUEST_HEADER_SIZE: usize = size_of::<hvdef::hypercall::PinUnpinGpaPageRangesHeader>();
Copy link
Member

Choose a reason for hiding this comment

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

Move this into the relevant function

let mut ranges = ArrayVec::new();

// Calculate the total number of pages in the memory range
let total_pages = (memory_range.end() - memory_range.start()).div_ceil(PAGE_SIZE);
Copy link
Member

Choose a reason for hiding this comment

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

.page_count_4k()

let total_pages = (memory_range.end() - memory_range.start()).div_ceil(PAGE_SIZE);

// Iterate over the memory range in chunks of 2048 pages
let mut current_page = memory_range.start() >> 12; // Convert start address to page number
Copy link
Member

Choose a reason for hiding this comment

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

.start_4k_gpn()

ranges.push(HvGpaRange(
HvGpaRangeExtended::new()
.with_additional_pages(pages_in_this_range - 1)
.with_large_page(false)
Copy link
Member

Choose a reason for hiding this comment

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

Why not use the large pages when possible?

let mut current_page = memory_range.start() >> 12; // Convert start address to page number
let mut remaining_pages = total_pages;

while remaining_pages > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

I recommend doing something like while current_page < memory_range.end_4k_gpn() and removing remaining_pages as a separate variable. IMO it's almost always better to have a single loop variable.

let header = hvdef::hypercall::PinUnpinGpaPageRangesHeader { reserved: 0 };
let input_offset = size_of::<hvdef::hypercall::PinUnpinGpaPageRangesHeader>();

while remaining_size_bytes > 0 {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto here.


while remaining_size_bytes > 0 {
// Determine the size for this chunk of memory
let chunk_bytes = cmp::min(remaining_size_bytes, max_bytes_per_request);
Copy link
Member

Choose a reason for hiding this comment

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

I'd just write let chunk_end = (current_start + max_bytes_per_request).min(memory_range.end())

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.

2 participants