[{"id":3687127,"web_url":"http://patchwork.ozlabs.org/comment/3687127/","msgid":"<aftR3eiNjbwCoqS/@example.com>","list_archive_url":null,"date":"2026-05-06T14:36:13","subject":"Re: [PATCH v2 4/7] target/i386/mshv: hv_vp_register_page setup for\n the vcpu","submitter":{"id":90753,"url":"http://patchwork.ozlabs.org/api/people/90753/","name":"Magnus Kulke","email":"magnuskulke@linux.microsoft.com"},"content":"On Tue, May 05, 2026 at 09:50:25PM +0300, Doru Blânzeanu wrote:\n> When the vcpu is created, call mmap to configure access to the register page.\n> In case the call to mmap fails, we log an error and continue with the\n> previous logic (using hypercalls).\n> \n> Update CPUArchState to store a pointer to the mmapped hv_vp_register_page.\n> \n> Signed-off-by: Doru Blânzeanu <dblanzeanu@linux.microsoft.com>\n> ---\n>  target/i386/cpu.h           |  5 +++++\n>  target/i386/mshv/mshv-cpu.c | 22 ++++++++++++++++++++++\n>  2 files changed, 27 insertions(+)\n> \n> diff --git a/target/i386/cpu.h b/target/i386/cpu.h\n> index 16de67e546..fd4c3712b1 100644\n> --- a/target/i386/cpu.h\n> +++ b/target/i386/cpu.h\n> @@ -2019,6 +2019,11 @@ typedef struct CPUArchState {\n>      uint64_t msr_bndcfgs;\n>      uint64_t efer;\n>  \n> +#ifdef CONFIG_MSHV\n> +    /* Shared register page */\n> +    struct hv_vp_register_page *regs_page;\n> +#endif\n\nsince this is declared before this marker\n\n    /* Fields up to this point are cleared by a CPU reset */\n    struct {} end_reset_fields;\n\nthe pointer will be zeroed out on init, best move it after the\nemu_mmio_buf field.\n\n> +\n>      /* Beginning of state preserved by INIT (dummy marker).  */\n>      struct {} start_init_save;\n>  \n> diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c\n> index 9defd05db6..3a3c269c33 100644\n> --- a/target/i386/mshv/mshv-cpu.c\n> +++ b/target/i386/mshv/mshv-cpu.c\n> @@ -1587,6 +1587,7 @@ void mshv_arch_init_vcpu(CPUState *cpu)\n>      CPUX86State *env = &x86_cpu->env;\n>      AccelCPUState *state = cpu->accel;\n>      size_t page = HV_HYP_PAGE_SIZE;\n> +    void *regs_page;\n>      void *mem = qemu_memalign(page, 2 * page);\n>  \n>      /* sanity check, to make sure we don't overflow the page */\n> @@ -1595,6 +1596,22 @@ void mshv_arch_init_vcpu(CPUState *cpu)\n>                        + sizeof(hv_input_get_vp_registers)\n>                        > HV_HYP_PAGE_SIZE));\n>  \n> +\n> +    /* mmap the registers page */\n> +    regs_page = mmap(NULL, page, PROT_READ | PROT_WRITE,\n> +                    MAP_SHARED, mshv_vcpufd(cpu),\n> +                    MSHV_VP_MMAP_OFFSET_REGISTERS * page);\n> +    if (regs_page == MAP_FAILED) {\n> +        /*\n> +         * Error is not fatal, but we won't be able to use the\n> +         * fast path for register access\n> +         */\n> +        error_report(\"register page mmap failed: %s\", strerror(errno));\n> +        env->regs_page = NULL;\n> +    } else {\n> +        env->regs_page = (struct hv_vp_register_page *) regs_page;\n> +    }\n> +\n>      state->hvcall_args.base = mem;\n>      state->hvcall_args.input_page = mem;\n>      state->hvcall_args.output_page = (uint8_t *)mem + page;\n> @@ -1608,6 +1625,11 @@ void mshv_arch_destroy_vcpu(CPUState *cpu)\n>      CPUX86State *env = &x86_cpu->env;\n>      AccelCPUState *state = cpu->accel;\n>  \n> +    /* Unmap the register page */\n> +    if (env->regs_page) {\n> +        munmap(env->regs_page, HV_HYP_PAGE_SIZE);\n> +        env->regs_page = NULL;\n> +    }\n>      g_free(state->hvcall_args.base);\n>      state->hvcall_args = (MshvHvCallArgs){0};\n>      g_clear_pointer(&env->emu_mmio_buf, g_free);\n> -- \n> 2.53.0","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 (1024-bit key;\n unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com\n header.a=rsa-sha256 header.s=default header.b=M7SI55G/;\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 4g9dHS40w5z1yJV\n\tfor <incoming@patchwork.ozlabs.org>; Thu, 07 May 2026 00:36: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 1wKdMR-0008Ri-5b; Wed, 06 May 2026 10:36:27 -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 <magnuskulke@linux.microsoft.com>)\n id 1wKdML-0008RG-9a\n for qemu-devel@nongnu.org; Wed, 06 May 2026 10:36:21 -0400","from linux.microsoft.com ([13.77.154.182])\n by eggs.gnu.org with esmtp (Exim 4.90_1)\n (envelope-from <magnuskulke@linux.microsoft.com>) id 1wKdMJ-0008Bp-Br\n for qemu-devel@nongnu.org; Wed, 06 May 2026 10:36:20 -0400","from example.com (unknown [167.220.208.68])\n by linux.microsoft.com (Postfix) with ESMTPSA id 0295120B7165;\n Wed,  6 May 2026 07:36:13 -0700 (PDT)"],"DKIM-Filter":"OpenDKIM Filter v2.11.0 linux.microsoft.com 0295120B7165","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;\n s=default; t=1778078175;\n bh=FKUfSDsIXOoZFWgGKOL6KFKf7v4gDq85YHXef0xMwsw=;\n h=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n b=M7SI55G/WcRHfMYvgmBXam9yrGusXPCojVPY6LZwGshuEmLlhfJo5V8HOqpRA0GcU\n 3c2AQnyAkQ71cjDwVlk9EAG/OU0qMFew5Htvc8TkoeRjRENMGmz7KzFaJknsN+npS9\n SlOACibC0/dffJNGsFSVkp+2nme8jCTfAKUjx1p0=","Date":"Wed, 6 May 2026 16:36:13 +0200","From":"Magnus Kulke <magnuskulke@linux.microsoft.com>","To":"Doru =?iso-8859-1?q?Bl=E2nzeanu?= <dblanzeanu@linux.microsoft.com>","Cc":"qemu-devel@nongnu.org, Zhao Liu <zhao1.liu@intel.com>,\n Wei Liu <wei.liu@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>","Subject":"Re: [PATCH v2 4/7] target/i386/mshv: hv_vp_register_page setup for\n the vcpu","Message-ID":"<aftR3eiNjbwCoqS/@example.com>","References":"<20260505185028.237207-1-dblanzeanu@linux.microsoft.com>\n <20260505185028.237207-5-dblanzeanu@linux.microsoft.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=iso-8859-1","Content-Disposition":"inline","Content-Transfer-Encoding":"8bit","In-Reply-To":"<20260505185028.237207-5-dblanzeanu@linux.microsoft.com>","Received-SPF":"pass client-ip=13.77.154.182;\n envelope-from=magnuskulke@linux.microsoft.com; helo=linux.microsoft.com","X-Spam_score_int":"-19","X-Spam_score":"-2.0","X-Spam_bar":"--","X-Spam_report":"(-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_NONE=-0.0001,\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"}}]