From: Magnus Kulke <magnuskulke@linux.microsoft.com>
To: Aastha Rawat <aastharawat@linux.microsoft.com>
Cc: qemu-devel@nongnu.org, "Wei Liu" <wei.liu@kernel.org>,
"Doru Blânzeanu" <dblanzeanu@linux.microsoft.com>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Anirudh Rayabharam" <anirudh@anirudhrb.com>,
qemu-arm@nongnu.org, "Alexander Graf" <agraf@csgraf.de>,
"Pedro Barbuda" <pbarbuda@microsoft.com>,
"Mohamed Mediouni" <mohamed@unpredictable.fr>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>
Subject: Re: [PATCH v6 11/14] target/arm/mshv: add vCPU run loop
Date: Fri, 20 Nov 2026 16:37:57 +0100 [thread overview]
Message-ID: <awBpVDVdwuMg4CD3@example.com> (raw)
In-Reply-To: <20261001-mshv_accel_arm64_supp-v6-11-aefe5e76a0e3@linux.microsoft.com>
On Thu, Oct 01, 2026 at 10:52:56AM +0000, Aastha Rawat wrote:
> From: "Anirudh Rayabharam (Microsoft)" <anirudh@anirudhrb.com>
>
> Add the main vCPU run loop for MSHV using the MSHV_RUN_VP_IOCTL.
>
> Handle MMIO exits by emulating the instruction using the syndrome
> information from ESR_EL2.
>
> Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com>
> ---
> include/hw/hyperv/hvgdk_mini.h | 44 +++++++++++++++++
> target/arm/mshv/mshv-all.c | 107 +++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 151 insertions(+)
>
> diff --git a/include/hw/hyperv/hvgdk_mini.h b/include/hw/hyperv/hvgdk_mini.h
> index 33c9e4f3e0..53dc58813e 100644
> --- a/include/hw/hyperv/hvgdk_mini.h
> +++ b/include/hw/hyperv/hvgdk_mini.h
> @@ -896,6 +896,50 @@ struct hv_x64_memory_intercept_message {
> uint8_t instruction_bytes[16];
> } QEMU_PACKED;
>
> +union hv_arm64_vp_execution_state {
> + uint16_t as_uint16;
> + struct {
> + uint16_t cpl:2;
> + uint16_t debug_active:1;
> + uint16_t interruption_pending:1;
> + uint16_t vtl:4;
> + uint16_t virtualization_fault_active:1;
> + uint16_t reserved:7;
> + };
> +};
> +
> +struct hv_arm64_intercept_message_header {
> + uint32_t vp_index;
> + uint8_t instruction_length;
> + uint8_t intercept_access_type;
> + union hv_arm64_vp_execution_state execution_state;
> + uint64_t pc;
> + uint64_t cpsr;
> +};
> +
> +union hv_arm64_memory_access_info {
> + uint8_t as_uint8;
> + struct {
> + uint8_t gva_valid:1;
> + uint8_t gva_gpa_valid:1;
> + uint8_t hypercall_output_pending:1;
> + uint8_t reserved:5;
> + };
> +};
> +
> +struct hv_arm64_memory_intercept_message {
> + struct hv_arm64_intercept_message_header header;
> + uint32_t cache_type; /* enum hv_cache_type */
> + uint8_t instruction_byte_count;
> + union hv_arm64_memory_access_info memory_access_info;
> + uint16_t reserved1;
> + uint8_t instruction_bytes[4];
> + uint32_t reserved2;
> + uint64_t guest_virtual_address;
> + uint64_t guest_physical_address;
> + uint64_t syndrome;
> +};
> +
> union hv_message_flags {
> uint8_t asu8;
> struct {
> diff --git a/target/arm/mshv/mshv-all.c b/target/arm/mshv/mshv-all.c
> index d835614fd5..786d815312 100644
> --- a/target/arm/mshv/mshv-all.c
> +++ b/target/arm/mshv/mshv-all.c
> @@ -20,6 +20,7 @@
> #include "target/arm/cpu.h"
> #include "target/arm/internals.h"
> #include "target/arm/mshv_arm.h"
> +#include "target/arm/helper.h"
>
> #include "system/mshv.h"
> #include "system/mshv_int.h"
> @@ -158,8 +159,114 @@ int mshv_arch_store_vcpu_state(const CPUState *cpu)
> return store_regs(cpu);
> }
>
> +static int set_memory_info(const struct hyperv_message *msg,
> + struct hv_arm64_memory_intercept_message *info)
> +{
> + if (msg->header.message_type != HVMSG_GPA_INTERCEPT
> + && msg->header.message_type != HVMSG_UNMAPPED_GPA
> + && msg->header.message_type != HVMSG_UNACCEPTED_GPA) {
> + error_report("invalid message type");
> + return -1;
> + }
> + memcpy(info, msg->payload, sizeof(*info));
> +
> + return 0;
> +}
> +
> +static uint64_t mshv_mmio_get_reg(CPUState *cpu, int reg_index)
> +{
> + ARMCPU *arm_cpu = ARM_CPU(cpu);
> + CPUARMState *env = &arm_cpu->env;
> + return reg_index < 31 ? env->xregs[reg_index] : 0ULL;
> +}
> +
> +static void mshv_mmio_set_reg(CPUState *cpu, int reg_index, uint64_t val)
> +{
> + ARMCPU *arm_cpu = ARM_CPU(cpu);
> + CPUARMState *env = &arm_cpu->env;
> + if (reg_index < 31) {
> + env->xregs[reg_index] = val;
> + }
> +}
> +
> +static int handle_unmapped_mem(int vm_fd, CPUState *cpu,
> + const struct hyperv_message *msg,
> + MshvVmExit *exit_reason)
> +{
> + ARMCPU *arm_cpu = ARM_CPU(cpu);
> + CPUARMState *env = &arm_cpu->env;
> + struct hv_arm64_memory_intercept_message info = { 0 };
> + int ret;
> + EsrEl2 syndrome;
> +
> + ret = set_memory_info(msg, &info);
> + if (ret < 0) {
> + error_report("failed to convert message to memory info");
> + return -1;
> + }
> +
> + syndrome.raw = info.syndrome;
> +
> + ret = load_regs(cpu);
> + if (ret < 0) {
> + error_report("Failed to load registers");
> + return -1;
> + }
> +
> + static const struct arm_emul_ops mshv_arm_emul_ops = {
> + .get_reg = mshv_mmio_get_reg,
> + .set_reg = mshv_mmio_set_reg,
> + };
> +
> + ret = arm_emulate_mmio(cpu, syndrome, info.guest_physical_address,
> + &mshv_arm_emul_ops);
> + if (ret < 0) {
> + error_report("Failed to emulate with syndrome");
> + return -1;
> + }
> +
> + /* Advance PC past the faulting instruction */
> + env->pc += (syndrome.il == 1) ? 4 : 2;
> +
> + ret = store_regs(cpu);
> + if (ret < 0) {
> + error_report("Failed to store registers");
> + return -1;
> + }
> +
> + *exit_reason = MshvVmExitIgnore;
> +
> + return 0;
> +}
> +
> int mshv_run_vcpu(int vm_fd, CPUState *cpu, hv_message *msg, MshvVmExit *exit)
> {
> + int ret;
> + int cpu_fd = mshv_vcpufd(cpu);
> +
> + ret = ioctl(cpu_fd, MSHV_RUN_VP, msg);
> + if (ret < 0) {
the ioctl can return EINTR after a userland kick, for x86 on master we
handle this with a special exit:
if (ret < 0) {
if (errno == EINTR) {
*exit = MshvVmExitSpecial;
return 0;
}
> + *exit = MshvVmExitShutdown;
> + return ret;
> + }
> +
> + switch (msg->header.message_type) {
> + case HVMSG_UNRECOVERABLE_EXCEPTION:
> + *exit = MshvVmExitShutdown;
> + break;
> + case HVMSG_GPA_INTERCEPT:
> + case HVMSG_UNMAPPED_GPA:
the whpx code handles a cache maintainance exit, do we need the same
here?
advance_pc = true;
if (vcpu->exit_ctx.MemoryAccess.Syndrome & BIT(8)) {
error_report("WHPX: cached access to unmapped memory"
"Pc = 0x%llx Gva = 0x%llx Gpa = 0x%llx",
vcpu->exit_ctx.MemoryAccess.Header.Pc,
vcpu->exit_ctx.MemoryAccess.Gpa,
vcpu->exit_ctx.MemoryAccess.Gva);
break;
}
> + ret = handle_unmapped_mem(vm_fd, cpu, msg, exit);
> + if (ret < 0) {
> + error_report("failed to handle mmio");
> + return -1;
> + }
> + break;
> + default:
> + error_report("Unhandled message type: 0x%x", msg->header.message_type);
> + return -1;
> + }
> +
> return 0;
> }
>
>
> --
> 2.45.4
next prev parent reply other threads:[~2026-11-20 15:38 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-01 10:52 [PATCH v6 00/14] Add ARM64 support for MSHV accelerator Aastha Rawat
2026-10-01 10:52 ` [PATCH v6 01/14] accel/mshv: extract common CPU register helpers Aastha Rawat
2026-11-19 13:41 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 02/14] accel/mshv: add arch-specific accelerator init hook Aastha Rawat
2026-11-19 14:57 ` Magnus Kulke
2026-11-19 15:06 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 03/14] accel/mshv: make MSHV migration initialization arch-specific Aastha Rawat
2026-11-13 11:37 ` Doru Blânzeanu
2026-11-19 15:21 ` Magnus Kulke
2026-11-19 15:24 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 04/14] meson, target/arm/mshv: Enable arm64 build & add initial MSHV support Aastha Rawat
2026-10-13 16:48 ` Peter Maydell
2026-11-13 12:23 ` Doru Blânzeanu
2026-11-13 12:56 ` Doru Blânzeanu
2026-11-19 15:40 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 05/14] target/arm/mshv: implement vcpu state operations for ARM64 Aastha Rawat
2026-11-13 15:05 ` Doru Blânzeanu
2026-11-19 16:15 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 06/14] target/arm: convert host CPU feature ifdef ladder to runtime checks Aastha Rawat
2026-10-13 16:46 ` Peter Maydell
2026-10-23 14:37 ` Aastha Rawat
2026-11-19 16:26 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 07/14] target/arm/mshv: implement -cpu host for MSHV Aastha Rawat
2026-11-20 13:20 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 08/14] accel/mshv: Add access_vp_regs synthetic proc features Aastha Rawat
2026-11-20 13:35 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 09/14] target/arm: cpu: Mark MSHV supporting PSCI 1.3 Aastha Rawat
2026-11-20 13:48 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 10/14] target/arm: extract MMIO emulation logic for HVF & WHPX Aastha Rawat
2026-10-13 16:40 ` Peter Maydell
2026-10-22 10:27 ` Aastha Rawat
2026-11-20 14:13 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 11/14] target/arm/mshv: add vCPU run loop Aastha Rawat
2026-10-13 16:50 ` Peter Maydell
2026-10-16 9:56 ` Anirudh Rayabharam
2026-11-20 15:37 ` Magnus Kulke [this message]
2026-10-01 10:52 ` [PATCH v6 12/14] include/hw/hyperv: adjust hv_interrupt_control structure for arm64 Aastha Rawat
2026-11-20 15:41 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 13/14] hw/intc,target/arm/mshv: add MSHV vGICv3 implementation Aastha Rawat
2026-11-20 16:25 ` Magnus Kulke
2026-10-01 10:52 ` [PATCH v6 14/14] MAINTAINERS: updates for MSHV arm64 code Aastha Rawat
2026-11-20 16:27 ` Magnus Kulke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=awBpVDVdwuMg4CD3@example.com \
--to=magnuskulke@linux.microsoft.com \
--cc=aastharawat@linux.microsoft.com \
--cc=agraf@csgraf.de \
--cc=anirudh@anirudhrb.com \
--cc=berrange@redhat.com \
--cc=dblanzeanu@linux.microsoft.com \
--cc=marcandre.lureau@redhat.com \
--cc=mohamed@unpredictable.fr \
--cc=mst@redhat.com \
--cc=pbarbuda@microsoft.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@oss.qualcomm.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=wei.liu@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.