From nobody Fri Apr 3 22:35:01 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=1774274344; cv=none; d=zohomail.com; s=zohoarc; b=fyxax+zcA1RDrdBqA6C60xeJVja8hXgyYhfVRy4mbp6u3j/wV8aq2Fb/nV4/qo/ARBVzGzVSM0EaDUI3/nrSdqizjfUkulT/TvVNxk4m9ZVhRDzpfJHnXKPbFCAlRi1XDDnQ3aetfcd8cjwsDKbS5HrLuWv2iy+pzCI9Ty7WDqU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1774274344; 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=VJNxhxOOFiPusHtx5YENFOefg54G1/K9ab3YYZ75Ulo=; b=cne2i9FcFu7L4UraWkdxmg7NBYkb0k5TafYpub8YoL26H3VzXBjCwLO2WzbXsQaPLnF0OkWP4RggSCmgtJeTwTZhON7mQqayKKf7j5bKUz3CEPU5sqBlMGuZmQNm8io7g6R1DO3cudlttrc+1L9LJnEq/t9a9Svq33P/wLQ7Q3Y= 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 1774274344523377.62265122005465; Mon, 23 Mar 2026 06:59:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w4fnj-0007un-8i; Mon, 23 Mar 2026 09:58:39 -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 1w4fnh-0007sH-6d for qemu-devel@nongnu.org; Mon, 23 Mar 2026 09:58:37 -0400 Received: from linux.microsoft.com ([13.77.154.182]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w4fnf-0006mc-6u for qemu-devel@nongnu.org; Mon, 23 Mar 2026 09:58:36 -0400 Received: from DESKTOP-TUU1E5L.localdomain (unknown [167.220.208.76]) by linux.microsoft.com (Postfix) with ESMTPSA id DC20120B712D; Mon, 23 Mar 2026 06:58:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com DC20120B712D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1774274313; bh=VJNxhxOOFiPusHtx5YENFOefg54G1/K9ab3YYZ75Ulo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kmLJXyhgRN7R5+fu7zGEnJLXHa4wEDaa2chbJr+BTysKWKE32jzQpMyi9TvaR4F3s 3CTfZBxZH23X+i5hi30IYA8Yof4RusN+Y1SUL3IfKe79MBXRW8+f/iJA8cGZstC5rw aUaEiec25ejvOs1ONncNOT25Ui6WWm9H2edoPwTc= From: Magnus Kulke To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org, Wei Liu , Richard Henderson , Marcelo Tosatti , Marcel Apfelbaum , Wei Liu , Alex Williamson , Paolo Bonzini , Zhao Liu , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Magnus Kulke , Magnus Kulke , "Michael S. Tsirkin" Subject: [RFC 04/32] accel/accel-irq: add AccelRouteChange abstraction Date: Mon, 23 Mar 2026 14:57:44 +0100 Message-Id: <20260323135812.383509-5-magnuskulke@linux.microsoft.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260323135812.383509-1-magnuskulke@linux.microsoft.com> References: <20260323135812.383509-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: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3, 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: qemu development 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: 1774274346429154100 Content-Type: text/plain; charset="utf-8" The accelerated irqchip routines use a record of changes to batch changes when programming routes. Currently this mechanism is coupled to the KVM accelerator, this change introduces an abstraction that replaces KVMRouteChange and keeps a pointer to an abstract AccelState instead of the concrete type, converting the state where necessary. This is done to further align the irqchip programming in the MSHV accelerator with the existing KVM code in QEMU. Subsequent commits will introduce AccelRouteChange to the MSHV accelerator code. Signed-off-by: Magnus Kulke --- accel/accel-irq.c | 4 ++-- accel/kvm/kvm-all.c | 6 +++--- accel/stubs/kvm-stub.c | 2 +- hw/misc/ivshmem-pci.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/virtio-pci.c | 3 +-- include/accel/accel-route.h | 17 +++++++++++++++++ include/system/accel-irq.h | 5 +++-- include/system/kvm.h | 21 ++++++++++----------- include/system/mshv.h | 1 + target/i386/kvm/kvm.c | 2 +- 11 files changed, 41 insertions(+), 24 deletions(-) create mode 100644 include/accel/accel-route.h diff --git a/accel/accel-irq.c b/accel/accel-irq.c index 7f864e35c4..0aa04c033d 100644 --- a/accel/accel-irq.c +++ b/accel/accel-irq.c @@ -16,7 +16,7 @@ #include "system/mshv.h" #include "system/accel-irq.h" =20 -int accel_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *= dev) +int accel_irqchip_add_msi_route(AccelRouteChange *c, int vector, PCIDevice= *dev) { #ifdef CONFIG_MSHV_IS_POSSIBLE if (mshv_msi_via_irqfd_enabled()) { @@ -42,7 +42,7 @@ int accel_irqchip_update_msi_route(int vector, MSIMessage= msg, PCIDevice *dev) return -ENOSYS; } =20 -void accel_irqchip_commit_route_changes(KVMRouteChange *c) +void accel_irqchip_commit_route_changes(AccelRouteChange *c) { #ifdef CONFIG_MSHV_IS_POSSIBLE if (mshv_msi_via_irqfd_enabled()) { diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index 774499d34f..0979545744 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -2359,11 +2359,11 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage ms= g) return kvm_vm_ioctl(s, KVM_SIGNAL_MSI, &msi); } =20 -int kvm_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *de= v) +int kvm_irqchip_add_msi_route(AccelRouteChange *c, int vector, PCIDevice *= dev) { struct kvm_irq_routing_entry kroute =3D {}; int virq; - KVMState *s =3D c->s; + KVMState *s =3D KVM_STATE(c->accel); MSIMessage msg =3D {0, 0}; =20 if (pci_available && dev) { @@ -2506,7 +2506,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg) abort(); } =20 -int kvm_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *de= v) +int kvm_irqchip_add_msi_route(AccelRouteChange *c, int vector, PCIDevice *= dev) { return -ENOSYS; } diff --git a/accel/stubs/kvm-stub.c b/accel/stubs/kvm-stub.c index c4617caac6..32b4b07403 100644 --- a/accel/stubs/kvm-stub.c +++ b/accel/stubs/kvm-stub.c @@ -44,7 +44,7 @@ int kvm_on_sigbus(int code, void *addr) return 1; } =20 -int kvm_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *de= v) +int kvm_irqchip_add_msi_route(AccelRouteChange *c, int vector, PCIDevice *= dev) { return -ENOSYS; } diff --git a/hw/misc/ivshmem-pci.c b/hw/misc/ivshmem-pci.c index c987eebb98..aa8f271755 100644 --- a/hw/misc/ivshmem-pci.c +++ b/hw/misc/ivshmem-pci.c @@ -424,7 +424,7 @@ static void ivshmem_add_kvm_msi_virq(IVShmemState *s, i= nt vector, Error **errp) { PCIDevice *pdev =3D PCI_DEVICE(s); - KVMRouteChange c; + AccelRouteChange c; int ret; =20 IVSHMEM_DPRINTF("ivshmem_add_kvm_msi_virq vector:%d\n", vector); diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 94c174a773..e48f4add4e 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -51,7 +51,7 @@ #include "vfio-helpers.h" =20 /* Protected by BQL */ -static KVMRouteChange vfio_route_change; +static AccelRouteChange vfio_route_change; =20 static void vfio_disable_interrupts(VFIOPCIDevice *vdev); static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled); diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index bcab2d18b8..5010572784 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -869,7 +869,7 @@ static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy = *proxy, int ret; =20 if (irqfd->users =3D=3D 0) { - KVMRouteChange c =3D kvm_irqchip_begin_route_changes(kvm_state); + AccelRouteChange c =3D kvm_irqchip_begin_route_changes(kvm_state); ret =3D accel_irqchip_add_msi_route(&c, vector, &proxy->pci_dev); if (ret < 0) { return ret; @@ -2695,4 +2695,3 @@ static void virtio_pci_register_types(void) } =20 type_init(virtio_pci_register_types) - diff --git a/include/accel/accel-route.h b/include/accel/accel-route.h new file mode 100644 index 0000000000..07fac27e2a --- /dev/null +++ b/include/accel/accel-route.h @@ -0,0 +1,17 @@ +/* + * Accelerator MSI route change tracking + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef ACCEL_ROUTE_H +#define ACCEL_ROUTE_H + +#include "qemu/accel.h" + +typedef struct AccelRouteChange { + AccelState *accel; + int changes; +} AccelRouteChange; + +#endif /* ACCEL_ROUTE_H */ diff --git a/include/system/accel-irq.h b/include/system/accel-irq.h index a2caa06f54..a148920711 100644 --- a/include/system/accel-irq.h +++ b/include/system/accel-irq.h @@ -25,9 +25,10 @@ static inline bool accel_irqchip_is_split(void) return mshv_msi_via_irqfd_enabled() || kvm_irqchip_is_split(); } =20 -int accel_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *= dev); +int accel_irqchip_add_msi_route(AccelRouteChange *c, int vector, + PCIDevice *dev); int accel_irqchip_update_msi_route(int vector, MSIMessage msg, PCIDevice *= dev); -void accel_irqchip_commit_route_changes(KVMRouteChange *c); +void accel_irqchip_commit_route_changes(AccelRouteChange *c); void accel_irqchip_commit_routes(void); void accel_irqchip_release_virq(int virq); int accel_irqchip_add_irqfd_notifier_gsi(EventNotifier *n, EventNotifier *= rn, diff --git a/include/system/kvm.h b/include/system/kvm.h index 5fa33eddda..ccf90b8341 100644 --- a/include/system/kvm.h +++ b/include/system/kvm.h @@ -18,6 +18,7 @@ =20 #include "exec/memattrs.h" #include "qemu/accel.h" +#include "accel/accel-route.h" #include "qom/object.h" =20 #ifdef COMPILING_PER_TARGET @@ -183,11 +184,6 @@ extern KVMState *kvm_state; typedef struct Notifier Notifier; typedef struct NotifierWithReturn NotifierWithReturn; =20 -typedef struct KVMRouteChange { - KVMState *s; - int changes; -} KVMRouteChange; - /* external API */ =20 unsigned int kvm_get_max_memslots(void); @@ -466,7 +462,7 @@ void kvm_init_cpu_signals(CPUState *cpu); =20 /** * kvm_irqchip_add_msi_route - Add MSI route for specific vector - * @c: KVMRouteChange instance. + * @c: AccelRouteChange instance. * @vector: which vector to add. This can be either MSI/MSIX * vector. The function will automatically detect whether * MSI/MSIX is enabled, and fetch corresponding MSI @@ -475,20 +471,23 @@ void kvm_init_cpu_signals(CPUState *cpu); * as @NULL, an empty MSI message will be inited. * @return: virq (>=3D0) when success, errno (<0) when failed. */ -int kvm_irqchip_add_msi_route(KVMRouteChange *c, int vector, PCIDevice *de= v); +int kvm_irqchip_add_msi_route(AccelRouteChange *c, int vector, PCIDevice *= dev); int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg, PCIDevice *dev); void kvm_irqchip_commit_routes(KVMState *s); =20 -static inline KVMRouteChange kvm_irqchip_begin_route_changes(KVMState *s) +static inline AccelRouteChange kvm_irqchip_begin_route_changes(KVMState *s) { - return (KVMRouteChange) { .s =3D s, .changes =3D 0 }; + return (AccelRouteChange) { + .accel =3D ACCEL(s), + .changes =3D 0, + }; } =20 -static inline void kvm_irqchip_commit_route_changes(KVMRouteChange *c) +static inline void kvm_irqchip_commit_route_changes(AccelRouteChange *c) { if (c->changes) { - kvm_irqchip_commit_routes(c->s); + kvm_irqchip_commit_routes(KVM_STATE(c->accel)); c->changes =3D 0; } } diff --git a/include/system/mshv.h b/include/system/mshv.h index 75286baf16..1e96b3a606 100644 --- a/include/system/mshv.h +++ b/include/system/mshv.h @@ -21,6 +21,7 @@ #include "qapi/qapi-types-common.h" #include "system/memory.h" #include "accel/accel-ops.h" +#include "accel/accel-route.h" =20 #ifdef COMPILING_PER_TARGET #ifdef CONFIG_MSHV diff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c index a29f757c16..9cc41758d7 100644 --- a/target/i386/kvm/kvm.c +++ b/target/i386/kvm/kvm.c @@ -6680,7 +6680,7 @@ void kvm_arch_init_irq_routing(KVMState *s) kvm_gsi_routing_allowed =3D true; =20 if (kvm_irqchip_is_split()) { - KVMRouteChange c =3D kvm_irqchip_begin_route_changes(s); + AccelRouteChange c =3D kvm_irqchip_begin_route_changes(s); int i; =20 /* If the ioapic is in QEMU and the lapics are in KVM, reserve --=20 2.34.1