[PATCH v2 6/7] mshv: Simplify pfn array handling in region processing
From: Stanislav Kinsburskii
Date: Thu Apr 02 2026 - 14:05:30 EST
The current code requires passing both the full pfn array and an offset
parameter to region processing functions, forcing callees to manually
index into arrays. This approach is inflexible and makes it difficult
to work with different sources of pfn arrays.
Upcoming changes will need to pass pfn arrays obtained from the HMM
framework directly to these functions. The HMM framework returns arrays
that represent specific ranges rather than full region arrays with
offsets, making the current offset-based indexing pattern incompatible.
Refactor by having callers pass pre-offset pointers to pfn arrays and
removing offset-based indexing from callees. This allows functions to
work with any pfn array starting at index 0, regardless of its source,
and prepares the code for HMM integration.
No functional change intended.
Signed-off-by: Stanislav Kinsburskii <skinsburskii@xxxxxxxxxxxxxxxxxxx>
---
drivers/hv/mshv_regions.c | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/drivers/hv/mshv_regions.c b/drivers/hv/mshv_regions.c
index 120ce2588501..3c2a35f3bc31 100644
--- a/drivers/hv/mshv_regions.c
+++ b/drivers/hv/mshv_regions.c
@@ -92,7 +92,7 @@ static long mshv_region_process_pfns(struct mshv_region *region,
unsigned long pfn;
int stride, ret;
- pfn = pfns[pfn_offset];
+ pfn = pfns[0];
if (!pfn_valid(pfn))
return -EINVAL;
@@ -102,7 +102,7 @@ static long mshv_region_process_pfns(struct mshv_region *region,
/* Start at stride since the first stride is validated */
for (count = stride; count < pfn_count ; count += stride) {
- pfn = pfns[pfn_offset + count];
+ pfn = pfns[count];
/* Break if current pfn is invalid */
if (!pfn_valid(pfn))
@@ -157,7 +157,7 @@ static long mshv_region_process_chunk(struct mshv_region *region,
unsigned long *pfns,
pfn_handler_t handler)
{
- if (pfn_valid(pfns[pfn_offset]))
+ if (pfn_valid(pfns[0]))
return mshv_region_process_pfns(region, flags,
pfn_offset, pfn_count, pfns,
handler);
@@ -204,10 +204,7 @@ static int mshv_region_process_range(struct mshv_region *region,
if (end > region->nr_pfns)
return -EINVAL;
- start = pfn_offset;
- end = pfn_offset + 1;
-
- while (end < pfn_offset + pfn_count) {
+ for (start = 0, end = 1; end < pfn_count; ) {
/*
* Accumulate contiguous pfns with the same validity
* (valid or not).
@@ -218,8 +215,9 @@ static int mshv_region_process_range(struct mshv_region *region,
}
ret = mshv_region_process_chunk(region, flags,
- start, end - start,
- pfns, handler);
+ pfn_offset + start,
+ end - start,
+ pfns + start, handler);
if (ret < 0)
return ret;
@@ -227,8 +225,9 @@ static int mshv_region_process_range(struct mshv_region *region,
}
ret = mshv_region_process_chunk(region, flags,
- start, end - start,
- pfns, handler);
+ pfn_offset + start,
+ end - start,
+ pfns + start, handler);
if (ret < 0)
return ret;
@@ -296,15 +295,14 @@ static int mshv_region_chunk_share(struct mshv_region *region,
unsigned long *pfns,
bool huge_page)
{
- if (!pfn_valid(pfns[pfn_offset]))
+ if (!pfn_valid(pfns[0]))
return -EINVAL;
if (huge_page)
flags |= HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE;
return hv_call_modify_spa_host_access(region->partition->pt_id,
- pfns + pfn_offset,
- pfn_count,
+ pfns, pfn_count,
HV_MAP_GPA_READABLE |
HV_MAP_GPA_WRITABLE,
flags, true);
@@ -326,15 +324,15 @@ static int mshv_region_chunk_unshare(struct mshv_region *region,
unsigned long *pfns,
bool huge_page)
{
- if (!pfn_valid(pfns[pfn_offset]))
+ if (!pfn_valid(pfns[0]))
return -EINVAL;
if (huge_page)
flags |= HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE;
return hv_call_modify_spa_host_access(region->partition->pt_id,
- pfns + pfn_offset,
- pfn_count, 0,
+ pfns, pfn_count,
+ 0,
flags, false);
}
@@ -359,7 +357,7 @@ static int mshv_region_chunk_remap(struct mshv_region *region,
* hypervisor track dirty pages, enabling precopy live
* migration.
*/
- if (!pfn_valid(pfns[pfn_offset]))
+ if (!pfn_valid(pfns[0]))
flags = HV_MAP_GPA_NO_ACCESS;
if (huge_page)
@@ -368,7 +366,7 @@ static int mshv_region_chunk_remap(struct mshv_region *region,
return hv_call_map_ram_pfns(region->partition->pt_id,
region->start_gfn + pfn_offset,
pfn_count, flags,
- pfns + pfn_offset);
+ pfns);
}
static int mshv_region_remap_pfns(struct mshv_region *region,
@@ -658,7 +656,7 @@ static int mshv_region_collect_and_map(struct mshv_region *region,
ret = mshv_region_remap_pfns(region, region->hv_map_flags,
pfn_offset, pfn_count,
- region->mreg_pfns);
+ region->mreg_pfns + pfn_offset);
mutex_unlock(®ion->mreg_mutex);
out: