get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/2196193/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2196193,
    "url": "http://patchwork.ozlabs.org/api/patches/2196193/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260213034556.13471-7-mohamed@unpredictable.fr/",
    "project": {
        "id": 14,
        "url": "http://patchwork.ozlabs.org/api/projects/14/?format=api",
        "name": "QEMU Development",
        "link_name": "qemu-devel",
        "list_id": "qemu-devel.nongnu.org",
        "list_email": "qemu-devel@nongnu.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20260213034556.13471-7-mohamed@unpredictable.fr>",
    "list_archive_url": null,
    "date": "2026-02-13T03:45:49",
    "name": "[v2,06/10] whpx: x86: switch over from winhvemulation to target/i386/emulate",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "19a238b494b6048716fbacd1eeff970caf200954",
    "submitter": {
        "id": 91318,
        "url": "http://patchwork.ozlabs.org/api/people/91318/?format=api",
        "name": "Mohamed Mediouni",
        "email": "mohamed@unpredictable.fr"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260213034556.13471-7-mohamed@unpredictable.fr/mbox/",
    "series": [
        {
            "id": 492055,
            "url": "http://patchwork.ozlabs.org/api/series/492055/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=492055",
            "date": "2026-02-13T03:45:43",
            "name": "whpx: x86 updates (2026-02)",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/492055/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2196193/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2196193/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>",
        "X-Original-To": "incoming@patchwork.ozlabs.org",
        "Delivered-To": "patchwork-incoming@legolas.ozlabs.org",
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=unpredictable.fr header.i=@unpredictable.fr\n header.a=rsa-sha256 header.s=sig1 header.b=aBvInLKQ;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"
        ],
        "Received": [
            "from lists.gnu.org (lists.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fBymD4pLsz1xpY\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 13 Feb 2026 14:47:24 +1100 (AEDT)",
            "from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1vqk8Z-0008Jr-3Y; Thu, 12 Feb 2026 22:46:35 -0500",
            "from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <mohamed@unpredictable.fr>)\n id 1vqk8Y-0008JZ-2T\n for qemu-devel@nongnu.org; Thu, 12 Feb 2026 22:46:34 -0500",
            "from p-west1-cluster4-host6-snip4-4.eps.apple.com ([57.103.65.245]\n helo=outbound.pv.icloud.com)\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <mohamed@unpredictable.fr>)\n id 1vqk8V-0005dp-Hf\n for qemu-devel@nongnu.org; Thu, 12 Feb 2026 22:46:33 -0500",
            "from outbound.pv.icloud.com (unknown [127.0.0.2])\n by p00-icloudmta-asmtp-us-west-1a-60-percent-11 (Postfix) with ESMTPS id\n F25E018002DA; Fri, 13 Feb 2026 03:46:25 +0000 (UTC)",
            "from localhost.localdomain (unknown [17.56.9.36])\n by p00-icloudmta-asmtp-us-west-1a-60-percent-11 (Postfix) with ESMTPSA id\n 190CD18002DF; Fri, 13 Feb 2026 03:46:21 +0000 (UTC)"
        ],
        "Dkim-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr;\n s=sig1; t=1770954390; x=1773546390;\n bh=7W6Lt13Z1XJSZmU+RzaMy+Ab1ScstdHKGazxZ1Eo+0Y=;\n h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme;\n b=aBvInLKQp5IsGA3jJshKK2O1Qojo7n7oSbi3KPf5Bo2hwOJY5ooAcOuwvBup+GxQ+neoEKEk/wGfPCRc1r8A3vPN1JBrYzZ61ckDsWtELLqseToyNV8tu4pIXbCvm/t2DuF71pNP7KUNhIUbFuaiN1QwYdLTsJtQhXSyc9VTb3odl9P2Q4XEw+U3yQx6QChEYNKmux1jz7TfQyWapVJB038oLiFUzHZ09p/Mmxe75AOulvUL9iqlr/hpEGBnsSJKnBZyinCP4AUeSyel87KCs+mENK0mL1NyO043JlL21Bir08EyyV16QOthLG5yCF43aKQOdIftGW2Q7/p74ZxprA==",
        "mail-alias-created-date": "1752046281608",
        "From": "Mohamed Mediouni <mohamed@unpredictable.fr>",
        "To": "qemu-devel@nongnu.org",
        "Cc": "=?utf-8?q?Marc-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>,\n Magnus Kulke <magnuskulke@linux.microsoft.com>, =?utf-8?q?Philippe_Mathieu-?=\n\t=?utf-8?q?Daud=C3=A9?= <philmd@linaro.org>,\n Bernhard Beschow <shentey@gmail.com>, Paolo Bonzini <pbonzini@redhat.com>,\n Mohamed Mediouni <mohamed@unpredictable.fr>, Wei Liu <wei.liu@kernel.org>,\n Pedro Barbuda <pbarbuda@microsoft.com>, Cameron Esfahani <dirty@apple.com>,\n Peter Maydell <peter.maydell@linaro.org>,\n Phil Dennis-Jordan <phil@philjordan.eu>, Zhao Liu <zhao1.liu@intel.com>,\n Roman Bolshakov <rbolshakov@ddn.com>,\n =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= <berrange@redhat.com>",
        "Subject": "[PATCH v2 06/10] whpx: x86: switch over from winhvemulation to\n target/i386/emulate",
        "Date": "Fri, 13 Feb 2026 04:45:49 +0100",
        "Message-ID": "<20260213034556.13471-7-mohamed@unpredictable.fr>",
        "X-Mailer": "git-send-email 2.50.1",
        "In-Reply-To": "<20260213034556.13471-1-mohamed@unpredictable.fr>",
        "References": "<20260213034556.13471-1-mohamed@unpredictable.fr>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "X-Authority-Info-Out": "v=2.4 cv=E7XAZKdl c=1 sm=1 tr=0 ts=698e9e93\n cx=c_apl:c_apl_out:c_pps a=azHRBMxVc17uSn+fyuI/eg==:117\n a=azHRBMxVc17uSn+fyuI/eg==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22\n a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=1q5U6jd5_WdO0fZ7RH8A:9",
        "X-Proofpoint-GUID": "ZpnCxrVR65V0ZC5p4YTlkXHeIANvixmM",
        "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwMjEzMDAyNSBTYWx0ZWRfXwqHG6SbFKonJ\n ggVBJ5X8i+jsLcg9M+0VhaoaRgDPPTm0GuOPINNEjV7QVNApcqozU+kst2RG+CSRp5ztjSvx1jG\n YK2MhBIADXJufNud4aZ2KAFZ2CuxjpSEUgDsbfERP6LvTpz6F5rUnlV4Qw4u7eglPh73aJGHdkx\n z4fR5yPzzjDQJfQiN+G2dZ9stGAd8y9psV3ZmkUrlNKxtpUc5BKY1YAcu9isnzaPwFxbmo8XoAC\n +C4U1Wl0OOHIFIqmhFT+nxNO62m9ssAQqy3cPjI9zSETsZU8zCj3PKXVtmdlnsQ7sIwa2ro8Tud\n CUicV4OojFimniwixMKK//cXOhz++5Lh0dHZ99d+jxJEBUDNdz0QTMZ6sCMX3A=",
        "X-Proofpoint-ORIG-GUID": "ZpnCxrVR65V0ZC5p4YTlkXHeIANvixmM",
        "X-Proofpoint-Virus-Version": "vendor=baseguard\n engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.51,FMLib:17.12.100.49\n definitions=2026-02-12_05,2026-02-12_03,2025-10-01_01",
        "X-Proofpoint-Spam-Details": "rule=notspam policy=default score=0 adultscore=0\n spamscore=0 clxscore=1030 bulkscore=0 mlxscore=0 mlxlogscore=999\n suspectscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 classifier=spam\n authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000\n definitions=main-2602130025",
        "X-JNJ": "\n AAAAAAABFgBvSnawIyD3hkH+5yB/wXQl0QDziFHUEGJexEBxmTcnIYNmN1On+weP0ODX0JWOD9qlVQG7PWx0w8jcbmfYmH6HE8Rny5q/w04CPu4D9svUkkbZyUJUUYfN/DRmrqNOZikGdHeQZ+vYNuDPMOy2u+kunspOhk6RHccJST0ZwxgCcSV36QE3Y9UaYWixGBuM00FAJgWCrBFV484kY7hq4vqf2hPd2IgVuXmOmkAoRI5rNaugg4hgsa2/u8MZfIae5laj78ZqfClmTeLV4n3QAWaiGH64F1Gu2nRgI48mo4KwKlWWd4aiPmTOOPJJMQNlCTbg9Sjnr1WuF/Kf3DkWSxS2ZEIBQx0a5leQP926E80YbNTF9fxshsDwQM53VhBmrtWYnjbGCvXANl6JJ9UXlxUyj5sYJripfKdfrew0JexTlU8+5OTB0NOgTPG3jQrVMMZU6EP3LrBshhQ2wZPd3xi8gItRdAJKZbvL6Mcn/oPWStuuhD1acEkYBN/+XYiIymHsCiAC1Tx26Ta2V9l5PX/LMNAXqf4GfTkXmetk0cTRQnZ0W2Zka8UlWiFO0Kbtw+tEpI2ot1GD6z5cN0vm2lOW/J7dk5HuvVxT8Zfbj9GHvOiIkPl6WjEZ6dtjYw8b2pi/dhTaMZzxXWIkToKV7nhC9rpm5yXS1YvA9ul0/FIAkiURHZ5RJVwU1V4dF7PFbLLGgbnb+kTIblGF1ai7hwMVLocpZ2bfy7GdRS8OtSa4YI2MYcJRJzFetpQEawgNC357C1Vk0hP4NhFaqRjjkETSAF3DkOFO",
        "Received-SPF": "pass client-ip=57.103.65.245;\n envelope-from=mohamed@unpredictable.fr; helo=outbound.pv.icloud.com",
        "X-Spam_score_int": "-20",
        "X-Spam_score": "-2.1",
        "X-Spam_bar": "--",
        "X-Spam_report": "(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n 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 <qemu-devel.nongnu.org>",
        "List-Unsubscribe": "<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.nongnu.org/archive/html/qemu-devel>",
        "List-Post": "<mailto:qemu-devel@nongnu.org>",
        "List-Help": "<mailto:qemu-devel-request@nongnu.org?subject=help>",
        "List-Subscribe": "<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>",
        "Errors-To": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org",
        "Sender": "qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"
    },
    "content": "Using the mshv backend as a base, move away from winhvemulation\nto using common QEMU code used by the HVF and mshv backends.\n\nSigned-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>\n---\n target/i386/whpx/whpx-all.c | 250 ++++++++++++++++--------------------\n 1 file changed, 114 insertions(+), 136 deletions(-)",
    "diff": "diff --git a/target/i386/whpx/whpx-all.c b/target/i386/whpx/whpx-all.c\nindex cdcaebbe16..eabb0ef913 100644\n--- a/target/i386/whpx/whpx-all.c\n+++ b/target/i386/whpx/whpx-all.c\n@@ -15,6 +15,7 @@\n #include \"gdbstub/helpers.h\"\n #include \"qemu/accel.h\"\n #include \"accel/accel-ops.h\"\n+#include \"system/memory.h\"\n #include \"system/whpx.h\"\n #include \"system/cpus.h\"\n #include \"system/runstate.h\"\n@@ -36,8 +37,12 @@\n #include \"system/whpx-all.h\"\n #include \"system/whpx-common.h\"\n \n+#include \"emulate/x86_decode.h\"\n+#include \"emulate/x86_emu.h\"\n+#include \"emulate/x86_flags.h\"\n+#include \"emulate/x86_mmu.h\"\n+\n #include <winhvplatform.h>\n-#include <winhvemulation.h>\n \n #define HYPERV_APIC_BUS_FREQUENCY      (200000000ULL)\n \n@@ -756,158 +761,138 @@ void whpx_get_registers(CPUState *cpu)\n     x86_update_hflags(env);\n }\n \n-static HRESULT CALLBACK whpx_emu_ioport_callback(\n-    void *ctx,\n-    WHV_EMULATOR_IO_ACCESS_INFO *IoAccess)\n+static int emulate_instruction(CPUState *cpu, const uint8_t *insn_bytes, size_t insn_len)\n {\n-    MemTxAttrs attrs = { 0 };\n-    address_space_rw(&address_space_io, IoAccess->Port, attrs,\n-                     &IoAccess->Data, IoAccess->AccessSize,\n-                     IoAccess->Direction);\n-    return S_OK;\n-}\n+    X86CPU *x86_cpu = X86_CPU(cpu);\n+    CPUX86State *env = &x86_cpu->env;\n+    struct x86_decode decode = { 0 };\n+    x86_insn_stream stream = { .bytes = insn_bytes, .len = insn_len };\n \n-static HRESULT CALLBACK whpx_emu_mmio_callback(\n-    void *ctx,\n-    WHV_EMULATOR_MEMORY_ACCESS_INFO *ma)\n-{\n-    CPUState *cs = (CPUState *)ctx;\n-    AddressSpace *as = cpu_addressspace(cs, MEMTXATTRS_UNSPECIFIED);\n+    whpx_get_registers(cpu);\n+    decode_instruction_stream(env, &decode, &stream);\n+    exec_instruction(env, &decode);\n+    whpx_set_registers(cpu, WHPX_SET_RUNTIME_STATE);\n \n-    address_space_rw(as, ma->GpaAddress, MEMTXATTRS_UNSPECIFIED,\n-                     ma->Data, ma->AccessSize, ma->Direction);\n-    return S_OK;\n+    return 0;\n }\n \n-static HRESULT CALLBACK whpx_emu_getreg_callback(\n-    void *ctx,\n-    const WHV_REGISTER_NAME *RegisterNames,\n-    UINT32 RegisterCount,\n-    WHV_REGISTER_VALUE *RegisterValues)\n+static int whpx_handle_mmio(CPUState *cpu, WHV_RUN_VP_EXIT_CONTEXT *exit_ctx)\n {\n-    HRESULT hr;\n-    struct whpx_state *whpx = &whpx_global;\n-    CPUState *cpu = (CPUState *)ctx;\n+    WHV_MEMORY_ACCESS_CONTEXT *ctx = &exit_ctx->MemoryAccess;\n+    int ret;\n \n-    hr = whp_dispatch.WHvGetVirtualProcessorRegisters(\n-        whpx->partition, cpu->cpu_index,\n-        RegisterNames, RegisterCount,\n-        RegisterValues);\n-    if (FAILED(hr)) {\n-        error_report(\"WHPX: Failed to get virtual processor registers,\"\n-                     \" hr=%08lx\", hr);\n+    ret = emulate_instruction(cpu, ctx->InstructionBytes, exit_ctx->VpContext.InstructionLength);\n+    if (ret < 0) {\n+        error_report(\"failed to emulate mmio\");\n+        return -1;\n     }\n \n-    return hr;\n+    return 0;\n }\n \n-static HRESULT CALLBACK whpx_emu_setreg_callback(\n-    void *ctx,\n-    const WHV_REGISTER_NAME *RegisterNames,\n-    UINT32 RegisterCount,\n-    const WHV_REGISTER_VALUE *RegisterValues)\n+static void handle_io(CPUState *env, uint16_t port, void *buffer,\n+                  int direction, int size, int count)\n {\n-    HRESULT hr;\n-    struct whpx_state *whpx = &whpx_global;\n-    CPUState *cpu = (CPUState *)ctx;\n+    int i;\n+    uint8_t *ptr = buffer;\n \n-    hr = whp_dispatch.WHvSetVirtualProcessorRegisters(\n-        whpx->partition, cpu->cpu_index,\n-        RegisterNames, RegisterCount,\n-        RegisterValues);\n-    if (FAILED(hr)) {\n-        error_report(\"WHPX: Failed to set virtual processor registers,\"\n-                     \" hr=%08lx\", hr);\n+    for (i = 0; i < count; i++) {\n+        address_space_rw(&address_space_io, port, MEMTXATTRS_UNSPECIFIED,\n+                         ptr, size,\n+                         direction);\n+        ptr += size;\n     }\n-\n-    /*\n-     * The emulator just successfully wrote the register state. We clear the\n-     * dirty state so we avoid the double write on resume of the VP.\n-     */\n-    cpu->vcpu_dirty = false;\n-\n-    return hr;\n }\n \n-static HRESULT CALLBACK whpx_emu_translate_callback(\n-    void *ctx,\n-    WHV_GUEST_VIRTUAL_ADDRESS Gva,\n-    WHV_TRANSLATE_GVA_FLAGS TranslateFlags,\n-    WHV_TRANSLATE_GVA_RESULT_CODE *TranslationResult,\n-    WHV_GUEST_PHYSICAL_ADDRESS *Gpa)\n+static void whpx_bump_rip(CPUState *cpu, WHV_RUN_VP_EXIT_CONTEXT *exit_ctx)\n {\n-    HRESULT hr;\n-    struct whpx_state *whpx = &whpx_global;\n-    CPUState *cpu = (CPUState *)ctx;\n-    WHV_TRANSLATE_GVA_RESULT res;\n-\n-    hr = whp_dispatch.WHvTranslateGva(whpx->partition, cpu->cpu_index,\n-                                      Gva, TranslateFlags, &res, Gpa);\n-    if (FAILED(hr)) {\n-        error_report(\"WHPX: Failed to translate GVA, hr=%08lx\", hr);\n-    } else {\n-        *TranslationResult = res.ResultCode;\n-    }\n-\n-    return hr;\n+    WHV_REGISTER_VALUE reg;\n+    whpx_get_reg(cpu, WHvX64RegisterRip, &reg);\n+    reg.Reg64 = exit_ctx->VpContext.Rip + exit_ctx->VpContext.InstructionLength;\n+    whpx_set_reg(cpu, WHvX64RegisterRip, reg);\n }\n \n-static const WHV_EMULATOR_CALLBACKS whpx_emu_callbacks = {\n-    .Size = sizeof(WHV_EMULATOR_CALLBACKS),\n-    .WHvEmulatorIoPortCallback = whpx_emu_ioport_callback,\n-    .WHvEmulatorMemoryCallback = whpx_emu_mmio_callback,\n-    .WHvEmulatorGetVirtualProcessorRegisters = whpx_emu_getreg_callback,\n-    .WHvEmulatorSetVirtualProcessorRegisters = whpx_emu_setreg_callback,\n-    .WHvEmulatorTranslateGvaPage = whpx_emu_translate_callback,\n-};\n-\n-static int whpx_handle_mmio(CPUState *cpu, WHV_MEMORY_ACCESS_CONTEXT *ctx)\n+static int whpx_handle_portio(CPUState *cpu,\n+                              WHV_RUN_VP_EXIT_CONTEXT *exit_ctx)\n {\n-    HRESULT hr;\n-    AccelCPUState *vcpu = cpu->accel;\n-    WHV_EMULATOR_STATUS emu_status;\n-\n-    hr = whp_dispatch.WHvEmulatorTryMmioEmulation(\n-        vcpu->emulator, cpu,\n-        &vcpu->exit_ctx.VpContext, ctx,\n-        &emu_status);\n-    if (FAILED(hr)) {\n-        error_report(\"WHPX: Failed to parse MMIO access, hr=%08lx\", hr);\n-        return -1;\n-    }\n+    WHV_X64_IO_PORT_ACCESS_CONTEXT *ctx = &exit_ctx->IoPortAccess;\n+    X86CPU *x86_cpu = X86_CPU(cpu);\n+    CPUX86State *env = &x86_cpu->env;\n+    int ret;\n \n-    if (!emu_status.EmulationSuccessful) {\n-        error_report(\"WHPX: Failed to emulate MMIO access with\"\n-                     \" EmulatorReturnStatus: %u\", emu_status.AsUINT32);\n+    if (!ctx->AccessInfo.StringOp && !ctx->AccessInfo.IsWrite) {\n+        uint64_t val = 0;\n+        WHV_REGISTER_VALUE reg;\n+\n+        whpx_get_reg(cpu, WHvX64RegisterRax, &reg);\n+        handle_io(cpu, ctx->PortNumber, &val, 0, ctx->AccessInfo.AccessSize, 1);\n+        if (ctx->AccessInfo.AccessSize == 1) {\n+            reg.Reg8 = val;\n+        } else if (ctx->AccessInfo.AccessSize == 2) {\n+            reg.Reg16 = val;\n+        } else if (ctx->AccessInfo.AccessSize == 4) {\n+            reg.Reg64 = (uint32_t)val;\n+        } else {\n+            reg.Reg64 = (uint64_t)val;\n+        }\n+        whpx_bump_rip(cpu, exit_ctx);\n+        whpx_set_reg(cpu, WHvX64RegisterRax, reg);\n+        return 0;\n+    } else if (!ctx->AccessInfo.StringOp && ctx->AccessInfo.IsWrite) {\n+        RAX(env) = ctx->Rax;\n+        handle_io(cpu, ctx->PortNumber, &RAX(env), 1, ctx->AccessInfo.AccessSize, 1);\n+        whpx_bump_rip(cpu, exit_ctx);\n+        return 0;\n+    }\n+\n+    ret = emulate_instruction(cpu, ctx->InstructionBytes, exit_ctx->VpContext.InstructionLength);\n+    if (ret < 0) {\n+        error_report(\"failed to emulate I/O port access\");\n         return -1;\n     }\n \n     return 0;\n }\n \n-static int whpx_handle_portio(CPUState *cpu,\n-                              WHV_X64_IO_PORT_ACCESS_CONTEXT *ctx)\n+static void write_mem(CPUState *cpu, void *data, target_ulong addr, int bytes)\n {\n-    HRESULT hr;\n-    AccelCPUState *vcpu = cpu->accel;\n-    WHV_EMULATOR_STATUS emu_status;\n+    vmx_write_mem(cpu, addr, data, bytes);\n+}\n \n-    hr = whp_dispatch.WHvEmulatorTryIoEmulation(\n-        vcpu->emulator, cpu,\n-        &vcpu->exit_ctx.VpContext, ctx,\n-        &emu_status);\n-    if (FAILED(hr)) {\n-        error_report(\"WHPX: Failed to parse PortIO access, hr=%08lx\", hr);\n-        return -1;\n-    }\n+static void read_mem(CPUState *cpu, void *data, target_ulong addr, int bytes)\n+{\n+    vmx_read_mem(cpu, data, addr, bytes);\n+}\n \n-    if (!emu_status.EmulationSuccessful) {\n-        error_report(\"WHPX: Failed to emulate PortIO access with\"\n-                     \" EmulatorReturnStatus: %u\", emu_status.AsUINT32);\n-        return -1;\n+static void read_segment_descriptor(CPUState *cpu,\n+                                    struct x86_segment_descriptor *desc,\n+                                    enum X86Seg seg_idx)\n+{\n+    bool ret;\n+    X86CPU *x86_cpu = X86_CPU(cpu);\n+    CPUX86State *env = &x86_cpu->env;\n+    SegmentCache *seg = &env->segs[seg_idx];\n+    x86_segment_selector sel = { .sel = seg->selector & 0xFFFF };\n+\n+    ret = x86_read_segment_descriptor(cpu, desc, sel);\n+    if (ret == false) {\n+        error_report(\"failed to read segment descriptor\");\n+        abort();\n     }\n+}\n \n-    return 0;\n+\n+static const struct x86_emul_ops whpx_x86_emul_ops = {\n+    .read_mem = read_mem,\n+    .write_mem = write_mem,\n+    .read_segment_descriptor = read_segment_descriptor,\n+    .handle_io = handle_io\n+};\n+\n+static void whpx_init_emu(void)\n+{\n+    init_decoder();\n+    init_emu(&whpx_x86_emul_ops);\n }\n \n /*\n@@ -1279,8 +1264,9 @@ bool whpx_arch_supports_guest_debug(void)\n \n void whpx_arch_destroy_vcpu(CPUState *cpu)\n {\n-    AccelCPUState *vcpu = cpu->accel;\n-    whp_dispatch.WHvEmulatorDestroyEmulator(vcpu->emulator);\n+    X86CPU *x86cpu = X86_CPU(cpu);\n+    CPUX86State *env = &x86cpu->env;\n+    g_free(env->emu_mmio_buf);\n }\n \n /* Returns the address of the next instruction that is about to be executed. */\n@@ -1639,11 +1625,11 @@ int whpx_vcpu_run(CPUState *cpu)\n \n         switch (vcpu->exit_ctx.ExitReason) {\n         case WHvRunVpExitReasonMemoryAccess:\n-            ret = whpx_handle_mmio(cpu, &vcpu->exit_ctx.MemoryAccess);\n+            ret = whpx_handle_mmio(cpu, &vcpu->exit_ctx);\n             break;\n \n         case WHvRunVpExitReasonX64IoPortAccess:\n-            ret = whpx_handle_portio(cpu, &vcpu->exit_ctx.IoPortAccess);\n+            ret = whpx_handle_portio(cpu, &vcpu->exit_ctx);\n             break;\n \n         case WHvRunVpExitReasonX64InterruptWindow:\n@@ -1990,22 +1976,11 @@ int whpx_init_vcpu(CPUState *cpu)\n \n     vcpu = g_new0(AccelCPUState, 1);\n \n-    hr = whp_dispatch.WHvEmulatorCreateEmulator(\n-        &whpx_emu_callbacks,\n-        &vcpu->emulator);\n-    if (FAILED(hr)) {\n-        error_report(\"WHPX: Failed to setup instruction completion support,\"\n-                     \" hr=%08lx\", hr);\n-        ret = -EINVAL;\n-        goto error;\n-    }\n-\n     hr = whp_dispatch.WHvCreateVirtualProcessor(\n         whpx->partition, cpu->cpu_index, 0);\n     if (FAILED(hr)) {\n         error_report(\"WHPX: Failed to create a virtual processor,\"\n                      \" hr=%08lx\", hr);\n-        whp_dispatch.WHvEmulatorDestroyEmulator(vcpu->emulator);\n         ret = -EINVAL;\n         goto error;\n     }\n@@ -2067,6 +2042,8 @@ int whpx_init_vcpu(CPUState *cpu)\n     max_vcpu_index = max(max_vcpu_index, cpu->cpu_index);\n     qemu_add_vm_change_state_handler(whpx_cpu_update_state, env);\n \n+    env->emu_mmio_buf = g_new(char, 4096);\n+\n     return 0;\n \n error:\n@@ -2256,6 +2233,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms)\n     }\n \n     whpx_memory_init();\n+    whpx_init_emu();\n \n     printf(\"Windows Hypervisor Platform accelerator is operational\\n\");\n     return 0;\n",
    "prefixes": [
        "v2",
        "06/10"
    ]
}