@samitouri / QOSamiQemu / commits / a173f8f170

target/i386/mshv: hv_vp_register_page setup for the vcpu

When the vcpu is created, call mmap to configure access to the register page. Update CPUArchState to store a pointer to the mmapped hv_vp_register_page. Signed-off-by: Doru Blânzeanu <dblanzeanu@linux.microsoft.com> Reviewed-by: Mohamed Mediouni <mohamed@unpredictable.fr> Link: https://lore.kernel.org/r/20260428135053.251200-5-dblanzeanu@linux.microsoft.com Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Doru Blânzeanu committed Apr 28, 2026 at 16:50 UTC a173f8f17001907ee41badcc9ceb824113bc0da4
2 files changed +24 -2
target/i386/cpu.h
+7 -2
@@ -1983,6 +1983,9 @@ typedef struct CPUCaches {
1983 CPUCacheInfo *l3_cache;
1984 } CPUCaches;
1985
1986 +struct kvm_msrs;
1987 +struct hv_vp_register_page;
1988 +
1989 typedef struct CPUArchState {
1990 /* standard registers */
1991 target_ulong regs[CPU_NB_EREGS];
@@ -2289,6 +2292,10 @@ typedef struct CPUArchState {
2292 QEMUTimer *xen_periodic_timer;
2293 QemuMutex xen_timers_lock;
2294 #endif
2295 +#if defined(CONFIG_MSHV)
2296 + /* Shared register page */
2297 + struct hv_vp_register_page *regs_page;
2298 +#endif
2299 #if defined(CONFIG_HVF) || defined(CONFIG_MSHV) || defined(CONFIG_WHPX)
2300 void *emu_mmio_buf;
2301 #endif
@@ -2315,8 +2322,6 @@ typedef struct CPUArchState {
2322 DECLARE_BITMAP(avail_cpu_topo, CPU_TOPOLOGY_LEVEL__MAX);
2323 } CPUX86State;
2324
2318 -struct kvm_msrs;
2319 -
2325 /**
2326 * X86CPU:
2327 * @env: #CPUX86State
target/i386/mshv/mshv-cpu.c
+17
@@ -1906,6 +1906,18 @@ void mshv_arch_init_vcpu(CPUState *cpu)
1906 + sizeof(hv_input_get_vp_registers)
1907 > HV_HYP_PAGE_SIZE));
1908
1909 + /* mmap the registers page */
1910 + void *rp = mmap(NULL, page, PROT_READ | PROT_WRITE,
1911 + MAP_SHARED, mshv_vcpufd(cpu),
1912 + MSHV_VP_MMAP_OFFSET_REGISTERS * page);
1913 + if (rp == MAP_FAILED) {
1914 + warn_report("register page mmap failed, falling back to hypercalls: %s",
1915 + strerror(errno));
1916 + env->regs_page = NULL;
1917 + } else {
1918 + env->regs_page = (struct hv_vp_register_page *) rp;
1919 + }
1920 +
1921 state->hvcall_args.base = mem;
1922 state->hvcall_args.input_page = mem;
1923 state->hvcall_args.output_page = (uint8_t *)mem + page;
@@ -1944,6 +1956,11 @@ void mshv_arch_destroy_vcpu(CPUState *cpu)
1956 CPUX86State *env = &x86_cpu->env;
1957 AccelCPUState *state = cpu->accel;
1958
1959 + /* Unmap the register page */
1960 + if (env->regs_page) {
1961 + munmap(env->regs_page, HV_HYP_PAGE_SIZE);
1962 + env->regs_page = NULL;
1963 + }
1964 g_free(state->hvcall_args.base);
1965 state->hvcall_args = (MshvHvCallArgs){0};
1966 g_clear_pointer(&env->emu_mmio_buf, g_free);