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 02/14] accel/mshv: add arch-specific accelerator init hook
Date: Thu, 19 Nov 2026 15:57:18 +0100 [thread overview]
Message-ID: <av8OTldUyqKQnppQ@example.com> (raw)
In-Reply-To: <20261001-mshv_accel_arm64_supp-v6-2-aefe5e76a0e3@linux.microsoft.com>
On Thu, Oct 01, 2026 at 10:52:47AM +0000, Aastha Rawat wrote:
> From: "Anirudh Rayabharam (Microsoft)" <anirudh@anirudhrb.com>
>
> Introduce mshv_arch_accel_init() as an arch-specific hook called early
> in mshv_init(), before VM creation. This allows each architecture to
> perform platform-specific initialization at accelerator init time.
>
> For x86, the hook calls mshv_init_mmio_emu() which was previously called
> directly from the common init path. Also move set_unimplemented_msr_action()
> and mshv_arch_post_init_vm() from mshv-cpu.c to the new mshv-all.c, as
> they are not vCPU-specific.
>
> Signed-off-by: Anirudh Rayabharam (Microsoft) <anirudh@anirudhrb.com>
> ---
> accel/mshv/mshv-all.c | 5 ++-
> include/system/mshv_int.h | 1 +
> target/i386/mshv/meson.build | 1 +
> target/i386/mshv/mshv-all.c | 80 ++++++++++++++++++++++++++++++++++++++++++++
> target/i386/mshv/mshv-cpu.c | 40 ----------------------
> 5 files changed, 86 insertions(+), 41 deletions(-)
>
> diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c
> index 5921ce693ee..860f511fcba 100644
> --- a/accel/mshv/mshv-all.c
> +++ b/accel/mshv/mshv-all.c
> @@ -544,7 +544,10 @@ static int mshv_init(AccelState *as, MachineState *ms)
> return -1;
> }
>
> - mshv_init_mmio_emu();
> + ret = mshv_arch_accel_init(as, ms, mshv_fd);
> + if (ret < 0) {
now that this is fallible, we probably want to close the mshv_fd before
returning.
> + return -1;
> + }
>
> ret = create_vm(mshv_fd, &vm_fd);
> if (ret < 0) {
> diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h
> index 2e8caad8fde..0e68365c63f 100644
> --- a/include/system/mshv_int.h
> +++ b/include/system/mshv_int.h
> @@ -106,6 +106,7 @@ void mshv_arch_amend_proc_features(
> union hv_partition_synthetic_processor_features *features);
> void mshv_arch_disable_partition_proc_features(
> union hv_partition_processor_features *disabled_features);
> +int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd);
> int mshv_arch_post_init_vm(int vm_fd);
> void mshv_setup_hvcall_args(AccelCPUState *state);
> int mshv_get_vp_state(int cpu_fd, struct mshv_get_set_vp_state *state);
> diff --git a/target/i386/mshv/meson.build b/target/i386/mshv/meson.build
> index 31ff4cc9950..0e95c5a00b9 100644
> --- a/target/i386/mshv/meson.build
> +++ b/target/i386/mshv/meson.build
> @@ -1,6 +1,7 @@
> i386_mshv_ss = ss.source_set()
>
> i386_mshv_ss.add(files(
> + 'mshv-all.c',
> 'mshv-cpu.c',
> 'msr.c',
> 'synic.c',
> diff --git a/target/i386/mshv/mshv-all.c b/target/i386/mshv/mshv-all.c
> new file mode 100644
> index 00000000000..f0b43aa86f1
> --- /dev/null
> +++ b/target/i386/mshv/mshv-all.c
> @@ -0,0 +1,80 @@
> +/*
> + * QEMU MSHV support
> + *
> + * Copyright Microsoft, Corp. 2026
> + *
> + * Authors: Ziqiao Zhou <ziqiaozhou@microsoft.com>
> + * Magnus Kulke <magnuskulke@microsoft.com>
> + * Jinank Jain <jinankjain@microsoft.com>
> + *
> + * SPDX-License-Identifier: GPL-2.0-or-later
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qemu/error-report.h"
> +#include "qemu/memalign.h"
> +
> +#include "system/mshv.h"
> +#include "system/mshv_int.h"
> +#include "system/address-spaces.h"
> +#include "linux/mshv.h"
> +#include "hw/hyperv/hvgdk.h"
> +#include "hw/hyperv/hvgdk_mini.h"
> +#include "hw/hyperv/hvhdk_mini.h"
> +#include "hw/i386/apic_internal.h"
> +
> +#include "cpu.h"
> +#include "emulate/x86_decode.h"
> +#include "emulate/x86_emu.h"
> +#include "emulate/x86_flags.h"
> +
> +#include "trace-accel_mshv.h"
> +#include "trace.h"
> +
> +#include <sys/ioctl.h>
> +
> +int mshv_arch_accel_init(AccelState *as, MachineState *ms, int mshv_fd)
> +{
> + mshv_init_mmio_emu();
> + return 0;
> +}
> +
> +/*
> + * Default Microsoft Hypervisor behavior for unimplemented MSR is to send a
> + * fault to the guest if it tries to access it. It is possible to override
> + * this behavior with a more suitable option i.e., ignore writes from the guest
> + * and return zero in attempt to read unimplemented.
> + */
> +static int set_unimplemented_msr_action(int vm_fd)
> +{
> + struct hv_input_set_partition_property in = {0};
> + struct mshv_root_hvcall args = {0};
> +
> + in.property_code = HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION;
> + in.property_value = HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZERO;
> +
> + args.code = HVCALL_SET_PARTITION_PROPERTY;
> + args.in_sz = sizeof(in);
> + args.in_ptr = (uint64_t)∈
> +
> + trace_mshv_hvcall_args("unimplemented_msr_action", args.code, args.in_sz);
> +
> + int ret = mshv_hvcall(vm_fd, &args);
> + if (ret < 0) {
> + error_report("Failed to set unimplemented MSR action");
> + return -1;
> + }
> + return 0;
> +}
> +
> +int mshv_arch_post_init_vm(int vm_fd)
> +{
> + int ret;
> +
> + ret = set_unimplemented_msr_action(vm_fd);
> + if (ret < 0) {
> + error_report("Failed to set unimplemented MSR action");
> + }
> +
> + return ret;
> +}
> diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c
> index 3eee097432a..f1056bd215e 100644
> --- a/target/i386/mshv/mshv-cpu.c
> +++ b/target/i386/mshv/mshv-cpu.c
> @@ -2125,46 +2125,6 @@ uint32_t mshv_get_supported_cpuid(uint32_t func, uint32_t idx, int reg)
> return ret;
> }
>
> -/*
> - * Default Microsoft Hypervisor behavior for unimplemented MSR is to send a
> - * fault to the guest if it tries to access it. It is possible to override
> - * this behavior with a more suitable option i.e., ignore writes from the guest
> - * and return zero in attempt to read unimplemented.
> - */
> -static int set_unimplemented_msr_action(int vm_fd)
> -{
> - struct hv_input_set_partition_property in = {0};
> - struct mshv_root_hvcall args = {0};
> -
> - in.property_code = HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION;
> - in.property_value = HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZERO;
> -
> - args.code = HVCALL_SET_PARTITION_PROPERTY;
> - args.in_sz = sizeof(in);
> - args.in_ptr = (uint64_t)∈
> -
> - trace_mshv_hvcall_args("unimplemented_msr_action", args.code, args.in_sz);
> -
> - int ret = mshv_hvcall(vm_fd, &args);
> - if (ret < 0) {
> - error_report("Failed to set unimplemented MSR action");
> - return -1;
> - }
> - return 0;
> -}
> -
> -int mshv_arch_post_init_vm(int vm_fd)
> -{
> - int ret;
> -
> - ret = set_unimplemented_msr_action(vm_fd);
> - if (ret < 0) {
> - error_report("Failed to set unimplemented MSR action");
> - }
> -
> - return ret;
> -}
> -
> static void mshv_cpu_xsave_init(void)
> {
> static bool first = true;
>
> --
> 2.45.4
next prev parent reply other threads:[~2026-11-19 15:03 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 [this message]
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
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=av8OTldUyqKQnppQ@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.