mshv: Handle completions on repeat hypercall failures
Subsystems (2)
PATCH 1/1 mshv: Handle completions on repeat hypercall failures
When a repeat hypercall fails, it could still have completed some of the entries requested. Fix places where completions are not checked in case of repeat hypercall failures. Also, add error prints in couple places with correct partial completion counts when repeat hypercall fails.
--- drivers/hv/mshv_common.c | 17 +++++++++++++---- drivers/hv/mshv_root_hv_call.c | 15 +++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-)
drivers/hv/mshv_common.c +13 -4
@@ -56,8 +56,6 @@ int hv_call_get_vp_registers(u32 vp_index, u64 partition_id, u16 count, status =hv_do_rep_hypercall (HVCALL_GET_VP_REGISTERS , rep_count,0 , input_page, output_page); -if (!hv_result_success (status)) -break ; completed =hv_repcomp (status);for (i =0 ; i < completed; ++i)
@@ -65,6 +63,13 @@ int hv_call_get_vp_registers(u32 vp_index, u64 partition_id, u16 count, registers += completed; remaining -= completed; + +if (!hv_result_success (status)) { +pr_err ("%s: count:%d comp:%d rem:%ld st:0x%llx\n" , + __func__, count, completed, remaining, status); +break ; + } + }local_irq_restore (flags);
@@ -99,12 +104,16 @@ int hv_call_set_vp_registers(u32 vp_index, u64 partition_id, u16 count, status =hv_do_rep_hypercall (HVCALL_SET_VP_REGISTERS , rep_count,0 , input_page,NULL ); -if (!hv_result_success (status)) -break ; completed =hv_repcomp (status); registers += completed; remaining -= completed; + +if (!hv_result_success (status)) { +pr_err ("%s: count:%d comp:%d rem:%ld st:0x%llx\n" , + __func__, count, completed, remaining, status); +break ; + } }local_irq_restore (flags);
drivers/hv/mshv_root_hv_call.c +9 -6
@@ -239,6 +239,7 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count,local_irq_restore (irq_flags); completed =hv_repcomp (status); + done += completed;if (hv_result_needs_memory (status)) { ret =hv_deposit_memory (partition_id, status);
@@ -246,11 +247,13 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count,break ; }else if (!hv_result_success (status)) { +pr_err ("%s: failed to map pages at gfn %#llx: done %u/%llu, flags=%#x, status=%#llx (%s)\n" , + __func__, gfn, done, page_count, flags, status, +hv_result_to_string (hv_result (status))); + ret =hv_result_to_errno (status);break ; } - - done += completed; }if (ret && done) {
@@ -358,18 +361,18 @@ int hv_call_get_gpa_access_states(u64 partition_id, u32 count, u64 gpa_base_pfn, status =hv_do_rep_hypercall (HVCALL_GET_GPA_PAGES_ACCESS_STATES , rep_count,0 , input_page, output_page); -if (!hv_result_success (status)) { -local_irq_restore (flags); -break ; - } completed =hv_repcomp (status);for (i =0 ; i < completed; ++i) states[i].as_uint8 = output_page[i].as_uint8;local_irq_restore (flags); + states += completed; *written_total += completed; remaining -= completed; + +if (!hv_result_success (status)) +break ; }return hv_result_to_errno (status);
Signature · 1 line
2.51.2.vfs.0.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] mshv: missing Fixes trailer for commit 621191d709b1 It also noticed 1 related pre-existing issue this…
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] mshv: missing Fixes trailer for commit 621191d709b1 It also noticed 1 related pre-existing issue this patch does not introduce:
- [High] mshv: reclaim lock inversion in hv_do_map_gpa_hcall() under mreg_mutex [1]
--
commit f6f04457a79d386b8628402d94d80fb4ab5e158c
Author: Mukesh R <[email protected]>
Quoted 8 lines
mshv: Handle completions on repeat hypercall failures
When a repeat hypercall fails, it could still have completed some of the entries requested. Fix places where completions are not checked in case of repeat hypercall failures. Also, add error prints in couple places with correct partial completion counts when repeat hypercall fails.
Signed-off-by Mukesh R <[email protected]>
[Severity: Low]
All four modified helpers were introduced with the status check placed before accounting for hv_repcomp(status). Should this include:
drivers/hv/mshv_root_hv_call.c static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count, · line 245
Quoted 12 lines
drivers/hv/mshv_root_hv_call.c +1
-0@@ -239,6 +239,7 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count,local_irq_restore (irq_flags); completed =hv_repcomp (status); + done += completed;if (hv_result_needs_memory (status)) { ret =hv_deposit_memory (partition_id, status);
[Severity: High]
This problem wasn't introduced by this patch, but can calling hv_deposit_memory() here cause a reclaim lock inversion on region->mreg_mutex [1]?
mshv_region_range_fault() and mshv_region_interval_invalidate() call mshv_region_remap_pages() -> ... -> hv_do_map_gpa_hcall() while holding region->mreg_mutex. When hv_result_needs_memory(status) is true, hv_deposit_memory() allocates pages with GFP_KERNEL via hv_call_deposit_pages() and hv_alloc_dep_pages(), which can enter direct reclaim and invoke the MMU interval notifier callback on the same region:
mshv_region_range_fault()
mutex_lock(®ion->mreg_mutex)
mshv_region_remap_pages()
...
hv_do_map_gpa_hcall()
hv_deposit_memory()
...
hv_call_deposit_pages()
get_zeroed_page(GFP_KERNEL)
<direct reclaim>
mmu_notifier_invalidate_range_start()
mshv_region_interval_invalidate()
mutex_lock(®ion->mreg_mutex) <-- deadlock[1] https://sashiko.dev/#/bug/linux-5f8ad8fe-ef3b-459b-a784-e85fb87d7746
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
From: Mukesh R <[email protected]> Sent: Thursday, November 19, 2026 6:09 PM
Quoted 7 lines
When a repeat hypercall fails, it could still have completed some of the entries requested. Fix places where completions are not checked in case of repeat hypercall failures. Also, add error prints in couple places with correct partial completion counts when repeat hypercall fails.
Signed-off-by Mukesh R <[email protected]>
Quoted 105 lines
--- drivers/hv/mshv_common.c | 17 +++++++++++++---- drivers/hv/mshv_root_hv_call.c | 15 +++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-)drivers/hv/mshv_common.c +13
-4@@ -56,8 +56,6 @@ int hv_call_get_vp_registers(u32 vp_index, u64 partition_id, u16 count, status =hv_do_rep_hypercall (HVCALL_GET_VP_REGISTERS , rep_count,0 , input_page, output_page); -if (!hv_result_success (status)) -break ; completed =hv_repcomp (status);for (i =0 ; i < completed; ++i)@@ -65,6 +63,13 @@ int hv_call_get_vp_registers(u32 vp_index, u64 partition_id, u16 count, registers += completed; remaining -= completed; + +if (!hv_result_success (status)) { +pr_err ("%s: count:%d comp:%d rem:%ld st:0x%llx\n" , + __func__, count, completed, remaining, status); +break ; + } + }local_irq_restore (flags);@@ -99,12 +104,16 @@ int hv_call_set_vp_registers(u32 vp_index, u64 partition_id, u16 count, status =hv_do_rep_hypercall (HVCALL_SET_VP_REGISTERS , rep_count,0 , input_page,NULL ); -if (!hv_result_success (status)) -break ; completed =hv_repcomp (status); registers += completed; remaining -= completed; + +if (!hv_result_success (status)) { +pr_err ("%s: count:%d comp:%d rem:%ld st:0x%llx\n" , + __func__, count, completed, remaining, status); +break ; + } }local_irq_restore (flags);drivers/hv/mshv_root_hv_call.c +9
-7@@ -239,6 +239,7 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count,local_irq_restore (irq_flags); completed =hv_repcomp (status); + done += completed;if (hv_result_needs_memory (status)) { ret =hv_deposit_memory (partition_id, status);@@ -246,11 +247,13 @@ static int hv_do_map_gpa_hcall(u64 partition_id, u64 gfn, u64 page_struct_count,break ; }else if (!hv_result_success (status)) { +pr_err ("%s: failed to map pages at gfn %#llx: done %u/%llu, flags=%#x, status=%#llx (%s)\n" , + __func__, gfn, done, page_count, flags, status, +hv_result_to_string (hv_result (status))); + ret =hv_result_to_errno (status);break ; } - - done += completed; }if (ret && done) {@@ -358,18 +361,18 @@ int hv_call_get_gpa_access_states(u64 partition_id, u32 count, u64 gpa_base_pfn, status =hv_do_rep_hypercall (HVCALL_GET_GPA_PAGES_ACCESS_STATES , rep_count,0 , input_page, output_page); -if (!hv_result_success (status)) { -local_irq_restore (flags); -break ; - } completed =hv_repcomp (status);for (i =0 ; i < completed; ++i) states[i].as_uint8 = output_page[i].as_uint8;local_irq_restore (flags); + states += completed; *written_total += completed; remaining -= completed; + +if (!hv_result_success (status)) +break ; }return hv_result_to_errno (status); --2.51.2.vfs.0.1