All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Peng Fan" <peng.fan@linux.dev>
Cc: virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH] virtio: reset the device when probe fails
Date: Sat, 05 Dec 2026 10:41:27 +0000	[thread overview]
Message-ID: <sashiko-outbox-251401@kernel.org> (raw)
In-Reply-To: <20261205-virtio-reset-v1-1-c2203390b005@nxp.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] virtio: probe error reset clears ACKNOWLEDGE and leaves
  FAILED set on rebind
--

commit d8797162668785b8b6784f10a498e39eb14b7ecf
Author: Peng Fan <peng.fan@nxp.com>

virtio: reset the device when probe fails

This commit calls virtio_reset_device() in the error path of
virtio_dev_probe() before setting VIRTIO_CONFIG_S_FAILED so that
virtqueues enabled before a probe failure are cleared for a later rebind.

> diff --git a/drivers/virtio/virtio.c b/drivers/virtio/virtio.c
> index c8be1a3f479d6..bf3ae72104567 100644
> --- a/drivers/virtio/virtio.c
> +++ b/drivers/virtio/virtio.c
> @@ -362,6 +362,12 @@ static int virtio_dev_probe(struct device *_d)
>  	return 0;
>  
>  err:
> +	/*
> +	 * Reset the device so a failed probe does not leave enabled queues
> +	 * behind (virtio-pci queue_enable can only be cleared by reset), which
> +	 * would otherwise make a later rebind fail in setup_vq().
> +	 */
> +	virtio_reset_device(dev);
>  	virtio_add_status(dev, VIRTIO_CONFIG_S_FAILED);

[Severity: Medium]
Does resetting the device here clear VIRTIO_CONFIG_S_ACKNOWLEDGE and leave
VIRTIO_CONFIG_S_FAILED set across a subsequent rebind?

virtio_reset_device() zeroes device status, so virtio_add_status() leaves
only VIRTIO_CONFIG_S_FAILED set.  On rebind, virtio_dev_probe() relies on
the register_virtio_device() / virtio_dev_remove() invariant and ORs
VIRTIO_CONFIG_S_DRIVER directly onto the existing status.

That drives status from VIRTIO_CONFIG_S_FAILED | VIRTIO_CONFIG_S_DRIVER
through VIRTIO_CONFIG_S_DRIVER_OK without resetting out of the failed state
or setting VIRTIO_CONFIG_S_ACKNOWLEDGE, violating the Virtio specification
(sections 2.1.1/2.1.2 and 3.1.1).

Strict devices or vDPA backends can reject VIRTIO_CONFIG_S_FEATURES_OK on
rebind, defeating the fix.  Even on lenient backends, the rebound device
keeps VIRTIO_CONFIG_S_FAILED set, which virtio_device_freeze() latches into
dev->failed and re-applies on future restores.

Setting VIRTIO_CONFIG_S_ACKNOWLEDGE before VIRTIO_CONFIG_S_FAILED in the
error path (as virtio_device_restore_priv() does), and resetting and
re-acknowledging on entry to virtio_dev_probe() when status is not cleanly
VIRTIO_CONFIG_S_ACKNOWLEDGE, would keep rebind spec-compliant.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205-virtio-reset-v1-1-c2203390b005@nxp.com?part=1

  reply	other threads:[~2026-12-05 10:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05 10:27 [PATCH] virtio: reset the device when probe fails Peng Fan
2026-12-05 10:41 ` sashiko-bot [this message]
2026-12-05 12:35 ` Michael S. Tsirkin

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=sashiko-outbox-251401@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --cc=peng.fan@linux.dev \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=virtualization@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.