From nobody Fri Nov 14 23:29:38 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1759996383; cv=none; d=zohomail.com; s=zohoarc; b=eoER4T16Mn+1oX1Mn4dl86aLVE53/TN0FCBcbUFyk1/CM2gxnskphoLl4Ku+aspe/AAIKfe0ZSmGZ0mgQlTGPEVAjTTVnHt2gM5rssRIwBvTEqatvOh+qAeA11iW2VhOitKbBYJP2nM3foB6jmQJmG0dXC6Vl42INGVSmx/FF5A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1759996383; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=/FsnFQ2/HC3jX91Jhs1DvKXLghyh1DJdCBxJnEQWP9w=; b=hfSZ8oVjC/M+NeklZkWsTJ1fQ1fAEhHFZSM7GWVyRP4EMg5OXgANzzNuxWS/FOlCjn+trrNcOLEI6OlgdE329E4cTlNb9FZYIwYhBd5lFXcgH27CL6qkIyVKbRQUcVj0Lm0g2aJWzaHRiC+JvaXjVv4pYkA05/uf/P65qowWgr8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1759996383856327.39082863452177; Thu, 9 Oct 2025 00:53:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1v6lQg-0008I0-Tj; Thu, 09 Oct 2025 03:51:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v6lQd-0008Ge-DU for qemu-devel@nongnu.org; Thu, 09 Oct 2025 03:51:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1v6lQY-0004PJ-Sh for qemu-devel@nongnu.org; Thu, 09 Oct 2025 03:51:11 -0400 Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-505-CTqUHinUPoCWT2qYUYZMXQ-1; Thu, 09 Oct 2025 03:51:04 -0400 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-46e3a049abaso4020085e9.0 for ; Thu, 09 Oct 2025 00:51:03 -0700 (PDT) Received: from [192.168.10.48] ([151.95.36.217]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-46fab648795sm32268175e9.4.2025.10.09.00.50.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Oct 2025 00:50:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1759996265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/FsnFQ2/HC3jX91Jhs1DvKXLghyh1DJdCBxJnEQWP9w=; b=XcrQfnGOGce3FtZYAgAqOpsgiAvaXdVUKm+W0Ghhif2bSYnaNBUUmCHKXphgXyAX0FahGg GfShB9OX8jeidsi0P9qnT0bICIRr77P8DshKvppuar07l8No0De3w9Igel6lGDy7ChnEqr KupOqdH5YUeE6AW5Evv6SnB1GbBan0c= X-MC-Unique: CTqUHinUPoCWT2qYUYZMXQ-1 X-Mimecast-MFC-AGG-ID: CTqUHinUPoCWT2qYUYZMXQ_1759996263 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759996262; x=1760601062; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/FsnFQ2/HC3jX91Jhs1DvKXLghyh1DJdCBxJnEQWP9w=; b=n5qv2QjUsAJNkIT2cDI2yh07CquV9uFS3XnBoujWDIVEDRPNWRAPM/6c9d7pTaCWNp cH6xfXjUVI37wfDqjk9amvtaPQBFB+/ePdhEacm5d//Ls4AiWd0DP7t1gIvSWW5sRKYe 7jRE0fnT/Eu+yDfA+ifYwgO2C8dWrNaREt3sSUkmV3vSZr9snVYjeOfX294Iw3J0BGyH 0RAvhQAJ0sgjS8Y4JyufB40hLR5EnPczkThufJTAPmwx70/KgZSbo2+yUIAdvskxbJ6N 6k7b7uQnhSwd5ZU1UCoj/pReW/eRG2VpNSAl2R1kOlO0/YoIeEnYs7TfZXaoxvakO+w/ zRqQ== X-Gm-Message-State: AOJu0YyhEvXIeQTD3nihZJ6Sc8b5Nn4Gl1/WvKP5GATu3MRyPRzteH1q xErLLIli5ABuJ17upa3Ai65egil63jQE+9yDu8+J/m70FjfIgdSy0cdGeTSRDjjH/W3kBrJn2OT n+XE+EKgqlaDKZQj1RfDDejQc54ZJd692bZITkmy+h8at9bk7uK9SEWC6b+D+rnSEFRo+4dlbA7 DhqynuByKvrFxPPFp9UDBGY4beU7w3a2igxQ7nBDOW9qk= X-Gm-Gg: ASbGncu+RVgFW5z0X7vjmMSkyHCLwYQfm0aXvXbgmg1hBVmVM7H2w7NvvyuzQEMRHL9 s2AaVU2RJeG4ZCs6uywA1YV7QvsoogETKZdcUtrmEUHB3TgnUjW+44ZbQ+DWPf79zTGyJf7r7sD 2SbyjbSVgMLT1AeTwUtlHAwxLcXSY0tBDR4bWYfI3IoAhaYHDFQg88AxcQdRxGZVeGzFPyI6lUY gS3R9TNUj7uYLPs6e1wIWfoWrDYLD9RvVGRtMtbsR8Bn5NeSyEULuJ9UvDVGJAhk+h5T3Nkiowi eAJ1Ycat3D2tts5mf+MDjf8ugLe7jOAGf499ABqpIqoCkfDs8YD0vOz4cf9SKT3DuWPzAaSe5Dr tCckXoNjTXdKR9V7k0jr36rELVYbqnKfpSJHXvIGi4di/q3Hp X-Received: by 2002:a05:600c:6487:b0:46e:4783:1a7a with SMTP id 5b1f17b1804b1-46fa9a8f37emr41701915e9.3.1759996261687; Thu, 09 Oct 2025 00:51:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgdg+9ERiVH283RtVsoURmp1rEjXD2T0RD6mpl06VwQEXl1m7n+B9JOai5dCHF2/U5crW5HA== X-Received: by 2002:a05:600c:6487:b0:46e:4783:1a7a with SMTP id 5b1f17b1804b1-46fa9a8f37emr41701575e9.3.1759996260924; Thu, 09 Oct 2025 00:51:00 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: Magnus Kulke Subject: [PULL 15/35] accel/mshv: Initialize VM partition Date: Thu, 9 Oct 2025 09:50:05 +0200 Message-ID: <20251009075026.505715-16-pbonzini@redhat.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251009075026.505715-1-pbonzini@redhat.com> References: <20251009075026.505715-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -24 X-Spam_score: -2.5 X-Spam_bar: -- X-Spam_report: (-2.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.442, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1759996389101116600 Content-Type: text/plain; charset="utf-8" From: Magnus Kulke Create the MSHV virtual machine by opening a partition and issuing the necessary ioctl to initialize it. This sets up the basic VM structure and initial configuration used by MSHV to manage guest state. Signed-off-by: Magnus Kulke Link: https://lore.kernel.org/r/20250916164847.77883-10-magnuskulke@linux.m= icrosoft.com [Add stubs; fix format strings for trace-events; make mshv_hvcall available only in per-target files; mshv.h/mshv_int.h split. - Paolo] Signed-off-by: Paolo Bonzini --- meson.build | 1 + accel/mshv/trace.h | 14 ++ include/system/mshv.h | 11 +- include/system/mshv_int.h | 25 +++ accel/mshv/irq.c | 399 +++++++++++++++++++++++++++++++++++ accel/mshv/mem.c | 129 ++++++++++- accel/mshv/mshv-all.c | 326 ++++++++++++++++++++++++++++ accel/stubs/mshv-stub.c | 44 ++++ hw/intc/apic.c | 8 + target/i386/mshv/mshv-cpu.c | 72 +++++++ accel/mshv/meson.build | 1 + accel/mshv/trace-events | 26 +++ accel/stubs/meson.build | 1 + target/i386/mshv/meson.build | 1 + 14 files changed, 1054 insertions(+), 4 deletions(-) create mode 100644 accel/mshv/trace.h create mode 100644 accel/mshv/irq.c create mode 100644 accel/stubs/mshv-stub.c create mode 100644 target/i386/mshv/mshv-cpu.c create mode 100644 accel/mshv/trace-events diff --git a/meson.build b/meson.build index 167021ed621..afaefa01722 100644 --- a/meson.build +++ b/meson.build @@ -3668,6 +3668,7 @@ if have_system trace_events_subdirs +=3D [ 'accel/hvf', 'accel/kvm', + 'accel/mshv', 'audio', 'backends', 'backends/tpm', diff --git a/accel/mshv/trace.h b/accel/mshv/trace.h new file mode 100644 index 00000000000..0dca48f9179 --- /dev/null +++ b/accel/mshv/trace.h @@ -0,0 +1,14 @@ +/* + * QEMU MSHV support + * + * Copyright Microsoft, Corp. 2025 + * + * Authors: + * Ziqiao Zhou + * Magnus Kulke + * + * SPDX-License-Identifier: GPL-2.0-or-later + * + */ + +#include "trace/trace-accel_mshv.h" diff --git a/include/system/mshv.h b/include/system/mshv.h index 434ea9682e1..1011e81df47 100644 --- a/include/system/mshv.h +++ b/include/system/mshv.h @@ -31,18 +31,27 @@ #define CONFIG_MSHV_IS_POSSIBLE #endif =20 +#define MSHV_MAX_MSI_ROUTES 4096 + +#define MSHV_PAGE_SHIFT 12 + #ifdef CONFIG_MSHV_IS_POSSIBLE extern bool mshv_allowed; #define mshv_enabled() (mshv_allowed) +#define mshv_msi_via_irqfd_enabled() mshv_enabled() #else /* CONFIG_MSHV_IS_POSSIBLE */ #define mshv_enabled() false -#endif #define mshv_msi_via_irqfd_enabled() false +#endif =20 typedef struct MshvState MshvState; extern MshvState *mshv_state; =20 /* interrupt */ +int mshv_request_interrupt(MshvState *mshv_state, uint32_t interrupt_type,= uint32_t vector, + uint32_t vp_index, bool logical_destination_mod= e, + bool level_triggered); + int mshv_irqchip_add_msi_route(int vector, PCIDevice *dev); int mshv_irqchip_update_msi_route(int virq, MSIMessage msg, PCIDevice *dev= ); void mshv_irqchip_commit_routes(void); diff --git a/include/system/mshv_int.h b/include/system/mshv_int.h index cfa177ff72f..b36124a0ea7 100644 --- a/include/system/mshv_int.h +++ b/include/system/mshv_int.h @@ -36,10 +36,35 @@ struct MshvState { /* number of listeners */ int nr_as; MshvAddressSpace *as; + int fd; }; =20 +typedef struct MshvMsiControl { + bool updated; + GHashTable *gsi_routes; +} MshvMsiControl; + +void mshv_arch_amend_proc_features( + union hv_partition_synthetic_processor_features *features); +int mshv_arch_post_init_vm(int vm_fd); + +#if defined COMPILING_PER_TARGET && defined CONFIG_MSHV_IS_POSSIBLE +int mshv_hvcall(int fd, const struct mshv_root_hvcall *args); +#endif + /* memory */ +typedef struct MshvMemoryRegion { + uint64_t guest_phys_addr; + uint64_t memory_size; + uint64_t userspace_addr; + bool readonly; +} MshvMemoryRegion; + void mshv_set_phys_mem(MshvMemoryListener *mml, MemoryRegionSection *secti= on, bool add); =20 +/* interrupt */ +void mshv_init_msicontrol(void); +int mshv_reserve_ioapic_msi_routes(int vm_fd); + #endif diff --git a/accel/mshv/irq.c b/accel/mshv/irq.c new file mode 100644 index 00000000000..adf8f337d9c --- /dev/null +++ b/accel/mshv/irq.c @@ -0,0 +1,399 @@ +/* + * QEMU MSHV support + * + * Copyright Microsoft, Corp. 2025 + * + * Authors: Ziqiao Zhou + * Magnus Kulke + * Stanislav Kinsburskii + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "linux/mshv.h" +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "hw/hyperv/hvhdk_mini.h" +#include "hw/hyperv/hvgdk_mini.h" +#include "hw/intc/ioapic.h" +#include "hw/pci/msi.h" +#include "system/mshv.h" +#include "system/mshv_int.h" +#include "trace.h" +#include +#include + +#define MSHV_IRQFD_RESAMPLE_FLAG (1 << MSHV_IRQFD_BIT_RESAMPLE) +#define MSHV_IRQFD_BIT_DEASSIGN_FLAG (1 << MSHV_IRQFD_BIT_DEASSIGN) + +static MshvMsiControl *msi_control; +static QemuMutex msi_control_mutex; + +void mshv_init_msicontrol(void) +{ + qemu_mutex_init(&msi_control_mutex); + msi_control =3D g_new0(MshvMsiControl, 1); + msi_control->gsi_routes =3D g_hash_table_new(g_direct_hash, g_direct_e= qual); + msi_control->updated =3D false; +} + +static int set_msi_routing(uint32_t gsi, uint64_t addr, uint32_t data) +{ + struct mshv_user_irq_entry *entry; + uint32_t high_addr =3D addr >> 32; + uint32_t low_addr =3D addr & 0xFFFFFFFF; + GHashTable *gsi_routes; + + trace_mshv_set_msi_routing(gsi, addr, data); + + if (gsi >=3D MSHV_MAX_MSI_ROUTES) { + error_report("gsi >=3D MSHV_MAX_MSI_ROUTES"); + return -1; + } + + assert(msi_control); + + WITH_QEMU_LOCK_GUARD(&msi_control_mutex) { + gsi_routes =3D msi_control->gsi_routes; + entry =3D g_hash_table_lookup(gsi_routes, GINT_TO_POINTER(gsi)); + + if (entry + && entry->address_hi =3D=3D high_addr + && entry->address_lo =3D=3D low_addr + && entry->data =3D=3D data) + { + /* nothing to update */ + return 0; + } + + /* free old entry */ + g_free(entry); + + /* create new entry */ + entry =3D g_new0(struct mshv_user_irq_entry, 1); + entry->gsi =3D gsi; + entry->address_hi =3D high_addr; + entry->address_lo =3D low_addr; + entry->data =3D data; + + g_hash_table_insert(gsi_routes, GINT_TO_POINTER(gsi), entry); + msi_control->updated =3D true; + } + + return 0; +} + +static int add_msi_routing(uint64_t addr, uint32_t data) +{ + struct mshv_user_irq_entry *route_entry; + uint32_t high_addr =3D addr >> 32; + uint32_t low_addr =3D addr & 0xFFFFFFFF; + int gsi; + GHashTable *gsi_routes; + + trace_mshv_add_msi_routing(addr, data); + + assert(msi_control); + + WITH_QEMU_LOCK_GUARD(&msi_control_mutex) { + /* find an empty slot */ + gsi =3D 0; + gsi_routes =3D msi_control->gsi_routes; + while (gsi < MSHV_MAX_MSI_ROUTES) { + route_entry =3D g_hash_table_lookup(gsi_routes, GINT_TO_POINTE= R(gsi)); + if (!route_entry) { + break; + } + gsi++; + } + if (gsi >=3D MSHV_MAX_MSI_ROUTES) { + error_report("No empty gsi slot available"); + return -1; + } + + /* create new entry */ + route_entry =3D g_new0(struct mshv_user_irq_entry, 1); + route_entry->gsi =3D gsi; + route_entry->address_hi =3D high_addr; + route_entry->address_lo =3D low_addr; + route_entry->data =3D data; + + g_hash_table_insert(gsi_routes, GINT_TO_POINTER(gsi), route_entry); + msi_control->updated =3D true; + } + + return gsi; +} + +static int commit_msi_routing_table(int vm_fd) +{ + guint len; + int i, ret; + size_t table_size; + struct mshv_user_irq_table *table; + GHashTableIter iter; + gpointer key, value; + + assert(msi_control); + + WITH_QEMU_LOCK_GUARD(&msi_control_mutex) { + if (!msi_control->updated) { + /* nothing to update */ + return 0; + } + + /* Calculate the size of the table */ + len =3D g_hash_table_size(msi_control->gsi_routes); + table_size =3D sizeof(struct mshv_user_irq_table) + + len * sizeof(struct mshv_user_irq_entry); + table =3D g_malloc0(table_size); + + g_hash_table_iter_init(&iter, msi_control->gsi_routes); + i =3D 0; + while (g_hash_table_iter_next(&iter, &key, &value)) { + struct mshv_user_irq_entry *entry =3D value; + table->entries[i] =3D *entry; + i++; + } + table->nr =3D i; + + trace_mshv_commit_msi_routing_table(vm_fd, len); + + ret =3D ioctl(vm_fd, MSHV_SET_MSI_ROUTING, table); + g_free(table); + if (ret < 0) { + error_report("Failed to commit msi routing table"); + return -1; + } + msi_control->updated =3D false; + } + return 0; +} + +static int remove_msi_routing(uint32_t gsi) +{ + struct mshv_user_irq_entry *route_entry; + GHashTable *gsi_routes; + + trace_mshv_remove_msi_routing(gsi); + + if (gsi >=3D MSHV_MAX_MSI_ROUTES) { + error_report("Invalid GSI: %u", gsi); + return -1; + } + + assert(msi_control); + + WITH_QEMU_LOCK_GUARD(&msi_control_mutex) { + gsi_routes =3D msi_control->gsi_routes; + route_entry =3D g_hash_table_lookup(gsi_routes, GINT_TO_POINTER(gs= i)); + if (route_entry) { + g_hash_table_remove(gsi_routes, GINT_TO_POINTER(gsi)); + g_free(route_entry); + msi_control->updated =3D true; + } + } + + return 0; +} + +/* Pass an eventfd which is to be used for injecting interrupts from userl= and */ +static int irqfd(int vm_fd, int fd, int resample_fd, uint32_t gsi, + uint32_t flags) +{ + int ret; + struct mshv_user_irqfd arg =3D { + .fd =3D fd, + .resamplefd =3D resample_fd, + .gsi =3D gsi, + .flags =3D flags, + }; + + ret =3D ioctl(vm_fd, MSHV_IRQFD, &arg); + if (ret < 0) { + error_report("Failed to set irqfd: gsi=3D%u, fd=3D%d", gsi, fd); + return -1; + } + return ret; +} + +static int register_irqfd(int vm_fd, int event_fd, uint32_t gsi) +{ + int ret; + + trace_mshv_register_irqfd(vm_fd, event_fd, gsi); + + ret =3D irqfd(vm_fd, event_fd, 0, gsi, 0); + if (ret < 0) { + error_report("Failed to register irqfd: gsi=3D%u", gsi); + return -1; + } + return 0; +} + +static int register_irqfd_with_resample(int vm_fd, int event_fd, + int resample_fd, uint32_t gsi) +{ + int ret; + uint32_t flags =3D MSHV_IRQFD_RESAMPLE_FLAG; + + ret =3D irqfd(vm_fd, event_fd, resample_fd, gsi, flags); + if (ret < 0) { + error_report("Failed to register irqfd with resample: gsi=3D%u", g= si); + return -errno; + } + return 0; +} + +static int unregister_irqfd(int vm_fd, int event_fd, uint32_t gsi) +{ + int ret; + uint32_t flags =3D MSHV_IRQFD_BIT_DEASSIGN_FLAG; + + ret =3D irqfd(vm_fd, event_fd, 0, gsi, flags); + if (ret < 0) { + error_report("Failed to unregister irqfd: gsi=3D%u", gsi); + return -errno; + } + return 0; +} + +static int irqchip_update_irqfd_notifier_gsi(const EventNotifier *event, + const EventNotifier *resample, + int virq, bool add) +{ + int fd =3D event_notifier_get_fd(event); + int rfd =3D resample ? event_notifier_get_fd(resample) : -1; + int vm_fd =3D mshv_state->vm; + + trace_mshv_irqchip_update_irqfd_notifier_gsi(fd, rfd, virq, add); + + if (!add) { + return unregister_irqfd(vm_fd, fd, virq); + } + + if (rfd > 0) { + return register_irqfd_with_resample(vm_fd, fd, rfd, virq); + } + + return register_irqfd(vm_fd, fd, virq); +} + + +int mshv_irqchip_add_msi_route(int vector, PCIDevice *dev) +{ + MSIMessage msg =3D { 0, 0 }; + int virq =3D 0; + + if (pci_available && dev) { + msg =3D pci_get_msi_message(dev, vector); + virq =3D add_msi_routing(msg.address, le32_to_cpu(msg.data)); + } + + return virq; +} + +void mshv_irqchip_release_virq(int virq) +{ + remove_msi_routing(virq); +} + +int mshv_irqchip_update_msi_route(int virq, MSIMessage msg, PCIDevice *dev) +{ + int ret; + + ret =3D set_msi_routing(virq, msg.address, le32_to_cpu(msg.data)); + if (ret < 0) { + error_report("Failed to set msi routing"); + return -1; + } + + return 0; +} + +int mshv_request_interrupt(MshvState *mshv_state, uint32_t interrupt_type,= uint32_t vector, + uint32_t vp_index, bool logical_dest_mode, + bool level_triggered) +{ + int ret; + int vm_fd =3D mshv_state->vm; + + if (vector =3D=3D 0) { + warn_report("Ignoring request for interrupt vector 0"); + return 0; + } + + union hv_interrupt_control control =3D { + .interrupt_type =3D interrupt_type, + .level_triggered =3D level_triggered, + .logical_dest_mode =3D logical_dest_mode, + .rsvd =3D 0, + }; + + struct hv_input_assert_virtual_interrupt arg =3D {0}; + arg.control =3D control; + arg.dest_addr =3D (uint64_t)vp_index; + arg.vector =3D vector; + + struct mshv_root_hvcall args =3D {0}; + args.code =3D HVCALL_ASSERT_VIRTUAL_INTERRUPT; + args.in_sz =3D sizeof(arg); + args.in_ptr =3D (uint64_t)&arg; + + ret =3D mshv_hvcall(vm_fd, &args); + if (ret < 0) { + error_report("Failed to request interrupt"); + return -errno; + } + return 0; +} + +void mshv_irqchip_commit_routes(void) +{ + int ret; + int vm_fd =3D mshv_state->vm; + + ret =3D commit_msi_routing_table(vm_fd); + if (ret < 0) { + error_report("Failed to commit msi routing table"); + abort(); + } +} + +int mshv_irqchip_add_irqfd_notifier_gsi(const EventNotifier *event, + const EventNotifier *resample, + int virq) +{ + return irqchip_update_irqfd_notifier_gsi(event, resample, virq, true); +} + +int mshv_irqchip_remove_irqfd_notifier_gsi(const EventNotifier *event, + int virq) +{ + return irqchip_update_irqfd_notifier_gsi(event, NULL, virq, false); +} + +int mshv_reserve_ioapic_msi_routes(int vm_fd) +{ + int ret, gsi; + + /* + * Reserve GSI 0-23 for IOAPIC pins, to avoid conflicts of legacy + * peripherals with MSI-X devices + */ + for (gsi =3D 0; gsi < IOAPIC_NUM_PINS; gsi++) { + ret =3D add_msi_routing(0, 0); + if (ret < 0) { + error_report("Failed to reserve GSI %d", gsi); + return -1; + } + } + + ret =3D commit_msi_routing_table(vm_fd); + if (ret < 0) { + error_report("Failed to commit reserved IOAPIC MSI routes"); + return -1; + } + + return 0; +} diff --git a/accel/mshv/mem.c b/accel/mshv/mem.c index 9889918c31f..a0a40eb3333 100644 --- a/accel/mshv/mem.c +++ b/accel/mshv/mem.c @@ -12,14 +12,137 @@ =20 #include "qemu/osdep.h" #include "qemu/error-report.h" +#include "linux/mshv.h" #include "system/address-spaces.h" #include "system/mshv.h" #include "system/mshv_int.h" +#include "exec/memattrs.h" +#include +#include "trace.h" + +static int set_guest_memory(int vm_fd, + const struct mshv_user_mem_region *region) +{ + int ret; + + ret =3D ioctl(vm_fd, MSHV_SET_GUEST_MEMORY, region); + if (ret < 0) { + error_report("failed to set guest memory"); + return -errno; + } + + return 0; +} + +static int map_or_unmap(int vm_fd, const MshvMemoryRegion *mr, bool map) +{ + struct mshv_user_mem_region region =3D {0}; + + region.guest_pfn =3D mr->guest_phys_addr >> MSHV_PAGE_SHIFT; + region.size =3D mr->memory_size; + region.userspace_addr =3D mr->userspace_addr; + + if (!map) { + region.flags |=3D (1 << MSHV_SET_MEM_BIT_UNMAP); + trace_mshv_unmap_memory(mr->userspace_addr, mr->guest_phys_addr, + mr->memory_size); + return set_guest_memory(vm_fd, ®ion); + } + + region.flags =3D BIT(MSHV_SET_MEM_BIT_EXECUTABLE); + if (!mr->readonly) { + region.flags |=3D BIT(MSHV_SET_MEM_BIT_WRITABLE); + } + + trace_mshv_map_memory(mr->userspace_addr, mr->guest_phys_addr, + mr->memory_size); + return set_guest_memory(vm_fd, ®ion); +} + +static int set_memory(const MshvMemoryRegion *mshv_mr, bool add) +{ + int ret =3D 0; + + if (!mshv_mr) { + error_report("Invalid mshv_mr"); + return -1; + } + + trace_mshv_set_memory(add, mshv_mr->guest_phys_addr, + mshv_mr->memory_size, + mshv_mr->userspace_addr, mshv_mr->readonly, + ret); + return map_or_unmap(mshv_state->vm, mshv_mr, add); +} + +/* + * Calculate and align the start address and the size of the section. + * Return the size. If the size is 0, the aligned section is empty. + */ +static hwaddr align_section(MemoryRegionSection *section, hwaddr *start) +{ + hwaddr size =3D int128_get64(section->size); + hwaddr delta, aligned; + + /* + * works in page size chunks, but the function may be called + * with sub-page size and unaligned start address. Pad the start + * address to next and truncate size to previous page boundary. + */ + aligned =3D ROUND_UP(section->offset_within_address_space, + qemu_real_host_page_size()); + delta =3D aligned - section->offset_within_address_space; + *start =3D aligned; + if (delta > size) { + return 0; + } + + return (size - delta) & qemu_real_host_page_mask(); +} =20 void mshv_set_phys_mem(MshvMemoryListener *mml, MemoryRegionSection *secti= on, bool add) { - error_report("unimplemented"); - abort(); -} + int ret =3D 0; + MemoryRegion *area =3D section->mr; + bool writable =3D !area->readonly && !area->rom_device; + hwaddr start_addr, mr_offset, size; + void *ram; + MshvMemoryRegion mshv_mr =3D {0}; =20 + size =3D align_section(section, &start_addr); + trace_mshv_set_phys_mem(add, section->mr->name, start_addr); + + /* + * If the memory device is a writable non-ram area, we do not + * want to map it into the guest memory. If it is not a ROM device, + * we want to remove mshv memory mapping, so accesses will trap. + */ + if (!memory_region_is_ram(area)) { + if (writable) { + return; + } else if (!area->romd_mode) { + add =3D false; + } + } + + if (!size) { + return; + } + + mr_offset =3D section->offset_within_region + start_addr - + section->offset_within_address_space; + + ram =3D memory_region_get_ram_ptr(area) + mr_offset; + + mshv_mr.guest_phys_addr =3D start_addr; + mshv_mr.memory_size =3D size; + mshv_mr.readonly =3D !writable; + mshv_mr.userspace_addr =3D (uint64_t)ram; + + ret =3D set_memory(&mshv_mr, add); + if (ret < 0) { + error_report("Failed to set memory region"); + abort(); + } +} diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index a684a366775..653195c57c9 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -7,6 +7,7 @@ * Ziqiao Zhou * Magnus Kulke * Jinank Jain + * Wei Liu * * SPDX-License-Identifier: GPL-2.0-or-later * @@ -23,6 +24,7 @@ #include "hw/hyperv/hvhdk.h" #include "hw/hyperv/hvhdk_mini.h" #include "hw/hyperv/hvgdk.h" +#include "hw/hyperv/hvgdk_mini.h" #include "linux/mshv.h" =20 #include "qemu/accel.h" @@ -49,6 +51,175 @@ bool mshv_allowed; =20 MshvState *mshv_state; =20 +static int init_mshv(int *mshv_fd) +{ + int fd =3D open("/dev/mshv", O_RDWR | O_CLOEXEC); + if (fd < 0) { + error_report("Failed to open /dev/mshv: %s", strerror(errno)); + return -1; + } + *mshv_fd =3D fd; + return 0; +} + +/* freeze 1 to pause, 0 to resume */ +static int set_time_freeze(int vm_fd, int freeze) +{ + int ret; + struct hv_input_set_partition_property in =3D {0}; + in.property_code =3D HV_PARTITION_PROPERTY_TIME_FREEZE; + in.property_value =3D freeze; + + struct mshv_root_hvcall args =3D {0}; + args.code =3D HVCALL_SET_PARTITION_PROPERTY; + args.in_sz =3D sizeof(in); + args.in_ptr =3D (uint64_t)∈ + + ret =3D mshv_hvcall(vm_fd, &args); + if (ret < 0) { + error_report("Failed to set time freeze"); + return -1; + } + + return 0; +} + +static int pause_vm(int vm_fd) +{ + int ret; + + ret =3D set_time_freeze(vm_fd, 1); + if (ret < 0) { + error_report("Failed to pause partition: %s", strerror(errno)); + return -1; + } + + return 0; +} + +static int resume_vm(int vm_fd) +{ + int ret; + + ret =3D set_time_freeze(vm_fd, 0); + if (ret < 0) { + error_report("Failed to resume partition: %s", strerror(errno)); + return -1; + } + + return 0; +} + +static int create_partition(int mshv_fd, int *vm_fd) +{ + int ret; + struct mshv_create_partition args =3D {0}; + + /* Initialize pt_flags with the desired features */ + uint64_t pt_flags =3D (1ULL << MSHV_PT_BIT_LAPIC) | + (1ULL << MSHV_PT_BIT_X2APIC) | + (1ULL << MSHV_PT_BIT_GPA_SUPER_PAGES); + + /* Set default isolation type */ + uint64_t pt_isolation =3D MSHV_PT_ISOLATION_NONE; + + args.pt_flags =3D pt_flags; + args.pt_isolation =3D pt_isolation; + + ret =3D ioctl(mshv_fd, MSHV_CREATE_PARTITION, &args); + if (ret < 0) { + error_report("Failed to create partition: %s", strerror(errno)); + return -1; + } + + *vm_fd =3D ret; + return 0; +} + +static int set_synthetic_proc_features(int vm_fd) +{ + int ret; + struct hv_input_set_partition_property in =3D {0}; + union hv_partition_synthetic_processor_features features =3D {0}; + + /* Access the bitfield and set the desired features */ + features.hypervisor_present =3D 1; + features.hv1 =3D 1; + features.access_partition_reference_counter =3D 1; + features.access_synic_regs =3D 1; + features.access_synthetic_timer_regs =3D 1; + features.access_partition_reference_tsc =3D 1; + features.access_frequency_regs =3D 1; + features.access_intr_ctrl_regs =3D 1; + features.access_vp_index =3D 1; + features.access_hypercall_regs =3D 1; + features.tb_flush_hypercalls =3D 1; + features.synthetic_cluster_ipi =3D 1; + features.direct_synthetic_timers =3D 1; + + mshv_arch_amend_proc_features(&features); + + in.property_code =3D HV_PARTITION_PROPERTY_SYNTHETIC_PROC_FEATURES; + in.property_value =3D features.as_uint64[0]; + + struct mshv_root_hvcall args =3D {0}; + args.code =3D HVCALL_SET_PARTITION_PROPERTY; + args.in_sz =3D sizeof(in); + args.in_ptr =3D (uint64_t)∈ + + trace_mshv_hvcall_args("synthetic_proc_features", args.code, args.in_s= z); + + ret =3D mshv_hvcall(vm_fd, &args); + if (ret < 0) { + error_report("Failed to set synthethic proc features"); + return -errno; + } + return 0; +} + +static int initialize_vm(int vm_fd) +{ + int ret =3D ioctl(vm_fd, MSHV_INITIALIZE_PARTITION); + if (ret < 0) { + error_report("Failed to initialize partition: %s", strerror(errno)= ); + return -1; + } + return 0; +} + +static int create_vm(int mshv_fd, int *vm_fd) +{ + int ret =3D create_partition(mshv_fd, vm_fd); + if (ret < 0) { + return -1; + } + + ret =3D set_synthetic_proc_features(*vm_fd); + if (ret < 0) { + return -1; + } + + ret =3D initialize_vm(*vm_fd); + if (ret < 0) { + return -1; + } + + ret =3D mshv_reserve_ioapic_msi_routes(*vm_fd); + if (ret < 0) { + return -1; + } + + ret =3D mshv_arch_post_init_vm(*vm_fd); + if (ret < 0) { + return -1; + } + + /* Always create a frozen partition */ + pause_vm(*vm_fd); + + return 0; +} + static void mem_region_add(MemoryListener *listener, MemoryRegionSection *section) { @@ -67,11 +238,124 @@ static void mem_region_del(MemoryListener *listener, memory_region_unref(section->mr); } =20 +typedef enum { + DATAMATCH_NONE, + DATAMATCH_U32, + DATAMATCH_U64, +} DatamatchTag; + +typedef struct { + DatamatchTag tag; + union { + uint32_t u32; + uint64_t u64; + } value; +} Datamatch; + +/* flags: determine whether to de/assign */ +static int ioeventfd(int vm_fd, int event_fd, uint64_t addr, Datamatch dm, + uint32_t flags) +{ + struct mshv_user_ioeventfd args =3D {0}; + args.fd =3D event_fd; + args.addr =3D addr; + args.flags =3D flags; + + if (dm.tag =3D=3D DATAMATCH_NONE) { + args.datamatch =3D 0; + } else { + flags |=3D BIT(MSHV_IOEVENTFD_BIT_DATAMATCH); + args.flags =3D flags; + if (dm.tag =3D=3D DATAMATCH_U64) { + args.len =3D sizeof(uint64_t); + args.datamatch =3D dm.value.u64; + } else { + args.len =3D sizeof(uint32_t); + args.datamatch =3D dm.value.u32; + } + } + + return ioctl(vm_fd, MSHV_IOEVENTFD, &args); +} + +static int unregister_ioevent(int vm_fd, int event_fd, uint64_t mmio_addr) +{ + uint32_t flags =3D 0; + Datamatch dm =3D {0}; + + flags |=3D BIT(MSHV_IOEVENTFD_BIT_DEASSIGN); + dm.tag =3D DATAMATCH_NONE; + + return ioeventfd(vm_fd, event_fd, mmio_addr, dm, flags); +} + +static int register_ioevent(int vm_fd, int event_fd, uint64_t mmio_addr, + uint64_t val, bool is_64bit, bool is_datamatch) +{ + uint32_t flags =3D 0; + Datamatch dm =3D {0}; + + if (!is_datamatch) { + dm.tag =3D DATAMATCH_NONE; + } else if (is_64bit) { + dm.tag =3D DATAMATCH_U64; + dm.value.u64 =3D val; + } else { + dm.tag =3D DATAMATCH_U32; + dm.value.u32 =3D val; + } + + return ioeventfd(vm_fd, event_fd, mmio_addr, dm, flags); +} + +static void mem_ioeventfd_add(MemoryListener *listener, + MemoryRegionSection *section, + bool match_data, uint64_t data, + EventNotifier *e) +{ + int fd =3D event_notifier_get_fd(e); + int ret; + bool is_64 =3D int128_get64(section->size) =3D=3D 8; + uint64_t addr =3D section->offset_within_address_space; + + trace_mshv_mem_ioeventfd_add(addr, int128_get64(section->size), data); + + ret =3D register_ioevent(mshv_state->vm, fd, addr, data, is_64, match_= data); + + if (ret < 0) { + error_report("Failed to register ioeventfd: %s (%d)", strerror(-re= t), + -ret); + abort(); + } +} + +static void mem_ioeventfd_del(MemoryListener *listener, + MemoryRegionSection *section, + bool match_data, uint64_t data, + EventNotifier *e) +{ + int fd =3D event_notifier_get_fd(e); + int ret; + uint64_t addr =3D section->offset_within_address_space; + + trace_mshv_mem_ioeventfd_del(section->offset_within_address_space, + int128_get64(section->size), data); + + ret =3D unregister_ioevent(mshv_state->vm, fd, addr); + if (ret < 0) { + error_report("Failed to unregister ioeventfd: %s (%d)", strerror(-= ret), + -ret); + abort(); + } +} + static MemoryListener mshv_memory_listener =3D { .name =3D "mshv", .priority =3D MEMORY_LISTENER_PRIORITY_ACCEL, .region_add =3D mem_region_add, .region_del =3D mem_region_del, + .eventfd_add =3D mem_ioeventfd_add, + .eventfd_del =3D mem_ioeventfd_del, }; =20 static MemoryListener mshv_io_listener =3D { @@ -97,15 +381,57 @@ static void register_mshv_memory_listener(MshvState *s= , MshvMemoryListener *mml, } } =20 +int mshv_hvcall(int fd, const struct mshv_root_hvcall *args) +{ + int ret =3D 0; + + ret =3D ioctl(fd, MSHV_ROOT_HVCALL, args); + if (ret < 0) { + error_report("Failed to perform hvcall: %s", strerror(errno)); + return -1; + } + return ret; +} + + static int mshv_init(AccelState *as, MachineState *ms) { MshvState *s; + int mshv_fd, vm_fd, ret; + + if (mshv_state) { + warn_report("MSHV accelerator already initialized"); + return 0; + } + s =3D MSHV_STATE(as); =20 accel_blocker_init(); =20 s->vm =3D 0; =20 + ret =3D init_mshv(&mshv_fd); + if (ret < 0) { + return -1; + } + + mshv_init_msicontrol(); + + ret =3D create_vm(mshv_fd, &vm_fd); + if (ret < 0) { + close(mshv_fd); + return -1; + } + + ret =3D resume_vm(vm_fd); + if (ret < 0) { + close(mshv_fd); + close(vm_fd); + return -1; + } + + s->vm =3D vm_fd; + s->fd =3D mshv_fd; s->nr_as =3D 1; s->as =3D g_new0(MshvAddressSpace, s->nr_as); =20 diff --git a/accel/stubs/mshv-stub.c b/accel/stubs/mshv-stub.c new file mode 100644 index 00000000000..e499b199d9d --- /dev/null +++ b/accel/stubs/mshv-stub.c @@ -0,0 +1,44 @@ +/* + * QEMU MSHV stub + * + * Copyright Red Hat, Inc. 2025 + * + * Author: Paolo Bonzini + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "hw/pci/msi.h" +#include "system/mshv.h" + +bool mshv_allowed; + +int mshv_irqchip_add_msi_route(int vector, PCIDevice *dev) +{ + return -ENOSYS; +} + +void mshv_irqchip_release_virq(int virq) +{ +} + +int mshv_irqchip_update_msi_route(int virq, MSIMessage msg, PCIDevice *dev) +{ + return -ENOSYS; +} + +void mshv_irqchip_commit_routes(void) +{ +} + +int mshv_irqchip_add_irqfd_notifier_gsi(const EventNotifier *n, + const EventNotifier *rn, int virq) +{ + return -ENOSYS; +} + +int mshv_irqchip_remove_irqfd_notifier_gsi(const EventNotifier *n, int vir= q) +{ + return -ENOSYS; +} diff --git a/hw/intc/apic.c b/hw/intc/apic.c index bcb103560c7..6d7859640c2 100644 --- a/hw/intc/apic.c +++ b/hw/intc/apic.c @@ -27,6 +27,7 @@ #include "hw/pci/msi.h" #include "qemu/host-utils.h" #include "system/kvm.h" +#include "system/mshv.h" #include "trace.h" #include "hw/i386/apic-msidef.h" #include "qapi/error.h" @@ -932,6 +933,13 @@ static void apic_send_msi(MSIMessage *msi) uint8_t trigger_mode =3D (data >> MSI_DATA_TRIGGER_SHIFT) & 0x1; uint8_t delivery =3D (data >> MSI_DATA_DELIVERY_MODE_SHIFT) & 0x7; /* XXX: Ignore redirection hint. */ +#ifdef CONFIG_MSHV + if (mshv_enabled()) { + mshv_request_interrupt(mshv_state, delivery, vector, dest, + dest_mode, trigger_mode); + return; + } +#endif apic_deliver_irq(dest, dest_mode, delivery, vector, trigger_mode); } =20 diff --git a/target/i386/mshv/mshv-cpu.c b/target/i386/mshv/mshv-cpu.c new file mode 100644 index 00000000000..de0c26bc6c6 --- /dev/null +++ b/target/i386/mshv/mshv-cpu.c @@ -0,0 +1,72 @@ +/* + * QEMU MSHV support + * + * Copyright Microsoft, Corp. 2025 + * + * 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/typedefs.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 "trace-accel_mshv.h" +#include "trace.h" + +void mshv_arch_amend_proc_features( + union hv_partition_synthetic_processor_features *features) +{ + features->access_guest_idle_reg =3D 1; +} + +/* + * 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 =3D {0}; + struct mshv_root_hvcall args =3D {0}; + + in.property_code =3D HV_PARTITION_PROPERTY_UNIMPLEMENTED_MSR_ACTION; + in.property_value =3D HV_UNIMPLEMENTED_MSR_ACTION_IGNORE_WRITE_READ_ZE= RO; + + args.code =3D HVCALL_SET_PARTITION_PROPERTY; + args.in_sz =3D sizeof(in); + args.in_ptr =3D (uint64_t)∈ + + trace_mshv_hvcall_args("unimplemented_msr_action", args.code, args.in_= sz); + + int ret =3D 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 =3D set_unimplemented_msr_action(vm_fd); + if (ret < 0) { + error_report("Failed to set unimplemented MSR action"); + } + + return ret; +} diff --git a/accel/mshv/meson.build b/accel/mshv/meson.build index 8a6beb3fb1e..f88fc8678c3 100644 --- a/accel/mshv/meson.build +++ b/accel/mshv/meson.build @@ -1,5 +1,6 @@ mshv_ss =3D ss.source_set() mshv_ss.add(if_true: files( + 'irq.c', 'mem.c', 'mshv-all.c' )) diff --git a/accel/mshv/trace-events b/accel/mshv/trace-events new file mode 100644 index 00000000000..6130c4abf8a --- /dev/null +++ b/accel/mshv/trace-events @@ -0,0 +1,26 @@ +# Authors: Ziqiao Zhou +# Magnus Kulke +# +# SPDX-License-Identifier: GPL-2.0-or-later + +mshv_set_memory(bool add, uint64_t gpa, uint64_t size, uint64_t user_addr,= bool readonly, int ret) "add=3D%d gpa=3D0x%" PRIx64 " size=3D0x%" PRIx64 "= user=3D0x%" PRIx64 " readonly=3D%d result=3D%d" +mshv_mem_ioeventfd_add(uint64_t addr, uint32_t size, uint32_t data) "addr= =3D0x%" PRIx64 " size=3D%d data=3D0x%x" +mshv_mem_ioeventfd_del(uint64_t addr, uint32_t size, uint32_t data) "addr= =3D0x%" PRIx64 " size=3D%d data=3D0x%x" + +mshv_hvcall_args(const char* hvcall, uint16_t code, uint16_t in_sz) "built= args for '%s' code: %d in_sz: %d" + +mshv_handle_interrupt(uint32_t cpu, int mask) "cpu_index=3D%d mask=3D0x%x" +mshv_set_msi_routing(uint32_t gsi, uint64_t addr, uint32_t data) "gsi=3D%d= addr=3D0x%" PRIx64 " data=3D0x%x" +mshv_remove_msi_routing(uint32_t gsi) "gsi=3D%d" +mshv_add_msi_routing(uint64_t addr, uint32_t data) "addr=3D0x%" PRIx64 " d= ata=3D0x%x" +mshv_commit_msi_routing_table(int vm_fd, int len) "vm_fd=3D%d table_size= =3D%d" +mshv_register_irqfd(int vm_fd, int event_fd, uint32_t gsi) "vm_fd=3D%d eve= nt_fd=3D%d gsi=3D%d" +mshv_irqchip_update_irqfd_notifier_gsi(int event_fd, int resample_fd, int = virq, bool add) "event_fd=3D%d resample_fd=3D%d virq=3D%d add=3D%d" + +mshv_insn_fetch(uint64_t addr, size_t size) "gpa=3D0x%" PRIx64 " size=3D%z= u" +mshv_mem_write(uint64_t addr, size_t size) "\tgpa=3D0x%" PRIx64 " size=3D%= zu" +mshv_mem_read(uint64_t addr, size_t size) "\tgpa=3D0x%" PRIx64 " size=3D%z= u" +mshv_map_memory(uint64_t userspace_addr, uint64_t gpa, uint64_t size) "\tu= _a=3D0x%" PRIx64 " gpa=3D0x%010" PRIx64 " size=3D0x%08" PRIx64 +mshv_unmap_memory(uint64_t userspace_addr, uint64_t gpa, uint64_t size) "\= tu_a=3D0x%" PRIx64 " gpa=3D0x%010" PRIx64 " size=3D0x%08" PRIx64 +mshv_set_phys_mem(bool add, const char *name, uint64_t gpa) "\tadd=3D%d na= me=3D%s gpa=3D0x%010" PRIx64 +mshv_handle_mmio(uint64_t gva, uint64_t gpa, uint64_t size, uint8_t access= _type) "\tgva=3D0x%" PRIx64 " gpa=3D0x%010" PRIx64 " size=3D0x%" PRIx64 " a= ccess_type=3D%d" diff --git a/accel/stubs/meson.build b/accel/stubs/meson.build index 9dfc4f9ddaf..48eccd1b861 100644 --- a/accel/stubs/meson.build +++ b/accel/stubs/meson.build @@ -5,5 +5,6 @@ system_stubs_ss.add(when: 'CONFIG_TCG', if_false: files('tc= g-stub.c')) system_stubs_ss.add(when: 'CONFIG_HVF', if_false: files('hvf-stub.c')) system_stubs_ss.add(when: 'CONFIG_NVMM', if_false: files('nvmm-stub.c')) system_stubs_ss.add(when: 'CONFIG_WHPX', if_false: files('whpx-stub.c')) +system_stubs_ss.add(when: 'CONFIG_MSHV', if_false: files('mshv-stub.c')) =20 specific_ss.add_all(when: ['CONFIG_SYSTEM_ONLY'], if_true: system_stubs_ss) diff --git a/target/i386/mshv/meson.build b/target/i386/mshv/meson.build index 8ddaa7c11dc..647e5dafb77 100644 --- a/target/i386/mshv/meson.build +++ b/target/i386/mshv/meson.build @@ -1,6 +1,7 @@ i386_mshv_ss =3D ss.source_set() =20 i386_mshv_ss.add(files( + 'mshv-cpu.c', 'x86.c', )) =20 --=20 2.51.0