From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (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 ECC552D9780 for ; Wed, 24 Jun 2026 14:08:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.41 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782310133; cv=none; b=WXTnujNx5Wf5F3MEop9zt7HmxtqK8IC41zmN/Ni2t5/Maqc4JUdjBrprkICV/vGe0isgd0ESecX8gmYCmQlh+1hmb+xxVyb4TA9a+QFlIV7xYdQVtBM62Xq1w3io2X+URV7McLc0EvosqWNp4AzxKFSAVYIne+VIgkHSG7/rkzw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782310133; c=relaxed/simple; bh=H3AofhNEHYpKH3qKmHnFcIZHklOCB+JEV5BWAwMmlvk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aU41zchm4aRROKT2SGdd2YlQyBdiUvqYU2uEny03GjAPO3tslDvUfug/XSnvHsnipGcnxe5geqPHcDdOqALW+hWJ/RVKZwSCAmCtVQeUvh4PfgPIbtknzgvixem4CXMwcijFvyLgTt5yxJ+b0E3gKsuM2o+BpBfC6Bx4hUhqur4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=openvz.org; spf=pass smtp.mailfrom=openvz.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b=eiri2IJ4; arc=none smtp.client-ip=209.85.221.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=openvz.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=openvz.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=openvz.org header.i=@openvz.org header.b="eiri2IJ4" Received: by mail-wr1-f41.google.com with SMTP id ffacd0b85a97d-4627adcf4d6so870316f8f.3 for ; Wed, 24 Jun 2026 07:08:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=openvz.org; s=google; t=1782310130; x=1782914930; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=48Au7et5Z4YbTFT58xfMD2qmVHKMDdo11xhFKNzYy74=; b=eiri2IJ42KAKupneII4I/IrRMHJPtpflvGgIVJn6R59JRjJxMJSmyHfj96p7nmGwS1 zHR6hGY8a7Vb62/64bONXTAGKt/W1g62QsCli0+uzk6srCa+HWMxPGsb4VwliURLIgJL XC8WZKoGxn3jNBEMX7PagtPmQk8bxN6/1KhDoHpD+f6RWr3c1pDJbhTMS2lEcrFqboO/ ygERVmxOc5QtY5n7zysXk5eV/xbVsYkjaKJF5aDR8OzSXacLgieyJREQs6Of5H+uuMeZ xi921IxzKcikGEAvmMwJp40wNtEID8K2nOGzL0yrAnmcIwsk2Z5R8/KB9Z/PdCf99tBt V0Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782310130; x=1782914930; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=48Au7et5Z4YbTFT58xfMD2qmVHKMDdo11xhFKNzYy74=; b=dxtm8PEeSL3jWQtm6rQ4SJ09uC/MDAtV3UtjdF+DzeJqLlWqfy4fhp0tuhseuO9/XS Qe1rULyJvBuEQ5Mu0A7MX4wwcr96gpsdv3JKfGD8XUnphbO/M5b5hckSsmmWjCdtMM7V /I9x7SxFL1Fik1qPO/M0bOMZjzgr3r1MdmM/m+CGeptpoT5RhaGtCg1o/JtbMxdpeCeC DqbsmhIRee7X8KGNiPiXUyUcRomKqRhLLdD0lmJ/WKMi4rsfyGq/i0+KLWMRdhNM2Tp2 co+d0ccdCwowEowD4Hdi5vn5noND5azJIbH9cBq626Xe3OzYMTHxSaQaUxDYL+ENaTq2 ki0A== X-Forwarded-Encrypted: i=1; AFNElJ8+A6f3yTy3DJN1ThVqvlWe2UxHaACHmdSddaZDKgkXzcJx69bV2egyQZfkAzl6e3sKnBjHQMI17O267Pw=@vger.kernel.org X-Gm-Message-State: AOJu0YzpBBGbtZm1j+5l8GdswrPmnRDNElsyvAT1r9O7M2ILBJOwKr3w R/3jeQMAPDbaN7bpIxi9ZrmVhrX0YZfA/RQPKjrWi4dZYFZzKoSI5B3j+QVq9Cfmm0qi/3q0sLv AvDY4s6z4ng== X-Gm-Gg: AfdE7cl9mMPdedxjUTxgIzEN27/f/AmmQaflluW9jJ3MsHj48hxoqWVjPPdgTvGVud6 n2mlTsXwPJe5eDLTYh2rwcrHMyOMPhUaPqVDwJUk5iA+53lRC+ksRtAjhUI/VafpnkqW6bQ6S45 UmOTZmkAJaG01CBQuQhxhQexh7KuQA1IbYGmkYQwlE9QcCqmZTzV4rrJkBtAV7sXM/L040xkfdO QoVHoFiiF3rstpaO7okPgPiQ3dh1gbMLOah5iXKRN9ysm7UGuDinYMAu7pvL1t1Tjnti9nPcgJX iIQzy4Z/t1RcqcJram06SO/1dOvcLu2XH63FHRi40mwiYsh5qntZbuyWwtqrmybjaxTfCv0GuDP yXaK7827d7d7nEY9acz0i1pAtPnlItks00b8xHAQqZOhK6QTE+pRqtFwslg+lnSQK9KvMqw== X-Received: by 2002:a05:600d:8495:10b0:490:c032:ae92 with SMTP id 5b1f17b1804b1-4926087f7edmr37928655e9.33.1782310130503; Wed, 24 Jun 2026 07:08:50 -0700 (PDT) Received: from athena.sw.ru ([2a06:5b06:b600:300:306c:c2d:85d5:28d5]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4923fd1fa34sm519680275e9.5.2026.06.24.07.08.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2026 07:08:50 -0700 (PDT) From: "Denis V. Lunev" To: mst@redhat.com, david@kernel.org Cc: virtualization@lists.linux.dev, linux-kernel@vger.kernel.org, "Denis V. Lunev" Subject: [PATCH v2 1/4] virtio: add virtio_device_shutdown() helper Date: Wed, 24 Jun 2026 16:08:43 +0200 Message-ID: <20260624140846.2616797-2-den@openvz.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260624140846.2616797-1-den@openvz.org> References: <20260624140846.2616797-1-den@openvz.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 --- 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 299fa83be1d5..75bb4ffe3b87 100644 --- a/drivers/virtio/virtio.c +++ b/drivers/virtio/virtio.c @@ -401,6 +401,32 @@ static const struct cpumask *virtio_irq_get_affinity(struct device *_d, return dev->config->get_vq_affinity(dev, irq_vec); } +/** + * 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); @@ -419,20 +445,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 int virtio_dev_num_vf(struct device *dev) diff --git a/include/linux/virtio.h b/include/linux/virtio.h index bf089e51970e..66184828fdd0 100644 --- a/include/linux/virtio.h +++ b/include/linux/virtio.h @@ -213,6 +213,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); int virtio_device_reset_prepare(struct virtio_device *dev); int virtio_device_reset_done(struct virtio_device *dev); -- 2.53.0