[PATCH v2 03/18] mshv: Fix mshv_prepare_pinned_region error path for unencrypted partitions

From: Stanislav Kinsburskii

Date: Sat May 02 2026 - 00:27:45 EST


mshv_prepare_pinned_region() returns 0 (success) when mshv_region_map()
fails on an unencrypted partition. The condition on the error path:

if (ret && mshv_partition_encrypted(partition))

only handles map failures for encrypted partitions — if the partition is
not encrypted and the map fails, execution falls through to 'return 0',
silently ignoring the error.

Fix by returning immediately on success and falling through to the
cleanup path on failure. For encrypted partitions, attempt to re-share
the region before invalidating. For unencrypted partitions, proceed
directly to invalidation and error return.

Fixes: 621191d709b14 ("Drivers: hv: Introduce mshv_root module to expose /dev/mshv to VMMs")
Signed-off-by: Stanislav Kinsburskii <skinsburskii@xxxxxxxxxxxxxxxxxxx>
---
drivers/hv/mshv_root_main.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c
index 665d565899c15..aa0f452aa17c1 100644
--- a/drivers/hv/mshv_root_main.c
+++ b/drivers/hv/mshv_root_main.c
@@ -1365,7 +1365,13 @@ static int mshv_prepare_pinned_region(struct mshv_mem_region *region)
}

ret = mshv_region_map(region);
- if (ret && mshv_partition_encrypted(partition)) {
+ if (ret)
+ goto share_region;
+
+ return 0;
+
+share_region:
+ if (mshv_partition_encrypted(partition)) {
int shrc;

shrc = mshv_region_share(region);
@@ -1381,9 +1387,6 @@ static int mshv_prepare_pinned_region(struct mshv_mem_region *region)
*/
goto err_out;
}
-
- return 0;
-
invalidate_region:
mshv_region_invalidate(region);
err_out: