Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2196568/?format=api
{ "id": 2196568, "url": "http://patchwork.ozlabs.org/api/patches/2196568/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/patch/20260215052225.22513-10-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": "<20260215052225.22513-10-mohamed@unpredictable.fr>", "list_archive_url": null, "date": "2026-02-15T05:22:20", "name": "[v3,09/14] whpx: i386: 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/20260215052225.22513-10-mohamed@unpredictable.fr/mbox/", "series": [ { "id": 492201, "url": "http://patchwork.ozlabs.org/api/series/492201/?format=api", "web_url": "http://patchwork.ozlabs.org/project/qemu-devel/list/?series=492201", "date": "2026-02-15T05:22:12", "name": "whpx: x86 updates (2026-02)", "version": 3, "mbox": "http://patchwork.ozlabs.org/series/492201/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2196568/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2196568/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=WVOa52dU;\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 4fDDqM2Fp2z1xwj\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 15 Feb 2026 16:24:31 +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 1vrUb7-0000PF-3K; Sun, 15 Feb 2026 00:23:09 -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 1vrUb6-0000Ov-4a\n for qemu-devel@nongnu.org; Sun, 15 Feb 2026 00:23:08 -0500", "from p-west2-cluster1-host4-snip4-8.eps.apple.com ([57.103.68.81]\n helo=outbound.mr.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 1vrUb4-0004tf-9q\n for qemu-devel@nongnu.org; Sun, 15 Feb 2026 00:23:07 -0500", "from outbound.mr.icloud.com (unknown [127.0.0.2])\n by p00-icloudmta-asmtp-us-west-2a-60-percent-1 (Postfix) with ESMTPS id\n DBEFA1800130; Sun, 15 Feb 2026 05:23:03 +0000 (UTC)", "from localhost.localdomain (unknown [17.57.152.38])\n by p00-icloudmta-asmtp-us-west-2a-60-percent-1 (Postfix) with ESMTPSA id\n 67244180010F; Sun, 15 Feb 2026 05:23:00 +0000 (UTC)" ], "Dkim-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr;\n s=sig1; t=1771132985; x=1773724985;\n bh=7W6Lt13Z1XJSZmU+RzaMy+Ab1ScstdHKGazxZ1Eo+0Y=;\n h=From:To:Subject:Date:Message-ID:MIME-Version:x-icloud-hme;\n b=WVOa52dUrMxbUnhRZTLawxV/cX3ZF20wamWxuLHRch5PqOabsg4kfFHl2dZjXPlQwEbDdh3+izPncE7FXgdJ1kEiqyjLTmPW9MU0gR3YI0QwonuiOPvJkKDjQ1xD9T4VExE7NIgKGi+BWrFvVoH/7b1NRyKbFwC4L+ww4PazAmeOtcSYRamYnAp9R6MBim7+cW+q678rX58sQxf3b4tOMku9fXJPIvSsByaEUOm/i0P49xzmYxn4jxvEfdN03Tm/p86LmBPurtofWlURc00PhDa3vV9eVQbHne99M3f6SVNUw18cE7SzZGAJb1U+ls3+SDodS10X+2Tv4UCQ3fBAPw==", "mail-alias-created-date": "1752046281608", "From": "Mohamed Mediouni <mohamed@unpredictable.fr>", "To": "qemu-devel@nongnu.org", "Cc": "Phil Dennis-Jordan <phil@philjordan.eu>,\n Bernhard Beschow <shentey@gmail.com>, Cameron Esfahani <dirty@apple.com>,\n Magnus Kulke <magnuskulke@linux.microsoft.com>, qemu-arm@nongnu.org,\n Peter Maydell <peter.maydell@linaro.org>,\n Roman Bolshakov <rbolshakov@ddn.com>, Paolo Bonzini <pbonzini@redhat.com>,\n Mohamed Mediouni <mohamed@unpredictable.fr>,\n Pedro Barbuda <pbarbuda@microsoft.com>,\n =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= <berrange@redhat.com>, =?utf-8?q?Marc?=\n\t=?utf-8?q?-Andr=C3=A9_Lureau?= <marcandre.lureau@redhat.com>,\n Magnus Kulke <magnus.kulke@linux.microsoft.com>, =?utf-8?q?Philippe_Mathieu?=\n\t=?utf-8?q?-Daud=C3=A9?= <philmd@linaro.org>, Wei Liu <wei.liu@kernel.org>,\n Zhao Liu <zhao1.liu@intel.com>", "Subject": "[PATCH v3 09/14] whpx: i386: switch over from winhvemulation to\n target/i386/emulate", "Date": "Sun, 15 Feb 2026 06:22:20 +0100", "Message-ID": "<20260215052225.22513-10-mohamed@unpredictable.fr>", "X-Mailer": "git-send-email 2.50.1", "In-Reply-To": "<20260215052225.22513-1-mohamed@unpredictable.fr>", "References": "<20260215052225.22513-1-mohamed@unpredictable.fr>", "MIME-Version": "1.0", "Content-Transfer-Encoding": "8bit", "X-Authority-Info-Out": "v=2.4 cv=aJn9aL9m c=1 sm=1 tr=0 ts=69915838\n cx=c_apl:c_apl_out:c_pps a=9OgfyREA4BUYbbCgc0Y0oA==:117\n a=9OgfyREA4BUYbbCgc0Y0oA==:17 a=HzLeVaNsDn8A:10 a=VkNPw1HP01LnGYTKEx00:22\n a=Mpw57Om8IfrbqaoTuvik:22 a=GgsMoib0sEa3-_RKJdDe:22 a=1q5U6jd5_WdO0fZ7RH8A:9", "X-Proofpoint-Spam-Details-Enc": "AW1haW4tMjYwMjE1MDAzNiBTYWx0ZWRfX5izaxBDDhpTD\n eJ5+UtkWUwIo9xLY1DW2oLSBqrxBZOBzshKBZhl+BT1pEt8pdtqW0DPh9RnYb4zY1vZR23Iah3R\n jzyGT5J6lhJZeAwNvnHk6YnGQL6qz7X8FXJqwwDi3dq+Lmt8YIKdaB1s89B/jxK7a8w9KDfuVaw\n vB8gzpcQnFWRTTUxcmvqpd6tPq1o2cnG8skP+Tt65g4CiJFRNxATxid/Nsc/mE30Oy4JyKn6OsI\n TkPgMxJqaz+iVOolMEiqkX9uX9JVjq3O7A4cqGCDW97Hlim4Jd08eprsyEEXlXH2iJg1+cCMQST\n Nog8dzDY76IjIPGksmZVvuSos6d7rBMbmK1yE3XT+sQ0GAst6Jf25FbjIvzu+Y=", "X-Proofpoint-ORIG-GUID": "dOiEXQT6K4NhTbqABiKlnjeFpE4GjRbP", "X-Proofpoint-GUID": "dOiEXQT6K4NhTbqABiKlnjeFpE4GjRbP", "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-15_02,2026-02-13_01,2025-10-01_01", "X-Proofpoint-Spam-Details": "rule=notspam policy=default score=0 adultscore=0\n suspectscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 phishscore=0\n lowpriorityscore=0 clxscore=1030 malwarescore=0 spamscore=0 classifier=spam\n authscore=0 adjust=0 reason=mlx scancount=1 engine=8.22.0-2601150000\n definitions=main-2602150036", "X-JNJ": "\n AAAAAAABLC0lEI5zgwCiGXNSQuDYksouAay9hlvIQRVtqGntcxsXQwAk/7XeRtXn5v4IZVXNRLxs0EdqQtzW1af5YK51sPJp09mTKcIOdS+DVpgcESPsCb1N9yHlfWebaudyFfYOWFmTPk70TUJ9pnSwgCDnjGTszJazlbFHYtPvI+D7uDodfgq5o2Xw1vA9ML9iwFeWD5mhHG33wijczWnJZt67NMMGWLjtAkjsyxjp1HYk8z8fO/UXwC0/f7mJ3Gg4rR52rmu7f/k1OBxfuMyQ2Zxh2mUjna3NXzTSEL5O2oEp7v5xGLrrW0M5WnTk7dQhrZZDeaqNtxZo7Eu81IZ0N/Fg8mv1K2vCXVHAbEAJatydgoYfhWcstyT6qvRv9uDIe6otRRhJTr/PfYnDAGxld1JffbupZw2m2rQfCPIdwXEJ9pAvHr9j72y51eudj+Yo1hhAL98tWEKkHoiP2QeiT6zRzeEkVMcrTOOKoyUhyhhcbtcxf0rSvhu6Lwu3i3lf3hcRTXrM9crLsj7lacdmOEb+Oi2uJhIxWoJmo4yvKvjDWKocpBgokQKbZAYaCd8Ip2fAv4CGJbMpVEwGmIxR+WZOhU4/u4PWh+eK1tlJRXaUu9IhUNSp/KQ80Azy5zneR6LmlLMTKsWwmXg8/lgz+zbxB4ED7cbvUJNU5SPxBAVGqgD6bsq61sWKpLn5uVedlck55sTuDWDiyMXMCnzgy34u8oCrBmXmCgHZho2rsb/gTEYlDzxicIECuHHHsi7R7Z5LG4SFnoUibDR0lvJ9GTVj9bhG1Sqnc5BO1dMro2halb7+iKY=", "Received-SPF": "pass client-ip=57.103.68.81;\n envelope-from=mohamed@unpredictable.fr; helo=outbound.mr.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,\n SPF_PASS=-0.001 autolearn=unavailable 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, ®);\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, ®);\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": [ "v3", "09/14" ] }