From nobody Mon Feb 9 20:35:16 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=1751391011; cv=none; d=zohomail.com; s=zohoarc; b=K6jxPsbQtJUEb3yUE+kc301AgtermfxE8qlVaTGV7Bfyat0RAmrT7cS6WvnKo4kskSiLDDcmK3Rk1AdUZ8kuz0p4zKMcIrTEsrv4OM88QCwdfEG06U447/YpZl6w8Pc855gVHkhwLTOfmV1pn9QFrlPTYoQeUEgO5cf+4eBHhHs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1751391011; 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=K1lIkrlruu6oeT5j1K7etit/5d86FNERSzl80JICpEE=; b=O7S6ZKstQy6BQTpH2tHZKi0/ooEWffj0LeS2/A3JmmZlFwhOq1eyKbwYq+tsXWBMWQkuYUBgSV9RXkxM9ferp/EiO6Yy2gNZ/xiP7Jzdz0m/YX+qBcD/qxUeubpDLrqeU81RONFCu2XvNrHGkvvB1H9fsYeis013ls5QkjGeuV0= 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 1751391011931366.21146686804127; Tue, 1 Jul 2025 10:30:11 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uWenf-0003Mu-Kt; Tue, 01 Jul 2025 13:29:43 -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 1uWena-00038I-9E for qemu-devel@nongnu.org; Tue, 01 Jul 2025 13:29:38 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1uWenU-0006eH-GZ for qemu-devel@nongnu.org; Tue, 01 Jul 2025 13:29:38 -0400 Received: from localhost.localdomain (unknown [167.220.208.67]) by linux.microsoft.com (Postfix) with ESMTPSA id 50359211222F; Tue, 1 Jul 2025 10:29:27 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 50359211222F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1751390970; bh=K1lIkrlruu6oeT5j1K7etit/5d86FNERSzl80JICpEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WjTCB0SClFruSx3+9hSzI7VGOBZ9YvhYOBHqiTalIL3noOlE0uZBeNmlRg2Ii+ZAk AmUK76EE/++Xn2r1eR4fOV7UrRq4H7vauanuVz4MxNLDZuCmonq+WBuv9ju/fdZoVr y1+bOQYtp5sJW84rkU9IguwVzChYiZrH4rGtTaWA= From: Magnus Kulke To: qemu-devel@nongnu.org Cc: Cameron Esfahani , Phil Dennis-Jordan , Roman Bolshakov , Thomas Huth , Zhao Liu , Wei Liu , Paolo Bonzini , Wei Liu , Richard Henderson , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Markus Armbruster , Cornelia Huck , Magnus Kulke , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Michael S. Tsirkin" , =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= , =?UTF-8?q?Alex=20Benn=C3=A9e?= Subject: [PATCH v2 07/27] accel/mshv: Register memory region listeners Date: Tue, 1 Jul 2025 19:28:14 +0200 Message-Id: <20250701172834.44849-8-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250701172834.44849-1-magnuskulke@linux.microsoft.com> References: <20250701172834.44849-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_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 @linux.microsoft.com) X-ZM-MESSAGEID: 1751391013444116600 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 ecc34594c2..9e0590c4f9 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 695a843582..43a22e0f48 100644 --- a/include/system/mshv.h +++ b/include/system/mshv.h @@ -68,6 +68,10 @@ struct AccelCPUState { #define mshv_msi_via_irqfd_enabled() false #endif =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