{"id":2219880,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2219880/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260405072857.66484-5-scottjgo@gmail.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/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":"<20260405072857.66484-5-scottjgo@gmail.com>","list_archive_url":null,"date":"2026-04-05T07:28:48","name":"[RFC,04/10] vfio: Prepare existing code for Apple VFIO backend","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"c969d5dfabd61ccb63177b75c07c1f8a44d5db70","submitter":{"id":93060,"url":"http://patchwork.ozlabs.org/api/1.2/people/93060/?format=json","name":"Scott J. Goldman","email":"scottjgo@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260405072857.66484-5-scottjgo@gmail.com/mbox/","series":[{"id":498765,"url":"http://patchwork.ozlabs.org/api/1.2/series/498765/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=498765","date":"2026-04-05T07:28:44","name":"vfio: PCI device passthrough on Apple Silicon Macs","version":1,"mbox":"http://patchwork.ozlabs.org/series/498765/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2219880/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219880/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 (2048-bit key;\n unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256\n header.s=20251104 header.b=UCdT6AHI;\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=lists.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists.gnu.org (lists.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 4fpPJD3QCTz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 05 Apr 2026 17:30:36 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1w9HvM-0003wF-HQ; Sun, 05 Apr 2026 03:29:36 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <scottjgo@gmail.com>)\n id 1w9HvK-0003vR-VB\n for qemu-devel@nongnu.org; Sun, 05 Apr 2026 03:29:34 -0400","from mail-dy1-x132c.google.com ([2607:f8b0:4864:20::132c])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <scottjgo@gmail.com>)\n id 1w9HvI-0007Gn-Ph\n for qemu-devel@nongnu.org; Sun, 05 Apr 2026 03:29:34 -0400","by mail-dy1-x132c.google.com with SMTP id\n 5a478bee46e88-2b6b0500e06so4607999eec.1\n for <qemu-devel@nongnu.org>; Sun, 05 Apr 2026 00:29:32 -0700 (PDT)","from localhost.localdomain ([2601:645:8200:47:41e4:ff2b:ff70:4d75])\n by smtp.gmail.com with ESMTPSA id\n 5a478bee46e88-2cb92ea0ef1sm7636502eec.21.2026.04.05.00.29.29\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Sun, 05 Apr 2026 00:29:30 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775374171; x=1775978971; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=BvX/ruZLVHznPTOumzyShvEw9LLr8MaO+93oE9E08wY=;\n b=UCdT6AHIVLoEnRjQJCpBEOH2nTCJrCaxg0m51vMedrqgLxwN6r08ofEn/xa+f04Jr4\n Kqz9rsi29VMCGrvAjrq7FYGlrTHzhnmduXCQAeNsPCPBQnwlv4XjA5qYwXvcPy3qM90V\n cjEMXXvclo1FYOnGB0x43BAFB6pPpGPpJd7W2Q+p7GiAMz5oEscw3yCGKnTjWcJofc5c\n 7UKTepu+qkbfP7RLTvbZ0PXti1H20gWF54tx5GciltaHmiIfXuTzDeevsoHipqJxXqEt\n 6fPTqIpm5eFBK/I5I6ayCzVzU6CSTPxsrvtQ0ufVHnVAmtQqSUhU/fvuV0+CZzZtuzXI\n BblQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775374171; x=1775978971;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=BvX/ruZLVHznPTOumzyShvEw9LLr8MaO+93oE9E08wY=;\n b=m4IITi3PEOHJVkvbF/vyXJgb50S27En1iSUP8E1UGeizXD97L177Ktup3LfJDhxJ6D\n rjyQVENaTqRheziRWIkSziZsNFKipedEHo+dZHrpvB09akpbFfE7ALcBi3vkLC51QTrt\n 3Lqw1iCbvx6clbc6ccj408bWSDRogknKwGecC68jgUJEqjaMOvSPltndGLYqkzSW+8qJ\n c0V0pEkIfTaz2V0MBCdlLqEoabNHzyuD+lOrrdFHayU1b88bfIg/e3OYKQ2FZDCp3PQu\n ba0hufvt/MDaJgW0S0G9VLJouEy0ZVrXjtC8LFU5cZVDbe5NobGIujP2KbsPQ85nUz4v\n p9Bw==","X-Gm-Message-State":"AOJu0YyzZ9xZqkQd/nOXcbXYkUHxx/nY8QjlGOpk/hIskmiwh6FaVnZx\n rEFRglf+EMF4WnbaK5FYq9yhwnIpOEq5uJwycIwW/l759JV/ffLbMVR4682CCUog6Y8=","X-Gm-Gg":"AeBDievhv4rrURYjFj95+vctVBDh/+SiYnQAJ17BmtqAVSBP+GBwK/Ao5yQtjJH1zB3\n VxARdkXUrJpCPwT4CLeYljEaZ5M4bpy0XYTyvdM2GI4O2V4kT1PdkqnlViHo4DKcOQNPXPtJsJp\n b/GUDIIN1PJUdy2gDee9E0oboUSSCx2Kuk+2xuZYOjqmOX1bnVZVhUDTpYA0kEcqMjM2IJVU32o\n 7LilaigU1fBdP409MPWYoXMF6BVN/asW/yoQw+ErDlPazKfg3iKz+L77/M/NixBG8pMqEfFSOJC\n urX/j9LgiPTD0BTp+qkHt8TJ2DYpwAujKbcUGq1+MEjTCB30GnivI+tGJRMTaHFXflQkXpYSOAH\n BI/llqlqX5nGBew6uBFtRr/tbVqXoCTur/9iy3anvI3R0T/eFN7CGRLaxzk896QkSXxlA4u2MyL\n KQV9NBShhbIl1bNEdTjNwNL14mYVykezd2caNvlUkQlnBQ+nIOmvJb3rftkHd3aP1TAFXFKDpLy\n bcnvIcVjC3TrC3hXyI+Idn1XsQF0oHC/rd7dw==","X-Received":"by 2002:a05:7301:1687:b0:2cb:bc02:6e13 with SMTP id\n 5a478bee46e88-2cbfbf78978mr4369879eec.16.1775374170739;\n Sun, 05 Apr 2026 00:29:30 -0700 (PDT)","From":"\"Scott J. Goldman\" <scottjgo@gmail.com>","To":"qemu-devel@nongnu.org","Cc":"alex@shazbot.org, clg@redhat.com, pbonzini@redhat.com, rbolshakov@ddn.com,\n phil@philjordan.eu, mst@redhat.com, john.levon@nutanix.com,\n thanos.makatos@nutanix.com, qemu-s390x@nongnu.org,\n \"Scott J. Goldman\" <scottjg@umich.edu>,\n \"Scott J. Goldman\" <scottjgo@gmail.com>","Subject":"[RFC PATCH 04/10] vfio: Prepare existing code for Apple VFIO backend","Date":"Sun,  5 Apr 2026 00:28:48 -0700","Message-ID":"<20260405072857.66484-5-scottjgo@gmail.com>","X-Mailer":"git-send-email 2.50.1","In-Reply-To":"<20260405072857.66484-1-scottjgo@gmail.com>","References":"<20260405072857.66484-1-scottjgo@gmail.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=UTF-8","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2607:f8b0:4864:20::132c;\n envelope-from=scottjgo@gmail.com; helo=mail-dy1-x132c.google.com","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=unavailable 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":"From: \"Scott J. Goldman\" <scottjg@umich.edu>\n\nAdjust the shared VFIO code so a non-Linux backend can plug in:\n\n- vfio_device_get_name(): accept a device that already has a name set\n  without requiring sysfsdev or an fd.\n- vfio_device_is_mdev(): return true on Darwin — the dext mediates all\n  device access and manages DMA mappings explicitly, so the mdev\n  assumptions (software-managed DMA, balloon-safe) hold.\n- vfio_device_attach(): select the Apple IOMMU container type on Darwin.\n- vfio_pci_realize(): allow realize when name is pre-set (no sysfsdev),\n  and add a no_bar_quirks flag so subclasses can skip BAR quirk setup.\n- Add TYPE_VFIO_IOMMU_APPLE and TYPE_VFIO_APPLE_PCI type strings.\n\nSigned-off-by: Scott J. Goldman <scottjgo@gmail.com>\n---\n hw/vfio/device.c                 | 20 ++++++++++++++++++++\n hw/vfio/pci.c                    |  8 +++++---\n hw/vfio/pci.h                    |  1 +\n hw/vfio/types.h                  |  2 ++\n include/hw/vfio/vfio-container.h |  1 +\n 5 files changed, 29 insertions(+), 3 deletions(-)","diff":"diff --git a/hw/vfio/device.c b/hw/vfio/device.c\nindex 973fc35b59..338becffa7 100644\n--- a/hw/vfio/device.c\n+++ b/hw/vfio/device.c\n@@ -316,6 +316,13 @@ bool vfio_device_get_name(VFIODevice *vbasedev, Error **errp)\n     struct stat st;\n \n     if (vbasedev->fd < 0) {\n+        if (!vbasedev->sysfsdev) {\n+            if (vbasedev->name) {\n+                return true;\n+            }\n+            error_setg(errp, \"No provided host device\");\n+            return false;\n+        }\n         if (stat(vbasedev->sysfsdev, &st) < 0) {\n             error_setg_errno(errp, errno, \"no such host device\");\n             error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->sysfsdev);\n@@ -404,7 +411,16 @@ bool vfio_device_is_mdev(VFIODevice *vbasedev)\n     g_autofree char *tmp = NULL;\n \n     if (!vbasedev->sysfsdev) {\n+#ifdef CONFIG_DARWIN\n+        /*\n+         * On Darwin the dext mediates all device access and manages DMA\n+         * mappings explicitly, so the mdev assumptions (software-managed\n+         * DMA, balloon-safe) hold.\n+         */\n+        return true;\n+#else\n         return false;\n+#endif\n     }\n \n     tmp = g_strdup_printf(\"%s/subsystem\", vbasedev->sysfsdev);\n@@ -462,9 +478,13 @@ bool vfio_device_attach_by_iommu_type(const char *iommu_type, char *name,\n bool vfio_device_attach(char *name, VFIODevice *vbasedev,\n                         AddressSpace *as, Error **errp)\n {\n+#ifdef CONFIG_DARWIN\n+    const char *iommu_type = TYPE_VFIO_IOMMU_APPLE;\n+#else\n     const char *iommu_type = vbasedev->iommufd ?\n                              TYPE_VFIO_IOMMU_IOMMUFD :\n                              TYPE_VFIO_IOMMU_LEGACY;\n+#endif\n \n     return vfio_device_attach_by_iommu_type(iommu_type, name, vbasedev,\n                                             as, errp);\ndiff --git a/hw/vfio/pci.c b/hw/vfio/pci.c\nindex 5a1c2d8c2e..cf817d9ae7 100644\n--- a/hw/vfio/pci.c\n+++ b/hw/vfio/pci.c\n@@ -3483,7 +3483,7 @@ static void vfio_pci_realize(PCIDevice *pdev, Error **errp)\n     char uuid[UUID_STR_LEN];\n     g_autofree char *name = NULL;\n \n-    if (vbasedev->fd < 0 && !vbasedev->sysfsdev) {\n+    if (vbasedev->fd < 0 && !vbasedev->sysfsdev && !vbasedev->name) {\n         if (!(~vdev->host.domain || ~vdev->host.bus ||\n               ~vdev->host.slot || ~vdev->host.function)) {\n             error_setg(errp, \"No provided host device\");\n@@ -3558,8 +3558,10 @@ static void vfio_pci_realize(PCIDevice *pdev, Error **errp)\n         vfio_vga_quirk_setup(vdev);\n     }\n \n-    for (i = 0; i < PCI_ROM_SLOT; i++) {\n-        vfio_bar_quirk_setup(vdev, i);\n+    if (!vdev->no_bar_quirks) {\n+        for (i = 0; i < PCI_ROM_SLOT; i++) {\n+            vfio_bar_quirk_setup(vdev, i);\n+        }\n     }\n \n     if (!vfio_pci_interrupt_setup(vdev, errp)) {\ndiff --git a/hw/vfio/pci.h b/hw/vfio/pci.h\nindex d6495d7f29..424acd71b6 100644\n--- a/hw/vfio/pci.h\n+++ b/hw/vfio/pci.h\n@@ -187,6 +187,7 @@ struct VFIOPCIDevice {\n     bool defer_kvm_irq_routing;\n     bool clear_parent_atomics_on_exit;\n     bool skip_vsc_check;\n+    bool no_bar_quirks;\n     uint16_t vpasid_cap_offset;\n     VFIODisplay *dpy;\n     Notifier irqchip_change_notifier;\ndiff --git a/hw/vfio/types.h b/hw/vfio/types.h\nindex 5482d90808..b44c234ac4 100644\n--- a/hw/vfio/types.h\n+++ b/hw/vfio/types.h\n@@ -20,4 +20,6 @@\n \n #define TYPE_VFIO_PCI_NOHOTPLUG \"vfio-pci-nohotplug\"\n \n+#define TYPE_VFIO_APPLE_PCI \"vfio-apple-pci\"\n+\n #endif /* HW_VFIO_VFIO_TYPES_H */\ndiff --git a/include/hw/vfio/vfio-container.h b/include/hw/vfio/vfio-container.h\nindex a7d5c5ed67..5ccbabccb4 100644\n--- a/include/hw/vfio/vfio-container.h\n+++ b/include/hw/vfio/vfio-container.h\n@@ -117,6 +117,7 @@ vfio_container_get_page_size_mask(const VFIOContainer *bcontainer)\n #define TYPE_VFIO_IOMMU_SPAPR TYPE_VFIO_IOMMU \"-spapr\"\n #define TYPE_VFIO_IOMMU_IOMMUFD TYPE_VFIO_IOMMU \"-iommufd\"\n #define TYPE_VFIO_IOMMU_USER TYPE_VFIO_IOMMU \"-user\"\n+#define TYPE_VFIO_IOMMU_APPLE TYPE_VFIO_IOMMU \"-apple\"\n \n struct VFIOIOMMUClass {\n     ObjectClass parent_class;\n","prefixes":["RFC","04/10"]}