Linux block layer
 help / color / mirror / Atom feed
From: Xixin Liu <liuxixin@kylinos.cn>
To: linux-block@vger.kernel.org
Cc: virtualization@lists.linux.dev, mst@redhat.com,
	jasowang@redhat.com, xuanzhuo@linux.alibaba.com,
	eperezma@redhat.com, pbonzini@redhat.com, stefanha@redhat.com,
	axboe@kernel.dk, linux-kernel@vger.kernel.org,
	liuxixin@kylinos.cn
Subject: [PATCH v3 1/2] virtio-pci: add error_detected and slot_reset for AER
Date: Thu, 6 Aug 2026 09:15:00 +0800	[thread overview]
Message-ID: <a1b2c3d4e5f0.v3.1785920716.git.liuxixin@kylinos.cn> (raw)
In-Reply-To: <cover.virtio-blk-ers-v3.1785920716.git.liuxixin@kylinos.cn>

virtio-pci only registered reset_prepare/reset_done.  Without
.error_detected the recovery core votes NO_AER_DRIVER on the first
broadcast, and report_perm_failure_detected skips the driver callback
whenever overall status is not RECOVERED.  That skip covers
NO_AER_DRIVER even when subordinate reset succeeded.  Virtio therefore
misses the normal ERS path and pci_channel_io_perm_failure.

AER's aer_root_reset() uses pci_bus_error_reset(), which does a bus or
slot reset without pci_dev_save_and_disable().  The existing
.reset_prepare and .reset_done therefore do not run on that path.
Those hooks still serve FLR and pci_reset_function.

Register error_detected and slot_reset:
- frozen / unknown: virtio_device_reset_prepare() then NEED_RESET
- after a successful PCI reset: restore config, virtio_device_reset_done()
- perm_failure: virtio_break_device() and return DISCONNECT

Assisted-by: DeepSeek:deepseek-v3
Signed-off-by: Xixin Liu <liuxixin@kylinos.cn>
---
 drivers/virtio/virtio_pci_common.c | 53 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c
index 164f480b18a6..c0ffeed00004 100644
--- a/drivers/virtio/virtio_pci_common.c
+++ b/drivers/virtio/virtio_pci_common.c
@@ -828,7 +828,60 @@ static void virtio_pci_reset_done(struct pci_dev *pci_dev)
 		dev_warn(&pci_dev->dev, "Reset done failure: %d", ret);
 }
 
+static pci_ers_result_t virtio_pci_error_detected(struct pci_dev *pci_dev,
+						  pci_channel_state_t state)
+{
+	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
+
+	/*
+	 * Quiesce on frozen/unknown before AER bus reset.  That path does
+	 * not call .reset_prepare.  On permanent failure only break
+	 * virtqueues.
+	 */
+	switch (state) {
+	case pci_channel_io_normal:
+		return PCI_ERS_RESULT_CAN_RECOVER;
+	case pci_channel_io_perm_failure:
+		dev_warn(&pci_dev->dev,
+			 "permanent failure, disconnecting device\n");
+		virtio_break_device(&vp_dev->vdev);
+		return PCI_ERS_RESULT_DISCONNECT;
+	case pci_channel_io_frozen:
+	default:
+		pci_info(pci_dev, "channel state %u, quiesce device\n", state);
+		if (virtio_device_reset_prepare(&vp_dev->vdev))
+			dev_warn(&pci_dev->dev, "reset prepare failed\n");
+		return PCI_ERS_RESULT_NEED_RESET;
+	}
+}
+
+static pci_ers_result_t virtio_pci_slot_reset(struct pci_dev *pci_dev)
+{
+	struct virtio_pci_device *vp_dev = pci_get_drvdata(pci_dev);
+	int ret;
+
+	if (pci_enable_device(pci_dev)) {
+		dev_err(&pci_dev->dev,
+			"Cannot re-enable PCI device after reset\n");
+		return PCI_ERS_RESULT_DISCONNECT;
+	}
+
+	pci_set_master(pci_dev);
+	pci_restore_state(pci_dev);
+
+	ret = virtio_device_reset_done(&vp_dev->vdev);
+	if (ret && ret != -EOPNOTSUPP) {
+		dev_warn(&pci_dev->dev, "slot reset restore failed: %d\n",
+			 ret);
+		return PCI_ERS_RESULT_DISCONNECT;
+	}
+
+	return PCI_ERS_RESULT_RECOVERED;
+}
+
 static const struct pci_error_handlers virtio_pci_err_handler = {
+	.error_detected = virtio_pci_error_detected,
+	.slot_reset     = virtio_pci_slot_reset,
 	.reset_prepare  = virtio_pci_reset_prepare,
 	.reset_done     = virtio_pci_reset_done,
 };
-- 
2.43.0


  reply	other threads:[~2026-08-07  6:58 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-15  2:00 [PATCH v1 0/2] virtio: PCI ERS permanent failure teardown for virtio-blk Xixin Liu
2026-06-10  6:20 ` [PATCH v1 1/2] virtio-pci: add error_detected for PCI AER recovery Xixin Liu
2026-06-12 10:00 ` [PATCH v1 2/2] virtio-blk: mark disk dead on ERS permanent failure Xixin Liu
2026-07-30 23:13   ` Michael S. Tsirkin
2026-07-31  3:29     ` Xixin Liu
2026-06-15 14:52 ` [PATCH v1 0/2] virtio: PCI ERS permanent failure teardown for virtio-blk Stefan Hajnoczi
2026-07-31  3:20 ` [PATCH v2 " Xixin Liu
2026-07-31  3:17   ` [PATCH v2 1/2] virtio-pci: add error_detected for PCI AER recovery Xixin Liu
2026-08-02 21:10     ` Michael S. Tsirkin
2026-08-07  6:15       ` Xixin Liu
2026-07-31  3:19   ` [PATCH v2 2/2] virtio-blk: mark disk dead on ERS permanent failure Xixin Liu
2026-08-02 20:59     ` Michael S. Tsirkin
2026-08-07  6:16       ` Xixin Liu
2026-08-06  1:20   ` [PATCH v3 0/2] virtio: PCI AER error_detected and virtio-blk shutdown Xixin Liu
2026-08-06  1:15     ` Xixin Liu [this message]
2026-08-06  1:20     ` [PATCH v3 2/2] virtio-blk: add shutdown and fail queue_rq after VQ teardown Xixin Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a1b2c3d4e5f0.v3.1785920716.git.liuxixin@kylinos.cn \
    --to=liuxixin@kylinos.cn \
    --cc=axboe@kernel.dk \
    --cc=eperezma@redhat.com \
    --cc=jasowang@redhat.com \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=virtualization@lists.linux.dev \
    --cc=xuanzhuo@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox