From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1B4D8606A320 for ; Thu, 19 Nov 2026 15:03:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com header.a=rsa-sha256 header.s=default header.b=s2VGFV5S Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xU3fW-0000NQ-RN; Thu, 19 Nov 2026 10:03:22 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xU3Zu-000393-Mn; Thu, 19 Nov 2026 09:57:36 -0500 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xU3Zr-0007u4-86; Thu, 19 Nov 2026 09:57:34 -0500 Received: from example.com (unknown [167.220.208.76]) by linux.microsoft.com (Postfix) with ESMTPSA id B613A20B716A; Thu, 19 Nov 2026 06:57:24 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B613A20B716A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1795100248; bh=H4E2pt5Jzb29mE5WvYKWv8kXQcxb3SOEBPwaSH2tLaI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=s2VGFV5SNvV6HwJEDa4bxv+AstzNCtRIIRCfN7SfdJAhWzxgWIt88gH/TQQsrV3j4 QhhEoeMuYVJKt4pkF3ruYaGmgyXJmNzFjrVzoPr6XKywUuS1jxWQxr2SHViNQRLsmc HFnmi0ewog3h+gJlCOIXDqWZTqq/f7ISGFoai2dQ= Date: Thu, 19 Nov 2026 15:57:18 +0100 From: Magnus Kulke To: Aastha Rawat Cc: qemu-devel@nongnu.org, Wei Liu , Doru =?iso-8859-1?Q?Bl=E2nzeanu?= , Paolo Bonzini , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Daniel =?iso-8859-1?Q?P=2E_Berrang=E9?= , Pierrick Bouvier , Peter Maydell , Anirudh Rayabharam , qemu-arm@nongnu.org, Alexander Graf , Pedro Barbuda , Mohamed Mediouni , "Michael S. Tsirkin" , Richard Henderson , Philippe =?iso-8859-1?Q?Mathieu-Daud=E9?= Subject: Re: [PATCH v6 02/14] accel/mshv: add arch-specific accelerator init hook Message-ID: References: <20261001-mshv_accel_arm64_supp-v6-0-aefe5e76a0e3@linux.microsoft.com> <20261001-mshv_accel_arm64_supp-v6-2-aefe5e76a0e3@linux.microsoft.com> X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261001-mshv_accel_arm64_supp-v6-2-aefe5e76a0e3@linux.microsoft.com> Received-SPF: pass client-ip=13.77.154.182; envelope-from=magnuskulke@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -26 X-Spam_score: -2.7 X-Spam_bar: -- X-Spam_report: (-2.7 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Thu, Oct 01, 2026 at 10:52:47AM +0000, Aastha Rawat wrote: > From: "Anirudh Rayabharam (Microsoft)" > > 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) > --- > 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 > + * Magnus Kulke > + * Jinank Jain > + * > + * 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 > + > +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