From nobody Tue Apr 7 21:46:19 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=1773242638; cv=pass; d=zohomail.com; s=zohoarc; b=F6HvVWhtPVyT+LyifWeYexWQnyb2Hu8+O9GIeTNtY+qW0BuFM7ZiSwZVgug2bQzftOzKOY8Kqixe/Ce5RTVEJBLhbeI26iCi2FARMe/HPLUAbnD4fcy/PCG1SMLckcirhGq0zgIw21LCWUT8774pI4e2RfjUN6MhXJImESDGqN8= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773242638; 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=5qLr/HGlBBp5eAwv40G/NIi2gnXK638n+PZYfzMbYrU=; b=B/5G1xmhI5PbJdYQYX0gg2cRrrGPB7l7WHsD2oP2dtsBs2YFjJu2xGn6bOxzhZ7mpxAk8q9pyvILf/ylSe5boTTM6kAzlt5jTwB+qt7beq62DM8vAMHQCCMqeNO8TOSXGOHTFkhpbthvYUJCwCi9cg+K1Lt9TkaO55LNaAfC+W4= 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 1773242638870437.55043809101505; Wed, 11 Mar 2026 08:23:58 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w0LLg-0002sf-Od; 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 1w0LLT-0002Ce-AC; Wed, 11 Mar 2026 11:19:40 -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 1w0LLO-00011P-OU; Wed, 11 Mar 2026 11:19:34 -0400 Received: by mx.zohomail.com with SMTPS id 1773242224928837.2347165867382; Wed, 11 Mar 2026 08:17:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1773242226; cv=none; d=zohomail.com; s=zohoarc; b=GLyXyFUaUg6nnWCcf85hjtKQJ54x/PnEBvc2iWUi5HzklkBLx1l+gAOKnrZBeQ6arHjuLBO7EXnGN9oNNDDN4vqDgjgo6TZJU3N53IRWi55c7TSD6Zra75XIWkpfab5F0v+0xOR0hKhFcTR6l/cic7XgliU/nsZhk+DxpVnQaC8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773242226; 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=5qLr/HGlBBp5eAwv40G/NIi2gnXK638n+PZYfzMbYrU=; b=EaxhQ08GeU4olQ0eTiEtkSNMZr1JtHVmaJgxfF/UvUMtyeKNrPTHvJeOK3sAo0v6F+6ADUDKvVNMT7FDd28DvGa3gN0IX/qJsw9i627YnXA+xOJxcoixJtg926hYBiI3huI5hBDnOeeoPfyetp+2FJq/88vS8VhrkNWiyH9+4+8= 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=1773242226; 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=5qLr/HGlBBp5eAwv40G/NIi2gnXK638n+PZYfzMbYrU=; b=ov5R8wlOJIKlJVSPJ5PTmck72MeaNwBmJbeOuUPAJJi1kl+2aghzXiBsIG3BY/Zh CdEqP2wE1fbxo/IN0JnV0E3pQsgPfJtTwA90b8x85h3lO+nH3EFCyNJMSUcT95KruM8 HtgJcCWgvI9wWEpiponXSQFlYzC0cWKd68a101LQ= From: "Anirudh Rayabharam (Microsoft)" Date: Wed, 11 Mar 2026 15:15:40 +0000 Subject: [PATCH 13/14] 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: <20260311-mshv_accel_arm64_supp-v1-13-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: 1773242639319158500 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 | 180 +++++++++++++++++++++++++++++++++= ++++ 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 | 62 +++++++++++++ target/i386/mshv/mshv-all.c | 5 ++ 11 files changed, 270 insertions(+), 4 deletions(-) diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index 9a101d51ff..d139f46916 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -243,6 +243,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 34eb5248a9..5f922ece9c 100644 --- a/hw/arm/virt.c +++ b/hw/arm/virt.c @@ -2117,7 +2117,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 (tcg_enabled() || hvf_enabled() || qtest_enabled()) { gics_supported |=3D VIRT_GIC_VERSION_2_MASK; @@ -2159,7 +2159,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 { vms->msi_controller =3D VIRT_MSI_CTRL_ITS; @@ -2176,8 +2176,8 @@ static void finalize_msi_controller(VirtMachineState = *vms) error_report("GICv2 + ITS is an invalid configuration."); exit(1); } - if (whpx_enabled()) { - error_report("ITS not supported on WHPX."); + if (whpx_enabled() || mshv_enabled()) { + error_report("ITS not supported on WHPX and MSHV."); exit(1); } } diff --git a/hw/intc/arm_gicv3_common.c b/hw/intc/arm_gicv3_common.c index 9200671c7a..239c645ab9 100644 --- a/hw/intc/arm_gicv3_common.c +++ b/hw/intc/arm_gicv3_common.c @@ -33,6 +33,7 @@ #include "hw/arm/linux-boot-if.h" #include "system/kvm.h" #include "system/whpx.h" +#include "system/mshv.h" =20 =20 static void gicv3_gicd_no_migration_shift_bug_post_load(GICv3State *cs) @@ -658,6 +659,8 @@ const char *gicv3_class_name(void) return "kvm-arm-gicv3"; } else if (whpx_enabled()) { return TYPE_WHPX_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..2d0b4cbf5e --- /dev/null +++ b/hw/intc/arm_gicv3_mshv.c @@ -0,0 +1,180 @@ +/* + * 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 96742df090..9d824db582 100644 --- a/hw/intc/meson.build +++ b/hw/intc/meson.build @@ -43,6 +43,7 @@ arm_common_ss.add(when: 'CONFIG_ARM_GICV3', if_true: file= s('arm_gicv3_cpuif.c')) specific_ss.add(when: 'CONFIG_ARM_GIC_KVM', if_true: files('arm_gic_kvm.c'= )) specific_ss.add(when: ['CONFIG_WHPX', 'TARGET_AARCH64'], if_true: files('a= rm_gicv3_whpx.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 eb766734d6..b50a65a0d4 100644 --- a/include/hw/hyperv/hvgdk_mini.h +++ b/include/hw/hyperv/hvgdk_mini.h @@ -66,6 +66,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 c55cf18120..3baac1a35c 100644 --- a/include/hw/intc/arm_gicv3_common.h +++ b/include/hw/intc/arm_gicv3_common.h @@ -315,6 +315,7 @@ DECLARE_OBJ_CHECKERS(GICv3State, ARMGICv3CommonClass, =20 /* Types for GICv3 kernel-irqchip */ #define TYPE_WHPX_GICV3 "whpx-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 c72c91cd23..0ef98abedf 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -97,6 +97,7 @@ 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_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 b0649ba10b..4323399455 100644 --- a/target/arm/mshv/mshv-all.c +++ b/target/arm/mshv/mshv-all.c @@ -393,6 +393,68 @@ void mshv_arch_amend_proc_features( =20 } =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; +} + int mshv_arch_post_init_vm(int vm_fd) { return 0; 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.43.0