[{"id":3683652,"web_url":"http://patchwork.ozlabs.org/comment/3683652/","msgid":"<11BFD4DB-D60C-4FF8-817A-2EFADBD729B4@unpredictable.fr>","list_archive_url":null,"date":"2026-04-28T18:36:38","subject":"Re: [PATCH 0/6] target/i386/mshv: use hv_vp_register_page for fast\n register access","submitter":{"id":91318,"url":"http://patchwork.ozlabs.org/api/people/91318/","name":"Mohamed Mediouni","email":"mohamed@unpredictable.fr"},"content":"> On 28. Apr 2026, at 15:50, Doru Blânzeanu <dblanzeanu@linux.microsoft.com> wrote:\n> \n> This series adds support for using the hypervisor's vp register page\n> in the mshv accelerator to optimize vcpu register access on mmio and pio\n> exits.\n> \n> Currently, all register reads and write go through hypercalls (ioctls),\n> which adds overhead on every VM exit. The VP register page is a shared\n> memory page that the hypervisor populates with vcpu register state,\n> allowing Qemu to read and write registers directly without hypercalls.\n> \n> The series is structured as follows:\n> 1. Remove the duplicate `fetch_guest_state` function, consolidating\n>  register loading into `mshv_load_regs`.\n> 2. Move `mshv_arch_init_vcpu` after vcpu creation so the vcpu fd is\n>  valid when we need it for mmap.\n> 3. Define the `hv_vp_register_page` structure in `hvgdk_mini.h`, matching\n>  the layout used by the Linux kernel's mshv driver.\n> 4. Set up the register page by mmapping the vcpu fd at init time. If the\n>  mmap fails, we fall back gracefully to the existing hypercall path.\n> 5. Use the register page to read registers on VM exit. General purpose\n>  registers, RIP, RFLAGS, segment registers, and control registers\n>  (CR0, CR4, CR4, CR8, EFER) are read directly from the page. Registers\n>  not present on the page (TR, LDTR, GDTR, IDTR, CR2, APIC_BASE) are still\n>  fetched via hypercall.\n> 6. Use register page to write registers on vmentry. GP registers,\n>  RIP, and RFLAGS are written to the page with the appropriate dirty\n>  bits set, avoiding the hypercall for the standard register store.\n> \n> The register page is only used when it has been successfully mmapped and\n> the hypervisor has marked it as valid (`isvalid != 0`). Otherwise, the\n> existing hypercall-based path is used as a fallback.\n\nHello,\n\nSome overall comments after reading this series:\n\n- bifurcated state sync is inevitable with not syncing the full\nstate for most MMIO/I/O port accesses. \n\nIt’s wanted to skip some state. LDTR/GDTR are among the painful\nones and you’ll very much want to avoid syncing those if you can.\n\nIn the typical WHP emulation case, there’s 0 state used outside\nof the shared register page and getting there made things so much\nsmoother than otherwise.\n\n- but there’s an exception:\n\nA pattern that causes problems:\n\n    /* Advance RIP and update RAX */\n    rip = info->header.rip + insn_len;\n    rax = info->rax;\n\n    reg_names[0] = HV_X64_REGISTER_RIP;\n    reg_values[0] = rip;\n    reg_names[1] = HV_X64_REGISTER_RAX;\n    reg_values[1] = rax;\n\n    ret = set_x64_registers(cpu, reg_names, reg_values);\n    if (ret < 0) {\n        error_report(\"Failed to set x64 registers\");\n        return -1;\n    }\n\n    cpu->accel->dirty = false;\n\nWhen put together with hw/i386/vmport.c, which calls cpu_synchronize_state\non an I/O port read (thankfully not very frequent), you’ll get issues with\nthis as vmport does both read and set register values on its own.\n\nIn WHPX, was dealt with in: https://patchew.org/QEMU/20260422214225.2242-1-mohamed@unpredictable.fr/20260422214225.2242-12-mohamed@unpredictable.fr/ \nand you’ll probably want to do something similar.\n\nI imagine that “cpu->accel->dirty = false;” was probably an attempt to\nget things to boot when faced with that.\n\nThis adds a small constraint that if additional state will be fetched in\nthe future, then writes have to happen either before that fetch, or on the\nnow synced state instead of the partial view.","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=aIS1pGLe;\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=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.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 4g4q1F56mvz1yHv\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 04:37:36 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wHnIq-0000qq-Ll; Tue, 28 Apr 2026 14:37:00 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.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 1wHnIn-0000qJ-Qc\n for qemu-devel@nongnu.org; Tue, 28 Apr 2026 14:36:58 -0400","from pv-2003l-snip4-7.eps.apple.com ([57.103.66.40]\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 1wHnIl-0007g8-Qu\n for qemu-devel@nongnu.org; Tue, 28 Apr 2026 14:36:57 -0400","from outbound.pv.icloud.com (unknown [127.0.0.2])\n by p00-icloudmta-asmtp-us-west-1a-20-percent-1 (Postfix) with ESMTPS id\n EE10718000AB; Tue, 28 Apr 2026 18:36:51 +0000 (UTC)","from smtpclient.apple (unknown [17.56.9.36])\n by p00-icloudmta-asmtp-us-west-1a-20-percent-1 (Postfix) with ESMTPSA id\n 4B1781800591; Tue, 28 Apr 2026 18:36:50 +0000 (UTC)"],"X-ICL-Out-Info":"\n HUtFAUMHWwJACUgBTUQeDx5WFlZNRAJCTQFIHV8DWRxBAUkdXw9LVxQEFVwFVgZXFHkNXR1FDlYZWgxSD1sOHBZLWFUJCgZdGFgVVgl3HlwASx1XBFQfUxJVHR0LRUtAEwROEwVSB11NVg1HD1geXBQXCEVDXgheH0wcHQ5YBhIATQoONgZZBV4JVgNDBTYSFF1FRgNHGVcUUBtHDFUHV15fChMAXg8PTAhJcStzX3YyFDwFXXRGBjZ/QB5VBlxzXQs9dSxzKXZHC0FxWXceXABLHVcEVB9TElUdHQtFVRIEQAhWUFQeQQRWFWwJWAZTGVc=","Dkim-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=unpredictable.fr;\n s=sig1; t=1777401413; x=1779993413;\n bh=LYM7TvQBAlTfmBdJ/lJvShbQcD4gsjvXXoL7IvZpCzQ=;\n h=Content-Type:Mime-Version:Subject:From:Date:Message-Id:To:x-icloud-hme;\n b=aIS1pGLeLUCPenznWrwBpbu9ViOeFUi8MkpHmX71+k6qdiAjEE5RSnwvP9e5QFrid94UKdVVkJrHK+jz1QtV9fl8hzzf2m7Hx/chIxcRXQHcx0YlnGE68a1lUlx2lch/sTgDKM7fYJAhbBIL8eWW2X9Ha08IZDZnzYPj+02hhOH+qoXR/Y5yJZEc0/zEVAMWyWAiQ3zdJGcFu42cJL/IiCoP/55YUY5NW5nZFLjPVqrIV/zCOhG++mZzpYORFVcJDKntDVMZOrz1ulRA2Nqf00utcH/Ut4kbotEqJaRW1n6GwSzyjZJ74o581KEv6rd1pgmrIAT7pFX8w8tJoGtGpQ==","mail-alias-created-date":"1752046281608","Content-Type":"text/plain;\n\tcharset=utf-8","Mime-Version":"1.0 (Mac OS X Mail 16.0 \\(3864.500.181\\))","Subject":"Re: [PATCH 0/6] target/i386/mshv: use hv_vp_register_page for fast\n register access","From":"Mohamed Mediouni <mohamed@unpredictable.fr>","In-Reply-To":"<20260428135053.251200-1-dblanzeanu@linux.microsoft.com>","Date":"Tue, 28 Apr 2026 20:36:38 +0200","Cc":"qemu-devel@nongnu.org, Magnus Kulke <magnuskulke@linux.microsoft.com>,\n Wei Liu <wei.liu@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>,\n Zhao Liu <zhao1.liu@intel.com>","Content-Transfer-Encoding":"quoted-printable","Message-Id":"<11BFD4DB-D60C-4FF8-817A-2EFADBD729B4@unpredictable.fr>","References":"<20260428135053.251200-1-dblanzeanu@linux.microsoft.com>","To":"=?utf-8?q?Doru_Bl=C3=A2nzeanu?= <dblanzeanu@linux.microsoft.com>","X-Mailer":"Apple Mail (2.3864.500.181)","X-Proofpoint-ORIG-GUID":"DhotmTqGjk9Z9rzJuLU-hB38Yc4qMjQD","X-Authority-Info-Out":"v=2.4 cv=D9JK6/Rj c=1 sm=1 tr=0 ts=69f0fe44\n cx=c_apl:c_pps:t_out a=azHRBMxVc17uSn+fyuI/eg==:117\n a=azHRBMxVc17uSn+fyuI/eg==:17 a=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10\n a=VkNPw1HP01LnGYTKEx00:22 a=GaQpPoNlAAAA:8 a=yMhMjlubAAAA:8\n a=J1EvKnRYTj4A5Ngll8oA:9 a=QEXdDO2ut3YA:10 a=xF5q_uoM5gZT5J3czcBi:22","X-Proofpoint-GUID":"DhotmTqGjk9Z9rzJuLU-hB38Yc4qMjQD","X-Proofpoint-Spam-Details-Enc":"AW1haW4tMjYwNDI4MDE4MCBTYWx0ZWRfX3mWUvabnzIQe\n BeunH1FPNDDtEIjI+AEBdi/CpsxQ+T3WNe+io6q5Hh3J+yEkxKWijeqBVCmMjyPDqx4RSl36/0K\n 4Ni7MIoGKFPHkj2DA16YMqXZVSD+DcSC45kUdqOS8cBQfYmtXdkDkb8FPTiKZ11HSztXN6mhc65\n jshLTZ2DHZIXDcCYOeLM+6JOcg8Y/DObkMMPj83x1NcudNVFrdu3Df+L0reJxBsGneIa34dszT/\n 6FZaddNulucL9I4C2ezN6/wv+ffd3adlq67IDePSjFdDWQ8Pi0XamtoSQOBg3zF3A8hmSPsjzsm\n KantWnDIf7OLB4S/MLJpl5fE36aUu+zTmFGHOQZuUX9KQ0Wve9Ki573xvJLuE8=","Received-SPF":"pass client-ip=57.103.66.40;\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 SPF_HELO_PASS=-0.001,\n 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"}}]