{"id":2219881,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2219881/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260405072857.66484-7-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-7-scottjgo@gmail.com>","list_archive_url":null,"date":"2026-04-05T07:28:50","name":"[RFC,06/10] vfio: Add device_reset callback to VFIODeviceIOOps","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"9b1a405b00ea98fb3ed1e384b7cb5bfb83d49591","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-7-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/2219881/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2219881/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=ZCV2QlFG;\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 4fpPJD5vXGz1yFs\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 1w9HvP-0003xa-S7; Sun, 05 Apr 2026 03:29:39 -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 1w9HvN-0003wf-SL\n for qemu-devel@nongnu.org; Sun, 05 Apr 2026 03:29:37 -0400","from mail-dy1-x1332.google.com ([2607:f8b0:4864:20::1332])\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 1w9HvM-0007Ls-6e\n for qemu-devel@nongnu.org; Sun, 05 Apr 2026 03:29:37 -0400","by mail-dy1-x1332.google.com with SMTP id\n 5a478bee46e88-2c56aa62931so7205459eec.0\n for <qemu-devel@nongnu.org>; Sun, 05 Apr 2026 00:29:35 -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.32\n (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256);\n Sun, 05 Apr 2026 00:29:34 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=gmail.com; s=20251104; t=1775374174; x=1775978974; 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=YLtrvafoDrJyXblIjHcl3upLz3DHq6xj+dch2j8+x6I=;\n b=ZCV2QlFGExB45llkySP4a2T2IDl0xcwJhIXhoOdzx2zMJeRnzC5fXVA3qFODG/D407\n HTkmW7KcqA6tQ1C30QeSWP53jGabwH01z2ZBf7uRQkX7eFQ3XjLpRjMxtV8W54Z4Kw8B\n ZYJ5jLukOkQWomSXAO/LGtgG2tGQ5kXXpmXojvp3z0UE5VcQ6jqxSklW3PhjoxJpKf95\n YNboIAJ5LHZTbyoAALNRLyMWYq+25im/DbC/W5hvYMnJeAarEsNkaIJC0R1A1q7SYejF\n gBGCRSHLkvUrerY75XzOg40m1XJ/Ldy5srRppw0+8pon5f9dOOrejTzlGNL9O5+d3Lxg\n dapw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1775374174; x=1775978974;\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=YLtrvafoDrJyXblIjHcl3upLz3DHq6xj+dch2j8+x6I=;\n b=Be2Jf3RetRt0HA+LEhuVY0v/1k+w54wA+br6kHnal9ZB80agdtsYrzXGNbIAUlZfsA\n cl/RTa8k+8qgLxpV7BYg7jZet5s1sPWVddmwtf0vfop8Z6B4uV7Of8i3r+qW/ZrZFt7I\n w7OWjcVexHjXw/mLSTQf4Hoa+EpK8JOpl7+dQNUHeY0FVtMqwGt/u4dUQVhyzS3gNw59\n sIh9EMXqm17jf2rSFb9xvwagqoHakuqZJwcifUSX6RejUd1xCMfuDXrouKnVKn4Nja33\n WSSkqhuZmUB3rrHCadsg+ISX94oxpaSUZDhDBrfM+PSkOu1xOckBwb/2imrPkSJD/kr9\n 2dwg==","X-Gm-Message-State":"AOJu0YzS3NNTzek36uwWuUYvyTbMofD7WCSj6vix3Ruye1KniGrBwQTj\n y+UWO6C/PjMIUbRd9TWkzFj52iJCafc7i221XuFTZYAvdvyTtqFSLOIVvewDLmb8QoQ=","X-Gm-Gg":"AeBDievuyop0YQhpA+cbD341AVeUcHMbY+YUvl0f/9pDCwZ8Iq379YqMW1WTV8ZIW8t\n Jb5l5n9gtDbYvLpZo8QAgog6RPfk8dIdBNcN8fKgUa1b2pThXrMeW89PXXmuak7ER1zIBkSQnth\n uqUddwYEYx1j6qXQMeLo76KJ9SdoS9OAAJ6esFoz2KsQf9BwKnrp3tn7DYn4Dz/pzHdg3Lv04Ov\n FkDpPxccuNeyz5LNbxA3TEjdTPsc2d+rzf1khILmJPOL9xtwCjgvFtS5DB4Mt8fsC9338bgGPOW\n vyB/5Xbho5XZ+75uPv5uVm6KudhaorHlFdz9D6xlOmd8DJ8JW6hJSCJiDtNkneE5nXE2RGvaj2Z\n XLBM1GpZQI+SUTw97LSAzdKlKPlCWjUpN9thpJ64sge97izgJ9q36hmiXI1an8d+9OQngpqsqbz\n axyNyFHIA/nP+CeDyxRRt+z8xfzxlXq+wdipNa6YpWb9pdDat10xfxgsCOgee8BRhKstkMeZiyD\n wFdsfzbmFSrVU4JKcdXdqope0k=","X-Received":"by 2002:a05:7300:371f:b0:2c5:76d1:7f95 with SMTP id\n 5a478bee46e88-2cbfc763331mr4392826eec.28.1775374174457;\n Sun, 05 Apr 2026 00:29:34 -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\" <scottjgo@gmail.com>","Subject":"[RFC PATCH 06/10] vfio: Add device_reset callback to VFIODeviceIOOps","Date":"Sun,  5 Apr 2026 00:28:50 -0700","Message-ID":"<20260405072857.66484-7-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-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2607:f8b0:4864:20::1332;\n envelope-from=scottjgo@gmail.com; helo=mail-dy1-x1332.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":"Route all VFIO_DEVICE_RESET ioctl calls through a new device_reset\nio_ops callback, matching the pattern established for region_map and\nregion_unmap. This allows non-Linux backends to provide their own\nreset implementation.\n\nThe Linux ioctl backend implements the callback by issuing the\nVFIO_DEVICE_RESET ioctl. All existing callsites in pci.c, ccw.c,\nap.c, and migration.c are converted to use the callback.\n\nSigned-off-by: Scott J. Goldman <scottjgo@gmail.com>\n---\n hw/vfio/ap.c                  |  4 ++--\n hw/vfio/ccw.c                 |  2 +-\n hw/vfio/device.c              |  8 ++++++++\n hw/vfio/migration.c           |  5 +++--\n hw/vfio/pci.c                 |  6 ++++--\n include/hw/vfio/vfio-device.h | 11 +++++++++++\n 6 files changed, 29 insertions(+), 7 deletions(-)","diff":"diff --git a/hw/vfio/ap.c b/hw/vfio/ap.c\nindex 5c8f305653..2f2f17e666 100644\n--- a/hw/vfio/ap.c\n+++ b/hw/vfio/ap.c\n@@ -290,10 +290,10 @@ static void vfio_ap_reset(DeviceState *dev)\n     int ret;\n     VFIOAPDevice *vapdev = VFIO_AP_DEVICE(dev);\n \n-    ret = ioctl(vapdev->vdev.fd, VFIO_DEVICE_RESET);\n+    ret = vapdev->vdev.io_ops->device_reset(&vapdev->vdev);\n     if (ret) {\n         error_report(\"%s: failed to reset %s device: %s\", __func__,\n-                     vapdev->vdev.name, strerror(errno));\n+                     vapdev->vdev.name, strerror(-ret));\n     }\n }\n \ndiff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c\nindex ce9c014e6a..330b733b7e 100644\n--- a/hw/vfio/ccw.c\n+++ b/hw/vfio/ccw.c\n@@ -242,7 +242,7 @@ static void vfio_ccw_reset(DeviceState *dev)\n {\n     VFIOCCWDevice *vcdev = VFIO_CCW(dev);\n \n-    ioctl(vcdev->vdev.fd, VFIO_DEVICE_RESET);\n+    vcdev->vdev.io_ops->device_reset(&vcdev->vdev);\n }\n \n static void vfio_ccw_crw_read(VFIOCCWDevice *vcdev)\ndiff --git a/hw/vfio/device.c b/hw/vfio/device.c\nindex 1b703dcbec..cf3953d975 100644\n--- a/hw/vfio/device.c\n+++ b/hw/vfio/device.c\n@@ -657,6 +657,13 @@ static int vfio_device_io_region_write(VFIODevice *vbasedev, uint8_t index,\n     return ret < 0 ? -errno : ret;\n }\n \n+static int vfio_device_io_device_reset(VFIODevice *vbasedev)\n+{\n+    int ret = ioctl(vbasedev->fd, VFIO_DEVICE_RESET);\n+\n+    return ret < 0 ? -errno : ret;\n+}\n+\n static int vfio_device_io_region_map(VFIODevice *vbasedev, VFIORegion *region)\n {\n     return vfio_region_mmap_fd(region);\n@@ -673,6 +680,7 @@ static VFIODeviceIOOps vfio_device_io_ops_ioctl = {\n     .get_region_info = vfio_device_io_get_region_info,\n     .get_irq_info = vfio_device_io_get_irq_info,\n     .set_irqs = vfio_device_io_set_irqs,\n+    .device_reset = vfio_device_io_device_reset,\n     .region_read = vfio_device_io_region_read,\n     .region_write = vfio_device_io_region_write,\n     .region_map = vfio_device_io_region_map,\ndiff --git a/hw/vfio/migration.c b/hw/vfio/migration.c\nindex 83327b6573..b31253ea90 100644\n--- a/hw/vfio/migration.c\n+++ b/hw/vfio/migration.c\n@@ -216,9 +216,10 @@ int vfio_migration_set_state(VFIODevice *vbasedev,\n     return 0;\n \n reset_device:\n-    if (ioctl(vbasedev->fd, VFIO_DEVICE_RESET)) {\n+    ret = vbasedev->io_ops->device_reset(vbasedev);\n+    if (ret) {\n         hw_error(\"%s: Failed resetting device, err: %s\", vbasedev->name,\n-                 strerror(errno));\n+                 strerror(-ret));\n     }\n \n     vfio_migration_set_device_state(vbasedev, VFIO_DEVICE_STATE_RUNNING);\ndiff --git a/hw/vfio/pci.c b/hw/vfio/pci.c\nindex cf817d9ae7..458b3400cc 100644\n--- a/hw/vfio/pci.c\n+++ b/hw/vfio/pci.c\n@@ -3691,7 +3691,8 @@ static void vfio_pci_reset(DeviceState *dev)\n \n     if (vdev->vbasedev.reset_works &&\n         (vdev->has_flr || !vdev->has_pm_reset) &&\n-        !ioctl(vdev->vbasedev.fd, VFIO_DEVICE_RESET)) {\n+        vdev->vbasedev.io_ops && vdev->vbasedev.io_ops->device_reset &&\n+        !vdev->vbasedev.io_ops->device_reset(&vdev->vbasedev)) {\n         trace_vfio_pci_reset_flr(vdev->vbasedev.name);\n         goto post_reset;\n     }\n@@ -3703,7 +3704,8 @@ static void vfio_pci_reset(DeviceState *dev)\n \n     /* If nothing else works and the device supports PM reset, use it */\n     if (vdev->vbasedev.reset_works && vdev->has_pm_reset &&\n-        !ioctl(vdev->vbasedev.fd, VFIO_DEVICE_RESET)) {\n+        vdev->vbasedev.io_ops && vdev->vbasedev.io_ops->device_reset &&\n+        !vdev->vbasedev.io_ops->device_reset(&vdev->vbasedev)) {\n         trace_vfio_pci_reset_pm(vdev->vbasedev.name);\n         goto post_reset;\n     }\ndiff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h\nindex 1a3b42bcaf..0e6bff774e 100644\n--- a/include/hw/vfio/vfio-device.h\n+++ b/include/hw/vfio/vfio-device.h\n@@ -262,6 +262,17 @@ struct VFIODeviceIOOps {\n     int (*region_write)(VFIODevice *vdev, uint8_t nr, off_t off, uint32_t size,\n                         void *data, bool post);\n \n+    /**\n+     * @device_reset\n+     *\n+     * Reset the device.\n+     *\n+     * @vdev: #VFIODevice to reset\n+     *\n+     * Returns 0 on success or -errno.\n+     */\n+    int (*device_reset)(VFIODevice *vdev);\n+\n     /**\n      * @region_map\n      *\n","prefixes":["RFC","06/10"]}