mshv: Do pre-commit before mapping a guest VM GPA
Subsystems (3)
PATCH 1/1 mshv: Do pre-commit before mapping a guest VM GPA
Pre commit reduces TLB flush overheads in the hypervisor. On systems with large number of CPUs, there is signficant advantage to doing this. Pre-commit allows the hypervisor to build all data structs needed in anticipation of the map gpa hypercall, thus reducing or eliminating deposit page returns from the map gpa hypercall, and as a result reducing TLB flushes. In some performance benchmarks, it made the maps of large ranges almost 30% faster.
Please note, the memory requirement is same whether the follow up map gpa calls use large page flag or not. The flags field in the input parameter in the pre-commit hypercall does not have any large page options/bits.
---
Changes in v1:
o Don't call pre-commit from hv_do_map_gpa_hcall(), that results in multiple calls: first during entire NO_ACCESS map of the ram range, then again when the range is actually mapped. Move calls up closer to where the regions are created.
drivers/hv/mshv_regions.c | 6 +++++ drivers/hv/mshv_root.h | 1 + drivers/hv/mshv_root_hv_call.c | 48 ++++++++++++++++++++++++++++++++++ drivers/hv/mshv_root_main.c | 5 ++++ include/asm-generic/mshyperv.h | 3 +++ include/hyperv/hvgdk_mini.h | 1 + include/hyperv/hvhdk.h | 7 +++++ 7 files changed, 71 insertions(+)
drivers/hv/mshv_regions.c +6 -0
@@ -266,6 +266,12 @@ static int mshv_region_remap_pages(struct mshv_mem_region *region,int mshv_region_map (struct mshv_mem_region *region) {u32 map_flags = region->hv_map_flags; +int ret; + + ret =hv_pre_commit_gpa (region->partition->pt_id, + region->start_gfn, region->nr_pages); +if (ret) +return ret;return mshv_region_remap_pages (region, map_flags,0 , region->nr_pages);
drivers/hv/mshv_root.h +1 -0
@@ -282,6 +282,7 @@ int hv_call_initialize_partition(u64 partition_id);int hv_call_finalize_partition (u64 partition_id);int hv_call_delete_partition (u64 partition_id);int hv_call_map_mmio_pages (u64 partition_id,u64 gfn,u64 mmio_spa,u64 numpgs); +int hv_pre_commit_gpa (u64 pt_id,u64 gfn,u64 num_pages);int hv_call_map_gpa_pages (u64 partition_id,u64 gpa_target,u64 page_count,u32 flags,struct page **pages); int hv_call_unmap_gpa_pages(u64 partition_id, u64 gpa_target, u64 page_count,
drivers/hv/mshv_root_hv_call.c +48 -0
54 lines not on this page · raw message
drivers/hv/mshv_root_main.c +5 -0
@@ -1394,6 +1394,11 @@ mshv_map_user_memory(struct mshv_partition *partition,* the hypervisor track dirty pages, enabling pre-copy live * migration. */ + ret =hv_pre_commit_gpa (region->partition->pt_id, + region->start_gfn, region->nr_pages); +if (ret) +break ; + ret = hv_call_map_gpa_pages(partition->pt_id, region->start_gfn, region->nr_pages,
include/asm-generic/mshyperv.h +3 -0
@@ -28,6 +28,9 @@#define VTPM_BASE_ADDRESS 0xfed40000 +#define HV_REP_COUNT_MAX \ + (HV_HYPERCALL_REP_COMP_MASK >> HV_HYPERCALL_REP_COMP_OFFSET) +enum hv_partition_type {HV_PARTITION_TYPE_GUEST ,HV_PARTITION_TYPE_ROOT ,
include/hyperv/hvgdk_mini.h +1 -0
@@ -489,6 +489,7 @@ union hv_vp_assist_msr_contents { /* HV_REGISTER_VP_ASSIST_PAGE */#define HVCALL_FLUSH_GUEST_PHYSICAL_ADDRESS_LIST 0x00b0#define HVCALL_CREATE_DEVICE_DOMAIN 0x00b1#define HVCALL_ATTACH_DEVICE_DOMAIN 0x00b2 +#define HVCALL_PRECOMMIT_GPA_PAGES 0x00be#define HVCALL_SIGNAL_EVENT_DIRECT 0x00c0#define HVCALL_POST_MESSAGE_DIRECT 0x00c1#define HVCALL_DISPATCH_VP 0x00c2
include/hyperv/hvhdk.h +7 -0
@@ -953,4 +953,11 @@ struct hv_input_modify_sparse_spa_page_host_access {#define HV_MODIFY_SPA_PAGE_HOST_ACCESS_LARGE_PAGE 0x4#define HV_MODIFY_SPA_PAGE_HOST_ACCESS_HUGE_PAGE 0x8 +struct hv_input_precommit_gpa_pages {/* HV_INPUT_PRECOMMIT_GPA_PAGES */ +u64 partition_id; +u32 flags; +u32 reserved; +u64 target_gpa_base; +} __packed; +#endif /* _HV_HVHDK_H */
Signature · 1 line
2.51.2.vfs.0.1