From nobody Sat Feb 7 07:30:28 2026 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=none dis=none) header.from=linux.microsoft.com ARC-Seal: i=1; a=rsa-sha256; t=1747740869; cv=none; d=zohomail.com; s=zohoarc; b=LoyRDZxbcoHWTN05oiUUzLuC6GP6oIo0NZ2dGMXfihPSF1JuuN4jm2P/N4eb7OfyymlX1T/AFctSS4A+LSOLaaC3Pwwk0lONnGzIiZnxLOz8GXtq1nsTAE3yLyelpX8W0AUy/vlx6qldgPDj51yIE/dnWl2JHxVaUcgEVdkPZQI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1747740869; 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=IcSlCax5u8x7dqCCFvJUa4pzkKDwA5amLgr0eAaZVcw=; b=gcy++g7X2q/pCoitUaNlrRJ8beO3WIz2cEK0FQAGRcLUiEaBCuWLZyUPXOXaLQRYXUFMoJiSZdtP7ZrL4W7+7sog9eFhLzmQ8Jg2giX46rdxToSYdsOeUKuGGih2t0FlMz+d3D9n/fGF4FfJBX5sNVh95yQgBzmhF9ELWr0gHGE= 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=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1747740868905557.6300047107932; Tue, 20 May 2025 04:34:28 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uHLC5-00087A-Il; Tue, 20 May 2025 07:31:37 -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 1uHLC2-00086J-LM for qemu-devel@nongnu.org; Tue, 20 May 2025 07:31:34 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uHLC0-0001GD-JH for qemu-devel@nongnu.org; Tue, 20 May 2025 07:31:34 -0400 Received: from DESKTOP-TUU1E5L.fritz.box (unknown [172.201.77.43]) by linux.microsoft.com (Postfix) with ESMTPSA id E04ED20277CF; Tue, 20 May 2025 04:31:28 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E04ED20277CF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1747740691; bh=IcSlCax5u8x7dqCCFvJUa4pzkKDwA5amLgr0eAaZVcw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AusqkJ6VwdaPIk7KVKzKF4XbTpNmN61VHorijghdV/IX762RlYw+l7eAsAffmAwTx 1M8AGUJHQ9M32FwSGacThAwSefmMhci1sqP8lgQkAu0+iIRy7BHt10b9ongqmAJFLj AIu4hd6n6wFzwM3vvDW4O0jw/XfaP9m5HlOHgHW4= From: Magnus Kulke To: magnuskulke@microsoft.com, qemu-devel@nongnu.org, liuwe@microsoft.com Cc: Paolo Bonzini , "Michael S. Tsirkin" , Wei Liu , Phil Dennis-Jordan , Roman Bolshakov , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Zhao Liu , Richard Henderson , Cameron Esfahani , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= Subject: [RFC PATCH 07/25] accel/mshv: Register memory region listeners Date: Tue, 20 May 2025 13:30:00 +0200 Message-Id: <20250520113018.49569-8-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250520113018.49569-1-magnuskulke@linux.microsoft.com> References: <20250520113018.49569-1-magnuskulke@linux.microsoft.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=13.77.154.182; envelope-from=magnuskulke@linux.microsoft.com; helo=linux.microsoft.com X-Spam_score_int: -19 X-Spam_score: -2.0 X-Spam_bar: -- X-Spam_report: (-2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_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 @linux.microsoft.com) X-ZM-MESSAGEID: 1747740870059116600 Content-Type: text/plain; charset="utf-8" Add memory listener hooks for the MSHV accelerator to track guest memory regions. This enables the backend to respond to region additions, removals and will be used to manage guest memory mappings inside the hypervisor. Actually registering physical memory in the hypervisor is still stubbed out. Signed-off-by: Magnus Kulke --- accel/mshv/mem.c | 25 ++++++++++++++++ accel/mshv/meson.build | 1 + accel/mshv/mshv-all.c | 68 ++++++++++++++++++++++++++++++++++++++++-- include/system/mshv.h | 4 +++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 accel/mshv/mem.c diff --git a/accel/mshv/mem.c b/accel/mshv/mem.c new file mode 100644 index 0000000000..eddd83ae83 --- /dev/null +++ b/accel/mshv/mem.c @@ -0,0 +1,25 @@ +/* + * QEMU MSHV support + * + * Copyright Microsoft, Corp. 2025 + * + * Authors: + * Magnus Kulke + * + * This work is licensed under the terms of the GNU GPL, version 2 or late= r. + * See the COPYING file in the top-level directory. + * + */ + +#include "qemu/osdep.h" +#include "qemu/error-report.h" +#include "system/address-spaces.h" +#include "system/mshv.h" + +void mshv_set_phys_mem(MshvMemoryListener *mml, MemoryRegionSection *secti= on, + bool add) +{ + error_report("unimplemented"); + abort(); +} + diff --git a/accel/mshv/meson.build b/accel/mshv/meson.build index 4c03ac7921..8a6beb3fb1 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( + 'mem.c', 'mshv-all.c' )) =20 diff --git a/accel/mshv/mshv-all.c b/accel/mshv/mshv-all.c index 44605adf94..63b0eca1fc 100644 --- a/accel/mshv/mshv-all.c +++ b/accel/mshv/mshv-all.c @@ -49,10 +49,74 @@ bool mshv_allowed; MshvState *mshv_state; =20 =20 +static void mem_region_add(MemoryListener *listener, + MemoryRegionSection *section) +{ + MshvMemoryListener *mml; + mml =3D container_of(listener, MshvMemoryListener, listener); + memory_region_ref(section->mr); + mshv_set_phys_mem(mml, section, true); +} + +static void mem_region_del(MemoryListener *listener, + MemoryRegionSection *section) +{ + MshvMemoryListener *mml; + mml =3D container_of(listener, MshvMemoryListener, listener); + mshv_set_phys_mem(mml, section, false); + memory_region_unref(section->mr); +} + +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, +}; + +static MemoryListener mshv_io_listener =3D { + .name =3D "mshv", .priority =3D MEMORY_LISTENER_PRIORITY_DEV_BACKEND, + /* MSHV does not support PIO eventfd */ +}; + +static void register_mshv_memory_listener(MshvState *s, MshvMemoryListener= *mml, + AddressSpace *as, int as_id, + const char *name) +{ + int i; + + mml->listener =3D mshv_memory_listener; + mml->listener.name =3D name; + memory_listener_register(&mml->listener, as); + for (i =3D 0; i < s->nr_as; ++i) { + if (!s->as[i].as) { + s->as[i].as =3D as; + s->as[i].ml =3D mml; + break; + } + } +} + + static int mshv_init(MachineState *ms) { - error_report("unimplemented"); - abort(); + MshvState *s; + s =3D MSHV_STATE(ms->accelerator); + + accel_blocker_init(); + + s->vm =3D 0; + + s->nr_as =3D 1; + s->as =3D g_new0(MshvAddressSpace, s->nr_as); + + mshv_state =3D s; + + register_mshv_memory_listener(s, &s->memory_listener, &address_space_m= emory, + 0, "mshv-memory"); + memory_listener_register(&mshv_io_listener, &address_space_io); + + return 0; } =20 static void mshv_start_vcpu_thread(CPUState *cpu) diff --git a/include/system/mshv.h b/include/system/mshv.h index 0858e47def..b93cf027d8 100644 --- a/include/system/mshv.h +++ b/include/system/mshv.h @@ -76,6 +76,10 @@ struct AccelCPUState { #define EFER_LMA ((uint64_t)0x400) #define EFER_LME ((uint64_t)0x100) =20 + +/* memory */ +void mshv_set_phys_mem(MshvMemoryListener *mml, MemoryRegionSection *secti= on, + bool add); /* interrupt */ int mshv_irqchip_add_msi_route(int vector, PCIDevice *dev); int mshv_irqchip_update_msi_route(int virq, MSIMessage msg, PCIDevice *dev= ); --=20 2.34.1