Skip to contentSkip to conversation

Add ARM64 support for MSHV accelerator

PATCH Superseded Aastha Rawat 3 participants 18 messages Apr 2 Arm/Amlogic Meson SoC support

v2 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add ARM64 support for MSHV accelerator

This series adds ARM64 guest support to the MSHV (Microsoft Hypervisor) accelerator, enabling QEMU to run aarch64 VMs on Microsoft's hypervisor using the mshv Linux kernel module.

The first few patches refactor the existing x86 MSHV code to separate arch-specific pieces from common infrastructure: moving MSR handling to target/i386, extracting shared register hypercall helpers, provisioning host CPU features, and introducing arch-specific init hooks.

The remaining patches add the ARM64 backend:
- vCPU state get/set using hypervisor register hypercalls
- -cpu host support by querying ID registers from the hypervisor
- vCPU run loop with MMIO emulation via ESR_EL2 syndrome decoding
- In-kernel vGICv3 backed by HVCALL_ASSERT_VIRTUAL_INTERRUPT
- Interrupt control structure adjustments for arm64

With this series, a standard aarch64 virt machine can be launched with:
qemu-system-aarch64 -accel mshv -cpu host -M virt ...

Caveats:
- Currently only direct kernel is supported. We're still debugging edk2 firmware boot.
- Live migration is not yet supported.

---
Changes in v2:
- Removed PATCH: "accel/mshv: provision guests with the same features as host".
- Extracted common MMIO emulation logic for hvf, whpx and mshv to a
common place.
- Fixed checkpatch errors/warnings.
- Picked up reviewed-by tags.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]

---
Aastha Rawat (8):
accel/mshv: move msr.c to target/i386
accel/mshv: extract common CPU register helpers
meson, target/arm/mshv: Enable arm64 build & add initial MSHV support target/arm/mshv: implement vcpu state operations for ARM64 target/arm/mshv: implement -cpu host for MSHV
accel/mshv: Add access_vp_regs synthetic proc features target/arm: cpu: Mark MSHV supporting PSCI 1.3 target/arm: extract MMIO emulation logic for HVF & WHPX

Anirudh Rayabharam (Microsoft) (5):
accel/mshv: add arch-specific accelerator init hook target/arm/mshv: add vCPU run loop
include/hw/hyperv: adjust hv_interrupt_control structure for arm64 hw/intc,target/arm/mshv: add MSHV vGICv3 implementation
MAINTAINERS: updates for MSHV arm64 code

Magnus Kulke (1):
accel/mshv: implement cpu_thread_is_idle() hook

 MAINTAINERS                        |   8 +
 accel/mshv/irq.c                   |   2 +
 accel/mshv/meson.build             |   4 +-
 accel/mshv/mshv-all.c              |  26 +-
 accel/mshv/mshv-cpu-common.c       | 151 ++++++++++
 hw/arm/virt.c                      |  11 +-
 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     | 130 +++++++++
 include/hw/hyperv/hvhdk.h          | 101 ++++++-
 include/hw/hyperv/hvhdk_mini.h     |   6 +
 include/hw/intc/arm_gicv3_common.h |   1 +
 include/system/hw_accel.h          |   3 +-
 include/system/mshv.h              |   2 +
 include/system/mshv_int.h          |   5 +
 meson.build                        |   7 +-
 target/arm/cpu.c                   |   8 +-
 target/arm/cpu64.c                 |  24 +-
 target/arm/helper.c                |  60 ++++
 target/arm/helper.h                |   5 +
 target/arm/hvf/hvf.c               |  64 +++--
 target/arm/meson.build             |   1 +
 target/arm/mshv/meson.build        |   7 +
 target/arm/mshv/mshv-all.c         | 566 +++++++++++++++++++++++++++++++++++++
 target/arm/mshv_arm.h              |  18 ++
 target/arm/syndrome.h              |  37 +++
 target/arm/whpx/whpx-all.c         |  62 +---
 target/i386/mshv/meson.build       |   2 +
 target/i386/mshv/mshv-all.c        |  85 ++++++
 target/i386/mshv/mshv-cpu.c        | 170 +----------
 {accel => target/i386}/mshv/msr.c  |   0
 32 files changed, 1479 insertions(+), 272 deletions(-)

---
base-commit: f429c4276c8349f2cc94fb4e46a2a7918bec95c3
change-id: 20260311-mshv_accel_arm64_supp-e86b0082aee4

Best regards,

Signature · 1 line
Aastha Rawat <[email protected]>
#1 lore raw

PATCH v2 1/14 accel/mshv: move msr.c to target/i386

This file has x86 specific implementations. Move this file to i386 folder in preparation for ARM64 MSHV support.

---
 accel/mshv/meson.build            | 1 -
 target/i386/mshv/meson.build      | 1 +
 {accel => target/i386}/mshv/msr.c | 0
 3 files changed, 1 insertion(+), 1 deletion(-)
accel/mshv/meson.build +0 -1
index c1b1787c5e..e433187cde 100644
@@ -1,6 +1,5 @@
 system_ss.add(when: 'CONFIG_MSHV', if_true: files(
   'irq.c',
   'mem.c',
-  'msr.c',
   'mshv-all.c'
 ))
target/i386/mshv/meson.build +1 -0
index 49f28d4a5b..6091c21887 100644
@@ -2,6 +2,7 @@ i386_mshv_ss = ss.source_set()
 
 i386_mshv_ss.add(files(
   'mshv-cpu.c',
+  'msr.c',
 ))
 
 i386_system_ss.add_all(when: 'CONFIG_MSHV', if_true: i386_mshv_ss)
