From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284175; cv=none; d=zohomail.com; s=zohoarc; b=HfE+jsLcq3GfJ3xrc3iOsJ/4xI8wvxCF0EPoE2etF9ruKZCrhDgupEsanGbSb8bwgfnKnt5EhAnPcbhiVvIeVXnN+R46lHlWqhBPiFiFqOdXNrhwYsXSTV0HzI+FlXkOK3Wcw0d1syAgIM1+t6HjmQbsdoOUpNLIdICLHw5v2ck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284175; h=Content-Type: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=i9I6xfNCWdau2JrcIHZW3TdKuyN8cTdaQCkBzvHufKQ=; b=EbohRFL1eHpkCMafFRmjchN+kuvE6HtUygJqp7X945NunhoIZ1OhcFISequrkjgpKuD3TOm8m2+Ty2b7dSGK2YoMES4+It83QeLKg6APfTahOLR8L9gZJNYjPYCxRxIKz0+YsQHbFksjgmahIpXPFZZYUvk24QoVr+Xn7ca7zdU= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 178428417579682.62839495654146; Fri, 17 Jul 2026 03:29:35 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnA-0005qB-Gz; Fri, 17 Jul 2026 06:27:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfn7-0005nX-O5; Fri, 17 Jul 2026 06:27:37 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn5-0000OP-8J; Fri, 17 Jul 2026 06:27:37 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id BDA7C20B716B; Fri, 17 Jul 2026 03:27:21 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com BDA7C20B716B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284041; bh=i9I6xfNCWdau2JrcIHZW3TdKuyN8cTdaQCkBzvHufKQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=a9XOK37BIGfUaHX4mKB8GW07+Mvp1IOr5xtnVqmFyypPr/uwLJmZKeMNXHXVZq4rU Vp+VIPseif80uC7DcQmF/mHiDIXq9lU/So2cvfdj5jxJEqJ4kVQ8zAiZx8fedQTPNI S0j3DRRjykXPjtCibSLO3ZqDcz1WTJoniHdoRKhg= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:16 +0000 Subject: [PATCH v5 01/13] accel/mshv: extract common CPU register helpers MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-1-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284177236158500 Move arch-independent MSHV CPU register handling functions into accel/mshv/mshv-cpu-common.c. Update x86 MSHV backends to use these shared helpers. Prefix get_generic_regs() with mshv_ for proper namespacing since it is now public. Signed-off-by: Aastha Rawat --- accel/mshv/meson.build | 3 +- accel/mshv/mshv-cpu-common.c | 151 +++++++++++++++++++++++++++++++++++++++= ++++ include/system/mshv_int.h | 1 + target/i386/mshv/mshv-cpu.c | 125 +---------------------------------- 4 files changed, 155 insertions(+), 125 deletions(-) diff --git a/accel/mshv/meson.build b/accel/mshv/meson.build index e433187cde..ebe32921b3 100644 --- a/accel/mshv/meson.build +++ b/accel/mshv/meson.build @@ -1,5 +1,6 @@ system_ss.add(when: 'CONFIG_MSHV', if_true: files( 'irq.c', 'mem.c', - 'mshv-all.c' + 'mshv-all.c', + 'mshv-cpu-common.c' )) diff --git a/accel/mshv/mshv-cpu-common.c b/accel/mshv/mshv-cpu-common.c new file mode 100644 index 0000000000..b104720161 --- /dev/null +++ b/accel/mshv/mshv-cpu-common.c @@ -0,0 +1,151 @@ +/* + * QEMU MSHV common CPU register helpers + * + * Copyright Microsoft, Corp. 2026 + * + * Authors: Ziqiao Zhou + * Magnus Kulke + * Jinank Jain + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/memalign.h" + +#include "system/mshv.h" +#include "system/mshv_int.h" + +#include "hw/core/cpu.h" +#include "linux/mshv.h" + +#include + +int mshv_set_generic_regs(const CPUState *cpu, const hv_register_assoc *as= socs, + size_t n_regs) +{ + int cpu_fd =3D mshv_vcpufd(cpu); + int vp_index =3D cpu->cpu_index; + size_t in_sz, assocs_sz; + hv_input_set_vp_registers *in =3D cpu->accel->hvcall_args.input_page; + struct mshv_root_hvcall args =3D {0}; + int ret; + + /* find out the size of the struct w/ a flexible array at the tail */ + assocs_sz =3D n_regs * sizeof(hv_register_assoc); + in_sz =3D sizeof(hv_input_set_vp_registers) + assocs_sz; + + /* fill the input struct */ + memset(in, 0, sizeof(hv_input_set_vp_registers)); + in->vp_index =3D vp_index; + memcpy(in->elements, assocs, assocs_sz); + + /* create the hvcall envelope */ + args.code =3D HVCALL_SET_VP_REGISTERS; + args.in_sz =3D in_sz; + args.in_ptr =3D (uint64_t) in; + args.reps =3D (uint16_t) n_regs; + + /* perform the call */ + ret =3D mshv_hvcall(cpu_fd, &args); + if (ret < 0) { + error_report("Failed to set registers"); + return -1; + } + + /* assert we set all registers */ + if (args.reps !=3D n_regs) { + error_report("Failed to set registers: expected %zu elements" + ", got %u", n_regs, args.reps); + return -1; + } + + return 0; +} + +int mshv_get_generic_regs(CPUState *cpu, hv_register_assoc *assocs, + size_t n_regs) +{ + int cpu_fd =3D mshv_vcpufd(cpu); + int vp_index =3D cpu->cpu_index; + hv_input_get_vp_registers *in =3D cpu->accel->hvcall_args.input_page; + hv_register_value *values =3D cpu->accel->hvcall_args.output_page; + size_t in_sz, names_sz, values_sz; + int i, ret; + struct mshv_root_hvcall args =3D {0}; + + /* find out the size of the struct w/ a flexible array at the tail */ + names_sz =3D n_regs * sizeof(hv_register_name); + in_sz =3D sizeof(hv_input_get_vp_registers) + names_sz; + + /* fill the input struct */ + memset(in, 0, sizeof(hv_input_get_vp_registers)); + in->vp_index =3D vp_index; + for (i =3D 0; i < n_regs; i++) { + in->names[i] =3D assocs[i].name; + } + + /* determine size of value output buffer */ + values_sz =3D n_regs * sizeof(union hv_register_value); + + /* create the hvcall envelope */ + args.code =3D HVCALL_GET_VP_REGISTERS; + args.in_sz =3D in_sz; + args.in_ptr =3D (uint64_t) in; + args.out_sz =3D values_sz; + args.out_ptr =3D (uint64_t) values; + args.reps =3D (uint16_t) n_regs; + + /* perform the call */ + ret =3D mshv_hvcall(cpu_fd, &args); + if (ret < 0) { + error_report("Failed to retrieve registers"); + return -1; + } + + /* assert we got all registers */ + if (args.reps !=3D n_regs) { + error_report("Failed to retrieve registers: expected %zu elements" + ", got %u", n_regs, args.reps); + return -1; + } + + /* copy values into assoc */ + for (i =3D 0; i < n_regs; i++) { + assocs[i].value =3D values[i]; + } + + return 0; +} + +int mshv_create_vcpu(int vm_fd, uint8_t vp_index, int *cpu_fd) +{ + int ret; + struct mshv_create_vp vp_arg =3D { + .vp_index =3D vp_index, + }; + + ret =3D ioctl(vm_fd, MSHV_CREATE_VP, &vp_arg); + if (ret < 0) { + error_report("failed to create mshv vcpu: %s", strerror(errno)); + return -1; + } + + *cpu_fd =3D ret; + + return 0; +} + +void mshv_remove_vcpu(int vm_fd, int cpu_fd) +{ + close(cpu_fd); +} + +void mshv_setup_hvcall_args(AccelCPUState *state) +{ + void *mem =3D qemu_memalign(HV_HYP_PAGE_SIZE, 2 * HV_HYP_PAGE_SIZE); + + state->hvcall_args.base =3D mem; + state->hvcall_args.input_page =3D mem; + state->hvcall_args.output_page =3D (uint8_t *)mem + HV_HYP_PAGE_SIZE; +} diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h index b91c4d661a..e9f4a2f9b9 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -105,6 +105,7 @@ void mshv_arch_amend_proc_features( void mshv_arch_disable_partition_proc_features( union hv_partition_processor_features *disabled_features); int mshv_arch_post_init_vm(int vm_fd); +void mshv_setup_hvcall_args(AccelCPUState *state); =20 typedef struct mshv_root_hvcall mshv_root_hvcall; int mshv_hvcall(int fd, const mshv_root_hvcall *args); diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index 1c433c408c..a142f79801 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -320,103 +320,6 @@ static int translate_gva(const CPUState *cpu, uint64_= t gva, uint64_t *gpa, return 0; } =20 -int mshv_set_generic_regs(const CPUState *cpu, const hv_register_assoc *as= socs, - size_t n_regs) -{ - int cpu_fd =3D mshv_vcpufd(cpu); - int vp_index =3D cpu->cpu_index; - size_t in_sz, assocs_sz; - hv_input_set_vp_registers *in =3D cpu->accel->hvcall_args.input_page; - struct mshv_root_hvcall args =3D {0}; - int ret; - - /* find out the size of the struct w/ a flexible array at the tail */ - assocs_sz =3D n_regs * sizeof(hv_register_assoc); - in_sz =3D sizeof(hv_input_set_vp_registers) + assocs_sz; - - /* fill the input struct */ - memset(in, 0, sizeof(hv_input_set_vp_registers)); - in->vp_index =3D vp_index; - memcpy(in->elements, assocs, assocs_sz); - - /* create the hvcall envelope */ - args.code =3D HVCALL_SET_VP_REGISTERS; - args.in_sz =3D in_sz; - args.in_ptr =3D (uint64_t) in; - args.reps =3D (uint16_t) n_regs; - - /* perform the call */ - ret =3D mshv_hvcall(cpu_fd, &args); - if (ret < 0) { - error_report("Failed to set registers"); - return -1; - } - - /* assert we set all registers */ - if (args.reps !=3D n_regs) { - error_report("Failed to set registers: expected %zu elements" - ", got %u", n_regs, args.reps); - return -1; - } - - return 0; -} - -int mshv_get_generic_regs(CPUState *cpu, hv_register_assoc *assocs, - size_t n_regs) -{ - int cpu_fd =3D mshv_vcpufd(cpu); - int vp_index =3D cpu->cpu_index; - hv_input_get_vp_registers *in =3D cpu->accel->hvcall_args.input_page; - hv_register_value *values =3D cpu->accel->hvcall_args.output_page; - size_t in_sz, names_sz, values_sz; - int i, ret; - struct mshv_root_hvcall args =3D {0}; - - /* find out the size of the struct w/ a flexible array at the tail */ - names_sz =3D n_regs * sizeof(hv_register_name); - in_sz =3D sizeof(hv_input_get_vp_registers) + names_sz; - - /* fill the input struct */ - memset(in, 0, sizeof(hv_input_get_vp_registers)); - in->vp_index =3D vp_index; - for (i =3D 0; i < n_regs; i++) { - in->names[i] =3D assocs[i].name; - } - - /* determine size of value output buffer */ - values_sz =3D n_regs * sizeof(union hv_register_value); - - /* create the hvcall envelope */ - args.code =3D HVCALL_GET_VP_REGISTERS; - args.in_sz =3D in_sz; - args.in_ptr =3D (uint64_t) in; - args.out_sz =3D values_sz; - args.out_ptr =3D (uint64_t) values; - args.reps =3D (uint16_t) n_regs; - - /* perform the call */ - ret =3D mshv_hvcall(cpu_fd, &args); - if (ret < 0) { - error_report("Failed to retrieve registers"); - return -1; - } - - /* assert we got all registers */ - if (args.reps !=3D n_regs) { - error_report("Failed to retrieve registers: expected %zu elements" - ", got %u", n_regs, args.reps); - return -1; - } - - /* copy values into assoc */ - for (i =3D 0; i < n_regs; i++) { - assocs[i].value =3D values[i]; - } - - return 0; -} - static int set_standard_regs(const CPUState *cpu) { X86CPU *x86cpu =3D X86_CPU(cpu); @@ -1968,29 +1871,6 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_messa= ge *msg, MshvVmExit *exit) return 0; } =20 -void mshv_remove_vcpu(int vm_fd, int cpu_fd) -{ - close(cpu_fd); -} - - -int mshv_create_vcpu(int vm_fd, uint8_t vp_index, int *cpu_fd) -{ - int ret; - struct mshv_create_vp vp_arg =3D { - .vp_index =3D vp_index, - }; - ret =3D ioctl(vm_fd, MSHV_CREATE_VP, &vp_arg); - if (ret < 0) { - error_report("failed to create mshv vcpu: %s", strerror(errno)); - return -1; - } - - *cpu_fd =3D ret; - - return 0; -} - static void read_segment_descriptor(CPUState *cpu, struct x86_segment_descriptor *desc, enum X86Seg seg_idx) @@ -2049,7 +1929,6 @@ void mshv_arch_init_vcpu(CPUState *cpu) CPUX86State *env =3D &x86_cpu->env; AccelCPUState *state =3D cpu->accel; size_t page =3D HV_HYP_PAGE_SIZE, xsave_len; - void *mem =3D qemu_memalign(page, 2 * page); int ret; X86XSaveHeader *header; =20 @@ -2071,9 +1950,7 @@ void mshv_arch_init_vcpu(CPUState *cpu) env->regs_page =3D (struct hv_vp_register_page *) rp; } =20 - state->hvcall_args.base =3D mem; - state->hvcall_args.input_page =3D mem; - state->hvcall_args.output_page =3D (uint8_t *)mem + page; + mshv_setup_hvcall_args(state); =20 env->emu_mmio_buf =3D g_new(char, 4096); =20 --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284185; cv=none; d=zohomail.com; s=zohoarc; b=Gf/hqYy0xjQCiEhnU7zVCSSXL67EXwvSDy1gy1HdMmRomFX26VKPPc++PGtXlgLpckiz+x5kn6BH/rSifEG3D1FqFIoBczZUf3pVn20QgqcYH7M3l6ViVZb8xWtgaiBXF4C4ZcJ2ALtdbJlndqQWsfM6AZGiF5GuT9biIIXvhxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284185; h=Content-Type: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=3F9+arkC1uiSexFloo23u4mxdhDWKX7XhaEN/wwXo0w=; b=D64vu40h7fd8xbrnGHlYkIv6n1ig0zNG7aw38PGi5F3JkM8aUCnt9ShB1kjIgukIGgmFASmG7COXFOKJg1OU2xnzw60lFRkVQmWKdKpstOcJzVWBYiiyaaXuHDXqHAqZ/wA1aeY5FxTXbjME2qYeuoiOj3aLd5XoMFbfNTKQqJY= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284185084368.91751481092206; Fri, 17 Jul 2026 03:29:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn7-0005mq-69; Fri, 17 Jul 2026 06:27:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfn5-0005mT-Vo; Fri, 17 Jul 2026 06:27:36 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn4-0000OT-27; Fri, 17 Jul 2026 06:27:35 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 96D7620B716C; Fri, 17 Jul 2026 03:27:22 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 96D7620B716C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284042; bh=3F9+arkC1uiSexFloo23u4mxdhDWKX7XhaEN/wwXo0w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=d6iNxTfMVmpEtEfh3kM4Ly4+3d7V2Uhg33dfev3CGkk2PVcIbndpeO8zk8VDXTEEK yJ9c+0JF1rXxTiMJYYgWlKR6URV0lXchiMTXn+T6RywTiJw0JQejkAh2BMw3MN7psm rdFWajbVY1srjlCjXlXibVhVdGFPrCWTO3ubUbVU= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:17 +0000 Subject: [PATCH v5 02/13] accel/mshv: add arch-specific accelerator init hook MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-2-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284187503158500 From: "Anirudh Rayabharam (Microsoft)" Introduce mshv_arch_accel_init() as an arch-specific hook called early in mshv_init(), before VM creation. This allows each architecture to perform platform-specific initialization at accelerator init time. For x86, the hook calls mshv_init_mmio_emu() which was previously called directly from the common init path. Also move set_unimplemented_msr_action() and mshv_arch_post_init_vm() from mshv-cpu.c to the new mshv-all.c, as they are not vCPU-specific. Signed-off-by: Anirudh Rayabharam (Microsoft) --- accel/mshv/mshv-all.c | 5 ++- include/system/mshv_int.h | 1 + target/i386/mshv/meson.build | 1 + target/i386/mshv/mshv-all.c | 80 ++++++++++++++++++++++++++++++++++++++++= ++++ target/i386/mshv/mshv-cpu.c | 40 ---------------------- 5 files changed, 86 insertions(+), 41 deletions(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index 72721d0f0d..7cf99b44e0 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -557,7 +557,10 @@ static int mshv_init(AccelState *as, MachineState *ms) return -1; } =20 - mshv_init_mmio_emu(); + ret =3D mshv_arch_accel_init(as, ms, mshv_fd); + if (ret < 0) { + return -1; + } =20 ret =3D create_vm(mshv_fd, &vm_fd); if (ret < 0) { diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h index e9f4a2f9b9..81e233be5f 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -104,6 +104,7 @@ void mshv_arch_amend_proc_features( union hv_partition_synthetic_processor_features *features); void mshv_arch_disable_partition_proc_features( union hv_partition_processor_features *disabled_features); +int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd); int mshv_arch_post_init_vm(int vm_fd); void mshv_setup_hvcall_args(AccelCPUState *state); =20 diff --git a/target/i386/mshv/meson.build b/target/i386/mshv/meson.build index 6091c21887..ce54e134cb 100644 --- a/target/i386/mshv/meson.build +++ b/target/i386/mshv/meson.build @@ -1,6 +1,7 @@ i386_mshv_ss =3D ss.source_set() =20 i386_mshv_ss.add(files( + 'mshv-all.c', 'mshv-cpu.c', 'msr.c', )) diff --git a/target/i386/mshv/mshv-all.c b/target/i386/mshv/mshv-all.c new file mode 100644 index 0000000000..f0b43aa86f --- /dev/null +++ b/target/i386/mshv/mshv-all.c @@ -0,0 +1,80 @@ +/* + * QEMU MSHV support + * + * Copyright Microsoft, Corp. 2026 + * + * Authors: Ziqiao Zhou + * Magnus Kulke + * Jinank Jain + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "qemu/memalign.h" + +#include "system/mshv.h" +#include "system/mshv_int.h" +#include "system/address-spaces.h" +#include "linux/mshv.h" +#include "hw/hyperv/hvgdk.h" +#include "hw/hyperv/hvgdk_mini.h" +#include "hw/hyperv/hvhdk_mini.h" +#include "hw/i386/apic_internal.h" + +#include "cpu.h" +#include "emulate/x86_decode.h" +#include "emulate/x86_emu.h" +#include "emulate/x86_flags.h" + +#include "trace-accel_mshv.h" +#include "trace.h" + +#include + +int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd) +{ + mshv_init_mmio_emu(); + return 0; +} + +/* + * Default Microsoft Hypervisor behavior for unimplemented MSR is to send a + * fault to the guest if it tries to access it. It is possible to override + * this behavior with a more suitable option i.e., ignore writes from the = guest + * and return zero in attempt to read unimplemented. + */ +static int set_unimplemented_msr_action(int vm_fd) +{ + struct hv_input_set_partition_property in =3D {0}; + struct mshv_root_hvcall args =3D {0}; + + in.property_code =3D HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION; + in.property_value =3D HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZE= RO; + + args.code =3D HVCALL_SET_PARTITION_PROPERTY; + args.in_sz =3D sizeof(in); + args.in_ptr =3D (uint64_t)∈ + + trace_mshv_hvcall_args("unimplemented_msr_action", args.code, args.in_= sz); + + int ret =3D mshv_hvcall(vm_fd, &args); + if (ret < 0) { + error_report("Failed to set unimplemented MSR action"); + return -1; + } + return 0; +} + +int mshv_arch_post_init_vm(int vm_fd) +{ + int ret; + + ret =3D set_unimplemented_msr_action(vm_fd); + if (ret < 0) { + error_report("Failed to set unimplemented MSR action"); + } + + return ret; +} diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c index a142f79801..0ae1c643a6 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -2037,46 +2037,6 @@ uint32_t mshv_get_supported_cpuid(uint32_t func, uin= t32_t idx, int reg) return ret; } =20 -/* - * Default Microsoft Hypervisor behavior for unimplemented MSR is to send a - * fault to the guest if it tries to access it. It is possible to override - * this behavior with a more suitable option i.e., ignore writes from the = guest - * and return zero in attempt to read unimplemented. - */ -static int set_unimplemented_msr_action(int vm_fd) -{ - struct hv_input_set_partition_property in =3D {0}; - struct mshv_root_hvcall args =3D {0}; - - in.property_code =3D HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION; - in.property_value =3D HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZE= RO; - - args.code =3D HVCALL_SET_PARTITION_PROPERTY; - args.in_sz =3D sizeof(in); - args.in_ptr =3D (uint64_t)∈ - - trace_mshv_hvcall_args("unimplemented_msr_action", args.code, args.in_= sz); - - int ret =3D mshv_hvcall(vm_fd, &args); - if (ret < 0) { - error_report("Failed to set unimplemented MSR action"); - return -1; - } - return 0; -} - -int mshv_arch_post_init_vm(int vm_fd) -{ - int ret; - - ret =3D set_unimplemented_msr_action(vm_fd); - if (ret < 0) { - error_report("Failed to set unimplemented MSR action"); - } - - return ret; -} - static void mshv_cpu_xsave_init(void) { static bool first =3D true; --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284154; cv=none; d=zohomail.com; s=zohoarc; b=eRKfS06iznhPABlj7Pktm76lFYl2Xwd3z24w3jLrjJDU19rTsa6LFCoOoV01pP0qxmiO9nxuw0dAut1pnOra8crXycPOmOu7joA4w74Q5SU9xZkRV3idqgPDSnCoCt/NfujQ7o4c/J7cxrtYkJnBDvbGrNIc9/6M1dYztYRHrFs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284154; h=Content-Type: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=K6XNIfnGqEyw42zXxZV2t+Z6zqUXl7ZnNvoCCyEEnOA=; b=Moxi2lduCNceZidPSgr0SyUEk095ZSgbfQaK857caiElM/R18ceJ6G0T0t4/GtO1ij0Z/qtGUVVgm/AtTnAWD7kf6j1H3OfH1ZH8MCNKzfXwZzYjFll1tE3yOQSSuQi0EtJ4FD51QXKO55pV0g414eYIT/Nnv8AsZSIYnUPsaLU= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284154919668.247057527508; Fri, 17 Jul 2026 03:29:14 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnC-0005rb-Ud; Fri, 17 Jul 2026 06:27:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfnA-0005qk-Sr; Fri, 17 Jul 2026 06:27:40 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn4-0000OZ-GF; Fri, 17 Jul 2026 06:27:40 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 4B15020B716D; Fri, 17 Jul 2026 03:27:23 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4B15020B716D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284043; bh=K6XNIfnGqEyw42zXxZV2t+Z6zqUXl7ZnNvoCCyEEnOA=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RgjaUR3ubIjq3bfCPGEmUA4lmgHRaNtUoIKDjoVBk+5mHkEJ0Dc4q6itCsH4rWSV+ hspz3hOP2KfSNo3ui7HJcZHanqm0ufPNQ6x2TVEpaMDLQvnuWJ/F/YSW+m1U2FnK4Q WkFHZ+zah1KqrH7bgCnUxlJ+V3LU68p/lhK9NFZ4= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:18 +0000 Subject: [PATCH v5 03/13] meson, target/arm/mshv: Enable arm64 build & add initial MSHV support MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-3-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284157345158500 Enable the build of the MSHV accelerator for arm64 in the Meson build system. Introduce initial files and stub implementations to support MSHV for the ARM target. Signed-off-by: Aastha Rawat --- accel/mshv/mshv-all.c | 10 +++++-- meson.build | 8 ++--- target/arm/meson.build | 1 + target/arm/mshv/meson.build | 7 +++++ target/arm/mshv/mshv-all.c | 72 +++++++++++++++++++++++++++++++++++++++++= ++++ 5 files changed, 92 insertions(+), 6 deletions(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index 7cf99b44e0..199b957a97 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -188,8 +188,10 @@ static int create_partition(int mshv_fd, int *vm_fd) { int ret; uint64_t pt_flags, host_proc_features; - union hv_partition_processor_xsave_features disabled_xsave_features; union hv_partition_processor_features disabled_partition_features =3D = {0}; +#if defined(__x86_64__) + union hv_partition_processor_xsave_features disabled_xsave_features; +#endif =20 struct mshv_create_partition_v2 args =3D {0}; =20 @@ -201,8 +203,10 @@ static int create_partition(int mshv_fd, int *vm_fd) (1ULL << MSHV_PT_BIT_GPA_SUPER_PAGES) | (1ULL << MSHV_PT_BIT_CPU_AND_XSAVE_FEATURES); =20 - /* enable all */ +#if defined(__x86_64__) + /* enable all xsave features (0 =3D enabled) */ disabled_xsave_features.as_uint64 =3D 0; +#endif =20 /* * query host for supported processor features and disable unsupported @@ -234,7 +238,9 @@ static int create_partition(int mshv_fd, int *vm_fd) /* populate args structure */ args.pt_flags =3D pt_flags; args.pt_isolation =3D MSHV_PT_ISOLATION_NONE; +#if defined(__x86_64__) args.pt_disabled_xsave =3D disabled_xsave_features.as_uint64; +#endif args.pt_num_cpu_fbanks =3D MSHV_NUM_CPU_FEATURES_BANKS; =20 ret =3D ioctl(mshv_fd, MSHV_CREATE_PARTITION, &args); diff --git a/meson.build b/meson.build index 164328ded8..b8fbcaab10 100644 --- a/meson.build +++ b/meson.build @@ -305,7 +305,8 @@ if cpu =3D=3D 'aarch64' accelerator_targets +=3D { 'CONFIG_HVF': ['aarch64-softmmu'], 'CONFIG_NITRO': ['aarch64-softmmu'], - 'CONFIG_WHPX': ['aarch64-softmmu'] + 'CONFIG_WHPX': ['aarch64-softmmu'], + 'CONFIG_MSHV': ['aarch64-softmmu'], } elif cpu =3D=3D 'x86_64' accelerator_targets +=3D { @@ -873,10 +874,9 @@ if get_option('kvm').allowed() and host_os =3D=3D 'lin= ux' endif =20 if get_option('mshv').allowed() and host_os =3D=3D 'linux' - if get_option('mshv').enabled() and host_machine.cpu() !=3D 'x86_64' - error('mshv accelerator requires x64_64 host') + if host_machine.cpu() in [ 'x86_64', 'aarch64' ] + accelerators +=3D 'CONFIG_MSHV' endif - accelerators +=3D 'CONFIG_MSHV' endif =20 if get_option('whpx').allowed() and host_os =3D=3D 'windows' diff --git a/target/arm/meson.build b/target/arm/meson.build index 4412fde065..acbf257048 100644 --- a/target/arm/meson.build +++ b/target/arm/meson.build @@ -61,6 +61,7 @@ arm_common_system_ss.add(files( =20 subdir('hvf') subdir('whpx') +subdir('mshv') =20 if 'CONFIG_TCG' in config_all_accel subdir('tcg') diff --git a/target/arm/mshv/meson.build b/target/arm/mshv/meson.build new file mode 100644 index 0000000000..169643691e --- /dev/null +++ b/target/arm/mshv/meson.build @@ -0,0 +1,7 @@ +arm_mshv_ss =3D ss.source_set() + +arm_mshv_ss.add(files( + 'mshv-all.c', +)) + +arm_system_ss.add_all(when: 'CONFIG_MSHV', if_true: arm_mshv_ss) diff --git a/target/arm/mshv/mshv-all.c b/target/arm/mshv/mshv-all.c new file mode 100644 index 0000000000..ac2302ff6c --- /dev/null +++ b/target/arm/mshv/mshv-all.c @@ -0,0 +1,72 @@ +/* + * QEMU MSHV support + * + * Copyright Microsoft, Corp. 2026 + * + * Authors: Aastha Rawat + * Anirudh Rayabharam + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/arm/virt.h" +#include "system/mshv.h" +#include "system/mshv_int.h" + +static int load_regs(CPUState *cpu) +{ + return 0; +} + +static int store_regs(const CPUState *cpu) +{ + return 0; +} + +int mshv_arch_load_vcpu_state(CPUState *cpu) +{ + return load_regs(cpu); +} + +int mshv_arch_store_vcpu_state(const CPUState *cpu) +{ + return store_regs(cpu); +} + +int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *e= xit) +{ + return 0; +} + +void mshv_arch_init_vcpu(CPUState *cpu) +{ + +} + +void mshv_arch_destroy_vcpu(CPUState *cpu) +{ + +} + +int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd) +{ + return 0; +} + +void mshv_arch_amend_proc_features( + union hv_partition_synthetic_processor_features *features) +{ + +} + +void mshv_arch_disable_partition_proc_features( + union hv_partition_processor_features *disabled_features) +{ + /* No processor features to disable on ARM */ +} + +int mshv_arch_post_init_vm(int vm_fd) +{ + return 0; +} --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284098; cv=none; d=zohomail.com; s=zohoarc; b=U0xrBLVercK5asR28OSH2XIsuWwVYlcQtc4rN4eLJiCfyzbXYuYyPiVPlhlrUP7itj1LrI3BvjqKj6tTz1Nu+uguC2Pswr7X6lAPIixCuqzGhbAa8Qa3fzOyLhufB/edrKKFxgwUqAKLCNSiwvRkGovG2THHgsowToe4gAQS4JM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284098; h=Content-Type: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=V6+mDNRbCLh/k1VfA774KE0sZK4GfW4wbcvjPJ2UHAg=; b=iJoplMsv2TquU5847h2rz1Ivz+13vqfA7n8hHSdWQBgafRBBsA1Vu81q/2RSEJNMxABgxgFSmck1BkWU7jiaXJ34lLM6urpXtMVKF82mMciNbVB2hnHKJP/Ae5XU6iQwl6a/awyXu4/Ev4xU3roqRguYOJf2cvOLzGuuGy3dux8= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284098665920.8113971867681; Fri, 17 Jul 2026 03:28:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn9-0005ov-MY; Fri, 17 Jul 2026 06:27:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfn7-0005nA-I2; Fri, 17 Jul 2026 06:27:37 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn5-0000Oi-8v; Fri, 17 Jul 2026 06:27:37 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id EA90720B716E; Fri, 17 Jul 2026 03:27:23 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com EA90720B716E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284044; bh=V6+mDNRbCLh/k1VfA774KE0sZK4GfW4wbcvjPJ2UHAg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=YJM6MB32GkSBMh4nwI1EMz4nO4Gi8urHvR1yZbhnk+md3FlmATuhxTkVUTHp/m/Ah N9BLb0J4ucO5sNPk0RnlAwdg5jun38pwDl++hEG//RtWThZz0KrDz3E4YvhpUfbz3I 2apIAvXUNIDxiDjBXtuvpfLO4GP3HLK6K9MocYdg= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:19 +0000 Subject: [PATCH v5 04/13] target/arm/mshv: implement vcpu state operations for ARM64 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-4-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284101490158500 Add support for reading and writing ARM64 CPU registers in the MSHV accelerator. This includes functions to set and get registers, initialize and destroy VCPU state, and manage register state synchronization between QEMU and hypervisor. Signed-off-by: Aastha Rawat --- include/hw/hyperv/hvgdk_mini.h | 42 +++++++++++++++ target/arm/mshv/mshv-all.c | 119 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 161 insertions(+) diff --git a/include/hw/hyperv/hvgdk_mini.h b/include/hw/hyperv/hvgdk_mini.h index f8838a31bb..740a73c85a 100644 --- a/include/hw/hyperv/hvgdk_mini.h +++ b/include/hw/hyperv/hvgdk_mini.h @@ -29,6 +29,46 @@ typedef enum hv_register_name { HV_REGISTER_PENDING_EVENT0 =3D 0x00010004, HV_REGISTER_PENDING_EVENT1 =3D 0x00010005, =20 +#if defined(__aarch64__) + HV_ARM64_REGISTER_XZR =3D 0x0002FFFE, + HV_ARM64_REGISTER_X0 =3D 0x00020000, + HV_ARM64_REGISTER_X1 =3D 0x00020001, + HV_ARM64_REGISTER_X2 =3D 0x00020002, + HV_ARM64_REGISTER_X3 =3D 0x00020003, + HV_ARM64_REGISTER_X4 =3D 0x00020004, + HV_ARM64_REGISTER_X5 =3D 0x00020005, + HV_ARM64_REGISTER_X6 =3D 0x00020006, + HV_ARM64_REGISTER_X7 =3D 0x00020007, + HV_ARM64_REGISTER_X8 =3D 0x00020008, + HV_ARM64_REGISTER_X9 =3D 0x00020009, + HV_ARM64_REGISTER_X10 =3D 0x0002000A, + HV_ARM64_REGISTER_X11 =3D 0x0002000B, + HV_ARM64_REGISTER_X12 =3D 0x0002000C, + HV_ARM64_REGISTER_X13 =3D 0x0002000D, + HV_ARM64_REGISTER_X14 =3D 0x0002000E, + HV_ARM64_REGISTER_X15 =3D 0x0002000F, + HV_ARM64_REGISTER_X16 =3D 0x00020010, + HV_ARM64_REGISTER_X17 =3D 0x00020011, + HV_ARM64_REGISTER_X18 =3D 0x00020012, + HV_ARM64_REGISTER_X19 =3D 0x00020013, + HV_ARM64_REGISTER_X20 =3D 0x00020014, + HV_ARM64_REGISTER_X21 =3D 0x00020015, + HV_ARM64_REGISTER_X22 =3D 0x00020016, + HV_ARM64_REGISTER_X23 =3D 0x00020017, + HV_ARM64_REGISTER_X24 =3D 0x00020018, + HV_ARM64_REGISTER_X25 =3D 0x00020019, + HV_ARM64_REGISTER_X26 =3D 0x0002001A, + HV_ARM64_REGISTER_X27 =3D 0x0002001B, + HV_ARM64_REGISTER_X28 =3D 0x0002001C, + HV_ARM64_REGISTER_FP =3D 0x0002001D, + HV_ARM64_REGISTER_LR =3D 0x0002001E, + HV_ARM64_REGISTER_PC =3D 0x00020022, + + /* AArch64 System Register Descriptions: General system control regist= ers */ + HV_ARM64_REGISTER_MIDR_EL1 =3D 0x00040051, + HV_ARM64_REGISTER_MPIDR_EL1 =3D 0x00040001, + +#elif defined(__x86_64__) /* X64 User-Mode Registers */ HV_X64_REGISTER_RAX =3D 0x00020000, HV_X64_REGISTER_RCX =3D 0x00020001, @@ -184,6 +224,8 @@ typedef enum hv_register_name { /* Other MSRs */ HV_X64_REGISTER_MSR_IA32_MISC_ENABLE =3D 0x000800A0, =20 +#endif + /* Misc */ HV_X64_REGISTER_HYPERCALL =3D 0x00090001, HV_REGISTER_GUEST_OS_ID =3D 0x00090002, diff --git a/target/arm/mshv/mshv-all.c b/target/arm/mshv/mshv-all.c index ac2302ff6c..a3ca60a4d5 100644 --- a/target/arm/mshv/mshv-all.c +++ b/target/arm/mshv/mshv-all.c @@ -10,17 +10,128 @@ */ =20 #include "qemu/osdep.h" +#include + +#include "qemu/error-report.h" +#include "qemu/memalign.h" #include "hw/arm/virt.h" + +#include "system/cpus.h" +#include "target/arm/cpu.h" + #include "system/mshv.h" #include "system/mshv_int.h" +#include "hw/hyperv/hvgdk_mini.h" + +static const enum hv_register_name STANDARD_REGISTER_NAMES[32] =3D { + HV_ARM64_REGISTER_X0, + HV_ARM64_REGISTER_X1, + HV_ARM64_REGISTER_X2, + HV_ARM64_REGISTER_X3, + HV_ARM64_REGISTER_X4, + HV_ARM64_REGISTER_X5, + HV_ARM64_REGISTER_X6, + HV_ARM64_REGISTER_X7, + HV_ARM64_REGISTER_X8, + HV_ARM64_REGISTER_X9, + HV_ARM64_REGISTER_X10, + HV_ARM64_REGISTER_X11, + HV_ARM64_REGISTER_X12, + HV_ARM64_REGISTER_X13, + HV_ARM64_REGISTER_X14, + HV_ARM64_REGISTER_X15, + HV_ARM64_REGISTER_X16, + HV_ARM64_REGISTER_X17, + HV_ARM64_REGISTER_X18, + HV_ARM64_REGISTER_X19, + HV_ARM64_REGISTER_X20, + HV_ARM64_REGISTER_X21, + HV_ARM64_REGISTER_X22, + HV_ARM64_REGISTER_X23, + HV_ARM64_REGISTER_X24, + HV_ARM64_REGISTER_X25, + HV_ARM64_REGISTER_X26, + HV_ARM64_REGISTER_X27, + HV_ARM64_REGISTER_X28, + HV_ARM64_REGISTER_FP, + HV_ARM64_REGISTER_LR, + HV_ARM64_REGISTER_PC, +}; + +static int set_standard_regs(const CPUState *cpu) +{ + size_t n_regs =3D ARRAY_SIZE(STANDARD_REGISTER_NAMES); + struct hv_register_assoc assocs[ARRAY_SIZE(STANDARD_REGISTER_NAMES)] = =3D {}; + int ret; + ARMCPU *arm_cpu =3D ARM_CPU(cpu); + CPUARMState *env =3D &arm_cpu->env; + + for (size_t i =3D 0; i < n_regs - 1; i++) { + assocs[i].name =3D STANDARD_REGISTER_NAMES[i]; + assocs[i].value.reg64 =3D env->xregs[i]; + } + + /* Last register is the program counter */ + assocs[n_regs - 1].name =3D STANDARD_REGISTER_NAMES[n_regs - 1]; + assocs[n_regs - 1].value.reg64 =3D env->pc; + + ret =3D mshv_set_generic_regs(cpu, assocs, n_regs); + if (ret < 0) { + error_report("failed to set standard registers"); + return -1; + } + + return 0; +} + +static int get_standard_regs(CPUState *cpu) +{ + size_t n_regs =3D ARRAY_SIZE(STANDARD_REGISTER_NAMES); + struct hv_register_assoc assocs[ARRAY_SIZE(STANDARD_REGISTER_NAMES)] = =3D {}; + int ret; + ARMCPU *arm_cpu =3D ARM_CPU(cpu); + CPUARMState *env =3D &arm_cpu->env; + + for (size_t i =3D 0; i < n_regs; i++) { + assocs[i].name =3D STANDARD_REGISTER_NAMES[i]; + } + ret =3D mshv_get_generic_regs(cpu, assocs, n_regs); + if (ret < 0) { + error_report("failed to get standard registers"); + return -1; + } + + for (size_t i =3D 0; i < n_regs - 1; i++) { + env->xregs[i] =3D assocs[i].value.reg64; + } + env->pc =3D assocs[n_regs - 1].value.reg64; + + return 0; +} =20 static int load_regs(CPUState *cpu) { + int ret; + + ret =3D get_standard_regs(cpu); + if (ret < 0) { + error_report("Failed to load standard registers"); + return -1; + } + return 0; } =20 static int store_regs(const CPUState *cpu) { + int ret; + + ret =3D set_standard_regs(cpu); + if (ret < 0) { + error_report("Failed to store standard registers"); + return -1; + } + return 0; } =20 @@ -41,12 +152,20 @@ int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message= *msg, MshvVmExit *exit) =20 void mshv_arch_init_vcpu(CPUState *cpu) { + AccelCPUState *state =3D cpu->accel; =20 + mshv_setup_hvcall_args(state); } =20 void mshv_arch_destroy_vcpu(CPUState *cpu) { + AccelCPUState *state =3D cpu->accel; + + if (state->hvcall_args.base) { + qemu_vfree(state->hvcall_args.base); + } =20 + state->hvcall_args =3D (MshvHvCallArgs){0}; } =20 int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd) --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284194; cv=none; d=zohomail.com; s=zohoarc; b=jtCmb/KScZbuGYwfqzRbIPeqfHh39SuREzmTmW4XApD3luhSOJlIW7WMrezINTBPks3ZafZPEcZSfuTBmUWJNKgs91TB+0vzlOhAylVs4Eh7rRKA6/8tLc1Cvqxv6DWJPRw5hSV+4c86U22uSe5dFbnopfpwAXxjyfjdaRmaqeA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284194; h=Content-Type: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=W5oTxHBqK2JiDAiHbkwJlqTOiYpl5s4zdpxfycSZFpU=; b=gViP4cFZnUmqyMAsmDXhFRc6TPkKKLDT1kw9/WXwi0bIkGqpplQgo4u6SdxGzWkyEb83z4ZD1tfG4Ne4K/XhDSAUfXzeezvueEC614CpYl44fnyi++AOqKf9vYEs//HqrFPmW2ohBQmXOW+T9iReHsffByR6161PfF8Cz+SSfc0= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284194124429.3802998802769; Fri, 17 Jul 2026 03:29:54 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnA-0005qC-Gd; Fri, 17 Jul 2026 06:27:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfn8-0005oL-Es; Fri, 17 Jul 2026 06:27:38 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn6-0000P7-R8; Fri, 17 Jul 2026 06:27:38 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 9EB6220B716F; Fri, 17 Jul 2026 03:27:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9EB6220B716F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284044; bh=W5oTxHBqK2JiDAiHbkwJlqTOiYpl5s4zdpxfycSZFpU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=PEYbGo/XFiwcT18RD0+IuwjC7JwznKIEfRLgprSMLlbr6sHVVtTY0lcWcuzoz05wQ 8/AlDMhDx5ylN2IEDt/aUDHfZvX/hJaVgPHhY2gK12Fh9yiN7GAS7FLDwKxHxbygMK 4Wdb71oPcad2Mw23sJfuJhDQHa9zJfLBc6z0f7Mo= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:20 +0000 Subject: [PATCH v5 05/13] target/arm: convert host CPU feature ifdef ladder to runtime checks MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-5-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284195077158500 Replace the compile-time #if/#elif preprocessor ladder in aarch64_host_initfn() with runtime calls and add mshv_enabled() to it. This ensures the correct accelerator is selected at runtime when multiple accelerators are compiled in. Add CONFIG_MSHV to the aarch64_cpus[] guard so that mshv accelerator can register the "host" CPU type. Signed-off-by: Aastha Rawat --- target/arm/cpu64.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 2816735577..9724c9475d 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -802,17 +802,21 @@ void aarch64_host_initfn(Object *obj) } #endif =20 + if (mshv_enabled()) { + mshv_arm_set_cpu_features_from_host(cpu); + } else if (kvm_enabled()) { #if defined(CONFIG_KVM) - kvm_arm_set_cpreg_mig_tolerances(cpu); - kvm_arm_set_cpu_features_from_host(cpu); - aarch64_add_sve_properties(obj); -#elif defined(CONFIG_HVF) - hvf_arm_set_cpu_features_from_host(cpu); -#elif defined(CONFIG_WHPX) - whpx_arm_set_cpu_features_from_host(cpu); -#else - g_assert_not_reached(); + kvm_arm_set_cpreg_mig_tolerances(cpu); #endif + kvm_arm_set_cpu_features_from_host(cpu); + aarch64_add_sve_properties(obj); + } else if (hvf_enabled()) { + hvf_arm_set_cpu_features_from_host(cpu); + } else if (whpx_enabled()) { + whpx_arm_set_cpu_features_from_host(cpu); + } else { + g_assert_not_reached(); + } if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { aarch64_add_pauth_properties(obj); } @@ -821,7 +825,8 @@ void aarch64_host_initfn(Object *obj) static const ARMCPUInfo aarch64_cpus[] =3D { { .name =3D "cortex-a57", .initfn =3D aarch64_a57_initfn }, { .name =3D "cortex-a53", .initfn =3D aarch64_a53_initfn }, -#if defined(CONFIG_KVM) || defined(CONFIG_HVF) || defined(CONFIG_WHPX) +#if defined(CONFIG_KVM) || defined(CONFIG_HVF) || \ + defined(CONFIG_WHPX) || defined(CONFIG_MSHV) { .name =3D "host", .initfn =3D aarch64_host_initfn }, #endif }; --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284170; cv=none; d=zohomail.com; s=zohoarc; b=DOlWt6Dg6JHlciVqJUiByHENCzZ2Uf2scyKu3DDodFLbneJaNePjgzzy56VVdb5fNyKfg4i3zjsRJllEAiPz3btDkrNAPjnSOAuVTz81+4cV1XgI8wQUE4T777CcNPP0/Oxmvvo8/rlKnG3fR2SGbBcdfoJdaIXAYkJbyJB9liw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284170; h=Content-Type: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=V8OzHC5oy918yB/21XHFyqNdjwQiewwEcgmUSw0zINY=; b=DCb9Pdx4Ur+uxWcZ1iDeSzHiAyg5smDEmZAtGNMEnBTOmv5YnDvZDIz3SHpsERa9N+DMqIE/woun69vk1SXqwcqCQ2jd2ffLIFcoEDRAtI3JAUkHGcexwwRR7yG1yOGN0ZZ6k40EOhj3dGfmNfdRUmsAXhFWkBPCes/2MYb+AoA= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284170905458.76186314170434; Fri, 17 Jul 2026 03:29:30 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnB-0005rU-M1; Fri, 17 Jul 2026 06:27:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfn9-0005ok-CK; Fri, 17 Jul 2026 06:27:39 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn6-0000P5-Oc; Fri, 17 Jul 2026 06:27:39 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 332E720B7171; Fri, 17 Jul 2026 03:27:25 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 332E720B7171 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284045; bh=V8OzHC5oy918yB/21XHFyqNdjwQiewwEcgmUSw0zINY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=kPDZmTCv+Mp6Isll245Q8EBrqsybPu+pD237gQWvSC1E+VcoJVTuyNv89OM/pblao zmSFOr8y5UR/JJpN345Bnk9xd/tXVUKRfWyXc47UaVpcxLV85uBNz3yJOppuQSRcwv 5F1jSAUiOepxigfCLW8WG8w04uNLCyJOiPeEFGYs= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:21 +0000 Subject: [PATCH v5 06/13] target/arm/mshv: implement -cpu host for MSHV MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-6-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284173237158500 This commit enables support for the `-cpu host` option with MSHV accelerator on ARM64. The implementation queries the partition's CPU's ID registers and features via hypervisor interface, allowing to pass all CPU capabilities for the host CPU to the guest. Signed-off-by: Aastha Rawat --- hw/arm/virt.c | 3 +- include/hw/hyperv/hvgdk_mini.h | 17 ++++ include/system/hw_accel.h | 3 +- target/arm/cpu.c | 6 +- target/arm/cpu64.c | 2 + target/arm/mshv/mshv-all.c | 217 +++++++++++++++++++++++++++++++++++++= ++++ target/arm/mshv_arm.h | 18 ++++ 7 files changed, 262 insertions(+), 4 deletions(-) diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 219597cabd..438bd408ba 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -49,6 +49,7 @@ #include "system/kvm.h" #include "system/hvf.h" #include "system/whpx.h" +#include "system/mshv.h" #include "system/qtest.h" #include "system/system.h" #include "hw/core/loader.h" @@ -4147,7 +4148,7 @@ static GPtrArray *virt_get_valid_cpu_types(const Mach= ineState *ms) if (target_aarch64()) { g_ptr_array_add(vct, g_strdup(ARM_CPU_TYPE_NAME("cortex-a53"))); g_ptr_array_add(vct, g_strdup(ARM_CPU_TYPE_NAME("cortex-a57"))); - if (kvm_enabled() || hvf_enabled() || whpx_enabled()) { + if (kvm_enabled() || hvf_enabled() || whpx_enabled() || mshv_enabl= ed()) { g_ptr_array_add(vct, g_strdup(ARM_CPU_TYPE_NAME("host"))); } } diff --git a/include/hw/hyperv/hvgdk_mini.h b/include/hw/hyperv/hvgdk_mini.h index 740a73c85a..fc014aa5d7 100644 --- a/include/hw/hyperv/hvgdk_mini.h +++ b/include/hw/hyperv/hvgdk_mini.h @@ -64,6 +64,20 @@ typedef enum hv_register_name { HV_ARM64_REGISTER_LR =3D 0x0002001E, HV_ARM64_REGISTER_PC =3D 0x00020022, =20 + /* AArch64 System Register Descriptions: ID Registers */ + HV_ARM64_REGISTER_ID_MIDR_EL1 =3D 0x00022000, + HV_ARM64_REGISTER_ID_MPIDR_EL1 =3D 0x00022005, + HV_ARM64_REGISTER_ID_AA64_PFR0_EL1 =3D 0x00022020, + HV_ARM64_REGISTER_ID_AA64_PFR1_EL1 =3D 0x00022021, + HV_ARM64_REGISTER_ID_AA64_ISAR0_EL1 =3D 0x00022030, + HV_ARM64_REGISTER_ID_AA64_ISAR1_EL1 =3D 0x00022031, + HV_ARM64_REGISTER_ID_AA64_ISAR2_EL1 =3D 0x00022032, + HV_ARM64_REGISTER_ID_AA64_MMFR0_EL1 =3D 0x00022038, + HV_ARM64_REGISTER_ID_AA64_MMFR1_EL1 =3D 0x00022039, + HV_ARM64_REGISTER_ID_AA64_MMFR2_EL1 =3D 0x0002203a, + HV_ARM64_REGISTER_ID_AA64_DFR0_EL1 =3D 0x00022028, + HV_ARM64_REGISTER_ID_AA64_DFR1_EL1 =3D 0x00022029, + /* AArch64 System Register Descriptions: General system control regist= ers */ HV_ARM64_REGISTER_MIDR_EL1 =3D 0x00040051, HV_ARM64_REGISTER_MPIDR_EL1 =3D 0x00040001, @@ -983,6 +997,9 @@ struct hv_cpuid { #define HV_HYP_PAGE_SIZE BIT(HV_HYP_PAGE_SHIFT) #define HV_HYP_PAGE_MASK (~(HV_HYP_PAGE_SIZE - 1)) =20 +#define HV_ANY_VP ((uint32_t)-1) +#define HV_VTL_ALL 0xF + #define HVCALL_GET_PARTITION_PROPERTY 0x0044 #define HVCALL_SET_PARTITION_PROPERTY 0x0045 #define HVCALL_GET_VP_REGISTERS 0x0050 diff --git a/include/system/hw_accel.h b/include/system/hw_accel.h index f0c10b6d80..614ea60be3 100644 --- a/include/system/hw_accel.h +++ b/include/system/hw_accel.h @@ -51,7 +51,8 @@ static inline bool hwaccel_enabled(void) return hvf_enabled() || kvm_enabled() || nvmm_enabled() - || whpx_enabled(); + || whpx_enabled() + || mshv_enabled(); } =20 #endif /* QEMU_HW_ACCEL_H */ diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 787e4dc7ab..c5037a145a 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -47,6 +47,7 @@ #include "system/tcg.h" #include "system/qtest.h" #include "system/hw_accel.h" +#include "system/mshv.h" #include "kvm_arm.h" #include "disas/capstone.h" #include "fpu/softfloat.h" @@ -1829,8 +1830,9 @@ static void arm_cpu_realizefn(DeviceState *dev, Error= **errp) * this is the first point where we can report it. */ if (cpu->host_cpu_probe_failed) { - if (!kvm_enabled() && !hvf_enabled() && !whpx_enabled()) { - error_setg(errp, "The 'host' CPU type can only be used with KV= M, HVF or WHPX"); + if (!kvm_enabled() && !hvf_enabled() && !whpx_enabled() && !mshv_e= nabled()) { + error_setg(errp, + "The 'host' CPU type can only be used with KVM, HVF= , WHPX, or MSHV"); } else { error_setg(errp, "Failed to retrieve host CPU features"); } diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index 9724c9475d..dc8239efc6 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -26,12 +26,14 @@ #include "qemu/units.h" #include "system/kvm.h" #include "system/hvf.h" +#include "system/mshv.h" #include "system/whpx.h" #include "system/hw_accel.h" #include "system/qtest.h" #include "system/tcg.h" #include "kvm_arm.h" #include "hvf_arm.h" +#include "mshv_arm.h" #include "whpx_arm.h" #include "qapi/visitor.h" #include "hw/core/qdev-properties.h" diff --git a/target/arm/mshv/mshv-all.c b/target/arm/mshv/mshv-all.c index a3ca60a4d5..da43333aa6 100644 --- a/target/arm/mshv/mshv-all.c +++ b/target/arm/mshv/mshv-all.c @@ -18,10 +18,23 @@ =20 #include "system/cpus.h" #include "target/arm/cpu.h" +#include "target/arm/internals.h" +#include "target/arm/mshv_arm.h" =20 #include "system/mshv.h" #include "system/mshv_int.h" #include "hw/hyperv/hvgdk_mini.h" +#include "hw/hyperv/hvhdk_mini.h" + +typedef struct ARMHostCPUFeatures { + ARMISARegisters isar; + uint64_t features; + uint64_t midr; + uint32_t reset_sctlr; + const char *dtb_compatible; +} ARMHostCPUFeatures; + +static ARMHostCPUFeatures arm_host_cpu_features; =20 static const enum hv_register_name STANDARD_REGISTER_NAMES[32] =3D { HV_ARM64_REGISTER_X0, @@ -168,8 +181,46 @@ void mshv_arch_destroy_vcpu(CPUState *cpu) state->hvcall_args =3D (MshvHvCallArgs){0}; } =20 + +static uint32_t mshv_arm_get_ipa_bit_size(int mshv_fd) +{ + int ret; + struct hv_input_get_partition_property in =3D {0}; + struct hv_output_get_partition_property out =3D {0}; + struct mshv_root_hvcall args =3D {0}; + + in.property_code =3D HV_PARTITION_PROPERTY_PHYSICAL_ADDRESS_WIDTH; + + args.code =3D HVCALL_GET_PARTITION_PROPERTY; + args.in_sz =3D sizeof(in); + args.in_ptr =3D (uint64_t)∈ + args.out_sz =3D sizeof(out); + args.out_ptr =3D (uint64_t)&out; + + ret =3D mshv_hvcall(mshv_fd, &args); + + if (ret < 0) { + error_report("Failed to get IPA size"); + exit(1); + } + + return out.property_value; +} + int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd) { + MachineClass *mc =3D MACHINE_GET_CLASS(ms); + int pa_range; + uint32_t ipa_size; + + if (mc->get_physical_address_range) { + ipa_size =3D mshv_arm_get_ipa_bit_size(mshv_fd); + pa_range =3D mc->get_physical_address_range(ms, ipa_size, ipa_size= ); + if (pa_range < 0) { + return -EINVAL; + } + } + return 0; } =20 @@ -189,3 +240,169 @@ int mshv_arch_post_init_vm(int vm_fd) { return 0; } + +static void clamp_id_aa64mmfr0_parange_to_ipa_size(int mshv_fd, + ARMISARegisters *isar) +{ + uint32_t ipa_size =3D mshv_arm_get_ipa_bit_size(mshv_fd); + uint64_t id_aa64mmfr0; + + /* Clamp down the PARange to the IPA size the kernel supports. */ + uint8_t index =3D round_down_to_parange_index(ipa_size); + id_aa64mmfr0 =3D GET_IDREG(isar, ID_AA64MMFR0); + id_aa64mmfr0 =3D FIELD_DP64(id_aa64mmfr0, ID_AA64MMFR0, PARANGE, index= ); + SET_IDREG(isar, ID_AA64MMFR0, id_aa64mmfr0); +} + +static int mshv_get_partition_regs(int vm_fd, hv_register_name *names, + hv_register_value *values, size_t n_regs) +{ + int ret =3D 0; + size_t in_sz, names_sz, values_sz; + void *in_buffer =3D qemu_memalign(HV_HYP_PAGE_SIZE, HV_HYP_PAGE_SIZE); + void *out_buffer =3D qemu_memalign(HV_HYP_PAGE_SIZE, HV_HYP_PAGE_SIZE); + hv_input_get_vp_registers *in =3D in_buffer; + + struct mshv_root_hvcall args =3D {0}; + + names_sz =3D n_regs * sizeof(hv_register_name); + in_sz =3D sizeof(hv_input_get_vp_registers) + names_sz; + + memset(in, 0, HV_HYP_PAGE_SIZE); + + in->vp_index =3D HV_ANY_VP; + in->input_vtl.target_vtl =3D HV_VTL_ALL; + in->input_vtl.use_target_vtl =3D 1; + + for (int i =3D 0; i < n_regs; i++) { + in->names[i] =3D names[i]; + } + + values_sz =3D n_regs * sizeof(hv_register_value); + + args.code =3D HVCALL_GET_VP_REGISTERS; + args.in_sz =3D in_sz; + args.in_ptr =3D (uintptr_t)in_buffer; + args.out_sz =3D values_sz; + args.out_ptr =3D (uintptr_t)out_buffer; + args.reps =3D n_regs; + + ret =3D mshv_hvcall(vm_fd, &args); + + if (ret =3D=3D 0) { + memcpy(values, out_buffer, values_sz); + } + + qemu_vfree(in_buffer); + qemu_vfree(out_buffer); + + return ret; +} + +static bool mshv_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) +{ + int mshv_fd =3D mshv_state->fd; + int vm_fd =3D mshv_state->vm; + int i, ret; + bool success =3D true; + uint64_t pfr0, pfr1; + gchar *contents =3D NULL; + + static const struct { + hv_register_name name; + int isar_idx; + } regs[] =3D { + { HV_ARM64_REGISTER_ID_AA64_PFR0_EL1, ID_AA64PFR0_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_PFR1_EL1, ID_AA64PFR1_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_ISAR0_EL1, ID_AA64ISAR0_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_ISAR1_EL1, ID_AA64ISAR1_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_ISAR2_EL1, ID_AA64ISAR2_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_MMFR0_EL1, ID_AA64MMFR0_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_MMFR1_EL1, ID_AA64MMFR1_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_MMFR2_EL1, ID_AA64MMFR2_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_DFR0_EL1, ID_AA64DFR0_EL1_IDX }, + { HV_ARM64_REGISTER_ID_AA64_DFR1_EL1, ID_AA64DFR1_EL1_IDX }, + }; + + size_t n_regs =3D ARRAY_SIZE(regs); + hv_register_name *reg_names =3D g_new(hv_register_name, n_regs); + hv_register_value *reg_values =3D g_new(hv_register_value, n_regs); + + for (i =3D 0; i < n_regs; i++) { + reg_names[i] =3D regs[i].name; + } + + ret =3D mshv_get_partition_regs(vm_fd, reg_names, reg_values, n_regs); + + if (ret < 0) { + error_report("Failed to get host ID registers"); + success =3D false; + goto out; + } + + for (i =3D 0; i < n_regs; i++) { + ahcf->isar.idregs[regs[i].isar_idx] =3D reg_values[i].reg64; + } + + /* Read MIDR_EL1 from sysfs */ + if (g_file_get_contents( + "/sys/devices/system/cpu/cpu0/regs/identification/midr_el1", + &contents, NULL, NULL)) { + ahcf->midr =3D g_ascii_strtoull(contents, NULL, 0); + } else { + error_report("Failed to read MIDR_EL1 from sysfs"); + success =3D false; + goto out; + } + + ahcf->dtb_compatible =3D "arm,armv8"; + ahcf->features =3D (1ULL << ARM_FEATURE_V8) | + (1ULL << ARM_FEATURE_AARCH64) | + (1ULL << ARM_FEATURE_PMU) | + (1ULL << ARM_FEATURE_GENERIC_TIMER) | + (1ULL << ARM_FEATURE_NEON); + + clamp_id_aa64mmfr0_parange_to_ipa_size(mshv_fd, &ahcf->isar); + + /* + * SVE (Scalable Vector Extension) and SME (Scalable Matrix Extension) + * require specific context switch logic in the accelerator. + * Mask them out for now to ensure stability. + */ + /* Mask SVE in PFR0 */ + pfr0 =3D GET_IDREG(&ahcf->isar, ID_AA64PFR0); + pfr0 &=3D ~R_ID_AA64PFR0_SVE_MASK; + SET_IDREG(&ahcf->isar, ID_AA64PFR0, pfr0); + + /* Mask SME in PFR1 */ + pfr1 =3D GET_IDREG(&ahcf->isar, ID_AA64PFR1); + pfr1 &=3D ~R_ID_AA64PFR1_SME_MASK; + SET_IDREG(&ahcf->isar, ID_AA64PFR1, pfr1); + +out: + g_free(contents); + g_free(reg_names); + g_free(reg_values); + return success; +} + +void mshv_arm_set_cpu_features_from_host(ARMCPU *cpu) +{ + if (!arm_host_cpu_features.dtb_compatible) { + if (!mshv_enabled() || + !mshv_arm_get_host_cpu_features(&arm_host_cpu_features)) { + /* + * We can't report this error yet, so flag that we need to + * in arm_cpu_realizefn(). + */ + cpu->host_cpu_probe_failed =3D true; + return; + } + } + + cpu->dtb_compatible =3D arm_host_cpu_features.dtb_compatible; + cpu->isar =3D arm_host_cpu_features.isar; + cpu->env.features =3D arm_host_cpu_features.features; + cpu->midr =3D arm_host_cpu_features.midr; + cpu->reset_sctlr =3D arm_host_cpu_features.reset_sctlr; +} diff --git a/target/arm/mshv_arm.h b/target/arm/mshv_arm.h new file mode 100644 index 0000000000..a03f9a4405 --- /dev/null +++ b/target/arm/mshv_arm.h @@ -0,0 +1,18 @@ +/* + * QEMU MSHV support + * + * Copyright Microsoft, Corp. 2026 + * + * Authors: Aastha Rawat + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef QEMU_MSHV_ARM_H +#define QEMU_MSHV_ARM_H + +#include "target/arm/cpu.h" + +void mshv_arm_set_cpu_features_from_host(ARMCPU *cpu); + +#endif --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284176; cv=none; d=zohomail.com; s=zohoarc; b=g1GNAt2bE2mpzBci6ICEMNxX9imC9NU7ozNQ0Y4vJdNapzTGmGSHuiOyEAX/dRrwU9y1UoaZ/KuaX/DHqaa13yM8pqrjK4POFMP3SVzpIWel+a0k+dQ+AErzGHmkMwNILjPJ10A1k5VFQ1I/SetWcRgMFW/UichG5xDFyA7B804= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284176; h=Content-Type: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=1W+ro0UCqHdRyuUzYJclJi4PAuQ6lSvcECtz7ysd7aM=; b=UvyYLbT6ypLvdHKpA282x87K9rtlqOLfymZF7IHg8vp9xmjEnqmlVoAbRhIeePrO0jgd5xruIteMVOX8jNhPvQ8u0Aii3xDyGS0IZYN7GXJTSgqZiUMJoXTZyOOqA7n8jI9J3ZSCI9bimt1Xzzg9iIKmOhkEJQxAusy/GaRKw7U= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284176080228.02008948585183; Fri, 17 Jul 2026 03:29:36 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnB-0005qu-4d; Fri, 17 Jul 2026 06:27:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfn9-0005oY-3E; Fri, 17 Jul 2026 06:27:39 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn7-0000PE-67; Fri, 17 Jul 2026 06:27:38 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 2312520B7170; Fri, 17 Jul 2026 03:27:26 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 2312520B7170 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284046; bh=1W+ro0UCqHdRyuUzYJclJi4PAuQ6lSvcECtz7ysd7aM=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=Bh8h0Hb/zQLmyYkj/Igb17pISVuNmzoC2XUuc97Y7s1IIpefVC0ZV4scoVBQ9dMAm H1PnuLgQLsm+OkxTPym2gHrbt4w4MMVUjkgmlvLCSyXE6eMUHRScx6VTAT2hVG1IzG 7io+eYq5Wj1fDyOwmh6+2RmEW+KEQa4UzwSdoTRg= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:22 +0000 Subject: [PATCH v5 07/13] accel/mshv: Add access_vp_regs synthetic proc features MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-7-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284177294158500 Enable access_vp_regs feature for regs. In arm64, this feature bit allows the guest to set VP registers using hypercall. This wasn't required for x86 because such registers are set using wrmsr instead of hypercall. Signed-off-by: Aastha Rawat --- accel/mshv/mshv-all.c | 1 + include/hw/hyperv/hvhdk.h | 91 +++++++++++++++++++++++++++++++++++++++++++= +++- 2 files changed, 91 insertions(+), 1 deletion(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index 199b957a97..d11813c3fd 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -273,6 +273,7 @@ static int set_synthetic_proc_features(int vm_fd) features.tb_flush_hypercalls =3D 1; features.synthetic_cluster_ipi =3D 1; features.direct_synthetic_timers =3D 1; + features.access_vp_regs =3D 1; =20 mshv_arch_amend_proc_features(&features); =20 diff --git a/include/hw/hyperv/hvhdk.h b/include/hw/hyperv/hvhdk.h index 9e6dcb22f6..d0adbea0c7 100644 --- a/include/hw/hyperv/hvhdk.h +++ b/include/hw/hyperv/hvhdk.h @@ -94,11 +94,16 @@ union hv_partition_synthetic_processor_features { */ uint64_t access_partition_reference_tsc:1; =20 +#if defined(__x86_64__) + /* * Partition has access to the guest idle reg. Corresponds to * access_guest_idle_reg privilege. */ uint64_t access_guest_idle_reg:1; +#else + uint64_t reserved_z10:1; +#endif =20 /* * Partition has access to frequency regs. corresponds to @@ -110,11 +115,16 @@ union hv_partition_synthetic_processor_features { uint64_t reserved_z13:1; /* Reserved for access_root_scheduler_reg= */ uint64_t reserved_z14:1; /* Reserved for access_tsc_invariant_cont= rols */ =20 +#if defined(__x86_64__) + /* * Extended GVA ranges for HvCallFlushVirtualAddressList hypercall. * Corresponds to privilege. */ uint64_t enable_extended_gva_ranges_for_flush_virtual_address_list= :1; +#else + uint64_t reserved_z15:1; +#endif =20 uint64_t reserved_z16:1; /* Reserved for access_vsm. */ uint64_t reserved_z17:1; /* Reserved for access_vp_registers. */ @@ -161,13 +171,92 @@ union hv_partition_synthetic_processor_features { /* HvCallRetargetDeviceInterrupt is supported. */ uint64_t retarget_device_interrupt:1; =20 +#if defined(__x86_64__) /* HvCallRestorePartitionTime is supported. */ uint64_t restore_time:1; =20 /* EnlightenedVmcs nested enlightenment is supported. */ uint64_t enlightened_vmcs:1; =20 - uint64_t reserved:30; + uint64_t nested_debug_ctl:1; + uint64_t synthetic_time_unhalted_timer:1; + uint64_t idle_spec_ctrl:1; + +#else + uint64_t reserved_z31:1; + uint64_t reserved_z32:1; + uint64_t reserved_z33:1; + uint64_t reserved_z34:1; + uint64_t reserved_z35:1; +#endif + +#if defined(__aarch64__) + /* + * Register intercepts supported in V1. As more registers are supp= orted + * in future releases, new bits will be added here to prevent migr= ation + * between incompatible hosts. + * + * List of registers supported in V1: + * 1. TPIDRRO_EL0 + * 2. TPIDR_EL1 + * 3. SCTLR_EL1 - Supports write intercept mask. + * 4. VBAR_EL1 + * 5. TCR_EL1 - Supports write intercept mask. + * 6. MAIR_EL1 - Supports write intercept mask. + * 7. CPACR_EL1 - Supports write intercept mask. + * 8. CONTEXTIDR_EL1 + * 9. PAuth keys (total 10 registers) + * 10. HvArm64RegisterSyntheticException + */ + uint64_t register_intercepts_v1:1; +#else + uint64_t reserved_z36:1; +#endif + + /* HvCallWakeVps is supported */ + uint64_t wake_vps:1; + + /* + * HvCallGet/SetVpRegisters is supported. + * Corresponds to AccessVpRegisters privilege. + * This feature only affects exo partitions. + */ + uint64_t access_vp_regs:1; + +#if defined(__aarch64__) + /* HvCallSyncContext/Ex is supported. */ + uint64_t sync_context:1; +#else + uint64_t reserved_z39:1; +#endif /* __aarch64__ */ + + /* + * Management VTL synic support is allowed. + * Corresponds to the ManagementVtlSynicSupport privilege. + */ + uint64_t management_vtl_synic_support:1; + +#if defined(__x86_64__) + /* + * Hypervisor supports guest mechanism to signal pending interrupt= s to + * paravisor. + */ + uint64_t proxy_interrupt_doorbell_support:1; +#else + uint64_t reserved_z41:1; +#endif + +#if defined(__aarch64__) + /* InterceptSystemResetAvailable is exposed. */ + uint64_t intercept_system_reset:1; +#else + uint64_t reserved_z42:1; +#endif + + /* Hypercalls for host MMIO operations are available. */ + uint64_t mmio_hypercalls:1; + + uint64_t reserved:20; }; }; =20 --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284166; cv=none; d=zohomail.com; s=zohoarc; b=lF2JG5Tl3RfU+cq3iKTRLH3LImCET1/7JFTGA3Z75+QBLoCKmJM7zf4zlG5i77cTD8QRh/vthJ9DkChGWMqEt11xfEMPU2tQCX3zQlHKWvFVh7oTLSBm3OENFVyqknRU33W8Ov9jWmq/KaL3ylEzaGJiBx+3ufgVNv31k/IJ/CU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284166; h=Content-Type: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=D2z6HfHW2i2BA1K8lCMT6aQQNina22ihNIdgfmM8pWs=; b=MGrnE952Xw8QfKewpIgAYKLQ/DT8l0F7r4alXgXti2OUXFoprlaC2QHo90M8L0ul5IGus/71DGgyViGPqswGBzab1KTaN/sIlH6JQ7LzQxtCeJHolMSEHi+4E9+n6t0FFe6XWwduzoWrbqOkIEBk8EAyroM/YL+Xv91OJq1XCdY= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284166897363.17013826955406; Fri, 17 Jul 2026 03:29:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnC-0005rX-2l; Fri, 17 Jul 2026 06:27:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfnA-0005pY-7W; Fri, 17 Jul 2026 06:27:40 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn8-0000Pn-L7; Fri, 17 Jul 2026 06:27:39 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id B5EB620B7172; Fri, 17 Jul 2026 03:27:26 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B5EB620B7172 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284046; bh=D2z6HfHW2i2BA1K8lCMT6aQQNina22ihNIdgfmM8pWs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aKkcmuP3fMl6gXS87KW7HzayoVVHKMpZ0BhJCjPtkkKHYH1eBVJHiJkle0mBAppff JGDu2IuCwktwxkQii03s04m92ZFacYfiGXRUa9dncgLnNNxfGokEynHLkCLnhHiKIu FrkuLqFgQxrBtH+iRRIsTvfwUWubzfopTf2Gp3vQ= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:23 +0000 Subject: [PATCH v5 08/13] target/arm: cpu: Mark MSHV supporting PSCI 1.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-8-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284169350158500 MSHV supports PSCI 1.3. Expose this version to guests. Signed-off-by: Aastha Rawat Reviewed-by: Mohamed Mediouni --- target/arm/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index c5037a145a..95682ef067 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1293,7 +1293,7 @@ static void arm_cpu_initfn(Object *obj) if (tcg_enabled() || hvf_enabled()) { /* TCG and HVF implement PSCI 1.1 */ cpu->psci_version =3D QEMU_PSCI_VERSION_1_1; - } else if (whpx_enabled()) { + } else if (whpx_enabled() || mshv_enabled()) { cpu->psci_version =3D QEMU_PSCI_VERSION_1_3; } } --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284098; cv=none; d=zohomail.com; s=zohoarc; b=N0J96/mT5q6KxcpunfNZD1xgrwg3/jyC9px9EoozWRZqj8vUi31LMRUrG1+ZctG2r+fIdexcuXj9gMhbhtXx4gPtb7sRoLXtwrK1eaaYrG4vbcnKGIeyr7gjbR1TKDOkeMcG84Rq6+QDVsfLHyupMEO7yCPcT0xNvjM8jLRInYI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284098; h=Content-Type: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=pTqGJEaZ9/ObWB7n2HbApC+4GS+iSa53rIJA4gZX+B0=; b=Pm2QTsU5pbcmFoNdlc3eGJRg2TdERdBYEHSo/QEiXYxMK6+FrSMZLYW6a3mbRQDpgm4Cir835JHb/RY/dfIId+8qdtaFwRznreYS1jjXpAyWkUKrJfFB1bYlr1TE6LPMQU3FaspZMmFyZ/xvHDgFP4urS+Lmki7WYyp/z0eFBog= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284098599170.443704923121; Fri, 17 Jul 2026 03:28:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnD-0005ri-EX; Fri, 17 Jul 2026 06:27:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfnA-0005qb-PB; Fri, 17 Jul 2026 06:27:40 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfn8-0000Pi-Ih; Fri, 17 Jul 2026 06:27:40 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 3D95C20B7175; Fri, 17 Jul 2026 03:27:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3D95C20B7175 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284047; bh=pTqGJEaZ9/ObWB7n2HbApC+4GS+iSa53rIJA4gZX+B0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=FyL70rEgftpVzKrcHb3l0FaREoyvkevm8qiguMMqF9iPT21q5IQ6s6m8WxvBPpKcE yEjXNdMP2dLHMafLgAAa1FOO0UvhFnbn/8v4fvSJBEcbFDF3CyMngdYE6MMrgJBVt9 MMNn7jemJ1uIzzgodunX7Fzt1DknCTJPLaC936tI= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:24 +0000 Subject: [PATCH v5 09/13] target/arm: extract MMIO emulation logic for HVF & WHPX MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-9-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284101493158500 - Move common MMIO emulation code from HVF and WHPX backend to arm_emulate_mmio() in helper.c. - Update HVF and WHPX to use the new helper and shared types. Signed-off-by: Aastha Rawat --- target/arm/helper.c | 62 ++++++++++++++++++++++++++++++++++++++++++= ++++ target/arm/helper.h | 16 ++++++++++++ target/arm/hvf/hvf.c | 57 +++++++++++++++++++----------------------- target/arm/syndrome.h | 47 +++++++++++++++++++++++++++++++++++ target/arm/whpx/whpx-all.c | 45 ++++++++++++++------------------- 5 files changed, 169 insertions(+), 58 deletions(-) diff --git a/target/arm/helper.c b/target/arm/helper.c index af45234ad2..43268fa02c 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -34,6 +34,8 @@ #endif #include "cpregs.h" #include "target/arm/gtimer.h" +#include "target/arm/helper.h" +#include "target/arm/syndrome.h" #include "qemu/plugin.h" =20 static void switch_mode(CPUARMState *env, int mode); @@ -9228,6 +9230,66 @@ static void arm_cpu_do_interrupt_aarch32(CPUState *c= s) take_aarch32_exception(env, new_mode, mask, offset, addr); } =20 +/* + * Emulate a data abort syndrome for MMIO/guest memory access + */ +int arm_emulate_mmio(CPUState *cpu, EsrEl2 syndrome, uint64_t gpa, + const struct arm_emul_ops *ops) +{ + int ret; + IssDataAbort iss =3D { 0 }; + iss.raw =3D syndrome.iss; + + if (!(syndrome.ec =3D=3D data_abort_lower || syndrome.ec =3D=3D data_a= bort)) { + error_report("Unknown exception class 0x%x", syndrome.ec); + return -1; + } + + if (!iss.isv) { + error_report("Cannot emulate MMIO. ISS not valid."); + return -1; + } + + AddressSpace *as =3D cpu_get_address_space(cpu, ARMASIdx_NS); + uint64_t len =3D 1ULL << iss.sas; + bool sign_extend =3D iss.sse; + uint64_t reg_index =3D iss.srt; + + if (iss.wnr) { + uint8_t data[8]; + uint64_t val =3D reg_index < 31 ? ops->get_reg(cpu, reg_index) : 0= ULL; + val =3D cpu_to_le64(val); + memcpy(data, &val, sizeof(val)); + ret =3D address_space_write(as, gpa, MEMTXATTRS_UNSPECIFIED, data,= len); + if (ret !=3D MEMTX_OK) { + error_report("Failed to write guest memory"); + return -1; + } + } else { + uint8_t data[8] =3D { 0 }; + ret =3D address_space_read(as, gpa, MEMTXATTRS_UNSPECIFIED, data, = len); + if (ret !=3D MEMTX_OK) { + error_report("Failed to read guest memory"); + return -1; + } + uint64_t val; + memcpy(&val, data, sizeof(val)); + val =3D le64_to_cpu(val); + if (sign_extend) { + uint64_t shift =3D 64 - (len * 8); + val =3D (((int64_t)val << shift) >> shift); + } + if (!iss.sf) { + val &=3D 0xffffffff; + } + if (reg_index < 31) { + ops->set_reg(cpu, reg_index, val); + } + } + + return 0; +} + static int aarch64_regnum(CPUARMState *env, int aarch32_reg) { /* diff --git a/target/arm/helper.h b/target/arm/helper.h index b1c26c180e..503404112d 100644 --- a/target/arm/helper.h +++ b/target/arm/helper.h @@ -3,8 +3,24 @@ #ifndef HELPER__H #define HELPER__H =20 +#include +#include #include "exec/helper-proto-common.h" #include "exec/helper-gen-common.h" +#include "target/arm/syndrome.h" + +/* + * Callback ops for per-register access during MMIO emulation. + * Each hypervisor backend provides its own implementation to avoid + * syncing the full CPU state for a single-register MMIO access. + */ +struct arm_emul_ops { + uint64_t (*get_reg)(CPUState *cpu, int reg); + void (*set_reg)(CPUState *cpu, int reg, uint64_t val); +}; + +int arm_emulate_mmio(CPUState *cpu, EsrEl2 syndrome, uint64_t gpa, + const struct arm_emul_ops *ops); =20 #define HELPER_H "tcg/helper-defs.h" #include "exec/helper-proto.h.inc" diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c index da3ec521fc..1dd8252fe4 100644 --- a/target/arm/hvf/hvf.c +++ b/target/arm/hvf/hvf.c @@ -13,6 +13,7 @@ #include "qemu/error-report.h" #include "qemu/log.h" =20 +#include "syndrome.h" #include "system/runstate.h" #include "system/hvf.h" #include "system/hvf_int.h" @@ -37,6 +38,7 @@ #include "target/arm/multiprocessing.h" #include "target/arm/gtimer.h" #include "target/arm/trace.h" +#include "target/arm/helper.h" #include "trace.h" #include "migration/vmstate.h" =20 @@ -2328,12 +2330,15 @@ static int hvf_handle_exception(CPUState *cpu, hv_v= cpu_exit_exception_t *excp) { CPUARMState *env =3D cpu_env(cpu); ARMCPU *arm_cpu =3D env_archcpu(env); - uint64_t syndrome =3D excp->syndrome; - uint32_t ec =3D syn_get_ec(syndrome); + uint64_t syndrome; + uint32_t ec; bool advance_pc =3D false; hv_return_t r; int ret =3D 0; =20 + syndrome =3D excp->syndrome; + ec =3D syn_get_ec(syndrome); + switch (ec) { case EC_SOFTWARESTEP: { ret =3D EXCP_DEBUG; @@ -2379,29 +2384,22 @@ static int hvf_handle_exception(CPUState *cpu, hv_v= cpu_exit_exception_t *excp) break; } case EC_DATAABORT: { - bool isv =3D FIELD_EX32(syndrome, DABORT_ISS, ISV); - bool iswrite =3D FIELD_EX32(syndrome, DABORT_ISS, WNR); - bool s1ptw =3D FIELD_EX32(syndrome, DABORT_ISS, S1PTW); - bool sse =3D FIELD_EX32(syndrome, DABORT_ISS, SSE); - uint32_t sas =3D FIELD_EX32(syndrome, DABORT_ISS, SAS); - uint32_t len =3D 1 << sas; - uint32_t srt =3D FIELD_EX32(syndrome, DABORT_ISS, SRT); - uint32_t cm =3D FIELD_EX32(syndrome, DABORT_ISS, CM); - uint64_t val =3D 0; + EsrEl2 esr_el2 =3D { .raw =3D syndrome }; + IssDataAbort iss =3D { .raw =3D esr_el2.iss }; uint64_t ipa =3D excp->physical_address; AddressSpace *as =3D cpu_get_address_space(cpu, ARMASIdx_NS); =20 - trace_hvf_data_abort(excp->virtual_address, ipa, isv, - iswrite, s1ptw, len, srt); + trace_hvf_data_abort(excp->virtual_address, ipa, iss.isv, + iss.wnr, iss.s1ptw, 1ULL << iss.sas, iss.srt); =20 - if (cm) { + if (iss.cm) { /* We don't cache MMIO regions */ advance_pc =3D true; break; } =20 /* Handle dirty page logging for ram. */ - if (iswrite) { + if (iss.wnr) { hwaddr xlat; MemoryRegion *mr =3D address_space_translate(as, ipa, &xlat, NULL, true, @@ -2428,28 +2426,25 @@ static int hvf_handle_exception(CPUState *cpu, hv_v= cpu_exit_exception_t *excp) * TODO: If s1ptw, this is an error in the guest os page tables. * Inject the exception into the guest. */ - assert(!s1ptw); - - /* - * TODO: ISV will be 0 for SIMD or SVE accesses. - * Inject the exception into the guest. - */ - assert(isv); + assert(!iss.s1ptw); =20 /* * Emulate MMIO. * TODO: Inject faults for errors. */ - if (iswrite) { - val =3D hvf_get_reg(cpu, srt); - address_space_write(as, ipa, MEMTXATTRS_UNSPECIFIED, &val, len= ); - } else { - address_space_read(as, ipa, MEMTXATTRS_UNSPECIFIED, &val, len); - if (sse) { - val =3D sextract64(val, 0, len * 8); - } - hvf_set_reg(cpu, srt, val); + + static const struct arm_emul_ops hvf_arm_emul_ops =3D { + .get_reg =3D hvf_get_reg, + .set_reg =3D hvf_set_reg, + }; + + ret =3D arm_emulate_mmio(cpu, esr_el2, ipa, &hvf_arm_emul_ops); + if (ret < 0) { + error_report("Failed to emulate MMIO, syndrome=3D0x%llx, gpa= =3D0x%llx", + esr_el2.raw, ipa); + return -1; } + advance_pc =3D true; break; } diff --git a/target/arm/syndrome.h b/target/arm/syndrome.h index 2a6fa903f2..8b4cc7f7b2 100644 --- a/target/arm/syndrome.h +++ b/target/arm/syndrome.h @@ -106,6 +106,53 @@ typedef enum { GCS_IT_GCSPOPX =3D 9, } GCSInstructionType; =20 +typedef union { + uint64_t raw; + struct { + uint32_t iss:25; + uint32_t il:1; + uint32_t ec:6; + uint32_t iss2:5; + uint32_t _rsvd:27; + } QEMU_PACKED; +} EsrEl2; + +typedef union { + uint32_t raw; + struct { + uint32_t dfsc:6; + uint32_t wnr:1; + uint32_t s1ptw:1; + uint32_t cm:1; + uint32_t ea:1; + uint32_t fnv:1; + uint32_t set:2; + uint32_t vncr:1; + uint32_t ar:1; + uint32_t sf:1; + uint32_t srt:5; + uint32_t sse:1; + uint32_t sas:2; + uint32_t isv:1; + uint32_t _unused:7; + } QEMU_PACKED; +} IssDataAbort; + +typedef enum { + data_abort_lower =3D 36, + data_abort =3D 37, +} ExceptionClass; + +#define ARM_EL_EC_LENGTH 6 +#define ARM_EL_EC_SHIFT 26 +#define ARM_EL_IL_SHIFT 25 +#define ARM_EL_ISV_SHIFT 24 +#define ARM_EL_IL (1 << ARM_EL_IL_SHIFT) +#define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT) + +/* In the Data Abort syndrome */ +#define ARM_EL_VNCR (1 << 13) + static inline uint32_t syn_get_ec(uint32_t syn) { return FIELD_EX32(syn, SYNDROME, EC); diff --git a/target/arm/whpx/whpx-all.c b/target/arm/whpx/whpx-all.c index 00a5de8cdc..4c14382de8 100644 --- a/target/arm/whpx/whpx-all.c +++ b/target/arm/whpx/whpx-all.c @@ -28,6 +28,8 @@ =20 #include "syndrome.h" #include "target/arm/cpregs.h" +#include "target/arm/helper.h" +#include "target/arm/syndrome.h" #include "internals.h" =20 #include "system/whpx-internal.h" @@ -349,34 +351,23 @@ static void whpx_set_gp_reg(CPUState *cpu, int rt, ui= nt64_t val) =20 static int whpx_handle_mmio(CPUState *cpu, WHV_MEMORY_ACCESS_CONTEXT *ctx) { - uint64_t syndrome =3D ctx->Syndrome; - - bool isv =3D FIELD_EX32(syndrome, DABORT_ISS, ISV); - bool iswrite =3D FIELD_EX32(syndrome, DABORT_ISS, WNR); - bool sse =3D FIELD_EX32(syndrome, DABORT_ISS, SSE); - uint32_t sas =3D FIELD_EX32(syndrome, DABORT_ISS, SAS); - uint32_t len =3D 1 << sas; - uint32_t srt =3D FIELD_EX32(syndrome, DABORT_ISS, SRT); - uint32_t cm =3D FIELD_EX32(syndrome, DABORT_ISS, CM); - uint64_t val =3D 0; - - assert(syn_get_ec(syndrome) =3D=3D EC_DATAABORT); + int ret =3D 0; + EsrEl2 esr =3D { .raw =3D ctx->Syndrome }; + uint32_t cm =3D (esr.iss >> 8) & 0x1; + + assert(syn_get_ec(esr.raw) =3D=3D EC_DATAABORT); assert(!cm); - assert(isv); - - if (iswrite) { - val =3D whpx_get_gp_reg(cpu, srt); - address_space_write(&address_space_memory, - ctx->Gpa, - MEMTXATTRS_UNSPECIFIED, &val, len); - } else { - address_space_read(&address_space_memory, - ctx->Gpa, - MEMTXATTRS_UNSPECIFIED, &val, len); - if (sse) { - val =3D sextract64(val, 0, len * 8); - } - whpx_set_gp_reg(cpu, srt, val); + + static const struct arm_emul_ops whpx_arm_emul_ops =3D { + .get_reg =3D whpx_get_gp_reg, + .set_reg =3D whpx_set_gp_reg, + }; + + ret =3D arm_emulate_mmio(cpu, esr, ctx->Gpa, &whpx_arm_emul_ops); + if (ret < 0) { + error_report("WHPX: Failed to handle MMIO, syndrome=3D0x%llx, gpa= =3D0x%llx", + esr.raw, ctx->Gpa); + return -1; } =20 return 0; --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284098; cv=none; d=zohomail.com; s=zohoarc; b=Hc8BxEmL+zkNOaJ90hQAdsddozR5Y4uHmb0lh6exiokNcJHN9cKxLSxq1/yGMiblEsc4tsuezSXHZvnbO4JudWQHKWAfDER+NM3xRSsVZmG0DdWW5SCF0T5vkLqFMfoB7qd37NkkfhlJzu5r1sT50InxQykKMMZv6l7QhwdWZ+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284098; h=Content-Type: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=OGGpowXvVwpFoT6iKc2B4BLya9B2Y4TG8FXlisamEn0=; b=e0CHatUYAdTMODEZFJNnHx6lryZwaGiQhuhH6d4P44tVfrMU/paLMzwRPAR/0jw2FXt0KchUBHXEqN+TiS6duEv6AnYQCqjaV0VgZ5svS7x7XmpiWZ8KiFNQle78PDPf1bJNkms3+CT8YKJob2zHfdCspsfZo26xA1gSgCx7Qto= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17842840985361012.3130444364497; Fri, 17 Jul 2026 03:28:18 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnX-0005wV-7Q; Fri, 17 Jul 2026 06:28:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfnU-0005vv-UW; Fri, 17 Jul 2026 06:28:01 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnT-0000P7-8I; Fri, 17 Jul 2026 06:28:00 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 3122720B7178; Fri, 17 Jul 2026 03:27:28 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3122720B7178 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284048; bh=OGGpowXvVwpFoT6iKc2B4BLya9B2Y4TG8FXlisamEn0=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=VupK1EmAmw/GnlsuwxHsCLLaHjJZmEKhHf1NLtotrs/ZaXsikPdT5rupRWAUg5FUm lHF1kT2JDHBZcJD2vdUXMIcacPrf3SdpbX+kZy7UcSc5Mr6rGoMAxtsSt1D7MKHqNO C6Qm7hJhf4TjyCMPZ5mqI459H31TTnP4dQxI8or4= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:25 +0000 Subject: [PATCH v5 10/13] target/arm/mshv: add vCPU run loop MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-10-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284101555158500 From: "Anirudh Rayabharam (Microsoft)" Add the main vCPU run loop for MSHV using the MSHV_RUN_VP_IOCTL. Handle MMIO exits by emulating the instruction using the syndrome information from ESR_EL2. Signed-off-by: Anirudh Rayabharam (Microsoft) --- include/hw/hyperv/hvgdk_mini.h | 44 +++++++++++++++++ target/arm/mshv/mshv-all.c | 107 +++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 151 insertions(+) diff --git a/include/hw/hyperv/hvgdk_mini.h b/include/hw/hyperv/hvgdk_mini.h index fc014aa5d7..63f05b01a6 100644 --- a/include/hw/hyperv/hvgdk_mini.h +++ b/include/hw/hyperv/hvgdk_mini.h @@ -892,6 +892,50 @@ struct hv_x64_memory_intercept_message { uint8_t instruction_bytes[16]; } QEMU_PACKED; =20 +union hv_arm64_vp_execution_state { + uint16_t as_uint16; + struct { + uint16_t cpl:2; + uint16_t debug_active:1; + uint16_t interruption_pending:1; + uint16_t vtl:4; + uint16_t virtualization_fault_active:1; + uint16_t reserved:7; + }; +}; + +struct hv_arm64_intercept_message_header { + uint32_t vp_index; + uint8_t instruction_length; + uint8_t intercept_access_type; + union hv_arm64_vp_execution_state execution_state; + uint64_t pc; + uint64_t cpsr; +}; + +union hv_arm64_memory_access_info { + uint8_t as_uint8; + struct { + uint8_t gva_valid:1; + uint8_t gva_gpa_valid:1; + uint8_t hypercall_output_pending:1; + uint8_t reserved:5; + }; +}; + +struct hv_arm64_memory_intercept_message { + struct hv_arm64_intercept_message_header header; + uint32_t cache_type; /* enum hv_cache_type */ + uint8_t instruction_byte_count; + union hv_arm64_memory_access_info memory_access_info; + uint16_t reserved1; + uint8_t instruction_bytes[4]; + uint32_t reserved2; + uint64_t guest_virtual_address; + uint64_t guest_physical_address; + uint64_t syndrome; +}; + union hv_message_flags { uint8_t asu8; struct { diff --git a/target/arm/mshv/mshv-all.c b/target/arm/mshv/mshv-all.c index da43333aa6..6ec9811258 100644 --- a/target/arm/mshv/mshv-all.c +++ b/target/arm/mshv/mshv-all.c @@ -20,6 +20,7 @@ #include "target/arm/cpu.h" #include "target/arm/internals.h" #include "target/arm/mshv_arm.h" +#include "target/arm/helper.h" =20 #include "system/mshv.h" #include "system/mshv_int.h" @@ -158,8 +159,114 @@ int mshv_arch_store_vcpu_state(const CPUState *cpu) return store_regs(cpu); } =20 +static int set_memory_info(const struct hyperv_message *msg, + struct hv_arm64_memory_intercept_message *info) +{ + if (msg->header.message_type !=3D HVMSG_GPA_INTERCEPT + && msg->header.message_type !=3D HVMSG_UNMAPPED_GPA + && msg->header.message_type !=3D HVMSG_UNACCEPTED_GPA) { + error_report("invalid message type"); + return -1; + } + memcpy(info, msg->payload, sizeof(*info)); + + return 0; +} + +static uint64_t mshv_mmio_get_reg(CPUState *cpu, int reg_index) +{ + ARMCPU *arm_cpu =3D ARM_CPU(cpu); + CPUARMState *env =3D &arm_cpu->env; + return reg_index < 31 ? env->xregs[reg_index] : 0ULL; +} + +static void mshv_mmio_set_reg(CPUState *cpu, int reg_index, uint64_t val) +{ + ARMCPU *arm_cpu =3D ARM_CPU(cpu); + CPUARMState *env =3D &arm_cpu->env; + if (reg_index < 31) { + env->xregs[reg_index] =3D val; + } +} + +static int handle_unmapped_mem(int vm_fd, CPUState *cpu, + const struct hyperv_message *msg, + MshvVmExit *exit_reason) +{ + ARMCPU *arm_cpu =3D ARM_CPU(cpu); + CPUARMState *env =3D &arm_cpu->env; + struct hv_arm64_memory_intercept_message info =3D { 0 }; + int ret; + EsrEl2 syndrome; + + ret =3D set_memory_info(msg, &info); + if (ret < 0) { + error_report("failed to convert message to memory info"); + return -1; + } + + syndrome.raw =3D info.syndrome; + + ret =3D load_regs(cpu); + if (ret < 0) { + error_report("Failed to load registers"); + return -1; + } + + static const struct arm_emul_ops mshv_arm_emul_ops =3D { + .get_reg =3D mshv_mmio_get_reg, + .set_reg =3D mshv_mmio_set_reg, + }; + + ret =3D arm_emulate_mmio(cpu, syndrome, info.guest_physical_address, + &mshv_arm_emul_ops); + if (ret < 0) { + error_report("Failed to emulate with syndrome"); + return -1; + } + + /* Advance PC past the faulting instruction */ + env->pc +=3D (syndrome.il =3D=3D 1) ? 4 : 2; + + ret =3D store_regs(cpu); + if (ret < 0) { + error_report("Failed to store registers"); + return -1; + } + + *exit_reason =3D MshvVmExitIgnore; + + return 0; +} + int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *e= xit) { + int ret; + int cpu_fd =3D mshv_vcpufd(cpu); + + ret =3D ioctl(cpu_fd, MSHV_RUN_VP, msg); + if (ret < 0) { + *exit =3D MshvVmExitShutdown; + return ret; + } + + switch (msg->header.message_type) { + case HVMSG_UNRECOVERABLE_EXCEPTION: + *exit =3D MshvVmExitShutdown; + break; + case HVMSG_GPA_INTERCEPT: + case HVMSG_UNMAPPED_GPA: + ret =3D handle_unmapped_mem(vm_fd, cpu, msg, exit); + if (ret < 0) { + error_report("failed to handle mmio"); + return -1; + } + break; + default: + error_report("Unhandled message type: 0x%x", msg->header.message_t= ype); + return -1; + } + return 0; } =20 --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284185; cv=none; d=zohomail.com; s=zohoarc; b=kZhSwDLFA7t5K+Spv+fEt3EWfnh9xpYeSiOO3WTZXNZilVcr9/lhf0g18JKDD75oAD4tki70StTI6ay7toseWOeJE1NsVuP/2ySzkaJQ7lHPnrwlSyOW7tbR7QAtkVR+GeRkR0BTc9V8U1d17PYl4jLc9H+G/k0xe8NZ8OXbZEI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284185; h=Content-Type: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=1QK2Ff6clHlkv6KcKYafk1otzjUG6SIl3BFetAKCNvY=; b=jKQR/1ORUnTaoplGTkoQy2y0x865baoV1qF9e0gRPCExz8kP+cBp5iqE9BdEI7V/gbR3WTZSu8HzY9nLpp8yfS6LaWWJgHR6S9fqqRGXi23XPyBTql16CGOqSKejicKMnXlSltnAvfJdHokPrJtTemHlZSsp1YlPBSu41b2xdUQ= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284185803482.7295185025024; Fri, 17 Jul 2026 03:29:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnZ-0005zD-MI; Fri, 17 Jul 2026 06:28:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfnW-0005w7-52; Fri, 17 Jul 2026 06:28:02 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnU-0000PE-0m; Fri, 17 Jul 2026 06:28:01 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id DD6B920B7179; Fri, 17 Jul 2026 03:27:28 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DD6B920B7179 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284048; bh=1QK2Ff6clHlkv6KcKYafk1otzjUG6SIl3BFetAKCNvY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=IIwFdt50j6yqR9dkvRL0n+3xPhMP7UG5NfHDsPj1itqnK56GJvtd5gTUF/nRet+iz wA7FAV2D2EwiKxJMMP4gwYSIVxmmOPHOnlK2Sbt3ItyGsvSTRaHx7yI9SMfEbzIt7R qdkss4YEeNGmOprXNYweSSF4vXt5ewgVshB9TzFc= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:26 +0000 Subject: [PATCH v5 11/13] include/hw/hyperv: adjust hv_interrupt_control structure for arm64 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-11-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284187476158500 From: "Anirudh Rayabharam (Microsoft)" Add the arm64 specific fields to the hv_interrupt_control struct and adjust the existing usage accordingly. mshv_request_interrupt is only needed only for x86 so compile it out entirely for arm64. Signed-off-by: Anirudh Rayabharam (Microsoft) --- accel/mshv/irq.c | 2 ++ include/hw/hyperv/hvgdk_mini.h | 24 ++++++++++++++++++++++++ include/system/mshv.h | 2 ++ 3 files changed, 28 insertions(+) diff --git a/accel/mshv/irq.c b/accel/mshv/irq.c index 4828ac51ac..f18e6a0f66 100644 --- a/accel/mshv/irq.c +++ b/accel/mshv/irq.c @@ -259,6 +259,7 @@ int mshv_irqchip_update_msi_route(int virq, MSIMessage = msg, PCIDevice *dev) return 0; } =20 +#if defined(__x86_64__) int mshv_request_interrupt(MshvState *mshv_state, uint32_t interrupt_type,= uint32_t vector, uint32_t vp_index, bool logical_dest_mode, bool level_triggered) @@ -295,6 +296,7 @@ int mshv_request_interrupt(MshvState *mshv_state, uint3= 2_t interrupt_type, uint3 } return 0; } +#endif =20 void mshv_irqchip_commit_routes(MshvState *s) { diff --git a/include/hw/hyperv/hvgdk_mini.h b/include/hw/hyperv/hvgdk_mini.h index 63f05b01a6..477898d919 100644 --- a/include/hw/hyperv/hvgdk_mini.h +++ b/include/hw/hyperv/hvgdk_mini.h @@ -539,14 +539,38 @@ typedef struct hv_input_set_vp_registers { } QEMU_PACKED hv_input_set_vp_registers; =20 #define MSHV_VP_MAX_REGISTERS 128 +enum hv_interrupt_type { +#if defined(__x86_64__) + HV_X64_INTERRUPT_TYPE_FIXED =3D 0x0000, + HV_X64_INTERRUPT_TYPE_LOWESTPRIORITY =3D 0x0001, + HV_X64_INTERRUPT_TYPE_SMI =3D 0x0002, + HV_X64_INTERRUPT_TYPE_REMOTEREAD =3D 0x0003, + HV_X64_INTERRUPT_TYPE_NMI =3D 0x0004, + HV_X64_INTERRUPT_TYPE_INIT =3D 0x0005, + HV_X64_INTERRUPT_TYPE_SIPI =3D 0x0006, + HV_X64_INTERRUPT_TYPE_EXTINT =3D 0x0007, + HV_X64_INTERRUPT_TYPE_LOCALINT0 =3D 0x0008, + HV_X64_INTERRUPT_TYPE_LOCALINT1 =3D 0x0009, + HV_X64_INTERRUPT_TYPE_MAXIMUM =3D 0x000A, +#elif defined(__aarch64__) + HV_ARM64_INTERRUPT_TYPE_FIXED =3D 0x0000, + HV_ARM64_INTERRUPT_TYPE_MAXIMUM =3D 0x0008, +#endif +}; =20 union hv_interrupt_control { uint64_t as_uint64; struct { uint32_t interrupt_type; /* enum hv_interrupt type */ +#if defined(__x86_64__) uint32_t level_triggered:1; uint32_t logical_dest_mode:1; uint32_t rsvd:30; +#elif defined(__aarch64__) + uint32_t rsvd1:2; + uint32_t asserted:1; + uint32_t rsvd2:29; +#endif }; }; =20 diff --git a/include/system/mshv.h b/include/system/mshv.h index 46fe3fcebc..6e20b32247 100644 --- a/include/system/mshv.h +++ b/include/system/mshv.h @@ -55,10 +55,12 @@ DECLARE_INSTANCE_CHECKER(MshvState, MSHV_STATE, =20 extern MshvState *mshv_state; =20 +#if defined(__x86_64__) /* interrupt */ int mshv_request_interrupt(MshvState *mshv_state, uint32_t interrupt_type,= uint32_t vector, uint32_t vp_index, bool logical_destination_mod= e, bool level_triggered); +#endif =20 int mshv_irqchip_add_msi_route(AccelRouteChange *c, int vector, PCIDevice = *dev); int mshv_irqchip_update_msi_route(int virq, MSIMessage msg, PCIDevice *dev= ); --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284137; cv=none; d=zohomail.com; s=zohoarc; b=hYAp9JxBOcZna6J+rKfWb9o4qoVFwKRX5nFKhxiQUHiuW4nQ1S1GQrl7OQpOIaeBGA13FHLeK4cZUE5GSfWyua4+siADhZElCTj3RHuPFUXhaowLh0Am4YudgnRAGvLsLfM3BP2ocgk2XpWeJPDDwsA8dVrqXuZDxN9ncdxHmXI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284137; h=Content-Type: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=xpVwt2nQwr+w4St6ziuxSFk9h+UoM6GCLdtYdWoEt7g=; b=EQFmvtsaEdR9rEg34B3UTDo+nj/G7RJbp6iMsoyuiNr/mHfffp++3fH3qS9DP8v3EVlExsGrwE284RAgNFH7ubUzgMt3h782uAJXeYg4SUbceQUFq7nTISmkoSeD9zblxZ5HH7wYVH3xt7GQtysO93NEsc7hmFCfblCf+OsCInQ= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1784284137209763.2227764185204; Fri, 17 Jul 2026 03:28:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnY-0005yC-Uv; Fri, 17 Jul 2026 06:28:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfnX-0005x6-Lg; Fri, 17 Jul 2026 06:28:03 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnV-0000P5-7t; Fri, 17 Jul 2026 06:28:03 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 73C2C20B717A; Fri, 17 Jul 2026 03:27:29 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 73C2C20B717A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284049; bh=xpVwt2nQwr+w4St6ziuxSFk9h+UoM6GCLdtYdWoEt7g=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=AmBM9e6KRPGpglZ5xn0mBAeb4oTPf6uy80BaDYfqB0VHPdIx/SwJ+9ykneWPGjCzQ 1LbKHQs+pmRXuiYQbYpL6irhIhBFeEx5u/94L0QXH8VoYVRBegLD/74ucfY5eKDc52 Um3TmKv+dHuOXmC3JKSZXunPQGfwh2a4QgHQpVDM= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:27 +0000 Subject: [PATCH v5 12/13] hw/intc,target/arm/mshv: add MSHV vGICv3 implementation MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-12-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284139375158500 From: "Anirudh Rayabharam (Microsoft)" Add in-kernel GICv3 support for the MSHV accelerator, following the same approach as the KVM and WHPX vGIC backends. The implementation handles IRQ injection via the HVCALL_ASSERT_VIRTUAL_INTERRUPT hypercall. Introduce mshv_arch_pre_init_vm(), an arch-specific hook called after VM creation but before VM initialization, used on arm64 to configure GIC partition properties (GICD base, ITS translater base, timer and PMU PPI numbers). The x86 side provides a no-op stub. Update the virt machine to treat MSHV like WHPX for GIC version selection (GICv3 only) and MSI controller finalization (no ITS support). Signed-off-by: Anirudh Rayabharam (Microsoft) --- accel/mshv/mshv-all.c | 5 + hw/arm/virt.c | 8 +- hw/intc/arm_gicv3_common.c | 3 + hw/intc/arm_gicv3_mshv.c | 181 +++++++++++++++++++++++++++++++++= ++++ hw/intc/meson.build | 1 + include/hw/hyperv/hvgdk_mini.h | 2 + include/hw/hyperv/hvhdk_mini.h | 6 ++ include/hw/intc/arm_gicv3_common.h | 1 + include/system/mshv_int.h | 1 + target/arm/mshv/mshv-all.c | 61 +++++++++++++ target/i386/mshv/mshv-all.c | 5 + 11 files changed, 272 insertions(+), 2 deletions(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index d11813c3fd..e093f05c54 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -317,6 +317,11 @@ static int create_vm(int mshv_fd, int *vm_fd) return -1; } =20 + ret =3D mshv_arch_pre_init_vm(*vm_fd); + if (ret < 0) { + return -1; + } + ret =3D initialize_vm(*vm_fd); if (ret < 0) { return -1; diff --git a/hw/arm/virt.c b/hw/arm/virt.c index 438bd408ba..4323309450 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2713,7 +2713,7 @@ static void finalize_gic_version(VirtMachineState *vm= s) /* KVM w/o kernel irqchip can only deal with GICv2 */ gics_supported |=3D VIRT_GIC_VERSION_2_MASK; accel_name =3D "KVM with kernel-irqchip=3Doff"; - } else if (whpx_enabled()) { + } else if (whpx_enabled() || mshv_enabled()) { gics_supported |=3D VIRT_GIC_VERSION_3_MASK; } else if (hvf_enabled()) { if (!hvf_irqchip_in_kernel()) { @@ -2767,7 +2767,7 @@ static void finalize_msi_controller(VirtMachineState = *vms) if (vms->msi_controller =3D=3D VIRT_MSI_CTRL_AUTO) { if (vms->gic_version =3D=3D VIRT_GIC_VERSION_2) { vms->msi_controller =3D VIRT_MSI_CTRL_GICV2M; - } else if (whpx_enabled()) { + } else if (whpx_enabled() || mshv_enabled()) { vms->msi_controller =3D VIRT_MSI_CTRL_GICV2M; } else if (hvf_enabled() && hvf_irqchip_in_kernel()) { vms->msi_controller =3D VIRT_MSI_CTRL_GICV2M; @@ -2797,6 +2797,10 @@ static void finalize_msi_controller(VirtMachineState= *vms) error_report("ITS not supported on WHPX."); exit(1); } + if (mshv_enabled()) { + error_report("ITS not supported on MSHV."); + exit(1); + } if (hvf_enabled() && hvf_irqchip_in_kernel()) { error_report("ITS not supported on HVF when using the hardware= vGIC."); exit(1); diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c index f7ba74e6d5..fb34b6a942 100644 --- a/hw/intc/arm_gicv3_common.c +++ b/hw/intc/arm_gicv3_common.c @@ -34,6 +34,7 @@ #include "system/kvm.h" #include "system/whpx.h" #include "system/hvf.h" +#include "system/mshv.h" =20 =20 static void gicv3_gicd_no_migration_shift_bug_post_load(GICv3State *cs) @@ -662,6 +663,8 @@ const char *gicv3_class_name(void) return TYPE_WHPX_GICV3; } else if (hvf_enabled() && hvf_irqchip_in_kernel()) { return TYPE_HVF_GICV3; + } else if (mshv_enabled()) { + return TYPE_MSHV_GICV3; } else { if (kvm_enabled()) { error_report("Userspace GICv3 is not supported with KVM"); diff --git a/hw/intc/arm_gicv3_mshv.c b/hw/intc/arm_gicv3_mshv.c new file mode 100644 index 0000000000..a87819a5ba --- /dev/null +++ b/hw/intc/arm_gicv3_mshv.c @@ -0,0 +1,181 @@ +/* + * ARM Generic Interrupt Controller using MSHV in-kernel support + * + * Copyright Microsoft, Corp. 2026 + * Based on vGICv3 KVM code by Pavel Fedin + * + * Authors: + * Aastha Rawat + * Anirudh Rayabharam (Microsoft) + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/error-report.h" +#include "hw/intc/arm_gicv3_common.h" +#include "migration/blocker.h" +#include "target/arm/cpregs.h" +#include "hw/hyperv/hvgdk_mini.h" +#include "system/mshv.h" +#include "system/mshv_int.h" + +struct MSHVARMGICv3Class { + ARMGICv3CommonClass parent_class; + DeviceRealize parent_realize; + ResettablePhases parent_phases; +}; + +OBJECT_DECLARE_TYPE(GICv3State, MSHVARMGICv3Class, MSHV_GICV3) + +static void mshv_gicv3_get(GICv3State *s) +{ +} + +static void mshv_gicv3_put(GICv3State *s) +{ +} + +static void mshv_gicv3_reset_hold(Object *obj, ResetType type) +{ + GICv3State *s =3D ARM_GICV3_COMMON(obj); + MSHVARMGICv3Class *mgc =3D MSHV_GICV3_GET_CLASS(s); + + if (mgc->parent_phases.hold) { + mgc->parent_phases.hold(obj, type); + } + + mshv_gicv3_put(s); +} + +static void mshv_gicv3_set_irq(void *opaque, int irq, int level) +{ + int ret; + GICv3State *s =3D (GICv3State *)opaque; + int vm_fd =3D mshv_state->vm; + struct hv_input_assert_virtual_interrupt arg =3D {0}; + struct mshv_root_hvcall args =3D {0}; + union hv_interrupt_control control =3D { + .interrupt_type =3D HV_ARM64_INTERRUPT_TYPE_FIXED, + .rsvd1 =3D 0, + .asserted =3D level, + .rsvd2 =3D 0 + }; + + if (irq >=3D s->num_irq) { + return; + } + + arg.control =3D control; + arg.vector =3D GIC_INTERNAL + irq; + + args.code =3D HVCALL_ASSERT_VIRTUAL_INTERRUPT; + args.in_sz =3D sizeof(arg); + args.in_ptr =3D (uint64_t)&arg; + + ret =3D mshv_hvcall(vm_fd, &args); + if (ret < 0) { + error_report("Failed to set GICv3 IRQ %d to level %d", irq, level); + } +} + +static void mshv_gicv3_realize(DeviceState *dev, Error **errp) +{ + ERRP_GUARD(); + GICv3State *s =3D MSHV_GICV3(dev); + MSHVARMGICv3Class *mgc =3D MSHV_GICV3_GET_CLASS(s); + int i, ret; + + mgc->parent_realize(dev, errp); + if (*errp) { + return; + } + + if (s->revision !=3D 3) { + error_setg(errp, "unsupported GIC revision %d for platform GIC", + s->revision); + return; + } + + if (s->security_extn) { + error_setg(errp, "the platform vGICv3 does not implement the " + "security extensions"); + return; + } + + if (s->nmi_support) { + error_setg(errp, "NMI is not supported with the platform GIC"); + return; + } + + if (s->nb_redist_regions > 1) { + error_setg(errp, "Multiple VGICv3 redistributor regions are not " + "supported by MSHV"); + error_append_hint(errp, "A maximum of %d VCPUs can be used", + s->redist_region_count[0]); + return; + } + + gicv3_init_irqs_and_mmio(s, mshv_gicv3_set_irq, NULL); + + for (i =3D 0; i < s->num_cpu; i++) { + CPUState *cpu_state =3D qemu_get_cpu(i); + + hv_register_assoc gicr_base =3D { + .name =3D HV_ARM64_REGISTER_GICR_BASE_GPA, + .value =3D { + .reg64 =3D 0x080A0000 + (GICV3_REDIST_SIZE * i) + } + }; + + ret =3D mshv_set_generic_regs(cpu_state, &gicr_base, 1); + if (ret < 0) { + error_setg(errp, "Failed to set GICR base for CPU %d", i); + return; + } + } + + if (s->maint_irq) { + error_setg(errp, + "Nested virtualisation not currently supported by MSHV"); + return; + } + + error_setg(&s->migration_blocker, + "Live migration disabled because GIC state save/restore not suppor= ted on MSHV"); + if (migrate_add_blocker(&s->migration_blocker, errp) < 0) { + error_report_err(*errp); + } +} + +static void mshv_gicv3_class_init(ObjectClass *klass, const void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + ResettableClass *rc =3D RESETTABLE_CLASS(klass); + ARMGICv3CommonClass *agcc =3D ARM_GICV3_COMMON_CLASS(klass); + MSHVARMGICv3Class *mgc =3D MSHV_GICV3_CLASS(klass); + + agcc->pre_save =3D mshv_gicv3_get; + agcc->post_load =3D mshv_gicv3_put; + + device_class_set_parent_realize(dc, mshv_gicv3_realize, + &mgc->parent_realize); + resettable_class_set_parent_phases(rc, NULL, mshv_gicv3_reset_hold, NU= LL, + &mgc->parent_phases); +} + +static const TypeInfo mshv_arm_gicv3_info =3D { + .name =3D TYPE_MSHV_GICV3, + .parent =3D TYPE_ARM_GICV3_COMMON, + .instance_size =3D sizeof(GICv3State), + .class_init =3D mshv_gicv3_class_init, + .class_size =3D sizeof(MSHVARMGICv3Class), +}; + +static void mshv_gicv3_register_types(void) +{ + type_register_static(&mshv_arm_gicv3_info); +} + +type_init(mshv_gicv3_register_types) diff --git a/hw/intc/meson.build b/hw/intc/meson.build index fac2d228f9..57505303e2 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -49,6 +49,7 @@ specific_ss.add(when: ['CONFIG_WHPX', 'TARGET_AARCH64'], = if_true: files('arm_gic specific_ss.add(when: ['CONFIG_HVF', 'CONFIG_ARM_GICV3'], if_true: files('= arm_gicv3_hvf.c')) stub_ss.add(files('arm_gicv3_hvf_stub.c')) specific_ss.add(when: ['CONFIG_ARM_GIC_KVM', 'TARGET_AARCH64'], if_true: f= iles('arm_gicv3_kvm.c', 'arm_gicv3_its_kvm.c')) +specific_ss.add(when: ['CONFIG_MSHV', 'TARGET_AARCH64'], if_true: files('a= rm_gicv3_mshv.c')) arm_common_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_nvic.c')) specific_ss.add(when: 'CONFIG_GRLIB', if_true: files('grlib_irqmp.c')) specific_ss.add(when: 'CONFIG_IOAPIC', if_true: files('ioapic.c')) diff --git a/include/hw/hyperv/hvgdk_mini.h b/include/hw/hyperv/hvgdk_mini.h index 477898d919..55da68428e 100644 --- a/include/hw/hyperv/hvgdk_mini.h +++ b/include/hw/hyperv/hvgdk_mini.h @@ -82,6 +82,8 @@ typedef enum hv_register_name { HV_ARM64_REGISTER_MIDR_EL1 =3D 0x00040051, HV_ARM64_REGISTER_MPIDR_EL1 =3D 0x00040001, =20 + HV_ARM64_REGISTER_GICR_BASE_GPA =3D 0x00063000, + #elif defined(__x86_64__) /* X64 User-Mode Registers */ HV_X64_REGISTER_RAX =3D 0x00020000, diff --git a/include/hw/hyperv/hvhdk_mini.h b/include/hw/hyperv/hvhdk_mini.h index 9c2f3cf5ae..4d78fa0677 100644 --- a/include/hw/hyperv/hvhdk_mini.h +++ b/include/hw/hyperv/hvhdk_mini.h @@ -62,6 +62,12 @@ enum hv_partition_property_code { HV_PARTITION_PROPERTY_ISOLATION_POLICY =3D 0x000= 50014, HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION =3D 0x000= 50017, HV_PARTITION_PROPERTY_SEV_VMGEXIT_OFFLOADS =3D 0x000= 50022, + HV_PARTITION_PROPERTY_GICD_BASE_ADDRESS =3D 0x000= 50028, + HV_PARTITION_PROPERTY_GITS_TRANSLATER_BASE_ADDRESS =3D 0x000= 50029, + HV_PARTITION_PROPERTY_GIC_LPI_INT_ID_BITS =3D 0x000= 5002A, + HV_PARTITION_PROPERTY_GIC_PPI_OVERFLOW_INTERRUPT_FROM_CNTV =3D 0x000= 5002B, + HV_PARTITION_PROPERTY_GIC_PPI_OVERFLOW_INTERRUPT_FROM_CNTP =3D 0x000= 5002C, + HV_PARTITION_PROPERTY_GIC_PPI_PERFORMANCE_MONITORS_INTERRUPT =3D 0x000= 5002D, =20 /* Compatibility properties */ HV_PARTITION_PROPERTY_PROCESSOR_VENDOR =3D 0x00060000, diff --git a/include/hw/intc/arm_gicv3_common.h b/include/hw/intc/arm_gicv3= _common.h index 03ab3e8f2f..2ed456e654 100644 --- a/include/hw/intc/arm_gicv3_common.h +++ b/include/hw/intc/arm_gicv3_common.h @@ -316,6 +316,7 @@ DECLARE_OBJ_CHECKERS(GICv3State, ARMGICv3CommonClass, /* Types for GICv3 kernel-irqchip */ #define TYPE_WHPX_GICV3 "whpx-arm-gicv3" #define TYPE_HVF_GICV3 "hvf-arm-gicv3" +#define TYPE_MSHV_GICV3 "mshv-arm-gicv3" =20 struct ARMGICv3CommonClass { /*< private >*/ diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h index 81e233be5f..b0feb58596 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -105,6 +105,7 @@ void mshv_arch_amend_proc_features( void mshv_arch_disable_partition_proc_features( union hv_partition_processor_features *disabled_features); int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd); +int mshv_arch_pre_init_vm(int vm_fd); int mshv_arch_post_init_vm(int vm_fd); void mshv_setup_hvcall_args(AccelCPUState *state); =20 diff --git a/target/arm/mshv/mshv-all.c b/target/arm/mshv/mshv-all.c index 6ec9811258..001ff896a1 100644 --- a/target/arm/mshv/mshv-all.c +++ b/target/arm/mshv/mshv-all.c @@ -288,6 +288,67 @@ void mshv_arch_destroy_vcpu(CPUState *cpu) state->hvcall_args =3D (MshvHvCallArgs){0}; } =20 +static int set_partition_prop(int vm_fd, uint32_t prop_code, + uint64_t prop_value) +{ + int ret; + struct hv_input_set_partition_property in =3D {0}; + in.property_code =3D prop_code; + in.property_value =3D prop_value; + + struct mshv_root_hvcall args =3D {0}; + args.code =3D HVCALL_SET_PARTITION_PROPERTY; + args.in_sz =3D sizeof(in); + args.in_ptr =3D (uint64_t)∈ + + ret =3D mshv_hvcall(vm_fd, &args); + if (ret < 0) { + error_report("Failed to set partition property code %u", prop_code= ); + return -1; + } + + return 0; +} + +int mshv_arch_pre_init_vm(int vm_fd) +{ + int ret; + VirtMachineState *vms =3D VIRT_MACHINE(qdev_get_machine()); + + ret =3D set_partition_prop(vm_fd, + HV_PARTITION_PROPERTY_GICD_BASE_ADDRESS, + vms->memmap[VIRT_GIC_DIST].base); + if (ret < 0) { + return ret; + } + + ret =3D set_partition_prop(vm_fd, + HV_PARTITION_PROPERTY_GITS_TRANSLATER_BASE_ADDRESS, + vms->memmap[VIRT_GIC_ITS].base); + if (ret < 0) { + return ret; + } + + ret =3D set_partition_prop(vm_fd, + HV_PARTITION_PROPERTY_GIC_LPI_INT_ID_BITS, + 0); + if (ret < 0) { + return ret; + } + + ret =3D set_partition_prop(vm_fd, + HV_PARTITION_PROPERTY_GIC_PPI_OVERFLOW_INTERRUPT_F= ROM_CNTV, + ARCH_TIMER_VIRT_IRQ); + if (ret < 0) { + return ret; + } + + ret =3D set_partition_prop(vm_fd, + HV_PARTITION_PROPERTY_GIC_PPI_PERFORMANCE_MONITORS= _INTERRUPT, + VIRTUAL_PMU_IRQ); + + return ret; +} =20 static uint32_t mshv_arm_get_ipa_bit_size(int mshv_fd) { diff --git a/target/i386/mshv/mshv-all.c b/target/i386/mshv/mshv-all.c index f0b43aa86f..ce8b426ea4 100644 --- a/target/i386/mshv/mshv-all.c +++ b/target/i386/mshv/mshv-all.c @@ -39,6 +39,11 @@ int mshv_arch_accel_init(AccelState *as, MachineState *m= s, int mshv_fd) return 0; } =20 +int mshv_arch_pre_init_vm(int vm_fd) +{ + return 0; +} + /* * Default Microsoft Hypervisor behavior for unimplemented MSR is to send a * fault to the guest if it tries to access it. It is possible to override --=20 2.45.4 From nobody Sat Jul 25 14:28:52 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1784284185; cv=none; d=zohomail.com; s=zohoarc; b=I3dVSYOYMUCiwHM5fmnb6ANVIovY0IszS4HV+Sb4rH8xo4j+UPKxeintNAjAj+ndal5fMEGHvV+jyd2QZOhZdfau/ZPeBONIVOgiwIvLb83jZV2ZJhNdYfX3vqXHhtpuBLemondaRHlZ1rnJt3Rgzxq3BWKbfek1G3JiUYiyFDY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1784284185; h=Content-Type: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=5l8DrEdAHkntUshww49dDf0wcUXhQ57J8wAn70K6C9w=; b=JOCu8cjjxaxlSSIiccPB7dDrOXZj8oEMwjaiIjo/WK3cFMubx6D7R5bgXMs0GAg8J8xZdQ5MwEC1qaqbvKUtOyr4hbaJVu8T0dYKWWFB1hRyleUcppF9p2328Zg3WfBKHwB9vCDsojpbqF8QLcM9De2CDV7KcJl2R8Lw0XEoZ7o= 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=none dis=none) Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17842841857231017.660960655302; Fri, 17 Jul 2026 03:29:45 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnZ-0005yd-3q; Fri, 17 Jul 2026 06:28:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wkfnW-0005wL-P4; Fri, 17 Jul 2026 06:28:02 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wkfnV-0000Pn-AL; Fri, 17 Jul 2026 06:28:02 -0400 Received: from localhost (unknown [131.107.159.8]) by linux.microsoft.com (Postfix) with ESMTPSA id 7FA9320B717B; Fri, 17 Jul 2026 03:27:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 7FA9320B717B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1784284050; bh=5l8DrEdAHkntUshww49dDf0wcUXhQ57J8wAn70K6C9w=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=pGkDAlU3+OirL/YehemJJoeLAWiFUryl0SWx29yu9sHFpJfRCFsKR19LsbafreW9F 3CiMHeWY3Gm1RAoVpjbdpezCmHpNIIkzzfittLgn9TWAv52UaokzRLPQ5kOTaHqNaO dYGzhhKhZNVttvqQgisrvL/l31+yALVqk4BYT3lY= From: Aastha Rawat Date: Fri, 17 Jul 2026 10:27:28 +0000 Subject: [PATCH v5 13/13] MAINTAINERS: updates for MSHV arm64 code MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260717-mshv_accel_arm64_supp-v5-13-ef07d4c6b337@linux.microsoft.com> References: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> In-Reply-To: <20260717-mshv_accel_arm64_supp-v5-0-ef07d4c6b337@linux.microsoft.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , =?utf-8?q?Doru_Bl=C3=A2nzeanu?= , Paolo Bonzini , =?utf-8?q?Marc-Andr=C3=A9_Lureau?= , =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= , =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni X-Mailer: b4 0.15.1 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=lists1p.gnu.org; Received-SPF: pass client-ip=13.77.154.182; envelope-from=aastharawat@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, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, 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 @linux.microsoft.com) X-ZM-MESSAGEID: 1784284187437158500 From: "Anirudh Rayabharam (Microsoft)" Add myself and Aastha Rawat as maintainers. Add Magnus Kulke as reviewer. Signed-off-by: Anirudh Rayabharam (Microsoft) --- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index ecb8cfdc41..e35e3160d9 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -614,6 +614,14 @@ R: Doru Bl=C3=A2nzeanu S: Supported F: target/i386/mshv/ =20 +ARM64 MSHV CPUs +M: Anirudh Rayabharam +M: Aastha Rawat +R: Magnus Kulke +S: Supported +F: target/arm/mshv/ +F: hw/intc/arm_gicv3_mshv.c + X86 Instruction Emulator M: Roman Bolshakov R: Phil Dennis-Jordan --=20 2.45.4