From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f44.google.com (mail-wm1-f44.google.com [209.85.128.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 520354AF69C for ; Sat, 5 Sep 2026 15:21:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.44 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788621682; cv=none; b=aZTwAvLf+8DGIJibNtQOWUolp3zrOHqVlKX2xQssD6pvz8qWYtEHzB8jxEOIlLsgC+s/itKCXAhsxWBYzwgQvsCoH0ZjJniinMTDKtsVbpUzguk0PU90jkPY4bqzRB6u778RMFF0nkZDNEsXWiHoI0UnOyqNpKeKZn2UxN+x6oo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788621682; c=relaxed/simple; bh=8uVPDx/td51aPS2alcJ1aZOS4zzVv+wny8A2GZu+Kcc=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=IjT22D4ZJDTkgHIVaRvOBFixn4JuuNwOEoI/HfpGVhucTTnZjPc+2We0biGI4PIU1AsskBd7PYPh8oSlifP1NwUTdrd5tAKYPUB+dyLsM4mqHiktVnfe6boEikb1ZTV2zsDDTmLjjhovChefy/TnWAYSbhLmF+mPOveZ+U/jYcg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=SkAv5ibx; arc=none smtp.client-ip=209.85.128.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="SkAv5ibx" Received: by mail-wm1-f44.google.com with SMTP id 5b1f17b1804b1-49954b88fffso14931705e9.0 for ; Sat, 05 Sep 2026 08:21:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1788621676; x=1789226476; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=Mje6MYnRuPoV/Y41DYCjMHdpBcGzemV8rMOix0c43HA=; b=SkAv5ibxItcgoih+oVUDj0FFrIVxzD6xxZ3tO5tO74YHrsSsip6Vmf/smEJ4IO004z HQCxhfoNKrXu8ANgYHizNFKiEer3+7/7Sfjf5+X/215ngdkS0Fjqrou/0jfvoBASAfOq j7RFHc4P7UrXaWbEMsZ8V5kidC5fwRyb5nJ3SWv+ZNPnmuy0wHJVIpaNFOf/Jil01ZT6 +pHfVWoE5TcfuC02bFbcL68k+uWJWpB/OQQuxEvPQVBmWwow/DhI93iFyxii7dKlwabI hjVaQMV6QONpChvUSrtxtlUw9lIEGKQGHCqquEPKxFrEMY4b2evcpUsHh3qkLMG7Vsio Aghw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1788621676; x=1789226476; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=Mje6MYnRuPoV/Y41DYCjMHdpBcGzemV8rMOix0c43HA=; b=SfIghIM+K6bLUNnCah5Xldsv+wQyUDBWle3DmsAGnLHRuEy2bzblXfkCshpdl3fB+5 LYshTd8JdEEy4u0gBue77rCwBeVu/FV7fP8y5WX32+XLJwzlap2eMIrtCFqv1UnC+873 FI8WrtUkPq0N2uJ5Al7tyBA+a58Rc8ZRaYTiviylAJ1zUAASuB+KK5QCquDPVdsqRwe+ SoONdqYZDdj8a4YT/WP9sZae20JoUM5fVihNG79SUzrGmw7e8GT6PNNJrMvWYjEGeP6N XtEykXLvReleX169RFU0azU+Rxmv8rxxahbVCVkd2LhJeb2lZzIXL6UESrtQUURUT9hP m/4A== X-Forwarded-Encrypted: i=1; AKwUvBwUJUkmH48j8OQVimJK+WxrV0bMtpnt+5ir4w+F4+CTM6rSrBhS6I6kYMilijsDJxzrmhuT8vGlZv5UPF07dXxD@vger.kernel.org X-Gm-Message-State: AFuF++mSNmGBSZU/kuuRGY7sQzMhFQFbnblbVje2A1UkZn1BrYSdBT13 Y8dxHbz3QL67WhOfXuLSEg1AAxREYbwSrAhDdJHhv0ALL0zU224dzrab X-Gm-Gg: AYBFou3JmoKbBDJJ9UbyPHU43wZbexVmlBVG6uIIGW0/vj4z305Sio/fe837j2Ccw88 kFjoBcos9oFkj6ye5LYOZI4sCTm8CIEuKB3RtbhNGMxvze3B2BsCaPO5NPkxhfB/wb6WqB7nUYw LA3dvuKaWwaZx2x6blSWXHvaHkXG7KrpRdZul09rmWzbiEr/H4FkgHWph9SuIcLABCLXSD1tsbP 4739EHVnA6/dV+afoOLZLnVjbigXyz57egGVLm4c8ktJh0Gq0QPHKiVWT5fe/w0xl6JrBa4bGmK H94kYzjz839/hP/Qx/Zw7IrxS7ACKnIuWdU3iE3UvexteLDJSmtMObedtSAS6tf+60uj9sMmnE0 4AP7AiTR45z3aXLXjAZp+bf7tcNmJEREBNYR7XTWN9bvaxs5y81H0xjH4Z3VkipeGOVFZBg69sM 8JKyEh61BgeSY9GrT8OISv0iL8XG/i/nAFOvSrgZUDtud2+aAmnOOS9/fw76zGR84abp5mwWNtG u769JpckIEyRDE2ebKWGfSEo82v75uTCFuIJY5CctKWfYF5GAfiBfQrccYrwqRHFUI6pRX0Baw9 5dWQSXrXq8H9SXJ2nm3GDBDPPmW8eCE3Z2Io1aV1uJ3xN+kkhQXjvtvJiFDL+EIvt1k= X-Received: by 2002:a05:600c:5493:b0:49b:8f18:714a with SMTP id 5b1f17b1804b1-49cf824a6c5mr137927365e9.12.1788621675623; Sat, 05 Sep 2026 08:21:15 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a02-3100-a4eb-3001-c06d-af27-9fa2-ea53.310.pool.telefonica.de. [2a02:3100:a4eb:3001:c06d:af27:9fa2:ea53]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-49cf75ce49esm267779515e9.1.2026.09.05.08.21.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 05 Sep 2026 08:21:14 -0700 (PDT) From: Karl Mehltretter To: "Michael S . Tsirkin" , Jason Wang , Gerd Hoffmann Cc: Karl Mehltretter , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Dmitry Torokhov , Rusty Russell , Pawel Moll , Cornelia Huck , Halil Pasic , Eric Farman , Richard Weinberger , Anton Ivanov , Johannes Berg , Hans de Goede , =?UTF-8?q?Ilpo=20J=C3=A4rvinen?= , Vadim Pasternak , Bjorn Andersson , Mathieu Poirier , 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: [PATCH v2 0/3] virtio: synchronize callbacks during device reset Date: Sat, 5 Sep 2026 17:20:56 +0200 Message-Id: <20260905152059.89560-1-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) Precedence: bulk X-Mailing-List: linux-remoteproc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. 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)