target/i386/mshv/msr.c renamed from accel/mshv/msr.c +0 -0
similarity index 100%
rename from accel/mshv/msr.c
rename to target/i386/mshv/msr.c
Signature · 1 line
2.45.4
#2 lore raw

PATCH v2 2/14 accel/mshv: extract common CPU register helpers

In reply to Aastha Rawat

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.

---
 accel/mshv/meson.build       |   3 +-
 accel/mshv/mshv-cpu-common.c | 151 +++++++++++++++++++++++++++++++++++++++++++
 include/system/mshv_int.h    |   3 +
 target/i386/mshv/mshv-cpu.c  | 130 +------------------------------------
 4 files changed, 159 insertions(+), 128 deletions(-)
accel/mshv/meson.build +2 -1
index e433187cde..ebe32921b3 100644
@@ -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'
 ))
accel/mshv/mshv-cpu-common.c new file +151 -0

151 lines not on this page · raw message

include/system/mshv_int.h +3 -0
index 35386c422f..ff3ab957b5 100644
@@ -89,12 +89,15 @@ int mshv_load_regs(CPUState *cpu);
 int mshv_store_regs(CPUState *cpu);
 int mshv_set_generic_regs(const CPUState *cpu, const hv_register_assoc *assocs,
                           size_t n_regs);
+int mshv_get_generic_regs(CPUState *cpu, hv_register_assoc *assocs,
+                        size_t n_regs);
 int mshv_arch_put_registers(const CPUState *cpu);
 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_post_init_vm(int vm_fd);
+void mshv_setup_hvcall_args(AccelCPUState *state);
 
 typedef struct mshv_root_hvcall mshv_root_hvcall;
 int mshv_hvcall(int fd, const mshv_root_hvcall *args);
target/i386/mshv/mshv-cpu.c +3 -127

166 lines not on this page · raw message

Signature · 1 line
2.45.4
#3 lore raw

PATCH v2 3/14 meson, target/arm/mshv: Enable arm64 build & add initial MSHV support

In reply to Aastha Rawat

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.

---
 meson.build                 |  7 +++---
 target/arm/meson.build      |  1 +
 target/arm/mshv/meson.build |  7 ++++++
 target/arm/mshv/mshv-all.c  | 54 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 66 insertions(+), 3 deletions(-)
