{"id":2224379,"url":"http://patchwork.ozlabs.org/api/patches/2224379/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260417105618.3621-6-magnuskulke@linux.microsoft.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260417105618.3621-6-magnuskulke@linux.microsoft.com>","list_archive_url":null,"date":"2026-04-17T10:55:49","name":"[05/34] accel/accel-irq: add generic begin_route_changes","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c1bf64c22bf88fec34f178fc2ec7d4cef306fc3a","submitter":{"id":90753,"url":"http://patchwork.ozlabs.org/api/people/90753/?format=json","name":"Magnus Kulke","email":"magnuskulke@linux.microsoft.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260417105618.3621-6-magnuskulke@linux.microsoft.com/mbox/","series":[{"id":500310,"url":"http://patchwork.ozlabs.org/api/series/500310/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=500310","date":"2026-04-17T10:55:44","name":"Add migration support to the MSHV accelerator","version":1,"mbox":"http://patchwork.ozlabs.org/series/500310/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2224379/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2224379/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=linux.microsoft.com header.i=@linux.microsoft.com\n header.a=rsa-sha256 header.s=default header.b=fEL9vQJP;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fxsKF6jcYz1yD3\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 17 Apr 2026 20:57:21 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wDgsR-0000MO-OC; Fri, 17 Apr 2026 06:56:47 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <magnuskulke@linux.microsoft.com>)\n id 1wDgsQ-0000M3-0W\n for qemu-devel@nongnu.org; Fri, 17 Apr 2026 06:56:46 -0400","from linux.microsoft.com ([13.77.154.182])\n by eggs.gnu.org with esmtp (Exim 4.90_1)\n (envelope-from <magnuskulke@linux.microsoft.com>) id 1wDgsO-0001WR-9s\n for qemu-devel@nongnu.org; Fri, 17 Apr 2026 06:56:45 -0400","from DESKTOP-TUU1E5L.fritz.box (p5086d620.dip0.t-ipconnect.de\n [80.134.214.32])\n by linux.microsoft.com (Postfix) with ESMTPSA id 4F46120B7129;\n Fri, 17 Apr 2026 03:56:40 -0700 (PDT)"],"DKIM-Filter":"OpenDKIM Filter v2.11.0 linux.microsoft.com 4F46120B7129","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com;\n s=default; t=1776423403;\n bh=UrEJXgspDcOoBFg+ngjPWDmPz3RH/NkqLVlRSZU3lZk=;\n h=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n b=fEL9vQJPdXVAFy2plFIi2tu6sY2Gg2yhHIhsvNjpfgw+2DhFndhyWeryD6F+hpXqg\n IrLZd21OQwOaoLL60ZWMmRSks22RuJH5tpHNpAvCf37nXa7zqc4yKPPGPHVI/zv2c8\n CUdoaHlJb67XPbFyNxqKmjU+lGNpW1w4rp99z0sk=","From":"Magnus Kulke <magnuskulke@linux.microsoft.com>","To":"qemu-devel@nongnu.org","Cc":"kvm@vger.kernel.org, Magnus Kulke <magnuskulke@microsoft.com>,\n Wei Liu <liuwe@microsoft.com>, \"Michael S. Tsirkin\" <mst@redhat.com>,\n\t=?utf-8?q?C=C3=A9dric_Le_Goater?= <clg@redhat.com>,\n Zhao Liu <zhao1.liu@intel.com>,\n Richard Henderson <richard.henderson@linaro.org>,\n Paolo Bonzini <pbonzini@redhat.com>, Wei Liu <wei.liu@kernel.org>,\n Magnus Kulke <magnuskulke@linux.microsoft.com>,\n Alex Williamson <alex@shazbot.org>,\n Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, =?utf-8?q?Philippe_Mathieu-D?=\n\t=?utf-8?q?aud=C3=A9?= <philmd@linaro.org>,\n Marcelo Tosatti <mtosatti@redhat.com>","Subject":"[PATCH 05/34] accel/accel-irq: add generic begin_route_changes","Date":"Fri, 17 Apr 2026 12:55:49 +0200","Message-Id":"<20260417105618.3621-6-magnuskulke@linux.microsoft.com>","X-Mailer":"git-send-email 2.34.1","In-Reply-To":"<20260417105618.3621-1-magnuskulke@linux.microsoft.com>","References":"<20260417105618.3621-1-magnuskulke@linux.microsoft.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=13.77.154.182;\n 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,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, RCVD_IN_DNSWL_MED=-2.3,\n RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001,\n 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 <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"A generic accel_irqchip_begin_route_change() fn has been introduced for\nusage in the MSHV accelerator. It replaces the respective kvm_ fn.\n\nSigned-off-by: Magnus Kulke <magnuskulke@linux.microsoft.com>\n---\n accel/accel-irq.c          | 21 +++++++++++++++++++++\n hw/misc/ivshmem-pci.c      |  4 ++--\n hw/vfio/pci.c              |  5 +++--\n hw/virtio/virtio-pci.c     |  2 +-\n include/system/accel-irq.h |  1 +\n include/system/kvm.h       |  8 --------\n target/i386/kvm/kvm.c      |  3 ++-\n 7 files changed, 30 insertions(+), 14 deletions(-)","diff":"diff --git a/accel/accel-irq.c b/accel/accel-irq.c\nindex 0aa04c033d..3815f6727c 100644\n--- a/accel/accel-irq.c\n+++ b/accel/accel-irq.c\n@@ -10,6 +10,7 @@\n  */\n \n #include \"qemu/osdep.h\"\n+#include \"qemu/error-report.h\"\n #include \"hw/pci/msi.h\"\n \n #include \"system/kvm.h\"\n@@ -104,3 +105,23 @@ int accel_irqchip_remove_irqfd_notifier_gsi(EventNotifier *n, int virq)\n     }\n     return -ENOSYS;\n }\n+\n+inline AccelRouteChange accel_irqchip_begin_route_changes(void)\n+{\n+#ifdef CONFIG_MSHV_IS_POSSIBLE\n+    if (mshv_msi_via_irqfd_enabled()) {\n+        return (AccelRouteChange) {\n+            .accel = ACCEL(mshv_state),\n+            .changes = 0,\n+        };\n+    }\n+#endif\n+    if (kvm_enabled()) {\n+        return (AccelRouteChange) {\n+            .accel = ACCEL(kvm_state),\n+            .changes = 0,\n+        };\n+    }\n+    error_report(\"can't initiate route change, no accel irqchip available\");\n+    abort();\n+}\ndiff --git a/hw/misc/ivshmem-pci.c b/hw/misc/ivshmem-pci.c\nindex aa8f271755..fa23562886 100644\n--- a/hw/misc/ivshmem-pci.c\n+++ b/hw/misc/ivshmem-pci.c\n@@ -26,7 +26,7 @@\n #include \"hw/core/qdev-properties-system.h\"\n #include \"hw/pci/msi.h\"\n #include \"hw/pci/msix.h\"\n-#include \"system/kvm.h\"\n+#include \"system/accel-irq.h\"\n #include \"migration/blocker.h\"\n #include \"migration/vmstate.h\"\n #include \"qemu/error-report.h\"\n@@ -430,7 +430,7 @@ static void ivshmem_add_kvm_msi_virq(IVShmemState *s, int vector,\n     IVSHMEM_DPRINTF(\"ivshmem_add_kvm_msi_virq vector:%d\\n\", vector);\n     assert(!s->msi_vectors[vector].pdev);\n \n-    c = kvm_irqchip_begin_route_changes(kvm_state);\n+    c = accel_irqchip_begin_route_changes();\n     ret = kvm_irqchip_add_msi_route(&c, vector, pdev);\n     if (ret < 0) {\n         error_setg(errp, \"kvm_irqchip_add_msi_route failed\");\ndiff --git a/hw/vfio/pci.c b/hw/vfio/pci.c\nindex 79c503c8ae..35b4545482 100644\n--- a/hw/vfio/pci.c\n+++ b/hw/vfio/pci.c\n@@ -39,6 +39,7 @@\n #include \"qemu/module.h\"\n #include \"qemu/range.h\"\n #include \"qemu/units.h\"\n+#include \"system/accel-irq.h\"\n #include \"system/kvm.h\"\n #include \"system/runstate.h\"\n #include \"pci.h\"\n@@ -692,7 +693,7 @@ static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr,\n             if (vdev->defer_kvm_irq_routing) {\n                 vfio_pci_add_kvm_msi_virq(vdev, vector, nr, true);\n             } else {\n-                vfio_route_change = kvm_irqchip_begin_route_changes(kvm_state);\n+                vfio_route_change = accel_irqchip_begin_route_changes();\n                 vfio_pci_add_kvm_msi_virq(vdev, vector, nr, true);\n                 kvm_irqchip_commit_route_changes(&vfio_route_change);\n                 vfio_connect_kvm_msi_virq(vector, nr);\n@@ -793,7 +794,7 @@ void vfio_pci_prepare_kvm_msi_virq_batch(VFIOPCIDevice *vdev)\n {\n     assert(!vdev->defer_kvm_irq_routing);\n     vdev->defer_kvm_irq_routing = true;\n-    vfio_route_change = kvm_irqchip_begin_route_changes(kvm_state);\n+    vfio_route_change = accel_irqchip_begin_route_changes();\n }\n \n void vfio_pci_commit_kvm_msi_virq_batch(VFIOPCIDevice *vdev)\ndiff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c\nindex 5010572784..faa4a41cca 100644\n--- a/hw/virtio/virtio-pci.c\n+++ b/hw/virtio/virtio-pci.c\n@@ -869,7 +869,7 @@ static int kvm_virtio_pci_vq_vector_use(VirtIOPCIProxy *proxy,\n     int ret;\n \n     if (irqfd->users == 0) {\n-        AccelRouteChange c = kvm_irqchip_begin_route_changes(kvm_state);\n+        AccelRouteChange c = accel_irqchip_begin_route_changes();\n         ret = accel_irqchip_add_msi_route(&c, vector, &proxy->pci_dev);\n         if (ret < 0) {\n             return ret;\ndiff --git a/include/system/accel-irq.h b/include/system/accel-irq.h\nindex a148920711..fc94c54264 100644\n--- a/include/system/accel-irq.h\n+++ b/include/system/accel-irq.h\n@@ -25,6 +25,7 @@ static inline bool accel_irqchip_is_split(void)\n     return mshv_msi_via_irqfd_enabled() || kvm_irqchip_is_split();\n }\n \n+AccelRouteChange accel_irqchip_begin_route_changes(void);\n int accel_irqchip_add_msi_route(AccelRouteChange *c, int vector,\n                                 PCIDevice *dev);\n int accel_irqchip_update_msi_route(int vector, MSIMessage msg, PCIDevice *dev);\ndiff --git a/include/system/kvm.h b/include/system/kvm.h\nindex ccf90b8341..fec24d2135 100644\n--- a/include/system/kvm.h\n+++ b/include/system/kvm.h\n@@ -476,14 +476,6 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg,\n                                  PCIDevice *dev);\n void kvm_irqchip_commit_routes(KVMState *s);\n \n-static inline AccelRouteChange kvm_irqchip_begin_route_changes(KVMState *s)\n-{\n-    return (AccelRouteChange) {\n-        .accel = ACCEL(s),\n-        .changes = 0,\n-    };\n-}\n-\n static inline void kvm_irqchip_commit_route_changes(AccelRouteChange *c)\n {\n     if (c->changes) {\ndiff --git a/target/i386/kvm/kvm.c b/target/i386/kvm/kvm.c\nindex 478a5573cd..03312922d5 100644\n--- a/target/i386/kvm/kvm.c\n+++ b/target/i386/kvm/kvm.c\n@@ -32,6 +32,7 @@\n #include \"vmsr_energy.h\"\n #include \"system/system.h\"\n #include \"system/hw_accel.h\"\n+#include \"system/accel-irq.h\"\n #include \"system/kvm_int.h\"\n #include \"system/runstate.h\"\n #include \"system/ramblock.h\"\n@@ -6678,7 +6679,7 @@ void kvm_arch_init_irq_routing(KVMState *s)\n     kvm_gsi_routing_allowed = true;\n \n     if (kvm_irqchip_is_split()) {\n-        AccelRouteChange c = kvm_irqchip_begin_route_changes(s);\n+        AccelRouteChange c = accel_irqchip_begin_route_changes();\n         int i;\n \n         /* If the ioapic is in QEMU and the lapics are in KVM, reserve\n","prefixes":["05/34"]}