From: Wei Liu <[email protected]> Unmap memory regions before destroying SNP partition state, and only release regions after SNP state is torn down. Dropping regions first attempts to regain host access while the partition is still secure and can leave pages inaccessible.
Signed-off-by: Wei Liu <[email protected]> --- drivers/hv/mshv_regions.c | 2 +- drivers/hv/mshv_root.h | 1 + drivers/hv/mshv_root_main.c | 6 ++---- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/hv/mshv_regions.c b/drivers/hv/mshv_regions.c index 6d65e5b42152..62c49b4d2a33 100644 --- a/drivers/hv/mshv_regions.c +++ b/drivers/hv/mshv_regions.c @@ -337,7 +337,7 @@ static int mshv_region_chunk_unmap(struct mshv_mem_region *region, page_count, flags); } -static int mshv_region_unmap(struct mshv_mem_region *region) +int mshv_region_unmap(struct mshv_mem_region *region) { return mshv_region_process_range(region, 0, 0, region->nr_pages, diff --git a/drivers/hv/mshv_root.h b/drivers/hv/mshv_root.h index 0e6d4ce25112..0423f4adb3ac 100644 --- a/drivers/hv/mshv_root.h +++ b/drivers/hv/mshv_root.h @@ -370,6 +370,7 @@ struct mshv_mem_region *mshv_region_create(u64 guest_pfn, u64 nr_pages, int mshv_region_share(struct mshv_mem_region *region); int mshv_region_unshare(struct mshv_mem_region *region); int mshv_region_map(struct mshv_mem_region *region); +int mshv_region_unmap(struct mshv_mem_region *region); void mshv_region_invalidate(struct mshv_mem_region *region); int mshv_region_pin(struct mshv_mem_region *region); void mshv_region_put(struct mshv_mem_region *region); diff --git a/drivers/hv/mshv_root_main.c b/drivers/hv/mshv_root_main.c index c81a8d0493c1..0fbd2158968d 100644 --- a/drivers/hv/mshv_root_main.c +++ b/drivers/hv/mshv_root_main.c @@ -2166,10 +2166,8 @@ static void destroy_partition(struct mshv_partition *partition) if (mshv_partition_encrypted(partition)) { hlist_for_each_entry_safe(region, n, &partition->pt_mem_regions, - hnode) { - hlist_del(®ion->hnode); - mshv_region_put(region); - } + hnode) + mshv_region_unmap(region); ret = destroy_snp_partition_state(partition); if (ret) { -- 2.43.0

