Linux virtualization list
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Anlai Lu" <agicy@qq.com>
Cc: virtualization@lists.linux.dev,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Eugenio Perez" <eperezma@redhat.com>
Subject: Re: [PATCH 4/6] iommu/virtio: stop queueing and draining once the device is removed
Date: Sun, 04 Oct 2026 12:09:57 +0000	[thread overview]
Message-ID: <20261004120957.CEB961F000FF@smtp.kernel.org> (raw)
In-Reply-To: <tencent_110F1F4156EDBA12B5409541DC2D9BA0C708@qq.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] iommu/virtio: memory leak of pending requests on device removal
--

commit 64ef340ce80cdcdb5ed14c36f584818573bc5be9
Author: Anlai Lu <agicy@qq.com>

iommu/virtio: stop queueing and draining once the device is removed

This commit introduces a removed flag to the viommu_dev struct to indicate
when the device is being torn down. It sets the flag under the request_lock in
viommu_remove() and checks it in the queueing and syncing paths to prevent
queueing or draining operations from running on virtqueues that are being
destroyed.

> diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
> index 1a43664587514..ba1d78e4daa0b 100644
> --- a/drivers/iommu/virtio-iommu.c
> +++ b/drivers/iommu/virtio-iommu.c
[ ... ]
> @@ -206,6 +221,10 @@ static int viommu_sync_req(struct viommu_dev *viommu)
>  	unsigned long flags;
>  
>  	spin_lock_irqsave(&viommu->request_lock, flags);
> +	if (!viommu_device_live(viommu)) {
> +		spin_unlock_irqrestore(&viommu->request_lock, flags);
> +		return 0;
> +	}

[Severity: Medium]
If a device is removed while IOMMU requests are queued but not yet synced,
does this early return bypass __viommu_sync_req() where those pending requests
would normally be freed?

>  	ret = __viommu_sync_req(viommu);
>  	if (ret)
>  		dev_dbg(viommu->dev, "could not sync requests (%d)\n", ret);
[ ... ]
> @@ -1555,10 +1577,20 @@ static int viommu_probe(struct virtio_device *vdev)
>  static void viommu_remove(struct virtio_device *vdev)
>  {
>  	struct viommu_dev *viommu = vdev->priv;
> +	unsigned long flags;
>  
>  	iommu_device_sysfs_remove(&viommu->iommu);
>  	iommu_device_unregister(&viommu->iommu);
>  
> +	/*
> +	 * The queues go away here: nothing may be queued or drained from now
> +	 * on.  Taking request_lock is what tells a drain in flight that it has
> +	 * to finish before the teardown, since the drain holds it throughout.
> +	 */
> +	spin_lock_irqsave(&viommu->request_lock, flags);
> +	viommu->removed = true;
> +	spin_unlock_irqrestore(&viommu->request_lock, flags);
> +

[Severity: Medium]
When setting viommu->removed to true during teardown, do we also need to
iterate over the viommu->requests list and free any abandoned viommu_request
objects?

These objects are dynamically allocated here:

drivers/iommu/virtio-iommu.c:__viommu_add_req() {
...
	req = kzalloc_flex(*req, buf, len, GFP_ATOMIC);
...
}

and bypassing __viommu_sync_req() leaves them without a cleanup path before
the queues are destroyed.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_85AC6E749F6A912B7BB9FF360F8ECB3F5C09@qq.com?part=4

  reply	other threads:[~2026-10-04 12:09 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-04 11:55 [PATCH 0/6] iommu/virtio: batch the mapping replay Anlai Lu
2026-10-04 11:57 ` [PATCH 1/6] iommu/virtio: publish the endpoint before replaying it Anlai Lu
2026-10-04 12:08   ` sashiko-bot
2026-10-04 13:02     ` Anlai Lu
2026-10-04 11:57 ` [PATCH 2/6] iommu/virtio: queue an UNMAP for every removed mapping Anlai Lu
2026-10-04 12:04   ` sashiko-bot
2026-10-04 11:57 ` [PATCH 3/6] iommu/virtio: allocate the UNMAP request with the mapping Anlai Lu
2026-10-04 12:06   ` sashiko-bot
2026-10-04 11:57 ` [PATCH 4/6] iommu/virtio: stop queueing and draining once the device is removed Anlai Lu
2026-10-04 12:09   ` sashiko-bot [this message]
2026-10-04 13:04     ` Anlai Lu
2026-10-04 11:57 ` [PATCH 5/6] iommu/virtio: read the endpoint count under the lock in the iotlb paths Anlai Lu
2026-10-04 12:04   ` sashiko-bot
2026-10-04 11:57 ` [PATCH 6/6] iommu/virtio: batch the mapping replay on domain attach Anlai Lu
2026-10-04 12:10   ` sashiko-bot
2026-10-04 13:04     ` Anlai Lu

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=20261004120957.CEB961F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=agicy@qq.com \
    --cc=eperezma@redhat.com \
    --cc=mst@redhat.com \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox