From: "Michael S. Tsirkin" <mst@redhat.com>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: "Jason Wang" <jasowangio@gmail.com>,
"Gerd Hoffmann" <kraxel@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Dmitry Torokhov" <dmitry.torokhov@gmail.com>,
"Rusty Russell" <rusty@rustcorp.com.au>,
"Pawel Moll" <pawel.moll@arm.com>,
"Cornelia Huck" <cohuck@redhat.com>,
"Halil Pasic" <pasic@linux.ibm.com>,
"Eric Farman" <farman@linux.ibm.com>,
"Richard Weinberger" <richard@nod.at>,
"Anton Ivanov" <anton.ivanov@cambridgegreys.com>,
"Johannes Berg" <johannes@sipsolutions.net>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Vadim Pasternak" <vadimp@nvidia.com>,
"Bjorn Andersson" <andersson@kernel.org>,
"Mathieu Poirier" <mathieu.poirier@linaro.org>,
virtualization@lists.linux.dev, linux-input@vger.kernel.org,
linux-s390@vger.kernel.org, kvm@vger.kernel.org,
linux-um@lists.infradead.org,
platform-driver-x86@vger.kernel.org,
linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 0/3] virtio: synchronize callbacks during device reset
Date: Sun, 6 Sep 2026 02:53:05 -0400 [thread overview]
Message-ID: <20260906025249-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20260905152059.89560-1-kmehltretter@gmail.com>
On Sat, Sep 05, 2026 at 05:20:56PM +0200, Karl Mehltretter wrote:
> A virtqueue callback can outlive virtio_reset_device() and race with a
> driver freeing the state it uses. The reset helper documents that no
> callbacks remain in progress, but that depends on the transport:
> virtio-pci waits in vp_reset(), while virtio-mmio does not.
>
> virtio_input has a related ordering problem: it unregisters the input
> device before resetting the virtio device, while an event callback may
> still be using the input device.
>
> Patch 1 moves the callback wait into the core, using the existing
> virtio_synchronize_cbs() operation. Patch 2 fixes the virtio_input teardown
> order. Patch 3 adds the missing synchronize_cbs hooks for UML, TmFIFO,
> remoteproc and virtio-vdpa. Remoteproc uses one SRCU domain per processor.
>
> The new hooks wait for callbacks already running. UML, TmFIFO and
> remoteproc still allow new callbacks after reset; fixing that is separate
> work. The event-virtqueue DMA mapping issue is also separate.
>
> Changes in v2:
> - Patch 1: move the wait into the core instead of fixing only MMIO, as
> Michael suggested. Remove the duplicate PCI wait, preserve its shutdown
> wait, and fix CCW callback locking. Drop the MMIO polling: reset polling
> for v3 and newer is already in fa8833c085b6 ("virtio-mmio: add support
> for transport version 3").
> - Patch 2: keep draining completed events when ready becomes false,
> instead of breaking out, so teardown does not truncate an input packet.
> - Patch 3 is new, at Michael's request.
You didn't send patch 3.
> I reran the 120-cycle unbind/rebind test in an arm64 KASAN guest with four
> vCPUs and a 5 ms busy delay per event. With patch 2 alone over virtio-mmio,
> reset returned with the callback still running in all 84 overlapping
> cycles. With the series, it waited in all 103. Over PCI with per-queue
> MSI-X, it waited in all 66, including runs with threadirqs. No KASAN or
> lockdep reports. These runs predate the per-rproc change, which leaves
> the tested MMIO and PCI paths unchanged. They confirmed the missing wait,
> but did not reproduce a use-after-free: with evdev attached,
> input_unregister_device() waits for an RCU grace period that the IRQ
> callback blocks.
>
> That version also passed QEMU input, rebind and shutdown checks on arm64
> MMIO and x86-64 PCI, including arm64 RT, KASAN and KCSAN builds, and x86
> UP/Tiny SRCU. A legacy INTx NIC was present for an additional x86
> shutdown check. The changed objects built with W=1 without warnings on
> arm64, x86-64, s390 and SMP UML. The per-rproc version built with W=1
> on arm64 KASAN and x86 Tiny SRCU, and passed six remoteproc callback and
> lifetime KUnit tests on each, using mock remoteproc devices.
>
> Link: https://lore.kernel.org/r/20260818040433.66986-1-kmehltretter@gmail.com
>
> Karl Mehltretter (3):
> virtio: synchronize callbacks during device reset
> virtio_input: stop callbacks before unregistering input device
> virtio: implement synchronize_cbs for remaining transports
>
> arch/um/drivers/virtio_uml.c | 10 ++++++++++
> drivers/platform/mellanox/mlxbf-tmfifo.c | 14 ++++++++++++++
> drivers/remoteproc/remoteproc_core.c | 10 ++++++++++
> drivers/remoteproc/remoteproc_virtio.c | 20 +++++++++++++++++---
> drivers/s390/virtio/virtio_ccw.c | 6 +-----
> drivers/virtio/virtio.c | 2 ++
> drivers/virtio/virtio_input.c | 8 ++++++--
> drivers/virtio/virtio_pci_legacy.c | 2 --
> drivers/virtio/virtio_pci_modern.c | 3 ---
> drivers/virtio/virtio_vdpa.c | 21 ++++++++++++++++++++-
> include/linux/remoteproc.h | 3 +++
> include/linux/virtio_config.h | 6 +++---
> 12 files changed, 86 insertions(+), 19 deletions(-)
>
> base-commit: a500db7819c50db59e55f1b4fa1c3baa5a2616f3
> --
> 2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2026-09-06 6:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-05 15:20 [PATCH v2 0/3] virtio: synchronize callbacks during device reset Karl Mehltretter
2026-09-05 15:20 ` [PATCH v2 1/3] " Karl Mehltretter
2026-09-05 15:35 ` sashiko-bot
2026-09-06 6:49 ` Michael S. Tsirkin
2026-09-07 21:36 ` Michael S. Tsirkin
2026-09-05 15:20 ` [PATCH v2 2/3] virtio_input: stop callbacks before unregistering input device Karl Mehltretter
2026-09-05 15:33 ` sashiko-bot
2026-09-07 21:19 ` Michael S. Tsirkin
2026-09-06 6:51 ` Michael S. Tsirkin
2026-09-07 21:46 ` Michael S. Tsirkin
2026-09-07 22:15 ` Karl Mehltretter
2026-09-07 22:22 ` Michael S. Tsirkin
2026-09-07 22:32 ` Karl Mehltretter
2026-09-05 15:20 ` [PATCH v2 3/3] virtio: implement synchronize_cbs for remaining transports Karl Mehltretter
2026-09-05 15:35 ` sashiko-bot
2026-09-06 18:59 ` Michael S. Tsirkin
2026-09-06 6:43 ` [PATCH v2 0/3] virtio: synchronize callbacks during device reset Michael S. Tsirkin
2026-09-06 6:53 ` Michael S. Tsirkin [this message]
2026-09-06 16:32 ` Karl Mehltretter
2026-09-06 18:56 ` Michael S. Tsirkin
2026-09-07 13:13 ` Michael S. Tsirkin
2026-09-07 21:23 ` Karl Mehltretter
2026-09-07 21:41 ` Michael S. Tsirkin
2026-09-11 12:39 ` Michael S. Tsirkin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260906025249-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=andersson@kernel.org \
--cc=anton.ivanov@cambridgegreys.com \
--cc=cohuck@redhat.com \
--cc=dmitry.torokhov@gmail.com \
--cc=eperezma@redhat.com \
--cc=farman@linux.ibm.com \
--cc=hansg@kernel.org \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=jasowangio@gmail.com \
--cc=johannes@sipsolutions.net \
--cc=kmehltretter@gmail.com \
--cc=kraxel@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
--cc=linux-um@lists.infradead.org \
--cc=mathieu.poirier@linaro.org \
--cc=pasic@linux.ibm.com \
--cc=pawel.moll@arm.com \
--cc=platform-driver-x86@vger.kernel.org \
--cc=richard@nod.at \
--cc=rusty@rustcorp.com.au \
--cc=vadimp@nvidia.com \
--cc=virtualization@lists.linux.dev \
--cc=xuanzhuo@linux.alibaba.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.