From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 082D527BF79; Tue, 27 May 2025 17:36:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748367383; cv=none; b=EvvpBbotyCkhE9EbjhWC81Fp/6dSZxGbBfofbm/eQeAVPRxRisx8fT37gZFBmqIXSYZMiiRKU0GVlXeJ53CQwLec2ZaVD5lzqgEarMFlXpyp5vQ6j5fPOxkDmOgnGJpObHLGpAdhJr1YTbU3dYiEmKrKgX4BWtRm7lXbGkDNbiA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748367383; c=relaxed/simple; bh=QxWtYy3qkkEfo/CiSKs1HvVCNKrmDsVsOe44wwA1tzg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=O91qHiXqKCBatu+9MUNW1E4oMsoMp+5tyizfdnvvnYg73+2dYVCTZPG7HSsT/b1ejyDjlGXUnx7j+4H+Gbf6s/WqGetK3keJ9Ewh60w9ZHukCd9b5nSxbEnDoZ3n0oJl4t4hN8FDtzkE9TSr0oxOvycy3pOJMiidWhTkE6ioswQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=t2lKWHKP; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="t2lKWHKP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 179CBC4CEE9; Tue, 27 May 2025 17:36:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1748367382; bh=QxWtYy3qkkEfo/CiSKs1HvVCNKrmDsVsOe44wwA1tzg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t2lKWHKPIuzBv08UzUYfkEvDlfAO3jdA0Ic60RFrfUa7qAAU54Sj2jR+QShTAqnLB +N9U/oXR4ofzehT/zr3NT4cMJYuLhocloGfdbsj+NjBbvhC8yiSS/+u0pA1qg5ZIJO 8g7O3Ez5k1g8fvzUL/jBFkRfkKIuHl7PmObq6Oto= 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.14 369/783] virtio: break and reset virtio devices on device_shutdown() Date: Tue, 27 May 2025 18:22:46 +0200 Message-ID: <20250527162528.107668043@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250527162513.035720581@linuxfoundation.org> References: <20250527162513.035720581@linuxfoundation.org> User-Agent: quilt/0.68 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.14-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 ba37665188b51..150753c3b5782 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -395,6 +395,34 @@ static const struct cpumask *virtio_irq_get_affinity(struct device *_d, return dev->config->get_vq_affinity(dev, irq_vec); } +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, @@ -403,6 +431,7 @@ static const struct bus_type virtio_bus = { .probe = virtio_dev_probe, .remove = virtio_dev_remove, .irq_get_affinity = virtio_irq_get_affinity, + .shutdown = virtio_dev_shutdown, }; int __register_virtio_driver(struct virtio_driver *driver, struct module *owner) -- 2.39.5