meson.build +4 -3
index ed82247111..bf12fda40f 100644
@@ -303,7 +303,8 @@ if cpu == 'aarch64'
   accelerator_targets += {
     'CONFIG_HVF': ['aarch64-softmmu'],
     'CONFIG_NITRO': ['aarch64-softmmu'],
-    'CONFIG_WHPX': ['aarch64-softmmu']
+    'CONFIG_WHPX': ['aarch64-softmmu'],
+    'CONFIG_MSHV': ['aarch64-softmmu'],
   }
 elif cpu == 'x86_64'
   accelerator_targets += {
@@ -855,8 +856,8 @@ if get_option('kvm').allowed() and host_os == 'linux'
 endif
 
 if get_option('mshv').allowed() and host_os == 'linux'
-  if get_option('mshv').enabled() and host_machine.cpu() != 'x86_64'
-    error('mshv accelerator requires x64_64 host')
+  if get_option('mshv').enabled() and not (host_machine.cpu() in [ 'x86_64', 'aarch64' ])
+    error('The mshv accelerator requires an x86_64 or aarch64 host')
   endif
   accelerators += 'CONFIG_MSHV'
 endif
target/arm/meson.build +1 -0
index 6e0e504a40..8aa8cac137 100644
@@ -59,6 +59,7 @@ arm_common_system_ss.add(files(
 
 subdir('hvf')
 subdir('whpx')
+subdir('mshv')
 
 if 'CONFIG_TCG' in config_all_accel
    subdir('tcg')
target/arm/mshv/meson.build new file +7 -0
new file mode 100644
index 0000000000..169643691e
@@ -0,0 +1,7 @@
+arm_mshv_ss = ss.source_set()
+
+arm_mshv_ss.add(files(
+  'mshv-all.c',
+))
+
+arm_system_ss.add_all(when: 'CONFIG_MSHV', if_true: arm_mshv_ss)
target/arm/mshv/mshv-all.c new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
2.45.4
#4 lore raw

PATCH v2 4/14 target/arm/mshv: implement vcpu state operations for ARM64

In reply to Aastha Rawat

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.

---
 include/hw/hyperv/hvgdk_mini.h |  42 +++++++++++++
 target/arm/mshv/mshv-all.c     | 138 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 180 insertions(+)
include/hw/hyperv/hvgdk_mini.h +42 -0
index cb52cc9de2..dfe94050f4 100644
@@ -13,6 +13,46 @@ typedef enum hv_register_name {
     /* Pending Interruption Register */
     HV_REGISTER_PENDING_INTERRUPTION = 0x00010002,
 
+#if defined(__aarch64__)
+    HV_ARM64_REGISTER_XZR   = 0x0002FFFE,
+    HV_ARM64_REGISTER_X0    = 0x00020000,
+    HV_ARM64_REGISTER_X1    = 0x00020001,
+    HV_ARM64_REGISTER_X2    = 0x00020002,
+    HV_ARM64_REGISTER_X3    = 0x00020003,
+    HV_ARM64_REGISTER_X4    = 0x00020004,
+    HV_ARM64_REGISTER_X5    = 0x00020005,
+    HV_ARM64_REGISTER_X6    = 0x00020006,
+    HV_ARM64_REGISTER_X7    = 0x00020007,
+    HV_ARM64_REGISTER_X8    = 0x00020008,
+    HV_ARM64_REGISTER_X9    = 0x00020009,
+    HV_ARM64_REGISTER_X10   = 0x0002000A,
+    HV_ARM64_REGISTER_X11   = 0x0002000B,
+    HV_ARM64_REGISTER_X12   = 0x0002000C,
+    HV_ARM64_REGISTER_X13   = 0x0002000D,
+    HV_ARM64_REGISTER_X14   = 0x0002000E,
+    HV_ARM64_REGISTER_X15   = 0x0002000F,
+    HV_ARM64_REGISTER_X16   = 0x00020010,
+    HV_ARM64_REGISTER_X17   = 0x00020011,
+    HV_ARM64_REGISTER_X18   = 0x00020012,
+    HV_ARM64_REGISTER_X19   = 0x00020013,
+    HV_ARM64_REGISTER_X20   = 0x00020014,
+    HV_ARM64_REGISTER_X21   = 0x00020015,
+    HV_ARM64_REGISTER_X22   = 0x00020016,
+    HV_ARM64_REGISTER_X23   = 0x00020017,
+    HV_ARM64_REGISTER_X24   = 0x00020018,
+    HV_ARM64_REGISTER_X25   = 0x00020019,
+    HV_ARM64_REGISTER_X26   = 0x0002001A,
+    HV_ARM64_REGISTER_X27   = 0x0002001B,
+    HV_ARM64_REGISTER_X28   = 0x0002001C,
+    HV_ARM64_REGISTER_FP    = 0x0002001D,
+    HV_ARM64_REGISTER_LR    = 0x0002001E,
+    HV_ARM64_REGISTER_PC    = 0x00020022,
+
+    /* AArch64 System Register Descriptions: General system control registers */
+    HV_ARM64_REGISTER_MIDR_EL1   = 0x00040051,
+    HV_ARM64_REGISTER_MPIDR_EL1  = 0x00040001,
+
+#elif defined(__x86_64__)
     /* X64 User-Mode Registers */
     HV_X64_REGISTER_RAX     = 0x00020000,
     HV_X64_REGISTER_RCX     = 0x00020001,
@@ -157,6 +197,8 @@ typedef enum hv_register_name {
     /* Other MSRs */
     HV_X64_REGISTER_MSR_IA32_MISC_ENABLE = 0x000800A0,
 
+#endif
+
     /* Misc */
     HV_REGISTER_GUEST_OS_ID         = 0x00090002,
     HV_REGISTER_REFERENCE_TSC       = 0x00090017,
target/arm/mshv/mshv-all.c +138 -0

166 lines not on this page · raw message

Signature · 1 line
2.45.4
#5 lore raw

PATCH v2 5/14 target/arm/mshv: implement -cpu host for MSHV

In reply to Aastha Rawat

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.

Replace preprocessor config checks with runtime calls to mshv_enabled(), kvm_enabled(), etc. This ensures that the correct accelerator is selected at runtime when both MSHV and KVM are enabled.

---
 accel/mshv/mshv-all.c          |   3 +-
 hw/arm/virt.c                  |   3 +-
 include/hw/hyperv/hvgdk_mini.h |  17 ++++
 include/hw/hyperv/hvhdk.h      |  10 ++
 include/system/hw_accel.h      |   3 +-
 target/arm/cpu.c               |   6 +-
 target/arm/cpu64.c             |  24 +++--
 target/arm/mshv/mshv-all.c     | 204 +++++++++++++++++++++++++++++++++++++++++
 target/arm/mshv_arm.h          |  18 ++++
 9 files changed, 273 insertions(+), 15 deletions(-)
accel/mshv/mshv-all.c +2 -1
index d4cc7f5371..44f35a1463 100644
@@ -400,13 +400,14 @@ static int mshv_init_vcpu(CPUState *cpu)
     int ret;
 
     cpu->accel = g_new0(AccelCPUState, 1);
-    mshv_arch_init_vcpu(cpu);
 
     ret = mshv_create_vcpu(vm_fd, vp_index, &cpu->accel->cpufd);
     if (ret < 0) {
         return -1;
     }
 
+    mshv_arch_init_vcpu(cpu);
+
     cpu->accel->dirty = true;
 
     return 0;
hw/arm/virt.c +2 -1
index 7456614d05..34eb5248a9 100644
@@ -50,6 +50,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"
@@ -3450,7 +3451,7 @@ static GPtrArray *virt_get_valid_cpu_types(const MachineState *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()) {
+        if (kvm_enabled() || hvf_enabled() || mshv_enabled()) {
             g_ptr_array_add(vct, g_strdup(ARM_CPU_TYPE_NAME("host")));
         }
     }
include/hw/hyperv/hvgdk_mini.h +17 -0
index dfe94050f4..d56be0d70f 100644
@@ -48,6 +48,20 @@ typedef enum hv_register_name {
     HV_ARM64_REGISTER_LR    = 0x0002001E,
     HV_ARM64_REGISTER_PC    = 0x00020022,
 
+    /* AArch64 System Register Descriptions: ID Registers */
+    HV_ARM64_REGISTER_ID_MIDR_EL1         = 0x00022000,
+    HV_ARM64_REGISTER_ID_MPIDR_EL1        = 0x00022005,
+    HV_ARM64_REGISTER_ID_AA64_PFR0_EL1    = 0x00022020,
+    HV_ARM64_REGISTER_ID_AA64_PFR1_EL1    = 0x00022021,
+    HV_ARM64_REGISTER_ID_AA64_ISAR0_EL1   = 0x00022030,
+    HV_ARM64_REGISTER_ID_AA64_ISAR1_EL1   = 0x00022031,
+    HV_ARM64_REGISTER_ID_AA64_ISAR2_EL1   = 0x00022032,
+    HV_ARM64_REGISTER_ID_AA64_MMFR0_EL1   = 0x00022038,
+    HV_ARM64_REGISTER_ID_AA64_MMFR1_EL1   = 0x00022039,
+    HV_ARM64_REGISTER_ID_AA64_MMFR2_EL1   = 0x0002203a,
+    HV_ARM64_REGISTER_ID_AA64_DFR0_EL1    = 0x00022028,
+    HV_ARM64_REGISTER_ID_AA64_DFR1_EL1    = 0x00022029,
+
     /* AArch64 System Register Descriptions: General system control registers */
     HV_ARM64_REGISTER_MIDR_EL1   = 0x00040051,
     HV_ARM64_REGISTER_MPIDR_EL1  = 0x00040001,
@@ -841,6 +855,9 @@ struct hv_cpuid {
 #define HV_HYP_PAGE_SIZE        BIT(HV_HYP_PAGE_SHIFT)
 #define HV_HYP_PAGE_MASK        (~(HV_HYP_PAGE_SIZE - 1))
 
+#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
include/hw/hyperv/hvhdk.h +10 -0
index 866c8211bf..2e1ef80972 100644
@@ -18,6 +18,16 @@ struct hv_input_set_partition_property {
     uint64_t property_value;
 };
 
+struct hv_input_get_partition_property {
+    uint64_t partition_id;
+    uint32_t property_code; /* enum hv_partition_property_code */
+    uint32_t padding;
+};
+
+struct hv_output_get_partition_property {
+    uint64_t property_value;
+};
+
 union hv_partition_synthetic_processor_features {
     uint64_t as_uint64[HV_PARTITION_SYNTHETIC_PROCESSOR_FEATURES_BANKS];
 
include/system/hw_accel.h +2 -1
index f0c10b6d80..614ea60be3 100644
@@ -51,7 +51,8 @@ static inline bool hwaccel_enabled(void)
     return hvf_enabled()
         || kvm_enabled()
         || nvmm_enabled()
-        || whpx_enabled();
+        || whpx_enabled()
+        || mshv_enabled();
 }
 
 #endif /* QEMU_HW_ACCEL_H */
target/arm/cpu.c +4 -2
index 7e3e84b4bb..8aa22747ff 100644
@@ -46,6 +46,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"
@@ -1629,8 +1630,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()) {
-            error_setg(errp, "The 'host' CPU type can only be used with KVM or HVF");
+        if (!kvm_enabled() && !hvf_enabled() && !mshv_enabled()) {
+            error_setg(errp,
+                       "The 'host' CPU type can only be used with KVM, HVF, or MSHV");
         } else {
             error_setg(errp, "Failed to retrieve host CPU features");
         }
target/arm/cpu64.c +14 -10
index d6feba220e..59cb23dd99 100644
@@ -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"
@@ -821,16 +823,18 @@ static void aarch64_host_initfn(Object *obj)
     }
 #endif
 
-#if defined(CONFIG_KVM)
-    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();
-#endif
+    if (mshv_enabled()) {
+        mshv_arm_set_cpu_features_from_host(cpu);
+    } else if (kvm_enabled()) {
+        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);
     }
target/arm/mshv/mshv-all.c +204 -0

217 lines not on this page · raw message

target/arm/mshv_arm.h new file +18 -0
new file mode 100644
index 0000000000..a03f9a4405
@@ -0,0 +1,18 @@
+/*
+ * QEMU MSHV support
+ *
+ * Copyright Microsoft, Corp. 2026
+ *
+ * Authors: Aastha Rawat   <[email protected]>
+ *
+ * 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
Signature · 1 line
2.45.4
#6 lore raw

PATCH v2 6/14 accel/mshv: add arch-specific accelerator init hook

In reply to Aastha Rawat

From: "Anirudh Rayabharam (Microsoft)" <[email protected]>

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.

---
 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(-)
accel/mshv/mshv-all.c +4 -1
index 44f35a1463..6940ad9989 100644
@@ -434,7 +434,10 @@ static int mshv_init(AccelState *as, MachineState *ms)
         return -1;
     }
 
-    mshv_init_mmio_emu();
+    ret = mshv_arch_accel_init(as, ms, mshv_fd);
+    if (ret < 0) {
+        return -1;
+    }
 
     mshv_init_msicontrol();
 
include/system/mshv_int.h +1 -0
index ff3ab957b5..c72c91cd23 100644
@@ -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);
 
target/arm/mshv/mshv-all.c +19 -6
index db1174b444..8d16971c0d 100644
@@ -9,12 +9,13 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-
 #include "qemu/osdep.h"
 #include <sys/ioctl.h>
 
 #include "qemu/error-report.h"
 #include "qemu/memalign.h"
+#include "hw/arm/bsa.h"
+#include "hw/arm/virt.h"
 
 #include "system/cpus.h"
 #include "target/arm/cpu.h"
@@ -188,11 +189,6 @@ void mshv_arch_destroy_vcpu(CPUState *cpu)
     state->hvcall_args = (MshvHvCallArgs){0};
 }
 
-void mshv_init_mmio_emu(void)
-{
-
-}
-
 void mshv_arch_amend_proc_features(
     union hv_partition_synthetic_processor_features *features)
 {
@@ -394,3 +390,20 @@ void mshv_arm_set_cpu_features_from_host(ARMCPU *cpu)
     cpu->midr = arm_host_cpu_features.midr;
     cpu->reset_sctlr = arm_host_cpu_features.reset_sctlr;
 }
+
+int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd)
+{
+    MachineClass *mc = MACHINE_GET_CLASS(ms);
+    int pa_range;
+    uint32_t ipa_size;
+
+    if (mc->get_physical_address_range) {
+        ipa_size = mshv_arm_get_ipa_bit_size(mshv_fd);
+        pa_range = mc->get_physical_address_range(ms, ipa_size, ipa_size);
+        if (pa_range < 0) {
+            return -EINVAL;
+        }
+    }
+
+    return 0;
+}
target/i386/mshv/meson.build +1 -0
index 6091c21887..ce54e134cb 100644
@@ -1,6 +1,7 @@
 i386_mshv_ss = ss.source_set()
 
 i386_mshv_ss.add(files(
+  'mshv-all.c',
   'mshv-cpu.c',
   'msr.c',
 ))
target/i386/mshv/mshv-all.c new file +80 -0

80 lines not on this page · raw message

target/i386/mshv/mshv-cpu.c +0 -40
index 9a80dc34d0..8325ac74a3 100644
@@ -1482,43 +1482,3 @@ void mshv_arch_destroy_vcpu(CPUState *cpu)
     state->hvcall_args = (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 = {0};
-    struct mshv_root_hvcall args = {0};
-
-    in.property_code  = HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION;
-    in.property_value = HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZERO;
-
-    args.code   = HVCALL_SET_PARTITION_PROPERTY;
-    args.in_sz  = sizeof(in);
-    args.in_ptr = (uint64_t)&in;
-
-    trace_mshv_hvcall_args("unimplemented_msr_action", args.code, args.in_sz);
-
-    int ret = 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 = set_unimplemented_msr_action(vm_fd);
-    if (ret < 0) {
-        error_report("Failed to set unimplemented MSR action");
-    }
-
-    return ret;
-}
Signature · 1 line
2.45.4
#7 lore raw

Re: [PATCH v2 06/14] accel/mshv: add arch-specific accelerator init hook

Quoted 8 lines

+/*
+ * 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.
+ */

Hi,

Is that desirable behaviour on arm64? I think it’s better to _not_ do this there.

Thanks,
-Mohamed

#8 lore raw

Re: [PATCH v2 06/14] accel/mshv: add arch-specific accelerator init hook

Quoted 9 lines · Mohamed Mediouni
Quoted 8 lines

+/*
+ * 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.
+ */

Quoted 4 lines

Hi,

Is that desirable behaviour on arm64? I think it’s better to _not_ do this there.

This is not for arm64. This is *existing* x86 code being moved to an arch-specific directory.

Thanks,
Anirudh.

Reviewed-by on v2 6/14
#9 lore raw

Re: [PATCH v2 06/14] accel/mshv: add arch-specific accelerator init hook

In reply to Aastha Rawat
Quoted 16 lines · Aastha Rawat

From: "Anirudh Rayabharam (Microsoft)" <[email protected]>

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.

Quoted 6 lines

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.

#10 lore raw

PATCH v2 7/14 accel/mshv: Add access_vp_regs synthetic proc features

In reply to Aastha Rawat

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.

---
 accel/mshv/mshv-all.c     |  1 +
 include/hw/hyperv/hvhdk.h | 91 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 91 insertions(+), 1 deletion(-)
accel/mshv/mshv-all.c +1 -0
index 6940ad9989..5ce76e86db 100644
@@ -156,6 +156,7 @@ static int set_synthetic_proc_features(int vm_fd)
     features.tb_flush_hypercalls = 1;
     features.synthetic_cluster_ipi = 1;
     features.direct_synthetic_timers = 1;
+    features.access_vp_regs = 1;
 
     mshv_arch_amend_proc_features(&features);
 
include/hw/hyperv/hvhdk.h +90 -1

125 lines not on this page · raw message

Signature · 1 line
2.45.4
#11 lore raw

PATCH v2 8/14 target/arm: cpu: Mark MSHV supporting PSCI 1.3

In reply to Aastha Rawat

MSHV supports PSCI 1.3. Expose this version to guests.

---
 target/arm/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/arm/cpu.c +1 -1
index 8aa22747ff..67f1991622 100644
@@ -1157,7 +1157,7 @@ static void arm_cpu_initfn(Object *obj)
     if (tcg_enabled() || hvf_enabled()) {
         /* TCG and HVF implement PSCI 1.1 */
         cpu->psci_version = QEMU_PSCI_VERSION_1_1;
-    } else if (whpx_enabled()) {
+    } else if (whpx_enabled() || mshv_enabled()) {
         cpu->psci_version = QEMU_PSCI_VERSION_1_3;
     }
 }
Signature · 1 line
2.45.4
#12 lore raw

PATCH v2 9/14 accel/mshv: implement cpu_thread_is_idle() hook

In reply to Aastha Rawat

From: Magnus Kulke <[email protected]>

In MSHV the hypervisor APIC is always used, so we to implement this hook to make sure the AP's vcpu thread is not blocked waiting for an INIT SIPI by the BSP. Without this change soft reboots with -smp cpus>=2 will hang.

---
 accel/mshv/mshv-all.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
accel/mshv/mshv-all.c +12 -0
index 5ce76e86db..6c0ddbf3ca 100644
@@ -704,11 +704,23 @@ static const TypeInfo mshv_accel_type = {
     .instance_size = sizeof(MshvState),
 };
 
+/*
+ * MSHV manages the LAPIC in the hypervisor. SIPI for APs are handled
+ * internally. Halted vCPUs must still enter mshv_cpu_exec() so that
+ * MSHV_RUN_VP is called and the hypervisor will deliver SIPI to wake APs.
+ */
+
+static bool mshv_vcpu_thread_is_idle(CPUState *cpu)
+{
+    return false;
+}
+
 static void mshv_accel_ops_class_init(ObjectClass *oc, const void *data)
 {
     AccelOpsClass *ops = ACCEL_OPS_CLASS(oc);
 
     ops->create_vcpu_thread = mshv_start_vcpu_thread;
+    ops->cpu_thread_is_idle = mshv_vcpu_thread_is_idle;
     ops->synchronize_post_init = mshv_cpu_synchronize_post_init;
     ops->synchronize_post_reset = mshv_cpu_synchronize_post_reset;
     ops->synchronize_state = mshv_cpu_synchronize;
Signature · 1 line
2.45.4
#13 lore raw

PATCH v2 10/14 target/arm: extract MMIO emulation logic for HVF & WHPX

In reply to Aastha Rawat

- 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.

---
 target/arm/helper.c        | 60 +++++++++++++++++++++++++++++++++++++++++++
 target/arm/helper.h        |  5 ++++
 target/arm/hvf/hvf.c       | 64 ++++++++++++++++++++++++----------------------
 target/arm/syndrome.h      | 37 +++++++++++++++++++++++++++
 target/arm/whpx/whpx-all.c | 62 +++++++++++---------------------------------
 5 files changed, 150 insertions(+), 78 deletions(-)
target/arm/helper.c +60 -0
index 7389f2988c..c9457c8384 100644
@@ -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"
 
 static void switch_mode(CPUARMState *env, int mode);
@@ -9130,6 +9132,64 @@ static void arm_cpu_do_interrupt_aarch32(CPUState *cs)
     take_aarch32_exception(env, new_mode, mask, offset, addr);
 }
 
+/*
+ * Emulate a data abort syndrome for MMIO/guest memory access
+ */
+int arm_emulate_mmio(CPUState *cpu, EsrEl2 syndrome, uint64_t gpa)
+{
+    CPUARMState *env = &ARM_CPU(cpu)->env;
+    int ret;
+    IssDataAbort iss = { 0 };
+    iss.raw = syndrome.iss;
+
+    if (!(syndrome.ec == data_abort_lower || syndrome.ec == data_abort)) {
+        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 = cpu_get_address_space(cpu, ARMASIdx_NS);
+    uint64_t len = 1ULL << iss.sas;
+    bool sign_extend = iss.sse;
+    uint64_t reg_index = iss.srt;
+
+    if (iss.wnr) {
+        uint8_t data[8];
+        uint64_t val = reg_index < 31 ? env->xregs[reg_index] : 0ULL;
+        val = cpu_to_le64(val);
+        memcpy(data, &val, sizeof(val));
+        ret = address_space_write(as, gpa, MEMTXATTRS_UNSPECIFIED, data, len);
+        if (ret != MEMTX_OK) {
+            error_report("Failed to write guest memory");
+            return -1;
+        }
+    } else {
+        uint8_t data[8] = { 0 };
+        ret = address_space_read(as, gpa, MEMTXATTRS_UNSPECIFIED, data, len);
+        if (ret != MEMTX_OK) {
+            error_report("Failed to read guest memory");
+            return -1;
+        }
+        uint64_t val;
+        memcpy(&val, data, sizeof(val));
+        val = le64_to_cpu(val);
+        if (sign_extend) {
+            uint64_t shift = 64 - (len * 8);
+            val = (((int64_t)val << shift) >> shift);
+        }
+        if (!iss.sf) {
+            val &= 0xffffffff;
+        }
+        env->xregs[reg_index] = val;
+    }
+
+    return 0;
+}
+
 static int aarch64_regnum(CPUARMState *env, int aarch32_reg)
 {
     /*
target/arm/helper.h +5 -0
index b1c26c180e..3bc22595fd 100644
@@ -3,8 +3,13 @@
 #ifndef HELPER__H
 #define HELPER__H
 
+#include <stdint.h>
+#include <stdbool.h>
 #include "exec/helper-proto-common.h"
 #include "exec/helper-gen-common.h"
+#include "target/arm/syndrome.h"
+
+int arm_emulate_mmio(CPUState *cpu, EsrEl2 syndrome, uint64_t gpa);
 
 #define HELPER_H "tcg/helper-defs.h"
 #include "exec/helper-proto.h.inc"
target/arm/hvf/hvf.c +33 -31

113 lines not on this page · raw message

target/arm/syndrome.h +37 -0
index bff61f052c..777d4fb975 100644
@@ -101,6 +101,43 @@ typedef enum {
     GCS_IT_GCSPOPX = 9,
 } GCSInstructionType;
 
+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 = 36,
+    data_abort = 37,
+} ExceptionClass;
+
 #define ARM_EL_EC_LENGTH 6
 #define ARM_EL_EC_SHIFT 26
 #define ARM_EL_IL_SHIFT 25
target/arm/whpx/whpx-all.c +15 -47

80 lines not on this page · raw message

Signature · 1 line
2.45.4
#14 lore raw

PATCH v2 11/14 target/arm/mshv: add vCPU run loop

In reply to Aastha Rawat

From: "Anirudh Rayabharam (Microsoft)" <[email protected]>

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.

---
 include/hw/hyperv/hvgdk_mini.h | 44 +++++++++++++++++++
 target/arm/mshv/mshv-all.c     | 95 ++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 139 insertions(+)
include/hw/hyperv/hvgdk_mini.h +44 -0
index d56be0d70f..84b3c6af5f 100644
@@ -750,6 +750,50 @@ struct hv_x64_memory_intercept_message {
     uint8_t instruction_bytes[16];
 };
 
+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 {
target/arm/mshv/mshv-all.c +95 -0

109 lines not on this page · raw message

Signature · 1 line
2.45.4
#15 lore raw

PATCH v2 12/14 include/hw/hyperv: adjust hv_interrupt_control structure for arm64

In reply to Aastha Rawat

From: "Anirudh Rayabharam (Microsoft)" <[email protected]>

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.

---
 accel/mshv/irq.c               |  2 ++
 include/hw/hyperv/hvgdk_mini.h | 25 +++++++++++++++++++++++++
 include/system/mshv.h          |  2 ++
 3 files changed, 29 insertions(+)
accel/mshv/irq.c +2 -0
index 3c238c33c3..a391d7db86 100644
@@ -310,6 +310,7 @@ int mshv_irqchip_update_msi_route(int virq, MSIMessage msg, PCIDevice *dev)
     return 0;
 }
 
+#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)
@@ -346,6 +347,7 @@ int mshv_request_interrupt(MshvState *mshv_state, uint32_t interrupt_type, uint3
     }
     return 0;
 }
+#endif
 
 void mshv_irqchip_commit_routes(void)
 {
include/hw/hyperv/hvgdk_mini.h +25 -0
index 84b3c6af5f..eb766734d6 100644
@@ -506,13 +506,38 @@ typedef struct hv_input_set_vp_registers {
     struct hv_register_assoc elements[];
 } hv_input_set_vp_registers;
 
+enum hv_interrupt_type {
+#if defined(__x86_64__)
+    HV_X64_INTERRUPT_TYPE_FIXED             = 0x0000,
+    HV_X64_INTERRUPT_TYPE_LOWESTPRIORITY    = 0x0001,
+    HV_X64_INTERRUPT_TYPE_SMI               = 0x0002,
+    HV_X64_INTERRUPT_TYPE_REMOTEREAD        = 0x0003,
+    HV_X64_INTERRUPT_TYPE_NMI               = 0x0004,
+    HV_X64_INTERRUPT_TYPE_INIT              = 0x0005,
+    HV_X64_INTERRUPT_TYPE_SIPI              = 0x0006,
+    HV_X64_INTERRUPT_TYPE_EXTINT            = 0x0007,
+    HV_X64_INTERRUPT_TYPE_LOCALINT0         = 0x0008,
+    HV_X64_INTERRUPT_TYPE_LOCALINT1         = 0x0009,
+    HV_X64_INTERRUPT_TYPE_MAXIMUM           = 0x000A,
+#elif defined(__aarch64__)
+    HV_ARM64_INTERRUPT_TYPE_FIXED           = 0x0000,
+    HV_ARM64_INTERRUPT_TYPE_MAXIMUM         = 0x0008,
+#endif
+};
+
 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
     };
 };
 
include/system/mshv.h +2 -0
index 75286baf16..0db18fcee9 100644
@@ -47,10 +47,12 @@ extern bool mshv_allowed;
 typedef struct MshvState MshvState;
 extern MshvState *mshv_state;
 
+#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_mode,
                            bool level_triggered);
+#endif
 
 int mshv_irqchip_add_msi_route(int vector, PCIDevice *dev);
 int mshv_irqchip_update_msi_route(int virq, MSIMessage msg, PCIDevice *dev);
Signature · 1 line
2.45.4
#16 lore raw

PATCH v2 13/14 hw/intc,target/arm/mshv: add MSHV vGICv3 implementation

In reply to Aastha Rawat

From: "Anirudh Rayabharam (Microsoft)" <[email protected]>

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).

---
 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         |  62 +++++++++++++
 target/i386/mshv/mshv-all.c        |   5 +
 11 files changed, 271 insertions(+), 4 deletions(-)
accel/mshv/mshv-all.c +5 -0
index 6c0ddbf3ca..628cd0ad17 100644
@@ -200,6 +200,11 @@ static int create_vm(int mshv_fd, int *vm_fd)
         return -1;
     }
 
+    ret = mshv_arch_pre_init_vm(*vm_fd);
+    if (ret < 0) {
+        return -1;
+    }
+
     ret = initialize_vm(*vm_fd);
     if (ret < 0) {
         return -1;
hw/arm/virt.c +4 -4
index 34eb5248a9..5f922ece9c 100644
@@ -2117,7 +2117,7 @@ static void finalize_gic_version(VirtMachineState *vms)
         /* KVM w/o kernel irqchip can only deal with GICv2 */
         gics_supported |= VIRT_GIC_VERSION_2_MASK;
         accel_name = "KVM with kernel-irqchip=off";
-    } else if (whpx_enabled()) {
+    } else if (whpx_enabled() || mshv_enabled()) {
         gics_supported |= VIRT_GIC_VERSION_3_MASK;
     } else if (tcg_enabled() || hvf_enabled() || qtest_enabled())  {
         gics_supported |= VIRT_GIC_VERSION_2_MASK;
@@ -2159,7 +2159,7 @@ static void finalize_msi_controller(VirtMachineState *vms)
     if (vms->msi_controller == VIRT_MSI_CTRL_AUTO) {
         if (vms->gic_version == VIRT_GIC_VERSION_2) {
             vms->msi_controller = VIRT_MSI_CTRL_GICV2M;
-        } else if (whpx_enabled()) {
+        } else if (whpx_enabled() || mshv_enabled()) {
             vms->msi_controller = VIRT_MSI_CTRL_GICV2M;
         } else {
             vms->msi_controller = 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);
         }
     }
hw/intc/arm_gicv3_common.c +3 -0
index 9200671c7a..239c645ab9 100644
@@ -33,6 +33,7 @@
 #include "hw/arm/linux-boot-if.h"
 #include "system/kvm.h"
 #include "system/whpx.h"
+#include "system/mshv.h"
 
 
 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");
hw/intc/arm_gicv3_mshv.c new file +181 -0

181 lines not on this page · raw message

hw/intc/meson.build +1 -0
index 96742df090..9d824db582 100644
@@ -43,6 +43,7 @@ arm_common_ss.add(when: 'CONFIG_ARM_GICV3', if_true: files('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('arm_gicv3_whpx.c'))
 specific_ss.add(when: ['CONFIG_ARM_GIC_KVM', 'TARGET_AARCH64'], if_true: files('arm_gicv3_kvm.c', 'arm_gicv3_its_kvm.c'))
+specific_ss.add(when: ['CONFIG_MSHV', 'TARGET_AARCH64'], if_true: files('arm_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'))
include/hw/hyperv/hvgdk_mini.h +2 -0
index eb766734d6..b50a65a0d4 100644
@@ -66,6 +66,8 @@ typedef enum hv_register_name {
     HV_ARM64_REGISTER_MIDR_EL1   = 0x00040051,
     HV_ARM64_REGISTER_MPIDR_EL1  = 0x00040001,
 
+    HV_ARM64_REGISTER_GICR_BASE_GPA       = 0x00063000,
+
 #elif defined(__x86_64__)
     /* X64 User-Mode Registers */
     HV_X64_REGISTER_RAX     = 0x00020000,
include/hw/hyperv/hvhdk_mini.h +6 -0
index 9c2f3cf5ae..4d78fa0677 100644
@@ -62,6 +62,12 @@ enum hv_partition_property_code {
     HV_PARTITION_PROPERTY_ISOLATION_POLICY                       = 0x00050014,
     HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION               = 0x00050017,
     HV_PARTITION_PROPERTY_SEV_VMGEXIT_OFFLOADS                   = 0x00050022,
+    HV_PARTITION_PROPERTY_GICD_BASE_ADDRESS                      = 0x00050028,
+    HV_PARTITION_PROPERTY_GITS_TRANSLATER_BASE_ADDRESS           = 0x00050029,
+    HV_PARTITION_PROPERTY_GIC_LPI_INT_ID_BITS                    = 0x0005002A,
+    HV_PARTITION_PROPERTY_GIC_PPI_OVERFLOW_INTERRUPT_FROM_CNTV   = 0x0005002B,
+    HV_PARTITION_PROPERTY_GIC_PPI_OVERFLOW_INTERRUPT_FROM_CNTP   = 0x0005002C,
+    HV_PARTITION_PROPERTY_GIC_PPI_PERFORMANCE_MONITORS_INTERRUPT = 0x0005002D,
 
     /* Compatibility properties */
     HV_PARTITION_PROPERTY_PROCESSOR_VENDOR              = 0x00060000,
include/hw/intc/arm_gicv3_common.h +1 -0
index c55cf18120..3baac1a35c 100644
@@ -315,6 +315,7 @@ DECLARE_OBJ_CHECKERS(GICv3State, ARMGICv3CommonClass,
 
 /* Types for GICv3 kernel-irqchip */
 #define TYPE_WHPX_GICV3 "whpx-arm-gicv3"
+#define TYPE_MSHV_GICV3 "mshv-arm-gicv3"
 
 struct ARMGICv3CommonClass {
     /*< private >*/
include/system/mshv_int.h +1 -0
index c72c91cd23..0ef98abedf 100644
@@ -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);
 
target/arm/mshv/mshv-all.c +62 -0

68 lines not on this page · raw message

target/i386/mshv/mshv-all.c +5 -0
index f0b43aa86f..ce8b426ea4 100644
@@ -39,6 +39,11 @@ int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd)
     return 0;
 }
 
+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
Signature · 1 line
2.45.4
#17 lore raw

PATCH v2 14/14 MAINTAINERS: updates for MSHV arm64 code

In reply to Aastha Rawat

From: "Anirudh Rayabharam (Microsoft)" <[email protected]>

Add myself and Aastha Rawat as maintainers.

Add Magnus Kulke as reviewer.

---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index 9d1614fd7e..e36b10a8dc 100644
@@ -606,6 +606,14 @@ R: Wei Liu <[email protected]>
 S: Supported
 F: target/i386/mshv/
 
+ARM64 MSHV CPUs
+M: Anirudh Rayabharam <[email protected]>
+M: Aastha Rawat <[email protected]>
+R: Magnus Kulke <[email protected]>
+S: Supported
+F: target/arm/mshv/
+F: hw/intc/arm_gicv3_mshv.c
+
 X86 Instruction Emulator
 M: Cameron Esfahani <[email protected]>
 M: Roman Bolshakov <[email protected]>
Signature · 1 line
2.45.4