From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C76193515E7; Sat, 17 Oct 2026 16:08:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792253301; cv=none; b=PehXJ8ZM3cMUwEXEO0k5UDFoPDADpo1xH7D//gFIKbFzV9PrbeqQpV2f2w11IW5srS/7NC+vf19vHEazntjMbtSD+EVux0ziUfSVr/r1Y6JZoxgbMJYJx/NOgAmXiDQLtcdPFnIm7Oka2izOQpo5/yF+LNcfJPYsf/ty38WspMA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1792253301; c=relaxed/simple; bh=nwrx/UvnNGYeoSrCQ8Nmwk1sul0ui966E2tvd1uy/fc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kC11ygstqxYrNfrn63clE2kklbvD1f6CLVWhxv2Jt1rECHJoZS7X84C7z7+xQah1kpPeNSj3zVe9YIY3+XDFoxSCUBwWwG6WojPo+1W+m8nMcFckwqsiF/qmaAhnwiHclcALmMZG+6vkMJ+aMHSWcwqkz9AQ/Jw76N/iwf+ksj4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=VTitccIt; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="VTitccIt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E6D641F000C4; Sat, 17 Oct 2026 16:08:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1792253299; bh=U0eHCxBTKgXCfDlyFI2PHoaniTocKIa683plJAg7qXo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=VTitccItGwGznfDAQliX5CXzzETbeI6SPnwXSOkY4kzfTSSRCqUAjAyKNVPnCM+o9 Z9NDDgeLXCesf7QwWc8QFYn1xOjfsvEZuNlbbOIp+KzSj1GK+0/pWmss+wg3j3P3zC HogSsubyfdSBZtFb/9ZmRdHocX90wCOjgNL07pzM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Eric Auger , Hongyu Ning , Eric Auger , Jason Wang , "Michael S. Tsirkin" , Sasha Levin Subject: [PATCH 6.12 074/869] virtio: break and reset virtio devices on device_shutdown() Date: Sat, 17 Oct 2026 17:48:35 +0200 Message-ID: <20261017160038.924387455@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261017160036.979869304@linuxfoundation.org> References: <20261017160036.979869304@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael S. Tsirkin [ Upstream commit 8bd2fa086a04886798b505f28db4002525895203 ] Hongyu reported a hang on kexec in a VM. QEMU reported invalid memory accesses during the hang. Invalid read at addr 0x102877002, size 2, region '(null)', reason: rejected Invalid write at addr 0x102877A44, size 2, region '(null)', reason: rejected ... It was traced down to virtio-console. Kexec works fine if virtio-console is not in use. The issue is that virtio-console continues to write to the MMIO even after underlying virtio-pci device is reset. Additionally, Eric noticed that IOMMUs are reset before devices, if devices are not reset on shutdown they continue to poke at guest memory and get errors from the IOMMU. Some devices get wedged then. The problem can be solved by breaking all virtio devices on virtio bus shutdown, then resetting them. Reported-by: Eric Auger Reported-by: Hongyu Ning Message-ID: Tested-by: Eric Auger Acked-by: Jason Wang Signed-off-by: Michael S. Tsirkin Signed-off-by: Sasha Levin --- drivers/virtio/virtio.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c index 1b193d08a6ba8..148ce610ccb83 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -377,6 +377,34 @@ static void virtio_dev_remove(struct device *_d) of_node_put(dev->dev.of_node); } +static void virtio_dev_shutdown(struct device *_d) +{ + struct virtio_device *dev = dev_to_virtio(_d); + struct virtio_driver *drv = drv_to_virtio(dev->dev.driver); + + /* + * Stop accesses to or from the device. + * We only need to do it if there's a driver - no accesses otherwise. + */ + if (!drv) + 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); +} + static const struct bus_type virtio_bus = { .name = "virtio", .match = virtio_dev_match, @@ -384,6 +412,7 @@ static const struct bus_type virtio_bus = { .uevent = virtio_uevent, .probe = virtio_dev_probe, .remove = virtio_dev_remove, + .shutdown = virtio_dev_shutdown, }; int __register_virtio_driver(struct virtio_driver *driver, struct module *owner) -- 2.53.0