From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796379400; b=1PWpbMpdx0Yq1rjUVemPFWcDVdpfK9tS/9mGRC+vu4zKDU6PVkA+Uip7hB97zVYZVxGr ssz2Pz6xvV+9zfoBzfMlXIF7cMsT0JU4l43GGOBe4QlDK3nt+y9U6tMJPLIZvZRv/0JBh jAwea2a86UaimwFgnW/7KWnqOcW4owFJJDLD2bkk/sc9gGkmDY0vJDGYpXjA6KPr3AErI d6H+tila2/3ugL08IfSxwpMpdOAsmq2DIihnrvMTmbxupIx84PAFr2wPfO1EBQ+JRwk+5 MCdm7PxYRtVJ6HXgPumUr498iDFNQR8v2OxTQ2eHqeItouZOtuBxd4YZ88uy7uiT9nA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796379400; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=gwW00sJVPGoinHdFQRwjc3Gc0DWRFxv96O9+nRAYKrQ=; b=kIsMbu68VQrrQ0vwRl4ZVXi4OKEPku3ILWdNCYQuq0HuSdULoHLCamXsTAVn68DIeiwP b8ss/Af+Q+n4mfxrJuH5d81aupHKVaqS02kmNCiYZ+MCUllvyYncLD+2qGUl0bRKLnU/y 5ufRLcOC28M7uIJ1+D6V0S+1i73eYbKjdJFrDMyMoEJTHj0naTTem98JoB348vTRUw7TP +JuOk5+4DAjCEEAltfiVRpaC7AdifBtb1QooH8xtlkKYMI3lpTMTD1lkNmyI50WjnBmH9 yN7xcqyv+kfJnT/nX5lhn2H6ZlSk2RZyS/19g964YcYLWFJA3mcDMeFRr7elghuzVmw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=w0j3ciwx; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 70ECC606A32C; Fri, 4 Dec 2026 10:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=w0j3ciwx Received: by smtp.kernel.org (Postfix) with ESMTPSA id AFF8E1F000CE; Fri, 4 Dec 2026 10:16:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796379400; bh=gwW00sJVPGoinHdFQRwjc3Gc0DWRFxv96O9+nRAYKrQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=w0j3ciwxDWjhz6p8cR8N+exUpI6Wqk1SJCrMu/aEwtzQf4kDiWrWU/VO+spmtLiD8 zGJEmBUmeUKtcYBwHiJu+04ZOQTPx37A6jkXNAy9MY/zduIbTEQ24aLgVewhqdqk6M zviSHNnUcV0mbMYbHgsAMUVACo7heH0o0stpFHW8= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "Denis V. Lunev" , "David Hildenbrand (Arm)" , "Michael S. Tsirkin" , Dickson Wu , Sasha Levin Subject: [PATCH 6.12 003/555] virtio: add virtio_device_shutdown() helper Date: Fri, 4 Dec 2026 19:00:46 +0900 Message-ID: <20261204100604.096938820@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100603.988357525@linuxfoundation.org> References: <20261204100603.988357525@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Denis V. Lunev commit 0d8aebe089b4ba887e792884cf041ce9f1040ff4 upstream. The generic virtio bus .shutdown handler, virtio_dev_shutdown(), breaks and resets a device once it has established that the driver has no .shutdown of its own. A driver that does implement .shutdown, to quiesce its own activity first, still needs the same break and reset afterwards and would otherwise have to open code it. Factor the break + synchronize_cbs + reset sequence out of virtio_dev_shutdown() into an exported virtio_device_shutdown() helper so such drivers can reuse it instead of duplicating the core logic. No functional change. Signed-off-by: Denis V. Lunev Reviewed-by: David Hildenbrand (Arm) Signed-off-by: Michael S. Tsirkin Message-ID: <20260624140846.2616797-2-den@openvz.org> [ adapted to 6.12: no virtio_irq_get_affinity(), put the helper above virtio_dev_shutdown() ] Signed-off-by: Dickson Wu Signed-off-by: Sasha Levin --- drivers/virtio/virtio.c | 41 +++++++++++++++++++++++++++-------------- include/linux/virtio.h | 1 + 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 8241024f0890b..f70ae3a672f72 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -379,6 +379,32 @@ static void virtio_dev_remove(struct device *_d) of_node_put(dev->dev.of_node); } +/** + * virtio_device_shutdown - break and reset a device on shutdown + * @dev: the device + * + * Drivers with their own .shutdown method should quiesce their activity and + * then call this to stop the device the way the generic shutdown path does. + */ +void virtio_device_shutdown(struct virtio_device *dev) +{ + /* + * Some devices get wedged if you kick them after they are + * reset. Mark all vqs as broken to make sure we don't. + */ + virtio_break_device(dev); + /* + * Guarantee that any callback will see vq->broken as true. + */ + virtio_synchronize_cbs(dev); + /* + * As IOMMUs are reset on shutdown, this will block device access to memory. + * Some devices get wedged if this happens, so reset to make sure it does not. + */ + dev->config->reset(dev); +} +EXPORT_SYMBOL_GPL(virtio_device_shutdown); + static void virtio_dev_shutdown(struct device *_d) { struct virtio_device *dev = dev_to_virtio(_d); @@ -397,20 +423,7 @@ static void virtio_dev_shutdown(struct device *_d) return; } - /* - * Some devices get wedged if you kick them after they are - * reset. Mark all vqs as broken to make sure we don't. - */ - virtio_break_device(dev); - /* - * Guarantee that any callback will see vq->broken as true. - */ - virtio_synchronize_cbs(dev); - /* - * As IOMMUs are reset on shutdown, this will block device access to memory. - * Some devices get wedged if this happens, so reset to make sure it does not. - */ - dev->config->reset(dev); + virtio_device_shutdown(dev); } static const struct bus_type virtio_bus = { diff --git a/include/linux/virtio.h b/include/linux/virtio.h index 2759e2c24d6ea..2d8820c0832af 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -180,6 +180,7 @@ int virtio_device_freeze(struct virtio_device *dev); int virtio_device_restore(struct virtio_device *dev); #endif void virtio_reset_device(struct virtio_device *dev); +void virtio_device_shutdown(struct virtio_device *dev); size_t virtio_max_dma_size(const struct virtio_device *vdev); -- 2.53.0