All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Pavol Sakac" <sakacpav@amazon.de>
Cc: linux-pci@vger.kernel.org
Subject: Re: [RFC PATCH 2/3] iommu: create device sysfs links outside iommu_probe_device_lock
Date: Fri, 11 Sep 2026 13:13:27 +0000	[thread overview]
Message-ID: <20260911131327.8DB9E1F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911125907.67105-2-sakacpav@amazon.de>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Early success return on `dev->iommu_group` allows concurrent probes to bypass synchronization, leading to Use-After-Free if publication fails.
--

commit 4fb83220aac8b0e212834d62f2d81e2c473af4b4
Author: Pavol Sakac <sakacpav@amazon.de>

iommu: create device sysfs links outside iommu_probe_device_lock

This patch optimizes parallel device probes by moving sysfs link publication
out of the iommu_probe_device_lock. It introduces a mechanism where devices
are added to the group first, and later passes attempt to establish the
sysfs links outside the lock.

> diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
> index 5f92981d9f345..a5e3327aeacaf 100644
> --- a/drivers/iommu/iommu.c
> +++ b/drivers/iommu/iommu.c
> @@ -710,19 +711,68 @@ static int __iommu_probe_device(struct device *dev, struct list_head *group_list
>  int iommu_probe_device(struct device *dev)
>  {
>  	const struct iommu_ops *ops;
> +	struct group_device *gdev, *own;
> +	struct iommu_group *group;
>  	int ret;
>  
>  	mutex_lock(&iommu_probe_device_lock);
> +	/* Already probed; publication belongs to the creating call. */
> +	if (dev->iommu_group) {
> +		mutex_unlock(&iommu_probe_device_lock);
> +		goto probe_finalize;
> +	}

[Severity: High]
Could this early return allow a concurrent thread to bypass synchronization
and proceed to finalize the device while the primary thread is still
executing publication steps?

If two threads concurrently call iommu_probe_device() for the same device
without device_lock() held, Thread B could see dev->iommu_group already
set by Thread A and jump straight to probe_finalize.

[ ... ]

> +probe_finalize:
>  	ops = dev_iommu_ops(dev);
>  	if (ops->probe_finalize)
>  		ops->probe_finalize(dev);

[Severity: High]
If Thread B jumps to probe_finalize, could it dereference dev->iommu
via dev_iommu_ops(dev) while Thread A executes the err_remove_device path?

[ ... ]

> +err_remove_device:
> +	/* Retried probes early-exit on membership; failure must undo it. */
> +	own = NULL;
> +	for_each_group_device(group, gdev) {
> +		if (gdev->dev == dev) {
> +			own = gdev;
> +			break;
> +		}
> +	}
> +	if (own) {
> +		list_del(&own->list);
> +		__iommu_group_free_device(group, own);
> +		iommu_deinit_device(dev);
> +	}

[Severity: High]
Does calling iommu_deinit_device(dev) free dev->iommu here in Thread A,
leading to a use-after-free when Thread B accesses it in probe_finalize?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260911-vfopt-s2-v1-0-fff3db7e01c2@amazon.de?part=2

  reply	other threads:[~2026-09-11 13:13 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-11 12:58 [RFC PATCH 0/3] iommu: Reduce iommu_probe_device_lock contention Pavol Sakac
2026-09-11 12:58 ` [RFC PATCH 1/3] iommu: split sysfs link publication out of iommu_group_alloc_device() Pavol Sakac
2026-09-11 13:14   ` sashiko-bot
2026-09-11 12:58 ` [RFC PATCH 2/3] iommu: create device sysfs links outside iommu_probe_device_lock Pavol Sakac
2026-09-11 13:13   ` sashiko-bot [this message]
2026-09-11 12:58 ` [RFC PATCH 3/3] iommu: set up the default domain " Pavol Sakac
2026-09-11 13:15   ` sashiko-bot
2026-09-11 17:45 ` [RFC PATCH 0/3] iommu: Reduce iommu_probe_device_lock contention Robin Murphy

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=20260911131327.8DB9E1F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=sakacpav@amazon.de \
    --cc=sashiko-reviews@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.