From nobody Tue Apr 7 21:50:02 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass header.i=anirudh@anirudhrb.com; 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; arc=pass (i=1 dmarc=pass fromdomain=anirudhrb.com); dmarc=pass(p=none dis=none) header.from=anirudhrb.com ARC-Seal: i=2; a=rsa-sha256; t=1773242607; cv=pass; d=zohomail.com; s=zohoarc; b=RLC0wWf2FzB1vF9114r4EC8AuZhReVvshcySAd6/IKs/TzPjAP5Sy5Gt7AAs80QLm6c41RUHcu7y5lvRN0bJb/kE0r5towPtbdJ+sQjrSsudWOD/WjwRJR5I9SGnRhGnfyn8hutuwCTpGEltJuYMwzXVNoAAgviDpN1TEgx0UW0= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773242607; 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=cnJTxXOgBy6MJhIg55PhHTZzBdD3gmEon1dDZyH3s7g=; b=NDMKOBW/5zBiHAGn0vSSzLa21zXjnB+OswhLwwCYpNhCPcDmSmMvjxvMAM/GmwUYW/E0lhzZ0Pv9fynZNsUeB/TehVm4ee9+oHWzcNl3AMx4YqyRTebGojQX8aCtl+sgDYiJ3uqL2nhRVC4yMwZPxd0nHHlmjRPktEfXl+KTI3g= ARC-Authentication-Results: i=2; mx.zohomail.com; dkim=pass header.i=anirudh@anirudhrb.com; 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; arc=pass (i=1 dmarc=pass fromdomain=anirudhrb.com); dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1773242607914577.254696987719; Wed, 11 Mar 2026 08:23:27 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0LLg-0002qo-91; Wed, 11 Mar 2026 11:19:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w0LKR-0001Px-SV; Wed, 11 Mar 2026 11:18:36 -0400 Received: from sender4-of-o54.zoho.com ([136.143.188.54]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w0LKP-0000ud-Mp; Wed, 11 Mar 2026 11:18:31 -0400 Received: by mx.zohomail.com with SMTPS id 1773242201333184.4496247944328; Wed, 11 Mar 2026 08:16:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773242203; cv=none; d=zohomail.com; s=zohoarc; b=C4i9+vFfhsXeNgFaubJCBwaUV0EyA1H9+PSsz0JqpRsmnFlw4FvsITiu7DDTBYNvjB9HiucbZ9Q367cx6vS0SYGjssLBwCs33U4axqeA3boKInJ5rtqRuQFuQlAsV2W2P64S/7j3eGTEv3xagjYW25xJ/80KWnEo8DGVScfKXXk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773242203; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=cnJTxXOgBy6MJhIg55PhHTZzBdD3gmEon1dDZyH3s7g=; b=S1cyznRc8CKAGS/CodC2JIaDfD/0pNL53bcGrMpg1n3XfOmVdEcG9WsLKT0SSZj7UtnxuNk+hmTDX9+jGp8hzSrnluJi0FiTvre6qDj24hlDUAsK4Fl3dI5vRsc7ndpghh2MmOwIRR7No1U0gEIjS4cZqD2u75Fs99pmEwPejnM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=anirudhrb.com; spf=pass smtp.mailfrom=anirudh@anirudhrb.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1773242203; s=zoho; d=anirudhrb.com; i=anirudh@anirudhrb.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=cnJTxXOgBy6MJhIg55PhHTZzBdD3gmEon1dDZyH3s7g=; b=kRJEWI+hAjSWD+0m7F37M6eZBF4PWXlYTT+e992V+w0OEKqyPgjYeCwYt41poaBu dAWWDVcBykG2GDMWKb3vivsMJMz8gxMafa+GcGUeU+4rFzGoAOf3Eig5T5rMXO1ylJR hIEQEtH7sUY+YYigZ5l+AKo/z1TGgvjWlLJxEUlk= From: "Anirudh Rayabharam (Microsoft)" Date: Wed, 11 Mar 2026 15:15:34 +0000 Subject: [PATCH 07/14] 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: <20260311-mshv_accel_arm64_supp-v1-7-c31699b7bc1f@anirudhrb.com> References: <20260311-mshv_accel_arm64_supp-v1-0-c31699b7bc1f@anirudhrb.com> In-Reply-To: <20260311-mshv_accel_arm64_supp-v1-0-c31699b7bc1f@anirudhrb.com> To: qemu-devel@nongnu.org Cc: Magnus Kulke , Wei Liu , 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?= , Peter Maydell , Anirudh Rayabharam , Aastha Rawat , qemu-arm@nongnu.org X-Mailer: b4 0.14.3 X-ZohoMailClient: External 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=lists.gnu.org; Received-SPF: pass client-ip=136.143.188.54; envelope-from=anirudh@anirudhrb.com; helo=sender4-of-o54.zoho.com X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no 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 anirudh@anirudhrb.com) X-ZM-MESSAGEID: 1773242609856154100 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 arm64, the hook queries the hypervisor for the supported IPA bit size and validates it against the guest memory map via the machine's get_physical_address_range callback, following the same pattern used by HVF and WHPX. This also populates the memory map which comes in handy later when retreiving the vGIC layout. 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/arm/mshv/mshv-all.c | 25 ++++++++++---- target/i386/mshv/meson.build | 1 + target/i386/mshv/mshv-all.c | 80 ++++++++++++++++++++++++++++++++++++++++= ++++ target/i386/mshv/mshv-cpu.c | 40 ---------------------- 6 files changed, 105 insertions(+), 47 deletions(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index c6dad18d2f..d63b3a53bf 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -477,7 +477,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 mshv_init_msicontrol(); =20 diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h index ff3ab957b5..c72c91cd23 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -96,6 +96,7 @@ void mshv_arch_init_vcpu(CPUState *cpu); void mshv_arch_destroy_vcpu(CPUState *cpu); void mshv_arch_amend_proc_features( union hv_partition_synthetic_processor_features *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/arm/mshv/mshv-all.c b/target/arm/mshv/mshv-all.c index 0102297305..2b983845d3 100644 --- a/target/arm/mshv/mshv-all.c +++ b/target/arm/mshv/mshv-all.c @@ -9,12 +9,13 @@ * SPDX-License-Identifier: GPL-2.0-or-later */ =20 - #include "qemu/osdep.h" #include =20 #include "qemu/error-report.h" #include "qemu/memalign.h" +#include "hw/arm/bsa.h" +#include "hw/arm/virt.h" =20 #include "system/cpus.h" #include "target/arm/cpu.h" @@ -188,11 +189,6 @@ void mshv_arch_destroy_vcpu(CPUState *cpu) state->hvcall_args =3D (MshvHvCallArgs){0}; } =20 -void mshv_init_mmio_emu(void) -{ - -} - void mshv_arch_amend_proc_features( union hv_partition_synthetic_processor_features *features) { @@ -390,3 +386,20 @@ void mshv_arm_set_cpu_features_from_host(ARMCPU *cpu) cpu->midr =3D arm_host_cpu_features.midr; cpu->reset_sctlr =3D arm_host_cpu_features.reset_sctlr; } + +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; +} 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 9a80dc34d0..8325ac74a3 100644 --- a/target/i386/mshv/mshv-cpu.c +++ b/target/i386/mshv/mshv-cpu.c @@ -1482,43 +1482,3 @@ void mshv_arch_destroy_vcpu(CPUState *cpu) state->hvcall_args =3D (MshvHvCallArgs){0}; g_clear_pointer(&env->emu_mmio_buf, g_free); } - -/* - * 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; -} --=20 2.43.0