From nobody Sun Apr 12 00:56:44 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1772441122; cv=none; d=zohomail.com; s=zohoarc; b=A6c3AzqvES3R/VeWrRNiTpHo44jd3w/LuL1FoLCfcuUchQlWiP3j9Quku1qUqXwZ5KIxsaL+G0iB0LOnUi9SD9E0GVP55NeEYhgGzP/RK8NFNKDgE1yF3oR0+IEDRajivsfkOY+W2x4iLBCPhq9BTEPzOj68bniPtKt39WFnzX0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772441122; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=lfcZzc/DZcWi8if1BQU+wSLjMESP5Db2QDdPAzM1JlA=; b=Zh7pQjHktpnyyf5pvJh4tl5qmn5x5Py7SCCAMstm9P3iqbJuLLY0PgXp6y143R++Me2S4SgJNQV+NoFvR3TToK6aT5XSybo/XCrT5/6GW+gseftkymrs0PnvIP/mvAAA5SUtTv9YqL8ivcvqJZDs+ClLek5fbKgdWN0Vyt2ervQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772441121997529.2035649571119; Mon, 2 Mar 2026 00:45:21 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vwyt8-0001ej-Fi; Mon, 02 Mar 2026 03:44:26 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vwyt4-0001X8-4k for qemu-devel@nongnu.org; Mon, 02 Mar 2026 03:44:23 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vwysy-0001Ww-BI for qemu-devel@nongnu.org; Mon, 02 Mar 2026 03:44:19 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-252-FktiBpIuO0Or_IgM3xCAZQ-1; Mon, 02 Mar 2026 03:44:14 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-48071615686so32863135e9.1 for ; Mon, 02 Mar 2026 00:44:14 -0800 (PST) Received: from [192.168.10.48] ([151.95.144.138]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483bd7030b9sm317685125e9.4.2026.03.02.00.44.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Mar 2026 00:44:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1772441055; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lfcZzc/DZcWi8if1BQU+wSLjMESP5Db2QDdPAzM1JlA=; b=dXkCNUXMQvz7hbmsEuwiJG2JfxyekZ8Am2JA6e8QejekpHMEy1AlmaN+nSyrAVMx4aKikT zcjzJQemqGXtfvCGCw0HkYI6KbcI9CwGWqM5fHYG0uOdILxHV3WVEU5nIYMPBiPCjhSDc+ LTbeV3mmuEO0GKwcU0++SU6k2nU/lAg= X-MC-Unique: FktiBpIuO0Or_IgM3xCAZQ-1 X-Mimecast-MFC-AGG-ID: FktiBpIuO0Or_IgM3xCAZQ_1772441053 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1772441052; x=1773045852; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=lfcZzc/DZcWi8if1BQU+wSLjMESP5Db2QDdPAzM1JlA=; b=mAZZ0Xl3la3bZJF6jcg/8R0W5eYM5z9bbHtV5pLbYiryZ51xAHWNuo2hB60+pREnW8 hMQ8iZxxbaUu4vaBOHLLQoZFnBKKcyuXuXKwxFhEtqYcoCj+WvIr1xxzZ/fwfQ38YynG NQXuzkaqAeovXkYbhtD9W7D/yvr5XNT9iixaHxiAA7LcZs+iKaG9JB4+JjA5ehXF+8K4 EnouZVvdW5Ny/T7SyeOB0R0uUR9rTYZn6Q/GUTKA772vTJFHWRYiuNo3+jaWfwqKn9nm OwMNhqwLL5IkPtie5Zr54AD2i9Vj3H09n+HcWXf9t6GzjCs16wnMSRaEvr749USTQT8m HgaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772441052; x=1773045852; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=lfcZzc/DZcWi8if1BQU+wSLjMESP5Db2QDdPAzM1JlA=; b=cxbBZpybxjBP6UI5PWUZtXWvsJRmnQ688dN7Dmck7y3GpC8W8hjePg23HTY/FNXOwL YD+36um4WQQ7prZDMo4SLhXeGImqEgPeO03tOw1VuxQ8TqEyo/YPUfUkwaWTVkNznVuc dsC+TtNhN7diGRQsTC+Tes4MZNWxRIiXOUnSXdaQ2J6yQFVXIloYxnmy2SXX+P3aY+YZ CK2S7kc4QgFHCbbRqVMIFZsDVknaXp4DoDidtWAsLYvwRn511zgN8X9iaAmK+bhWAPSF PcCEfzyt3P7IuFwzOpoQOFmR1UTY+IapsRBzwq4hWDE8f7gheReknIJ2xtAmroAizZOr 0VSA== X-Gm-Message-State: AOJu0YyL0EMJbj82s+DJJiqU8dj5CYzuL1448lyNShDpEx8DazWPRYGz +692VjMM7+INdWkTQ55iGbzJBahM6G9RZxa733nysClnIEyGkZZCuPxbxpnXA9YXig0xF4HrkO8 ApnsWdZl/3zM8qSijRM16AEcbgLMGAmro1/S7eZwIeXBP8oX1paTnMO6Ilxwhh+rgwJ0G88wLm1 1mgCda9VRD43vpavpZxYhn3VDyDQI8rOXfOD/ISTl3 X-Gm-Gg: ATEYQzy2YKCoSnoT7Yn0k1tb7Y/4GsT3CFbMmQRuP+jQ0qyuX6thvnlixHw4fI6JLE0 cRWEdVzCQsUykGQOhoFV7gq5cmlWUfxGkB9gp3n18h2MBhzyOtvxtCZC3PhZ8CRU2MrFhVXwMiO Xmtzb30BUSxbxbqgX3Y9j46XGPud9tK+Gqkvw5NaZfIYTHB3GmyWu+w2P/HSAOwnYdTc/udUDGw K/TdDgnFKVPOQ0NpHlJRG5/ZD0d4m62mWW3UjJRCCfS71NJgbTdLPfuG/4UxlF5T34cD6DmrytB /bGVxyv1ZdcoUcW4Wigync/45xUIRDBbZulyhzvm3GM+KNjKps/6T4RF3wSzrbGeIlyfUkpNV/B tPlH5Hpe8VPBIyoBPrjs4cGABkgIj9/3AXuv7tjvHraPo1sUV3FVEH4+qBQapYLruyVaTxU4AGi McDLlFB77zBZtdoGVqIntHHicqEpE= X-Received: by 2002:a05:600c:4fc8:b0:47b:e2a9:2bd7 with SMTP id 5b1f17b1804b1-483c9beaca0mr238450375e9.19.1772441052291; Mon, 02 Mar 2026 00:44:12 -0800 (PST) X-Received: by 2002:a05:600c:4fc8:b0:47b:e2a9:2bd7 with SMTP id 5b1f17b1804b1-483c9beaca0mr238449855e9.19.1772441051694; Mon, 02 Mar 2026 00:44:11 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Mohamed Mediouni Subject: [PULL 011/102] whpx: i386: switch over from winhvemulation to target/i386/emulate Date: Mon, 2 Mar 2026 09:42:06 +0100 Message-ID: <20260302084338.473368-12-pbonzini@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260302084338.473368-1-pbonzini@redhat.com> References: <20260302084338.473368-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.012, RCVD_IN_VALIDITY_RPBL_BLOCKED=1.188, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1772441127653158501 Content-Type: text/plain; charset="utf-8" From: Mohamed Mediouni Using the mshv backend as a base, move away from winhvemulation to using common QEMU code used by the HVF and mshv backends. Signed-off-by: Mohamed Mediouni Link: https://lore.kernel.org/r/20260223233950.96076-11-mohamed@unpredictab= le.fr Signed-off-by: Paolo Bonzini --- target/i386/whpx/whpx-all.c | 274 +++++++++++++++++------------------- 1 file changed, 126 insertions(+), 148 deletions(-) diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c index cdcaebbe167..eb6076d2f49 100644 --- a/target/i386/whpx/whpx-all.c +++ b/target/i386/whpx/whpx-all.c @@ -15,6 +15,7 @@ #include "gdbstub/helpers.h" #include "qemu/accel.h" #include "accel/accel-ops.h" +#include "system/memory.h" #include "system/whpx.h" #include "system/cpus.h" #include "system/runstate.h" @@ -36,8 +37,12 @@ #include "system/whpx-all.h" #include "system/whpx-common.h" =20 +#include "emulate/x86_decode.h" +#include "emulate/x86_emu.h" +#include "emulate/x86_flags.h" +#include "emulate/x86_mmu.h" + #include -#include =20 #define HYPERV_APIC_BUS_FREQUENCY (200000000ULL) =20 @@ -756,160 +761,140 @@ void whpx_get_registers(CPUState *cpu) x86_update_hflags(env); } =20 -static HRESULT CALLBACK whpx_emu_ioport_callback( - void *ctx, - WHV_EMULATOR_IO_ACCESS_INFO *IoAccess) +static int emulate_instruction(CPUState *cpu, const uint8_t *insn_bytes, s= ize_t insn_len) { - MemTxAttrs attrs =3D { 0 }; - address_space_rw(&address_space_io, IoAccess->Port, attrs, - &IoAccess->Data, IoAccess->AccessSize, - IoAccess->Direction); - return S_OK; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + struct x86_decode decode =3D { 0 }; + x86_insn_stream stream =3D { .bytes =3D insn_bytes, .len =3D insn_len = }; + + whpx_get_registers(cpu); + decode_instruction_stream(env, &decode, &stream); + exec_instruction(env, &decode); + whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE); + + return 0; } =20 -static HRESULT CALLBACK whpx_emu_mmio_callback( - void *ctx, - WHV_EMULATOR_MEMORY_ACCESS_INFO *ma) +static int whpx_handle_mmio(CPUState *cpu, WHV_RUN_VP_EXIT_CONTEXT *exit_c= tx) { - CPUState *cs =3D (CPUState *)ctx; - AddressSpace *as =3D cpu_addressspace(cs, MEMTXATTRS_UNSPECIFIED); + WHV_MEMORY_ACCESS_CONTEXT *ctx =3D &exit_ctx->MemoryAccess; + int ret; =20 - address_space_rw(as, ma->GpaAddress, MEMTXATTRS_UNSPECIFIED, - ma->Data, ma->AccessSize, ma->Direction); - return S_OK; -} - -static HRESULT CALLBACK whpx_emu_getreg_callback( - void *ctx, - const WHV_REGISTER_NAME *RegisterNames, - UINT32 RegisterCount, - WHV_REGISTER_VALUE *RegisterValues) -{ - HRESULT hr; - struct whpx_state *whpx =3D &whpx_global; - CPUState *cpu =3D (CPUState *)ctx; - - hr =3D whp_dispatch.WHvGetVirtualProcessorRegisters( - whpx->partition, cpu->cpu_index, - RegisterNames, RegisterCount, - RegisterValues); - if (FAILED(hr)) { - error_report("WHPX: Failed to get virtual processor registers," - " hr=3D%08lx", hr); - } - - return hr; -} - -static HRESULT CALLBACK whpx_emu_setreg_callback( - void *ctx, - const WHV_REGISTER_NAME *RegisterNames, - UINT32 RegisterCount, - const WHV_REGISTER_VALUE *RegisterValues) -{ - HRESULT hr; - struct whpx_state *whpx =3D &whpx_global; - CPUState *cpu =3D (CPUState *)ctx; - - hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( - whpx->partition, cpu->cpu_index, - RegisterNames, RegisterCount, - RegisterValues); - if (FAILED(hr)) { - error_report("WHPX: Failed to set virtual processor registers," - " hr=3D%08lx", hr); - } - - /* - * The emulator just successfully wrote the register state. We clear t= he - * dirty state so we avoid the double write on resume of the VP. - */ - cpu->vcpu_dirty =3D false; - - return hr; -} - -static HRESULT CALLBACK whpx_emu_translate_callback( - void *ctx, - WHV_GUEST_VIRTUAL_ADDRESS Gva, - WHV_TRANSLATE_GVA_FLAGS TranslateFlags, - WHV_TRANSLATE_GVA_RESULT_CODE *TranslationResult, - WHV_GUEST_PHYSICAL_ADDRESS *Gpa) -{ - HRESULT hr; - struct whpx_state *whpx =3D &whpx_global; - CPUState *cpu =3D (CPUState *)ctx; - WHV_TRANSLATE_GVA_RESULT res; - - hr =3D whp_dispatch.WHvTranslateGva(whpx->partition, cpu->cpu_index, - Gva, TranslateFlags, &res, Gpa); - if (FAILED(hr)) { - error_report("WHPX: Failed to translate GVA, hr=3D%08lx", hr); - } else { - *TranslationResult =3D res.ResultCode; - } - - return hr; -} - -static const WHV_EMULATOR_CALLBACKS whpx_emu_callbacks =3D { - .Size =3D sizeof(WHV_EMULATOR_CALLBACKS), - .WHvEmulatorIoPortCallback =3D whpx_emu_ioport_callback, - .WHvEmulatorMemoryCallback =3D whpx_emu_mmio_callback, - .WHvEmulatorGetVirtualProcessorRegisters =3D whpx_emu_getreg_callback, - .WHvEmulatorSetVirtualProcessorRegisters =3D whpx_emu_setreg_callback, - .WHvEmulatorTranslateGvaPage =3D whpx_emu_translate_callback, -}; - -static int whpx_handle_mmio(CPUState *cpu, WHV_MEMORY_ACCESS_CONTEXT *ctx) -{ - HRESULT hr; - AccelCPUState *vcpu =3D cpu->accel; - WHV_EMULATOR_STATUS emu_status; - - hr =3D whp_dispatch.WHvEmulatorTryMmioEmulation( - vcpu->emulator, cpu, - &vcpu->exit_ctx.VpContext, ctx, - &emu_status); - if (FAILED(hr)) { - error_report("WHPX: Failed to parse MMIO access, hr=3D%08lx", hr); - return -1; - } - - if (!emu_status.EmulationSuccessful) { - error_report("WHPX: Failed to emulate MMIO access with" - " EmulatorReturnStatus: %u", emu_status.AsUINT32); + ret =3D emulate_instruction(cpu, ctx->InstructionBytes, ctx->Instructi= onByteCount); + if (ret < 0) { + error_report("failed to emulate mmio"); return -1; } =20 return 0; } =20 +static void handle_io(CPUState *env, uint16_t port, void *buffer, + int direction, int size, int count) +{ + int i; + uint8_t *ptr =3D buffer; + + for (i =3D 0; i < count; i++) { + address_space_rw(&address_space_io, port, MEMTXATTRS_UNSPECIFIED, + ptr, size, + direction); + ptr +=3D size; + } +} + +static void whpx_bump_rip(CPUState *cpu, WHV_RUN_VP_EXIT_CONTEXT *exit_ctx) +{ + WHV_REGISTER_VALUE reg; + whpx_get_reg(cpu, WHvX64RegisterRip, ®); + reg.Reg64 =3D exit_ctx->VpContext.Rip + exit_ctx->VpContext.Instructio= nLength; + whpx_set_reg(cpu, WHvX64RegisterRip, reg); +} + static int whpx_handle_portio(CPUState *cpu, - WHV_X64_IO_PORT_ACCESS_CONTEXT *ctx) + WHV_RUN_VP_EXIT_CONTEXT *exit_ctx) { - HRESULT hr; - AccelCPUState *vcpu =3D cpu->accel; - WHV_EMULATOR_STATUS emu_status; + WHV_X64_IO_PORT_ACCESS_CONTEXT *ctx =3D &exit_ctx->IoPortAccess; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + int ret; =20 - hr =3D whp_dispatch.WHvEmulatorTryIoEmulation( - vcpu->emulator, cpu, - &vcpu->exit_ctx.VpContext, ctx, - &emu_status); - if (FAILED(hr)) { - error_report("WHPX: Failed to parse PortIO access, hr=3D%08lx", hr= ); - return -1; + if (!ctx->AccessInfo.StringOp && !ctx->AccessInfo.IsWrite) { + uint64_t val =3D 0; + WHV_REGISTER_VALUE reg; + + whpx_get_reg(cpu, WHvX64RegisterRax, ®); + handle_io(cpu, ctx->PortNumber, &val, 0, ctx->AccessInfo.AccessSiz= e, 1); + if (ctx->AccessInfo.AccessSize =3D=3D 1) { + reg.Reg8 =3D val; + } else if (ctx->AccessInfo.AccessSize =3D=3D 2) { + reg.Reg16 =3D val; + } else if (ctx->AccessInfo.AccessSize =3D=3D 4) { + reg.Reg64 =3D (uint32_t)val; + } else { + reg.Reg64 =3D (uint64_t)val; + } + whpx_bump_rip(cpu, exit_ctx); + whpx_set_reg(cpu, WHvX64RegisterRax, reg); + return 0; + } else if (!ctx->AccessInfo.StringOp && ctx->AccessInfo.IsWrite) { + RAX(env) =3D ctx->Rax; + handle_io(cpu, ctx->PortNumber, &RAX(env), 1, ctx->AccessInfo.Acce= ssSize, 1); + whpx_bump_rip(cpu, exit_ctx); + return 0; } =20 - if (!emu_status.EmulationSuccessful) { - error_report("WHPX: Failed to emulate PortIO access with" - " EmulatorReturnStatus: %u", emu_status.AsUINT32); + ret =3D emulate_instruction(cpu, ctx->InstructionBytes, exit_ctx->VpCo= ntext.InstructionLength); + if (ret < 0) { + error_report("failed to emulate I/O port access"); return -1; } =20 return 0; } =20 +static void write_mem(CPUState *cpu, void *data, target_ulong addr, int by= tes) +{ + vmx_write_mem(cpu, addr, data, bytes); +} + +static void read_mem(CPUState *cpu, void *data, target_ulong addr, int byt= es) +{ + vmx_read_mem(cpu, data, addr, bytes); +} + +static void read_segment_descriptor(CPUState *cpu, + struct x86_segment_descriptor *desc, + enum X86Seg seg_idx) +{ + bool ret; + X86CPU *x86_cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86_cpu->env; + SegmentCache *seg =3D &env->segs[seg_idx]; + x86_segment_selector sel =3D { .sel =3D seg->selector & 0xFFFF }; + + ret =3D x86_read_segment_descriptor(cpu, desc, sel); + if (ret =3D=3D false) { + error_report("failed to read segment descriptor"); + abort(); + } +} + + +static const struct x86_emul_ops whpx_x86_emul_ops =3D { + .read_mem =3D read_mem, + .write_mem =3D write_mem, + .read_segment_descriptor =3D read_segment_descriptor, + .handle_io =3D handle_io +}; + +static void whpx_init_emu(void) +{ + init_decoder(); + init_emu(&whpx_x86_emul_ops); +} + /* * Controls whether we should intercept various exceptions on the guest, * namely breakpoint/single-step events. @@ -1279,8 +1264,9 @@ bool whpx_arch_supports_guest_debug(void) =20 void whpx_arch_destroy_vcpu(CPUState *cpu) { - AccelCPUState *vcpu =3D cpu->accel; - whp_dispatch.WHvEmulatorDestroyEmulator(vcpu->emulator); + X86CPU *x86cpu =3D X86_CPU(cpu); + CPUX86State *env =3D &x86cpu->env; + g_free(env->emu_mmio_buf); } =20 /* Returns the address of the next instruction that is about to be execute= d. */ @@ -1639,11 +1625,11 @@ int whpx_vcpu_run(CPUState *cpu) =20 switch (vcpu->exit_ctx.ExitReason) { case WHvRunVpExitReasonMemoryAccess: - ret =3D whpx_handle_mmio(cpu, &vcpu->exit_ctx.MemoryAccess); + ret =3D whpx_handle_mmio(cpu, &vcpu->exit_ctx); break; =20 case WHvRunVpExitReasonX64IoPortAccess: - ret =3D whpx_handle_portio(cpu, &vcpu->exit_ctx.IoPortAccess); + ret =3D whpx_handle_portio(cpu, &vcpu->exit_ctx); break; =20 case WHvRunVpExitReasonX64InterruptWindow: @@ -1990,22 +1976,11 @@ int whpx_init_vcpu(CPUState *cpu) =20 vcpu =3D g_new0(AccelCPUState, 1); =20 - hr =3D whp_dispatch.WHvEmulatorCreateEmulator( - &whpx_emu_callbacks, - &vcpu->emulator); - if (FAILED(hr)) { - error_report("WHPX: Failed to setup instruction completion support= ," - " hr=3D%08lx", hr); - ret =3D -EINVAL; - goto error; - } - hr =3D whp_dispatch.WHvCreateVirtualProcessor( whpx->partition, cpu->cpu_index, 0); if (FAILED(hr)) { error_report("WHPX: Failed to create a virtual processor," " hr=3D%08lx", hr); - whp_dispatch.WHvEmulatorDestroyEmulator(vcpu->emulator); ret =3D -EINVAL; goto error; } @@ -2067,6 +2042,8 @@ int whpx_init_vcpu(CPUState *cpu) max_vcpu_index =3D max(max_vcpu_index, cpu->cpu_index); qemu_add_vm_change_state_handler(whpx_cpu_update_state, env); =20 + env->emu_mmio_buf =3D g_new(char, 4096); + return 0; =20 error: @@ -2256,6 +2233,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) } =20 whpx_memory_init(); + whpx_init_emu(); =20 printf("Windows Hypervisor Platform accelerator is operational\n"); return 0; --=20 2.53.0