WHPX support for Arm
v4 cover WHPX support for Arm
Link to branch: https://github.com/mediouni-m/qemu whpx (tag for this submission: whpx-v3)
Missing features:
- PSCI state sync with Hyper-V: notably breaks reboots when multiple cores are enabled
- Interrupt controller save-restore
- Debug register sync
- SVE register sync
- Adding a migration blocker because of the items above.
Note:
"accel/system: Introduce hwaccel_enabled() helper" taken from the mailing list, added here as part of this series to make it compilable as a whole.
"hw/arm: virt: add GICv2m for the case when ITS is not available" present in both the HVF vGIC and this series.
Updates since v3:
- Disabling SVE on WHPX
- Taking into account review comments incl:
- fixing x86 support
- reduce the amount of __x86_64__ checks in common code to the minimum (winhvemulation) which can be reduced even further down the road.
- generalize get_physical_address_range into something common between hvf and whpx
Updates since v2:
- Fixed up a rebase screwup for whpx-internal.h
- Fixed ID_AA64ISAR1_EL1 and ID_AA64ISAR2_EL1 feature probe for -cpu host
- Switched to ID_AA64PFR1_EL1/ID_AA64DFR0_EL1 instead of their non-AA64 variant
Updates since v1:
- Shutdowns and reboots
- MPIDR_EL1 register sync
- Fixing GICD_TYPER_LPIS value
- IPA size clamping
- -cpu host now implemented
Mohamed Mediouni (16):
hw/arm: virt: add GICv2m for the case when ITS is not available
whpx: Move around files before introducing AArch64 support
whpx: reshuffle common code
whpx: ifdef out winhvemulation on non-x86_64
whpx: common: add WHPX_INTERCEPT_DEBUG_TRAPS define
hw, target, accel: whpx: change apic_in_platform to kernel_irqchip
whpx: interrupt controller support
whpx: add arm64 support
whpx: copy over memory management logic from hvf target/arm: cpu: mark WHPX as supporting PSCI 1.1
hw/arm: virt: cleanly fail on attempt to use the platform vGIC
together with ITS
whpx: arm64: clamp down IPA size
hw/arm, accel/hvf, whpx: unify get_physical_address_range between WHPX
and HVF
whpx: arm64: implement -cpu host
target/arm: whpx: instantiate GIC early
MAINTAINERS: Add myself as a maintainer for WHPX
Philippe Mathieu-Daudé (1):
accel/system: Introduce hwaccel_enabled() helper
MAINTAINERS | 9 +-
accel/hvf/hvf-all.c | 7 +-
accel/meson.build | 1 +
accel/whpx/meson.build | 7 +
{target/i386 => accel}/whpx/whpx-accel-ops.c | 6 +-
accel/whpx/whpx-common.c | 666 +++++++++++
hw/arm/virt-acpi-build.c | 4 +-
hw/arm/virt.c | 34 +-
hw/i386/x86-cpu.c | 4 +-
hw/intc/arm_gicv3_common.c | 3 +
hw/intc/arm_gicv3_whpx.c | 261 +++++
hw/intc/meson.build | 1 +
include/hw/arm/virt.h | 2 +
include/hw/boards.h | 3 +-
include/hw/intc/arm_gicv3_common.h | 3 +
include/system/hvf_int.h | 2 +
include/system/hw_accel.h | 13 +
.../whpx => include/system}/whpx-accel-ops.h | 4 +-
include/system/whpx-all.h | 20 +
include/system/whpx-common.h | 26 +
.../whpx => include/system}/whpx-internal.h | 14 +-
include/system/whpx.h | 4 +-
meson.build | 21 +-
target/arm/cpu.c | 3 +-
target/arm/cpu64.c | 19 +-
target/arm/hvf-stub.c | 20 -
target/arm/hvf/hvf.c | 6 +-
target/arm/hvf_arm.h | 3 -
target/arm/meson.build | 2 +-
target/arm/whpx/meson.build | 5 +
target/arm/whpx/whpx-all.c | 1021 +++++++++++++++++
target/arm/whpx/whpx-stub.c | 15 +
target/arm/whpx_arm.h | 17 +
target/i386/cpu-apic.c | 2 +-
target/i386/hvf/hvf.c | 10 +
target/i386/whpx/meson.build | 1 -
target/i386/whpx/whpx-all.c | 569 +--------
target/i386/whpx/whpx-apic.c | 2 +-
38 files changed, 2191 insertions(+), 619 deletions(-)
create mode 100644 accel/whpx/meson.build
rename {target/i386 => accel}/whpx/whpx-accel-ops.c (96%)
create mode 100644 accel/whpx/whpx-common.c
create mode 100644 hw/intc/arm_gicv3_whpx.c
rename {target/i386/whpx => include/system}/whpx-accel-ops.h (92%)
create mode 100644 include/system/whpx-all.h
create mode 100644 include/system/whpx-common.h
rename {target/i386/whpx => include/system}/whpx-internal.h (96%)
delete mode 100644 target/arm/hvf-stub.c
create mode 100644 target/arm/whpx/meson.build
create mode 100644 target/arm/whpx/whpx-all.c
create mode 100644 target/arm/whpx/whpx-stub.c
create mode 100644 target/arm/whpx_arm.hSignature · 1 line
2.39.5 (Apple Git-154)
PATCH v4 1/17 accel/system: Introduce hwaccel_enabled() helper
From: Philippe Mathieu-Daudé <[email protected]>
hwaccel_enabled() return whether any hardware accelerator is available.
--- include/system/hw_accel.h | 13 +++++++++++++ 1 file changed, 13 insertions(+)
include/system/hw_accel.h +13 -0
@@ -39,4 +39,17 @@ void cpu_synchronize_pre_loadvm(CPUState *cpu);void cpu_synchronize_post_reset (CPUState *cpu);void cpu_synchronize_post_init (CPUState *cpu); +/** +* hwaccel_enabled: +* +* Returns: %true if a hardware accelerator is enabled, %false otherwise. +*/ +static inline bool hwaccel_enabled (void ) +{ +return hvf_enabled () + ||kvm_enabled () + ||nvmm_enabled () + ||whpx_enabled (); +} +#endif /* QEMU_HW_ACCEL_H */
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 01/17] accel/system: Introduce hwaccel_enabled() helper
Quoted 4 lines · Mohamed Mediouni
From: Philippe Mathieu-Daudé <[email protected]>
hwaccel_enabled()return whether any hardware accelerator is available.
Available or enabled?
Ciao,
Claudio
Re: [PATCH v4 01/17] accel/system: Introduce hwaccel_enabled() helper
Quoted 10 lines · Claudio Fontana
Quoted 4 lines · Mohamed Mediouni
From: Philippe Mathieu-Daudé <[email protected]>
hwaccel_enabled()return whether any hardware accelerator is available.Available or enabled?
enabled
Took the patch from https://lore.kernel.org/qemu-devel/[email protected]/
Should I edit the commit message locally or will be taken care of when it gets merged on that series?
Thank you,
Re: [PATCH v4 01/17] accel/system: Introduce hwaccel_enabled() helper
Quoted 11 lines · Mohamed Mediouni
Quoted 10 lines · Claudio Fontana
Quoted 4 lines · Mohamed Mediouni
From: Philippe Mathieu-Daudé <[email protected]>
hwaccel_enabled()return whether any hardware accelerator is available.Available or enabled?
enabled
Oops indeed.
Orthogonal, but still not trivial to follow available (built in?) / loaded (as module) / enabled (selected?) / usable (permissions OK) logic (there is also another state, but I don't remember right now).
Quoted 4 lines
Took the patch from https://lore.kernel.org/qemu- devel/[email protected]/ <https:// lore.kernel.org/qemu-devel/[email protected]/>
Should I edit the commit message locally or will be taken care of when it gets merged on that series?
I'll do it.
Thanks!
PATCH v4 2/17 hw/arm: virt: add GICv2m for the case when ITS is not available
In reply to Mohamed MediouniOn Hypervisor.framework for macOS and WHPX for Windows, the provided environment is a GICv3 without ITS.
As such, support a GICv3 w/ GICv2m for that scenario.
--- hw/arm/virt-acpi-build.c | 4 +++- hw/arm/virt.c | 8 ++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-)
hw/arm/virt-acpi-build.c +3 -1
@@ -848,7 +848,9 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)build_append_int_noprefix (table_data, memmap[VIRT_GIC_ITS ].base,8 );build_append_int_noprefix (table_data,0 ,4 );/* Reserved */ } - }else { + } + +if (!vms->its && !vms->no_gicv3_with_gicv2m) {const uint16_t spi_base = vms->irqmap[VIRT_GIC_V2M ] +ARM_SPI_BASE ;/* 5.2.12.16 GIC MSI Frame Structure */
hw/arm/virt.c +8 -0
@@ -953,6 +953,8 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)if (vms->gic_version !=VIRT_GIC_VERSION_2 && vms->its) {create_its (vms); + }else if (vms->gic_version !=VIRT_GIC_VERSION_2 && !vms->no_gicv3_with_gicv2m) { +create_v2m (vms); }else if (vms->gic_version ==VIRT_GIC_VERSION_2 ) {create_v2m (vms); }
@@ -2402,6 +2404,8 @@ static void machvirt_init(MachineState *machine) vms->ns_el2_virt_timer_irq =ns_el2_virt_timer_present () && !vmc->no_ns_el2_virt_timer_irq; + vms->no_gicv3_with_gicv2m = vmc->no_gicv3_with_gicv2m; +fdt_add_timer_nodes (vms);fdt_add_cpu_nodes (vms);
@@ -3410,6 +3414,7 @@ static void virt_instance_init(Object *obj) vms->its = true;/* Allow ITS emulation if the machine version supports it */ vms->tcg_its = !vmc->no_tcg_its; + vms->no_gicv3_with_gicv2m = false;/* Default disallows iommu instantiation */ vms->iommu =VIRT_IOMMU_NONE ;
@@ -3462,8 +3467,11 @@ DEFINE_VIRT_MACHINE_AS_LATEST(10, 1)static void virt_machine_10_0_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); +virt_machine_10_1_options (mc);compat_props_add (mc->compat_props, hw_compat_10_0, hw_compat_10_0_len); + vmc->no_gicv3_with_gicv2m = true; }DEFINE_VIRT_MACHINE (10 ,0 )
include/hw/arm/virt.h +2 -0
@@ -131,6 +131,7 @@ struct VirtMachineClass {bool no_cpu_topology;bool no_tcg_lpa2;bool no_ns_el2_virt_timer_irq; +bool no_gicv3_with_gicv2m;bool no_nested_smmu; };
@@ -178,6 +179,7 @@ struct VirtMachineState {char *oem_id;char *oem_table_id;bool ns_el2_virt_timer_irq; +bool no_gicv3_with_gicv2m;CXLState cxl_devices_state; };
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 02/17] hw/arm: virt: add GICv2m for the case when ITS is not available
Quoted 81 lines · Mohamed Mediouni
On Hypervisor.framework for macOS and WHPX for Windows, the provided environment is a GICv3 without ITS.
As such, support a GICv3 w/ GICv2m for that scenario.
Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt-acpi-build.c | 4 +++- hw/arm/virt.c | 8 ++++++++ include/hw/arm/virt.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-)hw/arm/virt-acpi-build.c +3
-1@@ -848,7 +848,9 @@ build_madt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)build_append_int_noprefix (table_data, memmap[VIRT_GIC_ITS ].base,8 );build_append_int_noprefix (table_data,0 ,4 );/* Reserved */ } - }else { + } + +if (!vms->its && !vms->no_gicv3_with_gicv2m) {const uint16_t spi_base = vms->irqmap[VIRT_GIC_V2M ] +ARM_SPI_BASE ;/* 5.2.12.16 GIC MSI Frame Structure */ hw/arm/virt.c +8
-0@@ -953,6 +953,8 @@ static void create_gic(VirtMachineState *vms, MemoryRegion *mem)if (vms->gic_version !=VIRT_GIC_VERSION_2 && vms->its) {create_its (vms); + }else if (vms->gic_version !=VIRT_GIC_VERSION_2 && !vms->no_gicv3_with_gicv2m) { +create_v2m (vms); }else if (vms->gic_version ==VIRT_GIC_VERSION_2 ) {create_v2m (vms); }@@ -2402,6 +2404,8 @@ static void machvirt_init(MachineState *machine) vms->ns_el2_virt_timer_irq =ns_el2_virt_timer_present () && !vmc->no_ns_el2_virt_timer_irq; + vms->no_gicv3_with_gicv2m = vmc->no_gicv3_with_gicv2m; +fdt_add_timer_nodes (vms);fdt_add_cpu_nodes (vms);@@ -3410,6 +3414,7 @@ static void virt_instance_init(Object *obj) vms->its = true;/* Allow ITS emulation if the machine version supports it */ vms->tcg_its = !vmc->no_tcg_its; + vms->no_gicv3_with_gicv2m = false;/* Default disallows iommu instantiation */ vms->iommu =VIRT_IOMMU_NONE ;@@ -3462,8 +3467,11 @@ DEFINE_VIRT_MACHINE_AS_LATEST(10, 1)static void virt_machine_10_0_options (MachineClass *mc) { +VirtMachineClass *vmc =VIRT_MACHINE_CLASS (OBJECT_CLASS (mc)); +virt_machine_10_1_options (mc);compat_props_add (mc->compat_props, hw_compat_10_0, hw_compat_10_0_len); + vmc->no_gicv3_with_gicv2m = true; }DEFINE_VIRT_MACHINE (10 ,0 )include/hw/arm/virt.h +1
-0@@ -131,6 +131,7 @@ struct VirtMachineClass {bool no_cpu_topology;bool no_tcg_lpa2;bool no_ns_el2_virt_timer_irq; +bool no_gicv3_with_gicv2m;bool no_nested_smmu; };
include/hw/arm/virt.h struct VirtMachineState { · line 185
Quoted 7 lines
include/hw/arm/virt.h +1
-0@@ -178,6 +179,7 @@ struct VirtMachineState {char *oem_id;char *oem_table_id;bool ns_el2_virt_timer_irq; +bool no_gicv3_with_gicv2m;CXLState cxl_devices_state; };
I'm not an expert about GIC, but this patch looks sane to me.
PATCH v4 3/17 whpx: Move around files before introducing AArch64 support
In reply to Mohamed MediouniSwitch to a design where we can share whpx code between x86 and AArch64 when it makes sense to do so.
---
MAINTAINERS | 2 ++
accel/meson.build | 1 +
accel/whpx/meson.build | 6 ++++++
{target/i386 => accel}/whpx/whpx-accel-ops.c | 4 ++--
{target/i386/whpx => include/system}/whpx-accel-ops.h | 4 ++--
{target/i386/whpx => include/system}/whpx-internal.h | 5 +++--
target/i386/whpx/meson.build | 1 -
target/i386/whpx/whpx-all.c | 4 ++--
target/i386/whpx/whpx-apic.c | 2 +-
9 files changed, 19 insertions(+), 10 deletions(-)
create mode 100644 accel/whpx/meson.build
rename {target/i386 => accel}/whpx/whpx-accel-ops.c (97%)
rename {target/i386/whpx => include/system}/whpx-accel-ops.h (92%)
rename {target/i386/whpx => include/system}/whpx-internal.h (98%)MAINTAINERS +2 -0
@@ -542,9 +542,11 @@ F: include/system/hvf_int.h WHPX CPUs M: Sunil Muthuswamy <[email protected]> S: Supported +F: accel/whpx/ F: target/i386/whpx/ F: accel/stubs/whpx-stub.c F: include/system/whpx.h +F: include/system/whpx-accel-ops.h X86 Instruction Emulator M: Cameron Esfahani <[email protected]>
accel/meson.build +1 -0
@@ -6,6 +6,7 @@ user_ss.add(files('accel-user.c')) subdir('tcg') if have_system subdir('hvf') + subdir('whpx') subdir('qtest') subdir('kvm') subdir('xen')
accel/whpx/meson.build new file +6 -0
@@ -0,0 +1,6 @@ +whpx_ss = ss.source_set() +whpx_ss.add(files( + 'whpx-accel-ops.c', +)) + +specific_ss.add_all(when: 'CONFIG_WHPX', if_true: whpx_ss)
accel/whpx/whpx-accel-ops.c renamed from target/i386/whpx/whpx-accel-ops.c +2 -2
@@ -16,8 +16,8 @@#include "qemu/guest-random.h" #include "system/whpx.h" -#include "whpx-internal.h" -#include "whpx-accel-ops.h" +#include "system/whpx-internal.h" +#include "system/whpx-accel-ops.h" static void *whpx_cpu_thread_fn (void *arg) {
include/system/whpx-accel-ops.h renamed from target/i386/whpx/whpx-accel-ops.h +2 -2
@@ -7,8 +7,8 @@* See the COPYING file in the top-level directory. */ -#ifndef TARGET_I386_WHPX_ACCEL_OPS_H -#define TARGET_I386_WHPX_ACCEL_OPS_H +#ifndef SYSTEM_WHPX_ACCEL_OPS_H +#define SYSTEM_WHPX_ACCEL_OPS_H #include "system/cpus.h"
include/system/whpx-internal.h renamed from target/i386/whpx/whpx-internal.h +3 -2
@@ -1,5 +1,6 @@ -#ifndef TARGET_I386_WHPX_INTERNAL_H -#define TARGET_I386_WHPX_INTERNAL_H +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef SYSTEM_WHPX_INTERNAL_H +#define SYSTEM_WHPX_INTERNAL_H #include <windows.h> #include <winhvplatform.h>
target/i386/whpx/meson.build +0 -1
@@ -1,5 +1,4 @@ i386_system_ss.add(when: 'CONFIG_WHPX', if_true: files( 'whpx-all.c', 'whpx-apic.c', - 'whpx-accel-ops.c', ))
target/i386/whpx/whpx-all.c +2 -2
@@ -31,8 +31,8 @@#include "accel/accel-cpu-target.h" #include <winerror.h> -#include "whpx-internal.h" -#include "whpx-accel-ops.h" +#include "system/whpx-internal.h" +#include "system/whpx-accel-ops.h" #include <winhvplatform.h> #include <winhvemulation.h>
target/i386/whpx/whpx-apic.c +1 -1
@@ -18,7 +18,7 @@#include "hw/pci/msi.h" #include "system/hw_accel.h" #include "system/whpx.h" -#include "whpx-internal.h" +#include "system/whpx-internal.h" struct whpx_lapic_state { struct {
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 03/17] whpx: Move around files before introducing AArch64 support
Quoted 17 lines · Mohamed Mediouni
Switch to a design where we can share whpx code between x86 and AArch64 when it makes sense to do so.
Signed-off-by Mohamed Mediouni <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- MAINTAINERS | 2 ++ accel/meson.build | 1 + accel/whpx/meson.build | 6 ++++++ {target/i386 => accel}/whpx/whpx-accel-ops.c | 4 ++-- {target/i386/whpx => include/system}/whpx-accel-ops.h | 4 ++-- {target/i386/whpx => include/system}/whpx-internal.h | 5 +++-- target/i386/whpx/meson.build | 1 - target/i386/whpx/whpx-all.c | 4 ++-- target/i386/whpx/whpx-apic.c | 2 +- 9 files changed, 19 insertions(+), 10 deletions(-)
Quoted 4 lines
create mode 100644 accel/whpx/meson.build
rename {target/i386 =>accel}/whpx/whpx-accel-ops.c(97%) rename {target/i386/whpx =>include/system}/whpx-accel-ops.h(92%) rename {target/i386/whpx =>include/system}/whpx-internal.h(98%)
PATCH v4 4/17 whpx: reshuffle common code
In reply to Mohamed MediouniSome code can be shared between x86_64 and arm64 WHPX. Do so as much as reasonable.
--- MAINTAINERS | 2 + accel/whpx/meson.build | 1 + accel/whpx/whpx-common.c | 564 +++++++++++++++++++++++++++++++++++ include/system/whpx-all.h | 20 ++ include/system/whpx-common.h | 21 ++ target/i386/whpx/whpx-all.c | 551 +--------------------------------- 6 files changed, 618 insertions(+), 541 deletions(-) create mode 100644 accel/whpx/whpx-common.c create mode 100644 include/system/whpx-all.h create mode 100644 include/system/whpx-common.h
MAINTAINERS +2 -0
@@ -547,6 +547,8 @@ F: target/i386/whpx/ F: accel/stubs/whpx-stub.c F: include/system/whpx.h F: include/system/whpx-accel-ops.h +F: include/system/whpx-common.h +F: include/system/whpx-internal.h X86 Instruction Emulator M: Cameron Esfahani <[email protected]>
accel/whpx/meson.build +1 -0
@@ -1,6 +1,7 @@ whpx_ss = ss.source_set() whpx_ss.add(files( 'whpx-accel-ops.c', + 'whpx-common.c' )) specific_ss.add_all(when: 'CONFIG_WHPX', if_true: whpx_ss)
accel/whpx/whpx-common.c new file +564 -0
564 lines not on this page · raw message
include/system/whpx-all.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef SYSTEM_WHPX_ALL_H +#define SYSTEM_WHPX_ALL_H + +/* Called by whpx-common */ +int whpx_vcpu_run (CPUState *cpu); +void whpx_get_registers (CPUState *cpu); +void whpx_set_registers (CPUState *cpu,int level); +int whpx_accel_init (AccelState *as,MachineState *ms); +void whpx_cpu_instance_init (CPUState *cs); +HRESULT whpx_set_exception_exit_bitmap (UINT64 exceptions); +void whpx_apply_breakpoints ( +struct whpx_breakpoint_collection *breakpoints, +CPUState *cpu, +bool resuming); +void whpx_translate_cpu_breakpoints ( +struct whpx_breakpoints *breakpoints, +CPUState *cpu, +int cpu_breakpoint_count); +#endif
include/system/whpx-common.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef SYSTEM_WHPX_COMMON_H +#define SYSTEM_WHPX_COMMON_H + +struct AccelCPUState { +WHV_EMULATOR_HANDLE emulator; +bool window_registered; +bool interruptable; +bool ready_for_pic_interrupt; +uint64_t tpr; +uint64_t apic_base; +bool interruption_pending; +/* Must be the last field as it may have a tail */ +WHV_RUN_VP_EXIT_CONTEXT exit_ctx; +}; + +int whpx_first_vcpu_starting (CPUState *cpu); +int whpx_last_vcpu_stopping (CPUState *cpu); +void whpx_memory_init (void ); +struct whpx_breakpoint *whpx_lookup_breakpoint_by_addr (uint64_t address); +#endif
target/i386/whpx/whpx-all.c +10 -541
639 lines not on this page · raw message
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 04/17] whpx: reshuffle common code
Quoted 11 lines · Mohamed Mediouni
Some code can be shared between
x86_64and arm64 WHPX. Do so as much as reasonable.Signed-off-by Mohamed Mediouni <[email protected]>--- MAINTAINERS | 2 + accel/whpx/meson.build | 1 + accel/whpx/whpx-common.c | 564 +++++++++++++++++++++++++++++++++++ include/system/whpx-all.h | 20 ++ include/system/whpx-common.h | 21 ++ target/i386/whpx/whpx-all.c | 551 +--------------------------------- 6 files changed, 618 insertions(+), 541 deletions(-)
Quoted 3 lines
create mode 100644
accel/whpx/whpx-common.c
create mode 100644include/system/whpx-all.h
create mode 100644include/system/whpx-common.h
It's just moving code around and declare common interface in include/system/whpx-common.h.
PATCH v4 5/17 whpx: ifdef out winhvemulation on non-x86_64
In reply to Mohamed Mediouniwinhvemulation is x86_64 only.
In the future, we might want to get rid of winhvemulation usage entirely.
--- accel/whpx/whpx-common.c | 16 ++++++++++++---- include/system/whpx-common.h | 2 ++ include/system/whpx-internal.h | 7 ++++++- 3 files changed, 20 insertions(+), 5 deletions(-)
accel/whpx/whpx-common.c +12 -4
@@ -41,7 +41,9 @@bool whpx_allowed;static bool whp_dispatch_initialized;static HMODULE hWinHvPlatform; +#ifdef __x86_64__static HMODULE hWinHvEmulation; +#endif struct whpx_state whpx_global;struct WHPDispatch whp_dispatch;
@@ -141,9 +143,7 @@ int whpx_first_vcpu_starting(CPUState *cpu)*/ int whpx_last_vcpu_stopping (CPUState *cpu) { -#ifdef __x86_64__whpx_apply_breakpoints (whpx_global.breakpoints.breakpoints, cpu, false); -#endif return 0 ; }
@@ -238,8 +238,10 @@ void whpx_destroy_vcpu(CPUState *cpu)struct whpx_state *whpx = &whpx_global; whp_dispatch.WHvDeleteVirtualProcessor (whpx->partition, cpu->cpu_index); +#ifdef __x86_64__AccelCPUState *vcpu = cpu->accel; whp_dispatch.WHvEmulatorDestroyEmulator (vcpu->emulator); +#endif g_free (cpu->accel); }
@@ -414,8 +416,12 @@ static bool load_whp_dispatch_fns(HMODULE *handle,LIST_WINHVPLATFORM_FUNCTIONS (WHP_LOAD_FIELD) break;case WINHV_EMULATION_FNS_DEFAULT : +#ifdef __x86_64__ WHP_LOAD_LIB(WINHV_EMULATION_DLL, hLib) LIST_WINHVEMULATION_FUNCTIONS(WHP_LOAD_FIELD) +#else +abort (); +#endif break ;case WINHV_PLATFORM_FNS_SUPPLEMENTAL :WHP_LOAD_LIB (WINHV_PLATFORM_DLL , hLib)
@@ -541,11 +547,11 @@ bool init_whp_dispatch(void)if (!load_whp_dispatch_fns (&hWinHvPlatform,WINHV_PLATFORM_FNS_DEFAULT )) { goto error; } - +#ifdef __x86_64__if (!load_whp_dispatch_fns (&hWinHvEmulation,WINHV_EMULATION_FNS_DEFAULT )) { goto error; } - +#endif assert (load_whp_dispatch_fns (&hWinHvPlatform,WINHV_PLATFORM_FNS_SUPPLEMENTAL )); whp_dispatch_initialized = true;
@@ -555,9 +561,11 @@ error:if (hWinHvPlatform) {FreeLibrary (hWinHvPlatform); } +#ifdef __x86_64__if (hWinHvEmulation) {FreeLibrary (hWinHvEmulation); } +#endif return false; }
include/system/whpx-common.h +2 -0
@@ -3,7 +3,9 @@#define SYSTEM_WHPX_COMMON_H struct AccelCPUState { +#ifdef __x86_64__WHV_EMULATOR_HANDLE emulator; +#endif bool window_registered;bool interruptable;bool ready_for_pic_interrupt;
include/system/whpx-internal.h +6 -1
@@ -4,8 +4,9 @@#include <windows.h> #include <winhvplatform.h> +#ifdef __x86_64__#include <winhvemulation.h> - +#endif typedef enum WhpxBreakpointState { WHPX_BP_CLEARED = 0, WHPX_BP_SET_PENDING,
@@ -98,12 +99,16 @@ void whpx_apic_get(DeviceState *s);/* Define function typedef */ LIST_WINHVPLATFORM_FUNCTIONS(WHP_DEFINE_TYPE) +#ifdef __x86_64__ LIST_WINHVEMULATION_FUNCTIONS(WHP_DEFINE_TYPE) +#endif LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL (WHP_DEFINE_TYPE) struct WHPDispatch { LIST_WINHVPLATFORM_FUNCTIONS(WHP_DECLARE_MEMBER) +#ifdef __x86_64__ LIST_WINHVEMULATION_FUNCTIONS(WHP_DECLARE_MEMBER) +#endif LIST_WINHVPLATFORM_FUNCTIONS_SUPPLEMENTAL(WHP_DECLARE_MEMBER) };
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 05/17] whpx: ifdef out winhvemulation on non-x86_64
Quoted 17 lines · Mohamed Mediouni
winhvemulation is
x86_64only.In the future, we might want to get rid of winhvemulation usage entirely.
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 16 ++++++++++++---- include/system/whpx-common.h | 2 ++ include/system/whpx-internal.h | 7 ++++++- 3 files changed, 20 insertions(+), 5 deletions(-)accel/whpx/whpx-common.c +0
-0
accel/whpx/whpx-common.c int whpx_first_vcpu_starting(CPUState *cpu) · line 147
Quoted 7 lines
accel/whpx/whpx-common.c +0
-2@@ -141,9 +143,7 @@ int whpx_first_vcpu_starting(CPUState *cpu)*/ int whpx_last_vcpu_stopping (CPUState *cpu) { -#ifdef __x86_64__whpx_apply_breakpoints (whpx_global.breakpoints.breakpoints, cpu, false); -#endif return 0 ;
Rebase mistake?
This was added with previous commit, but I don't think it was intended.
Else,
PATCH v4 6/17 whpx: common: add WHPX_INTERCEPT_DEBUG_TRAPS define
In reply to Mohamed MediouniAs of why 0: WHPX on arm64 doesn't have debug trap support as of today.
Keep the exception bitmap interface for now - despite that being entirely unavailable on arm64 too.
--- accel/whpx/whpx-common.c | 2 +- include/system/whpx-common.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
accel/whpx/whpx-common.c +1 -1
@@ -123,7 +123,7 @@ int whpx_first_vcpu_starting(CPUState *cpu)* have one or more breakpoints enabled. Both require intercepting * the WHvX64ExceptionTypeBreakpointTrap exception. */ - exception_mask =1UL << WHvX64ExceptionTypeDebugTrapOrFault; + exception_mask =1UL <<WHPX_INTERCEPT_DEBUG_TRAPS ; }else {/* Let the guest handle all exceptions. */ exception_mask =0 ;
include/system/whpx-common.h +3 -0
@@ -20,4 +20,7 @@ int whpx_first_vcpu_starting(CPUState *cpu);int whpx_last_vcpu_stopping (CPUState *cpu);void whpx_memory_init (void );struct whpx_breakpoint *whpx_lookup_breakpoint_by_addr (uint64_t address); + +/* On x64: same as WHvX64ExceptionTypeDebugTrapOrFault */ +#define WHPX_INTERCEPT_DEBUG_TRAPS 1#endif
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 06/17] whpx: common: add WHPX_INTERCEPT_DEBUG_TRAPS define
Quoted 9 lines · Mohamed Mediouni
As of why 0: WHPX on arm64 doesn't have debug trap support as of today.
Keep the exception bitmap interface for now - despite that being entirely unavailable on arm64 too.
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 2 +- include/system/whpx-common.h | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-)
PATCH v4 7/17 hw, target, accel: whpx: change apic_in_platform to kernel_irqchip
In reply to Mohamed MediouniChange terminology to match the KVM one, as APIC is x86-specific.
--- accel/whpx/whpx-accel-ops.c | 2 +- accel/whpx/whpx-common.c | 4 ++-- hw/i386/x86-cpu.c | 4 ++-- include/system/whpx-internal.h | 2 +- include/system/whpx.h | 4 ++-- target/i386/cpu-apic.c | 2 +- target/i386/whpx/whpx-all.c | 14 +++++++------- 7 files changed, 16 insertions(+), 16 deletions(-)
accel/whpx/whpx-accel-ops.c +1 -1
@@ -80,7 +80,7 @@ static void whpx_kick_vcpu_thread(CPUState *cpu)static bool whpx_vcpu_thread_is_idle (CPUState *cpu) { -return !whpx_apic_in_platform (); +return !whpx_irqchip_in_kernel (); }static void whpx_accel_ops_class_init (ObjectClass *oc,const void *data)
accel/whpx/whpx-common.c +2 -2
@@ -496,9 +496,9 @@ static const TypeInfo whpx_cpu_accel_type = {* Partition support */ -bool whpx_apic_in_platform (void ) +bool whpx_irqchip_in_kernel (void ) { -return whpx_global.apic_in_platform; +return whpx_global.kernel_irqchip; }static void whpx_accel_class_init (ObjectClass *oc,const void *data)
hw/i386/x86-cpu.c +2 -2
@@ -45,7 +45,7 @@ static void pic_irq_request(void *opaque, int irq, int level)trace_x86_pic_interrupt (irq, level);if (cpu_is_apic_enabled (cpu->apic_state) && !kvm_irqchip_in_kernel () && - !whpx_apic_in_platform ()) { + !whpx_irqchip_in_kernel ()) {CPU_FOREACH (cs) { cpu =X86_CPU (cs);if (apic_accept_pic_intr (cpu->apic_state)) {
@@ -71,7 +71,7 @@ int cpu_get_pic_interrupt(CPUX86State *env)X86CPU *cpu =env_archcpu (env);int intno; -if (!kvm_irqchip_in_kernel () && !whpx_apic_in_platform ()) { +if (!kvm_irqchip_in_kernel () && !whpx_irqchip_in_kernel ()) { intno =apic_get_interrupt (cpu->apic_state);if (intno >=0 ) {return intno;
include/system/whpx-internal.h +1 -1
@@ -42,7 +42,7 @@ struct whpx_state {bool kernel_irqchip_allowed;bool kernel_irqchip_required; -bool apic_in_platform; +bool kernel_irqchip; };extern struct whpx_state whpx_global;
include/system/whpx.h +2 -2
@@ -26,10 +26,10 @@#ifdef CONFIG_WHPX_IS_POSSIBLE extern bool whpx_allowed;#define whpx_enabled () (whpx_allowed) -bool whpx_apic_in_platform (void ); +bool whpx_irqchip_in_kernel (void );#else /* !CONFIG_WHPX_IS_POSSIBLE */ #define whpx_enabled () 0 -#define whpx_apic_in_platform () (0) +#define whpx_irqchip_in_kernel () (0)#endif /* !CONFIG_WHPX_IS_POSSIBLE */ #endif /* QEMU_WHPX_H */
target/i386/cpu-apic.c +1 -1
@@ -32,7 +32,7 @@ APICCommonClass *apic_get_class(Error **errp) apic_type ="kvm-apic" ; }else if (xen_enabled ()) { apic_type ="xen-apic" ; - }else if (whpx_apic_in_platform ()) { + }else if (whpx_irqchip_in_kernel ()) { apic_type ="whpx-apic" ; }
target/i386/whpx/whpx-all.c +7 -7
@@ -607,7 +607,7 @@ void whpx_get_registers(CPUState *cpu) hr); } -if (whpx_apic_in_platform ()) { +if (whpx_irqchip_in_kernel ()) {/* * Fetch the TPR value from the emulated APIC. It may get overwritten * below with the value from CR8 returned by
@@ -749,7 +749,7 @@ void whpx_get_registers(CPUState *cpu)assert (idx ==RTL_NUMBER_OF (whpx_register_names)); -if (whpx_apic_in_platform ()) { +if (whpx_irqchip_in_kernel ()) {whpx_apic_get (x86_cpu->apic_state); }
@@ -1376,7 +1376,7 @@ static void whpx_vcpu_pre_run(CPUState *cpu) }/* Get pending hard interruption or replay one that was overwritten */ -if (!whpx_apic_in_platform ()) { +if (!whpx_irqchip_in_kernel ()) {if (!vcpu->interruption_pending && vcpu->interruptable && (env->eflags &IF_MASK )) {assert (!new_int.InterruptionPending);
@@ -1549,7 +1549,7 @@ int whpx_vcpu_run(CPUState *cpu)if (exclusive_step_mode ==WHPX_STEP_NONE ) {whpx_vcpu_process_async_events (cpu); -if (cpu->halted && !whpx_apic_in_platform ()) { +if (cpu->halted && !whpx_irqchip_in_kernel ()) { cpu->exception_index =EXCP_HLT ;qatomic_set (&cpu->exit_request, false);return 0 ;
@@ -1637,7 +1637,7 @@ int whpx_vcpu_run(CPUState *cpu)break ;case WHvRunVpExitReasonX64ApicEoi: -assert (whpx_apic_in_platform ()); +assert (whpx_irqchip_in_kernel ());ioapic_eoi_broadcast (vcpu->exit_ctx.ApicEoi.InterruptVector);break ;
@@ -2184,7 +2184,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } }else { - whpx->apic_in_platform = true; + whpx->kernel_irqchip = true; } }
@@ -2193,7 +2193,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms) prop.ExtendedVmExits.X64MsrExit =1 ; prop.ExtendedVmExits.X64CpuidExit =1 ; prop.ExtendedVmExits.ExceptionExit =1 ; -if (whpx_apic_in_platform ()) { +if (whpx_irqchip_in_kernel ()) { prop.ExtendedVmExits.X64ApicInitSipiExitTrap =1 ; }
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 07/17] hw, target, accel: whpx: change apic_in_platform to kernel_irqchip
Quoted 5 lines · Mohamed Mediouni
Change terminology to match the KVM one, as APIC is x86-specific.
Signed-off-by Mohamed Mediouni <[email protected]>Reviewed-by Richard Henderson <[email protected]>
Quoted 9 lines
--- accel/whpx/whpx-accel-ops.c | 2 +- accel/whpx/whpx-common.c | 4 ++-- hw/i386/x86-cpu.c | 4 ++-- include/system/whpx-internal.h | 2 +- include/system/whpx.h | 4 ++-- target/i386/cpu-apic.c | 2 +- target/i386/whpx/whpx-all.c | 14 +++++++------- 7 files changed, 16 insertions(+), 16 deletions(-)
Looks good to unify terminologies.
PATCH v4 8/17 whpx: interrupt controller support
In reply to Mohamed Mediouni--- hw/arm/virt.c | 3 + hw/intc/arm_gicv3_common.c | 3 + hw/intc/arm_gicv3_whpx.c | 261 +++++++++++++++++++++++++++++ hw/intc/meson.build | 1 + include/hw/intc/arm_gicv3_common.h | 3 + 5 files changed, 271 insertions(+) create mode 100644 hw/intc/arm_gicv3_whpx.c
hw/arm/virt.c +3 -0
@@ -49,6 +49,7 @@#include "system/tcg.h" #include "system/kvm.h" #include "system/hvf.h" +#include "system/whpx.h" #include "system/qtest.h" #include "hw/loader.h" #include "qapi/error.h"
@@ -2060,6 +2061,8 @@ 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 ()) { + gics_supported |=VIRT_GIC_VERSION_3_MASK ; }else if (tcg_enabled () ||hvf_enabled () ||qtest_enabled ()) { gics_supported |=VIRT_GIC_VERSION_2_MASK ;if (module_object_class_by_name ("arm-gicv3" )) {
hw/intc/arm_gicv3_common.c +3 -0
@@ -32,6 +32,7 @@#include "gicv3_internal.h" #include "hw/arm/linux-boot-if.h" #include "system/kvm.h" +#include "system/whpx.h" static void gicv3_gicd_no_migration_shift_bug_post_load (GICv3State *cs)
@@ -662,6 +663,8 @@ const char *gicv3_class_name(void) {if (kvm_irqchip_in_kernel ()) {return "kvm-arm-gicv3" ; + }else if (whpx_enabled ()) { +return TYPE_WHPX_GICV3 ; }else {if (kvm_enabled ()) {error_report ("Userspace GICv3 is not supported with KVM" );
hw/intc/arm_gicv3_whpx.c new file +261 -0
261 lines not on this page · raw message
hw/intc/meson.build +1 -0
@@ -41,6 +41,7 @@ specific_ss.add(when: 'CONFIG_APIC', if_true: files('apic.c', 'apic_common.c')) specific_ss.add(when: 'CONFIG_ARM_GIC', if_true: files('arm_gicv3_cpuif_common.c')) specific_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_ARM_V7M', if_true: files('armv7m_nvic.c')) specific_ss.add(when: 'CONFIG_GRLIB', if_true: files('grlib_irqmp.c'))
include/hw/intc/arm_gicv3_common.h +3 -0
@@ -306,6 +306,9 @@ typedef struct ARMGICv3CommonClass ARMGICv3CommonClass;DECLARE_OBJ_CHECKERS (GICv3State, ARMGICv3CommonClass,ARM_GICV3_COMMON ,TYPE_ARM_GICV3_COMMON ) +/* Types for GICv3 kernel-irqchip */ +#define TYPE_WHPX_GICV3 "whpx-arm-gicv3" +struct ARMGICv3CommonClass {/*< private >*/ SysBusDeviceClass parent_class;
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 08/17] whpx: interrupt controller support
Quoted 123 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 3 + hw/intc/arm_gicv3_common.c | 3 + hw/intc/arm_gicv3_whpx.c | 261 +++++++++++++++++++++++++++++ hw/intc/meson.build | 1 + include/hw/intc/arm_gicv3_common.h | 3 + 5 files changed, 271 insertions(+)create mode 100644
hw/intc/arm_gicv3_whpx.chw/arm/virt.c +3
-0@@ -49,6 +49,7 @@#include "system/tcg.h" #include "system/kvm.h" #include "system/hvf.h" +#include "system/whpx.h" #include "system/qtest.h" #include "hw/loader.h" #include "qapi/error.h" @@ -2060,6 +2061,8 @@ 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 ()) { + gics_supported |=VIRT_GIC_VERSION_3_MASK ; }else if (tcg_enabled () ||hvf_enabled () ||qtest_enabled ()) { gics_supported |=VIRT_GIC_VERSION_2_MASK ;if (module_object_class_by_name ("arm-gicv3" )) {hw/intc/arm_gicv3_common.c +3
-0@@ -32,6 +32,7 @@#include "gicv3_internal.h" #include "hw/arm/linux-boot-if.h" #include "system/kvm.h" +#include "system/whpx.h" static void gicv3_gicd_no_migration_shift_bug_post_load (GICv3State *cs)@@ -662,6 +663,8 @@ const char *gicv3_class_name(void) {if (kvm_irqchip_in_kernel ()) {return "kvm-arm-gicv3" ; + }else if (whpx_enabled ()) { +return TYPE_WHPX_GICV3 ; }else {if (kvm_enabled ()) {error_report ("Userspace GICv3 is not supported with KVM" );hw/intc/arm_gicv3_whpx.c new file +65
-0@@ -0,0 +1,261 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* ARM Generic Interrupt Controller using HVF platform support +* +* Copyright (c) 2025 Mohamed Mediouni +* Based on vGICv3 KVM code by Pavel Fedin +* +*/ + +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "hw/intc/arm_gicv3_common.h" +#include "qemu/error-report.h" +#include "qemu/module.h" +#include "system/runstate.h" +#include "system/whpx.h" +#include "system/whpx-internal.h" +#include "gicv3_internal.h" +#include "vgic_common.h" +#include "qom/object.h" +#include "target/arm/cpregs.h" + +#include "hw/arm/bsa.h" +#include <winhvplatform.h> +#include <winhvplatformdefs.h> +#include <winnt.h> + +struct WHPXARMGICv3Class { +ARMGICv3CommonClass parent_class; +DeviceRealize parent_realize; +ResettablePhases parent_phases; +}; + +typedef struct WHPXARMGICv3Class WHPXARMGICv3Class ; + +/* This is reusing the GICv3State typedef from ARM_GICV3_ITS_COMMON */ +DECLARE_OBJ_CHECKERS (GICv3State, WHPXARMGICv3Class, +WHPX_GICV3 ,TYPE_WHPX_GICV3 ); + +static void whpx_gicv3_check (GICv3State *s) +{ +} + +static void whpx_gicv3_put_cpu (CPUState *cpu_state,run_on_cpu_data arg) +{ +} + +static void whpx_gicv3_put (GICv3State *s) +{ +int ncpu; + +whpx_gicv3_check (s); + +for (ncpu =0 ; ncpu < s->num_cpu; ncpu++) { +run_on_cpu_data data; + data.host_ptr = &s->cpu[ncpu]; +run_on_cpu (s->cpu[ncpu].cpu, whpx_gicv3_put_cpu, data); + } +} + +static void whpx_gicv3_get_cpu (CPUState *cpu_state,run_on_cpu_data arg) +{ +} + +static void whpx_gicv3_get (GICv3State *s)
hw/intc/arm_gicv3_whpx.c line 75
Quoted 10 lines
hw/intc/arm_gicv3_whpx.c new file +10
-0+{ +int ncpu; + +for (ncpu =0 ; ncpu < s->num_cpu; ncpu++) { +run_on_cpu_data data; + data.host_ptr = &s->cpu[ncpu]; +run_on_cpu (s->cpu[ncpu].cpu, whpx_gicv3_get_cpu, data); + } +} +
Probably a stupid question, but since check, get_cpu and put_cpu are empty functions, why define them and the logic associated?
Quoted 212 lines
hw/intc/arm_gicv3_whpx.c new file +186
-0+static void whpx_gicv3_set_irq (void *opaque,int irq,int level) +{ +struct whpx_state *whpx = &whpx_global; + +GICv3State *s = (GICv3State *)opaque; +if (irq > s->num_irq) { +return ; + } +WHV_INTERRUPT_TYPE interrupt_type = WHvArm64InterruptTypeFixed; +WHV_INTERRUPT_CONTROL interrupt_control = { + interrupt_type = WHvArm64InterruptTypeFixed, + .RequestedVector =GIC_INTERNAL + irq, .InterruptControl.Asserted = level}; + + whp_dispatch.WHvRequestInterrupt (whpx->partition, &interrupt_control, +sizeof (interrupt_control)); +} + +static void whpx_gicv3_icc_reset (CPUARMState *env,const ARMCPRegInfo *ri) +{ +GICv3State *s; +GICv3CPUState *c; + + c = (GICv3CPUState *)env->gicv3state; + s = c->gic; + + c->icc_pmr_el1 =0 ; +/* +* Architecturally the reset value of the ICC_BPR registers +* is UNKNOWN. We set them all to 0 here; when the kernel +* uses these values to program the ICH_VMCR_EL2 fields that +* determine the guest-visible ICC_BPR register values, the +* hardware's "writing a value less than the minimum sets +* the field to the minimum value" behaviour will result in +* them effectively resetting to the correct minimum value +* for the host GIC. +*/ + c->icc_bpr[GICV3_G0 ] =0 ; + c->icc_bpr[GICV3_G1 ] =0 ; + c->icc_bpr[GICV3_G1NS ] =0 ; + + c->icc_sre_el1 =0x7 ; +memset (c->icc_apr,0 ,sizeof (c->icc_apr)); +memset (c->icc_igrpen,0 ,sizeof (c->icc_igrpen)); + +if (s->migration_blocker) { +return ; + } + + c->icc_ctlr_el1[GICV3_S ] = c->icc_ctlr_el1[GICV3_NS ]; +} + +static void whpx_gicv3_reset_hold (Object *obj,ResetType type) +{ +GICv3State *s =ARM_GICV3_COMMON (obj); +WHPXARMGICv3Class *kgc =WHPX_GICV3_GET_CLASS (s); + +if (kgc->parent_phases.hold) { + kgc->parent_phases.hold (obj, type); + } + +whpx_gicv3_put (s); +} + + +/* +* CPU interface registers of GIC needs to be reset on CPU reset. +* For the calling arm_gicv3_icc_reset() on CPU reset, we register +* below ARMCPRegInfo. As we reset the whole cpu interface under single +* register reset, we define only one register of CPU interface instead +* of defining all the registers. +*/ +static const ARMCPRegInfo gicv3_cpuif_reginfo[] = { + { .name ="ICC_CTLR_EL1" , .state =ARM_CP_STATE_BOTH , + .opc0 =3 , .opc1 =0 , .crn =12 , .crm =12 , .opc2 =4 , +/* +* If ARM_CP_NOP is used, resetfn is not called, +* So ARM_CP_NO_RAW is appropriate type. +*/ + .type =ARM_CP_NO_RAW , + .access =PL1_RW , + .readfn = arm_cp_read_zero, + .writefn = arm_cp_write_ignore, +/* +* We hang the whole cpu interface reset routine off here +* rather than parcelling it out into one little function +* per register +*/ + .resetfn = whpx_gicv3_icc_reset, + }, +}; + +static void whpx_set_reg (CPUState *cpu,WHV_REGISTER_NAME reg,WHV_REGISTER_VALUE val) +{ +struct whpx_state *whpx = &whpx_global; +HRESULT hr; + hr = whp_dispatch.WHvSetVirtualProcessorRegisters (whpx->partition, cpu->cpu_index, + ®,1 , &val); + +if (FAILED (hr)) { +error_report ("WHPX: Failed to set register %08x, hr=%08lx" , reg, hr); + } +} + +static void whpx_gicv3_realize (DeviceState *dev,Error **errp) +{ +GICv3State *s =WHPX_GICV3 (dev); +WHPXARMGICv3Class *kgc =WHPX_GICV3_GET_CLASS (s); +Error *local_err =NULL ; +int i; + + kgc->parent_realize (dev, &local_err); +if (local_err) { +error_propagate (errp, local_err); +return ; + } + +if (s->revision !=3 ) { +error_setg (errp,"unsupported GIC revision %d for platform GIC" , + s->revision); + } + +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 WHPX" ); +error_append_hint (errp,"A maximum of %d VCPUs can be used" , + s->redist_region_count[0 ]); +return ; + } + +gicv3_init_irqs_and_mmio (s, whpx_gicv3_set_irq,NULL ); + +for (i =0 ; i < s->num_cpu; i++) { +CPUState *cpu_state =qemu_get_cpu (i); +ARMCPU *cpu =ARM_CPU (cpu_state); +WHV_REGISTER_VALUE val = {.Reg64 =0x080A0000 + (GICV3_REDIST_SIZE * i)}; +whpx_set_reg (cpu_state, WHvArm64RegisterGicrBaseGpa, val); +define_arm_cp_regs (cpu, gicv3_cpuif_reginfo); + } + +if (s->maint_irq) { +error_setg (errp,"Nested virtualisation not currently supported by WHPX." ); +return ; + } +} + +static void whpx_gicv3_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +ResettableClass *rc =RESETTABLE_CLASS (klass); +ARMGICv3CommonClass *agcc =ARM_GICV3_COMMON_CLASS (klass); +WHPXARMGICv3Class *kgc =WHPX_GICV3_CLASS (klass); + + agcc->pre_save = whpx_gicv3_get; + agcc->post_load = whpx_gicv3_put; + +device_class_set_parent_realize (dc, whpx_gicv3_realize, + &kgc->parent_realize); +resettable_class_set_parent_phases (rc,NULL , whpx_gicv3_reset_hold,NULL , + &kgc->parent_phases); +} + +static const TypeInfo whpx_arm_gicv3_info = { + .name =TYPE_WHPX_GICV3 , + .parent =TYPE_ARM_GICV3_COMMON , + .instance_size =sizeof (GICv3State), + .class_init = whpx_gicv3_class_init, + .class_size =sizeof (WHPXARMGICv3Class), +}; + +static void whpx_gicv3_register_types (void ) +{ +type_register_static (&whpx_arm_gicv3_info); +} + +type_init (whpx_gicv3_register_types)hw/intc/meson.build +1
-0@@ -41,6 +41,7 @@ specific_ss.add(when: 'CONFIG_APIC', if_true: files('apic.c', 'apic_common.c')) specific_ss.add(when: 'CONFIG_ARM_GIC', if_true: files('arm_gicv3_cpuif_common.c')) specific_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_ARM_V7M', if_true: files('armv7m_nvic.c')) specific_ss.add(when: 'CONFIG_GRLIB', if_true: files('grlib_irqmp.c'))include/hw/intc/arm_gicv3_common.h +3
-0@@ -306,6 +306,9 @@ typedef struct ARMGICv3CommonClass ARMGICv3CommonClass;DECLARE_OBJ_CHECKERS (GICv3State, ARMGICv3CommonClass,ARM_GICV3_COMMON ,TYPE_ARM_GICV3_COMMON ) +/* Types for GICv3 kernel-irqchip */ +#define TYPE_WHPX_GICV3 "whpx-arm-gicv3" +struct ARMGICv3CommonClass {/*< private >*/ SysBusDeviceClass parent_class;
Re: [PATCH v4 08/17] whpx: interrupt controller support
Quoted 4 lines · Pierrick Bouvier
Probably a stupid question, but since check,
get_cpuandput_cpuare empty functions, why define them and the logic associated?
They are empty today but won’t be once save/restore is implemented for the GICv3 state, which is still incomplete so that I carved it out of this patch series.
That’s one of the last remaining blockers before VM save/restore
-m
Re: [PATCH v4 08/17] whpx: interrupt controller support
Quoted 9 lines · Mohamed Mediouni
Quoted 4 lines · Pierrick Bouvier
Probably a stupid question, but since check,
get_cpuandput_cpuare empty functions, why define them and the logic associated?They are empty today but won’t be once save/restore is implemented for the GICv3 state, which is still incomplete so that I carved it out of this patch series.
That’s one of the last remaining blockers before VM save/restore
I see thanks.
Worth adding a comment into them for that.
Quoted 1 line
-m
Re: [PATCH v4 08/17] whpx: interrupt controller support
In reply to Mohamed MediouniQuoted 9 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 3 + hw/intc/arm_gicv3_common.c | 3 + hw/intc/arm_gicv3_whpx.c | 261 +++++++++++++++++++++++++++++ hw/intc/meson.build | 1 + include/hw/intc/arm_gicv3_common.h | 3 + 5 files changed, 271 insertions(+)create mode 100644
hw/intc/arm_gicv3_whpx.c
It would definitely needs another pair of eyes, which is more familiar with GIC topic, but patch looks good to me.
PATCH v4 9/17 whpx: add arm64 support
In reply to Mohamed Mediouni--- accel/whpx/whpx-common.c | 1 + meson.build | 21 +- target/arm/meson.build | 1 + target/arm/whpx/meson.build | 3 + target/arm/whpx/whpx-all.c | 845 ++++++++++++++++++++++++++++++++++++ 5 files changed, 864 insertions(+), 7 deletions(-) create mode 100644 target/arm/whpx/meson.build create mode 100644 target/arm/whpx/whpx-all.c
accel/whpx/whpx-common.c +1 -0
@@ -16,6 +16,7 @@#include "gdbstub/helpers.h" #include "qemu/accel.h" #include "accel/accel-ops.h" +#include "system/memory.h" #include "system/whpx.h" #include "system/cpus.h" #include "system/runstate.h"
meson.build +14 -7
@@ -327,7 +327,8 @@ accelerator_targets += { 'CONFIG_XEN': xen_targets } if cpu == 'aarch64' accelerator_targets += { - 'CONFIG_HVF': ['aarch64-softmmu'] + 'CONFIG_HVF': ['aarch64-softmmu'], + 'CONFIG_WHPX': ['aarch64-softmmu'] } elif cpu == 'x86_64' accelerator_targets += {
@@ -884,14 +885,20 @@ accelerators = [] if get_option('kvm').allowed() and host_os == 'linux' accelerators += 'CONFIG_KVM' endif + if get_option('whpx').allowed() and host_os == 'windows' - if get_option('whpx').enabled() and host_machine.cpu() != 'x86_64' - error('WHPX requires 64-bit host') - elif cc.has_header('winhvplatform.h', required: get_option('whpx')) and \ - cc.has_header('winhvemulation.h', required: get_option('whpx')) - accelerators += 'CONFIG_WHPX' + if cpu == 'i386' + if get_option('whpx').enabled() + error('WHPX requires 64-bit host') + endif + # Leave CONFIG_WHPX disabled + else + if cc.has_header('winhvplatform.h', required: get_option('whpx')) and \ + cc.has_header('winhvemulation.h', required: get_option('whpx')) + accelerators += 'CONFIG_WHPX' + endif endif -endif + endif hvf = not_found if get_option('hvf').allowed()
target/arm/meson.build +1 -0
@@ -46,6 +46,7 @@ arm_common_system_ss.add(files( )) subdir('hvf') +subdir('whpx') if 'CONFIG_TCG' in config_all_accel subdir('tcg')
target/arm/whpx/meson.build new file +3 -0
@@ -0,0 +1,3 @@ +arm_system_ss.add(when: 'CONFIG_WHPX', if_true: files( + 'whpx-all.c', +))
target/arm/whpx/whpx-all.c new file +845 -0
845 lines not on this page · raw message
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 09/17] whpx: add arm64 support
Quoted 16 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 1 + meson.build | 21 +- target/arm/meson.build | 1 + target/arm/whpx/meson.build | 3 + target/arm/whpx/whpx-all.c | 845 ++++++++++++++++++++++++++++++++++++ 5 files changed, 864 insertions(+), 7 deletions(-)create mode 100644 target/arm/whpx/meson.build
create mode 100644target/arm/whpx/whpx-all.ctarget/arm/whpx/whpx-all.c new file +0
-0
...
Quoted 12 lines
target/arm/whpx/whpx-all.c new file +12
-0+ { WHvArm64RegisterDbgbvr15El1, WHPX_SYSREG(0, 15, 2, 0, 4) }, + { WHvArm64RegisterDbgbcr15El1, WHPX_SYSREG(0, 15, 2, 0, 5) }, + { WHvArm64RegisterDbgwvr15El1, WHPX_SYSREG(0, 15, 2, 0, 6) }, + { WHvArm64RegisterDbgwcr15El1, WHPX_SYSREG(0, 15, 2, 0, 7) }, +#ifdef SYNC_NO_RAW_REGS + /* + * The registers below are manually synced on init because they are + * marked as NO_RAW. We still list them to make number space sync easier. + */ + { WHvArm64RegisterMidrEl1, WHPX_SYSREG(0, 0, 3, 0, 0) }, + { WHvArm64RegisterMpidrEl1, WHPX_SYSREG(0, 0, 3, 0, 5) }, + { WHvArm64RegisterIdPfr0El1, WHPX_SYSREG(0, 4, 3, 0, 0) },
target/arm/whpx/whpx-all.c line 226
Quoted 10 lines
target/arm/whpx/whpx-all.c new file +10
-0+#endif + { WHvArm64RegisterIdAa64Pfr1El1, WHPX_SYSREG(0, 4, 3, 0, 1), true }, + { WHvArm64RegisterIdAa64Dfr0El1, WHPX_SYSREG(0, 5, 3, 0, 0), true }, + { WHvArm64RegisterIdAa64Dfr1El1, WHPX_SYSREG(0, 5, 3, 0, 1), true }, + { WHvArm64RegisterIdAa64Isar0El1, WHPX_SYSREG(0, 6, 3, 0, 0), true }, + { WHvArm64RegisterIdAa64Isar1El1, WHPX_SYSREG(0, 6, 3, 0, 1), true }, +#ifdef SYNC_NO_MMFR0 + /* We keep the hardware MMFR0 around. HW limits are there anyway */ + { WHvArm64RegisterIdAa64Mmfr0El1, WHPX_SYSREG(0, 7, 3, 0, 0) }, +#endif
...
I understand this comes from existing hvf implementation, but I can't find where SYNC_NO_.* defines are supposed to come from (including on hvf side). Any idea?
Re: [PATCH v4 09/17] whpx: add arm64 support
Quoted 49 lines · Pierrick Bouvier
Quoted 16 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 1 + meson.build | 21 +- target/arm/meson.build | 1 + target/arm/whpx/meson.build | 3 + target/arm/whpx/whpx-all.c | 845 ++++++++++++++++++++++++++++++++++++ 5 files changed, 864 insertions(+), 7 deletions(-) create mode 100644 target/arm/whpx/meson.build create mode 100644 target/arm/whpx/whpx-all.ctarget/arm/whpx/whpx-all.c new file +0
-0...
Quoted 22 lines
target/arm/whpx/whpx-all.c new file +22
-0+ { WHvArm64RegisterDbgbvr15El1, WHPX_SYSREG(0, 15, 2, 0, 4) }, + { WHvArm64RegisterDbgbcr15El1, WHPX_SYSREG(0, 15, 2, 0, 5) }, + { WHvArm64RegisterDbgwvr15El1, WHPX_SYSREG(0, 15, 2, 0, 6) }, + { WHvArm64RegisterDbgwcr15El1, WHPX_SYSREG(0, 15, 2, 0, 7) }, +#ifdef SYNC_NO_RAW_REGS + /* + * The registers below are manually synced on init because they are + * marked as NO_RAW. We still list them to make number space sync easier. + */ + { WHvArm64RegisterMidrEl1, WHPX_SYSREG(0, 0, 3, 0, 0) }, + { WHvArm64RegisterMpidrEl1, WHPX_SYSREG(0, 0, 3, 0, 5) }, + { WHvArm64RegisterIdPfr0El1, WHPX_SYSREG(0, 4, 3, 0, 0) }, +#endif + { WHvArm64RegisterIdAa64Pfr1El1, WHPX_SYSREG(0, 4, 3, 0, 1), true }, + { WHvArm64RegisterIdAa64Dfr0El1, WHPX_SYSREG(0, 5, 3, 0, 0), true }, + { WHvArm64RegisterIdAa64Dfr1El1, WHPX_SYSREG(0, 5, 3, 0, 1), true }, + { WHvArm64RegisterIdAa64Isar0El1, WHPX_SYSREG(0, 6, 3, 0, 0), true }, + { WHvArm64RegisterIdAa64Isar1El1, WHPX_SYSREG(0, 6, 3, 0, 1), true }, +#ifdef SYNC_NO_MMFR0 + /* We keep the hardware MMFR0 around. HW limits are there anyway */ + { WHvArm64RegisterIdAa64Mmfr0El1, WHPX_SYSREG(0, 7, 3, 0, 0) }, +#endif...
Quoted 1 line
I understand this comes from existing hvf implementation, but I can't find where SYNC_NO_.* defines are supposed to come from (including on hvf side). Any idea?
They’re just annotations for developer use so that readers of the code know why they aren’t in the list.
Re: [PATCH v4 09/17] whpx: add arm64 support
Quoted 49 lines · Mohamed Mediouni
Quoted 49 lines · Pierrick Bouvier
Quoted 16 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 1 + meson.build | 21 +- target/arm/meson.build | 1 + target/arm/whpx/meson.build | 3 + target/arm/whpx/whpx-all.c | 845 ++++++++++++++++++++++++++++++++++++ 5 files changed, 864 insertions(+), 7 deletions(-)create mode 100644 target/arm/whpx/meson.build
create mode 100644target/arm/whpx/whpx-all.ctarget/arm/whpx/whpx-all.c new file +0
-0...
Quoted 22 lines
target/arm/whpx/whpx-all.c new file +22
-0+ { WHvArm64RegisterDbgbvr15El1, WHPX_SYSREG(0, 15, 2, 0, 4) }, + { WHvArm64RegisterDbgbcr15El1, WHPX_SYSREG(0, 15, 2, 0, 5) }, + { WHvArm64RegisterDbgwvr15El1, WHPX_SYSREG(0, 15, 2, 0, 6) }, + { WHvArm64RegisterDbgwcr15El1, WHPX_SYSREG(0, 15, 2, 0, 7) }, +#ifdef SYNC_NO_RAW_REGS + /* + * The registers below are manually synced on init because they are + * marked as NO_RAW. We still list them to make number space sync easier. + */ + { WHvArm64RegisterMidrEl1, WHPX_SYSREG(0, 0, 3, 0, 0) }, + { WHvArm64RegisterMpidrEl1, WHPX_SYSREG(0, 0, 3, 0, 5) }, + { WHvArm64RegisterIdPfr0El1, WHPX_SYSREG(0, 4, 3, 0, 0) }, +#endif + { WHvArm64RegisterIdAa64Pfr1El1, WHPX_SYSREG(0, 4, 3, 0, 1), true }, + { WHvArm64RegisterIdAa64Dfr0El1, WHPX_SYSREG(0, 5, 3, 0, 0), true }, + { WHvArm64RegisterIdAa64Dfr1El1, WHPX_SYSREG(0, 5, 3, 0, 1), true }, + { WHvArm64RegisterIdAa64Isar0El1, WHPX_SYSREG(0, 6, 3, 0, 0), true }, + { WHvArm64RegisterIdAa64Isar1El1, WHPX_SYSREG(0, 6, 3, 0, 1), true }, +#ifdef SYNC_NO_MMFR0 + /* We keep the hardware MMFR0 around. HW limits are there anyway */ + { WHvArm64RegisterIdAa64Mmfr0El1, WHPX_SYSREG(0, 7, 3, 0, 0) }, +#endif...
Quoted 4 lines
Quoted 1 line
I understand this comes from existing hvf implementation, but I can't find where SYNC_NO_.* defines are supposed to come from (including on hvf side). Any idea?
They’re just annotations for developer use so that readers of the code know why they aren’t in the list.
Ok, thanks.
Re: [PATCH v4 09/17] whpx: add arm64 support
In reply to Mohamed MediouniQuoted 11 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 1 + meson.build | 21 +- target/arm/meson.build | 1 + target/arm/whpx/meson.build | 3 + target/arm/whpx/whpx-all.c | 845 ++++++++++++++++++++++++++++++++++++ 5 files changed, 864 insertions(+), 7 deletions(-)create mode 100644 target/arm/whpx/meson.build
create mode 100644target/arm/whpx/whpx-all.c
...
target/arm/whpx/whpx-all.c line 482
Quoted 11 lines
target/arm/whpx/whpx-all.c new file +11
-0+case WHvRunVpExitReasonCanceled: + cpu->exception_index =EXCP_INTERRUPT ; + ret =1 ; +break ; +case WHvRunVpExitReasonArm64Reset: +if (vcpu->exit_ctx.Arm64Reset.ResetType == WHvArm64ResetTypePowerOff) { +qemu_system_shutdown_request (SHUTDOWN_CAUSE_GUEST_SHUTDOWN ); + }else if (vcpu->exit_ctx.Arm64Reset.ResetType == WHvArm64ResetTypeReboot) { +qemu_system_reset_request (SHUTDOWN_CAUSE_GUEST_RESET ); + }else { +abort ();
Just a nit about style: would be better to use a switch (as this is a propert enum), and g_assert_not_reached() for default case..
---------------
The rest of the code is pretty clear and straightforward, congrats.
For other reviewers, most of the constants and functions used can be found here:
https://github.com/MicrosoftDocs/Virtualization-Documentation/blob/main/virtualization/api/hypervisor-platform/headers/WinHvPlatformDefs.h
Thanks,
Pierrick
Re: [PATCH v4 09/17] whpx: add arm64 support
In reply to Mohamed MediouniQuoted 79 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 1 + meson.build | 21 +- target/arm/meson.build | 1 + target/arm/whpx/meson.build | 3 + target/arm/whpx/whpx-all.c | 845 ++++++++++++++++++++++++++++++++++++ 5 files changed, 864 insertions(+), 7 deletions(-)create mode 100644 target/arm/whpx/meson.build
create mode 100644target/arm/whpx/whpx-all.ctarget/arm/whpx/whpx-all.c new file +67
-0+int whpx_init_vcpu (CPUState *cpu) +{ +HRESULT hr; +struct whpx_state *whpx = &whpx_global; +AccelCPUState *vcpu =NULL ; +ARMCPU *arm_cpu =ARM_CPU (cpu); +CPUARMState *env = &arm_cpu->env; +int ret; + +uint32_t sregs_match_len =ARRAY_SIZE (whpx_sreg_match); +uint32_t sregs_cnt =0 ; +WHV_REGISTER_VALUE val; +int i; + + vcpu =g_new0 (AccelCPUState,1 ); + + hr = whp_dispatch.WHvCreateVirtualProcessor ( + whpx->partition, cpu->cpu_index,0 ); +if (FAILED (hr)) { +error_report ("WHPX: Failed to create a virtual processor," +" hr=%08lx" , hr); + ret = -EINVAL ; + goto error; + } + +/* Assumption that CNTFRQ_EL0 is the same between the VMM and the partition. */ + asmvolatile ("mrs %0, cntfrq_el0" :"=r" (arm_cpu->gt_cntfrq_hz)); + + cpu->vcpu_dirty = true; + cpu->accel = vcpu; + max_vcpu_index =max (max_vcpu_index, cpu->cpu_index); +qemu_add_vm_change_state_handler (whpx_cpu_update_state, env); + + env->aarch64 = true; + +/* Allocate enough space for our sysreg sync */ + arm_cpu->cpreg_indexes =g_renew (uint64_t, arm_cpu->cpreg_indexes, + sregs_match_len); + arm_cpu->cpreg_values =g_renew (uint64_t, arm_cpu->cpreg_values, + sregs_match_len); + arm_cpu->cpreg_vmstate_indexes =g_renew (uint64_t, + arm_cpu->cpreg_vmstate_indexes, + sregs_match_len); + arm_cpu->cpreg_vmstate_values =g_renew (uint64_t, + arm_cpu->cpreg_vmstate_values, + sregs_match_len); + +memset (arm_cpu->cpreg_values,0 , sregs_match_len *sizeof (uint64_t )); + +/* Populate cp list for all known sysregs */ +for (i =0 ; i < sregs_match_len; i++) { +const ARMCPRegInfo *ri; +uint32_t key = whpx_sreg_match[i].key; + + ri =get_arm_cp_reginfo (arm_cpu->cp_regs, key); +if (ri) { +assert (!(ri->type &ARM_CP_NO_RAW )); + whpx_sreg_match[i].cp_idx = sregs_cnt; + arm_cpu->cpreg_indexes[sregs_cnt++] =cpreg_to_kvm_id (key); + }else { + whpx_sreg_match[i].cp_idx =-1 ; + } + } + arm_cpu->cpreg_array_len = sregs_cnt; + arm_cpu->cpreg_vmstate_array_len = sregs_cnt; + +assert (write_cpustate_to_list (arm_cpu, false));
target/arm/whpx/whpx-all.c line 734
Quoted 10 lines
target/arm/whpx/whpx-all.c new file +10
-0+ +/* Set CP_NO_RAW system registers on init */ + val.Reg64 = arm_cpu->midr; +whpx_set_reg (cpu, WHvArm64RegisterMidrEl1, + val); + +clean_whv_register_value (&val); + +/* bit 31 of MPIDR_EL1 is RES1, and this is enforced by WHPX */ + val.Reg64 =0x80000000 + arm_cpu->mp_affinity;
Preferably:
val.Reg64 = deposit64(arm_cpu->mp_affinity, 31, 1, 1 /* RES1 */);
target/arm/whpx/whpx-all.c line 736
Quoted 2 lines
target/arm/whpx/whpx-all.c new file +2
-0+whpx_set_reg (cpu, WHvArm64RegisterMpidrEl1, + val);
(note, your indentation is often off)
Quoted 9 lines
target/arm/whpx/whpx-all.c new file +9
-0+ +return 0 ; + +error: +g_free (vcpu); + +return ret; + +}
PATCH v4 10/17 whpx: copy over memory management logic from hvf
In reply to Mohamed MediouniThis allows edk2 to work, although u-boot is still not functional.
--- accel/whpx/whpx-common.c | 201 ++++++++++++++++++++++++++++----------- 1 file changed, 147 insertions(+), 54 deletions(-)
accel/whpx/whpx-common.c +147 -54
@@ -258,89 +258,174 @@ void whpx_vcpu_kick(CPUState *cpu)* Memory support. */ -static void whpx_update_mapping (hwaddr start_pa,ram_addr_t size, -void *host_va,int add,int rom, -const char *name) +/* whpx_slot flags */ +#define WHPX_SLOT_LOG (1 << 0) +typedef struct whpx_slot { +uint64_t start; +uint64_t size; +uint8_t *mem; +int slot_id; +uint32_t flags; +MemoryRegion *region; +}whpx_slot ; + +typedef struct WHPXState { +whpx_slot slots[32 ]; +int num_slots; +}WHPXState ; + +WHPXState *whpx_state; + +struct mac_slot { +int present; +uint64_t size; +uint64_t gpa_start; +uint64_t gva; +}; + +struct mac_slot mac_slots[32 ]; + +static int do_whpx_set_memory (whpx_slot *slot,WHV_MAP_GPA_RANGE_FLAGS flags) {struct whpx_state *whpx = &whpx_global; +struct mac_slot *macslot;HRESULT hr; -/* -if (add) { -printf("WHPX: ADD PA:%p Size:%p, Host:%p, %s, '%s'\n", -(void*)start_pa, (void*)size, host_va, -(rom ? "ROM" : "RAM"), name); -} else { -printf("WHPX: DEL PA:%p Size:%p, Host:%p, '%s'\n", -(void*)start_pa, (void*)size, host_va, name); + macslot = &mac_slots[slot->slot_id]; + +if (macslot->present) { +if (macslot->size != slot->size) { + macslot->present =0 ; + hr = whp_dispatch.WHvUnmapGpaRange (whpx->partition, + macslot->gpa_start, macslot->size); +if (FAILED (hr)) { +abort (); + } + } } -*/ - -if (add) { - hr = whp_dispatch.WHvMapGpaRange (whpx->partition, - host_va, - start_pa, - size, - (WHvMapGpaRangeFlagRead | - WHvMapGpaRangeFlagExecute | - (rom ?0 : WHvMapGpaRangeFlagWrite))); - }else { - hr = whp_dispatch.WHvUnmapGpaRange (whpx->partition, - start_pa, - size); + +if (!slot->size) { +return 0 ; } -if (FAILED (hr)) { -error_report ("WHPX: Failed to %s GPA range '%s' PA:%p, Size:%p bytes," -" Host:%p, hr=%08lx" , - (add ?"MAP" :"UNMAP" ), name, - (void *)(uintptr_t )start_pa, (void *)size, host_va, hr); + macslot->present =1 ; + macslot->gpa_start = slot->start; + macslot->size = slot->size; + hr = whp_dispatch.WHvMapGpaRange (whpx->partition, + slot->mem, slot->start, slot->size, flags); +return 0 ; +} + +static whpx_slot *whpx_find_overlap_slot (uint64_t start,uint64_t size) +{ +whpx_slot *slot; +int x; +for (x =0 ; x < whpx_state->num_slots; ++x) { + slot = &whpx_state->slots[x]; +if (slot->size && start < (slot->start + slot->size) && + (start + size) > slot->start) { +return slot; + } } +return NULL ; } -static void whpx_process_section (MemoryRegionSection *section,int add) +static void whpx_set_phys_mem (MemoryRegionSection *section,bool add) { -MemoryRegion *mr = section->mr; -hwaddr start_pa = section->offset_within_address_space; -ram_addr_t size =int128_get64 (section->size); -unsigned int delta; -uint64_t host_va; +whpx_slot *mem; +MemoryRegion *area = section->mr; +bool writable = !area->readonly && !area->rom_device; +WHV_MAP_GPA_RANGE_FLAGS flags; +uint64_t page_size =qemu_real_host_page_size (); + +if (!memory_region_is_ram (area)) { +if (writable) { +return ; + }else if (!memory_region_is_romd (area)) { +/* +* If the memory device is not in romd_mode, then we actually want +* to remove the whpx memory slot so all accesses will trap. +*/ + add = false; + } + } -if (!memory_region_is_ram (mr)) { -return ; +if (!QEMU_IS_ALIGNED (int128_get64 (section->size), page_size) || + !QEMU_IS_ALIGNED (section->offset_within_address_space, page_size)) { +/* Not page aligned, so we can not map as RAM */ + add = false; } - delta =qemu_real_host_page_size () - (start_pa & ~qemu_real_host_page_mask ()); - delta &= ~qemu_real_host_page_mask (); -if (delta > size) { -return ; + mem =whpx_find_overlap_slot ( + section->offset_within_address_space, +int128_get64 (section->size)); + +if (mem && add) { +if (mem->size ==int128_get64 (section->size) && + mem->start == section->offset_within_address_space && + mem->mem == (memory_region_get_ram_ptr (area) + + section->offset_within_region)) { +return ;/* Same region was attempted to register, go away. */ + } + } + +/* Region needs to be reset. set the size to 0 and remap it. */ +if (mem) { + mem->size =0 ; +if (do_whpx_set_memory (mem,0 )) { +error_report ("Failed to reset overlapping slot" ); +abort (); + } } - start_pa += delta; - size -= delta; - size &=qemu_real_host_page_mask (); -if (!size || (start_pa & ~qemu_real_host_page_mask ())) { + +if (!add) {return ; } - host_va = (uintptr_t )memory_region_get_ram_ptr (mr) - + section->offset_within_region + delta; +if (area->readonly || + (!memory_region_is_ram (area) &&memory_region_is_romd (area))) { + flags = WHvMapGpaRangeFlagRead | WHvMapGpaRangeFlagExecute; + }else { + flags = WHvMapGpaRangeFlagRead | WHvMapGpaRangeFlagWrite + | WHvMapGpaRangeFlagExecute; + } + +/* Now make a new slot. */ +int x; + +for (x =0 ; x < whpx_state->num_slots; ++x) { + mem = &whpx_state->slots[x]; +if (!mem->size) { +break ; + } + } + +if (x == whpx_state->num_slots) { +error_report ("No free slots" ); +abort (); + } -whpx_update_mapping (start_pa, size, (void *)(uintptr_t )host_va, add, -memory_region_is_rom (mr), mr->name); + mem->size =int128_get64 (section->size); + mem->mem =memory_region_get_ram_ptr (area) + section->offset_within_region; + mem->start = section->offset_within_address_space; + mem->region = area; + +if (do_whpx_set_memory (mem, flags)) { +error_report ("Error registering new memory slot" ); +abort (); + } }static void whpx_region_add (MemoryListener *listener,MemoryRegionSection *section) { -memory_region_ref (section->mr); -whpx_process_section (section,1 ); +whpx_set_phys_mem (section, true); }static void whpx_region_del (MemoryListener *listener,MemoryRegionSection *section) { -whpx_process_section (section,0 ); -memory_region_unref (section->mr); +whpx_set_phys_mem (section, false); }static void whpx_transaction_begin (MemoryListener *listener)
@@ -524,6 +609,14 @@ static void whpx_accel_instance_init(Object *obj)memset (whpx,0 ,sizeof (struct whpx_state ));/* Turn on kernel-irqchip, by default */ whpx->kernel_irqchip_allowed = true; + +int x; + whpx_state =malloc (sizeof (WHPXState)); + whpx_state->num_slots =ARRAY_SIZE (whpx_state->slots); +for (x =0 ; x < whpx_state->num_slots; ++x) { + whpx_state->slots[x].size =0 ; + whpx_state->slots[x].slot_id = x; + } }static const TypeInfo whpx_accel_type = {
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 10/17] whpx: copy over memory management logic from hvf
Quoted 6 lines · Mohamed Mediouni
This allows edk2 to work, although u-boot is still not functional.
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 201 ++++++++++++++++++++++++++++----------- 1 file changed, 147 insertions(+), 54 deletions(-)
It's indeed duplicated from hvf.
I would be worth to factorize this, once we identify what is missing to boot u-boot. In the, it would be nice to have same implementations for hvf and whpx, with accelerator specific bits extracted. For now, we can live with the duplication I think.
Re: [PATCH v4 10/17] whpx: copy over memory management logic from hvf
In reply to Mohamed MediouniQuoted 21 lines · Mohamed Mediouni
This allows edk2 to work, although u-boot is still not functional.
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 201 ++++++++++++++++++++++++++++----------- 1 file changed, 147 insertions(+), 54 deletions(-)accel/whpx/whpx-common.c +3
-3@@ -258,89 +258,174 @@ void whpx_vcpu_kick(CPUState *cpu)* Memory support. */ -static void whpx_update_mapping (hwaddr start_pa,ram_addr_t size, -void *host_va,int add,int rom, -const char *name) +/* whpx_slot flags */ +#define WHPX_SLOT_LOG (1 << 0) +typedef struct whpx_slot {
accel/whpx/whpx-common.c void whpx_vcpu_kick(CPUState *cpu) · line 273
Quoted 10 lines
accel/whpx/whpx-common.c +10
-0+uint64_t start; +uint64_t size; +uint8_t *mem; +int slot_id; +uint32_t flags; +MemoryRegion *region; +} whpx_slot; + +typedef struct WHPXState { + whpx_slot slots[32];
Please add a #define for this magic 32 value.
accel/whpx/whpx-common.c void whpx_vcpu_kick(CPUState *cpu) · line 286
Quoted 13 lines
accel/whpx/whpx-common.c +13
-0+int num_slots; +} WHPXState; + +WHPXState *whpx_state; + +struct mac_slot { +int present; +uint64_t size; +uint64_t gpa_start; +uint64_t gva; +}; + +struct mac_slot mac_slots[32 ];
Ditto.
Re: [PATCH v4 10/17] whpx: copy over memory management logic from hvf
Quoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Mohamed Mediouni
This allows edk2 to work, although u-boot is still not functional.
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/whpx/whpx-common.c | 201 ++++++++++++++++++++++++++++----------- 1 file changed, 147 insertions(+), 54 deletions(-)accel/whpx/whpx-common.c +7
-3@@ -258,89 +258,174 @@ void whpx_vcpu_kick(CPUState *cpu)* Memory support. */ -static void whpx_update_mapping (hwaddr start_pa,ram_addr_t size, -void *host_va,int add,int rom, -const char *name) +/* whpx_slot flags */ +#define WHPX_SLOT_LOG (1 << 0) +typedef struct whpx_slot { + uint64_t start; + uint64_t size; + uint8_t *mem; + int slot_id;
Quoted 9 lines
accel/whpx/whpx-common.c void whpx_vcpu_kick(CPUState *cpu) · line 273
Quoted 6 lines
accel/whpx/whpx-common.c +6
-0+uint32_t flags; +MemoryRegion *region; +} whpx_slot; + +typedef struct WHPXState { + whpx_slot slots[32];Please add a #define for this magic 32 value.
hvf code does not.
And the size is never used out ofwhpx_state->num_slots = ARRAY_SIZE(whpx_state->slots), so there is no risk to have anything out of sync, thus no benefit to define this.
Quoted 15 lines
accel/whpx/whpx-common.c void whpx_vcpu_kick(CPUState *cpu) · line 286
Quoted 13 lines
accel/whpx/whpx-common.c +13
-0+int num_slots; +} WHPXState; + +WHPXState *whpx_state; + +struct mac_slot { +int present; +uint64_t size; +uint64_t gpa_start; +uint64_t gva; +}; + +struct mac_slot mac_slots[32 ];Ditto.
PATCH v4 11/17 target/arm: cpu: mark WHPX as supporting PSCI 1.1
In reply to Mohamed MediouniHyper-V supports PSCI 1.3, and that implementation is exposed through WHPX.
--- target/arm/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
target/arm/cpu.c +2 -1
@@ -23,6 +23,7 @@#include "qemu/timer.h" #include "qemu/log.h" #include "exec/page-vary.h" +#include "system/whpx.h" #include "target/arm/idau.h" #include "qemu/module.h" #include "qapi/error.h"
@@ -1496,7 +1497,7 @@ static void arm_cpu_initfn(Object *obj) cpu->psci_version =QEMU_PSCI_VERSION_0_1 ;/* By default assume PSCI v0.1 */ cpu->kvm_target =QEMU_KVM_ARM_TARGET_NONE ; -if (tcg_enabled () ||hvf_enabled ()) { +if (tcg_enabled () ||hvf_enabled () ||whpx_enabled ()) {/* TCG and HVF implement PSCI 1.1 */ cpu->psci_version =QEMU_PSCI_VERSION_1_1 ; }
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 11/17] target/arm: cpu: mark WHPX as supporting PSCI 1.1
Quoted 9 lines · Mohamed Mediouni
Hyper-V supports PSCI 1.3, and that implementation is exposed through WHPX.
Signed-off-by Mohamed Mediouni <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- target/arm/cpu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
PATCH v4 12/17 hw/arm: virt: cleanly fail on attempt to use the platform vGIC together with ITS
In reply to Mohamed MediouniWindows Hypervisor Platform's vGIC doesn't support ITS.
Deal with this by reporting to the user and not creating the ITS device.
--- hw/arm/virt.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
hw/arm/virt.c +10 -0
@@ -741,6 +741,16 @@ static void create_its(VirtMachineState *vms)return ; } +if (whpx_enabled () && vms->tcg_its) { +/* +* Signal to the user when ITS is neither supported by the host +* nor emulated by the machine. +*/ +info_report ("ITS not supported on WHPX." ); +info_report ("To support MSIs, use its=off to enable GICv3 + GICv2m." ); +return ; + } + dev =qdev_new (its_class_name ()); object_property_set_link(OBJECT(dev), "parent-gicv3", OBJECT(vms->gic),
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 12/17] hw/arm: virt: cleanly fail on attempt to use the platform vGIC together with ITS
Quoted 19 lines · Mohamed Mediouni
Windows Hypervisor Platform's vGIC doesn't support ITS.
Deal with this by reporting to the user and not creating the ITS device.Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/arm/virt.c +3
-0@@ -741,6 +741,16 @@ static void create_its(VirtMachineState *vms)return ; } +if (whpx_enabled () && vms->tcg_its) { +/* +* Signal to the user when ITS is neither supported by the host
hw/arm/virt.c static void create_its(VirtMachineState *vms) · line 756
Quoted 10 lines
hw/arm/virt.c +7
-0+* nor emulated by the machine. +*/ +info_report ("ITS not supported on WHPX." ); +info_report ("To support MSIs, use its=off to enable GICv3 + GICv2m." ); +return ; + } + dev =qdev_new (its_class_name ()); object_property_set_link(OBJECT(dev), "parent-gicv3", OBJECT(vms->gic),
Is it equivalent to simply using its=off, or is there a difference? The info_report seems to imply it's not the same.
Re: [PATCH v4 12/17] hw/arm: virt: cleanly fail on attempt to use the platform vGIC together with ITS
Quoted 25 lines · Pierrick Bouvier
Quoted 20 lines · Mohamed Mediouni
Windows Hypervisor Platform's vGIC doesn't support ITS.
Deal with this by reporting to the user and not creating the ITS device.Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/arm/virt.c +6
-0@@ -741,6 +741,16 @@ static void create_its(VirtMachineState *vms)return ; } + if (whpx_enabled() && vms->tcg_its) { +/* +* Signal to the user when ITS is neither supported by the host +* nor emulated by the machine. +*/ +info_report ("ITS not supported on WHPX." ); +info_report ("To support MSIs, use its=off to enable GICv3 + GICv2m." );
Quoted 8 lines
hw/arm/virt.c static void create_its(VirtMachineState *vms) · line 756
Quoted 5 lines
hw/arm/virt.c +3
-0+return ; + } + dev =qdev_new (its_class_name ()); object_property_set_link(OBJECT(dev), "parent-gicv3", OBJECT(vms->gic),Is it equivalent to simply using its=off, or is there a difference? The
info_reportseems to imply it's not the same.
Not equivalent.
Regular system: GICv3 + ITS
This configuration (for the newest machine version): GICv3 with no MSIs And its=off explicitly: GICv3 + GICv2m
It became not equivalent since the intro of GICv3 + GICv2m in patch 2 of this series.
Thank you,
Pierrick Bouvier
Reviewed-byRe: [PATCH v4 12/17] hw/arm: virt: cleanly fail on attempt to use the platform vGIC together with ITS
Quoted 37 lines · Mohamed Mediouni
Quoted 26 lines · Pierrick Bouvier
Quoted 21 lines · Mohamed Mediouni
Windows Hypervisor Platform's vGIC doesn't support ITS.
Deal with this by reporting to the user and not creating the ITS device.Signed-off-by Mohamed Mediouni <[email protected]>---
hw/arm/virt.c | 10 ++++++++++1 file changed, 10 insertions(+)hw/arm/virt.c +6
-0@@ -741,6 +741,16 @@ static void create_its(VirtMachineState *vms) return; } + if (whpx_enabled() && vms->tcg_its) { + /* + * Signal to the user when ITS is neither supported by the host + * nor emulated by the machine. + */ + info_report("ITS not supported on WHPX."); + info_report("To support MSIs, use its=off to enable GICv3 + GICv2m.");Quoted 8 lines
hw/arm/virt.c static void create_its(VirtMachineState *vms) · line 756
Quoted 5 lines
hw/arm/virt.c +3
-0+ return; + } + dev = qdev_new(its_class_name()); object_property_set_link(OBJECT(dev), "parent-gicv3", OBJECT(vms->gic),Is it equivalent to simply using its=off, or is there a difference? The
info_reportseems to imply it's not the same.Not equivalent.
Quoted 8 lines
Regular system: GICv3 + ITS
This configuration (for the newest machine version): GICv3 with no MSIs And its=off explicitly: GICv3 + GICv2mIt became not equivalent since the intro of GICv3 + GICv2m in patch 2 of this series.
Thank you,
I see. It could be worth adding this information to commit message. With that,
Slightly off topic for this commit, is there any downside to always have GICv3 + GICv2m setup enabled? Do some systems don't support GICv2m?
Thanks,
Pierrick
Re: [PATCH v4 12/17] hw/arm: virt: cleanly fail on attempt to use the platform vGIC together with ITS
Quoted 15 lines · Pierrick Bouvier
Quoted 10 lines · Mohamed Mediouni
Quoted 4 lines · Pierrick Bouvier
Is it equivalent to simply using its=off, or is there a difference? The
info_reportseems to imply it's not the same.Not equivalent.
Regular system: GICv3 + ITS
This configuration (for the newest machine version): GICv3 with no MSIs And its=off explicitly: GICv3 + GICv2m
It became not equivalent since the intro of GICv3 + GICv2m in patch 2 of this series.
Quoted 8 lines
Quoted 1 line
Thank you,
I see. It could be worth adding this information to commit message. With that,
Reviewed-by Pierrick Bouvier <[email protected]>Slightly off topic for this commit, is there any downside to always have GICv3 + GICv2m setup enabled? Do some systems don't support GICv2m?
GICv2m is modelled as a device external from the GIC, and so it can be emulated everywhere.
It can be done but then it supposes that the same Qemu command line will expose a different device model (instead of just MSI support missing) when ran on a different system. Not sure that’s the right thing to do…
That’s because the current setup already has ITS on by default when a GICv3 is chosen.
Note that GICv3 + GICv2m* hardware exists in the wild (Graviton1 notably) but VMs have a GICv3 w/ ITS configuration there.
* not quite, but gets shoehorned in with Linux quirks
Thank you,
-m
Re: [PATCH v4 12/17] hw/arm: virt: cleanly fail on attempt to use the platform vGIC together with ITS
Quoted 21 lines · Mohamed Mediouni
Quoted 21 lines · Pierrick Bouvier
Quoted 11 lines · Mohamed Mediouni
Quoted 4 lines · Pierrick Bouvier
Is it equivalent to simply using its=off, or is there a difference? The
info_reportseems to imply it's not the same.Not equivalent.
Regular system: GICv3 + ITS
This configuration (for the newest machine version): GICv3 with no MSIs And its=off explicitly: GICv3 + GICv2m
It became not equivalent since the intro of GICv3 + GICv2m in patch 2 of this series.Thank you,
I see. It could be worth adding this information to commit message. With that,
Reviewed-by Pierrick Bouvier <[email protected]>
Quoted 6 lines
Quoted 2 lines
Slightly off topic for this commit, is there any downside to always have GICv3 + GICv2m setup enabled? Do some systems don't support GICv2m?
GICv2m is modelled as a device external from the GIC, and so it can be emulated everywhere.
It can be done but then it supposes that the same Qemu command line will expose a different device model (instead of just MSI support missing) when ran on a different system. Not sure that’s the right thing to do…
Indeed, it might be surprising, but on the other side, we already do something specific to whpx, so it might be better to choose the default offering the maximum support.
From user point of view, the question is how hard it would be for them to guess what is missing in case they need MSI support, and didn't see the warning message about using its=off in this case.
Peter, any opinion on this?
Re: [PATCH v4 12/17] hw/arm: virt: cleanly fail on attempt to use the platform vGIC together with ITS
In reply to Mohamed MediouniQuoted 13 lines · Mohamed Mediouni
Windows Hypervisor Platform's vGIC doesn't support ITS.
Deal with this by reporting to the user and not creating the ITS device.Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/arm/virt.c +0
-0
hw/arm/virt.c static void create_its(VirtMachineState *vms) · line 750
Quoted 10 lines
hw/arm/virt.c +7
-0@@ -741,6 +741,16 @@ static void create_its(VirtMachineState *vms)return ; } +if (whpx_enabled () && vms->tcg_its) { +/* +* Signal to the user when ITS is neither supported by the host +* nor emulated by the machine. +*/ +info_report ("ITS not supported on WHPX." ); +info_report ("To support MSIs, use its=off to enable GICv3 + GICv2m." );
So if the users deliberately asks for its=on, we ignore the request and keep going. Shouldn't we just exit so the user adapts its command line?
Quoted 6 lines
hw/arm/virt.c +3
-0+return ; + } + dev =qdev_new (its_class_name ()); object_property_set_link(OBJECT(dev), "parent-gicv3", OBJECT(vms->gic),
Re: [PATCH v4 12/17] hw/arm: virt: cleanly fail on attempt to use the platform vGIC together with ITS
Quoted 20 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Mohamed Mediouni
Windows Hypervisor Platform's vGIC doesn't support ITS.
Deal with this by reporting to the user and not creating the ITS device.Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 10 ++++++++++ 1 file changed, 10 insertions(+)hw/arm/virt.c +1
-0@@ -741,6 +741,16 @@ static void create_its(VirtMachineState *vms)return ; } + if (whpx_enabled() && vms->tcg_its) { +/*
Quoted 8 lines
hw/arm/virt.c static void create_its(VirtMachineState *vms) · line 750
Quoted 5 lines
hw/arm/virt.c +5
-0+* Signal to the user when ITS is neither supported by the host +* nor emulated by the machine. +*/ +info_report ("ITS not supported on WHPX." ); +info_report ("To support MSIs, use its=off to enable GICv3 + GICv2m." );So if the users deliberately asks for its=on, we ignore the request and keep going. Shouldn't we just exit so the user adapts its command line?
Maybe that’s the best way to go… what makes me a bit hesitant on that one though is that the default is its=on.
Quoted 7 lines
Quoted 5 lines
hw/arm/virt.c +3
-0+return ; + } + dev =qdev_new (its_class_name ()); object_property_set_link(OBJECT(dev), "parent-gicv3", OBJECT(vms->gic),
PATCH v4 13/17 whpx: arm64: clamp down IPA size
In reply to Mohamed MediouniCode taken from HVF and adapted for WHPX use. Note that WHPX doesn't have a default vs maximum IPA distinction.
--- hw/arm/virt.c | 32 ++++++++++++++++++++++++++ include/hw/boards.h | 1 + target/arm/whpx/meson.build | 2 ++ target/arm/whpx/whpx-all.c | 45 +++++++++++++++++++++++++++++++++++++ target/arm/whpx/whpx-stub.c | 15 +++++++++++++ target/arm/whpx_arm.h | 16 +++++++++++++ 6 files changed, 111 insertions(+) create mode 100644 target/arm/whpx/whpx-stub.c create mode 100644 target/arm/whpx_arm.h
hw/arm/virt.c +32 -0
@@ -70,6 +70,7 @@#include "hw/irq.h" #include "kvm_arm.h" #include "hvf_arm.h" +#include "whpx_arm.h" #include "hw/firmware/smbios.h" #include "qapi/visitor.h" #include "qapi/qapi-visit-common.h"
@@ -3162,6 +3163,36 @@ static int virt_kvm_type(MachineState *ms, const char *type_str)return fixed_ipa ?0 : requested_pa_size; } +static int virt_whpx_get_physical_address_range (MachineState *ms) +{ +VirtMachineState *vms =VIRT_MACHINE (ms); + +int max_ipa_size =whpx_arm_get_ipa_bit_size (); + +/* We freeze the memory map to compute the highest gpa */ +virt_set_memmap (vms, max_ipa_size); + +int requested_ipa_size =64 -clz64 (vms->highest_gpa); + +/* +* If we're <= the default IPA size just use the default. +* If we're above the default but below the maximum, round up to +* the maximum. hvf_arm_get_max_ipa_bit_size() conveniently only +* returns values that are valid ARM PARange values. +*/ +if (requested_ipa_size <= max_ipa_size) { + requested_ipa_size = max_ipa_size; + }else { +error_report ("-m and ,maxmem option values " +"require an IPA range (%d bits) larger than " +"the one supported by the host (%d bits)" , + requested_ipa_size, max_ipa_size); +return -1 ; + } + +return requested_ipa_size; +} +static int virt_hvf_get_physical_address_range (MachineState *ms) {VirtMachineState *vms =VIRT_MACHINE (ms);
@@ -3256,6 +3287,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data) mc->get_default_cpu_node_id = virt_get_default_cpu_node_id; mc->kvm_type = virt_kvm_type; mc->hvf_get_physical_address_range = virt_hvf_get_physical_address_range; + mc->whpx_get_physical_address_range = virt_whpx_get_physical_address_range;assert (!mc->get_hotplug_handler); mc->get_hotplug_handler = virt_machine_get_hotplug_handler; hc->pre_plug = virt_machine_device_pre_plug_cb;
include/hw/boards.h +1 -0
@@ -276,6 +276,7 @@ struct MachineClass {void (*wakeup)(MachineState *state);int (*kvm_type)(MachineState *machine,const char *arg);int (*hvf_get_physical_address_range)(MachineState *machine); +int (*whpx_get_physical_address_range)(MachineState *machine);BlockInterfaceType block_default_type;int units_per_default_bus;
target/arm/whpx/meson.build +2 -0
@@ -1,3 +1,5 @@ arm_system_ss.add(when: 'CONFIG_WHPX', if_true: files( 'whpx-all.c', )) + +arm_common_system_ss.add(when: 'CONFIG_WHPX', if_false: files('whpx-stub.c'))
target/arm/whpx/whpx-all.c +45 -0
75 lines not on this page · raw message
target/arm/whpx/whpx-stub.c new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* WHPX stubs for ARM +* +* Copyright (c) 2025 Mohamed Mediouni +* +*/ + +#include "qemu/osdep.h" +#include "whpx_arm.h" + +uint32_t whpx_arm_get_ipa_bit_size (void ) +{ +g_assert_not_reached (); +}
target/arm/whpx_arm.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* WHPX support -- ARM specifics +* +* Copyright (c) 2025 Mohamed Mediouni +* +*/ + +#ifndef QEMU_WHPX_ARM_H +#define QEMU_WHPX_ARM_H + +#include "target/arm/cpu-qom.h" + +uint32_t whpx_arm_get_ipa_bit_size (void ); + +#endif
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 13/17] whpx: arm64: clamp down IPA size
Quoted 12 lines · Mohamed Mediouni
Code taken from HVF and adapted for WHPX use. Note that WHPX doesn't have a default vs maximum IPA distinction.
Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 32 ++++++++++++++++++++++++++ include/hw/boards.h | 1 + target/arm/whpx/meson.build | 2 ++ target/arm/whpx/whpx-all.c | 45 +++++++++++++++++++++++++++++++++++++ target/arm/whpx/whpx-stub.c | 15 +++++++++++++ target/arm/whpx_arm.h | 16 +++++++++++++ 6 files changed, 111 insertions(+)
Quoted 2 lines
create mode 100644
target/arm/whpx/whpx-stub.c
create mode 100644target/arm/whpx_arm.h
Logic is good, and should be safe on any hardware.
PATCH v4 14/17 hw/arm, accel/hvf, whpx: unify get_physical_address_range between WHPX and HVF
In reply to Mohamed Mediouni--- accel/hvf/hvf-all.c | 7 +++++-- hw/arm/virt.c | 41 ++++---------------------------------- include/hw/boards.h | 4 ++-- include/system/hvf_int.h | 2 ++ target/arm/hvf-stub.c | 20 ------------------- target/arm/hvf/hvf.c | 6 +++--- target/arm/hvf_arm.h | 3 --- target/arm/meson.build | 1 - target/arm/whpx/whpx-all.c | 5 +++-- target/i386/hvf/hvf.c | 10 ++++++++++ 10 files changed, 29 insertions(+), 70 deletions(-) delete mode 100644 target/arm/hvf-stub.c
accel/hvf/hvf-all.c +5 -2
@@ -17,6 +17,7 @@#include "system/hvf_int.h" #include "hw/core/cpu.h" #include "hw/boards.h" +#include "target/arm/hvf_arm.h" #include "trace.h" bool hvf_allowed;
@@ -256,8 +257,10 @@ static int hvf_accel_init(AccelState *as, MachineState *ms)int pa_range =36 ;MachineClass *mc =MACHINE_GET_CLASS (ms); -if (mc->hvf_get_physical_address_range) { - pa_range = mc->hvf_get_physical_address_range (ms); + +if (mc->get_physical_address_range) { + pa_range = mc->get_physical_address_range (ms, +hvf_arch_get_default_ipa_bit_size (),hvf_arch_get_max_ipa_bit_size ());if (pa_range <0 ) {return -EINVAL ; }
hw/arm/virt.c +4 -37
62 lines not on this page · raw message
include/hw/boards.h +2 -2
@@ -275,8 +275,8 @@ struct MachineClass {void (*reset)(MachineState *state,ResetType type);void (*wakeup)(MachineState *state);int (*kvm_type)(MachineState *machine,const char *arg); -int (*hvf_get_physical_address_range)(MachineState *machine); -int (*whpx_get_physical_address_range)(MachineState *machine); +int (*get_physical_address_range)(MachineState *machine, +int default_ipa_size,int max_ipa_size);BlockInterfaceType block_default_type;int units_per_default_bus;
include/system/hvf_int.h +2 -0
@@ -71,6 +71,8 @@ void assert_hvf_ok_impl(hv_return_t ret, const char *file, unsigned int line,const char *hvf_return_string (hv_return_t ret);int hvf_arch_init (void );hv_return_t hvf_arch_vm_create (MachineState *ms,uint32_t pa_range); +uint32_t hvf_arch_get_default_ipa_bit_size (void ); +uint32_t hvf_arch_get_max_ipa_bit_size (void );int hvf_arch_init_vcpu (CPUState *cpu);void hvf_arch_vcpu_destroy (CPUState *cpu);int hvf_vcpu_exec (CPUState *);
target/arm/hvf-stub.c deleted +0 -20
@@ -1,20 +0,0 @@ -/* -* QEMU Hypervisor.framework (HVF) stubs for ARM -* -* Copyright (c) Linaro -* -* SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#include "qemu/osdep.h" -#include "hvf_arm.h" - -uint32_t hvf_arm_get_default_ipa_bit_size (void ) -{ -g_assert_not_reached (); -} - -uint32_t hvf_arm_get_max_ipa_bit_size (void ) -{ -g_assert_not_reached (); -}
target/arm/hvf/hvf.c +3 -3
@@ -850,7 +850,7 @@ static uint64_t hvf_get_reg(CPUState *cpu, int rt)static void clamp_id_aa64mmfr0_parange_to_ipa_size (ARMISARegisters *isar) {uint32_t ipa_size = chosen_ipa_bit_size ? - chosen_ipa_bit_size :hvf_arm_get_max_ipa_bit_size (); + chosen_ipa_bit_size :hvf_arch_get_max_ipa_bit_size ();uint64_t id_aa64mmfr0;/* Clamp down the PARange to the IPA size the kernel supports. */
@@ -940,7 +940,7 @@ static bool hvf_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf)return r ==HV_SUCCESS ; } -uint32_t hvf_arm_get_default_ipa_bit_size (void ) +uint32_t hvf_arch_get_default_ipa_bit_size (void ) {uint32_t default_ipa_size;hv_return_t ret =hv_vm_config_get_default_ipa_size (&default_ipa_size);
@@ -949,7 +949,7 @@ uint32_t hvf_arm_get_default_ipa_bit_size(void)return default_ipa_size; } -uint32_t hvf_arm_get_max_ipa_bit_size (void ) +uint32_t hvf_arch_get_max_ipa_bit_size (void ) {uint32_t max_ipa_size;hv_return_t ret =hv_vm_config_get_max_ipa_size (&max_ipa_size);
target/arm/hvf_arm.h +0 -3
@@ -22,7 +22,4 @@ void hvf_arm_init_debug(void);void hvf_arm_set_cpu_features_from_host (ARMCPU *cpu); -uint32_t hvf_arm_get_default_ipa_bit_size (void ); -uint32_t hvf_arm_get_max_ipa_bit_size (void ); -#endif
target/arm/meson.build +0 -1
@@ -32,7 +32,6 @@ arm_common_system_ss.add(files('cpu.c')) arm_common_system_ss.add(when: 'TARGET_AARCH64', if_false: files( 'cpu32-stubs.c')) arm_common_system_ss.add(when: 'CONFIG_KVM', if_false: files('kvm-stub.c')) -arm_common_system_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c')) arm_common_system_ss.add(files( 'arch_dump.c', 'arm-powerctl.c',
target/arm/whpx/whpx-all.c +3 -2
@@ -805,8 +805,9 @@ int whpx_accel_init(AccelState *as, MachineState *ms) goto error; } -if (mc->whpx_get_physical_address_range) { - pa_range = mc->whpx_get_physical_address_range (ms); +if (mc->get_physical_address_range) { + pa_range = mc->get_physical_address_range (ms, +whpx_arm_get_ipa_bit_size (),whpx_arm_get_ipa_bit_size ());if (pa_range <0 ) {return -EINVAL ; }
target/i386/hvf/hvf.c +10 -0
@@ -225,6 +225,16 @@ int hvf_arch_init(void)return 0 ; } +uint32_t hvf_arch_get_default_ipa_bit_size (void ) +{ +return 48 ; +} + +uint32_t hvf_arch_get_max_ipa_bit_size (void ) +{ +return 48 ; +} +hv_return_t hvf_arch_vm_create (MachineState *ms,uint32_t pa_range) {return hv_vm_create (HV_VM_DEFAULT );
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 14/17] hw/arm, accel/hvf, whpx: unify get_physical_address_range between WHPX and HVF
Quoted 13 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/hvf/hvf-all.c | 7 +++++-- hw/arm/virt.c | 41 ++++---------------------------------- include/hw/boards.h | 4 ++-- include/system/hvf_int.h | 2 ++ target/arm/hvf-stub.c | 20 ------------------- target/arm/hvf/hvf.c | 6 +++--- target/arm/hvf_arm.h | 3 --- target/arm/meson.build | 1 - target/arm/whpx/whpx-all.c | 5 +++-- target/i386/hvf/hvf.c | 10 ++++++++++ 10 files changed, 29 insertions(+), 70 deletions(-)
Quoted 1 line
delete mode 100644
target/arm/hvf-stub.c
Good cleanup!
Re: [PATCH v4 14/17] hw/arm, accel/hvf, whpx: unify get_physical_address_range between WHPX and HVF
In reply to Mohamed MediouniQuoted 22 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/hvf/hvf-all.c | 7 +++++-- hw/arm/virt.c | 41 ++++---------------------------------- include/hw/boards.h | 4 ++-- include/system/hvf_int.h | 2 ++ target/arm/hvf-stub.c | 20 ------------------- target/arm/hvf/hvf.c | 6 +++--- target/arm/hvf_arm.h | 3 --- target/arm/meson.build | 1 - target/arm/whpx/whpx-all.c | 5 +++-- target/i386/hvf/hvf.c | 10 ++++++++++ 10 files changed, 29 insertions(+), 70 deletions(-)delete mode 100644
target/arm/hvf-stub.ctarget/i386/hvf/hvf.c +0
-0@@ -225,6 +225,16 @@ int hvf_arch_init(void)return 0 ;
target/i386/hvf/hvf.c int hvf_arch_init(void) · line 235
Quoted 10 lines
target/i386/hvf/hvf.c +8
-0} +uint32_t hvf_arch_get_default_ipa_bit_size (void ) +{ +return 48 ; +} + +uint32_t hvf_arch_get_max_ipa_bit_size (void ) +{ +return 48 ;
These don't make much sense on x86...
Quoted 1 line
target/i386/hvf/hvf.c +1
-0+}
Re: [PATCH v4 14/17] hw/arm, accel/hvf, whpx: unify get_physical_address_range between WHPX and HVF
Quoted 25 lines · Philippe Mathieu-Daudé
Quoted 24 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/hvf/hvf-all.c | 7 +++++-- hw/arm/virt.c | 41 ++++---------------------------------- include/hw/boards.h | 4 ++-- include/system/hvf_int.h | 2 ++ target/arm/hvf-stub.c | 20 ------------------- target/arm/hvf/hvf.c | 6 +++--- target/arm/hvf_arm.h | 3 --- target/arm/meson.build | 1 - target/arm/whpx/whpx-all.c | 5 +++-- target/i386/hvf/hvf.c | 10 ++++++++++ 10 files changed, 29 insertions(+), 70 deletions(-)delete mode 100644
target/arm/hvf-stub.ctarget/i386/hvf/hvf.c +0
-0@@ -225,6 +225,16 @@ int hvf_arch_init(void)return 0 ; }
Quoted 11 lines
target/i386/hvf/hvf.c int hvf_arch_init(void) · line 235
Quoted 8 lines
target/i386/hvf/hvf.c +8
-0+uint32_t hvf_arch_get_default_ipa_bit_size (void ) +{ +return 48 ; +} + +uint32_t hvf_arch_get_max_ipa_bit_size (void ) +{ +return 48 ;These don't make much sense on x86...
Common path in accel/hvf/hvf-all.c makes use of it, so it's not a bad idea to have an architecture agnostic function for it, instead of:
if (arm_function) {...}.
It happens that on x64, VA space is 48 bits.
Quoted 3 lines
Quoted 1 line
target/i386/hvf/hvf.c +1
-0+}
Re: [PATCH v4 14/17] hw/arm, accel/hvf, whpx: unify get_physical_address_range between WHPX and HVF
In reply to Philippe Mathieu-DaudéQuoted 26 lines · Philippe Mathieu-Daudé
Quoted 25 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>---
accel/hvf/hvf-all.c | 7 +++++--
hw/arm/virt.c | 41 ++++---------------------------------- include/hw/boards.h | 4 ++-- include/system/hvf_int.h | 2 ++
target/arm/hvf-stub.c | 20 ------------------- target/arm/hvf/hvf.c | 6 +++--- target/arm/hvf_arm.h | 3 ---
target/arm/meson.build | 1 -target/arm/whpx/whpx-all.c| 5 +++-- target/i386/hvf/hvf.c | 10 ++++++++++10 files changed, 29 insertions(+), 70 deletions(-)delete mode 100644
target/arm/hvf-stub.ctarget/i386/hvf/hvf.c +2
-0@@ -225,6 +225,16 @@ int hvf_arch_init(void) return 0; } +uint32_t hvf_arch_get_default_ipa_bit_size (void ) +{
Quoted 8 lines
target/i386/hvf/hvf.c int hvf_arch_init(void) · line 235
Quoted 6 lines
target/i386/hvf/hvf.c +6
-0+ return 48; +} + +uint32_t hvf_arch_get_max_ipa_bit_size (void ) +{ + return 48;These don't make much sense on x86...
They don't *not* make sense. x86 does have two-stage translation, though it has both 48-bit and 52-bit translation.
While this is only invoked from hw/arm/virt.c at present, I can see that by piping the path through accel/hvf/ means that x86 needs to provide the symbols. Though perhaps they should just be g_assert_not_reached() stubs for now.
r~
Re: [PATCH v4 14/17] hw/arm, accel/hvf, whpx: unify get_physical_address_range between WHPX and HVF
Quoted 37 lines · Richard Henderson
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 22 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/hvf/hvf-all.c | 7 +++++-- hw/arm/virt.c | 41 ++++---------------------------------- include/hw/boards.h | 4 ++-- include/system/hvf_int.h | 2 ++ target/arm/hvf-stub.c | 20 ------------------- target/arm/hvf/hvf.c | 6 +++--- target/arm/hvf_arm.h | 3 --- target/arm/meson.build | 1 - target/arm/whpx/whpx-all.c | 5 +++-- target/i386/hvf/hvf.c | 10 ++++++++++ 10 files changed, 29 insertions(+), 70 deletions(-)delete mode 100644
target/arm/hvf-stub.ctarget/i386/hvf/hvf.c +1
-0@@ -225,6 +225,16 @@ int hvf_arch_init(void)return 0 ; } +uint32_t hvf_arch_get_default_ipa_bit_size (void )Quoted 8 lines
target/i386/hvf/hvf.c int hvf_arch_init(void) · line 235
Quoted 7 lines
target/i386/hvf/hvf.c +7
-0+{ +return 48 ; +} + +uint32_t hvf_arch_get_max_ipa_bit_size (void ) +{ +return 48 ;These don't make much sense on x86...
Quoted 3 lines
They don't *not* make sense. x86 does have two-stage translation, though it has both 48-bit and 52-bit translation.
While this is only invoked from
hw/arm/virt.cat present, I can see that by piping the path through accel/hvf/ means that x86 needs to provide the symbols. Though perhaps they should just beg_assert_not_reached()stubs for now.
Random note that probably doesn’t change things: every Intel Mac has 48-bit, and extended addressing will never happen as macOS 26 is the last x86 macOS release.
The other option I think is just #ifdefing out if (mc->get_physical_address_range) in hvf_accel_init based on arch...
Quoted 2 lines
r~
Re: [PATCH v4 14/17] hw/arm, accel/hvf, whpx: unify get_physical_address_range between WHPX and HVF
Quoted 41 lines · Mohamed Mediouni
Quoted 38 lines · Richard Henderson
Quoted 31 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Mohamed Mediouni
Signed-off-by Mohamed Mediouni <[email protected]>--- accel/hvf/hvf-all.c | 7 +++++-- hw/arm/virt.c | 41 ++++---------------------------------- include/hw/boards.h | 4 ++-- include/system/hvf_int.h | 2 ++ target/arm/hvf-stub.c | 20 ------------------- target/arm/hvf/hvf.c | 6 +++--- target/arm/hvf_arm.h | 3 --- target/arm/meson.build | 1 - target/arm/whpx/whpx-all.c | 5 +++-- target/i386/hvf/hvf.c | 10 ++++++++++ 10 files changed, 29 insertions(+), 70 deletions(-) delete mode 100644 target/arm/hvf-stub.ctarget/i386/hvf/hvf.c +0
-0target/i386/hvf/hvf.c int hvf_arch_init(void) · line 234
Quoted 10 lines
target/i386/hvf/hvf.c +8
-0@@ -225,6 +225,16 @@ int hvf_arch_init(void)return 0 ; } +uint32_t hvf_arch_get_default_ipa_bit_size (void ) +{ +return 48 ; +} + +uint32_t hvf_arch_get_max_ipa_bit_size (void ) +{ +return 48 ;These don't make much sense on x86...
Quoted 6 lines
Quoted 3 lines
They don't *not* make sense. x86 does have two-stage translation, though it has both 48-bit and 52-bit translation.
While this is only invoked from
hw/arm/virt.cat present, I can see that by piping the path through accel/hvf/ means that x86 needs to provide the symbols. Though perhaps they should just beg_assert_not_reached()stubs for now.Random note that probably doesn’t change things: every Intel Mac has 48-bit, and extended addressing will never happen as macOS 26 is the last x86 macOS release.
The other option I think is just #ifdefing out if (
mc->get_physical_address_range) inhvf_accel_initbased on arch…
Think that I’ll just go the g_assert_not_reached route...
PATCH v4 15/17 whpx: arm64: implement -cpu host
In reply to Mohamed MediouniOpenProcessorKey and ReadRegU64 adapted from:
https://github.com/FEX-Emu/FEX/blob/e6de17e72ef03aa88ba14fa0ec13163061608c74/Source/Windows/Common/CPUFeatures.cpp#L62
--- hw/arm/virt.c | 2 +- target/arm/cpu64.c | 19 ++++--- target/arm/whpx/whpx-all.c | 107 +++++++++++++++++++++++++++++++++++++ target/arm/whpx_arm.h | 1 + 4 files changed, 122 insertions(+), 7 deletions(-)
hw/arm/virt.c +1 -1
@@ -3217,7 +3217,7 @@ static void virt_machine_class_init(ObjectClass *oc, const void *data)#ifdef TARGET_AARCH64 ARM_CPU_TYPE_NAME("cortex-a53"), ARM_CPU_TYPE_NAME("cortex-a57"), -#if defined(CONFIG_KVM ) || defined(CONFIG_HVF ) +#if defined(CONFIG_KVM ) || defined(CONFIG_HVF ) || defined(CONFIG_WHPX ) ARM_CPU_TYPE_NAME("host"),#endif /* CONFIG_KVM || CONFIG_HVF */ #endif /* TARGET_AARCH64 */
target/arm/cpu64.c +13 -6
@@ -26,10 +26,13 @@#include "qemu/units.h" #include "system/kvm.h" #include "system/hvf.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 "whpx_arm.h" #include "qapi/visitor.h" #include "hw/qdev-properties.h" #include "internals.h"
@@ -522,7 +525,7 @@ void arm_cpu_pauth_finalize(ARMCPU *cpu, Error **errp) isar2 =FIELD_DP64 (isar2,ID_AA64ISAR2 ,APA3 ,0 ); isar2 =FIELD_DP64 (isar2,ID_AA64ISAR2 ,GPA3 ,0 ); -if (kvm_enabled () ||hvf_enabled ()) { +if (hwaccel_enabled ()) {/* * Exit early if PAuth is enabled and fall through to disable it. * The algorithm selection properties are not present.
@@ -599,10 +602,10 @@ void aarch64_add_pauth_properties(Object *obj)/* Default to PAUTH on, with the architected algorithm on TCG. */ qdev_property_add_static (DEVICE (obj), &arm_cpu_pauth_property); -if (kvm_enabled () ||hvf_enabled ()) { +if (hwaccel_enabled ()) {/* * Mirror PAuth support from the probed sysregs back into the -* property for KVM or hvf. Is it just a bit backward? Yes it is! +* property for HW accel. Is it just a bit backward? Yes it is! * Note that prop_pauth is true whether the host CPU supports the * architected QARMA5 algorithm or the IMPDEF one. We don't * provide the separate pauth-impdef property for KVM or hvf,
@@ -773,6 +776,10 @@ static void aarch64_host_initfn(Object *obj)ARMCPU *cpu =ARM_CPU (obj);hvf_arm_set_cpu_features_from_host (cpu);aarch64_add_pauth_properties (obj); +#elif defined(CONFIG_WHPX ) +ARMCPU *cpu =ARM_CPU (obj); +whpx_arm_set_cpu_features_from_host (cpu); +aarch64_add_pauth_properties (obj);#else g_assert_not_reached ();#endif
@@ -780,8 +787,8 @@ static void aarch64_host_initfn(Object *obj)static void aarch64_max_initfn (Object *obj) { -if (kvm_enabled () ||hvf_enabled ()) { -/* With KVM or HVF, '-cpu max' is identical to '-cpu host' */ +if (hwaccel_enabled ()) { +/* When hardware acceleration enabled, '-cpu max' is identical to '-cpu host' */ aarch64_host_initfn (obj);return ; }
@@ -800,7 +807,7 @@ static const ARMCPUInfo aarch64_cpus[] = { { .name = "cortex-a57", .initfn = aarch64_a57_initfn }, { .name = "cortex-a53", .initfn = aarch64_a53_initfn }, { .name = "max", .initfn = aarch64_max_initfn }, -#if defined(CONFIG_KVM) || defined(CONFIG_HVF) +#if defined(CONFIG_KVM) || defined(CONFIG_HVF) || defined(CONFIG_WHPX) { .name = "host", .initfn = aarch64_host_initfn }, #endif };
target/arm/whpx/whpx-all.c +107 -0
119 lines not on this page · raw message
target/arm/whpx_arm.h +1 -0
@@ -12,5 +12,6 @@#include "target/arm/cpu-qom.h" uint32_t whpx_arm_get_ipa_bit_size (void ); +void whpx_arm_set_cpu_features_from_host (ARMCPU *cpu);#endif
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 15/17] whpx: arm64: implement -cpu host
Quoted 10 lines · Mohamed Mediouni
OpenProcessorKey and ReadRegU64 adapted from:
https://github.com/FEX-Emu/FEX/blob/e6de17e72ef03aa88ba14fa0ec13163061608c74/Source/Windows/Common/CPUFeatures.cpp#L62Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 2 +- target/arm/cpu64.c | 19 ++++--- target/arm/whpx/whpx-all.c | 107 +++++++++++++++++++++++++++++++++++++ target/arm/whpx_arm.h | 1 + 4 files changed, 122 insertions(+), 7 deletions(-)
Additional question, what is missing for SVE/SME support?
Re: [PATCH v4 15/17] whpx: arm64: implement -cpu host
Quoted 15 lines · Pierrick Bouvier
Quoted 9 lines · Mohamed Mediouni
OpenProcessorKey and ReadRegU64 adapted from:
https://github.com/FEX-Emu/FEX/blob/e6de17e72ef03aa88ba14fa0ec13163061608c74/Source/Windows/Common/CPUFeatures.cpp#L62Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 2 +- target/arm/cpu64.c | 19 ++++--- target/arm/whpx/whpx-all.c | 107 +++++++++++++++++++++++++++++++++++++ target/arm/whpx_arm.h | 1 + 4 files changed, 122 insertions(+), 7 deletions(-)
Quoted 3 lines
Reviewed-by Pierrick Bouvier <[email protected]>Additional question, what is missing for SVE/SME support?
For SVE it’s mainly about the state save/restore part. And having good hardware for testing it too.
For SME, Hyper-V doesn’t support it yet, but done preventively so that it doesn’t suddenly get enabled once that happens. (and that scenario happened on macOS and promptly broke things)
Re: [PATCH v4 15/17] whpx: arm64: implement -cpu host
Quoted 15 lines · Mohamed Mediouni
Quoted 15 lines · Pierrick Bouvier
Quoted 9 lines · Mohamed Mediouni
OpenProcessorKey and ReadRegU64 adapted from:
https://github.com/FEX-Emu/FEX/blob/e6de17e72ef03aa88ba14fa0ec13163061608c74/Source/Windows/Common/CPUFeatures.cpp#L62Signed-off-by Mohamed Mediouni <[email protected]>--- hw/arm/virt.c | 2 +- target/arm/cpu64.c | 19 ++++--- target/arm/whpx/whpx-all.c | 107 +++++++++++++++++++++++++++++++++++++ target/arm/whpx_arm.h | 1 + 4 files changed, 122 insertions(+), 7 deletions(-)
Quoted 7 lines
Quoted 3 lines
Reviewed-by Pierrick Bouvier <[email protected]>Additional question, what is missing for SVE/SME support?
For SVE it’s mainly about the state save/restore part. And having good hardware for testing it too.
For SME, Hyper-V doesn’t support it yet, but done preventively so that it doesn’t suddenly get enabled once that happens. (and that scenario happened on macOS and promptly broke things)
Thanks.
Worth adding it in comment next to deactivation part for next reader.
PATCH v4 16/17 target/arm: whpx: instantiate GIC early
In reply to Mohamed MediouniWhile figuring out a better spot for it, put it in whpx_accel_init.
Needs to be done before WHvSetupPartition.
--- target/arm/whpx/whpx-all.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
target/arm/whpx/whpx-all.c +23 -0
@@ -976,6 +976,29 @@ int whpx_accel_init(AccelState *as, MachineState *ms)memset (&prop,0 ,sizeof (WHV_PARTITION_PROPERTY )); +WHV_ARM64_IC_PARAMETERS ic_params = { + .EmulationMode = WHvArm64IcEmulationModeGicV3, + .GicV3Parameters = { + .GicdBaseAddress =0x08000000 , + .GitsTranslaterBaseAddress =0x08080000 , + .GicLpiIntIdBits =0 , + .GicPpiPerformanceMonitorsInterrupt =VIRTUAL_PMU_IRQ , + .GicPpiOverflowInterruptFromCntv =ARCH_TIMER_VIRT_IRQ + } + }; + prop.Arm64IcParameters = ic_params; + + hr = whp_dispatch.WHvSetPartitionProperty ( + whpx->partition, + WHvPartitionPropertyCodeArm64IcParameters, + &prop, +sizeof (WHV_PARTITION_PROPERTY )); +if (FAILED (hr)) { +error_report ("WHPX: Failed to enable GICv3 interrupt controller, hr=%08lx" , hr); + ret = -EINVAL ; + goto error; + } + hr = whp_dispatch.WHvSetupPartition (whpx->partition);if (FAILED (hr)) {error_report ("WHPX: Failed to setup partition, hr=%08lx" , hr);
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 16/17] target/arm: whpx: instantiate GIC early
Quoted 8 lines · Mohamed Mediouni
While figuring out a better spot for it, put it in
whpx_accel_init.Needs to be done before WHvSetupPartition.
Signed-off-by Mohamed Mediouni <[email protected]>--- target/arm/whpx/whpx-all.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+)
PATCH v4 17/17 MAINTAINERS: Add myself as a maintainer for WHPX
In reply to Mohamed MediouniAnd add arm64 files.
--- MAINTAINERS | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
MAINTAINERS +4 -1
@@ -539,11 +539,14 @@ F: accel/stubs/hvf-stub.c F: include/system/hvf.h F: include/system/hvf_int.h -WHPX CPUs +WHPX M: Sunil Muthuswamy <[email protected]> +M: Mohamed Mediouni <[email protected]> S: Supported F: accel/whpx/ F: target/i386/whpx/ +F: target/arm/whpx_arm.h +F: target/arm/whpx/ F: accel/stubs/whpx-stub.c F: include/system/whpx.h F: include/system/whpx-accel-ops.h
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v4 17/17] MAINTAINERS: Add myself as a maintainer for WHPX
Quoted 7 lines · Mohamed Mediouni
And add arm64 files.
Signed-off-by Mohamed Mediouni <[email protected]>Reviewed-by Richard Henderson <[email protected]>--- MAINTAINERS | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
Quoted 100 lines · Mohamed Mediouni
Link to branch: https://github.com/mediouni-m/qemu whpx (tag for this submission: whpx-v3)
Missing features:
- PSCI state sync with Hyper-V: notably breaks reboots when multiple cores are enabled
- Interrupt controller save-restore
- Debug register sync
- SVE register sync
- Adding a migration blocker because of the items above.Note:
"accel/system: Introduce
hwaccel_enabled()helper" taken from the mailing list, added here as part of this series to make it compilable as a whole."hw/arm: virt: add GICv2m for the case when ITS is not available" present in both the HVF vGIC and this series.
Updates since v3:
- Disabling SVE on WHPX
- Taking into account review comments incl:- fixing x86 support
- reduce the amount of__x86_64__checks in common code to the minimum (winhvemulation) which can be reduced even further down the road.
- generalizeget_physical_address_rangeinto something common between hvf and whpxUpdates since v2:
- Fixed up a rebase screwup forwhpx-internal.h
- FixedID_AA64ISAR1_EL1andID_AA64ISAR2_EL1feature probe for -cpu host
- Switched to ID_AA64PFR1_EL1/ID_AA64DFR0_EL1 instead of their non-AA64 variantUpdates since v1:
- Shutdowns and reboots
-MPIDR_EL1register sync
- FixingGICD_TYPER_LPISvalue
- IPA size clamping
- -cpu host now implementedMohamed Mediouni (16):
hw/arm: virt: add GICv2m for the case when ITS is not available
whpx: Move around files before introducing AArch64 support
whpx: reshuffle common code
whpx: ifdef out winhvemulation on non-x86_64
whpx: common: addWHPX_INTERCEPT_DEBUG_TRAPSdefine
hw, target, accel: whpx: changeapic_in_platformtokernel_irqchip
whpx: interrupt controller support
whpx: add arm64 support
whpx: copy over memory management logic from hvf target/arm: cpu: mark WHPX as supporting PSCI 1.1
hw/arm: virt: cleanly fail on attempt to use the platform vGIC
together with ITS
whpx: arm64: clamp down IPA size
hw/arm, accel/hvf, whpx: unifyget_physical_address_rangebetween WHPX
and HVF
whpx: arm64: implement -cpu host
target/arm: whpx: instantiate GIC early
MAINTAINERS: Add myself as a maintainer for WHPXPhilippe Mathieu-Daudé (1):
accel/system: Introducehwaccel_enabled()helperMAINTAINERS | 9 +- accel/hvf/hvf-all.c | 7 +- accel/meson.build | 1 + accel/whpx/meson.build | 7 + {target/i386 => accel}/whpx/whpx-accel-ops.c | 6 +- accel/whpx/whpx-common.c | 666 +++++++++++ hw/arm/virt-acpi-build.c | 4 +- hw/arm/virt.c | 34 +- hw/i386/x86-cpu.c | 4 +- hw/intc/arm_gicv3_common.c | 3 + hw/intc/arm_gicv3_whpx.c | 261 +++++ hw/intc/meson.build | 1 + include/hw/arm/virt.h | 2 + include/hw/boards.h | 3 +- include/hw/intc/arm_gicv3_common.h | 3 + include/system/hvf_int.h | 2 + include/system/hw_accel.h | 13 + .../whpx => include/system}/whpx-accel-ops.h | 4 +- include/system/whpx-all.h | 20 + include/system/whpx-common.h | 26 + .../whpx => include/system}/whpx-internal.h | 14 +- include/system/whpx.h | 4 +- meson.build | 21 +- target/arm/cpu.c | 3 +- target/arm/cpu64.c | 19 +- target/arm/hvf-stub.c | 20 - target/arm/hvf/hvf.c | 6 +- target/arm/hvf_arm.h | 3 - target/arm/meson.build | 2 +- target/arm/whpx/meson.build | 5 + target/arm/whpx/whpx-all.c | 1021 +++++++++++++++++ target/arm/whpx/whpx-stub.c | 15 + target/arm/whpx_arm.h | 17 + target/i386/cpu-apic.c | 2 +- target/i386/hvf/hvf.c | 10 + target/i386/whpx/meson.build | 1 - target/i386/whpx/whpx-all.c | 569 +-------- target/i386/whpx/whpx-apic.c | 2 +- 38 files changed, 2191 insertions(+), 619 deletions(-)
Quoted 14 lines
create mode 100644 accel/whpx/meson.build
rename {target/i386 =>accel}/whpx/whpx-accel-ops.c(96%) create mode 100644accel/whpx/whpx-common.c
create mode 100644hw/intc/arm_gicv3_whpx.c
rename {target/i386/whpx =>include/system}/whpx-accel-ops.h(92%) create mode 100644include/system/whpx-all.h
create mode 100644include/system/whpx-common.h
rename {target/i386/whpx =>include/system}/whpx-internal.h(96%) delete mode 100644target/arm/hvf-stub.c
create mode 100644 target/arm/whpx/meson.build
create mode 100644target/arm/whpx/whpx-all.c
create mode 100644target/arm/whpx/whpx-stub.c
create mode 100644target/arm/whpx_arm.h
For the whole series:
Booting a linux guest (direct kernel boot + edk2):
./build/qemu-system-aarch64.exe \
-M virt,accel=whpx \
-m 2048 \
-cpu host \
-kernel out/Image.gz \
./out/host.ext4 \
-nographic \
-append ' root=/dev/vda'
Thanks,
Pierrick