When hv_do_map_pfns() fails after partially mapping large pages, the
unmap count passed to hv_call_unmap_pfns() is incorrect. The 'done'
variable tracks the number of large pages mapped, but the unmap
function expects the count in 4KB page units.

This causes incomplete cleanup on error, potentially leaving stale
mappings in the partition. Shift the count by large_shift to convert
from large page count to 4KB page count before calling the unmap
function.

Fixes: 621191d709b14 ("Drivers: hv: Introduce mshv_root module to expose 
/dev/mshv to VMMs")
Signed-off-by: Stanislav Kinsburskii <[email protected]>
---
 drivers/hv/mshv_root_hv_call.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/hv/mshv_root_hv_call.c b/drivers/hv/mshv_root_hv_call.c
index 6381f949d9d9..905ea32e2c75 100644
--- a/drivers/hv/mshv_root_hv_call.c
+++ b/drivers/hv/mshv_root_hv_call.c
@@ -268,8 +268,10 @@ static int hv_do_map_pfns(u64 partition_id, u64 gfn, u64 
pfns_count,
        if (ret && done) {
                u32 unmap_flags = 0;
 
-               if (flags & HV_MAP_GPA_LARGE_PAGE)
+               if (flags & HV_MAP_GPA_LARGE_PAGE) {
                        unmap_flags |= HV_UNMAP_GPA_LARGE_PAGE;
+                       done <<= large_shift;
+               }
                hv_call_unmap_pfns(partition_id, gfn, done, unmap_flags);
        }
 



Reply via email to